merged #38
This commit is contained in:
parent
a6adeec5e4
commit
c669f1cec4
@ -1,12 +1,12 @@
|
||||
package com.foxinmy.weixin4j.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONCreator;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 媒体文件上传结果
|
||||
*
|
||||
@ -22,14 +22,20 @@ public class MediaUploadResult implements Serializable {
|
||||
private String mediaId;
|
||||
private MediaType mediaType;
|
||||
private Date createdAt;
|
||||
/**
|
||||
* 新增的图片素材的图片URL
|
||||
*/
|
||||
private String url;
|
||||
|
||||
@JSONCreator
|
||||
public MediaUploadResult(@JSONField(name = "media_id") String mediaId,
|
||||
@JSONField(name = "type") MediaType mediaType,
|
||||
@JSONField(name = "created_at") Date createdAt) {
|
||||
@JSONField(name = "created_at") Date createdAt,
|
||||
@JSONField(name = "url") String url) {
|
||||
this.mediaId = mediaId;
|
||||
this.mediaType = mediaType;
|
||||
this.createdAt = createdAt;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getMediaId() {
|
||||
@ -44,9 +50,13 @@ public class MediaUploadResult implements Serializable {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MediaUploadResult [mediaId=" + mediaId + ", mediaType=" + mediaType
|
||||
+ ", createdAt=" + createdAt + "]";
|
||||
return "MediaUploadResult [mediaId=" + mediaId + ", mediaType="
|
||||
+ mediaType + ", createdAt=" + createdAt + ", url=" + url + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,8 +60,18 @@ public class Weixin4jSettings {
|
||||
*/
|
||||
public Weixin4jSettings(WeixinPayAccount weixinPayAccount,
|
||||
String certificateFile) {
|
||||
this.weixinPayAccount = weixinPayAccount;
|
||||
this(weixinPayAccount);
|
||||
this.certificateFile = certificateFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付代理接口
|
||||
*
|
||||
* @param weixinPayAccount
|
||||
* 商户信息
|
||||
*/
|
||||
public Weixin4jSettings(WeixinPayAccount weixinPayAccount) {
|
||||
this.weixinPayAccount = weixinPayAccount;
|
||||
this.weixinAccount = new WeixinAccount(weixinPayAccount.getId(),
|
||||
weixinPayAccount.getSecret());
|
||||
}
|
||||
|
||||
@ -194,8 +194,9 @@ public class MediaApi extends MpApi {
|
||||
.getContentType().getMimeType(),
|
||||
fileName)), new FormBodyPart("type",
|
||||
new StringBody(mediaType.name(), Consts.UTF_8)));
|
||||
return new MediaUploadResult(response.getAsJson().getString(
|
||||
"media_id"), mediaType, new Date());
|
||||
JSONObject obj = response.getAsJson();
|
||||
return new MediaUploadResult(obj.getString("media_id"),
|
||||
mediaType, new Date(), obj.getString("url"));
|
||||
} else {
|
||||
String media_upload_uri = getRequestUri("media_upload_uri");
|
||||
response = weixinExecutor.post(String.format(media_upload_uri,
|
||||
@ -207,11 +208,8 @@ public class MediaApi extends MpApi {
|
||||
JSONObject obj = response.getAsJson();
|
||||
return new MediaUploadResult(obj.getString("media_id"),
|
||||
obj.getObject("type", MediaType.class), new Date(
|
||||
obj.getLong("created_at") * 1000l));
|
||||
/*
|
||||
* return response.getAsObject(new
|
||||
* TypeReference<MediaUploadResult>() { });
|
||||
*/
|
||||
obj.getLong("created_at") * 1000l),
|
||||
obj.getString("url"));
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new WeixinException(e);
|
||||
|
||||
@ -157,8 +157,9 @@ public class MediaApi extends QyApi {
|
||||
mediaType.name(), agentid), new FormBodyPart("media",
|
||||
new ByteArrayBody(content, mediaType.getContentType()
|
||||
.getMimeType(), fileName)));
|
||||
return new MediaUploadResult(response.getAsJson().getString(
|
||||
"media_id"), mediaType, new Date());
|
||||
JSONObject obj = response.getAsJson();
|
||||
return new MediaUploadResult(obj.getString("media_id"),
|
||||
mediaType, new Date(), obj.getString("url"));
|
||||
} else {
|
||||
String media_upload_uri = getRequestUri("media_upload_uri");
|
||||
response = weixinExecutor.post(String.format(media_upload_uri,
|
||||
@ -169,11 +170,8 @@ public class MediaApi extends QyApi {
|
||||
JSONObject obj = response.getAsJson();
|
||||
return new MediaUploadResult(obj.getString("media_id"),
|
||||
obj.getObject("type", MediaType.class), new Date(
|
||||
obj.getLong("created_at") * 1000l));
|
||||
/*
|
||||
* return response.getAsObject(new
|
||||
* TypeReference<MediaUploadResult>() { });
|
||||
*/
|
||||
obj.getLong("created_at") * 1000l),
|
||||
obj.getString("url"));
|
||||
}
|
||||
} finally {
|
||||
if (is != null) {
|
||||
|
||||
@ -47,7 +47,7 @@ public class AgentSetter implements Serializable {
|
||||
@JSONField(name = "redirect_domain")
|
||||
private String redirectDomain;
|
||||
/**
|
||||
* 是否接收用户变更通知。0:不接收;1:接收
|
||||
* 是否接收用户变更通知。0:不接收;1:接收。主页型应用无需该参数
|
||||
*/
|
||||
@JSONField(name = "isreportuser")
|
||||
private boolean isReportUser;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user