This commit is contained in:
jinyu 2016-03-18 22:12:04 +08:00
parent a6adeec5e4
commit c669f1cec4
5 changed files with 38 additions and 22 deletions

View File

@ -1,12 +1,12 @@
package com.foxinmy.weixin4j.model; package com.foxinmy.weixin4j.model;
import java.io.Serializable;
import java.util.Date;
import com.alibaba.fastjson.annotation.JSONCreator; import com.alibaba.fastjson.annotation.JSONCreator;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.type.MediaType; 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 String mediaId;
private MediaType mediaType; private MediaType mediaType;
private Date createdAt; private Date createdAt;
/**
* 新增的图片素材的图片URL
*/
private String url;
@JSONCreator @JSONCreator
public MediaUploadResult(@JSONField(name = "media_id") String mediaId, public MediaUploadResult(@JSONField(name = "media_id") String mediaId,
@JSONField(name = "type") MediaType mediaType, @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.mediaId = mediaId;
this.mediaType = mediaType; this.mediaType = mediaType;
this.createdAt = createdAt; this.createdAt = createdAt;
this.url = url;
} }
public String getMediaId() { public String getMediaId() {
@ -44,9 +50,13 @@ public class MediaUploadResult implements Serializable {
return createdAt; return createdAt;
} }
public String getUrl() {
return url;
}
@Override @Override
public String toString() { public String toString() {
return "MediaUploadResult [mediaId=" + mediaId + ", mediaType=" + mediaType return "MediaUploadResult [mediaId=" + mediaId + ", mediaType="
+ ", createdAt=" + createdAt + "]"; + mediaType + ", createdAt=" + createdAt + ", url=" + url + "]";
} }
} }

View File

@ -60,8 +60,18 @@ public class Weixin4jSettings {
*/ */
public Weixin4jSettings(WeixinPayAccount weixinPayAccount, public Weixin4jSettings(WeixinPayAccount weixinPayAccount,
String certificateFile) { String certificateFile) {
this.weixinPayAccount = weixinPayAccount; this(weixinPayAccount);
this.certificateFile = certificateFile; this.certificateFile = certificateFile;
}
/**
* 支付代理接口
*
* @param weixinPayAccount
* 商户信息
*/
public Weixin4jSettings(WeixinPayAccount weixinPayAccount) {
this.weixinPayAccount = weixinPayAccount;
this.weixinAccount = new WeixinAccount(weixinPayAccount.getId(), this.weixinAccount = new WeixinAccount(weixinPayAccount.getId(),
weixinPayAccount.getSecret()); weixinPayAccount.getSecret());
} }

View File

@ -194,8 +194,9 @@ public class MediaApi extends MpApi {
.getContentType().getMimeType(), .getContentType().getMimeType(),
fileName)), new FormBodyPart("type", fileName)), new FormBodyPart("type",
new StringBody(mediaType.name(), Consts.UTF_8))); new StringBody(mediaType.name(), Consts.UTF_8)));
return new MediaUploadResult(response.getAsJson().getString( JSONObject obj = response.getAsJson();
"media_id"), mediaType, new Date()); return new MediaUploadResult(obj.getString("media_id"),
mediaType, new Date(), obj.getString("url"));
} else { } else {
String media_upload_uri = getRequestUri("media_upload_uri"); String media_upload_uri = getRequestUri("media_upload_uri");
response = weixinExecutor.post(String.format(media_upload_uri, response = weixinExecutor.post(String.format(media_upload_uri,
@ -207,11 +208,8 @@ public class MediaApi extends MpApi {
JSONObject obj = response.getAsJson(); JSONObject obj = response.getAsJson();
return new MediaUploadResult(obj.getString("media_id"), return new MediaUploadResult(obj.getString("media_id"),
obj.getObject("type", MediaType.class), new Date( obj.getObject("type", MediaType.class), new Date(
obj.getLong("created_at") * 1000l)); obj.getLong("created_at") * 1000l),
/* obj.getString("url"));
* return response.getAsObject(new
* TypeReference<MediaUploadResult>() { });
*/
} }
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
throw new WeixinException(e); throw new WeixinException(e);

View File

@ -157,8 +157,9 @@ public class MediaApi extends QyApi {
mediaType.name(), agentid), new FormBodyPart("media", mediaType.name(), agentid), new FormBodyPart("media",
new ByteArrayBody(content, mediaType.getContentType() new ByteArrayBody(content, mediaType.getContentType()
.getMimeType(), fileName))); .getMimeType(), fileName)));
return new MediaUploadResult(response.getAsJson().getString( JSONObject obj = response.getAsJson();
"media_id"), mediaType, new Date()); return new MediaUploadResult(obj.getString("media_id"),
mediaType, new Date(), obj.getString("url"));
} else { } else {
String media_upload_uri = getRequestUri("media_upload_uri"); String media_upload_uri = getRequestUri("media_upload_uri");
response = weixinExecutor.post(String.format(media_upload_uri, response = weixinExecutor.post(String.format(media_upload_uri,
@ -169,11 +170,8 @@ public class MediaApi extends QyApi {
JSONObject obj = response.getAsJson(); JSONObject obj = response.getAsJson();
return new MediaUploadResult(obj.getString("media_id"), return new MediaUploadResult(obj.getString("media_id"),
obj.getObject("type", MediaType.class), new Date( obj.getObject("type", MediaType.class), new Date(
obj.getLong("created_at") * 1000l)); obj.getLong("created_at") * 1000l),
/* obj.getString("url"));
* return response.getAsObject(new
* TypeReference<MediaUploadResult>() { });
*/
} }
} finally { } finally {
if (is != null) { if (is != null) {

View File

@ -47,7 +47,7 @@ public class AgentSetter implements Serializable {
@JSONField(name = "redirect_domain") @JSONField(name = "redirect_domain")
private String redirectDomain; private String redirectDomain;
/** /**
* 是否接收用户变更通知0不接收1接收 * 是否接收用户变更通知0不接收1接收主页型应用无需该参数
*/ */
@JSONField(name = "isreportuser") @JSONField(name = "isreportuser")
private boolean isReportUser; private boolean isReportUser;