diff --git a/pom.xml b/pom.xml index f93c5dd5c6..6a683db1a0 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 com.github.binarywang weixin-java-parent - 2.8.0 + 2.9.0 pom WeiXin Java Tools - Parent 微信公众号、企业号上级POM @@ -80,6 +80,11 @@ crskyp@gmail.com https://github.com/crskyp + + 007 + 007gzs@gmail.com + https://github.com/007gzs + @@ -94,6 +99,7 @@ weixin-java-mp weixin-java-pay weixin-java-miniapp + weixin-java-open @@ -225,6 +231,12 @@ 2.9.0 provided + + org.projectlombok + lombok + 1.16.18 + compile + diff --git a/quality-checks/google_checks.xml b/quality-checks/google_checks.xml index 925172dab6..af44980285 100644 --- a/quality-checks/google_checks.xml +++ b/quality-checks/google_checks.xml @@ -40,7 +40,7 @@ - + @@ -52,7 +52,7 @@ - + @@ -163,9 +163,12 @@ + + + - - + diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml index 68c6130612..7dcff6ad6c 100644 --- a/weixin-java-common/pom.xml +++ b/weixin-java-common/pom.xml @@ -7,7 +7,7 @@ com.github.binarywang weixin-java-parent - 2.8.0 + 2.9.0 weixin-java-common @@ -74,6 +74,10 @@ com.google.guava guava + + org.projectlombok + lombok + ch.qos.logback diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java index e416323e02..6380749224 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java @@ -3,187 +3,248 @@ import java.util.HashMap; import java.util.Map; +/** + * 微信开发所使用到的常量类. + * + * @author chanjarster & binarywang + */ public class WxConsts { - - /////////////////////// - // 微信推送过来的消息的类型,和发送给微信xml格式消息的消息类型 - /////////////////////// - public static final String XML_MSG_TEXT = "text"; - public static final String XML_MSG_IMAGE = "image"; - public static final String XML_MSG_VOICE = "voice"; - public static final String XML_MSG_SHORTVIDEO = "shortvideo"; - public static final String XML_MSG_VIDEO = "video"; - public static final String XML_MSG_NEWS = "news"; - public static final String XML_MSG_MUSIC = "music"; - public static final String XML_MSG_LOCATION = "location"; - public static final String XML_MSG_LINK = "link"; - public static final String XML_MSG_EVENT = "event"; - public static final String XML_MSG_DEVICE_TEXT = "device_text"; - public static final String XML_MSG_DEVICE_EVENT = "device_event"; - public static final String XML_MSG_DEVICE_STATUS = "device_status"; - public static final String XML_MSG_HARDWARE = "hardware"; - public static final String XML_TRANSFER_CUSTOMER_SERVICE = "transfer_customer_service"; - - /////////////////////// - // 主动发送消息(即客服消息)的消息类型 - /////////////////////// - public static final String CUSTOM_MSG_TEXT = "text";//文本消息 - public static final String CUSTOM_MSG_IMAGE = "image";//图片消息 - public static final String CUSTOM_MSG_VOICE = "voice";//语音消息 - public static final String CUSTOM_MSG_VIDEO = "video";//视频消息 - public static final String CUSTOM_MSG_MUSIC = "music";//音乐消息 - public static final String CUSTOM_MSG_NEWS = "news";//图文消息(点击跳转到外链) - public static final String CUSTOM_MSG_MPNEWS = "mpnews";//图文消息(点击跳转到图文消息页面) - public static final String CUSTOM_MSG_FILE = "file";//发送文件(CP专用) - public static final String CUSTOM_MSG_TEXTCARD = "textcard";//文本卡片消息(CP专用) - public static final String CUSTOM_MSG_WXCARD = "wxcard";//卡券消息 - public static final String CUSTOM_MSG_TRANSFER_CUSTOMER_SERVICE = "transfer_customer_service"; - public static final String CUSTOM_MSG_SAFE_NO = "0"; - public static final String CUSTOM_MSG_SAFE_YES = "1"; - - /////////////////////// - // 群发消息的消息类型 - /////////////////////// - public static final String MASS_MSG_NEWS = "mpnews"; - public static final String MASS_MSG_TEXT = "text"; - public static final String MASS_MSG_VOICE = "voice"; - public static final String MASS_MSG_IMAGE = "image"; - public static final String MASS_MSG_VIDEO = "mpvideo"; - - /////////////////////// - // 群发消息后微信端推送给服务器的反馈消息 - /////////////////////// - public static final String MASS_ST_SUCCESS = "send success"; - public static final String MASS_ST_FAIL = "send fail"; - public static final String MASS_ST_10001 = "err(10001)"; - public static final String MASS_ST_20001 = "err(20001)"; - public static final String MASS_ST_20004 = "err(20004)"; - public static final String MASS_ST_20002 = "err(20002)"; - public static final String MASS_ST_20006 = "err(20006)"; - public static final String MASS_ST_20008 = "err(20008)"; - public static final String MASS_ST_20013 = "err(20013)"; - public static final String MASS_ST_22000 = "err(22000)"; - public static final String MASS_ST_21000 = "err(21000)"; - /** - * 群发反馈消息代码所对应的文字描述 + * 微信推送过来的消息的类型,和发送给微信xml格式消息的消息类型. */ - public static final Map MASS_ST_2_DESC = new HashMap<>(); - - /////////////////////// - // 微信端推送过来的事件类型 - /////////////////////// - public static final String EVT_SUBSCRIBE = "subscribe"; - public static final String EVT_UNSUBSCRIBE = "unsubscribe"; - public static final String EVT_SCAN = "SCAN"; - public static final String EVT_LOCATION = "LOCATION"; - public static final String EVT_CLICK = "CLICK"; - public static final String EVT_VIEW = "VIEW"; - public static final String EVT_MASS_SEND_JOB_FINISH = "MASSSENDJOBFINISH"; - public static final String EVT_SCANCODE_PUSH = "scancode_push"; - public static final String EVT_SCANCODE_WAITMSG = "scancode_waitmsg"; - public static final String EVT_PIC_SYSPHOTO = "pic_sysphoto"; - public static final String EVT_PIC_PHOTO_OR_ALBUM = "pic_photo_or_album"; - public static final String EVT_PIC_WEIXIN = "pic_weixin"; - public static final String EVT_LOCATION_SELECT = "location_select"; - public static final String EVT_TEMPLATESENDJOBFINISH = "TEMPLATESENDJOBFINISH"; - public static final String EVT_ENTER_AGENT = "enter_agent"; - - /////////////////////// - // 上传多媒体文件的类型 - /////////////////////// - public static final String MEDIA_IMAGE = "image"; - public static final String MEDIA_VOICE = "voice"; - public static final String MEDIA_VIDEO = "video"; - public static final String MEDIA_THUMB = "thumb"; - public static final String MEDIA_FILE = "file"; - + public static class XmlMsgType { + public static final String TEXT = "text"; + public static final String IMAGE = "image"; + public static final String VOICE = "voice"; + public static final String SHORTVIDEO = "shortvideo"; + public static final String VIDEO = "video"; + public static final String NEWS = "news"; + public static final String MUSIC = "music"; + public static final String LOCATION = "location"; + public static final String LINK = "link"; + public static final String EVENT = "event"; + public static final String DEVICE_TEXT = "device_text"; + public static final String DEVICE_EVENT = "device_event"; + public static final String DEVICE_STATUS = "device_status"; + public static final String HARDWARE = "hardware"; + public static final String TRANSFER_CUSTOMER_SERVICE = "transfer_customer_service"; + } - /////////////////////// - // 自定义菜单的按钮类型 - /////////////////////// - /** - * 点击推事件 - */ - public static final String BUTTON_CLICK = "click"; - /** - * 跳转URL - */ - public static final String BUTTON_VIEW = "view"; - /** - * 跳转到小程序 - */ - public static final String BUTTON_MINIPROGRAM = "miniprogram"; - /** - * 扫码推事件 - */ - public static final String BUTTON_SCANCODE_PUSH = "scancode_push"; /** - * 扫码推事件且弹出“消息接收中”提示框 + * 主动发送消息(即客服消息)的消息类型. */ - public static final String BUTTON_SCANCODE_WAITMSG = "scancode_waitmsg"; + public static class KefuMsgType { + /** + * 文本消息. + */ + public static final String TEXT = "text"; + /** + * 图片消息. + */ + public static final String IMAGE = "image"; + /** + * 语音消息. + */ + public static final String VOICE = "voice"; + /** + * 视频消息. + */ + public static final String VIDEO = "video"; + /** + * 音乐消息. + */ + public static final String MUSIC = "music"; + /** + * 图文消息(点击跳转到外链). + */ + public static final String NEWS = "news"; + /** + * 图文消息(点击跳转到图文消息页面). + */ + public static final String MPNEWS = "mpnews"; + /** + * 发送文件(CP专用). + */ + public static final String FILE = "file"; + /** + * 文本卡片消息(CP专用). + */ + public static final String TEXTCARD = "textcard"; + /** + * 卡券消息. + */ + public static final String WXCARD = "wxcard"; + /** + * 转发到客服的消息. + */ + public static final String TRANSFER_CUSTOMER_SERVICE = "transfer_customer_service"; + } + /** - * 弹出系统拍照发图 + * 表示是否是保密消息,0表示否,1表示是,默认0. */ - public static final String BUTTON_PIC_SYSPHOTO = "pic_sysphoto"; + public static class KefuMsgSafe { + public static final String NO = "0"; + public static final String YES = "1"; + } + /** - * 弹出拍照或者相册发图 + * 群发消息的消息类型. */ - public static final String BUTTON_PIC_PHOTO_OR_ALBUM = "pic_photo_or_album"; + public static class MassMsgType { + public static final String MPNEWS = "mpnews"; + public static final String TEXT = "text"; + public static final String VOICE = "voice"; + public static final String IMAGE = "image"; + public static final String MPVIDEO = "mpvideo"; + } + /** - * 弹出微信相册发图器 + * 群发消息后微信端推送给服务器的反馈消息. */ - public static final String BUTTON_PIC_WEIXIN = "pic_weixin"; + public static class MassMsgStatus { + public static final String SEND_SUCCESS = "send success"; + public static final String SEND_FAIL = "send fail"; + public static final String ERR_10001 = "err(10001)"; + public static final String ERR_20001 = "err(20001)"; + public static final String ERR_20004 = "err(20004)"; + public static final String ERR_20002 = "err(20002)"; + public static final String ERR_20006 = "err(20006)"; + public static final String ERR_20008 = "err(20008)"; + public static final String ERR_20013 = "err(20013)"; + public static final String ERR_22000 = "err(22000)"; + public static final String ERR_21000 = "err(21000)"; + + /** + * 群发反馈消息代码所对应的文字描述. + */ + public static final Map STATUS_DESC = new HashMap<>(); + + static { + STATUS_DESC.put(SEND_SUCCESS, "发送成功"); + STATUS_DESC.put(SEND_FAIL, "发送失败"); + STATUS_DESC.put(ERR_10001, "涉嫌广告"); + STATUS_DESC.put(ERR_20001, "涉嫌政治"); + STATUS_DESC.put(ERR_20004, "涉嫌社会"); + STATUS_DESC.put(ERR_20002, "涉嫌色情"); + STATUS_DESC.put(ERR_20006, "涉嫌违法犯罪"); + STATUS_DESC.put(ERR_20008, "涉嫌欺诈"); + STATUS_DESC.put(ERR_20013, "涉嫌版权"); + STATUS_DESC.put(ERR_22000, "涉嫌互推_互相宣传"); + STATUS_DESC.put(ERR_21000, "涉嫌其他"); + } + } + /** - * 弹出地理位置选择器 + * 微信端推送过来的事件类型. */ - public static final String BUTTON_LOCATION_SELECT = "location_select"; + public static class EventType { + public static final String SUBSCRIBE = "subscribe"; + public static final String UNSUBSCRIBE = "unsubscribe"; + public static final String SCAN = "SCAN"; + public static final String LOCATION = "LOCATION"; + public static final String CLICK = "CLICK"; + public static final String VIEW = "VIEW"; + public static final String MASS_SEND_JOB_FINISH = "MASSSENDJOBFINISH"; + public static final String SCANCODE_PUSH = "scancode_push"; + public static final String SCANCODE_WAITMSG = "scancode_waitmsg"; + public static final String PIC_SYSPHOTO = "pic_sysphoto"; + public static final String PIC_PHOTO_OR_ALBUM = "pic_photo_or_album"; + public static final String PIC_WEIXIN = "pic_weixin"; + public static final String LOCATION_SELECT = "location_select"; + public static final String TEMPLATE_SEND_JOB_FINISH = "TEMPLATESENDJOBFINISH"; + public static final String ENTER_AGENT = "enter_agent"; + } + /** - * 下发消息(除文本消息) + * 上传多媒体(临时素材)文件的类型. */ - public static final String BUTTON_MEDIA_ID = "media_id"; + public static class MediaFileType { + public static final String IMAGE = "image"; + public static final String VOICE = "voice"; + public static final String VIDEO = "video"; + public static final String THUMB = "thumb"; + public static final String FILE = "file"; + } + /** - * 跳转图文消息URL + * 自定义菜单的按钮类型. */ - public static final String BUTTON_VIEW_LIMITED = "view_limited"; + public static class MenuButtonType { + /** + * 点击推事件. + */ + public static final String CLICK = "click"; + /** + * 跳转URL. + */ + public static final String VIEW = "view"; + /** + * 跳转到小程序. + */ + public static final String MINIPROGRAM = "miniprogram"; + /** + * 扫码推事件. + */ + public static final String SCANCODE_PUSH = "scancode_push"; + /** + * 扫码推事件且弹出“消息接收中”提示框. + */ + public static final String SCANCODE_WAITMSG = "scancode_waitmsg"; + /** + * 弹出系统拍照发图. + */ + public static final String PIC_SYSPHOTO = "pic_sysphoto"; + /** + * 弹出拍照或者相册发图. + */ + public static final String PIC_PHOTO_OR_ALBUM = "pic_photo_or_album"; + /** + * 弹出微信相册发图器. + */ + public static final String PIC_WEIXIN = "pic_weixin"; + /** + * 弹出地理位置选择器. + */ + public static final String LOCATION_SELECT = "location_select"; + /** + * 下发消息(除文本消息). + */ + public static final String MEDIA_ID = "media_id"; + /** + * 跳转图文消息URL. + */ + public static final String VIEW_LIMITED = "view_limited"; + } /** - * 不弹出授权页面,直接跳转,只能获取用户openid + * oauth2网页授权的scope. */ - public static final String OAUTH2_SCOPE_BASE = "snsapi_base"; + public static class OAuth2Scope { + /** + * 不弹出授权页面,直接跳转,只能获取用户openid. + */ + public static final String SNSAPI_BASE = "snsapi_base"; + /** + * 弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息. + */ + public static final String SNSAPI_USERINFO = "snsapi_userinfo"; + } - /////////////////////// - // oauth2网页授权的scope - /////////////////////// /** - * 弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息 + * 网页应用登录授权作用域. */ - public static final String OAUTH2_SCOPE_USER_INFO = "snsapi_userinfo"; + public static class QrConnectScope { + public static final String SNSAPI_LOGIN = "snsapi_login"; + } /** - * 网页应用登录授权作用域 snsapi_login + * 永久素材类型. */ - public static final String QRCONNECT_SCOPE_SNSAPI_LOGIN = "snsapi_login"; - - /////////////////////// - // 永久素材类型 - /////////////////////// - public static final String MATERIAL_NEWS = "news"; - public static final String MATERIAL_VOICE = "voice"; - public static final String MATERIAL_IMAGE = "image"; - public static final String MATERIAL_VIDEO = "video"; - - static { - MASS_ST_2_DESC.put(MASS_ST_SUCCESS, "发送成功"); - MASS_ST_2_DESC.put(MASS_ST_FAIL, "发送失败"); - MASS_ST_2_DESC.put(MASS_ST_10001, "涉嫌广告"); - MASS_ST_2_DESC.put(MASS_ST_20001, "涉嫌政治"); - MASS_ST_2_DESC.put(MASS_ST_20004, "涉嫌社会"); - MASS_ST_2_DESC.put(MASS_ST_20002, "涉嫌色情"); - MASS_ST_2_DESC.put(MASS_ST_20006, "涉嫌违法犯罪"); - MASS_ST_2_DESC.put(MASS_ST_20008, "涉嫌欺诈"); - MASS_ST_2_DESC.put(MASS_ST_20013, "涉嫌版权"); - MASS_ST_2_DESC.put(MASS_ST_22000, "涉嫌互推_互相宣传"); - MASS_ST_2_DESC.put(MASS_ST_21000, "涉嫌其他"); + public static class MaterialType { + public static final String NEWS = "news"; + public static final String VOICE = "voice"; + public static final String IMAGE = "image"; + public static final String VIDEO = "video"; } } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxErrorExceptionHandler.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxErrorExceptionHandler.java index d6acf55b52..5117c765f3 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxErrorExceptionHandler.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxErrorExceptionHandler.java @@ -3,7 +3,7 @@ import me.chanjar.weixin.common.exception.WxErrorException; /** - * WxErrorException处理器 + * WxErrorException处理器. */ public interface WxErrorExceptionHandler { diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageDuplicateChecker.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageDuplicateChecker.java index 831458a443..fdb0cd81bc 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageDuplicateChecker.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageDuplicateChecker.java @@ -2,22 +2,21 @@ /** *
- * 消息重复检查器
+ * 消息重复检查器.
  * 微信服务器在五秒内收不到响应会断掉连接,并且重新发起请求,总共重试三次
  * 
*/ public interface WxMessageDuplicateChecker { /** + * 判断消息是否重复. *

公众号的排重方式

- *

+ * *

普通消息:关于重试的消息排重,推荐使用msgid排重。文档参考

*

事件消息:关于重试的消息排重,推荐使用FromUserName + CreateTime 排重。文档参考

- *

+ * *

企业号的排重方式

- *

- * 官方文档完全没有写,参照公众号的方式排重。 - *

+ *

官方文档完全没有写,参照公众号的方式排重。

*

或者可以采取更简单的方式,如果有MsgId就用MsgId排重,如果没有就用FromUserName+CreateTime排重

* * @param messageId messageId需要根据上面讲的方式构造 diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageInMemoryDuplicateChecker.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageInMemoryDuplicateChecker.java index 1281e26012..d8be08f446 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageInMemoryDuplicateChecker.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageInMemoryDuplicateChecker.java @@ -6,46 +6,46 @@ /** *
- * 默认消息重复检查器
+ * 默认消息重复检查器.
  * 将每个消息id保存在内存里,每隔5秒清理已经过期的消息id,每个消息id的过期时间是15秒
  * 
*/ public class WxMessageInMemoryDuplicateChecker implements WxMessageDuplicateChecker { /** - * 一个消息ID在内存的过期时间:15秒 + * 一个消息ID在内存的过期时间:15秒. */ private final Long timeToLive; /** - * 每隔多少周期检查消息ID是否过期:5秒 + * 每隔多少周期检查消息ID是否过期:5秒. */ private final Long clearPeriod; /** - * 消息id->消息时间戳的map + * 消息id->消息时间戳的map. */ private final ConcurrentHashMap msgId2Timestamp = new ConcurrentHashMap<>(); /** - * 后台清理线程是否已经开启 + * 后台清理线程是否已经开启. */ private final AtomicBoolean backgroundProcessStarted = new AtomicBoolean(false); /** - * WxMsgIdInMemoryDuplicateChecker构造函数 + * 无参构造方法. *
    * 一个消息ID在内存的过期时间:15秒
    * 每隔多少周期检查消息ID是否过期:5秒
    * 
*/ public WxMessageInMemoryDuplicateChecker() { - this.timeToLive = 15 * 1000l; - this.clearPeriod = 5 * 1000l; + this.timeToLive = 15 * 1000L; + this.clearPeriod = 5 * 1000L; } /** - * WxMsgIdInMemoryDuplicateChecker构造函数 + * 构造方法. * * @param timeToLive 一个消息ID在内存的过期时间:毫秒 * @param clearPeriod 每隔多少周期检查消息ID是否过期:毫秒 @@ -66,7 +66,8 @@ public void run() { while (true) { Thread.sleep(WxMessageInMemoryDuplicateChecker.this.clearPeriod); Long now = System.currentTimeMillis(); - for (Map.Entry entry : WxMessageInMemoryDuplicateChecker.this.msgId2Timestamp.entrySet()) { + for (Map.Entry entry : + WxMessageInMemoryDuplicateChecker.this.msgId2Timestamp.entrySet()) { if (now - entry.getValue() > WxMessageInMemoryDuplicateChecker.this.timeToLive) { WxMessageInMemoryDuplicateChecker.this.msgId2Timestamp.entrySet().remove(entry); } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxAccessToken.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxAccessToken.java index 6476205a54..6327965152 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxAccessToken.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxAccessToken.java @@ -1,9 +1,11 @@ package me.chanjar.weixin.common.bean; +import lombok.Data; import me.chanjar.weixin.common.util.json.WxGsonBuilder; import java.io.Serializable; +@Data public class WxAccessToken implements Serializable { private static final long serialVersionUID = 8709719312922168909L; @@ -15,20 +17,4 @@ public static WxAccessToken fromJson(String json) { return WxGsonBuilder.create().fromJson(json, WxAccessToken.class); } - public String getAccessToken() { - return this.accessToken; - } - - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } - - public int getExpiresIn() { - return this.expiresIn; - } - - public void setExpiresIn(int expiresIn) { - this.expiresIn = expiresIn; - } - } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxCardApiSignature.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxCardApiSignature.java index df272318e7..9d5d7a06dd 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxCardApiSignature.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxCardApiSignature.java @@ -1,17 +1,18 @@ package me.chanjar.weixin.common.bean; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import java.io.Serializable; /** - * 卡券Api签名 + * 卡券Api签名. * * @author YuJian * @version 15/11/8 */ +@Data public class WxCardApiSignature implements Serializable { - private static final long serialVersionUID = 158176707226975979L; private String appId; @@ -37,75 +38,4 @@ public String toString() { return ToStringUtils.toSimpleString(this); } - public String getAppId() { - return this.appId; - } - - public void setAppId(String appId) { - this.appId = appId; - } - - public String getCardId() { - return this.cardId; - } - - public void setCardId(String cardId) { - this.cardId = cardId; - } - - public String getCardType() { - return this.cardType; - } - - public void setCardType(String cardType) { - this.cardType = cardType; - } - - public String getLocationId() { - return this.locationId; - } - - public void setLocationId(String locationId) { - this.locationId = locationId; - } - - public String getCode() { - return this.code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getOpenId() { - return this.openId; - } - - public void setOpenId(String openId) { - this.openId = openId; - } - - public Long getTimestamp() { - return this.timestamp; - } - - public void setTimestamp(Long timestamp) { - this.timestamp = timestamp; - } - - public String getNonceStr() { - return this.nonceStr; - } - - public void setNonceStr(String nonceStr) { - this.nonceStr = nonceStr; - } - - public String getSignature() { - return this.signature; - } - - public void setSignature(String signature) { - this.signature = signature; - } } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java index 7837158361..619f0a7504 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java @@ -1,10 +1,13 @@ package me.chanjar.weixin.common.bean; +import lombok.Data; + import java.io.Serializable; /** - * jspai signature + * jspai signature. */ +@Data public class WxJsapiSignature implements Serializable { private static final long serialVersionUID = -1116808193154384804L; @@ -18,43 +21,4 @@ public class WxJsapiSignature implements Serializable { private String signature; - public String getSignature() { - return this.signature; - } - - public void setSignature(String signature) { - this.signature = signature; - } - - public String getNonceStr() { - return nonceStr; - } - - public void setNonceStr(String nonceStr) { - this.nonceStr = nonceStr; - } - - public long getTimestamp() { - return this.timestamp; - } - - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } - - public String getUrl() { - return this.url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getAppId() { - return appId; - } - - public void setAppId(String appId) { - this.appId = appId; - } } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenu.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenu.java index 4e61a46591..4d349acb25 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenu.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenu.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.common.bean.menu; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.common.util.json.WxGsonBuilder; @@ -11,12 +12,12 @@ import java.util.List; /** - * 菜单(公众号和企业号共用的) + * 菜单(公众号和企业号共用的). * * @author Daniel Qian */ +@Data public class WxMenu implements Serializable { - private static final long serialVersionUID = -7083914585539687746L; private List buttons = new ArrayList<>(); @@ -36,23 +37,8 @@ public static WxMenu fromJson(String json) { * 相比 http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html 的格式,外层多套了一个menu */ public static WxMenu fromJson(InputStream is) { - return WxGsonBuilder.create().fromJson(new InputStreamReader(is, StandardCharsets.UTF_8), WxMenu.class); - } - - public List getButtons() { - return this.buttons; - } - - public void setButtons(List buttons) { - this.buttons = buttons; - } - - public WxMenuRule getMatchRule() { - return this.matchRule; - } - - public void setMatchRule(WxMenuRule matchRule) { - this.matchRule = matchRule; + return WxGsonBuilder.create() + .fromJson(new InputStreamReader(is, StandardCharsets.UTF_8), WxMenu.class); } public String toJson() { diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuButton.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuButton.java index aa6ea4cfb2..2f9276b025 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuButton.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuButton.java @@ -1,18 +1,20 @@ package me.chanjar.weixin.common.bean.menu; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import java.io.Serializable; import java.util.ArrayList; import java.util.List; +@Data public class WxMenuButton implements Serializable { private static final long serialVersionUID = -1070939403109776555L; /** *
-   * 菜单的响应动作类型:
+   * 菜单的响应动作类型.
    * view表示网页类型,
    * click表示点击类型,
    * miniprogram表示小程序类型
@@ -21,13 +23,13 @@ public class WxMenuButton implements Serializable {
   private String type;
 
   /**
-   * 菜单标题,不超过16个字节,子菜单不超过60个字节
+   * 菜单标题,不超过16个字节,子菜单不超过60个字节.
    */
   private String name;
 
   /**
    * 
-   * 菜单KEY值,用于消息接口推送,不超过128字节
+   * 菜单KEY值,用于消息接口推送,不超过128字节.
    * click等点击类型必须
    * 
*/ @@ -35,7 +37,8 @@ public class WxMenuButton implements Serializable { /** *
-   * 网页链接,用户点击菜单可打开链接,不超过1024字节。type为miniprogram时,不支持小程序的老版本客户端将打开本url。
+   * 网页链接.
+   * 用户点击菜单可打开链接,不超过1024字节。type为miniprogram时,不支持小程序的老版本客户端将打开本url。
    * view、miniprogram类型必须
    * 
*/ @@ -43,7 +46,7 @@ public class WxMenuButton implements Serializable { /** *
-   * 调用新增永久素材接口返回的合法media_id
+   * 调用新增永久素材接口返回的合法media_id.
    * media_id类型和view_limited类型必须
    * 
*/ @@ -52,7 +55,7 @@ public class WxMenuButton implements Serializable { /** *
-   * 小程序的appid
+   * 小程序的appid.
    * miniprogram类型必须
    * 
*/ @@ -61,7 +64,7 @@ public class WxMenuButton implements Serializable { /** *
-   * 小程序的页面路径
+   * 小程序的页面路径.
    * miniprogram类型必须
    * 
*/ @@ -76,67 +79,4 @@ public String toString() { return ToStringUtils.toSimpleString(this); } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public String getKey() { - return this.key; - } - - public void setKey(String key) { - this.key = key; - } - - public String getUrl() { - return this.url; - } - - public void setUrl(String url) { - this.url = url; - } - - public List getSubButtons() { - return this.subButtons; - } - - public void setSubButtons(List subButtons) { - this.subButtons = subButtons; - } - - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } - - public String getAppId() { - return appId; - } - - public void setAppId(String appId) { - this.appId = appId; - } - - public String getPagePath() { - return pagePath; - } - - public void setPagePath(String pagePath) { - this.pagePath = pagePath; - } } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java index e0182c9678..16542dec69 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java @@ -1,12 +1,19 @@ package me.chanjar.weixin.common.bean.menu; +import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import java.io.Serializable; +@Data public class WxMenuRule implements Serializable { private static final long serialVersionUID = -4587181819499286670L; + /** + * 变态的微信接口,反序列化时这里反人类的使用和序列化时不一样的名字. + */ + @SerializedName(value = "tag_id", alternate = "group_id") private String tagId; private String sex; private String country; @@ -15,62 +22,6 @@ public class WxMenuRule implements Serializable { private String clientPlatformType; private String language; - public String getTagId() { - return this.tagId; - } - - public void setTagId(String tagId) { - this.tagId = tagId; - } - - public String getSex() { - return this.sex; - } - - public void setSex(String sex) { - this.sex = sex; - } - - public String getCountry() { - return this.country; - } - - public void setCountry(String country) { - this.country = country; - } - - public String getProvince() { - return this.province; - } - - public void setProvince(String province) { - this.province = province; - } - - public String getCity() { - return this.city; - } - - public void setCity(String city) { - this.city = city; - } - - public String getClientPlatformType() { - return this.clientPlatformType; - } - - public void setClientPlatformType(String clientPlatformType) { - this.clientPlatformType = clientPlatformType; - } - - public String getLanguage() { - return this.language; - } - - public void setLanguage(String language) { - this.language = language; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java index 46c0ae89be..25a06f4785 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java @@ -1,14 +1,18 @@ package me.chanjar.weixin.common.bean.result; +import lombok.Builder; +import lombok.Data; import me.chanjar.weixin.common.util.json.WxGsonBuilder; import java.io.Serializable; /** - * 微信错误码说明,请阅读: 全局返回码说明 + * 微信错误码说明,请阅读: 全局返回码说明. * * @author Daniel Qian */ +@Data +@Builder public class WxError implements Serializable { private static final long serialVersionUID = 7869786563361406291L; @@ -23,34 +27,6 @@ public static WxError fromJson(String json) { return WxGsonBuilder.create().fromJson(json, WxError.class); } - public static Builder newBuilder() { - return new Builder(); - } - - public int getErrorCode() { - return this.errorCode; - } - - public void setErrorCode(int errorCode) { - this.errorCode = errorCode; - } - - public String getErrorMsg() { - return this.errorMsg; - } - - public void setErrorMsg(String errorMsg) { - this.errorMsg = errorMsg; - } - - public String getJson() { - return this.json; - } - - public void setJson(String json) { - this.json = json; - } - @Override public String toString() { if (this.json != null) { @@ -59,26 +35,4 @@ public String toString() { return "错误: Code=" + this.errorCode + ", Msg=" + this.errorMsg; } - public static class Builder { - private int errorCode; - private String errorMsg; - - public Builder setErrorCode(int errorCode) { - this.errorCode = errorCode; - return this; - } - - public Builder setErrorMsg(String errorMsg) { - this.errorMsg = errorMsg; - return this; - } - - public WxError build() { - WxError wxError = new WxError(); - wxError.setErrorCode(this.errorCode); - wxError.setErrorMsg(this.errorMsg); - return wxError; - } - - } } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMediaUploadResult.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMediaUploadResult.java index 706de712c7..a50018aaef 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMediaUploadResult.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMediaUploadResult.java @@ -1,11 +1,12 @@ package me.chanjar.weixin.common.bean.result; +import lombok.Data; +import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.common.util.json.WxGsonBuilder; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; import java.io.Serializable; +@Data public class WxMediaUploadResult implements Serializable { private static final long serialVersionUID = 330834334738622341L; @@ -18,41 +19,9 @@ public static WxMediaUploadResult fromJson(String json) { return WxGsonBuilder.create().fromJson(json, WxMediaUploadResult.class); } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } - - public long getCreatedAt() { - return this.createdAt; - } - - public void setCreatedAt(long createdAt) { - this.createdAt = createdAt; - } - - public String getThumbMediaId() { - return this.thumbMediaId; - } - - public void setThumbMediaId(String thumbMediaId) { - this.thumbMediaId = thumbMediaId; - } - @Override public String toString() { - return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); + return ToStringUtils.toSimpleString(this); } } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/BeanUtils.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/BeanUtils.java index 630821e954..12ce3a4e13 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/BeanUtils.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/BeanUtils.java @@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory; import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -20,8 +21,9 @@ *
  * bean操作的一些工具类
  * Created by Binary Wang on 2016-10-21.
- * @author binarywang(Binary Wang)
  * 
+ * + * @author binarywang(Binary Wang) */ public class BeanUtils { private static Logger log = LoggerFactory.getLogger(BeanUtils.class); @@ -42,22 +44,27 @@ public static void checkRequiredFields(Object bean) throws WxErrorException { boolean isAccessible = field.isAccessible(); field.setAccessible(true); if (field.isAnnotationPresent(Required.class)) { - if (field.get(bean) == null || (field.get(bean) instanceof String && StringUtils.isBlank(field.get(bean).toString()))) { - //两种情况,一种是值为null,另外一种情况是类型为字符串,但是字符串内容为空的,都认为是没有提供值 + // 两种情况,一种是值为null, + // 另外一种情况是类型为字符串,但是字符串内容为空的,都认为是没有提供值 + boolean isRequiredMissing = field.get(bean) == null + || (field.get(bean) instanceof String + && StringUtils.isBlank(field.get(bean).toString()) + ); + if (isRequiredMissing) { requiredFields.add(field.getName()); } } field.setAccessible(isAccessible); } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { - e.printStackTrace(); + log.error(e.getMessage(), e); } } if (!requiredFields.isEmpty()) { String msg = "必填字段 " + requiredFields + " 必须提供值"; log.debug(msg); - throw new WxErrorException(WxError.newBuilder().setErrorMsg(msg).build()); + throw new WxErrorException(WxError.builder().errorMsg(msg).build()); } } @@ -82,11 +89,14 @@ public static Map xmlBean2Map(Object bean) { if (field.isAnnotationPresent(XStreamAlias.class)) { result.put(field.getAnnotation(XStreamAlias.class).value(), field.get(bean).toString()); + } else if (!Modifier.isStatic(field.getModifiers())) { + //忽略掉静态成员变量 + result.put(field.getName(), field.get(bean).toString()); } field.setAccessible(isAccessible); } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { - e.printStackTrace(); + log.error(e.getMessage(), e); } } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/ToStringUtils.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/ToStringUtils.java index 333e484a8f..a0b069d166 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/ToStringUtils.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/ToStringUtils.java @@ -8,8 +8,9 @@ *
  * 自定义的ToString方法,用于产生去掉空值属性的字符串
  * Created by Binary Wang on 2016-10-27.
- * @author binarywang(Binary Wang)
  * 
+ * + * @author Binary Wang */ public class ToStringUtils { public static final ToStringStyle THE_STYLE = new SimpleMultiLineToStringStyle(); diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/ByteGroup.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/ByteGroup.java index b12ec65555..bff08d680d 100755 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/ByteGroup.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/ByteGroup.java @@ -1,26 +1,26 @@ -package me.chanjar.weixin.common.util.crypto; - -import java.util.ArrayList; - -public class ByteGroup { - ArrayList byteContainer = new ArrayList<>(); - - public byte[] toBytes() { - byte[] bytes = new byte[this.byteContainer.size()]; - for (int i = 0; i < this.byteContainer.size(); i++) { - bytes[i] = this.byteContainer.get(i); - } - return bytes; - } - - public ByteGroup addBytes(byte[] bytes) { - for (byte b : bytes) { - this.byteContainer.add(b); - } - return this; - } - - public int size() { - return this.byteContainer.size(); - } -} +package me.chanjar.weixin.common.util.crypto; + +import java.util.ArrayList; + +public class ByteGroup { + ArrayList byteContainer = new ArrayList<>(); + + public byte[] toBytes() { + byte[] bytes = new byte[this.byteContainer.size()]; + for (int i = 0; i < this.byteContainer.size(); i++) { + bytes[i] = this.byteContainer.get(i); + } + return bytes; + } + + public ByteGroup addBytes(byte[] bytes) { + for (byte b : bytes) { + this.byteContainer.add(b); + } + return this; + } + + public int size() { + return this.byteContainer.size(); + } +} diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/PKCS7Encoder.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/PKCS7Encoder.java index 145896a577..8ce94cbac0 100755 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/PKCS7Encoder.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/PKCS7Encoder.java @@ -1,68 +1,68 @@ -/** - * 对公众平台发送给公众账号的消息加解密示例代码. - * - * @copyright Copyright (c) 1998-2014 Tencent Inc. - */ - -// ------------------------------------------------------------------------ - -package me.chanjar.weixin.common.util.crypto; - -import java.nio.charset.Charset; -import java.util.Arrays; - -/** - * 提供基于PKCS7算法的加解 - */ -public class PKCS7Encoder { - - private static final Charset CHARSET = Charset.forName("utf-8"); - private static final int BLOCK_SIZE = 32; - - /** - * 获得对明文进行补位填充的字节. - * - * @param count 需要进行填充补位操作的明文字节个数 - * @return 补齐用的字节数组 - */ - public static byte[] encode(int count) { - // 计算需要填充的位数 - int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE); - if (amountToPad == 0) { - amountToPad = BLOCK_SIZE; - } - // 获得补位所用的字符 - char padChr = chr(amountToPad); - String tmp = new String(); - for (int index = 0; index < amountToPad; index++) { - tmp += padChr; - } - return tmp.getBytes(CHARSET); - } - - /** - * 删除解密后明文的补位字符 - * - * @param decrypted 解密后的明文 - * @return 删除补位字符后的明文 - */ - public static byte[] decode(byte[] decrypted) { - int pad = decrypted[decrypted.length - 1]; - if (pad < 1 || pad > 32) { - pad = 0; - } - return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad); - } - - /** - * 将数字转化成ASCII码对应的字符,用于对明文进行补码 - * - * @param a 需要转化的数字 - * @return 转化得到的字符 - */ - public static char chr(int a) { - byte target = (byte) (a & 0xFF); - return (char) target; - } - -} +/** + * 对公众平台发送给公众账号的消息加解密示例代码. + * + * @copyright Copyright (c) 1998-2014 Tencent Inc. + */ + +// ------------------------------------------------------------------------ + +package me.chanjar.weixin.common.util.crypto; + +import java.nio.charset.Charset; +import java.util.Arrays; + +/** + * 提供基于PKCS7算法的加解 + */ +public class PKCS7Encoder { + + private static final Charset CHARSET = Charset.forName("utf-8"); + private static final int BLOCK_SIZE = 32; + + /** + * 获得对明文进行补位填充的字节. + * + * @param count 需要进行填充补位操作的明文字节个数 + * @return 补齐用的字节数组 + */ + public static byte[] encode(int count) { + // 计算需要填充的位数 + int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE); + if (amountToPad == 0) { + amountToPad = BLOCK_SIZE; + } + // 获得补位所用的字符 + char padChr = chr(amountToPad); + String tmp = new String(); + for (int index = 0; index < amountToPad; index++) { + tmp += padChr; + } + return tmp.getBytes(CHARSET); + } + + /** + * 删除解密后明文的补位字符 + * + * @param decrypted 解密后的明文 + * @return 删除补位字符后的明文 + */ + public static byte[] decode(byte[] decrypted) { + int pad = decrypted[decrypted.length - 1]; + if (pad < 1 || pad > 32) { + pad = 0; + } + return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad); + } + + /** + * 将数字转化成ASCII码对应的字符,用于对明文进行补码 + * + * @param a 需要转化的数字 + * @return 转化得到的字符 + */ + public static char chr(int a) { + byte target = (byte) (a & 0xFF); + return (char) target; + } + +} diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/fs/FileUtils.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/fs/FileUtils.java index df031b3371..9d24d6d3f5 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/fs/FileUtils.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/fs/FileUtils.java @@ -1,52 +1,37 @@ package me.chanjar.weixin.common.util.fs; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Files; public class FileUtils { - /** * 创建临时文件 * - * @param inputStream + * @param inputStream 输入文件流 * @param name 文件名 * @param ext 扩展名 * @param tmpDirFile 临时文件夹目录 */ public static File createTmpFile(InputStream inputStream, String name, String ext, File tmpDirFile) throws IOException { - File tmpFile; - if (tmpDirFile == null) { - tmpFile = File.createTempFile(name, '.' + ext); - } else { - tmpFile = File.createTempFile(name, '.' + ext, tmpDirFile); - } - - tmpFile.deleteOnExit(); - - try (FileOutputStream fos = new FileOutputStream(tmpFile)) { - int read = 0; - byte[] bytes = new byte[1024 * 100]; - while ((read = inputStream.read(bytes)) != -1) { - fos.write(bytes, 0, read); - } + File resultFile = File.createTempFile(name, '.' + ext, tmpDirFile); - fos.flush(); - return tmpFile; - } + resultFile.deleteOnExit(); + org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, resultFile); + return resultFile; } /** * 创建临时文件 * - * @param inputStream + * @param inputStream 输入文件流 * @param name 文件名 * @param ext 扩展名 */ public static File createTmpFile(InputStream inputStream, String name, String ext) throws IOException { - return createTmpFile(inputStream, name, ext, null); + return createTmpFile(inputStream, name, ext, Files.createTempDirectory("weixin-java-tools-temp").toFile()); } } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/BaseMediaDownloadRequestExecutor.java similarity index 85% rename from weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/BaseMediaDownloadRequestExecutor.java index d948859748..990e162008 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/BaseMediaDownloadRequestExecutor.java @@ -12,11 +12,11 @@ * * @author Daniel Qian */ -public abstract class MediaDownloadRequestExecutor implements RequestExecutor { - +public abstract class BaseMediaDownloadRequestExecutor implements RequestExecutor { protected RequestHttp requestHttp; protected File tmpDirFile; - public MediaDownloadRequestExecutor(RequestHttp requestHttp, File tmpDirFile) { + + public BaseMediaDownloadRequestExecutor(RequestHttp requestHttp, File tmpDirFile) { this.requestHttp = requestHttp; this.tmpDirFile = tmpDirFile; } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/HttpResponseProxy.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/HttpResponseProxy.java index a75aa963e0..37efdaaf38 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/HttpResponseProxy.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/HttpResponseProxy.java @@ -19,6 +19,8 @@ * @author Binary Wang */ public class HttpResponseProxy { + private static final Pattern PATTERN = Pattern.compile(".*filename=\"(.*)\""); + private CloseableHttpResponse apacheHttpResponse; private HttpResponse joddHttpResponse; private Response okHttpResponse; @@ -56,7 +58,7 @@ public String getFileName() throws WxErrorException { private String getFileName(CloseableHttpResponse response) throws WxErrorException { Header[] contentDispositionHeader = response.getHeaders("Content-disposition"); if (contentDispositionHeader == null || contentDispositionHeader.length == 0) { - throw new WxErrorException(WxError.newBuilder().setErrorMsg("无法获取到文件名").build()); + throw new WxErrorException(WxError.builder().errorMsg("无法获取到文件名").build()); } return this.extractFileNameFromContentString(contentDispositionHeader[0].getValue()); @@ -74,15 +76,15 @@ private String getFileName(Response response) throws WxErrorException { private String extractFileNameFromContentString(String content) throws WxErrorException { if (content == null || content.length() == 0) { - throw new WxErrorException(WxError.newBuilder().setErrorMsg("无法获取到文件名").build()); + throw new WxErrorException(WxError.builder().errorMsg("无法获取到文件名").build()); } - Pattern p = Pattern.compile(".*filename=\"(.*)\""); - Matcher m = p.matcher(content); + Matcher m = PATTERN.matcher(content); if (m.matches()) { return m.group(1); } - throw new WxErrorException(WxError.newBuilder().setErrorMsg("无法获取到文件名").build()); + + throw new WxErrorException(WxError.builder().errorMsg("无法获取到文件名").build()); } } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheHttpClientBuilder.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheHttpClientBuilder.java index 939b624785..fcd56c48a7 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheHttpClientBuilder.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheHttpClientBuilder.java @@ -4,51 +4,41 @@ import org.apache.http.impl.client.CloseableHttpClient; /** - * httpclient build interface + * httpclient build interface. * * @author kakotor */ public interface ApacheHttpClientBuilder { /** - * 构建httpclient实例 + * 构建httpclient实例. * * @return new instance of CloseableHttpClient */ CloseableHttpClient build(); /** - * 代理服务器地址 - * - * @param httpProxyHost + * 代理服务器地址. */ ApacheHttpClientBuilder httpProxyHost(String httpProxyHost); /** - * 代理服务器端口 - * - * @param httpProxyPort + * 代理服务器端口. */ ApacheHttpClientBuilder httpProxyPort(int httpProxyPort); /** - * 代理服务器用户名 - * - * @param httpProxyUsername + * 代理服务器用户名. */ ApacheHttpClientBuilder httpProxyUsername(String httpProxyUsername); /** - * 代理服务器密码 - * - * @param httpProxyPassword + * 代理服务器密码. */ ApacheHttpClientBuilder httpProxyPassword(String httpProxyPassword); /** - * ssl连接socket工厂 - * - * @param sslConnectionSocketFactory + * ssl连接socket工厂. */ ApacheHttpClientBuilder sslConnectionSocketFactory(SSLConnectionSocketFactory sslConnectionSocketFactory); } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheHttpDnsClientBuilder.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheHttpDnsClientBuilder.java index d3e5a1c167..b99b09fb8f 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheHttpDnsClientBuilder.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheHttpDnsClientBuilder.java @@ -29,9 +29,8 @@ import java.util.concurrent.atomic.AtomicBoolean; /** - * httpclient 连接管理器 自带DNS解析 - *

- * 大部分代码拷贝自:DefaultApacheHttpClientBuilder + * httpclient 连接管理器 自带DNS解析. + *

大部分代码拷贝自:DefaultApacheHttpClientBuilder

* * @author Andy.Huo */ @@ -64,7 +63,7 @@ public boolean retryRequest(IOException exception, int executionCount, HttpConte private String httpProxyPassword; /** - * 闲置连接监控线程 + * 闲置连接监控线程. */ private IdleConnectionMonitorThread idleConnectionMonitorThread; private HttpClientBuilder httpClientBuilder; @@ -162,7 +161,7 @@ public void setCheckWaitTime(int checkWaitTime) { } /** - * 每路的最大链接数,默认10 + * 每路的最大链接数,默认10. * * @param maxConnPerHost 每路的最大链接数,默认10 */ @@ -171,7 +170,7 @@ public void setMaxConnPerHost(int maxConnPerHost) { } /** - * 最大总连接数,默认50 + * 最大总连接数,默认50. * * @param maxTotalConn 最大总连接数,默认50 */ @@ -180,7 +179,7 @@ public void setMaxTotalConn(int maxTotalConn) { } /** - * 自定义httpclient的User Agent + * 自定义httpclient的User Agent. * * @param userAgent User Agent */ @@ -196,9 +195,12 @@ private synchronized void prepare() { if (prepared.get()) { return; } - Registry registry = RegistryBuilder.create() - .register("http", this.plainConnectionSocketFactory).register("https", this.sslConnectionSocketFactory) - .build(); + + Registry registry = + RegistryBuilder.create() + .register("http", this.plainConnectionSocketFactory) + .register("https", this.sslConnectionSocketFactory) + .build(); @SuppressWarnings("resource") PoolingHttpClientConnectionManager connectionManager; @@ -219,8 +221,8 @@ private synchronized void prepare() { connectionManager .setDefaultSocketConfig(SocketConfig.copy(SocketConfig.DEFAULT).setSoTimeout(this.soTimeout).build()); - this.idleConnectionMonitorThread = new IdleConnectionMonitorThread(connectionManager, this.idleConnTimeout, - this.checkWaitTime); + this.idleConnectionMonitorThread = new IdleConnectionMonitorThread( + connectionManager, this.idleConnTimeout, this.checkWaitTime); this.idleConnectionMonitorThread.setDaemon(true); this.idleConnectionMonitorThread.start(); @@ -234,8 +236,8 @@ private synchronized void prepare() { if (StringUtils.isNotBlank(this.httpProxyHost) && StringUtils.isNotBlank(this.httpProxyUsername)) { // 使用代理服务器 需要用户认证的代理服务器 CredentialsProvider provider = new BasicCredentialsProvider(); - provider.setCredentials(new AuthScope(this.httpProxyHost, this.httpProxyPort), - new UsernamePasswordCredentials(this.httpProxyUsername, this.httpProxyPassword)); + provider.setCredentials(new AuthScope(this.httpProxyHost, this.httpProxyPort) + , new UsernamePasswordCredentials(this.httpProxyUsername, this.httpProxyPassword)); this.httpClientBuilder.setDefaultCredentialsProvider(provider); } @@ -267,8 +269,10 @@ public static class IdleConnectionMonitorThread extends Thread { private final int checkWaitTime; private volatile boolean shutdown; - public IdleConnectionMonitorThread(HttpClientConnectionManager connMgr, int idleConnTimeout, - int checkWaitTime) { + /** + * 构造方法. + */ + public IdleConnectionMonitorThread(HttpClientConnectionManager connMgr, int idleConnTimeout, int checkWaitTime) { super("IdleConnectionMonitorThread"); this.connMgr = connMgr; this.idleConnTimeout = idleConnTimeout; @@ -289,12 +293,18 @@ public void run() { } } + /** + * 触发. + */ public void trigger() { synchronized (this) { notifyAll(); } } + /** + * 关闭. + */ public void shutdown() { this.shutdown = true; synchronized (this) { diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheMediaDownloadRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheMediaDownloadRequestExecutor.java index 0a5a504873..be2d91b84f 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheMediaDownloadRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheMediaDownloadRequestExecutor.java @@ -4,7 +4,7 @@ import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; import me.chanjar.weixin.common.util.http.HttpResponseProxy; -import me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor; +import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; @@ -23,7 +23,7 @@ /** * Created by ecoolper on 2017/5/5. */ -public class ApacheMediaDownloadRequestExecutor extends MediaDownloadRequestExecutor { +public class ApacheMediaDownloadRequestExecutor extends BaseMediaDownloadRequestExecutor { public ApacheMediaDownloadRequestExecutor(RequestHttp requestHttp, File tmpDirFile) { super(requestHttp, tmpDirFile); diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheSimplePostRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheSimplePostRequestExecutor.java index cc85fa76d7..1a8a292b9f 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheSimplePostRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheSimplePostRequestExecutor.java @@ -39,9 +39,7 @@ public String execute(String uri, String postEntity) throws WxErrorException, IO try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) { String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); if (responseContent.isEmpty()) { - throw new WxErrorException( - WxError.newBuilder().setErrorCode(9999).setErrorMsg("无响应内容") - .build()); + throw new WxErrorException(WxError.builder().errorCode(9999).errorMsg("无响应内容").build()); } if (responseContent.startsWith("")) { diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMediaDownloadRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMediaDownloadRequestExecutor.java index bbd8bec47c..f3442aaa6d 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMediaDownloadRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMediaDownloadRequestExecutor.java @@ -9,7 +9,7 @@ import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; import me.chanjar.weixin.common.util.http.HttpResponseProxy; -import me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor; +import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; @@ -22,7 +22,7 @@ /** * Created by ecoolper on 2017/5/5. */ -public class JoddHttpMediaDownloadRequestExecutor extends MediaDownloadRequestExecutor { +public class JoddHttpMediaDownloadRequestExecutor extends BaseMediaDownloadRequestExecutor { public JoddHttpMediaDownloadRequestExecutor(RequestHttp requestHttp, File tmpDirFile) { super(requestHttp, tmpDirFile); diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpSimplePostRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpSimplePostRequestExecutor.java index 8fa349c67a..57207f1b3e 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpSimplePostRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpSimplePostRequestExecutor.java @@ -5,7 +5,6 @@ import jodd.http.HttpResponse; import jodd.http.ProxyInfo; import jodd.util.StringPool; - import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; @@ -40,9 +39,8 @@ public String execute(String uri, String postEntity) throws WxErrorException, IO String responseContent = response.bodyText(); if (responseContent.isEmpty()) { - throw new WxErrorException( - WxError.newBuilder().setErrorCode(9999).setErrorMsg("无响应内容") - .build()); + throw new WxErrorException(WxError.builder().errorCode(9999).errorMsg("无响应内容") + .build()); } if (responseContent.startsWith("")) { diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpMediaDownloadRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpMediaDownloadRequestExecutor.java index 0923527b71..80f8199296 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpMediaDownloadRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpMediaDownloadRequestExecutor.java @@ -2,8 +2,8 @@ import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor; import me.chanjar.weixin.common.util.http.HttpResponseProxy; -import me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -21,7 +21,7 @@ /** * Created by ecoolper on 2017/5/5. */ -public class OkHttpMediaDownloadRequestExecutor extends MediaDownloadRequestExecutor { +public class OkHttpMediaDownloadRequestExecutor extends BaseMediaDownloadRequestExecutor { private final Logger logger = LoggerFactory.getLogger(this.getClass()); public OkHttpMediaDownloadRequestExecutor(RequestHttp requestHttp, File tmpDirFile) { diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxErrorAdapter.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxErrorAdapter.java index cc426bc8ca..abd0da6052 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxErrorAdapter.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxErrorAdapter.java @@ -14,23 +14,26 @@ import java.lang.reflect.Type; /** - * @author Daniel Qian + * @author Daniel Qian. */ public class WxErrorAdapter implements JsonDeserializer { @Override - public WxError deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - WxError wxError = new WxError(); + public WxError deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + WxError.WxErrorBuilder errorBuilder = WxError.builder(); JsonObject wxErrorJsonObject = json.getAsJsonObject(); if (wxErrorJsonObject.get("errcode") != null && !wxErrorJsonObject.get("errcode").isJsonNull()) { - wxError.setErrorCode(GsonHelper.getAsPrimitiveInt(wxErrorJsonObject.get("errcode"))); + errorBuilder.errorCode(GsonHelper.getAsPrimitiveInt(wxErrorJsonObject.get("errcode"))); } if (wxErrorJsonObject.get("errmsg") != null && !wxErrorJsonObject.get("errmsg").isJsonNull()) { - wxError.setErrorMsg(GsonHelper.getAsString(wxErrorJsonObject.get("errmsg"))); + errorBuilder.errorMsg(GsonHelper.getAsString(wxErrorJsonObject.get("errmsg"))); } - wxError.setJson(json.toString()); - return wxError; + + errorBuilder.json(json.toString()); + + return errorBuilder.build(); } } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java index c506c1ed75..31c3c0204c 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java @@ -70,6 +70,7 @@ protected JsonObject convertToJson(WxMenuRule menuRule) { return matchRule; } + @Deprecated private WxMenuRule convertToRule(JsonObject json) { WxMenuRule menuRule = new WxMenuRule(); //变态的微信接口,这里居然反人类的使用和序列化时不一样的名字 diff --git a/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxErrorTest.java b/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxErrorTest.java index 477fcdabc0..1c05ea731e 100644 --- a/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxErrorTest.java +++ b/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxErrorTest.java @@ -8,7 +8,6 @@ public class WxErrorTest { public void testFromJson() { - String json = "{ \"errcode\": 40003, \"errmsg\": \"invalid openid\" }"; WxError wxError = WxError.fromJson(json); Assert.assertTrue(wxError.getErrorCode() == 40003); diff --git a/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/crypto/SHA1Test.java b/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/crypto/SHA1Test.java index 323fc7060e..ffdb613128 100644 --- a/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/crypto/SHA1Test.java +++ b/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/crypto/SHA1Test.java @@ -10,7 +10,7 @@ * Created by BinaryWang on 2017/6/10. *
* - * @author binarywang(Binary Wang) + * @author Binary Wang */ public class SHA1Test { @Test diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index 233a94ecc3..f589bbe003 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -7,7 +7,7 @@ com.github.binarywang weixin-java-parent - 2.8.0 + 2.9.0 weixin-java-cp diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImpl.java index 1364550aac..706ba2e01d 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImpl.java @@ -3,7 +3,7 @@ import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; -import me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor; +import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor; import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; import me.chanjar.weixin.cp.api.WxCpMediaService; import me.chanjar.weixin.cp.api.WxCpService; @@ -43,7 +43,7 @@ public WxMediaUploadResult upload(String mediaType, File file) throws WxErrorExc public File download(String mediaId) throws WxErrorException { String url = "https://qyapi.weixin.qq.com/cgi-bin/media/get"; return this.mainService.execute( - MediaDownloadRequestExecutor.create(this.mainService.getRequestHttp(), + BaseMediaDownloadRequestExecutor.create(this.mainService.getRequestHttp(), this.mainService.getWxCpConfigStorage().getTmpDirFile()), url, "media_id=" + mediaId); } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceAbstractImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceAbstractImpl.java index 83bc5e13c6..aac09e342b 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceAbstractImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceAbstractImpl.java @@ -381,7 +381,7 @@ public T execute(RequestExecutor executor, String uri, E data) thro throw new RuntimeException("微信服务端异常,超出重试次数"); } - protected synchronized T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException { + protected T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException { if (uri.contains("access_token=")) { throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri); } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceImpl.java index ff8e149c77..a7538c6ead 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceImpl.java @@ -4,8 +4,9 @@ *
  *  默认接口实现类,使用apache httpclient实现
  * Created by Binary Wang on 2017-5-27.
- * @author binarywang(Binary Wang)
  * 
+ * + * @author Binary Wang */ public class WxCpServiceImpl extends WxCpServiceApacheHttpClientImpl { } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java index f8476ff5af..af9219cfe8 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java @@ -7,14 +7,10 @@ import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo; import me.chanjar.weixin.cp.config.WxCpConfigStorage; import okhttp3.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; public class WxCpServiceOkHttpImpl extends WxCpServiceAbstractImpl { - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - protected OkHttpClient httpClient; protected OkHttpProxyInfo httpProxy; @@ -36,7 +32,7 @@ public HttpType getRequestType() { @Override public String getAccessToken(boolean forceRefresh) throws WxErrorException { - logger.debug("WxCpServiceOkHttpImpl is running"); + this.log.debug("WxCpServiceOkHttpImpl is running"); if (this.configStorage.isAccessTokenExpired() || forceRefresh) { synchronized (this.globalAccessTokenRefreshLock) { if (this.configStorage.isAccessTokenExpired()) { @@ -47,18 +43,14 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException { OkHttpClient client = getRequestHttpClient(); //请求的request Request request = new Request.Builder().url(url).get().build(); - Response response = null; - try { - response = client.newCall(request).execute(); - } catch (IOException e) { - e.printStackTrace(); - } String resultContent = null; try { + Response response = client.newCall(request).execute(); resultContent = response.body().string(); } catch (IOException e) { - e.printStackTrace(); + this.log.error(e.getMessage(), e); } + WxError error = WxError.fromJson(resultContent); if (error.getErrorCode() != 0) { throw new WxErrorException(error); @@ -74,9 +66,16 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException { @Override public void initHttp() { - logger.debug("WxCpServiceOkHttpImpl initHttp"); - OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder(); + this.log.debug("WxCpServiceOkHttpImpl initHttp"); //设置代理 + if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) { + httpProxy = OkHttpProxyInfo.httpProxy(configStorage.getHttpProxyHost(), + configStorage.getHttpProxyPort(), + configStorage.getHttpProxyUsername(), + configStorage.getHttpProxyPassword()); + } + + OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder(); if (httpProxy != null) { clientBuilder.proxy(getRequestHttpProxy().getProxy()); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java index 118c500488..2890ce61eb 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java @@ -1,69 +1,30 @@ package me.chanjar.weixin.cp.bean; +import lombok.Data; import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; import java.io.Serializable; /** - * 微信部门 + * 微信部门. * * @author Daniel Qian */ +@Data public class WxCpDepart implements Serializable { private static final long serialVersionUID = -5028321625140879571L; private Integer id; private String name; private Integer parentId; - private Integer order; + private Long order; public static WxCpDepart fromJson(String json) { return WxCpGsonBuilder.create().fromJson(json, WxCpDepart.class); } - public Integer getId() { - return this.id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public Integer getParentId() { - return this.parentId; - } - - public void setParentId(Integer parentId) { - this.parentId = parentId; - } - - public Integer getOrder() { - return this.order; - } - - public void setOrder(Integer order) { - this.order = order; - } - public String toJson() { return WxCpGsonBuilder.create().toJson(this); } - @Override - public String toString() { - return "WxCpDepart{" + - "id=" + this.id + - ", name='" + this.name + '\'' + - ", parentId=" + this.parentId + - ", order=" + this.order + - '}'; - } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java index c59ca87e1f..403e9dc365 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java @@ -1,5 +1,7 @@ package me.chanjar.weixin.cp.bean; +import lombok.Data; +import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.cp.bean.article.MpnewsArticle; import me.chanjar.weixin.cp.bean.article.NewArticle; import me.chanjar.weixin.cp.bean.messagebuilder.*; @@ -10,13 +12,14 @@ import java.util.List; /** - * 消息 + * 消息. * * @author Daniel Qian */ +@Data public class WxCpMessage implements Serializable { - private static final long serialVersionUID = -2082278303476631708L; + private String toUser; private String toParty; private String toTag; @@ -35,115 +38,72 @@ public class WxCpMessage implements Serializable { private List mpnewsArticles = new ArrayList<>(); /** - * 获得文本消息builder + * 获得文本消息builder. */ public static TextBuilder TEXT() { return new TextBuilder(); } /** - * 获得文本卡片消息builder + * 获得文本卡片消息builder. */ public static TextCardBuilder TEXTCARD() { return new TextCardBuilder(); } /** - * 获得图片消息builder + * 获得图片消息builder. */ public static ImageBuilder IMAGE() { return new ImageBuilder(); } /** - * 获得语音消息builder + * 获得语音消息builder. */ public static VoiceBuilder VOICE() { return new VoiceBuilder(); } /** - * 获得视频消息builder + * 获得视频消息builder. */ public static VideoBuilder VIDEO() { return new VideoBuilder(); } /** - * 获得图文消息builder + * 获得图文消息builder. */ public static NewsBuilder NEWS() { return new NewsBuilder(); } /** - * 获得mpnews图文消息builder + * 获得mpnews图文消息builder. */ public static MpnewsBuilder MPNEWS() { return new MpnewsBuilder(); } /** - * 获得文件消息builder + * 获得文件消息builder. */ public static FileBuilder FILE() { return new FileBuilder(); } - public List getMpnewsArticles() { - return mpnewsArticles; - } - - public void setMpnewsArticles(List mpnewsArticles) { - this.mpnewsArticles = mpnewsArticles; - } - - public String getToUser() { - return this.toUser; - } - - public void setToUser(String toUser) { - this.toUser = toUser; - } - - public String getToParty() { - return this.toParty; - } - - public void setToParty(String toParty) { - this.toParty = toParty; - } - - public String getToTag() { - return this.toTag; - } - - public void setToTag(String toTag) { - this.toTag = toTag; - } - - public Integer getAgentId() { - return this.agentId; - } - - public void setAgentId(Integer agentId) { - this.agentId = agentId; - } - - public String getMsgType() { - return this.msgType; - } /** *
    * 请使用
-   * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_TEXT}
-   * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_IMAGE}
-   * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_VOICE}
-   * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_MUSIC}
-   * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_VIDEO}
-   * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_NEWS}
-   * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_MPNEWS}
+   * {@link WxConsts.KefuMsgType#TEXT}
+   * {@link WxConsts.KefuMsgType#IMAGE}
+   * {@link WxConsts.KefuMsgType#VOICE}
+   * {@link WxConsts.KefuMsgType#MUSIC}
+   * {@link WxConsts.KefuMsgType#VIDEO}
+   * {@link WxConsts.KefuMsgType#NEWS}
+   * {@link WxConsts.KefuMsgType#MPNEWS}
    * 
* * @param msgType 消息类型 @@ -152,87 +112,8 @@ public void setMsgType(String msgType) { this.msgType = msgType; } - public String getSafe() { - return this.safe; - } - - public void setSafe(String safe) { - this.safe = safe; - } - - public String getContent() { - return this.content; - } - - public void setContent(String content) { - this.content = content; - } - - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } - - public String getThumbMediaId() { - return this.thumbMediaId; - } - - public void setThumbMediaId(String thumbMediaId) { - this.thumbMediaId = thumbMediaId; - } - - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getMusicUrl() { - return this.musicUrl; - } - - public void setMusicUrl(String musicUrl) { - this.musicUrl = musicUrl; - } - - public String getHqMusicUrl() { - return this.hqMusicUrl; - } - - public void setHqMusicUrl(String hqMusicUrl) { - this.hqMusicUrl = hqMusicUrl; - } - - public List getArticles() { - return this.articles; - } - - public void setArticles(List articles) { - this.articles = articles; - } - public String toJson() { return WxCpGsonBuilder.INSTANCE.create().toJson(this); } - public String getUrl() { - return this.url; - } - - public void setUrl(String url) { - this.url = url; - } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessageSendResult.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessageSendResult.java index 6989c4988f..e54a01eccd 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessageSendResult.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessageSendResult.java @@ -2,21 +2,25 @@ import com.google.common.base.Splitter; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; import org.apache.commons.lang3.StringUtils; +import java.io.Serializable; import java.util.Collections; import java.util.List; /** - *
- * 消息发送结果对象类
+ * 消息发送结果对象类.
  * Created by Binary Wang on 2017-6-22.
+ *
  * @author Binary Wang
- * 
*/ -public class WxCpMessageSendResult { +@Data +public class WxCpMessageSendResult implements Serializable { + private static final long serialVersionUID = 916455987193190004L; + @Override public String toString() { return ToStringUtils.toSimpleString(this); @@ -41,52 +45,13 @@ public static WxCpMessageSendResult fromJson(String json) { @SerializedName("invalidtag") private String invalidTag; - public Integer getErrCode() { - return this.errCode; - } - - public void setErrCode(Integer errCode) { - this.errCode = errCode; - } - - public String getErrMsg() { - return this.errMsg; - } - - public void setErrMsg(String errMsg) { - this.errMsg = errMsg; - } - - public String getInvalidUser() { - return this.invalidUser; - } - - public void setInvalidUser(String invalidUser) { - this.invalidUser = invalidUser; - } - - public String getInvalidParty() { - return this.invalidParty; - } - - public void setInvalidParty(String invalidParty) { - this.invalidParty = invalidParty; - } - - public String getInvalidTag() { - return this.invalidTag; - } - - public void setInvalidTag(String invalidTag) { - this.invalidTag = invalidTag; - } public List getInvalidUserList() { return this.content2List(this.invalidUser); } private List content2List(String content) { - if(StringUtils.isBlank(content)){ + if (StringUtils.isBlank(content)) { return Collections.emptyList(); } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java index 79ec3f1321..360ddd28be 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java @@ -1,50 +1,30 @@ package me.chanjar.weixin.cp.bean; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; import java.io.Serializable; /** - * Created by Daniel Qian + * Created by Daniel Qian. */ +@Data +@AllArgsConstructor +@NoArgsConstructor public class WxCpTag implements Serializable { - private static final long serialVersionUID = -7243320279646928402L; private String id; private String name; - public WxCpTag() { - super(); - } - - public WxCpTag(String id, String name) { - super(); - this.id = id; - this.name = name; - } public static WxCpTag fromJson(String json) { return WxCpGsonBuilder.create().fromJson(json, WxCpTag.class); } - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public String getId() { - return this.id; - } - - public void setId(String id) { - this.id = id; - } - public String toJson() { return WxCpGsonBuilder.create().toJson(this); } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTagAddOrRemoveUsersResult.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTagAddOrRemoveUsersResult.java index c216ae46a6..3d89c073fc 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTagAddOrRemoveUsersResult.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTagAddOrRemoveUsersResult.java @@ -2,21 +2,25 @@ import com.google.common.base.Splitter; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; import org.apache.commons.lang3.StringUtils; +import java.io.Serializable; import java.util.Collections; import java.util.List; /** - *
- * 为标签添加或移除用户结果对象类
+ * 为标签添加或移除用户结果对象类.
  * Created by Binary Wang on 2017-6-22.
+ *
  * @author Binary Wang
- * 
*/ -public class WxCpTagAddOrRemoveUsersResult { +@Data +public class WxCpTagAddOrRemoveUsersResult implements Serializable { + private static final long serialVersionUID = 1420065684270213578L; + @Override public String toString() { return ToStringUtils.toSimpleString(this); @@ -38,44 +42,12 @@ public static WxCpTagAddOrRemoveUsersResult fromJson(String json) { @SerializedName("invalidparty") private String[] invalidParty; - public Integer getErrCode() { - return this.errCode; - } - - public void setErrCode(Integer errCode) { - this.errCode = errCode; - } - - public String getErrMsg() { - return this.errMsg; - } - - public void setErrMsg(String errMsg) { - this.errMsg = errMsg; - } - - public String getInvalidUser() { - return this.invalidUsers; - } - - public void setInvalidUser(String invalidUser) { - this.invalidUsers = invalidUser; - } - - public String[] getInvalidParty() { - return this.invalidParty; - } - - public void setInvalidParty(String[] invalidParty) { - this.invalidParty = invalidParty; - } - public List getInvalidUserList() { return this.content2List(this.invalidUsers); } private List content2List(String content) { - if(StringUtils.isBlank(content)){ + if (StringUtils.isBlank(content)) { return Collections.emptyList(); } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java index 647a4e6ba2..0a3aaeb7a7 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java @@ -1,5 +1,7 @@ package me.chanjar.weixin.cp.bean; +import lombok.AllArgsConstructor; +import lombok.Data; import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; import java.io.Serializable; @@ -7,12 +9,12 @@ import java.util.List; /** - * 微信用户信息 + * 微信用户信息. * * @author Daniel Qian */ +@Data public class WxCpUser implements Serializable { - public enum Gender { MALE("男", "1"), FEMAIL("女", "2"); @@ -62,159 +64,23 @@ public static Gender fromCode(String code) { private String englishName; private String telephone; - public static WxCpUser fromJson(String json) { - return WxCpGsonBuilder.INSTANCE.create().fromJson(json, WxCpUser.class); - } - - public String getUserId() { - return this.userId; - } - - public void setUserId(String userId) { - this.userId = userId; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public Integer[] getDepartIds() { - return this.departIds; - } - - public void setDepartIds(Integer[] departIds) { - this.departIds = departIds; - } - - public Gender getGender() { - return this.gender; - } - - public void setGender(Gender gender) { - this.gender = gender; - } - - public String getPosition() { - return this.position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getMobile() { - return this.mobile; - } - - public void setMobile(String mobile) { - this.mobile = mobile; - } - - public String getTelephone() { - return this.telephone; - } - - public void setTelephone(String telephone) { - this.telephone = telephone; - } - - public String getEmail() { - return this.email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getAvatar() { - return this.avatar; - } - - public void setAvatar(String avatar) { - this.avatar = avatar; - } - - public Integer getStatus() { - return this.status; - } - - public void setStatus(Integer status) { - this.status = status; - } - - public Integer getEnable() { - return this.enable; - } - - public void setEnable(Integer enable) { - this.enable = enable; - } - public void addExtAttr(String name, String value) { this.extAttrs.add(new Attr(name, value)); } - public List getExtAttrs() { - return this.extAttrs; - } - - public Integer getIsLeader() { - return isLeader; - } - - public void setIsLeader(Integer isLeader) { - this.isLeader = isLeader; - } - - public Integer getHideMobile() { - return hideMobile; - } - - public void setHideMobile(Integer hideMobile) { - this.hideMobile = hideMobile; - } - - public String getEnglishName() { - return englishName; - } - - public void setEnglishName(String englishName) { - this.englishName = englishName; + public static WxCpUser fromJson(String json) { + return WxCpGsonBuilder.INSTANCE.create().fromJson(json, WxCpUser.class); } public String toJson() { return WxCpGsonBuilder.INSTANCE.create().toJson(this); } + @Data + @AllArgsConstructor public static class Attr { private String name; private String value; - - public Attr(String name, String value) { - this.name = name; - this.value = value; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public String getValue() { - return this.value; - } - - public void setValue(String value) { - this.value = value; - } - } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java index 117cf4115b..785884a174 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java @@ -2,6 +2,9 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamConverter; +import lombok.Data; +import me.chanjar.weixin.common.api.WxConsts; +import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.common.util.xml.XStreamCDataConverter; import me.chanjar.weixin.cp.config.WxCpConfigStorage; import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil; @@ -26,6 +29,7 @@ * @author Daniel Qian */ @XStreamAlias("xml") +@Data public class WxCpXmlMessage implements Serializable { private static final long serialVersionUID = -1042994982179476410L; @@ -128,28 +132,29 @@ public class WxCpXmlMessage implements Serializable { // 群发消息返回的结果 /////////////////////////////////////// /** - * 群发的结果 + * 群发的结果. */ @XStreamAlias("Status") @XStreamConverter(value = XStreamCDataConverter.class) private String status; /** - * group_id下粉丝数;或者openid_list中的粉丝数 + * group_id下粉丝数;或者openid_list中的粉丝数. */ @XStreamAlias("TotalCount") private Integer totalCount; /** - * 过滤(过滤是指特定地区、性别的过滤、用户设置拒收的过滤,用户接收已超4条的过滤)后,准备发送的粉丝数,原则上,filterCount = sentCount + errorCount + * 过滤. + * (过滤是指特定地区、性别的过滤、用户设置拒收的过滤,用户接收已超4条的过滤)后,准备发送的粉丝数,原则上,filterCount = sentCount + errorCount */ @XStreamAlias("FilterCount") private Integer filterCount; /** - * 发送成功的粉丝数 + * 发送成功的粉丝数. */ @XStreamAlias("SentCount") private Integer sentCount; /** - * 发送失败的粉丝数 + * 发送失败的粉丝数. */ @XStreamAlias("ErrorCount") private Integer errorCount; @@ -174,13 +179,7 @@ protected static WxCpXmlMessage fromXml(InputStream is) { } /** - * 从加密字符串转换 - * - * @param encryptedXml - * @param wxCpConfigStorage - * @param timestamp - * @param nonce - * @param msgSignature + * 从加密字符串转换. */ public static WxCpXmlMessage fromEncryptedXml( String encryptedXml, @@ -202,40 +201,16 @@ public static WxCpXmlMessage fromEncryptedXml( } } - public Integer getAgentId() { - return this.agentId; - } - - public void setAgentId(Integer agentId) { - this.agentId = agentId; - } - - public String getToUserName() { - return this.toUserName; - } - - public void setToUserName(String toUserName) { - this.toUserName = toUserName; - } - - public Long getCreateTime() { - return this.createTime; - } - - public void setCreateTime(Long createTime) { - this.createTime = createTime; - } - /** *
    * 当接受用户消息时,可能会获得以下值:
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_TEXT}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_IMAGE}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_VOICE}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_VIDEO}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_LOCATION}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_LINK}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_EVENT}
+   * {@link WxConsts.XmlMsgType#TEXT}
+   * {@link WxConsts.XmlMsgType#IMAGE}
+   * {@link WxConsts.XmlMsgType#VOICE}
+   * {@link WxConsts.XmlMsgType#VIDEO}
+   * {@link WxConsts.XmlMsgType#LOCATION}
+   * {@link WxConsts.XmlMsgType#LINK}
+   * {@link WxConsts.XmlMsgType#EVENT}
    * 
*/ public String getMsgType() { @@ -245,363 +220,60 @@ public String getMsgType() { /** *
    * 当发送消息的时候使用:
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_TEXT}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_IMAGE}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_VOICE}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_VIDEO}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_NEWS}
+   * {@link WxConsts.XmlMsgType#TEXT}
+   * {@link WxConsts.XmlMsgType#IMAGE}
+   * {@link WxConsts.XmlMsgType#VOICE}
+   * {@link WxConsts.XmlMsgType#VIDEO}
+   * {@link WxConsts.XmlMsgType#NEWS}
    * 
- * - * @param msgType */ public void setMsgType(String msgType) { this.msgType = msgType; } - public String getContent() { - return this.content; - } - - public void setContent(String content) { - this.content = content; - } - - public Long getMsgId() { - return this.msgId; - } - - public void setMsgId(Long msgId) { - this.msgId = msgId; - } - - public String getPicUrl() { - return this.picUrl; - } - - public void setPicUrl(String picUrl) { - this.picUrl = picUrl; - } - - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } - - public String getFormat() { - return this.format; - } - - public void setFormat(String format) { - this.format = format; - } - - public String getThumbMediaId() { - return this.thumbMediaId; - } - - public void setThumbMediaId(String thumbMediaId) { - this.thumbMediaId = thumbMediaId; - } - - public Double getLocationX() { - return this.locationX; - } - - public void setLocationX(Double locationX) { - this.locationX = locationX; - } - - public Double getLocationY() { - return this.locationY; - } - - public void setLocationY(Double locationY) { - this.locationY = locationY; - } - - public Double getScale() { - return this.scale; - } - - public void setScale(Double scale) { - this.scale = scale; - } - - public String getLabel() { - return this.label; - } - - public void setLabel(String label) { - this.label = label; - } - - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getUrl() { - return this.url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getEvent() { - return this.event; - } - - public void setEvent(String event) { - this.event = event; - } - - public String getEventKey() { - return this.eventKey; - } - - public void setEventKey(String eventKey) { - this.eventKey = eventKey; - } - - public String getTicket() { - return this.ticket; - } - - public void setTicket(String ticket) { - this.ticket = ticket; - } - - public Double getLatitude() { - return this.latitude; - } - - public void setLatitude(Double latitude) { - this.latitude = latitude; - } - - public Double getLongitude() { - return this.longitude; - } - - public void setLongitude(Double longitude) { - this.longitude = longitude; - } - - public Double getPrecision() { - return this.precision; - } - - public void setPrecision(Double precision) { - this.precision = precision; - } - - public String getRecognition() { - return this.recognition; - } - - public void setRecognition(String recognition) { - this.recognition = recognition; - } - - public String getFromUserName() { - return this.fromUserName; - } - - public void setFromUserName(String fromUserName) { - this.fromUserName = fromUserName; - } - - public String getStatus() { - return this.status; - } - - public void setStatus(String status) { - this.status = status; - } - - public Integer getTotalCount() { - return this.totalCount; - } - - public void setTotalCount(Integer totalCount) { - this.totalCount = totalCount; - } - - public Integer getFilterCount() { - return this.filterCount; - } - - public void setFilterCount(Integer filterCount) { - this.filterCount = filterCount; - } - - public Integer getSentCount() { - return this.sentCount; - } - - public void setSentCount(Integer sentCount) { - this.sentCount = sentCount; - } - - public Integer getErrorCount() { - return this.errorCount; - } - - public void setErrorCount(Integer errorCount) { - this.errorCount = errorCount; - } - - public WxCpXmlMessage.ScanCodeInfo getScanCodeInfo() { - return this.scanCodeInfo; - } - - public void setScanCodeInfo(WxCpXmlMessage.ScanCodeInfo scanCodeInfo) { - this.scanCodeInfo = scanCodeInfo; - } - - public WxCpXmlMessage.SendPicsInfo getSendPicsInfo() { - return this.sendPicsInfo; - } - - public void setSendPicsInfo(WxCpXmlMessage.SendPicsInfo sendPicsInfo) { - this.sendPicsInfo = sendPicsInfo; - } - - public WxCpXmlMessage.SendLocationInfo getSendLocationInfo() { - return this.sendLocationInfo; - } - - public void setSendLocationInfo(WxCpXmlMessage.SendLocationInfo sendLocationInfo) { - this.sendLocationInfo = sendLocationInfo; - } - @Override public String toString() { - return "WxCpXmlMessage{" + - "agentId=" + this.agentId + - ", toUserName='" + this.toUserName + '\'' + - ", fromUserName='" + this.fromUserName + '\'' + - ", createTime=" + this.createTime + - ", msgType='" + this.msgType + '\'' + - ", content='" + this.content + '\'' + - ", msgId=" + this.msgId + - ", picUrl='" + this.picUrl + '\'' + - ", mediaId='" + this.mediaId + '\'' + - ", format='" + this.format + '\'' + - ", thumbMediaId='" + this.thumbMediaId + '\'' + - ", locationX=" + this.locationX + - ", locationY=" + this.locationY + - ", scale=" + this.scale + - ", label='" + this.label + '\'' + - ", title='" + this.title + '\'' + - ", description='" + this.description + '\'' + - ", url='" + this.url + '\'' + - ", event='" + this.event + '\'' + - ", eventKey='" + this.eventKey + '\'' + - ", ticket='" + this.ticket + '\'' + - ", latitude=" + this.latitude + - ", longitude=" + this.longitude + - ", precision=" + this.precision + - ", recognition='" + this.recognition + '\'' + - ", status='" + this.status + '\'' + - ", totalCount=" + this.totalCount + - ", filterCount=" + this.filterCount + - ", sentCount=" + this.sentCount + - ", errorCount=" + this.errorCount + - ", scanCodeInfo=" + this.scanCodeInfo + - ", sendPicsInfo=" + this.sendPicsInfo + - ", sendLocationInfo=" + this.sendLocationInfo + - '}'; + return ToStringUtils.toSimpleString(this); } + @Data @XStreamAlias("ScanCodeInfo") public static class ScanCodeInfo { + /** + * 扫描类型,一般是qrcode. + */ @XStreamAlias("ScanType") @XStreamConverter(value = XStreamCDataConverter.class) private String scanType; + /** + * 扫描结果,即二维码对应的字符串信息. + */ @XStreamAlias("ScanResult") @XStreamConverter(value = XStreamCDataConverter.class) private String scanResult; - - /** - * 扫描类型,一般是qrcode - */ - public String getScanType() { - - return this.scanType; - } - - public void setScanType(String scanType) { - this.scanType = scanType; - } - - /** - * 扫描结果,即二维码对应的字符串信息 - */ - public String getScanResult() { - return this.scanResult; - } - - public void setScanResult(String scanResult) { - this.scanResult = scanResult; - } - } + @Data @XStreamAlias("SendPicsInfo") public static class SendPicsInfo { - @XStreamAlias("PicList") protected final List picList = new ArrayList<>(); + @XStreamAlias("Count") private Long count; - public Long getCount() { - return this.count; - } - - public void setCount(Long count) { - this.count = count; - } - - public List getPicList() { - return this.picList; - } - @XStreamAlias("item") + @Data public static class Item { - @XStreamAlias("PicMd5Sum") @XStreamConverter(value = XStreamCDataConverter.class) - private String PicMd5Sum; - - public String getPicMd5Sum() { - return this.PicMd5Sum; - } - - public void setPicMd5Sum(String picMd5Sum) { - this.PicMd5Sum = picMd5Sum; - } + private String picMd5Sum; } } + @Data @XStreamAlias("SendLocationInfo") public static class SendLocationInfo { @@ -623,47 +295,8 @@ public static class SendLocationInfo { @XStreamAlias("Poiname") @XStreamConverter(value = XStreamCDataConverter.class) - private String poiname; - - public String getLocationX() { - return this.locationX; - } - - public void setLocationX(String locationX) { - this.locationX = locationX; - } - - public String getLocationY() { - return this.locationY; - } - - public void setLocationY(String locationY) { - this.locationY = locationY; - } + private String poiName; - public String getScale() { - return this.scale; - } - - public void setScale(String scale) { - this.scale = scale; - } - - public String getLabel() { - return this.label; - } - - public void setLabel(String label) { - this.label = label; - } - - public String getPoiname() { - return this.poiname; - } - - public void setPoiname(String poiname) { - this.poiname = poiname; - } } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessage.java index 2ddb78afc9..dc77875e7e 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessage.java @@ -2,10 +2,12 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamConverter; +import lombok.Data; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.util.xml.XStreamMediaIdConverter; @XStreamAlias("xml") +@Data public class WxCpXmlOutImageMessage extends WxCpXmlOutMessage { private static final long serialVersionUID = -1099446240667237313L; @@ -14,15 +16,7 @@ public class WxCpXmlOutImageMessage extends WxCpXmlOutMessage { private String mediaId; public WxCpXmlOutImageMessage() { - this.msgType = WxConsts.XML_MSG_IMAGE; - } - - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; + this.msgType = WxConsts.XmlMsgType.IMAGE; } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMessage.java index d69703502f..34c5499f06 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMessage.java @@ -2,6 +2,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamConverter; +import lombok.Data; import me.chanjar.weixin.common.util.xml.XStreamCDataConverter; import me.chanjar.weixin.cp.config.WxCpConfigStorage; import me.chanjar.weixin.cp.bean.outxmlbuilder.*; @@ -11,8 +12,8 @@ import java.io.Serializable; @XStreamAlias("xml") +@Data public abstract class WxCpXmlOutMessage implements Serializable { - private static final long serialVersionUID = 1418629839964153110L; @XStreamAlias("ToUserName") @@ -31,78 +32,46 @@ public abstract class WxCpXmlOutMessage implements Serializable { protected String msgType; /** - * 获得文本消息builder + * 获得文本消息builder. */ public static TextBuilder TEXT() { return new TextBuilder(); } /** - * 获得图片消息builder + * 获得图片消息builder. */ public static ImageBuilder IMAGE() { return new ImageBuilder(); } /** - * 获得语音消息builder + * 获得语音消息builder. */ public static VoiceBuilder VOICE() { return new VoiceBuilder(); } /** - * 获得视频消息builder + * 获得视频消息builder. */ public static VideoBuilder VIDEO() { return new VideoBuilder(); } /** - * 获得图文消息builder + * 获得图文消息builder. */ public static NewsBuilder NEWS() { return new NewsBuilder(); } - public String getToUserName() { - return this.toUserName; - } - - public void setToUserName(String toUserName) { - this.toUserName = toUserName; - } - - public String getFromUserName() { - return this.fromUserName; - } - - public void setFromUserName(String fromUserName) { - this.fromUserName = fromUserName; - } - - public Long getCreateTime() { - return this.createTime; - } - - public void setCreateTime(Long createTime) { - this.createTime = createTime; - } - - public String getMsgType() { - return this.msgType; - } - - public void setMsgType(String msgType) { - this.msgType = msgType; - } - protected String toXml() { return XStreamTransformer.toXml((Class) this.getClass(), this); } /** - * 转换成加密的xml格式 + * 转换成加密的xml格式. */ public String toEncryptedXml(WxCpConfigStorage wxCpConfigStorage) { String plainXml = toXml(); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessage.java index 0997841081..992397981f 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessage.java @@ -2,6 +2,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamConverter; +import lombok.Data; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.util.xml.XStreamCDataConverter; @@ -9,84 +10,46 @@ import java.util.List; @XStreamAlias("xml") +@Data public class WxCpXmlOutNewsMessage extends WxCpXmlOutMessage { private static final long serialVersionUID = -5796178637883178826L; @XStreamAlias("Articles") protected final List articles = new ArrayList<>(); + @XStreamAlias("ArticleCount") protected int articleCount; public WxCpXmlOutNewsMessage() { - this.msgType = WxConsts.XML_MSG_NEWS; + this.msgType = WxConsts.XmlMsgType.NEWS; } - public int getArticleCount() { - return this.articleCount; - } public void addArticle(Item item) { this.articles.add(item); this.articleCount = this.articles.size(); } - public List getArticles() { - return this.articles; - } - - @XStreamAlias("item") + @Data public static class Item { @XStreamAlias("Title") @XStreamConverter(value = XStreamCDataConverter.class) - private String Title; + private String title; @XStreamAlias("Description") @XStreamConverter(value = XStreamCDataConverter.class) - private String Description; + private String description; @XStreamAlias("PicUrl") @XStreamConverter(value = XStreamCDataConverter.class) - private String PicUrl; + private String picUrl; @XStreamAlias("Url") @XStreamConverter(value = XStreamCDataConverter.class) - private String Url; - - public String getTitle() { - return this.Title; - } - - public void setTitle(String title) { - this.Title = title; - } - - public String getDescription() { - return this.Description; - } - - public void setDescription(String description) { - this.Description = description; - } - - public String getPicUrl() { - return this.PicUrl; - } - - public void setPicUrl(String picUrl) { - this.PicUrl = picUrl; - } - - public String getUrl() { - return this.Url; - } - - public void setUrl(String url) { - this.Url = url; - } + private String url; } - } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessage.java index 5f09abf485..1c354a12d4 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessage.java @@ -2,10 +2,12 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamConverter; +import lombok.Data; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.util.xml.XStreamCDataConverter; @XStreamAlias("xml") +@Data public class WxCpXmlOutTextMessage extends WxCpXmlOutMessage { private static final long serialVersionUID = 2569239617185930232L; @@ -14,16 +16,7 @@ public class WxCpXmlOutTextMessage extends WxCpXmlOutMessage { private String content; public WxCpXmlOutTextMessage() { - this.msgType = WxConsts.XML_MSG_TEXT; + this.msgType = WxConsts.XmlMsgType.TEXT; } - public String getContent() { - return this.content; - } - - public void setContent(String content) { - this.content = content; - } - - } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessage.java index 46dae31c3f..6d3bd0b4d1 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessage.java @@ -2,10 +2,12 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamConverter; +import lombok.Data; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.util.xml.XStreamCDataConverter; @XStreamAlias("xml") +@Data public class WxCpXmlOutVideoMessage extends WxCpXmlOutMessage { private static final long serialVersionUID = -8672761162722733622L; @@ -13,7 +15,7 @@ public class WxCpXmlOutVideoMessage extends WxCpXmlOutMessage { protected final Video video = new Video(); public WxCpXmlOutVideoMessage() { - this.msgType = WxConsts.XML_MSG_VIDEO; + this.msgType = WxConsts.XmlMsgType.VIDEO; } public String getMediaId() { @@ -40,7 +42,7 @@ public void setDescription(String description) { this.video.setDescription(description); } - + @Data @XStreamAlias("Video") public static class Video { @@ -56,30 +58,6 @@ public static class Video { @XStreamConverter(value = XStreamCDataConverter.class) private String description; - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } - - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String description) { - this.description = description; - } - } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessage.java index b1827706dd..c880bccfff 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessage.java @@ -2,10 +2,12 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamConverter; +import lombok.Data; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.util.xml.XStreamMediaIdConverter; @XStreamAlias("xml") +@Data public class WxCpXmlOutVoiceMessage extends WxCpXmlOutMessage { private static final long serialVersionUID = -7947384031546099340L; @@ -14,15 +16,7 @@ public class WxCpXmlOutVoiceMessage extends WxCpXmlOutMessage { private String mediaId; public WxCpXmlOutVoiceMessage() { - this.msgType = WxConsts.XML_MSG_VOICE; - } - - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; + this.msgType = WxConsts.XmlMsgType.VOICE; } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/article/MpnewsArticle.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/article/MpnewsArticle.java index b3f4acf402..af622fefd8 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/article/MpnewsArticle.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/article/MpnewsArticle.java @@ -1,5 +1,8 @@ package me.chanjar.weixin.cp.bean.article; +import lombok.Builder; +import lombok.Data; + import java.io.Serializable; /** @@ -9,6 +12,8 @@ * * @author Binary Wang */ +@Data +@Builder(builderMethodName = "newBuilder") public class MpnewsArticle implements Serializable { private static final long serialVersionUID = 6985871812170756481L; @@ -20,125 +25,4 @@ public class MpnewsArticle implements Serializable { private String digest; private String showCoverPic; - private MpnewsArticle(Builder builder) { - setTitle(builder.title); - setThumbMediaId(builder.thumbMediaId); - setAuthor(builder.author); - setContentSourceUrl(builder.contentSourceUrl); - setContent(builder.content); - setDigest(builder.digest); - setShowCoverPic(builder.showCoverPic); - } - - public static Builder newBuilder() { - return new Builder(); - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getThumbMediaId() { - return thumbMediaId; - } - - public void setThumbMediaId(String thumbMediaId) { - this.thumbMediaId = thumbMediaId; - } - - public String getAuthor() { - return author; - } - - public void setAuthor(String author) { - this.author = author; - } - - public String getContentSourceUrl() { - return contentSourceUrl; - } - - public void setContentSourceUrl(String contentSourceUrl) { - this.contentSourceUrl = contentSourceUrl; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public String getDigest() { - return digest; - } - - public void setDigest(String digest) { - this.digest = digest; - } - - public String getShowCoverPic() { - return showCoverPic; - } - - public void setShowCoverPic(String showCoverPic) { - this.showCoverPic = showCoverPic; - } - - public static final class Builder { - private String title; - private String thumbMediaId; - private String author; - private String contentSourceUrl; - private String content; - private String digest; - private String showCoverPic; - - private Builder() { - } - - public Builder title(String title) { - this.title = title; - return this; - } - - public Builder thumbMediaId(String thumbMediaId) { - this.thumbMediaId = thumbMediaId; - return this; - } - - public Builder author(String author) { - this.author = author; - return this; - } - - public Builder contentSourceUrl(String contentSourceUrl) { - this.contentSourceUrl = contentSourceUrl; - return this; - } - - public Builder content(String content) { - this.content = content; - return this; - } - - public Builder digest(String digest) { - this.digest = digest; - return this; - } - - public Builder showCoverPic(String showCoverPic) { - this.showCoverPic = showCoverPic; - return this; - } - - public MpnewsArticle build() { - return new MpnewsArticle(this); - } - } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/article/NewArticle.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/article/NewArticle.java index 02b0b1086f..7f10d363b4 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/article/NewArticle.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/article/NewArticle.java @@ -1,5 +1,7 @@ package me.chanjar.weixin.cp.bean.article; +import lombok.Data; + import java.io.Serializable; /** @@ -9,6 +11,7 @@ * * @author Binary Wang */ +@Data public class NewArticle implements Serializable { private static final long serialVersionUID = 4087852055781140659L; @@ -17,36 +20,4 @@ public class NewArticle implements Serializable { private String url; private String picUrl; - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getUrl() { - return this.url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getPicUrl() { - return this.picUrl; - } - - public void setPicUrl(String picUrl) { - this.picUrl = picUrl; - } - } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/BaseBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/BaseBuilder.java index 784de9a769..1064f00526 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/BaseBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/BaseBuilder.java @@ -44,7 +44,7 @@ public WxCpMessage build() { m.setToUser(this.toUser); m.setToParty(this.toParty); m.setToTag(this.toTag); - m.setSafe(StringUtils.defaultIfBlank(this.safe, WxConsts.CUSTOM_MSG_SAFE_NO)); + m.setSafe(StringUtils.defaultIfBlank(this.safe, WxConsts.KefuMsgSafe.NO)); return m; } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/FileBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/FileBuilder.java index 1da7816926..f67cf6e50d 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/FileBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/FileBuilder.java @@ -15,7 +15,7 @@ public final class FileBuilder extends BaseBuilder { private String mediaId; public FileBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_FILE; + this.msgType = WxConsts.KefuMsgType.FILE; } public FileBuilder mediaId(String media_id) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/ImageBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/ImageBuilder.java index a74f5016e4..ddf3b7373b 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/ImageBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/ImageBuilder.java @@ -15,7 +15,7 @@ public final class ImageBuilder extends BaseBuilder { private String mediaId; public ImageBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_IMAGE; + this.msgType = WxConsts.KefuMsgType.IMAGE; } public ImageBuilder mediaId(String media_id) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/MpnewsBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/MpnewsBuilder.java index 55ed20abab..75739803f4 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/MpnewsBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/MpnewsBuilder.java @@ -23,7 +23,7 @@ public final class MpnewsBuilder extends BaseBuilder { private String mediaId; public MpnewsBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_MPNEWS; + this.msgType = WxConsts.KefuMsgType.MPNEWS; } public MpnewsBuilder mediaId(String mediaId) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/NewsBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/NewsBuilder.java index dd23941244..9d0d2f603a 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/NewsBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/NewsBuilder.java @@ -22,7 +22,7 @@ public final class NewsBuilder extends BaseBuilder { private List articles = new ArrayList<>(); public NewsBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_NEWS; + this.msgType = WxConsts.KefuMsgType.NEWS; } public NewsBuilder addArticle(NewArticle... articles) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/TextBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/TextBuilder.java index 8c1ee1d014..5079b5f846 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/TextBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/TextBuilder.java @@ -15,7 +15,7 @@ public final class TextBuilder extends BaseBuilder { private String content; public TextBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_TEXT; + this.msgType = WxConsts.KefuMsgType.TEXT; } public TextBuilder content(String content) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/TextCardBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/TextCardBuilder.java index a30b9d4059..f453bddb9b 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/TextCardBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/TextCardBuilder.java @@ -18,7 +18,7 @@ public class TextCardBuilder extends BaseBuilder { private String url; public TextCardBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_TEXTCARD; + this.msgType = WxConsts.KefuMsgType.TEXTCARD; } public TextCardBuilder title(String title) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VideoBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VideoBuilder.java index 52cba28703..8d47399407 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VideoBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VideoBuilder.java @@ -24,7 +24,7 @@ public final class VideoBuilder extends BaseBuilder { private String thumbMediaId; public VideoBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_VIDEO; + this.msgType = WxConsts.KefuMsgType.VIDEO; } public VideoBuilder mediaId(String mediaId) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VoiceBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VoiceBuilder.java index 0960fe8f0c..33c36abcbe 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VoiceBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VoiceBuilder.java @@ -15,7 +15,7 @@ public final class VoiceBuilder extends BaseBuilder { private String mediaId; public VoiceBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_VOICE; + this.msgType = WxConsts.KefuMsgType.VOICE; } public VoiceBuilder mediaId(String media_id) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpJedisConfigStorage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpJedisConfigStorage.java index 39b2ae5023..5ef99a3ca8 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpJedisConfigStorage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpJedisConfigStorage.java @@ -9,7 +9,11 @@ import java.io.File; /** - * Jedis client implementor for wechat config storage + * Jedis client implementor for wechat config storage. + *
+ *    使用说明:本实现仅供参考,并不完整,
+ *    比如为减少项目依赖,未加入redis分布式锁的实现,如有需要请自行实现。
+ * 
* * @author gaigeshen */ diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouter.java index 3c53d26106..99e4fd4573 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouter.java @@ -11,6 +11,7 @@ import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.bean.WxCpXmlMessage; import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -215,17 +216,19 @@ public WxCpXmlOutMessage route(final WxCpXmlMessage wxMessage) { } protected boolean isDuplicateMessage(WxCpXmlMessage wxMessage) { - - String messageId = ""; + String messageId; if (wxMessage.getMsgId() == null) { messageId = String.valueOf(wxMessage.getCreateTime()) - + "-" + String.valueOf(wxMessage.getAgentId() == null ? "" : wxMessage.getAgentId()) + + "-" + StringUtils.trimToEmpty(String.valueOf(wxMessage.getAgentId())) + "-" + wxMessage.getFromUserName() - + "-" + String.valueOf(wxMessage.getEventKey() == null ? "" : wxMessage.getEventKey()) - + "-" + String.valueOf(wxMessage.getEvent() == null ? "" : wxMessage.getEvent()) + + "-" + StringUtils.trimToEmpty(wxMessage.getEventKey()) + + "-" + StringUtils.trimToEmpty(wxMessage.getEvent()) ; } else { - messageId = String.valueOf(wxMessage.getMsgId()); + messageId = new StringBuilder().append(wxMessage.getMsgId()) + .append("-").append(wxMessage.getCreateTime()) + .append("-").append(wxMessage.getFromUserName()) + .toString(); } return this.messageDuplicateChecker.isDuplicate(messageId); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpDepartGsonAdapter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpDepartGsonAdapter.java index 431c38039b..a5a11d24f4 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpDepartGsonAdapter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpDepartGsonAdapter.java @@ -49,7 +49,7 @@ public WxCpDepart deserialize(JsonElement json, Type typeOfT, JsonDeserializatio depart.setName(GsonHelper.getAsString(departJson.get("name"))); } if (departJson.get("order") != null && !departJson.get("order").isJsonNull()) { - depart.setOrder(GsonHelper.getAsInteger(departJson.get("order"))); + depart.setOrder(GsonHelper.getAsLong(departJson.get("order"))); } if (departJson.get("parentid") != null && !departJson.get("parentid").isJsonNull()) { depart.setParentId(GsonHelper.getAsInteger(departJson.get("parentid"))); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpMessageGsonAdapter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpMessageGsonAdapter.java index 67e43c4ccc..5e19b50121 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpMessageGsonAdapter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpMessageGsonAdapter.java @@ -37,13 +37,13 @@ public JsonElement serialize(WxCpMessage message, Type typeOfSrc, JsonSerializat if (StringUtils.isNotBlank(message.getToTag())) { messageJson.addProperty("totag", message.getToTag()); } - if (WxConsts.CUSTOM_MSG_TEXT.equals(message.getMsgType())) { + if (WxConsts.KefuMsgType.TEXT.equals(message.getMsgType())) { JsonObject text = new JsonObject(); text.addProperty("content", message.getContent()); messageJson.add("text", text); } - if (WxConsts.CUSTOM_MSG_TEXTCARD.equals(message.getMsgType())) { + if (WxConsts.KefuMsgType.TEXTCARD.equals(message.getMsgType())) { JsonObject text = new JsonObject(); text.addProperty("title", message.getTitle()); text.addProperty("description", message.getDescription()); @@ -51,19 +51,19 @@ public JsonElement serialize(WxCpMessage message, Type typeOfSrc, JsonSerializat messageJson.add("textcard", text); } - if (WxConsts.CUSTOM_MSG_IMAGE.equals(message.getMsgType())) { + if (WxConsts.KefuMsgType.IMAGE.equals(message.getMsgType())) { JsonObject image = new JsonObject(); image.addProperty("media_id", message.getMediaId()); messageJson.add("image", image); } - if (WxConsts.CUSTOM_MSG_FILE.equals(message.getMsgType())) { + if (WxConsts.KefuMsgType.FILE.equals(message.getMsgType())) { JsonObject image = new JsonObject(); image.addProperty("media_id", message.getMediaId()); messageJson.add("file", image); } - if (WxConsts.CUSTOM_MSG_VOICE.equals(message.getMsgType())) { + if (WxConsts.KefuMsgType.VOICE.equals(message.getMsgType())) { JsonObject voice = new JsonObject(); voice.addProperty("media_id", message.getMediaId()); messageJson.add("voice", voice); @@ -73,7 +73,7 @@ public JsonElement serialize(WxCpMessage message, Type typeOfSrc, JsonSerializat messageJson.addProperty("safe", message.getSafe()); } - if (WxConsts.CUSTOM_MSG_VIDEO.equals(message.getMsgType())) { + if (WxConsts.KefuMsgType.VIDEO.equals(message.getMsgType())) { JsonObject video = new JsonObject(); video.addProperty("media_id", message.getMediaId()); video.addProperty("thumb_media_id", message.getThumbMediaId()); @@ -82,7 +82,7 @@ public JsonElement serialize(WxCpMessage message, Type typeOfSrc, JsonSerializat messageJson.add("video", video); } - if (WxConsts.CUSTOM_MSG_NEWS.equals(message.getMsgType())) { + if (WxConsts.KefuMsgType.NEWS.equals(message.getMsgType())) { JsonObject newsJsonObject = new JsonObject(); JsonArray articleJsonArray = new JsonArray(); for (NewArticle article : message.getArticles()) { @@ -97,7 +97,7 @@ public JsonElement serialize(WxCpMessage message, Type typeOfSrc, JsonSerializat messageJson.add("news", newsJsonObject); } - if (WxConsts.CUSTOM_MSG_MPNEWS.equals(message.getMsgType())) { + if (WxConsts.KefuMsgType.MPNEWS.equals(message.getMsgType())) { JsonObject newsJsonObject = new JsonObject(); if (message.getMediaId() != null) { newsJsonObject.addProperty("media_id", message.getMediaId()); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/xml/XStreamTransformer.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/xml/XStreamTransformer.java index 6b58063062..e08ef4df60 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/xml/XStreamTransformer.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/xml/XStreamTransformer.java @@ -28,7 +28,7 @@ public static T fromXml(Class clazz, InputStream is) { } /** - * 注册扩展消息的解析器 + * 注册扩展消息的解析器. * * @param clz 类型 * @param xStream xml解析器 @@ -46,17 +46,19 @@ public static String toXml(Class clazz, T object) { private static Map configXStreamInstance() { Map map = new HashMap<>(); - map.put(WxCpXmlMessage.class, config_WxCpXmlMessage()); - map.put(WxCpXmlOutNewsMessage.class, config_WxCpXmlOutNewsMessage()); - map.put(WxCpXmlOutTextMessage.class, config_WxCpXmlOutTextMessage()); - map.put(WxCpXmlOutImageMessage.class, config_WxCpXmlOutImageMessage()); - map.put(WxCpXmlOutVideoMessage.class, config_WxCpXmlOutVideoMessage()); - map.put(WxCpXmlOutVoiceMessage.class, config_WxCpXmlOutVoiceMessage()); + map.put(WxCpXmlMessage.class, configWxCpXmlMessage()); + map.put(WxCpXmlOutNewsMessage.class, configWxCpXmlOutNewsMessage()); + map.put(WxCpXmlOutTextMessage.class, configWxCpXmlOutTextMessage()); + map.put(WxCpXmlOutImageMessage.class, configWxCpXmlOutImageMessage()); + map.put(WxCpXmlOutVideoMessage.class, configWxCpXmlOutVideoMessage()); + map.put(WxCpXmlOutVoiceMessage.class, configWxCpXmlOutVoiceMessage()); return map; } - private static XStream config_WxCpXmlMessage() { + private static XStream configWxCpXmlMessage() { XStream xstream = XStreamInitializer.getInstance(); + xstream.setClassLoader(Thread.currentThread().getContextClassLoader()); + xstream.processAnnotations(WxCpXmlMessage.class); xstream.processAnnotations(WxCpXmlMessage.ScanCodeInfo.class); xstream.processAnnotations(WxCpXmlMessage.SendPicsInfo.class); @@ -65,38 +67,48 @@ private static XStream config_WxCpXmlMessage() { return xstream; } - private static XStream config_WxCpXmlOutImageMessage() { + private static XStream configWxCpXmlOutImageMessage() { XStream xstream = XStreamInitializer.getInstance(); + xstream.setClassLoader(Thread.currentThread().getContextClassLoader()); + xstream.processAnnotations(WxCpXmlOutMessage.class); xstream.processAnnotations(WxCpXmlOutImageMessage.class); return xstream; } - private static XStream config_WxCpXmlOutNewsMessage() { + private static XStream configWxCpXmlOutNewsMessage() { XStream xstream = XStreamInitializer.getInstance(); + xstream.setClassLoader(Thread.currentThread().getContextClassLoader()); + xstream.processAnnotations(WxCpXmlOutMessage.class); xstream.processAnnotations(WxCpXmlOutNewsMessage.class); xstream.processAnnotations(WxCpXmlOutNewsMessage.Item.class); return xstream; } - private static XStream config_WxCpXmlOutTextMessage() { + private static XStream configWxCpXmlOutTextMessage() { XStream xstream = XStreamInitializer.getInstance(); + xstream.setClassLoader(Thread.currentThread().getContextClassLoader()); + xstream.processAnnotations(WxCpXmlOutMessage.class); xstream.processAnnotations(WxCpXmlOutTextMessage.class); return xstream; } - private static XStream config_WxCpXmlOutVideoMessage() { + private static XStream configWxCpXmlOutVideoMessage() { XStream xstream = XStreamInitializer.getInstance(); + xstream.setClassLoader(Thread.currentThread().getContextClassLoader()); + xstream.processAnnotations(WxCpXmlOutMessage.class); xstream.processAnnotations(WxCpXmlOutVideoMessage.class); xstream.processAnnotations(WxCpXmlOutVideoMessage.Video.class); return xstream; } - private static XStream config_WxCpXmlOutVoiceMessage() { + private static XStream configWxCpXmlOutVoiceMessage() { XStream xstream = XStreamInitializer.getInstance(); + xstream.setClassLoader(Thread.currentThread().getContextClassLoader()); + xstream.processAnnotations(WxCpXmlOutMessage.class); xstream.processAnnotations(WxCpXmlOutVoiceMessage.class); return xstream; diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBusyRetryTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBusyRetryTest.java index 2c964d309c..6d4e8ce893 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBusyRetryTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBusyRetryTest.java @@ -24,9 +24,7 @@ public synchronized T executeInternal( RequestExecutor executor, String uri, E data) throws WxErrorException { this.log.info("Executed"); - WxError error = new WxError(); - error.setErrorCode(-1); - throw new WxErrorException(error); + throw new WxErrorException(WxError.builder().errorCode(-1).build()); } }; diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java index 0cecc01588..4194efc17a 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java @@ -3,7 +3,6 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl; import me.chanjar.weixin.cp.bean.WxCpMessage; import me.chanjar.weixin.cp.bean.WxCpMessageSendResult; import org.testng.annotations.*; @@ -32,7 +31,7 @@ public void setup() { public void testSendMessage() throws WxErrorException { WxCpMessage message = new WxCpMessage(); // message.setAgentId(configStorage.getAgentId()); - message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); + message.setMsgType(WxConsts.KefuMsgType.TEXT); message.setToUser(configStorage.getUserId()); message.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageRouterTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageRouterTest.java index e52101f508..d37f45354a 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageRouterTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageRouterTest.java @@ -27,21 +27,21 @@ public void prepare(boolean async, StringBuffer sb, WxCpMessageRouter router) { router .rule() .async(async) - .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1") + .msgType(WxConsts.XmlMsgType.TEXT).event(WxConsts.EventType.CLICK).eventKey("KEY_1").content("CONTENT_1") .handler(new WxEchoCpMessageHandler(sb, "COMBINE_4")) .end() .rule() .async(async) - .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1") + .msgType(WxConsts.XmlMsgType.TEXT).event(WxConsts.EventType.CLICK).eventKey("KEY_1") .handler(new WxEchoCpMessageHandler(sb, "COMBINE_3")) .end() .rule() .async(async) - .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK) + .msgType(WxConsts.XmlMsgType.TEXT).event(WxConsts.EventType.CLICK) .handler(new WxEchoCpMessageHandler(sb, "COMBINE_2")) .end() - .rule().async(async).msgType(WxConsts.XML_MSG_TEXT).handler(new WxEchoCpMessageHandler(sb, WxConsts.XML_MSG_TEXT)).end() - .rule().async(async).event(WxConsts.EVT_CLICK).handler(new WxEchoCpMessageHandler(sb, WxConsts.EVT_CLICK)).end() + .rule().async(async).msgType(WxConsts.XmlMsgType.TEXT).handler(new WxEchoCpMessageHandler(sb, WxConsts.XmlMsgType.TEXT)).end() + .rule().async(async).event(WxConsts.EventType.CLICK).handler(new WxEchoCpMessageHandler(sb, WxConsts.EventType.CLICK)).end() .rule().async(async).eventKey("KEY_1").handler(new WxEchoCpMessageHandler(sb, "KEY_1")).end() .rule().async(async).content("CONTENT_1").handler(new WxEchoCpMessageHandler(sb, "CONTENT_1")).end() .rule().async(async).rContent(".*bc.*").handler(new WxEchoCpMessageHandler(sb, "abcd")).end() @@ -104,10 +104,10 @@ public void run() { @DataProvider(name = "messages-1") public Object[][] messages2() { WxCpXmlMessage message1 = new WxCpXmlMessage(); - message1.setMsgType(WxConsts.XML_MSG_TEXT); + message1.setMsgType(WxConsts.XmlMsgType.TEXT); WxCpXmlMessage message2 = new WxCpXmlMessage(); - message2.setEvent(WxConsts.EVT_CLICK); + message2.setEvent(WxConsts.EventType.CLICK); WxCpXmlMessage message3 = new WxCpXmlMessage(); message3.setEventKey("KEY_1"); @@ -125,24 +125,24 @@ public Object[][] messages2() { message7.setFormat("strangeformat"); WxCpXmlMessage c2 = new WxCpXmlMessage(); - c2.setMsgType(WxConsts.XML_MSG_TEXT); - c2.setEvent(WxConsts.EVT_CLICK); + c2.setMsgType(WxConsts.XmlMsgType.TEXT); + c2.setEvent(WxConsts.EventType.CLICK); WxCpXmlMessage c3 = new WxCpXmlMessage(); - c3.setMsgType(WxConsts.XML_MSG_TEXT); - c3.setEvent(WxConsts.EVT_CLICK); + c3.setMsgType(WxConsts.XmlMsgType.TEXT); + c3.setEvent(WxConsts.EventType.CLICK); c3.setEventKey("KEY_1"); WxCpXmlMessage c4 = new WxCpXmlMessage(); - c4.setMsgType(WxConsts.XML_MSG_TEXT); - c4.setEvent(WxConsts.EVT_CLICK); + c4.setMsgType(WxConsts.XmlMsgType.TEXT); + c4.setEvent(WxConsts.EventType.CLICK); c4.setEventKey("KEY_1"); c4.setContent("CONTENT_1"); return new Object[][]{ - new Object[]{message1, WxConsts.XML_MSG_TEXT + ","}, - new Object[]{message2, WxConsts.EVT_CLICK + ","}, + new Object[]{message1, WxConsts.XmlMsgType.TEXT + ","}, + new Object[]{message2, WxConsts.EventType.CLICK + ","}, new Object[]{message3, "KEY_1,"}, new Object[]{message4, "CONTENT_1,"}, new Object[]{message5, "ALL,"}, diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImplTest.java index 685f37444f..5e2502082a 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImplTest.java @@ -1,12 +1,10 @@ package me.chanjar.weixin.cp.api.impl; import com.google.inject.Inject; -import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.cp.api.ApiTestModule; import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.bean.WxCpDepart; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.annotations.*; import java.util.List; @@ -31,7 +29,7 @@ public void testCreate() throws Exception { WxCpDepart cpDepart = new WxCpDepart(); cpDepart.setName("子部门" + System.currentTimeMillis()); cpDepart.setParentId(1); - cpDepart.setOrder(1); + cpDepart.setOrder(1L); Integer departId = this.wxCpService.getDepartmentService().create(cpDepart); System.out.println(departId); } diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImplTest.java index 4bdb73413d..084f59f289 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImplTest.java @@ -34,11 +34,11 @@ public class WxCpMediaServiceImplTest { @DataProvider public Object[][] mediaData() { return new Object[][]{ - new Object[]{WxConsts.MEDIA_IMAGE, TestConstants.FILE_JPG, "mm.jpeg"}, - new Object[]{WxConsts.MEDIA_VOICE, TestConstants.FILE_MP3, "mm.mp3"}, - new Object[]{WxConsts.MEDIA_VOICE, TestConstants.FILE_AMR, "mm.amr"},//{"errcode":301017,"errmsg":"voice file only support amr like myvoice.amr"} - new Object[]{WxConsts.MEDIA_VIDEO, TestConstants.FILE_MP4, "mm.mp4"}, - new Object[]{WxConsts.MEDIA_FILE, TestConstants.FILE_JPG, "mm.jpeg"} + new Object[]{WxConsts.MediaFileType.IMAGE, TestConstants.FILE_JPG, "mm.jpeg"}, + new Object[]{WxConsts.MediaFileType.VOICE, TestConstants.FILE_MP3, "mm.mp3"}, + new Object[]{WxConsts.MediaFileType.VOICE, TestConstants.FILE_AMR, "mm.amr"},//{"errcode":301017,"errmsg":"voice file only support amr like myvoice.amr"} + new Object[]{WxConsts.MediaFileType.VIDEO, TestConstants.FILE_MP4, "mm.mp4"}, + new Object[]{WxConsts.MediaFileType.FILE, TestConstants.FILE_JPG, "mm.jpeg"} }; } diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImplTest.java index def6419820..b9dbbd3aa1 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImplTest.java @@ -26,12 +26,12 @@ public class WxCpMenuServiceImplTest { public Object[][] menuData() { WxMenu menu = new WxMenu(); WxMenuButton button1 = new WxMenuButton(); - button1.setType(WxConsts.BUTTON_CLICK); + button1.setType(WxConsts.MenuButtonType.CLICK); button1.setName("今日歌曲"); button1.setKey("V1001_TODAY_MUSIC"); WxMenuButton button2 = new WxMenuButton(); - button2.setType(WxConsts.BUTTON_CLICK); + button2.setType(WxConsts.MenuButtonType.CLICK); button2.setName("歌手简介"); button2.setKey("V1001_TODAY_SINGER"); @@ -43,17 +43,17 @@ public Object[][] menuData() { menu.getButtons().add(button3); WxMenuButton button31 = new WxMenuButton(); - button31.setType(WxConsts.BUTTON_VIEW); + button31.setType(WxConsts.MenuButtonType.VIEW); button31.setName("搜索"); button31.setUrl("http://www.soso.com/"); WxMenuButton button32 = new WxMenuButton(); - button32.setType(WxConsts.BUTTON_VIEW); + button32.setType(WxConsts.MenuButtonType.VIEW); button32.setName("视频"); button32.setUrl("http://v.qq.com/"); WxMenuButton button33 = new WxMenuButton(); - button33.setType(WxConsts.BUTTON_CLICK); + button33.setType(WxConsts.MenuButtonType.CLICK); button33.setName("赞一下我们"); button33.setKey("V1001_GOOD"); diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlMessageTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlMessageTest.java index 87e16d773a..e320d8cb2e 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlMessageTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlMessageTest.java @@ -58,7 +58,7 @@ public void testFromXml() { assertEquals(wxMessage.getToUserName(), "toUser"); assertEquals(wxMessage.getFromUserName(), "fromUser"); assertEquals(wxMessage.getCreateTime(), new Long(1348831860l)); - assertEquals(wxMessage.getMsgType(), WxConsts.XML_MSG_TEXT); + assertEquals(wxMessage.getMsgType(), WxConsts.XmlMsgType.TEXT); assertEquals(wxMessage.getContent(), "this is a test"); assertEquals(wxMessage.getMsgId(), new Long(1234567890123456l)); assertEquals(wxMessage.getPicUrl(), "this is a url"); @@ -86,7 +86,7 @@ public void testFromXml() { assertEquals(wxMessage.getSendLocationInfo().getLocationY(), "113"); assertEquals(wxMessage.getSendLocationInfo().getScale(), "15"); assertEquals(wxMessage.getSendLocationInfo().getLabel(), " 广州市海珠区客村艺苑路 106号"); - assertEquals(wxMessage.getSendLocationInfo().getPoiname(), "wo de poi"); + assertEquals(wxMessage.getSendLocationInfo().getPoiName(), "wo de poi"); } public void testSendPicsInfo() { @@ -108,7 +108,7 @@ public void testSendPicsInfo() { assertEquals(wxMessage.getToUserName(), "wx45a0972125658be9"); assertEquals(wxMessage.getFromUserName(), "xiaohe"); assertEquals(wxMessage.getCreateTime(), new Long(1502012364L)); - assertEquals(wxMessage.getMsgType(), WxConsts.XML_MSG_EVENT); + assertEquals(wxMessage.getMsgType(), WxConsts.XmlMsgType.EVENT); assertEquals(wxMessage.getAgentId(), Integer.valueOf(1000004)); assertEquals(wxMessage.getEvent(), "pic_weixin"); assertEquals(wxMessage.getEventKey(), "faceSimilarity"); diff --git a/weixin-java-miniapp/pom.xml b/weixin-java-miniapp/pom.xml index 3a2614aa59..d10de23659 100644 --- a/weixin-java-miniapp/pom.xml +++ b/weixin-java-miniapp/pom.xml @@ -7,7 +7,7 @@ com.github.binarywang weixin-java-parent - 2.8.0 + 2.9.0 weixin-java-miniapp WeiXin Java Tools - MiniApp diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaQrcodeService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaQrcodeService.java index c2222bc93e..4b3ec5feba 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaQrcodeService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaQrcodeService.java @@ -1,5 +1,6 @@ package cn.binarywang.wx.miniapp.api; +import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor; import me.chanjar.weixin.common.exception.WxErrorException; import java.io.File; @@ -16,6 +17,9 @@ * @author Binary Wang */ public interface WxMaQrcodeService { + String CREATE_QRCODE_URL = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode"; + String GET_WXACODE_URL = "https://api.weixin.qq.com/wxa/getwxacode"; + String GET_WXACODE_UNLIMIT_URL = "https://api.weixin.qq.com/wxa/getwxacodeunlimit"; /** * 接口C @@ -42,10 +46,8 @@ public interface WxMaQrcodeService { * @param width 默认430 二维码的宽度 * @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 * @param lineColor auth_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} - * @return - * @throws WxErrorException */ - File createWxCode(String path, int width, boolean autoColor, LineColor lineColor) throws WxErrorException; + File createWxCode(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException; File createWxCode(String path, int width) throws WxErrorException; @@ -65,49 +67,9 @@ public interface WxMaQrcodeService { * @param width 默认false 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 * @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 * @param lineColor auth_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} - * @return - * @throws WxErrorException */ - File createWxCodeLimit(String scene, String page, int width, boolean autoColor, LineColor lineColor) throws WxErrorException; + File createWxCodeLimit(String scene, String page, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException; File createWxCodeLimit(String scene, String page) throws WxErrorException; - /** - * lineColor 包装类 - * 用于描述二维码(小程序码)颜色(RGB参数值),详情请查看文档 - */ - public static class LineColor { - - private String r = "0", g = "0", b = "0"; - - public LineColor(String r, String g, String b) { - this.r = r; - this.g = g; - this.b = b; - } - - public String getR() { - return r; - } - - public void setR(String r) { - this.r = r; - } - - public String getG() { - return g; - } - - public void setG(String g) { - this.g = g; - } - - public String getB() { - return b; - } - - public void setB(String b) { - this.b = b; - } - } } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaMediaServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaMediaServiceImpl.java index 66ad3c2a91..b198fc7a07 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaMediaServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaMediaServiceImpl.java @@ -6,11 +6,9 @@ import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; -import me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor; +import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor; import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; import me.chanjar.weixin.common.util.http.RequestExecutor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; @@ -22,8 +20,6 @@ * @author Binary Wang */ public class WxMaMediaServiceImpl implements WxMaMediaService { - private final Logger log = LoggerFactory.getLogger(this.getClass()); - private WxMaService wxMaService; public WxMaMediaServiceImpl(WxMaService wxMaService) { @@ -35,8 +31,7 @@ public WxMediaUploadResult uploadMedia(String mediaType, String fileType, InputS try { return this.uploadMedia(mediaType, FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), fileType)); } catch (IOException e) { - e.printStackTrace(); - throw new WxErrorException(WxError.newBuilder().setErrorMsg(e.getMessage()).build()); + throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e); } } @@ -49,12 +44,11 @@ public WxMediaUploadResult uploadMedia(String mediaType, File file) throws WxErr @Override public File getMedia(String mediaId) throws WxErrorException { try { - RequestExecutor executor = MediaDownloadRequestExecutor + RequestExecutor executor = BaseMediaDownloadRequestExecutor .create(this.wxMaService.getRequestHttp(), Files.createTempDirectory("wxma").toFile()); return this.wxMaService.execute(executor, MEDIA_GET_URL, "media_id=" + mediaId); } catch (IOException e) { - this.log.error(e.getMessage(), e); - throw new WxErrorException(WxError.newBuilder().setErrorMsg(e.getMessage()).build()); + throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e); } } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaMsgServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaMsgServiceImpl.java index 70a4e50445..aadc04f8a0 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaMsgServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaMsgServiceImpl.java @@ -4,6 +4,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.bean.WxMaKefuMessage; import cn.binarywang.wx.miniapp.bean.WxMaTemplateMessage; +import cn.binarywang.wx.miniapp.constant.WxMaConstants; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import me.chanjar.weixin.common.bean.result.WxError; @@ -30,7 +31,7 @@ public boolean sendKefuMsg(WxMaKefuMessage message) throws WxErrorException { public void sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException { String responseContent = this.wxMaService.post(TEMPLATE_MSG_SEND_URL, templateMessage.toJson()); JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject(); - if (jsonObject.get("errcode").getAsInt() != 0) { + if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) { throw new WxErrorException(WxError.fromJson(responseContent)); } } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImpl.java index fd58855b3d..806e0e99b8 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImpl.java @@ -2,6 +2,7 @@ import cn.binarywang.wx.miniapp.api.WxMaQrcodeService; import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor; import cn.binarywang.wx.miniapp.bean.WxMaQrcode; import cn.binarywang.wx.miniapp.bean.WxMaWxcode; import cn.binarywang.wx.miniapp.bean.WxMaWxcodeLimit; @@ -22,9 +23,8 @@ public WxMaQrcodeServiceImpl(WxMaService wxMaService) { @Override public File createQrcode(String path, int width) throws WxErrorException { - String url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode"; return this.wxMaService.execute(new QrCodeRequestExecutor(this.wxMaService.getRequestHttp()), - url, new WxMaQrcode(path, width)); + CREATE_QRCODE_URL, new WxMaQrcode(path, width)); } @Override @@ -33,15 +33,14 @@ public File createQrcode(String path) throws WxErrorException { } @Override - public File createWxCode(String path, int width, boolean autoColor, LineColor lineColor) throws WxErrorException { - String url = "https://api.weixin.qq.com/wxa/getwxacode"; + public File createWxCode(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException { WxMaWxcode wxMaWxcode = new WxMaWxcode(); wxMaWxcode.setPath(path); wxMaWxcode.setWidth(width); wxMaWxcode.setAutoColor(autoColor); wxMaWxcode.setLineColor(lineColor); return this.wxMaService.execute(new QrCodeRequestExecutor(this.wxMaService.getRequestHttp()), - url, wxMaWxcode); + GET_WXACODE_URL, wxMaWxcode); } @Override @@ -55,8 +54,7 @@ public File createWxCode(String path) throws WxErrorException { } @Override - public File createWxCodeLimit(String scene, String page, int width, boolean autoColor, LineColor lineColor) throws WxErrorException { - String url = "http://api.weixin.qq.com/wxa/getwxacodeunlimit"; + public File createWxCodeLimit(String scene, String page, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException { WxMaWxcodeLimit wxMaWxcodeLimit = new WxMaWxcodeLimit(); wxMaWxcodeLimit.setScene(scene); wxMaWxcodeLimit.setPage(page); @@ -64,7 +62,7 @@ public File createWxCodeLimit(String scene, String page, int width, boolean auto wxMaWxcodeLimit.setAutoColor(autoColor); wxMaWxcodeLimit.setLineColor(lineColor); return this.wxMaService.execute(new QrCodeRequestExecutor(this.wxMaService.getRequestHttp()), - url, wxMaWxcodeLimit); + GET_WXACODE_UNLIMIT_URL, wxMaWxcodeLimit); } @Override diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImpl.java index 106f020e53..df3fad8efb 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImpl.java @@ -2,6 +2,7 @@ import cn.binarywang.wx.miniapp.api.*; import cn.binarywang.wx.miniapp.config.WxMaConfig; +import cn.binarywang.wx.miniapp.constant.WxMaConstants; import com.google.gson.JsonParser; import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.bean.result.WxError; @@ -147,6 +148,7 @@ public String post(String url, String postData) throws WxErrorException { /** * 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求 */ + @Override public T execute(RequestExecutor executor, String uri, E data) throws WxErrorException { int retryTimes = 0; do { @@ -179,7 +181,7 @@ public T execute(RequestExecutor executor, String uri, E data) thro throw new RuntimeException("微信服务端异常,超出重试次数"); } - public synchronized T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException { + public T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException { if (uri.contains("access_token=")) { throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri); } @@ -195,11 +197,10 @@ public synchronized T executeInternal(RequestExecutor executor, Str WxError error = e.getError(); /* * 发生以下情况时尝试刷新access_token - * 40001 获取access_token时AppSecret错误,或者access_token无效 - * 42001 access_token超时 - * 40014 不合法的access_token,请开发者认真比对access_token的有效性(如是否过期) */ - if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001 || error.getErrorCode() == 40014) { + if (error.getErrorCode() == WxMaConstants.ErrorCode.ERR_40001 + || error.getErrorCode() == WxMaConstants.ErrorCode.ERR_42001 + || error.getErrorCode() == WxMaConstants.ErrorCode.ERR_40014) { // 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token this.getWxMaConfig().expireAccessToken(); if (this.getWxMaConfig().autoRefreshToken()) { diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaUserServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaUserServiceImpl.java index e2fdb9dc2b..8dbc139a0b 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaUserServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaUserServiceImpl.java @@ -19,14 +19,14 @@ public class WxMaUserServiceImpl implements WxMaUserService { private WxMaService service; - WxMaUserServiceImpl(WxMaService service) { + public WxMaUserServiceImpl(WxMaService service) { this.service = service; } @Override public WxMaJscode2SessionResult getSessionInfo(String jsCode) throws WxErrorException { final WxMaConfig config = service.getWxMaConfig(); - Map params = new HashMap<>(); + Map params = new HashMap<>(8); params.put("appid", config.getAppid()); params.put("secret", config.getSecret()); params.put("js_code", jsCode); diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaQrcodeWrapper.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/AbstractWxMaQrcodeWrapper.java similarity index 62% rename from weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaQrcodeWrapper.java rename to weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/AbstractWxMaQrcodeWrapper.java index 37c5c5db88..f329dd30e8 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaQrcodeWrapper.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/AbstractWxMaQrcodeWrapper.java @@ -3,10 +3,11 @@ import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; /** - * 微信二维码(小程序码)包装器 - * Created by Element on 2017/7/27. + * 微信二维码(小程序码)包装器. + * + * @author Element */ -public abstract class WxMaQrcodeWrapper { +public abstract class AbstractWxMaQrcodeWrapper { @Override public String toString() { diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaCodeLineColor.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaCodeLineColor.java new file mode 100644 index 0000000000..2afb4c073e --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaCodeLineColor.java @@ -0,0 +1,18 @@ +package cn.binarywang.wx.miniapp.bean; + +import lombok.AllArgsConstructor; +import lombok.Data; + +/** + *
+ * lineColor 包装类
+ * 用于描述二维码(小程序码)颜色(RGB参数值),
+ * 详情请查看文档 https://mp.weixin.qq.com/debug/wxadoc/dev/api/qrcode.html
+ * 
+ * @author Element + */ +@Data +@AllArgsConstructor +public class WxMaCodeLineColor { + private String r = "0", g = "0", b = "0"; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaJscode2SessionResult.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaJscode2SessionResult.java index 471e6c46ec..7d3e2d8de6 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaJscode2SessionResult.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaJscode2SessionResult.java @@ -2,13 +2,21 @@ import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; /** * {"session_key":"nzoqhc3OnwHzeTxJs+inbQ==","expires_in":2592000,"openid":"oVBkZ0aYgDMDIywRdgPW8-joxXc4"} * * @author Binary Wang */ -public class WxMaJscode2SessionResult { +@Data +@EqualsAndHashCode(callSuper = false) +public class WxMaJscode2SessionResult implements Serializable { + private static final long serialVersionUID = -1060216618475607933L; + @SerializedName("session_key") private String sessionKey; @@ -25,36 +33,4 @@ public static WxMaJscode2SessionResult fromJson(String json) { return WxMaGsonBuilder.create().fromJson(json, WxMaJscode2SessionResult.class); } - public String getSessionKey() { - return sessionKey; - } - - public void setSessionKey(String sessionKey) { - this.sessionKey = sessionKey; - } - - public Integer getExpiresin() { - return expiresin; - } - - public void setExpiresin(Integer expiresin) { - this.expiresin = expiresin; - } - - public String getOpenid() { - return openid; - } - - public void setOpenid(String openid) { - this.openid = openid; - } - - public String getUnionid() { - return unionid; - } - - public void setUnionid(String unionid) { - this.unionid = unionid; - } - } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaKefuMessage.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaKefuMessage.java index d75fbf12ae..ec1728db60 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaKefuMessage.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaKefuMessage.java @@ -3,6 +3,7 @@ import cn.binarywang.wx.miniapp.builder.ImageBuilder; import cn.binarywang.wx.miniapp.builder.TextBuilder; import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; +import lombok.Data; import java.io.Serializable; @@ -11,6 +12,7 @@ * * @author Binary Wang */ +@Data public class WxMaKefuMessage implements Serializable { private static final long serialVersionUID = -9196732086954365246L; @@ -25,73 +27,17 @@ public class WxMaKefuMessage implements Serializable { /** * 获得文本消息builder */ - public static TextBuilder TEXT() { + public static TextBuilder newTextBuilder() { return new TextBuilder(); } /** * 获得图片消息builder */ - public static ImageBuilder IMAGE() { + public static ImageBuilder newImageBuilder() { return new ImageBuilder(); } - public String getToUser() { - return this.toUser; - } - - public void setToUser(String toUser) { - this.toUser = toUser; - } - - public String getMsgType() { - return this.msgType; - } - - public void setMsgType(String msgType) { - this.msgType = msgType; - } - - public String getContent() { - return this.content; - } - - public void setContent(String content) { - this.content = content; - } - - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } - - public String getThumbMediaId() { - return this.thumbMediaId; - } - - public void setThumbMediaId(String thumbMediaId) { - this.thumbMediaId = thumbMediaId; - } - - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String description) { - this.description = description; - } - public String toJson() { return WxMaGsonBuilder.create().toJson(this); } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaMessage.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaMessage.java index 4b201da1cd..cb1fed6923 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaMessage.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaMessage.java @@ -7,6 +7,7 @@ import com.google.gson.annotations.SerializedName; import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamConverter; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.common.util.xml.XStreamCDataConverter; import org.apache.commons.io.IOUtils; @@ -20,6 +21,7 @@ * @author Binary Wang */ @XStreamAlias("xml") +@Data public class WxMaMessage implements Serializable { private static final long serialVersionUID = -3586245291677274914L; @@ -146,91 +148,4 @@ public String toJson() { return WxMaGsonBuilder.create().toJson(this); } - public String getToUser() { - return toUser; - } - - public void setToUser(String toUser) { - this.toUser = toUser; - } - - public String getFromUser() { - return fromUser; - } - - public void setFromUser(String fromUser) { - this.fromUser = fromUser; - } - - public Integer getCreateTime() { - return createTime; - } - - public void setCreateTime(Integer createTime) { - this.createTime = createTime; - } - - public String getMsgType() { - return msgType; - } - - public void setMsgType(String msgType) { - this.msgType = msgType; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public Long getMsgId() { - return msgId; - } - - public void setMsgId(Long msgId) { - this.msgId = msgId; - } - - public String getPicUrl() { - return picUrl; - } - - public void setPicUrl(String picUrl) { - this.picUrl = picUrl; - } - - public String getMediaId() { - return mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } - - public String getEvent() { - return event; - } - - public void setEvent(String event) { - this.event = event; - } - - public String getSessionFrom() { - return sessionFrom; - } - - public void setSessionFrom(String sessionFrom) { - this.sessionFrom = sessionFrom; - } - - public String getEncrypt() { - return encrypt; - } - - public void setEncrypt(String encrypt) { - this.encrypt = encrypt; - } } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaQrcode.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaQrcode.java index a047d7c8b1..5c17cd1e58 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaQrcode.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaQrcode.java @@ -1,13 +1,17 @@ package cn.binarywang.wx.miniapp.bean; import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; +import lombok.Data; +import lombok.EqualsAndHashCode; import java.io.Serializable; /** * @author Binary Wang */ -public class WxMaQrcode extends WxMaQrcodeWrapper implements Serializable { +@Data +@EqualsAndHashCode(callSuper = false) +public class WxMaQrcode extends AbstractWxMaQrcodeWrapper implements Serializable { private static final long serialVersionUID = 5777119669111011584L; private String path; private int width = 430; @@ -21,22 +25,6 @@ public static WxMaQrcode fromJson(String json) { return WxMaGsonBuilder.create().fromJson(json, WxMaQrcode.class); } - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public int getWidth() { - return width; - } - - public void setWidth(int width) { - this.width = width; - } - @Override public String toString() { return WxMaGsonBuilder.create().toJson(this); diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaTemplateMessage.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaTemplateMessage.java index 79f955c6d2..32268b4c4b 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaTemplateMessage.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaTemplateMessage.java @@ -1,6 +1,8 @@ package cn.binarywang.wx.miniapp.bean; import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; +import lombok.Builder; +import lombok.Data; import java.io.Serializable; import java.util.ArrayList; @@ -11,6 +13,8 @@ * * @author Binary Wang */ +@Data +@Builder public class WxMaTemplateMessage implements Serializable { private static final long serialVersionUID = 5063374783759519418L; @@ -57,7 +61,8 @@ public class WxMaTemplateMessage implements Serializable { * 描述: 模板内容,不填则下发空模板 * */ - private List data = new ArrayList<>(); + @Builder.Default + private final List data = new ArrayList<>(); /** *
@@ -77,80 +82,11 @@ public class WxMaTemplateMessage implements Serializable {
    */
   private String emphasisKeyword;
 
-  private WxMaTemplateMessage(Builder builder) {
-    setToUser(builder.toUser);
-    setTemplateId(builder.templateId);
-    setPage(builder.page);
-    setFormId(builder.formId);
-    setData(builder.data);
-    setColor(builder.color);
-    setEmphasisKeyword(builder.emphasisKeyword);
-  }
-
-  public static Builder newBuilder() {
-    return new Builder();
-  }
-
   public String toJson() {
     return WxMaGsonBuilder.create().toJson(this);
   }
 
-  public String getToUser() {
-    return toUser;
-  }
-
-  public void setToUser(String toUser) {
-    this.toUser = toUser;
-  }
-
-  public String getTemplateId() {
-    return templateId;
-  }
-
-  public void setTemplateId(String templateId) {
-    this.templateId = templateId;
-  }
-
-  public String getPage() {
-    return page;
-  }
-
-  public void setPage(String page) {
-    this.page = page;
-  }
-
-  public String getFormId() {
-    return formId;
-  }
-
-  public void setFormId(String formId) {
-    this.formId = formId;
-  }
-
-  public List getData() {
-    return data;
-  }
-
-  public void setData(List data) {
-    this.data = data;
-  }
-
-  public String getColor() {
-    return color;
-  }
-
-  public void setColor(String color) {
-    this.color = color;
-  }
-
-  public String getEmphasisKeyword() {
-    return emphasisKeyword;
-  }
-
-  public void setEmphasisKeyword(String emphasisKeyword) {
-    this.emphasisKeyword = emphasisKeyword;
-  }
-
+  @lombok.Data
   public static class Data {
     private String name;
     private String value;
@@ -167,81 +103,6 @@ public Data(String name, String value, String color) {
       this.color = color;
     }
 
-    public String getName() {
-      return this.name;
-    }
-
-    public void setName(String name) {
-      this.name = name;
-    }
-
-    public String getValue() {
-      return this.value;
-    }
-
-    public void setValue(String value) {
-      this.value = value;
-    }
-
-    public String getColor() {
-      return this.color;
-    }
-
-    public void setColor(String color) {
-      this.color = color;
-    }
-
   }
 
-  public static final class Builder {
-    private String toUser;
-    private String templateId;
-    private String page;
-    private String formId;
-    private List data;
-    private String color;
-    private String emphasisKeyword;
-
-    private Builder() {
-    }
-
-    public Builder toUser(String toUser) {
-      this.toUser = toUser;
-      return this;
-    }
-
-    public Builder templateId(String templateId) {
-      this.templateId = templateId;
-      return this;
-    }
-
-    public Builder page(String page) {
-      this.page = page;
-      return this;
-    }
-
-    public Builder formId(String formId) {
-      this.formId = formId;
-      return this;
-    }
-
-    public Builder data(List data) {
-      this.data = data;
-      return this;
-    }
-
-    public Builder color(String color) {
-      this.color = color;
-      return this;
-    }
-
-    public Builder emphasisKeyword(String emphasisKeyword) {
-      this.emphasisKeyword = emphasisKeyword;
-      return this;
-    }
-
-    public WxMaTemplateMessage build() {
-      return new WxMaTemplateMessage(this);
-    }
-  }
 }
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaUserInfo.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaUserInfo.java
index e3cc69d913..8b0ed8fe6a 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaUserInfo.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaUserInfo.java
@@ -1,13 +1,17 @@
 package cn.binarywang.wx.miniapp.bean;
 
 import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
+import lombok.Data;
+
+import java.io.Serializable;
 
 /**
  * @author Binary Wang
  */
-public class WxMaUserInfo {
+@Data
+public class WxMaUserInfo implements Serializable {
+  private static final long serialVersionUID = 6719822331555402137L;
+
   private String openId;
   private String nickName;
   private String gender;
@@ -23,109 +27,9 @@ public static WxMaUserInfo fromJson(String json) {
     return WxMaGsonBuilder.create().fromJson(json, WxMaUserInfo.class);
   }
 
-  @Override
-  public String toString() {
-    return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
-  }
-
-  public String getOpenId() {
-    return openId;
-  }
-
-  public void setOpenId(String openId) {
-    this.openId = openId;
-  }
-
-  public String getNickName() {
-    return nickName;
-  }
-
-  public void setNickName(String nickName) {
-    this.nickName = nickName;
-  }
-
-  public String getGender() {
-    return gender;
-  }
-
-  public void setGender(String gender) {
-    this.gender = gender;
-  }
-
-  public String getLanguage() {
-    return language;
-  }
-
-  public void setLanguage(String language) {
-    this.language = language;
-  }
-
-  public String getCity() {
-    return city;
-  }
-
-  public void setCity(String city) {
-    this.city = city;
-  }
-
-  public String getProvince() {
-    return province;
-  }
-
-  public void setProvince(String province) {
-    this.province = province;
-  }
-
-  public String getCountry() {
-    return country;
-  }
-
-  public void setCountry(String country) {
-    this.country = country;
-  }
-
-  public String getAvatarUrl() {
-    return avatarUrl;
-  }
-
-  public void setAvatarUrl(String avatarUrl) {
-    this.avatarUrl = avatarUrl;
-  }
-
-  public String getUnionId() {
-    return unionId;
-  }
-
-  public void setUnionId(String unionId) {
-    this.unionId = unionId;
-  }
-
-  public Watermark getWatermark() {
-    return watermark;
-  }
-
-  public void setWatermark(Watermark watermark) {
-    this.watermark = watermark;
-  }
-
+  @Data
   public static class Watermark {
     private String timestamp;
     private String appid;
-
-    public String getTimestamp() {
-      return timestamp;
-    }
-
-    public void setTimestamp(String timestamp) {
-      this.timestamp = timestamp;
-    }
-
-    public String getAppid() {
-      return appid;
-    }
-
-    public void setAppid(String appid) {
-      this.appid = appid;
-    }
   }
 }
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaWxcode.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaWxcode.java
index 9ea674ed98..8e629096c6 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaWxcode.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaWxcode.java
@@ -1,17 +1,22 @@
 package cn.binarywang.wx.miniapp.bean;
 
-import cn.binarywang.wx.miniapp.api.WxMaQrcodeService;
 import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
 import com.google.gson.annotations.SerializedName;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
 
 import java.io.Serializable;
 
 /**
- * Created by Element on 2017/7/27.
+ *
+ * @author Element
+ * @date 2017/7/27
  */
-public class WxMaWxcode extends WxMaQrcodeWrapper implements Serializable {
-
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class WxMaWxcode extends AbstractWxMaQrcodeWrapper implements Serializable {
   private static final long serialVersionUID = 1287399621649210322L;
+
   private String path;
   private int width = 430;
 
@@ -19,46 +24,10 @@ public class WxMaWxcode extends WxMaQrcodeWrapper implements Serializable {
   private boolean autoColor = true;
 
   @SerializedName("line_color")
-  private WxMaQrcodeService.LineColor lineColor = new WxMaQrcodeService.LineColor("0", "0", "0");
+  private WxMaCodeLineColor lineColor = new WxMaCodeLineColor("0", "0", "0");
 
   public static WxMaWxcode fromJson(String json) {
     return WxMaGsonBuilder.create().fromJson(json, WxMaWxcode.class);
   }
 
-  public static long getSerialVersionUID() {
-    return serialVersionUID;
-  }
-
-  public String getPath() {
-    return path;
-  }
-
-  public void setPath(String path) {
-    this.path = path;
-  }
-
-  public int getWidth() {
-    return width;
-  }
-
-  public void setWidth(int width) {
-    this.width = width;
-  }
-
-  public boolean isAutoColor() {
-    return autoColor;
-  }
-
-  public void setAutoColor(boolean autoColor) {
-    this.autoColor = autoColor;
-  }
-
-  public WxMaQrcodeService.LineColor getLineColor() {
-    return lineColor;
-  }
-
-  public void setLineColor(WxMaQrcodeService.LineColor lineColor) {
-    this.lineColor = lineColor;
-  }
-
 }
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaWxcodeLimit.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaWxcodeLimit.java
index 7619fe46f2..5f76273b54 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaWxcodeLimit.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaWxcodeLimit.java
@@ -1,15 +1,20 @@
 package cn.binarywang.wx.miniapp.bean;
 
-import cn.binarywang.wx.miniapp.api.WxMaQrcodeService;
 import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
 import com.google.gson.annotations.SerializedName;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
 
 import java.io.Serializable;
 
 /**
- * Created by Element on 2017/7/27.
+ *
+ * @author Element
+ * @date 2017/7/27
  */
-public class WxMaWxcodeLimit extends WxMaQrcodeWrapper implements Serializable {
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class WxMaWxcodeLimit extends AbstractWxMaQrcodeWrapper implements Serializable {
   private static final long serialVersionUID = 4782193774524960401L;
   private String scene;
   private String page;
@@ -20,49 +25,10 @@ public class WxMaWxcodeLimit extends WxMaQrcodeWrapper implements Serializable {
   private boolean autoColor = true;
 
   @SerializedName("line_color")
-  private WxMaQrcodeService.LineColor lineColor = new WxMaQrcodeService.LineColor("0", "0", "0");
+  private WxMaCodeLineColor lineColor = new WxMaCodeLineColor("0", "0", "0");
 
   public static WxMaWxcodeLimit fromJson(String json) {
     return WxMaGsonBuilder.create().fromJson(json, WxMaWxcodeLimit.class);
   }
 
-  public String getPage() {
-    return page;
-  }
-
-  public void setPage(String page) {
-    this.page = page;
-  }
-
-  public String getScene() {
-    return scene;
-  }
-
-  public void setScene(String scene) {
-    this.scene = scene;
-  }
-
-  public int getWidth() {
-    return width;
-  }
-
-  public void setWidth(int width) {
-    this.width = width;
-  }
-
-  public boolean isAutoColor() {
-    return autoColor;
-  }
-
-  public void setAutoColor(boolean autoColor) {
-    this.autoColor = autoColor;
-  }
-
-  public WxMaQrcodeService.LineColor getLineColor() {
-    return lineColor;
-  }
-
-  public void setLineColor(WxMaQrcodeService.LineColor lineColor) {
-    this.lineColor = lineColor;
-  }
 }
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/builder/BaseBuilder.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/builder/BaseBuilder.java
index 70d7cf4b7c..c353534c3f 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/builder/BaseBuilder.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/builder/BaseBuilder.java
@@ -15,6 +15,9 @@ public T toUser(String toUser) {
     return (T) this;
   }
 
+  /**
+   * 构造器方法.
+   */
   public WxMaKefuMessage build() {
     WxMaKefuMessage m = new WxMaKefuMessage();
     m.setMsgType(this.msgType);
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/builder/ImageBuilder.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/builder/ImageBuilder.java
index a903e97c43..d4bd068877 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/builder/ImageBuilder.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/builder/ImageBuilder.java
@@ -13,8 +13,8 @@ public ImageBuilder() {
     this.msgType = WxMaConstants.KefuMsgType.IMAGE;
   }
 
-  public ImageBuilder mediaId(String media_id) {
-    this.mediaId = media_id;
+  public ImageBuilder mediaId(String mediaId) {
+    this.mediaId = mediaId;
     return this;
   }
 
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/WxMaInMemoryConfig.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/WxMaInMemoryConfig.java
index 735a52b56a..7d84c90fbf 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/WxMaInMemoryConfig.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/WxMaInMemoryConfig.java
@@ -175,6 +175,7 @@ public boolean autoRefreshToken() {
     return true;
   }
 
+  @Override
   public String getAppid() {
     return appid;
   }
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaConstants.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaConstants.java
index 14016fa578..ccc492d1e0 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaConstants.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaConstants.java
@@ -8,11 +8,19 @@
  * @author Binary Wang
  */
 public class WxMaConstants {
+  /**
+   * 微信接口返回的参数errcode
+   */
+  public static final String ERRCODE = "errcode";
+
   /**
    * 素材类型
    */
   public static class MediaType {
-    public static final String IMAGE = "image";//图片
+    /**
+     * 图片
+     */
+    public static final String IMAGE = "image";
   }
 
   /**
@@ -27,7 +35,30 @@ public static class MsgDataFormat {
    * 客服消息的消息类型
    */
   public static class KefuMsgType {
-    public static final String TEXT = "text";//文本消息
-    public static final String IMAGE = "image";//图片消息
+    /**
+     * 文本消息
+     */
+    public static final String TEXT = "text";
+    /**
+     * 图片消息
+     */
+    public static final String IMAGE = "image";
+  }
+
+  public static final class ErrorCode {
+    /**
+     * 40001 获取access_token时AppSecret错误,或者access_token无效
+     */
+    public static final int ERR_40001 = 40001;
+
+    /**
+     * 42001 access_token超时
+     */
+    public static final int ERR_42001 = 42001;
+
+    /**
+     * 40014 不合法的access_token,请开发者认真比对access_token的有效性(如是否过期)
+     */
+    public static final int ERR_40014 = 40014;
   }
 }
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouter.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouter.java
index cbe42b1f26..be3af708bd 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouter.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouter.java
@@ -2,6 +2,7 @@
 
 import cn.binarywang.wx.miniapp.api.WxMaService;
 import cn.binarywang.wx.miniapp.bean.WxMaMessage;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
 import me.chanjar.weixin.common.api.WxMessageDuplicateChecker;
 import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker;
@@ -17,10 +18,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
+import java.util.concurrent.*;
 
 /**
  * @author Binary Wang
@@ -42,7 +40,9 @@ public class WxMaMessageRouter {
 
   public WxMaMessageRouter(WxMaService wxMaService) {
     this.wxMaService = wxMaService;
-    this.executorService = Executors.newFixedThreadPool(DEFAULT_THREAD_POOL_SIZE);
+    ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("WxMaMessageRouter-pool-%d").build();
+    this.executorService = new ThreadPoolExecutor(DEFAULT_THREAD_POOL_SIZE, DEFAULT_THREAD_POOL_SIZE,
+      0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), namedThreadFactory);
     this.messageDuplicateChecker = new WxMessageInMemoryDuplicateChecker();
     this.sessionManager = new StandardSessionManager();
     this.exceptionHandler = new LogExceptionHandler();
@@ -159,7 +159,7 @@ public void run() {
   }
 
   public void route(final WxMaMessage wxMessage) {
-    this.route(wxMessage, new HashMap());
+    this.route(wxMessage, new HashMap(2));
   }
 
   /**
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouterRule.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouterRule.java
index 835eb2894a..5353652995 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouterRule.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouterRule.java
@@ -196,7 +196,7 @@ protected void service(WxMaMessage wxMessage,
                          WxSessionManager sessionManager,
                          WxErrorExceptionHandler exceptionHandler) {
     if (context == null) {
-      context = new HashMap<>();
+      context = new HashMap<>(16);
     }
 
     try {
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java
index 3c026f4a18..9b35df8957 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java
@@ -1,6 +1,6 @@
 package cn.binarywang.wx.miniapp.util.http;
 
-import cn.binarywang.wx.miniapp.bean.WxMaQrcodeWrapper;
+import cn.binarywang.wx.miniapp.bean.AbstractWxMaQrcodeWrapper;
 import me.chanjar.weixin.common.bean.result.WxError;
 import me.chanjar.weixin.common.exception.WxErrorException;
 import me.chanjar.weixin.common.util.fs.FileUtils;
@@ -25,7 +25,7 @@
 /**
  * @author Binary Wang
  */
-public class QrCodeRequestExecutor implements RequestExecutor {
+public class QrCodeRequestExecutor implements RequestExecutor {
   protected RequestHttp requestHttp;
 
   public QrCodeRequestExecutor(RequestHttp requestHttp) {
@@ -33,14 +33,12 @@ public QrCodeRequestExecutor(RequestHttp requestHttp) {
   }
 
   @Override
-  public File execute(String uri, WxMaQrcodeWrapper ticket) throws WxErrorException, IOException {
+  public File execute(String uri, AbstractWxMaQrcodeWrapper ticket) throws WxErrorException, IOException {
     HttpPost httpPost = new HttpPost(uri);
     if (requestHttp.getRequestHttpProxy() != null) {
-      httpPost
-        .setConfig(RequestConfig.custom()
-          .setProxy(requestHttp.getRequestHttpProxy())
-          .build()
-        );
+      httpPost.setConfig(
+          RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build()
+      );
     }
     httpPost.setEntity(new StringEntity(ticket.toString()));
 
@@ -48,7 +46,8 @@ public File execute(String uri, WxMaQrcodeWrapper ticket) throws WxErrorExceptio
          InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);) {
       Header[] contentTypeHeader = response.getHeaders("Content-Type");
       if (contentTypeHeader != null && contentTypeHeader.length > 0
-        && ContentType.APPLICATION_JSON.getMimeType().equals(contentTypeHeader[0].getValue())) {
+          && ContentType.APPLICATION_JSON.getMimeType()
+          .equals(ContentType.parse(contentTypeHeader[0].getValue()).getMimeType())) {
         String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
         throw new WxErrorException(WxError.fromJson(responseContent));
       }
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/xml/XStreamTransformer.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/xml/XStreamTransformer.java
index f85c716acb..578bf68c71 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/xml/XStreamTransformer.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/xml/XStreamTransformer.java
@@ -18,7 +18,7 @@ public class XStreamTransformer {
   }
 
   /**
-   * xml -> pojo
+   * xml -> pojo.
    */
   @SuppressWarnings("unchecked")
   public static  T fromXml(Class clazz, String xml) {
@@ -33,14 +33,14 @@ public static  T fromXml(Class clazz, InputStream is) {
   }
 
   /**
-   * pojo -> xml
+   * pojo -> xml.
    */
   public static  String toXml(Class clazz, T object) {
     return CLASS_2_XSTREAM_INSTANCE.get(clazz).toXML(object);
   }
 
   /**
-   * 注册扩展消息的解析器
+   * 注册扩展消息的解析器.
    *
    * @param clz     类型
    * @param xStream xml解析器
@@ -50,12 +50,14 @@ private static void register(Class clz, XStream xStream) {
   }
 
   /**
-   * 会自动注册该类及其子类
+   * 会自动注册该类及其子类.
    *
    * @param clz 要注册的类
    */
   private static void registerClass(Class clz) {
     XStream xstream = XStreamInitializer.getInstance();
+    xstream.setClassLoader(Thread.currentThread().getContextClassLoader());
+
     xstream.processAnnotations(clz);
     xstream.processAnnotations(getInnerClasses(clz));
     if (clz.equals(WxMaMessage.class)) {
diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaMsgServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaMsgServiceImplTest.java
index 37e3608bff..d6aa31a71f 100644
--- a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaMsgServiceImplTest.java
+++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaMsgServiceImplTest.java
@@ -31,7 +31,7 @@ public void testSendKefuMpNewsMessage() throws WxErrorException {
     TestConfig configStorage = (TestConfig) this.wxService
       .getWxMaConfig();
     WxMaKefuMessage message = new WxMaKefuMessage();
-    message.setMsgType(WxConsts.CUSTOM_MSG_MPNEWS);
+    message.setMsgType(WxConsts.KefuMsgType.MPNEWS);
     message.setToUser(configStorage.getOpenid());
 
     this.wxService.getMsgService().sendKefuMsg(message);
@@ -41,7 +41,7 @@ public void testSendKefuMessage() throws WxErrorException {
     TestConfig config = (TestConfig) this.wxService
       .getWxMaConfig();
     WxMaKefuMessage message = new WxMaKefuMessage();
-    message.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
+    message.setMsgType(WxConsts.KefuMsgType.TEXT);
     message.setToUser(config.getOpenid());
     message.setContent(
       "欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World");
@@ -54,7 +54,7 @@ public void testSendTemplateMsg() throws WxErrorException {
     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
     TestConfig config = (TestConfig) this.wxService.getWxMaConfig();
 
-    WxMaTemplateMessage templateMessage = WxMaTemplateMessage.newBuilder()
+    WxMaTemplateMessage templateMessage = WxMaTemplateMessage.builder()
       .toUser(config.getOpenid())
       .formId("FORMID")
       .page("index")
diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/WxMaKefuMessageTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/WxMaKefuMessageTest.java
index f2ef8bfac5..667ab2de63 100644
--- a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/WxMaKefuMessageTest.java
+++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/WxMaKefuMessageTest.java
@@ -13,26 +13,26 @@ public class WxMaKefuMessageTest {
   public void testTextReply() {
     WxMaKefuMessage reply = new WxMaKefuMessage();
     reply.setToUser("OPENID");
-    reply.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
+    reply.setMsgType(WxConsts.KefuMsgType.TEXT);
     reply.setContent("sfsfdsdf");
     Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
   }
 
   public void testTextBuild() {
-    WxMaKefuMessage reply = WxMaKefuMessage.TEXT().toUser("OPENID").content("sfsfdsdf").build();
+    WxMaKefuMessage reply = WxMaKefuMessage.newTextBuilder().toUser("OPENID").content("sfsfdsdf").build();
     Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
   }
 
   public void testImageReply() {
     WxMaKefuMessage reply = new WxMaKefuMessage();
     reply.setToUser("OPENID");
-    reply.setMsgType(WxConsts.CUSTOM_MSG_IMAGE);
+    reply.setMsgType(WxConsts.KefuMsgType.IMAGE);
     reply.setMediaId("MEDIA_ID");
     Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
   }
 
   public void testImageBuild() {
-    WxMaKefuMessage reply = WxMaKefuMessage.IMAGE().toUser("OPENID").mediaId("MEDIA_ID").build();
+    WxMaKefuMessage reply = WxMaKefuMessage.newImageBuilder().toUser("OPENID").mediaId("MEDIA_ID").build();
     Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
   }
 
diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/WxMaMessageTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/WxMaMessageTest.java
index cdf989a6af..fa7d3ebb92 100644
--- a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/WxMaMessageTest.java
+++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/WxMaMessageTest.java
@@ -60,7 +60,7 @@ public void testFromXml() {
     assertEquals(wxMessage.getToUser(), "toUser");
     assertEquals(wxMessage.getFromUser(), "fromUser");
     assertEquals(wxMessage.getCreateTime(), new Long(1348831860L));
-    assertEquals(wxMessage.getMsgType(), WxConsts.XML_MSG_TEXT);
+    assertEquals(wxMessage.getMsgType(), WxConsts.XmlMsgType.TEXT);
     assertEquals(wxMessage.getContent(), "this is a test");
     assertEquals(wxMessage.getMsgId(), new Long(1234567890123456L));
     assertEquals(wxMessage.getPicUrl(), "this is a url");
@@ -118,7 +118,7 @@ public void testFromXml2() {
     assertEquals(wxMessage.getToUser(), "toUser");
     assertEquals(wxMessage.getFromUser(), "fromUser");
     assertEquals(wxMessage.getCreateTime(), new Integer(1348831860));
-    assertEquals(wxMessage.getMsgType(), WxConsts.XML_MSG_TEXT);
+    assertEquals(wxMessage.getMsgType(), WxConsts.XmlMsgType.TEXT);
     assertEquals(wxMessage.getContent(), "this is a test");
     assertEquals(wxMessage.getMsgId(), new Long(1234567890123456L));
     assertEquals(wxMessage.getPicUrl(), "this is a url");
diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/WxMaTemplateMessageTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/WxMaTemplateMessageTest.java
index ad6e62c2ca..d4464312eb 100644
--- a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/WxMaTemplateMessageTest.java
+++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/WxMaTemplateMessageTest.java
@@ -11,7 +11,7 @@
 public class WxMaTemplateMessageTest {
   @Test
   public void testToJson() throws Exception {
-    WxMaTemplateMessage tm = WxMaTemplateMessage.newBuilder()
+    WxMaTemplateMessage tm = WxMaTemplateMessage.builder()
       .toUser("OPENID")
       //.color("aaaaa")
       .formId("FORMID")
diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/demo/WxMaDemoServer.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/demo/WxMaDemoServer.java
index f6dcbae27b..8d14b261ff 100644
--- a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/demo/WxMaDemoServer.java
+++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/demo/WxMaDemoServer.java
@@ -34,7 +34,7 @@ public class WxMaDemoServer {
     public void handle(WxMaMessage wxMessage, Map context,
                        WxMaService service, WxSessionManager sessionManager) throws WxErrorException {
       System.out.println("收到消息:" + wxMessage.toString());
-      service.getMsgService().sendKefuMsg(WxMaKefuMessage.TEXT().content("收到信息为:" + wxMessage.toJson())
+      service.getMsgService().sendKefuMsg(WxMaKefuMessage.newTextBuilder().content("收到信息为:" + wxMessage.toJson())
         .toUser(wxMessage.getFromUser()).build());
     }
   };
@@ -44,7 +44,7 @@ public void handle(WxMaMessage wxMessage, Map context,
     public void handle(WxMaMessage wxMessage, Map context,
                        WxMaService service, WxSessionManager sessionManager)
       throws WxErrorException {
-      service.getMsgService().sendKefuMsg(WxMaKefuMessage.TEXT().content("回复文本消息")
+      service.getMsgService().sendKefuMsg(WxMaKefuMessage.newTextBuilder().content("回复文本消息")
         .toUser(wxMessage.getFromUser()).build());
     }
 
@@ -60,7 +60,7 @@ public void handle(WxMaMessage wxMessage, Map context,
             ClassLoader.getSystemResourceAsStream("tmp.png"));
         service.getMsgService().sendKefuMsg(
           WxMaKefuMessage
-            .IMAGE()
+            .newImageBuilder()
             .mediaId(uploadResult.getMediaId())
             .toUser(wxMessage.getFromUser())
             .build());
@@ -79,7 +79,7 @@ public void handle(WxMaMessage wxMessage, Map context,
         WxMediaUploadResult uploadResult = service.getMediaService().uploadMedia(WxMaConstants.MediaType.IMAGE, file);
         service.getMsgService().sendKefuMsg(
           WxMaKefuMessage
-            .IMAGE()
+            .newImageBuilder()
             .mediaId(uploadResult.getMediaId())
             .toUser(wxMessage.getFromUser())
             .build());
@@ -94,7 +94,7 @@ public void handle(WxMaMessage wxMessage, Map context,
     public void handle(WxMaMessage wxMessage, Map context,
                        WxMaService service, WxSessionManager sessionManager)
       throws WxErrorException {
-      service.getMsgService().sendTemplateMsg(WxMaTemplateMessage.newBuilder()
+      service.getMsgService().sendTemplateMsg(WxMaTemplateMessage.builder()
         .templateId(templateId).data(Lists.newArrayList(
           new WxMaTemplateMessage.Data("keyword1", "339208499", "#173177")))
         .toUser(wxMessage.getFromUser())
diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml
index 81ec2c01ab..a135b6dda6 100644
--- a/weixin-java-mp/pom.xml
+++ b/weixin-java-mp/pom.xml
@@ -7,7 +7,7 @@
   
     com.github.binarywang
     weixin-java-parent
-    2.8.0
+    2.9.0
   
   weixin-java-mp
   WeiXin Java Tools - MP
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInRedisConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInRedisConfigStorage.java
index d22214dfa1..6974221c10 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInRedisConfigStorage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInRedisConfigStorage.java
@@ -1,11 +1,15 @@
 package me.chanjar.weixin.mp.api;
 
 import redis.clients.jedis.Jedis;
+import redis.clients.jedis.JedisPool;
 
 /**
  * 基于Redis的微信配置provider
- *
- * @author lly835
+ * 
+ *    使用说明:本实现仅供参考,并不完整,
+ *    比如为减少项目依赖,未加入redis分布式锁的实现,如有需要请自行实现。
+ * 
+ * @author nickwong */ @SuppressWarnings("hiding") public class WxMpInRedisConfigStorage extends WxMpInMemoryConfigStorage { @@ -16,75 +20,115 @@ public class WxMpInRedisConfigStorage extends WxMpInMemoryConfigStorage { private final static String CARDAPI_TICKET_KEY = "wechat_cardapi_ticket_"; - protected Jedis jedis; + /** + * 使用连接池保证线程安全 + */ + protected final JedisPool jedisPool; + + private String accessTokenKey; + + private String jsapiTicketKey; + + private String cardapiTicketKey; + + public WxMpInRedisConfigStorage(JedisPool jedisPool) { + this.jedisPool = jedisPool; + } + + /** + * 每个公众号生成独有的存储key + * + * @param appId + */ + @Override + public void setAppId(String appId) { + super.setAppId(appId); + this.accessTokenKey = ACCESS_TOKEN_KEY.concat(appId); + this.jsapiTicketKey = JSAPI_TICKET_KEY.concat(appId); + this.cardapiTicketKey = CARDAPI_TICKET_KEY.concat(appId); + } @Override public String getAccessToken() { - return jedis.get(ACCESS_TOKEN_KEY.concat(appId)); + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.get(accessTokenKey); + } } @Override public boolean isAccessTokenExpired() { - return jedis.ttl(ACCESS_TOKEN_KEY.concat(appId)) < 2; + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.ttl(accessTokenKey) < 2; + } } @Override public synchronized void updateAccessToken(String accessToken, int expiresInSeconds) { - jedis.set(ACCESS_TOKEN_KEY.concat(appId), accessToken); - jedis.expire(ACCESS_TOKEN_KEY.concat(appId), expiresInSeconds - 200); + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.setex(accessTokenKey, expiresInSeconds - 200, accessToken); + } } @Override public void expireAccessToken() { - jedis.expire(ACCESS_TOKEN_KEY.concat(appId), 0); + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.expire(accessTokenKey, 0); + } } @Override public String getJsapiTicket() { - return jedis.get(JSAPI_TICKET_KEY.concat(appId)); + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.get(jsapiTicketKey); + } } @Override public boolean isJsapiTicketExpired() { - return jedis.ttl(JSAPI_TICKET_KEY.concat(appId)) < 2; + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.ttl(jsapiTicketKey) < 2; + } } @Override public synchronized void updateJsapiTicket(String jsapiTicket, int expiresInSeconds) { - jedis.set(JSAPI_TICKET_KEY.concat(appId), jsapiTicket); - jedis.expire(JSAPI_TICKET_KEY.concat(appId), expiresInSeconds - 200); + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.setex(jsapiTicketKey, expiresInSeconds - 200, jsapiTicket); + } } @Override public void expireJsapiTicket() { - jedis.expire(JSAPI_TICKET_KEY.concat(appId), 0); + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.expire(jsapiTicketKey, 0); + } } - /** - * 卡券api_ticket - */ @Override public String getCardApiTicket() { - return jedis.get(CARDAPI_TICKET_KEY.concat(appId)); + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.get(cardapiTicketKey); + } } @Override public boolean isCardApiTicketExpired() { - return jedis.ttl(CARDAPI_TICKET_KEY.concat(appId)) < 2; + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.ttl(cardapiTicketKey) < 2; + } } @Override public synchronized void updateCardApiTicket(String cardApiTicket, int expiresInSeconds) { - jedis.set(CARDAPI_TICKET_KEY.concat(appId), cardApiTicket); - jedis.expire(CARDAPI_TICKET_KEY.concat(appId), expiresInSeconds - 200); + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.setex(cardapiTicketKey, expiresInSeconds - 200, cardApiTicket); + } } @Override public void expireCardApiTicket() { - jedis.expire(CARDAPI_TICKET_KEY.concat(appId), 0); - } - - public void setJedis(Jedis jedis) { - this.jedis = jedis; + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.expire(cardapiTicketKey, 0); + } } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpKefuService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpKefuService.java index 36e13b13c4..9e0de39c4b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpKefuService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpKefuService.java @@ -92,11 +92,10 @@ public interface WxMpKefuService { *
    * 上传客服头像
    * 详情请见:客服管理
-   * 接口url格式:http://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?access_token=ACCESS_TOKEN&kf_account=KFACCOUNT
+   * 接口url格式:https://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?access_token=ACCESS_TOKEN&kf_account=KFACCOUNT
    * 
*/ - boolean kfAccountUploadHeadImg(String kfAccount, File imgFile) - throws WxErrorException; + boolean kfAccountUploadHeadImg(String kfAccount, File imgFile) throws WxErrorException; /** *
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMassMessageService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMassMessageService.java
index 6d1f025728..a7aacd544c 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMassMessageService.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMassMessageService.java
@@ -94,7 +94,7 @@ public interface WxMpMassMessageService {
    *
    * @return wxMpMassSendResult
    */
-  WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage) throws Exception;
+  WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage) throws WxErrorException;
 
   /**
    * 
@@ -114,6 +114,6 @@ public interface WxMpMassMessageService {
    * @param msgId        发送出去的消息ID
    * @param articleIndex 要删除的文章在图文消息中的位置,第一篇编号为1,该字段不填或填0会删除全部文章
    */
-  void delete(Integer msgId, Integer articleIndex) throws Exception;
+  void delete(Integer msgId, Integer articleIndex) throws WxErrorException;
 
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java
index 5acf0040aa..6b7ddd08e2 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java
@@ -10,6 +10,7 @@
 import me.chanjar.weixin.common.util.LogExceptionHandler;
 import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
 import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -195,16 +196,17 @@ public WxMpXmlOutMessage route(final WxMpXmlMessage wxMessage) {
   }
 
   protected boolean isMsgDuplicated(WxMpXmlMessage wxMessage) {
-
     StringBuilder messageId = new StringBuilder();
     if (wxMessage.getMsgId() == null) {
       messageId.append(wxMessage.getCreateTime())
         .append("-").append(wxMessage.getFromUser())
-        .append("-").append(wxMessage.getEventKey() == null ? "" : wxMessage.getEventKey())
-        .append("-").append(wxMessage.getEvent() == null ? "" : wxMessage.getEvent())
+        .append("-").append(StringUtils.trimToEmpty(wxMessage.getEventKey()))
+        .append("-").append(StringUtils.trimToEmpty(wxMessage.getEvent()))
       ;
     } else {
-      messageId.append(wxMessage.getMsgId());
+      messageId.append(wxMessage.getMsgId())
+        .append("-").append(wxMessage.getCreateTime())
+        .append("-").append(wxMessage.getFromUser());
     }
 
     return this.messageDuplicateChecker.isDuplicate(messageId.toString());
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
index 914c902d44..0dd5a66bd3 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
@@ -5,8 +5,11 @@
 import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
 import me.chanjar.weixin.common.util.http.RequestExecutor;
 import me.chanjar.weixin.common.util.http.RequestHttp;
-import me.chanjar.weixin.mp.bean.*;
-import me.chanjar.weixin.mp.bean.result.*;
+import me.chanjar.weixin.mp.bean.WxMpSemanticQuery;
+import me.chanjar.weixin.mp.bean.result.WxMpCurrentAutoReplyInfo;
+import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
+import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
+import me.chanjar.weixin.mp.bean.result.WxMpUser;
 
 /**
  * 微信API的Service
@@ -62,6 +65,11 @@ public interface WxMpService {
    */
   String GET_CURRENT_AUTOREPLY_INFO_URL = "https://api.weixin.qq.com/cgi-bin/get_current_autoreply_info";
 
+  /**
+   * 公众号调用或第三方平台帮公众号调用对公众号的所有api调用(包括第三方帮其调用)次数进行清零
+   */
+  String CLEAR_QUOTA_URL = "https://api.weixin.qq.com/cgi-bin/clear_quota";
+
   /**
    * 
    * 验证消息的确来自微信服务器
@@ -219,6 +227,18 @@ public interface WxMpService {
    */
   WxMpCurrentAutoReplyInfo getCurrentAutoReplyInfo() throws WxErrorException;
 
+  /**
+   * 
+   *  公众号调用或第三方平台帮公众号调用对公众号的所有api调用(包括第三方帮其调用)次数进行清零:
+   *  HTTP调用:https://api.weixin.qq.com/cgi-bin/clear_quota?access_token=ACCESS_TOKEN
+   *  接口文档地址:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433744592
+   *
+   * 
+ * + * @param appid 公众号的APPID + */ + void clearQuota(String appid) throws WxErrorException; + /** * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求 */ @@ -376,6 +396,7 @@ public interface WxMpService { /** * 返回群发消息相关接口方法的实现类对象,以方便调用其各个接口 + * * @return WxMpMassMessageService */ WxMpMassMessageService getMassMessageService(); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpShakeService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpShakeService.java index 87a6747af5..697bfe899d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpShakeService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpShakeService.java @@ -1,8 +1,10 @@ package me.chanjar.weixin.mp.api; +import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult; import me.chanjar.weixin.mp.bean.WxMpShakeQuery; +import me.chanjar.weixin.mp.bean.shake.*; /** * 摇一摇周边的相关接口 @@ -24,4 +26,36 @@ public interface WxMpShakeService { */ WxMpShakeInfoResult getShakeInfo(WxMpShakeQuery wxMpShakeQuery) throws WxErrorException; + /** + *
+   * 页面管理
+ * 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1459246752 + *
+ * @param shakeAroundPageAddQuery + * @return + * @throws WxErrorException + */ + WxMpShakeAroundPageAddResult pageAdd(WxMpShakeAroundPageAddQuery shakeAroundPageAddQuery) throws WxErrorException; + + /** + *
+   * 配置设备与页面的关联关系
+ * 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1459301931 + *
+ * @param shakeAroundDeviceBindPageQuery + * @return + * @throws WxErrorException + */ + WxError deviceBindPageQuery(WxMpShakeAroundDeviceBindPageQuery shakeAroundDeviceBindPageQuery) throws WxErrorException; + + /** + *
+   * 查询设备与页面的关联关系
+ * 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1443447914 + *
+ * @param shakeAroundRelationSearchQuery + * @return + * @throws WxErrorException + */ + WxMpShakeAroundRelationSearchResult relationSearch(WxMpShakeAroundRelationSearchQuery shakeAroundRelationSearchQuery) throws WxErrorException; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java index 2634c3f36c..fa349c93b2 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java @@ -9,11 +9,19 @@ /** * 门店管理的相关接口代码 + *

+ * Created by Binary Wang on 2016-09-23. * - * @author binarywang(Binary Wang) - * Created by Binary Wang on 2016-09-23. + * @author Binary Wang */ public interface WxMpStoreService { + String POI_GET_WX_CATEGORY_URL = "https://api.weixin.qq.com/cgi-bin/poi/getwxcategory"; + String POI_UPDATE_URL = "https://api.weixin.qq.com/cgi-bin/poi/updatepoi"; + String POI_LIST_URL = "https://api.weixin.qq.com/cgi-bin/poi/getpoilist"; + String POI_DEL_URL = "https://api.weixin.qq.com/cgi-bin/poi/delpoi"; + String POI_GET_URL = "https://api.weixin.qq.com/cgi-bin/poi/getpoi"; + String POI_ADD_URL = "https://api.weixin.qq.com/cgi-bin/poi/addpoi"; + /** *

    * 创建门店
@@ -22,7 +30,7 @@ public interface WxMpStoreService {
    * 创建门店接口调用成功后会返回errcode 0、errmsg ok,但不会实时返回poi_id。
    * 成功创建后,会生成poi_id,但该id不一定为最终id。门店信息会经过审核,审核通过后方可获取最终poi_id,该id为门店的唯一id,强烈建议自行存储审核通过后的最终poi_id,并为后续调用使用。
    * 详情请见: 微信门店接口
-   * 接口格式: http://api.weixin.qq.com/cgi-bin/poi/addpoi?access_token=TOKEN
+   * 接口格式: https://api.weixin.qq.com/cgi-bin/poi/addpoi?access_token=TOKEN
    * 
*/ void add(WxMpStoreBaseInfo request) throws WxErrorException; @@ -35,11 +43,10 @@ public interface WxMpStoreService { * 最终结果会在5 个工作日内,最终确认是否采纳,并前端生效(但该扩展字段的采纳过程不影响门店的可用性,即available_state仍为审核通过状态) * 注:扩展字段为公共编辑信息(大家都可修改),修改将会审核,并决定是否对修改建议进行采纳,但不会影响该门店的生效可用状态。 * 详情请见: 微信门店接口 - * 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getpoi?access_token=TOKEN + * 接口格式:https://api.weixin.qq.com/cgi-bin/poi/getpoi?access_token=TOKEN *
* * @param poiId 门店Id - * @throws WxErrorException */ WxMpStoreBaseInfo get(String poiId) throws WxErrorException; @@ -48,11 +55,10 @@ public interface WxMpStoreService { * 删除门店 * 商户可以通过该接口,删除已经成功创建的门店。请商户慎重调用该接口。 * 详情请见: 微信门店接口 - * 接口格式:http://api.weixin.qq.com/cgi-bin/poi/delpoi?access_token=TOKEN + * 接口格式:https://api.weixin.qq.com/cgi-bin/poi/delpoi?access_token=TOKEN *
* * @param poiId 门店Id - * @throws WxErrorException */ void delete(String poiId) throws WxErrorException; @@ -61,12 +67,11 @@ public interface WxMpStoreService { * 查询门店列表(指定查询起始位置和个数) * 商户可以通过该接口,批量查询自己名下的门店list,并获取已审核通过的poi_id(所有状态均会返回poi_id,但该poi_id不一定为最终id)、商户自身sid 用于对应、商户名、分店名、地址字段。 * 详情请见: 微信门店接口 - * 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=TOKEN + * 接口格式:https://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=TOKEN *
* * @param begin 开始位置,0 即为从第一条开始查询 * @param limit 返回数据条数,最大允许50,默认为20 - * @throws WxErrorException */ WxMpStoreListResult list(int begin, int limit) throws WxErrorException; @@ -75,10 +80,8 @@ public interface WxMpStoreService { * 查询门店列表(所有) * 商户可以通过该接口,批量查询自己名下的门店list,并获取已审核通过的poi_id(所有状态均会返回poi_id,但该poi_id不一定为最终id)、商户自身sid 用于对应、商户名、分店名、地址字段。 * 详情请见: 微信门店接口 - * 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=TOKEN + * 接口格式:https://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=TOKEN *
- * - * @throws WxErrorException */ List listAll() throws WxErrorException; @@ -87,10 +90,8 @@ public interface WxMpStoreService { * 修改门店服务信息 * 商户可以通过该接口,修改门店的服务信息,包括:sid、图片列表、营业时间、推荐、特色服务、简介、人均价格、电话8个字段(名称、坐标、地址等不可修改)修改后需要人工审核。 * 详情请见: 微信门店接口 - * 接口格式:http://api.weixin.qq.com/cgi-bin/poi/updatepoi?access_token=TOKEN + * 接口格式:https://api.weixin.qq.com/cgi-bin/poi/updatepoi?access_token=TOKEN * - * - * @throws WxErrorException */ void update(WxMpStoreBaseInfo info) throws WxErrorException; @@ -99,10 +100,8 @@ public interface WxMpStoreService { * 门店类目表 * 类目名称接口是为商户提供自己门店类型信息的接口。门店类目定位的越规范,能够精准的吸引更多用户,提高曝光率。 * 详情请见: 微信门店接口 - * 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getwxcategory?access_token=TOKEN + * 接口格式:https://api.weixin.qq.com/cgi-bin/poi/getwxcategory?access_token=TOKEN * - * - * @throws WxErrorException */ List listCategories() throws WxErrorException; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpTemplateMsgService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpTemplateMsgService.java index f9203c1644..494813ecae 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpTemplateMsgService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpTemplateMsgService.java @@ -13,7 +13,7 @@ * http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN * Created by Binary Wang on 2016-10-14. * @author miller.lin - * @author binarywang(Binary Wang) + * @author Binary Wang * */ public interface WxMpTemplateMsgService { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java index 4a666eff1b..ce218922c3 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java @@ -10,7 +10,7 @@ * 用户标签管理相关接口 * Created by Binary Wang on 2016/9/2. * - * @author binarywang(Binary Wang) + * @author Binary Wang */ public interface WxMpUserTagService { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImpl.java index 8ec5945f7b..49ed7589f3 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImpl.java @@ -229,10 +229,9 @@ public String getCardDetail(String cardId) throws WxErrorException { String errcode = json.get("errcode").getAsString(); if (!"0".equals(errcode)) { String errmsg = json.get("errmsg").getAsString(); - WxError error = new WxError(); - error.setErrorCode(Integer.valueOf(errcode)); - error.setErrorMsg(errmsg); - throw new WxErrorException(error); + throw new WxErrorException(WxError.builder() + .errorCode(Integer.valueOf(errcode)).errorMsg(errmsg) + .build()); } return responseContent; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java index 8d98a07a32..6bda9e5caf 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java @@ -112,11 +112,11 @@ public WxMpKfSessionWaitCaseList kfSessionGetWaitCase() throws WxErrorException @Override public WxMpKfMsgList kfMsgList(Date startTime, Date endTime, Long msgId, Integer number) throws WxErrorException { if (number > 10000) { - throw new WxErrorException(WxError.newBuilder().setErrorMsg("非法参数请求,每次最多查询10000条记录!").build()); + throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("非法参数请求,每次最多查询10000条记录!").build()); } if (startTime.after(endTime)) { - throw new WxErrorException(WxError.newBuilder().setErrorMsg("起始时间不能晚于结束时间!").build()); + throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("起始时间不能晚于结束时间!").build()); } JsonObject param = new JsonObject(); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMassMessageServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMassMessageServiceImpl.java index c54fcc768c..779bbc4d9d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMassMessageServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMassMessageServiceImpl.java @@ -51,13 +51,13 @@ public WxMpMassSendResult massOpenIdsMessageSend(WxMpMassOpenIdsMessage message) } @Override - public WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage) throws Exception { + public WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage) throws WxErrorException { String responseContent = this.wxMpService.post(MESSAGE_MASS_PREVIEW_URL, wxMpMassPreviewMessage.toJson()); return WxMpMassSendResult.fromJson(responseContent); } @Override - public void delete(Integer msgId, Integer articleIndex) throws Exception { + public void delete(Integer msgId, Integer articleIndex) throws WxErrorException { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("msg_id", msgId); jsonObject.addProperty("article_idx", articleIndex); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImpl.java index 90594fe031..520f69ea0d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImpl.java @@ -5,7 +5,7 @@ import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; -import me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor; +import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor; import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; import me.chanjar.weixin.common.util.json.WxGsonBuilder; import me.chanjar.weixin.mp.api.WxMpMaterialService; @@ -37,8 +37,7 @@ public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputS try { return this.mediaUpload(mediaType, FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), fileType)); } catch (IOException e) { - e.printStackTrace(); - throw new WxErrorException(WxError.newBuilder().setErrorMsg(e.getMessage()).build()); + throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg(e.getMessage()).build(), e); } } @@ -51,7 +50,7 @@ public WxMediaUploadResult mediaUpload(String mediaType, File file) throws WxErr @Override public File mediaDownload(String mediaId) throws WxErrorException { return this.wxMpService.execute( - MediaDownloadRequestExecutor.create(this.wxMpService.getRequestHttp(), this.wxMpService.getWxMpConfigStorage().getTmpDirFile()), + BaseMediaDownloadRequestExecutor.create(this.wxMpService.getRequestHttp(), this.wxMpService.getWxMpConfigStorage().getTmpDirFile()), MEDIA_GET_URL, "media_id=" + mediaId); } @@ -122,7 +121,7 @@ public WxMpMaterialCountResult materialCount() throws WxErrorException { @Override public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(int offset, int count) throws WxErrorException { Map params = new HashMap<>(); - params.put("type", WxConsts.MATERIAL_NEWS); + params.put("type", WxConsts.MaterialType.NEWS); params.put("offset", offset); params.put("count", count); String responseText = this.wxMpService.post(MATERIAL_BATCHGET_URL, WxGsonBuilder.create().toJson(params)); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java index 5f6c3ad54f..f6af96e5f8 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java @@ -28,13 +28,13 @@ public WxMpQrcodeServiceImpl(WxMpService wxMpService) { @Override public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException { if (sceneId == 0) { - throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("临时二维码场景值不能为0!").build()); + throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("临时二维码场景值不能为0!").build()); } //expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。 if (expireSeconds != null && expireSeconds > 2592000) { - throw new WxErrorException(WxError.newBuilder().setErrorCode(-1) - .setErrorMsg("临时二维码有效时间最大不能超过2592000(即30天)!").build()); + throw new WxErrorException(WxError.builder().errorCode(-1) + .errorMsg("临时二维码有效时间最大不能超过2592000(即30天)!").build()); } if (expireSeconds == null) { @@ -59,13 +59,13 @@ public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds @Override public WxMpQrCodeTicket qrCodeCreateTmpTicket(String sceneStr, Integer expireSeconds) throws WxErrorException { if (StringUtils.isBlank(sceneStr)) { - throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("临时二维码场景值不能为空!").build()); + throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("临时二维码场景值不能为空!").build()); } //expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。 if (expireSeconds != null && expireSeconds > 2592000) { - throw new WxErrorException(WxError.newBuilder().setErrorCode(-1) - .setErrorMsg("临时二维码有效时间最大不能超过2592000(即30天)!").build()); + throw new WxErrorException(WxError.builder().errorCode(-1) + .errorMsg("临时二维码有效时间最大不能超过2592000(即30天)!").build()); } if (expireSeconds == null) { @@ -90,7 +90,9 @@ public WxMpQrCodeTicket qrCodeCreateTmpTicket(String sceneStr, Integer expireSec @Override public WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId) throws WxErrorException { if (sceneId < 1 || sceneId > 100000) { - throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("永久二维码的场景值目前只支持1--100000!").build()); + throw new WxErrorException(WxError.builder().errorCode(-1) + .errorMsg("永久二维码的场景值目前只支持1--100000!") + .build()); } String url = API_URL_PREFIX + "/create"; @@ -137,9 +139,7 @@ public String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErr return resultUrl; } catch (UnsupportedEncodingException e) { - WxError error = WxError.newBuilder().setErrorCode(-1) - .setErrorMsg(e.getMessage()).build(); - throw new WxErrorException(error); + throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg(e.getMessage()).build()); } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceAbstractImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceAbstractImpl.java index e4482d5aa7..d81018daa5 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceAbstractImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceAbstractImpl.java @@ -28,7 +28,7 @@ public abstract class WxMpServiceAbstractImpl implements WxMpService, Requ protected final Logger log = LoggerFactory.getLogger(this.getClass()); protected WxSessionManager sessionManager = new StandardSessionManager(); - private WxMpConfigStorage wxMpConfigStorage; + protected WxMpConfigStorage wxMpConfigStorage; private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this); private WxMpMaterialService materialService = new WxMpMaterialServiceImpl(this); private WxMpMenuService menuService = new WxMpMenuServiceImpl(this); @@ -67,7 +67,7 @@ public String getJsapiTicket() throws WxErrorException { @Override public String getJsapiTicket(boolean forceRefresh) throws WxErrorException { - Lock lock = this.getWxMpConfigStorage().getAccessTokenLock(); + Lock lock = this.getWxMpConfigStorage().getJsapiTicketLock(); try { lock.lock(); if (forceRefresh) { @@ -207,6 +207,13 @@ public WxMpCurrentAutoReplyInfo getCurrentAutoReplyInfo() throws WxErrorExceptio return WxMpCurrentAutoReplyInfo.fromJson(this.get(GET_CURRENT_AUTOREPLY_INFO_URL, null)); } + @Override + public void clearQuota(String appid) throws WxErrorException { + JsonObject o = new JsonObject(); + o.addProperty("appid", appid); + this.post(CLEAR_QUOTA_URL, o.toString()); + } + @Override public String get(String url, String queryParam) throws WxErrorException { return execute(SimpleGetRequestExecutor.create(this), url, queryParam); @@ -252,7 +259,7 @@ public T execute(RequestExecutor executor, String uri, E data) thro throw new RuntimeException("微信服务端异常,超出重试次数"); } - public synchronized T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException { + public T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException { if (uri.contains("access_token=")) { throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java index 4d2017dd63..79317f99fc 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java @@ -4,8 +4,9 @@ *
  * 默认接口实现类,使用apache httpclient实现
  * Created by Binary Wang on 2017-5-27.
- * @author binarywang(Binary Wang)
  * 
+ * + * @author Binary Wang */ public class WxMpServiceImpl extends WxMpServiceApacheHttpClientImpl { } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceOkHttpImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceOkHttpImpl.java index 9066dc8d17..b5135cebcb 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceOkHttpImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceOkHttpImpl.java @@ -5,19 +5,13 @@ import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.HttpType; import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo; -import me.chanjar.weixin.mp.api.WxMpConfigStorage; import me.chanjar.weixin.mp.api.WxMpService; import okhttp3.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.concurrent.locks.Lock; public class WxMpServiceOkHttpImpl extends WxMpServiceAbstractImpl { - - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private OkHttpClient httpClient; private OkHttpProxyInfo httpProxy; @@ -38,7 +32,7 @@ public HttpType getRequestType() { @Override public String getAccessToken(boolean forceRefresh) throws WxErrorException { - logger.debug("WxMpServiceOkHttpImpl is running"); + this.log.debug("WxMpServiceOkHttpImpl is running"); Lock lock = this.getWxMpConfigStorage().getAccessTokenLock(); try { lock.lock(); @@ -59,7 +53,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException { accessToken.getExpiresIn()); } } catch (IOException e) { - e.printStackTrace(); + this.log.error(e.getMessage(), e); } finally { lock.unlock(); } @@ -68,14 +62,17 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException { @Override public void initHttp() { - logger.debug("WxMpServiceOkHttpImpl initHttp"); - WxMpConfigStorage configStorage = this.getWxMpConfigStorage(); + this.log.debug("WxMpServiceOkHttpImpl initHttp"); - if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) { - httpProxy = OkHttpProxyInfo.socks5Proxy(configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort(), configStorage.getHttpProxyUsername(), configStorage.getHttpProxyPassword()); + //设置代理 + if (wxMpConfigStorage.getHttpProxyHost() != null && wxMpConfigStorage.getHttpProxyPort() > 0) { + httpProxy = OkHttpProxyInfo.httpProxy(wxMpConfigStorage.getHttpProxyHost(), + wxMpConfigStorage.getHttpProxyPort(), + wxMpConfigStorage.getHttpProxyUsername(), + wxMpConfigStorage.getHttpProxyPassword()); } + OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder(); - //设置代理 if (httpProxy != null) { clientBuilder.proxy(getRequestHttpProxy().getProxy()); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpShakeServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpShakeServiceImpl.java index bee636fd54..2c90f70e2b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpShakeServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpShakeServiceImpl.java @@ -1,13 +1,16 @@ package me.chanjar.weixin.mp.api.impl; +import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpShakeService; import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult; import me.chanjar.weixin.mp.bean.WxMpShakeQuery; +import me.chanjar.weixin.mp.bean.shake.*; /** * Created by rememberber on 2017/6/5. + * * @author rememberber */ public class WxMpShakeServiceImpl implements WxMpShakeService { @@ -27,7 +30,7 @@ public WxMpShakeServiceImpl(WxMpService wxMpService) { * 接口地址:https://api.weixin.qq.com/shakearound/user/getshakeinfo?access_token=ACCESS_TOKE * * - * @param wxMpShakeQuery 查询参数 + * @param wxMpShakeQuery 查询参数 */ @Override public WxMpShakeInfoResult getShakeInfo(WxMpShakeQuery wxMpShakeQuery) throws WxErrorException { @@ -36,4 +39,28 @@ public WxMpShakeInfoResult getShakeInfo(WxMpShakeQuery wxMpShakeQuery) throws Wx String responseContent = this.wxMpService.post(url, postData); return WxMpShakeInfoResult.fromJson(responseContent); } + + @Override + public WxMpShakeAroundPageAddResult pageAdd(WxMpShakeAroundPageAddQuery shakeAroundPageAddQuery) throws WxErrorException { + String url = "https://api.weixin.qq.com/shakearound/page/add"; + String postData = shakeAroundPageAddQuery.toJsonString(); + String responseContent = this.wxMpService.post(url, postData); + return WxMpShakeAroundPageAddResult.fromJson(responseContent); + } + + @Override + public WxError deviceBindPageQuery(WxMpShakeAroundDeviceBindPageQuery shakeAroundDeviceBindPageQuery) throws WxErrorException { + String url = "https://api.weixin.qq.com/shakearound/device/bindpage"; + String postData = shakeAroundDeviceBindPageQuery.toJsonString(); + String responseContent = this.wxMpService.post(url, postData); + return WxError.fromJson(responseContent); + } + + @Override + public WxMpShakeAroundRelationSearchResult relationSearch(WxMpShakeAroundRelationSearchQuery shakeAroundRelationSearchQuery) throws WxErrorException { + String url = "https://api.weixin.qq.com/shakearound/relation/search"; + String postData = shakeAroundRelationSearchQuery.toJsonString(); + String responseContent = this.wxMpService.post(url, postData); + return WxMpShakeAroundRelationSearchResult.fromJson(responseContent); + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java index 5f1b5f2a82..00c0c1097c 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java @@ -21,8 +21,6 @@ * @author binarywang (https://github.com/binarywang) */ public class WxMpStoreServiceImpl implements WxMpStoreService { - private static final String API_BASE_URL = "http://api.weixin.qq.com/cgi-bin/poi"; - private WxMpService wxMpService; public WxMpStoreServiceImpl(WxMpService wxMpService) { @@ -33,8 +31,7 @@ public WxMpStoreServiceImpl(WxMpService wxMpService) { public void add(WxMpStoreBaseInfo request) throws WxErrorException { BeanUtils.checkRequiredFields(request); - String url = API_BASE_URL + "/addpoi"; - String response = this.wxMpService.post(url, request.toJson()); + String response = this.wxMpService.post(POI_ADD_URL, request.toJson()); WxError wxError = WxError.fromJson(response); if (wxError.getErrorCode() != 0) { throw new WxErrorException(wxError); @@ -43,10 +40,9 @@ public void add(WxMpStoreBaseInfo request) throws WxErrorException { @Override public WxMpStoreBaseInfo get(String poiId) throws WxErrorException { - String url = API_BASE_URL + "/getpoi"; JsonObject paramObject = new JsonObject(); paramObject.addProperty("poi_id", poiId); - String response = this.wxMpService.post(url, paramObject.toString()); + String response = this.wxMpService.post(POI_GET_URL, paramObject.toString()); WxError wxError = WxError.fromJson(response); if (wxError.getErrorCode() != 0) { throw new WxErrorException(wxError); @@ -57,10 +53,9 @@ public WxMpStoreBaseInfo get(String poiId) throws WxErrorException { @Override public void delete(String poiId) throws WxErrorException { - String url = API_BASE_URL + "/delpoi"; JsonObject paramObject = new JsonObject(); paramObject.addProperty("poi_id", poiId); - String response = this.wxMpService.post(url, paramObject.toString()); + String response = this.wxMpService.post(POI_DEL_URL, paramObject.toString()); WxError wxError = WxError.fromJson(response); if (wxError.getErrorCode() != 0) { throw new WxErrorException(wxError); @@ -70,11 +65,10 @@ public void delete(String poiId) throws WxErrorException { @Override public WxMpStoreListResult list(int begin, int limit) throws WxErrorException { - String url = API_BASE_URL + "/getpoilist"; JsonObject params = new JsonObject(); params.addProperty("begin", begin); params.addProperty("limit", limit); - String response = this.wxMpService.post(url, params.toString()); + String response = this.wxMpService.post(POI_LIST_URL, params.toString()); WxError wxError = WxError.fromJson(response); if (wxError.getErrorCode() != 0) { @@ -107,8 +101,7 @@ public List listAll() throws WxErrorException { @Override public void update(WxMpStoreBaseInfo request) throws WxErrorException { - String url = API_BASE_URL + "/updatepoi"; - String response = this.wxMpService.post(url, request.toJson()); + String response = this.wxMpService.post(POI_UPDATE_URL, request.toJson()); WxError wxError = WxError.fromJson(response); if (wxError.getErrorCode() != 0) { throw new WxErrorException(wxError); @@ -117,8 +110,7 @@ public void update(WxMpStoreBaseInfo request) throws WxErrorException { @Override public List listCategories() throws WxErrorException { - String url = API_BASE_URL + "/getwxcategory"; - String response = this.wxMpService.get(url, null); + String response = this.wxMpService.get(POI_GET_WX_CATEGORY_URL, null); WxError wxError = WxError.fromJson(response); if (wxError.getErrorCode() != 0) { throw new WxErrorException(wxError); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImpl.java index 82ce829cdd..7b73f102d6 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImpl.java @@ -15,8 +15,9 @@ /** *
  * Created by Binary Wang on 2016-10-14.
- * @author binarywang(Binary Wang)
  * 
+ * + * @author Binary Wang */ public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService { public static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/template"; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java index 99f271065c..e5357b1ed7 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java @@ -16,8 +16,9 @@ import java.util.List; /** - * @author binarywang(Binary Wang) - * Created by Binary Wang on 2016/9/2. + * Created by Binary Wang on 2016/9/2. + * + * @author Binary Wang */ public class WxMpUserTagServiceImpl implements WxMpUserTagService { private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/tags"; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCard.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCard.java index 76fc4a6451..0fcb9185ee 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCard.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCard.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import java.io.Serializable; @@ -11,6 +12,7 @@ * @author YuJian * @version 15/11/11 */ +@Data public class WxMpCard implements Serializable{ private static final long serialVersionUID = 9214301870017772921L; @@ -24,46 +26,6 @@ public class WxMpCard implements Serializable{ private Boolean canConsume; - public String getCardId() { - return this.cardId; - } - - public void setCardId(String cardId) { - this.cardId = cardId; - } - - public Long getBeginTime() { - return this.beginTime; - } - - public void setBeginTime(Long beginTime) { - this.beginTime = beginTime; - } - - public Long getEndTime() { - return this.endTime; - } - - public void setEndTime(Long endTime) { - this.endTime = endTime; - } - - public String getUserCardStatus() { - return this.userCardStatus; - } - - public void setUserCardStatus(String userCardStatus) { - this.userCardStatus = userCardStatus; - } - - public Boolean getCanConsume() { - return this.canConsume; - } - - public void setCanConsume(Boolean canConsume) { - this.canConsume = canConsume; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassNews.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassNews.java index bb19f0e79e..b2ef87b1d6 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassNews.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassNews.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -12,15 +13,12 @@ * * @author chanjarster */ +@Data public class WxMpMassNews implements Serializable { private static final long serialVersionUID = 565937155013581016L; private List articles = new ArrayList<>(); - public List getArticles() { - return this.articles; - } - public void addArticle(WxMpMassNewsArticle article) { this.articles.add(article); } @@ -52,6 +50,7 @@ public String toString() { * * @author chanjarster */ + @Data public static class WxMpMassNewsArticle { /** * (必填) 图文消息缩略图的media_id,可以在基础支持-上传多媒体文件接口中获得 @@ -82,62 +81,6 @@ public static class WxMpMassNewsArticle { */ private boolean showCoverPic; - public String getThumbMediaId() { - return this.thumbMediaId; - } - - public void setThumbMediaId(String thumbMediaId) { - this.thumbMediaId = thumbMediaId; - } - - public String getAuthor() { - return this.author; - } - - public void setAuthor(String author) { - this.author = author; - } - - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getContentSourceUrl() { - return this.contentSourceUrl; - } - - public void setContentSourceUrl(String contentSourceUrl) { - this.contentSourceUrl = contentSourceUrl; - } - - public String getContent() { - return this.content; - } - - public void setContent(String content) { - this.content = content; - } - - public String getDigest() { - return this.digest; - } - - public void setDigest(String digest) { - this.digest = digest; - } - - public boolean isShowCoverPic() { - return this.showCoverPic; - } - - public void setShowCoverPic(boolean showCoverPic) { - this.showCoverPic = showCoverPic; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassOpenIdsMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassOpenIdsMessage.java index 73b6c9e241..7f480e3fa4 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassOpenIdsMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassOpenIdsMessage.java @@ -1,5 +1,7 @@ package me.chanjar.weixin.mp.bean; +import lombok.Data; +import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.Serializable; @@ -11,93 +13,47 @@ * * @author chanjarster */ +@Data public class WxMpMassOpenIdsMessage implements Serializable { private static final long serialVersionUID = -8022910911104788999L; + /** + * openid列表,最多支持10,000个 + */ private List toUsers = new ArrayList<>(); - private String msgType; - private String content; - private String mediaId; - private boolean sendIgnoreReprint = false; - - public WxMpMassOpenIdsMessage() { - super(); - } - - public String getMsgType() { - return this.msgType; - } /** *
    * 请使用
-   * {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_IMAGE}
-   * {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_NEWS}
-   * {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_TEXT}
-   * {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_VIDEO}
-   * {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_VOICE}
+   * {@link WxConsts.MassMsgType#IMAGE}
+   * {@link WxConsts.MassMsgType#MPNEWS}
+   * {@link WxConsts.MassMsgType#TEXT}
+   * {@link WxConsts.MassMsgType#MPVIDEO}
+   * {@link WxConsts.MassMsgType#VOICE}
    * 如果msgtype和media_id不匹配的话,会返回系统繁忙的错误
    * 
- * - * @param msgType */ - public void setMsgType(String msgType) { - this.msgType = msgType; - } - - public String getContent() { - return this.content; - } - - public void setContent(String content) { - this.content = content; - } - - public String getMediaId() { - return this.mediaId; - } + private String msgType; + private String content; + private String mediaId; + /** + * 文章被判定为转载时,是否继续进行群发操作。 + */ + private boolean sendIgnoreReprint = false; - public void setMediaId(String mediaId) { - this.mediaId = mediaId; + public WxMpMassOpenIdsMessage() { + super(); } public String toJson() { return WxMpGsonBuilder.INSTANCE.create().toJson(this); } - /** - * openid列表,最多支持10,000个 - */ - public List getToUsers() { - return this.toUsers; - } - - /** - * 提供set方法,方便客户端直接设置所有群发对象的openid列表 - * - * @param toUsers - */ - public void setToUsers(List toUsers) { - this.toUsers = toUsers; - } - /** * 添加openid,最多支持10,000个 - * - * @param openid */ public void addUser(String openid) { this.toUsers.add(openid); } - public boolean isSendIgnoreReprint() { - return sendIgnoreReprint; - } - - /** - * @param sendIgnoreReprint 文章被判定为转载时,是否继续进行群发操作。 - */ - public void setSendIgnoreReprint(boolean sendIgnoreReprint) { - this.sendIgnoreReprint = sendIgnoreReprint; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassPreviewMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassPreviewMessage.java index 503bdec43b..512c454c47 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassPreviewMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassPreviewMessage.java @@ -1,5 +1,7 @@ package me.chanjar.weixin.mp.bean; +import lombok.Data; +import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.Serializable; @@ -7,70 +9,30 @@ /** * @author miller */ +@Data public class WxMpMassPreviewMessage implements Serializable { private static final long serialVersionUID = 9095211638358424020L; private String toWxUserName; private String toWxUserOpenid; - private String msgType; - private String content; - private String mediaId; - - public WxMpMassPreviewMessage() { - super(); - } - - public String getToWxUserName() { - return this.toWxUserName; - } - - public void setToWxUserName(String toWxUserName) { - this.toWxUserName = toWxUserName; - } - - public String getMsgType() { - return this.msgType; - } - /** *
+   * 消息类型
    * 请使用
-   * {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_IMAGE}
-   * {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_NEWS}
-   * {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_TEXT}
-   * {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_VIDEO}
-   * {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_VOICE}
+   * {@link WxConsts.MassMsgType#IMAGE}
+   * {@link WxConsts.MassMsgType#MPNEWS}
+   * {@link WxConsts.MassMsgType#TEXT}
+   * {@link WxConsts.MassMsgType#MPVIDEO}
+   * {@link WxConsts.MassMsgType#VOICE}
    * 如果msgtype和media_id不匹配的话,会返回系统繁忙的错误
    * 
- * - * @param msgType 消息类型 */ - public void setMsgType(String msgType) { - this.msgType = msgType; - } - - public String getContent() { - return this.content; - } - - public void setContent(String content) { - this.content = content; - } - - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } - - public String getToWxUserOpenid() { - return this.toWxUserOpenid; - } + private String msgType; + private String content; + private String mediaId; - public void setToWxUserOpenid(String toWxUserOpenid) { - this.toWxUserOpenid = toWxUserOpenid; + public WxMpMassPreviewMessage() { + super(); } public String toJson() { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java index acf9d0f4c1..5bcd408441 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java @@ -1,5 +1,7 @@ package me.chanjar.weixin.mp.bean; +import lombok.Data; +import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.Serializable; @@ -9,90 +11,44 @@ * * @author chanjarster */ +@Data public class WxMpMassTagMessage implements Serializable { private static final long serialVersionUID = -6625914040986749286L; + /** + * 标签id,如果不设置则就意味着发给所有用户 + */ private Long tagId; - private String msgType; - private String content; - private String mediaId; - private boolean isSendAll = false; - private boolean sendIgnoreReprint = false; - - public WxMpMassTagMessage() { - super(); - } - - public String getMsgType() { - return this.msgType; - } - /** *
+   * 消息类型
    * 请使用
-   * {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_IMAGE}
-   * {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_NEWS}
-   * {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_TEXT}
-   * {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_VIDEO}
-   * {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_VOICE}
+   * {@link WxConsts.MassMsgType#IMAGE}
+   * {@link WxConsts.MassMsgType#MPNEWS}
+   * {@link WxConsts.MassMsgType#TEXT}
+   * {@link WxConsts.MassMsgType#MPVIDEO}
+   * {@link WxConsts.MassMsgType#VOICE}
    * 如果msgtype和media_id不匹配的话,会返回系统繁忙的错误
    * 
- * - * @param msgType 消息类型 */ - public void setMsgType(String msgType) { - this.msgType = msgType; - } - - public String getContent() { - return this.content; - } - - public void setContent(String content) { - this.content = content; - } - - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } - - public String toJson() { - return WxMpGsonBuilder.INSTANCE.create().toJson(this); - } - - public Long getTagId() { - return this.tagId; - } - + private String msgType; + private String content; + private String mediaId; /** - * 如果不设置则就意味着发给所有用户 - * - * @param tagId 标签id + * 是否群发给所有用户 */ - public void setTagId(Long tagId) { - this.tagId = tagId; - } - - public boolean isSendIgnoreReprint() { - return sendIgnoreReprint; - } - + private boolean isSendAll = false; /** - * @param sendIgnoreReprint 文章被判定为转载时,是否继续进行群发操作。 + * 文章被判定为转载时,是否继续进行群发操作。 */ - public void setSendIgnoreReprint(boolean sendIgnoreReprint) { - this.sendIgnoreReprint = sendIgnoreReprint; + private boolean sendIgnoreReprint = false; + + public WxMpMassTagMessage() { + super(); } - /** - * 是否群发给所有用户 - */ - public boolean isSendAll() { - return isSendAll; + public String toJson() { + return WxMpGsonBuilder.INSTANCE.create().toJson(this); } public void setSendAll(boolean sendAll) { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassVideo.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassVideo.java index 1683be5bdf..d536ff989f 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassVideo.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassVideo.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean; +import lombok.Data; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.Serializable; @@ -9,6 +10,7 @@ * * @author chanjarster */ +@Data public class WxMpMassVideo implements Serializable { private static final long serialVersionUID = 9153925016061915637L; @@ -16,30 +18,6 @@ public class WxMpMassVideo implements Serializable { private String title; private String description; - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } - public String toJson() { return WxMpGsonBuilder.INSTANCE.create().toJson(this); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpSemanticQuery.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpSemanticQuery.java index 8c18a6a9ea..f9de30f552 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpSemanticQuery.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpSemanticQuery.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean; +import lombok.Data; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.Serializable; @@ -11,6 +12,7 @@ * * @author Daniel Qian */ +@Data public class WxMpSemanticQuery implements Serializable { private static final long serialVersionUID = 7685873048199870690L; @@ -23,70 +25,6 @@ public class WxMpSemanticQuery implements Serializable { private String appid; private String uid; - public String getQuery() { - return this.query; - } - - public void setQuery(String query) { - this.query = query; - } - - public String getCategory() { - return this.category; - } - - public void setCategory(String category) { - this.category = category; - } - - public Float getLatitude() { - return this.latitude; - } - - public void setLatitude(Float latitude) { - this.latitude = latitude; - } - - public Float getLongitude() { - return this.longitude; - } - - public void setLongitude(Float longitude) { - this.longitude = longitude; - } - - public String getCity() { - return this.city; - } - - public void setCity(String city) { - this.city = city; - } - - public String getRegion() { - return this.region; - } - - public void setRegion(String region) { - this.region = region; - } - - public String getAppid() { - return this.appid; - } - - public void setAppid(String appid) { - this.appid = appid; - } - - public String getUid() { - return this.uid; - } - - public void setUid(String uid) { - this.uid = uid; - } - public String toJson() { return WxMpGsonBuilder.create().toJson(this); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpShakeInfoResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpShakeInfoResult.java index 5fb2ab1735..313cfaba84 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpShakeInfoResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpShakeInfoResult.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean; +import lombok.Data; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.Serializable; @@ -10,6 +11,7 @@ * * @author rememberber */ +@Data public class WxMpShakeInfoResult implements Serializable { private static final long serialVersionUID = -1604561297395395468L; @@ -17,13 +19,15 @@ public class WxMpShakeInfoResult implements Serializable { private String errmsg; - private Data data; + private ShakeInfoData data; public static WxMpShakeInfoResult fromJson(String json) { return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpShakeInfoResult.class); } - public class Data { + @Data + public class ShakeInfoData implements Serializable { + private static final long serialVersionUID = -4828142206067489488L; private String page_id; @@ -35,7 +39,9 @@ public class Data { private BeaconInfo beacon_info; - public class BeaconInfo { + @Data + public class BeaconInfo implements Serializable { + private static final long serialVersionUID = -8995733049982933362L; private double distance; @@ -48,118 +54,7 @@ public class BeaconInfo { private Integer rssi; private String uuid; - - public double getDistance() { - return distance; - } - - public void setDistance(double distance) { - this.distance = distance; - } - - public Integer getMajor() { - return major; - } - - public void setMajor(Integer major) { - this.major = major; - } - - public Integer getMeasure_power() { - return measure_power; - } - - public void setMeasure_power(Integer measure_power) { - this.measure_power = measure_power; - } - - public Integer getMinor() { - return minor; - } - - public void setMinor(Integer minor) { - this.minor = minor; - } - - public Integer getRssi() { - return rssi; - } - - public void setRssi(Integer rssi) { - this.rssi = rssi; - } - - public String getUuid() { - return uuid; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - } - - public String getPage_id() { - return page_id; - } - - public void setPage_id(String page_id) { - this.page_id = page_id; - } - - public String getOpenid() { - return openid; - } - - public void setOpenid(String openid) { - this.openid = openid; - } - - public String getPoi_id() { - return poi_id; - } - - public void setPoi_id(String poi_id) { - this.poi_id = poi_id; - } - - public BeaconInfo getBeacon_info() { - return beacon_info; - } - - public void setBeacon_info(BeaconInfo beacon_info) { - this.beacon_info = beacon_info; - } - - public String getBrand_userame() { - return brand_userame; - } - - public void setBrand_userame(String brand_userame) { - this.brand_userame = brand_userame; } } - public Integer getErrcode() { - return errcode; - } - - public void setErrcode(Integer errcode) { - this.errcode = errcode; - } - - public String getErrmsg() { - return errmsg; - } - - public void setErrmsg(String errmsg) { - this.errmsg = errmsg; - } - - public Data getData() { - return data; - } - - public void setData(Data data) { - this.data = data; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpShakeQuery.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpShakeQuery.java index 0f4aeadd19..709e59e50f 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpShakeQuery.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpShakeQuery.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean; import com.google.gson.Gson; +import lombok.Data; import java.io.Serializable; import java.util.HashMap; @@ -11,6 +12,7 @@ * * @author rememberber */ +@Data public class WxMpShakeQuery implements Serializable { private static final long serialVersionUID = 4316527352035275412L; @@ -25,19 +27,4 @@ public String toJsonString() { return new Gson().toJson(map); } - public String getTicket() { - return ticket; - } - - public void setTicket(String ticket) { - this.ticket = ticket; - } - - public int getNeedPoi() { - return needPoi; - } - - public void setNeedPoi(int needPoi) { - this.needPoi = needPoi; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpUserQuery.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpUserQuery.java index 243163c28b..9e73b46159 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpUserQuery.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpUserQuery.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean; import com.google.gson.Gson; +import lombok.Data; import java.io.Serializable; import java.util.ArrayList; @@ -14,6 +15,7 @@ * * @author LiuJunGuang */ +@Data public class WxMpUserQuery implements Serializable { private static final long serialVersionUID = -1344224837373149313L; @@ -110,19 +112,18 @@ public String toJsonString() { } // 查询参数封装 + @Data public class WxMpUserQueryParam implements Serializable { private static final long serialVersionUID = -6863571795702385319L; private String openid; private String lang; public WxMpUserQueryParam(String openid, String lang) { - super(); this.openid = openid; this.lang = lang; } public WxMpUserQueryParam(String openid) { - super(); this.openid = openid; this.lang = "zh_CN"; } @@ -131,56 +132,6 @@ public WxMpUserQueryParam() { super(); } - public String getOpenid() { - return this.openid; - } - - public void setOpenid(String openid) { - this.openid = openid; - } - - public String getLang() { - return this.lang; - } - - public void setLang(String lang) { - this.lang = lang; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + getOuterType().hashCode(); - result = prime * result + ((this.lang == null) ? 0 : this.lang.hashCode()); - result = prime * result + ((this.openid == null) ? 0 : this.openid.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - WxMpUserQueryParam other = (WxMpUserQueryParam) obj; - if (!getOuterType().equals(other.getOuterType())) - return false; - if (this.lang == null) { - if (other.lang != null) - return false; - } else if (!this.lang.equals(other.lang)) - return false; - if (this.openid == null) { - if (other.openid != null) - return false; - } else if (!this.openid.equals(other.openid)) - return false; - return true; - } - private WxMpUserQuery getOuterType() { return WxMpUserQuery.this; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleResult.java index e6518064bb..3901c61fbc 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleResult.java @@ -1,18 +1,22 @@ package me.chanjar.weixin.mp.bean.datacube; -import com.google.gson.JsonParser; import com.google.gson.annotations.SerializedName; import com.google.gson.reflect.TypeToken; +import lombok.Data; +import lombok.EqualsAndHashCode; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.util.List; /** * 图文分析数据接口返回结果对象 + *

+ * Created by Binary Wang on 2016/8/24. * - * @author binarywang(Binary Wang) - * Created by Binary Wang on 2016/8/24. + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) public class WxDataCubeArticleResult extends WxDataCubeBaseResult { private static final long serialVersionUID = -9222452497954511765L; @@ -116,107 +120,4 @@ public static List fromJson(String json) { }.getType()); } - public Integer getRefHour() { - return this.refHour; - } - - public void setRefHour(Integer refHour) { - this.refHour = refHour; - } - - public String getMsgId() { - return this.msgId; - } - - public void setMsgId(String msgId) { - this.msgId = msgId; - } - - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } - - public Integer getIntPageReadUser() { - return this.intPageReadUser; - } - - public void setIntPageReadUser(Integer intPageReadUser) { - this.intPageReadUser = intPageReadUser; - } - - public Integer getIntPageReadCount() { - return this.intPageReadCount; - } - - public void setIntPageReadCount(Integer intPageReadCount) { - this.intPageReadCount = intPageReadCount; - } - - public Integer getOriPageReadUser() { - return this.oriPageReadUser; - } - - public void setOriPageReadUser(Integer oriPageReadUser) { - this.oriPageReadUser = oriPageReadUser; - } - - public Integer getOriPageReadCount() { - return this.oriPageReadCount; - } - - public void setOriPageReadCount(Integer oriPageReadCount) { - this.oriPageReadCount = oriPageReadCount; - } - - public Integer getShareScene() { - return this.shareScene; - } - - public void setShareScene(Integer shareScene) { - this.shareScene = shareScene; - } - - public Integer getShareUser() { - return this.shareUser; - } - - public void setShareUser(Integer shareUser) { - this.shareUser = shareUser; - } - - public Integer getShareCount() { - return this.shareCount; - } - - public void setShareCount(Integer shareCount) { - this.shareCount = shareCount; - } - - public Integer getAddToFavUser() { - return this.addToFavUser; - } - - public void setAddToFavUser(Integer addToFavUser) { - this.addToFavUser = addToFavUser; - } - - public Integer getAddToFavCount() { - return this.addToFavCount; - } - - public void setAddToFavCount(Integer addToFavCount) { - this.addToFavCount = addToFavCount; - } - - public Integer getUserSource() { - return this.userSource; - } - - public void setUserSource(Integer userSource) { - this.userSource = userSource; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotal.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotal.java index a059c45f3b..bef0e66d15 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotal.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotal.java @@ -1,37 +1,40 @@ package me.chanjar.weixin.mp.bean.datacube; -import com.google.gson.JsonParser; import com.google.gson.annotations.SerializedName; import com.google.gson.reflect.TypeToken; +import lombok.Data; +import lombok.EqualsAndHashCode; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.util.List; /** - * 图文分析数据接口返回结果对象 + * 图文分析数据接口返回结果对象. + * Created by Binary Wang on 2016/8/24. * - * @author binarywang(Binary Wang) - * Created by Binary Wang on 2016/8/24. + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) public class WxDataCubeArticleTotal extends WxDataCubeBaseResult { private static final long serialVersionUID = -7634365687303052699L; /** - * msgid + * msgid. * 请注意:这里的msgid实际上是由msgid(图文消息id,这也就是群发接口调用后返回的msg_data_id)和index(消息次序索引)组成, 例如12003_3, 其中12003是msgid,即一次群发的消息的id; 3为index,假设该次群发的图文消息共5个文章(因为可能为多图文),3表示5个中的第3个 */ @SerializedName("msgid") private String msgId; /** - * title + * title. * 图文消息的标题 */ @SerializedName("title") private String title; /** - * details + * details. * 详细信息 */ @SerializedName("details") @@ -44,27 +47,4 @@ public static List fromJson(String json) { }.getType()); } - public String getMsgId() { - return this.msgId; - } - - public void setMsgId(String msgId) { - this.msgId = msgId; - } - - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } - - public List getDetails() { - return this.details; - } - - public void setDetails(List details) { - this.details = details; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotalDetail.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotalDetail.java index 86897427d1..0c3bf2916c 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotalDetail.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotalDetail.java @@ -1,16 +1,19 @@ package me.chanjar.weixin.mp.bean.datacube; import com.google.gson.annotations.SerializedName; +import lombok.Data; import java.io.Serializable; /** * 获取图文群发总数据接口(getarticletotal)中的详细字段 + *

+ * Created by Binary Wang on 2016/8/24. * - * @author binarywang(Binary Wang) - * Created by Binary Wang on 2016/8/24. + * @author Binary Wang */ -public class WxDataCubeArticleTotalDetail implements Serializable{ +@Data +public class WxDataCubeArticleTotalDetail implements Serializable { private static final long serialVersionUID = -5136169129771430052L; /** @@ -195,215 +198,4 @@ public class WxDataCubeArticleTotalDetail implements Serializable{ @SerializedName("feed_share_from_other_cnt") private Integer feedShareFromOtherCnt; - public String getStatDate() { - return this.statDate; - } - - public void setStatDate(String statDate) { - this.statDate = statDate; - } - - public Integer getTargetUser() { - return this.targetUser; - } - - public void setTargetUser(Integer targetUser) { - this.targetUser = targetUser; - } - - public Integer getIntPageReadUser() { - return this.intPageReadUser; - } - - public void setIntPageReadUser(Integer intPageReadUser) { - this.intPageReadUser = intPageReadUser; - } - - public Integer getIntPageReadCount() { - return this.intPageReadCount; - } - - public void setIntPageReadCount(Integer intPageReadCount) { - this.intPageReadCount = intPageReadCount; - } - - public Integer getOriPageReadUser() { - return this.oriPageReadUser; - } - - public void setOriPageReadUser(Integer oriPageReadUser) { - this.oriPageReadUser = oriPageReadUser; - } - - public Integer getOriPageReadCount() { - return this.oriPageReadCount; - } - - public void setOriPageReadCount(Integer oriPageReadCount) { - this.oriPageReadCount = oriPageReadCount; - } - - public Integer getShareUser() { - return this.shareUser; - } - - public void setShareUser(Integer shareUser) { - this.shareUser = shareUser; - } - - public Integer getShareCount() { - return this.shareCount; - } - - public void setShareCount(Integer shareCount) { - this.shareCount = shareCount; - } - - public Integer getAddToFavUser() { - return this.addToFavUser; - } - - public void setAddToFavUser(Integer addToFavUser) { - this.addToFavUser = addToFavUser; - } - - public Integer getAddToFavCount() { - return this.addToFavCount; - } - - public void setAddToFavCount(Integer addToFavCount) { - this.addToFavCount = addToFavCount; - } - - public Integer getIntPageFromSessionReadUser() { - return this.intPageFromSessionReadUser; - } - - public void setIntPageFromSessionReadUser(Integer intPageFromSessionReadUser) { - this.intPageFromSessionReadUser = intPageFromSessionReadUser; - } - - public Integer getIntPageFromSessionReadCount() { - return this.intPageFromSessionReadCount; - } - - public void setIntPageFromSessionReadCount( - Integer intPageFromSessionReadCount) { - this.intPageFromSessionReadCount = intPageFromSessionReadCount; - } - - public Integer getIntPageFromHistMsgReadUser() { - return this.intPageFromHistMsgReadUser; - } - - public void setIntPageFromHistMsgReadUser(Integer intPageFromHistMsgReadUser) { - this.intPageFromHistMsgReadUser = intPageFromHistMsgReadUser; - } - - public Integer getIntPageFromHistMsgReadCount() { - return this.intPageFromHistMsgReadCount; - } - - public void setIntPageFromHistMsgReadCount( - Integer intPageFromHistMsgReadCount) { - this.intPageFromHistMsgReadCount = intPageFromHistMsgReadCount; - } - - public Integer getIntPageFromFeedReadUser() { - return this.intPageFromFeedReadUser; - } - - public void setIntPageFromFeedReadUser(Integer intPageFromFeedReadUser) { - this.intPageFromFeedReadUser = intPageFromFeedReadUser; - } - - public Integer getIntPageFromFeedReadCount() { - return this.intPageFromFeedReadCount; - } - - public void setIntPageFromFeedReadCount(Integer intPageFromFeedReadCount) { - this.intPageFromFeedReadCount = intPageFromFeedReadCount; - } - - public Integer getIntPageFromFriendsReadUser() { - return this.intPageFromFriendsReadUser; - } - - public void setIntPageFromFriendsReadUser(Integer intPageFromFriendsReadUser) { - this.intPageFromFriendsReadUser = intPageFromFriendsReadUser; - } - - public Integer getIntPageFromFriendsReadCount() { - return this.intPageFromFriendsReadCount; - } - - public void setIntPageFromFriendsReadCount( - Integer intPageFromFriendsReadCount) { - this.intPageFromFriendsReadCount = intPageFromFriendsReadCount; - } - - public Integer getIntPageFromOtherReadUser() { - return this.intPageFromOtherReadUser; - } - - public void setIntPageFromOtherReadUser(Integer intPageFromOtherReadUser) { - this.intPageFromOtherReadUser = intPageFromOtherReadUser; - } - - public Integer getIntPageFromOtherReadCount() { - return this.intPageFromOtherReadCount; - } - - public void setIntPageFromOtherReadCount(Integer intPageFromOtherReadCount) { - this.intPageFromOtherReadCount = intPageFromOtherReadCount; - } - - public Integer getFeedShareFromSessionUser() { - return this.feedShareFromSessionUser; - } - - public void setFeedShareFromSessionUser(Integer feedShareFromSessionUser) { - this.feedShareFromSessionUser = feedShareFromSessionUser; - } - - public Integer getFeedShareFromSessionCnt() { - return this.feedShareFromSessionCnt; - } - - public void setFeedShareFromSessionCnt(Integer feedShareFromSessionCnt) { - this.feedShareFromSessionCnt = feedShareFromSessionCnt; - } - - public Integer getFeedShareFromFeedUser() { - return this.feedShareFromFeedUser; - } - - public void setFeedShareFromFeedUser(Integer feedShareFromFeedUser) { - this.feedShareFromFeedUser = feedShareFromFeedUser; - } - - public Integer getFeedShareFromFeedCnt() { - return this.feedShareFromFeedCnt; - } - - public void setFeedShareFromFeedCnt(Integer feedShareFromFeedCnt) { - this.feedShareFromFeedCnt = feedShareFromFeedCnt; - } - - public Integer getFeedShareFromOtherUser() { - return this.feedShareFromOtherUser; - } - - public void setFeedShareFromOtherUser(Integer feedShareFromOtherUser) { - this.feedShareFromOtherUser = feedShareFromOtherUser; - } - - public Integer getFeedShareFromOtherCnt() { - return this.feedShareFromOtherCnt; - } - - public void setFeedShareFromOtherCnt(Integer feedShareFromOtherCnt) { - this.feedShareFromOtherCnt = feedShareFromOtherCnt; - } - } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeBaseResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeBaseResult.java index cfc8636143..df86ab4e15 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeBaseResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeBaseResult.java @@ -2,24 +2,26 @@ import com.google.gson.JsonParser; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import java.io.Serializable; /** *

- *  统计接口的共用属性类
+ *  统计接口的共用属性类.
  *  Created by Binary Wang on 2016/8/25.
  * 
* - * @author binarywang(Binary Wang) + * @author Binary Wang */ +@Data public abstract class WxDataCubeBaseResult implements Serializable { private static final long serialVersionUID = 8780389911053297600L; protected static final JsonParser JSON_PARSER = new JsonParser(); /** - * ref_date + * ref_date. * 数据的日期,需在begin_date和end_date之间 */ @SerializedName("ref_date") @@ -30,12 +32,4 @@ public String toString() { return ToStringUtils.toSimpleString(this); } - public String getRefDate() { - return this.refDate; - } - - public void setRefDate(String refDate) { - this.refDate = refDate; - } - } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeInterfaceResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeInterfaceResult.java index fce9fc2018..b151c0089f 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeInterfaceResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeInterfaceResult.java @@ -1,18 +1,22 @@ package me.chanjar.weixin.mp.bean.datacube; -import com.google.gson.JsonParser; import com.google.gson.annotations.SerializedName; import com.google.gson.reflect.TypeToken; +import lombok.Data; +import lombok.EqualsAndHashCode; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.util.List; /** * 接口分析数据接口返回结果对象 + *

+ * Created by Binary Wang on 2016/8/30. * - * @author binarywang(Binary Wang) - * Created by Binary Wang on 2016/8/30. + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) public class WxDataCubeInterfaceResult extends WxDataCubeBaseResult { private static final long serialVersionUID = 597734329161281398L; @@ -58,44 +62,4 @@ public static List fromJson(String json) { }.getType()); } - public Integer getRefHour() { - return this.refHour; - } - - public void setRefHour(Integer refHour) { - this.refHour = refHour; - } - - public Integer getCallbackCount() { - return this.callbackCount; - } - - public void setCallbackCount(Integer callbackCount) { - this.callbackCount = callbackCount; - } - - public Integer getFailCount() { - return this.failCount; - } - - public void setFailCount(Integer failCount) { - this.failCount = failCount; - } - - public Integer getTotalTimeCost() { - return this.totalTimeCost; - } - - public void setTotalTimeCost(Integer totalTimeCost) { - this.totalTimeCost = totalTimeCost; - } - - public Integer getMaxTimeCost() { - return this.maxTimeCost; - } - - public void setMaxTimeCost(Integer maxTimeCost) { - this.maxTimeCost = maxTimeCost; - } - } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeMsgResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeMsgResult.java index 4800c9c422..1e7e1f58c2 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeMsgResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeMsgResult.java @@ -1,51 +1,54 @@ package me.chanjar.weixin.mp.bean.datacube; -import com.google.gson.JsonParser; import com.google.gson.annotations.SerializedName; import com.google.gson.reflect.TypeToken; +import lombok.Data; +import lombok.EqualsAndHashCode; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.util.List; /** - * 消息分析数据接口返回结果对象 + * 消息分析数据接口返回结果对象. + * Created by Binary Wang on 2016/8/29. * - * @author binarywang(Binary Wang) - * Created by Binary Wang on 2016/8/29. + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) public class WxDataCubeMsgResult extends WxDataCubeBaseResult { private static final long serialVersionUID = 6932121822150573659L; /** - * ref_hour + * ref_hour. * 数据的小时,包括从000到2300,分别代表的是[000,100)到[2300,2400),即每日的第1小时和最后1小时 */ @SerializedName("ref_hour") private Integer refHour; /** - * msg_type + * msg_type. * 消息类型,代表含义如下:1代表文字 2代表图片 3代表语音 4代表视频 6代表第三方应用消息(链接消息) */ @SerializedName("msg_type") private Integer msgType; /** - * msg_user + * msg_user. * 上行发送了(向公众号发送了)消息的用户数 */ @SerializedName("msg_user") private Integer msgUser; /** - * msg_count + * msg_count. * 上行发送了消息的消息总数 */ @SerializedName("msg_count") private Integer msgCount; /** - * count_interval + * count_interval. * 当日发送消息量分布的区间,0代表 “0”,1代表“1-5”,2代表“6-10”,3代表“10次以上” */ @SerializedName("count_interval") @@ -59,7 +62,7 @@ public class WxDataCubeMsgResult extends WxDataCubeBaseResult { private Integer intPageReadCount; /** - * ori_page_read_user + * ori_page_read_user. * 原文页(点击图文页“阅读原文”进入的页面)的阅读人数,无原文页时此处数据为0 */ @SerializedName("ori_page_read_user") @@ -72,60 +75,4 @@ public static List fromJson(String json) { }.getType()); } - public Integer getRefHour() { - return this.refHour; - } - - public void setRefHour(Integer refHour) { - this.refHour = refHour; - } - - public Integer getMsgType() { - return this.msgType; - } - - public void setMsgType(Integer msgType) { - this.msgType = msgType; - } - - public Integer getMsgUser() { - return this.msgUser; - } - - public void setMsgUser(Integer msgUser) { - this.msgUser = msgUser; - } - - public Integer getMsgCount() { - return this.msgCount; - } - - public void setMsgCount(Integer msgCount) { - this.msgCount = msgCount; - } - - public Integer getCountInterval() { - return this.countInterval; - } - - public void setCountInterval(Integer countInterval) { - this.countInterval = countInterval; - } - - public Integer getIntPageReadCount() { - return this.intPageReadCount; - } - - public void setIntPageReadCount(Integer intPageReadCount) { - this.intPageReadCount = intPageReadCount; - } - - public Integer getOriPageReadUser() { - return this.oriPageReadUser; - } - - public void setOriPageReadUser(Integer oriPageReadUser) { - this.oriPageReadUser = oriPageReadUser; - } - } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserCumulate.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserCumulate.java index d3237a3b6e..ee0db76ad9 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserCumulate.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserCumulate.java @@ -2,6 +2,7 @@ import com.google.gson.JsonParser; import com.google.gson.reflect.TypeToken; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -15,6 +16,7 @@ * 详情查看文档:用户分析数据接口 * */ +@Data public class WxDataCubeUserCumulate implements Serializable { private static final JsonParser JSON_PARSER = new JsonParser(); @@ -31,22 +33,6 @@ public static List fromJson(String json) { }.getType()); } - public Date getRefDate() { - return this.refDate; - } - - public void setRefDate(Date refDate) { - this.refDate = refDate; - } - - public Integer getCumulateUser() { - return this.cumulateUser; - } - - public void setCumulateUser(Integer cumulateUser) { - this.cumulateUser = cumulateUser; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserSummary.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserSummary.java index 3b76725cc2..48c53a7e0c 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserSummary.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserSummary.java @@ -2,6 +2,7 @@ import com.google.gson.JsonParser; import com.google.gson.reflect.TypeToken; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -15,6 +16,7 @@ * 详情查看文档:用户分析数据接口 * */ +@Data public class WxDataCubeUserSummary implements Serializable { private static final long serialVersionUID = -2336654489906694173L; @@ -35,38 +37,6 @@ public static List fromJson(String json) { }.getType()); } - public Date getRefDate() { - return this.refDate; - } - - public void setRefDate(Date refDate) { - this.refDate = refDate; - } - - public Integer getUserSource() { - return this.userSource; - } - - public void setUserSource(Integer userSource) { - this.userSource = userSource; - } - - public Integer getNewUser() { - return this.newUser; - } - - public void setNewUser(Integer newUser) { - this.newUser = newUser; - } - - public Integer getCancelUser() { - return this.cancelUser; - } - - public void setCancelUser(Integer cancelUser) { - this.cancelUser = cancelUser; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/AbstractDeviceBean.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/AbstractDeviceBean.java index 4aef452270..d49999c504 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/AbstractDeviceBean.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/AbstractDeviceBean.java @@ -5,9 +5,12 @@ import java.io.Serializable; /** - * Created by keungtung on 14/12/2016. + * 设备抽象类. + * + * @author keungtung + * @date 14/12/2016 */ -public abstract class AbstractDeviceBean implements Serializable{ +public abstract class AbstractDeviceBean implements Serializable { private static final long serialVersionUID = 4359729626772515385L; public String toJson() { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/BaseResp.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/BaseResp.java index 7d1fd8aa77..5c66b0cd60 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/BaseResp.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/BaseResp.java @@ -1,10 +1,15 @@ package me.chanjar.weixin.mp.bean.device; import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; /** - * Created by keungtung on 10/12/2016. + * @author keungtung. + * @date 10/12/2016 */ +@Data +@EqualsAndHashCode(callSuper = false) public class BaseResp extends AbstractDeviceBean { private static final long serialVersionUID = 4252655933699659073L; @@ -15,50 +20,12 @@ public class BaseResp extends AbstractDeviceBean { @SerializedName("errmsg") private String errMsg; - public Integer getErrCode() { - return errCode; - } - - public void setErrCode(Integer errCode) { - this.errCode = errCode; - } - - public BaseInfo getBaseInfo() { - return baseInfo; - } - - public void setBaseInfo(BaseInfo baseInfo) { - this.baseInfo = baseInfo; - } - - public String getErrMsg() { - return errMsg; - } - - public void setErrMsg(String errMsg) { - this.errMsg = errMsg; - } - + @Data private class BaseInfo { @SerializedName("device_type") private String deviceType; + @SerializedName("device_id") private String deviceId; - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceId() { - return deviceId; - } - - public void setDeviceId(String deviceId) { - this.deviceId = deviceId; - } } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/RespMsg.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/RespMsg.java index 9c62d36f93..601f848223 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/RespMsg.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/RespMsg.java @@ -1,11 +1,16 @@ package me.chanjar.weixin.mp.bean.device; import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; /** - * Created by keungtung on 10/12/2016. + * + * @author keungtung. + * @date 10/12/2016 */ - +@Data +@EqualsAndHashCode(callSuper = false) public class RespMsg extends AbstractDeviceBean { private static final long serialVersionUID = -4241272701707684136L; @@ -13,20 +18,4 @@ public class RespMsg extends AbstractDeviceBean { private Integer retCode; @SerializedName("error_info") private String errorInfo; - - public Integer getRetCode() { - return retCode; - } - - public void setRetCode(Integer retCode) { - this.retCode = retCode; - } - - public String getErrorInfo() { - return errorInfo; - } - - public void setErrorInfo(String errorInfo) { - this.errorInfo = errorInfo; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/TransMsgResp.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/TransMsgResp.java index 1572da75ac..f2b35da5ea 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/TransMsgResp.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/TransMsgResp.java @@ -1,11 +1,17 @@ package me.chanjar.weixin.mp.bean.device; import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; import me.chanjar.weixin.common.util.json.WxGsonBuilder; /** - * Created by keungtung on 14/12/2016. + * + * @author keungtung. + * @date 14/12/2016 */ +@Data +@EqualsAndHashCode(callSuper = false) public class TransMsgResp extends AbstractDeviceBean { private static final long serialVersionUID = 5386954916622816491L; @@ -20,36 +26,4 @@ public class TransMsgResp extends AbstractDeviceBean { public static TransMsgResp fromJson(String json) { return WxGsonBuilder.create().fromJson(json, TransMsgResp.class); } - - public Integer getRet() { - return ret; - } - - public void setRet(Integer ret) { - this.ret = ret; - } - - public String getRetInfo() { - return retInfo; - } - - public void setRetInfo(String retInfo) { - this.retInfo = retInfo; - } - - public Integer getErrCode() { - return errCode; - } - - public void setErrCode(Integer errCode) { - this.errCode = errCode; - } - - public String getErrMsg() { - return errMsg; - } - - public void setErrMsg(String errMsg) { - this.errMsg = errMsg; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDevice.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDevice.java index 4527d368d2..84c5b2d66d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDevice.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDevice.java @@ -1,12 +1,15 @@ package me.chanjar.weixin.mp.bean.device; import com.google.gson.annotations.SerializedName; +import lombok.Data; import java.io.Serializable; /** - * Created by keungtung on 10/12/2016. + * @author keungtung + * @date 10/12/2016 */ +@Data public class WxDevice implements Serializable { private static final long serialVersionUID = -3284819760735456195L; @@ -30,92 +33,4 @@ public class WxDevice implements Serializable { private String serMacPos; @SerializedName("ble_simple_protocol") private String bleSimpleProtocol; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getMac() { - return mac; - } - - public void setMac(String mac) { - this.mac = mac; - } - - public String getConnectProtocol() { - return connectProtocol; - } - - public void setConnectProtocol(String connectProtocol) { - this.connectProtocol = connectProtocol; - } - - public String getAuthKey() { - return authKey; - } - - public void setAuthKey(String authKey) { - this.authKey = authKey; - } - - public String getCloseStrategy() { - return closeStrategy; - } - - public void setCloseStrategy(String closeStrategy) { - this.closeStrategy = closeStrategy; - } - - public String getConnStrategy() { - return connStrategy; - } - - public void setConnStrategy(String connStrategy) { - this.connStrategy = connStrategy; - } - - public String getCryptMethod() { - return cryptMethod; - } - - public void setCryptMethod(String cryptMethod) { - this.cryptMethod = cryptMethod; - } - - public String getAuthVer() { - return authVer; - } - - public void setAuthVer(String authVer) { - this.authVer = authVer; - } - - public String getManuMacPos() { - return manuMacPos; - } - - public void setManuMacPos(String manuMacPos) { - this.manuMacPos = manuMacPos; - } - - public String getSerMacPos() { - return serMacPos; - } - - public void setSerMacPos(String serMacPos) { - this.serMacPos = serMacPos; - } - - public String getBleSimpleProtocol() { - return bleSimpleProtocol; - } - - public void setBleSimpleProtocol(String bleSimpleProtocol) { - this.bleSimpleProtocol = bleSimpleProtocol; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java index 055e41c879..5e00c4faea 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java @@ -1,14 +1,19 @@ package me.chanjar.weixin.mp.bean.device; import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; import java.util.Arrays; import java.util.LinkedList; import java.util.List; /** - * Created by keungtung on 10/12/2016. + * @author keungtung + * @date 10/12/2016 */ +@Data +@EqualsAndHashCode(callSuper = false) public class WxDeviceAuthorize extends AbstractDeviceBean { private static final long serialVersionUID = 8786321356569903887L; @@ -21,38 +26,6 @@ public class WxDeviceAuthorize extends AbstractDeviceBean { @SerializedName("device_list") private List deviceList = new LinkedList<>(); - public String getDeviceNum() { - return deviceNum; - } - - public void setDeviceNum(String deviceNum) { - this.deviceNum = deviceNum; - } - - public String getOpType() { - return opType; - } - - public void setOpType(String opType) { - this.opType = opType; - } - - public String getProductId() { - return productId; - } - - public void setProductId(String productId) { - this.productId = productId; - } - - public List getDeviceList() { - return deviceList; - } - - public void setDeviceList(List deviceList) { - this.deviceList = deviceList; - } - public void addDevice(WxDevice... devices) { this.deviceList.addAll(Arrays.asList(devices)); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorizeResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorizeResult.java index 560f5498bb..9608452ce1 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorizeResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorizeResult.java @@ -1,12 +1,17 @@ package me.chanjar.weixin.mp.bean.device; +import lombok.Data; +import lombok.EqualsAndHashCode; import me.chanjar.weixin.common.util.json.WxGsonBuilder; import java.util.List; /** - * Created by keungtung on 10/12/2016. + * @author keungtung. + * @date 10/12/2016 */ +@Data +@EqualsAndHashCode(callSuper = false) public class WxDeviceAuthorizeResult extends AbstractDeviceBean { private static final long serialVersionUID = 9105294570912249811L; @@ -16,11 +21,4 @@ public static WxDeviceAuthorizeResult fromJson(String response) { return WxGsonBuilder.create().fromJson(response, WxDeviceAuthorizeResult.class); } - public List getResp() { - return resp; - } - - public void setResp(List resp) { - this.resp = resp; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBind.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBind.java index 4945cfbbf2..aeb7f819ce 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBind.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBind.java @@ -1,10 +1,15 @@ package me.chanjar.weixin.mp.bean.device; import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; /** - * Created by keungtung on 10/12/2016. + * @author keungtung. + * @date 10/12/2016 */ +@Data +@EqualsAndHashCode(callSuper = false) public class WxDeviceBind extends AbstractDeviceBean { private static final long serialVersionUID = 467559769037590880L; @@ -14,27 +19,4 @@ public class WxDeviceBind extends AbstractDeviceBean { @SerializedName("openid") private String openId; - public String getTicket() { - return ticket; - } - - public void setTicket(String ticket) { - this.ticket = ticket; - } - - public String getDeviceId() { - return deviceId; - } - - public void setDeviceId(String deviceId) { - this.deviceId = deviceId; - } - - public String getOpenId() { - return openId; - } - - public void setOpenId(String openId) { - this.openId = openId; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBindDeviceResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBindDeviceResult.java index 52c5f45609..ec032e8617 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBindDeviceResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBindDeviceResult.java @@ -1,13 +1,18 @@ package me.chanjar.weixin.mp.bean.device; import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.util.List; /** - * Created by keungtung on 16/12/2016. + * @author keungtung. + * @date 16/12/2016 */ +@Data +@EqualsAndHashCode(callSuper = false) public class WxDeviceBindDeviceResult extends AbstractDeviceBean { private static final long serialVersionUID = 725870295905935355L; @@ -22,27 +27,13 @@ public static WxDeviceBindDeviceResult fromJson(String json) { return WxMpGsonBuilder.create().fromJson(json, WxDeviceBindDeviceResult.class); } + @Data private class Device { @SerializedName("device_type") private String deviceType; @SerializedName("device_id") private String deviceId; - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceId() { - return deviceId; - } - - public void setDeviceId(String deviceId) { - this.deviceId = deviceId; - } } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBindResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBindResult.java index c26e9c85d1..f6c702aa29 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBindResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBindResult.java @@ -1,11 +1,16 @@ package me.chanjar.weixin.mp.bean.device; import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; /** - * Created by keungtung on 10/12/2016. + * @author keungtung. + * @date 10/12/2016 */ +@Data +@EqualsAndHashCode(callSuper = false) public class WxDeviceBindResult extends AbstractDeviceBean { private static final long serialVersionUID = 4687725146279339359L; @@ -16,11 +21,4 @@ public static WxDeviceBindResult fromJson(String json) { return WxMpGsonBuilder.create().fromJson(json, WxDeviceBindResult.class); } - public BaseResp getBaseResp() { - return baseResp; - } - - public void setBaseResp(BaseResp baseResp) { - this.baseResp = baseResp; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceMsg.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceMsg.java index 182cb27241..4128a9f82b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceMsg.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceMsg.java @@ -1,11 +1,16 @@ package me.chanjar.weixin.mp.bean.device; import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; import me.chanjar.weixin.common.util.ToStringUtils; /** - * Created by keungtung on 10/12/2016. + * @author keungtung. + * @date 10/12/2016 */ +@Data +@EqualsAndHashCode(callSuper = false) public class WxDeviceMsg extends AbstractDeviceBean { private static final long serialVersionUID = -5567110858455277963L; @@ -21,36 +26,4 @@ public class WxDeviceMsg extends AbstractDeviceBean { public String toString() { return ToStringUtils.toSimpleString(this); } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceId() { - return deviceId; - } - - public void setDeviceId(String deviceId) { - this.deviceId = deviceId; - } - - public String getOpenId() { - return openId; - } - - public void setOpenId(String openId) { - this.openId = openId; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceOpenIdResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceOpenIdResult.java index a2ea56c080..95cf2a94ff 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceOpenIdResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceOpenIdResult.java @@ -1,13 +1,18 @@ package me.chanjar.weixin.mp.bean.device; import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.util.List; /** - * Created by keungtung on 16/12/2016. + * @author keungtung. + * @date 16/12/2016 */ +@Data +@EqualsAndHashCode(callSuper = false) public class WxDeviceOpenIdResult extends AbstractDeviceBean { private static final long serialVersionUID = 4980885167833836220L; @@ -24,35 +29,4 @@ public static WxDeviceOpenIdResult fromJson(String json) { return WxMpGsonBuilder.create().fromJson(json, WxDeviceOpenIdResult.class); } - public Integer getErrCode() { - return errCode; - } - - public void setErrCode(Integer errCode) { - this.errCode = errCode; - } - - public String getErrMsg() { - return errMsg; - } - - public void setErrMsg(String errMsg) { - this.errMsg = errMsg; - } - - public List getOpenIds() { - return openIds; - } - - public void setOpenIds(List openIds) { - this.openIds = openIds; - } - - public RespMsg getRespMsg() { - return respMsg; - } - - public void setRespMsg(RespMsg respMsg) { - this.respMsg = respMsg; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceQrCodeResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceQrCodeResult.java index 8d6efac90b..0e0d96f419 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceQrCodeResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceQrCodeResult.java @@ -1,11 +1,16 @@ package me.chanjar.weixin.mp.bean.device; import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; /** - * Created by keungtung on 10/12/2016. + * @author keungtung. + * @date 10/12/2016 */ +@Data +@EqualsAndHashCode(callSuper = false) public class WxDeviceQrCodeResult extends AbstractDeviceBean { private static final long serialVersionUID = -4312858303060918266L; @@ -22,35 +27,4 @@ public static WxDeviceQrCodeResult fromJson(String json) { return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxDeviceQrCodeResult.class); } - public String getDeviceLicence() { - return deviceLicence; - } - - public void setDeviceLicence(String deviceLicence) { - this.deviceLicence = deviceLicence; - } - - public BaseResp getBaseResp() { - return baseResp; - } - - public void setBaseResp(BaseResp baseResp) { - this.baseResp = baseResp; - } - - public String getDeviceId() { - return deviceId; - } - - public void setDeviceId(String deviceId) { - this.deviceId = deviceId; - } - - public String getQrTicket() { - return qrTicket; - } - - public void setQrTicket(String qrTicket) { - this.qrTicket = qrTicket; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessage.java index 2c02a6207d..97b40920ea 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessage.java @@ -1,5 +1,7 @@ package me.chanjar.weixin.mp.bean.kefu; +import lombok.Data; +import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.mp.builder.kefu.*; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -12,6 +14,7 @@ * * @author chanjarster */ +@Data public class WxMpKefuMessage implements Serializable { private static final long serialVersionUID = -9196732086954365246L; @@ -85,166 +88,35 @@ public static WxCardBuilder WXCARD() { return new WxCardBuilder(); } - public String getToUser() { - return this.toUser; - } - - public void setToUser(String toUser) { - this.toUser = toUser; - } - - public String getMsgType() { - return this.msgType; - } - /** *

    * 请使用
-   * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_TEXT}
-   * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_IMAGE}
-   * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_VOICE}
-   * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_MUSIC}
-   * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_VIDEO}
-   * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_NEWS}
-   * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_MPNEWS}
-   * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_WXCARD}
+   * {@link WxConsts.KefuMsgType#TEXT}
+   * {@link WxConsts.KefuMsgType#IMAGE}
+   * {@link WxConsts.KefuMsgType#VOICE}
+   * {@link WxConsts.KefuMsgType#MUSIC}
+   * {@link WxConsts.KefuMsgType#VIDEO}
+   * {@link WxConsts.KefuMsgType#NEWS}
+   * {@link WxConsts.KefuMsgType#MPNEWS}
+   * {@link WxConsts.KefuMsgType#WXCARD}
    * 
* - * @param msgType */ public void setMsgType(String msgType) { this.msgType = msgType; } - public String getMpNewsMediaId() { - return this.mpNewsMediaId; - } - - public void setMpNewsMediaId(String mpNewsMediaId) { - this.mpNewsMediaId = mpNewsMediaId; - } - - public String getContent() { - return this.content; - } - - public void setContent(String content) { - this.content = content; - } - - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } - - public String getThumbMediaId() { - return this.thumbMediaId; - } - - public void setThumbMediaId(String thumbMediaId) { - this.thumbMediaId = thumbMediaId; - } - - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getMusicUrl() { - return this.musicUrl; - } - - public void setMusicUrl(String musicUrl) { - this.musicUrl = musicUrl; - } - - public String getHqMusicUrl() { - return this.hqMusicUrl; - } - - public void setHqMusicUrl(String hqMusicUrl) { - this.hqMusicUrl = hqMusicUrl; - } - - public String getCardId() { - return this.cardId; - } - - public void setCardId(String cardId) { - this.cardId = cardId; - } - - public List getArticles() { - return this.articles; - } - - public void setArticles(List articles) { - this.articles = articles; - } - public String toJson() { return WxMpGsonBuilder.INSTANCE.create().toJson(this); } - public String getKfAccount() { - return this.kfAccount; - } + @Data + public static class WxArticle implements Serializable { + private static final long serialVersionUID = 5145137235440507379L; - public void setKfAccount(String kfAccount) { - this.kfAccount = kfAccount; - } - - public static class WxArticle { private String title; private String description; private String url; private String picUrl; - - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getUrl() { - return this.url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getPicUrl() { - return this.picUrl; - } - - public void setPicUrl(String picUrl) { - this.picUrl = picUrl; - } - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/request/WxMpKfAccountRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/request/WxMpKfAccountRequest.java index 85cdfe5507..273282a6a9 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/request/WxMpKfAccountRequest.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/request/WxMpKfAccountRequest.java @@ -1,11 +1,15 @@ package me.chanjar.weixin.mp.bean.kefu.request; import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; import java.io.Serializable; +@Data +@Builder public class WxMpKfAccountRequest implements Serializable { private static final long serialVersionUID = -5451863610674856927L; @@ -27,10 +31,6 @@ public class WxMpKfAccountRequest implements Serializable { @SerializedName("invite_wx") private String inviteWx; - public static Builder builder() { - return new Builder(); - } - @Override public String toString() { return ToStringBuilder.reflectionToString(this); @@ -40,64 +40,4 @@ public String toJson() { return WxMpGsonBuilder.INSTANCE.create().toJson(this); } - public String getKfAccount() { - return this.kfAccount; - } - - public void setKfAccount(String kfAccount) { - this.kfAccount = kfAccount; - } - - public String getNickName() { - return this.nickName; - } - - public void setNickName(String nickName) { - this.nickName = nickName; - } - - public String getInviteWx() { - return this.inviteWx; - } - - public void setInviteWx(String inviteWx) { - this.inviteWx = inviteWx; - } - - public static class Builder { - private String kfAccount; - private String nickName; - private String inviteWx; - - public Builder kfAccount(String kfAccount) { - this.kfAccount = kfAccount; - return this; - } - - public Builder nickName(String nickName) { - this.nickName = nickName; - return this; - } - - public Builder inviteWx(String inviteWx) { - this.inviteWx = inviteWx; - return this; - } - - public Builder from(WxMpKfAccountRequest origin) { - this.kfAccount(origin.kfAccount); - this.nickName(origin.nickName); - this.inviteWx(origin.inviteWx); - return this; - } - - public WxMpKfAccountRequest build() { - WxMpKfAccountRequest m = new WxMpKfAccountRequest(); - m.kfAccount = this.kfAccount; - m.nickName = this.nickName; - m.inviteWx = this.inviteWx; - return m; - } - } - } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/request/WxMpKfSessionRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/request/WxMpKfSessionRequest.java index ac59e3238e..2f077d3f59 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/request/WxMpKfSessionRequest.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/request/WxMpKfSessionRequest.java @@ -1,11 +1,13 @@ package me.chanjar.weixin.mp.bean.kefu.request; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.Serializable; +@Data public class WxMpKfSessionRequest implements Serializable { private static final long serialVersionUID = -5451863610674856927L; @@ -35,12 +37,4 @@ public String toJson() { return WxMpGsonBuilder.INSTANCE.create().toJson(this); } - public String getKfAccount() { - return this.kfAccount; - } - - public void setKfAccount(String kfAccount) { - this.kfAccount = kfAccount; - } - } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfInfo.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfInfo.java index c879e9f63a..60b5370d8e 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfInfo.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfInfo.java @@ -2,6 +2,7 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import java.io.Serializable; @@ -11,6 +12,7 @@ * * @author Binary Wang */ +@Data public class WxMpKfInfo implements Serializable { private static final long serialVersionUID = -5877300750666022290L; @@ -75,88 +77,9 @@ public class WxMpKfInfo implements Serializable { @SerializedName("accepted_case") private Integer acceptedCase; - public Integer getStatus() { - return this.status; - } - - public void setStatus(Integer status) { - this.status = status; - } - - public Integer getAcceptedCase() { - return this.acceptedCase; - } - - public void setAcceptedCase(Integer acceptedCase) { - this.acceptedCase = acceptedCase; - } - - public String getAccount() { - return this.account; - } - - public void setAccount(String account) { - this.account = account; - } - - public String getHeadImgUrl() { - return this.headImgUrl; - } - - public void setHeadImgUrl(String headImgUrl) { - this.headImgUrl = headImgUrl; - } - - public String getId() { - return this.id; - } - - public void setId(String id) { - this.id = id; - } - - public String getNick() { - return this.nick; - } - - public void setNick(String nick) { - this.nick = nick; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); } - public String getWxAccount() { - return this.wxAccount; - } - - public void setWxAccount(String wxAccount) { - this.wxAccount = wxAccount; - } - - public String getInviteWx() { - return this.inviteWx; - } - - public void setInviteWx(String inviteWx) { - this.inviteWx = inviteWx; - } - - public Long getInviteExpireTime() { - return this.inviteExpireTime; - } - - public void setInviteExpireTime(Long inviteExpireTime) { - this.inviteExpireTime = inviteExpireTime; - } - - public String getInviteStatus() { - return this.inviteStatus; - } - - public void setInviteStatus(String inviteStatus) { - this.inviteStatus = inviteStatus; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfList.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfList.java index 5cce093dfc..3d9a8872ab 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfList.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfList.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean.kefu.result; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -10,6 +11,7 @@ /** * @author Binary Wang */ +@Data public class WxMpKfList implements Serializable { private static final long serialVersionUID = -8194193505173564894L; @@ -25,11 +27,4 @@ public String toString() { return ToStringUtils.toSimpleString(this); } - public List getKfList() { - return this.kfList; - } - - public void setKfList(List kfList) { - this.kfList = kfList; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgList.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgList.java index 253652a883..ee2f751473 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgList.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgList.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean.kefu.result; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -8,8 +9,11 @@ import java.util.List; /** - * Created by Binary Wang on 2016/7/15. + * + * @author Binary Wang + * @date 2016/7/15 */ +@Data public class WxMpKfMsgList implements Serializable { private static final long serialVersionUID = 4524296707435188202L; @@ -26,30 +30,6 @@ public static WxMpKfMsgList fromJson(String responseContent) { return WxMpGsonBuilder.INSTANCE.create().fromJson(responseContent, WxMpKfMsgList.class); } - public List getRecords() { - return this.records; - } - - public void setRecords(List records) { - this.records = records; - } - - public Integer getNumber() { - return this.number; - } - - public void setNumber(Integer number) { - this.number = number; - } - - public Long getMsgId() { - return this.msgId; - } - - public void setMsgId(Long msgId) { - this.msgId = msgId; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgRecord.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgRecord.java index 1b32164879..baba81da04 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgRecord.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgRecord.java @@ -1,13 +1,17 @@ package me.chanjar.weixin.mp.bean.kefu.result; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import java.io.Serializable; /** - * Created by Binary Wang on 2016/7/18. + * + * @author Binary Wang + * @date 2016/7/18 */ +@Data public class WxMpKfMsgRecord implements Serializable { private static final long serialVersionUID = -280692188908528688L; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfOnlineList.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfOnlineList.java index 6778520c2b..cb5f90719d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfOnlineList.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfOnlineList.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean.kefu.result; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -10,6 +11,7 @@ /** * @author Binary Wang */ +@Data public class WxMpKfOnlineList implements Serializable { private static final long serialVersionUID = -6154705288500854617L; @@ -25,11 +27,4 @@ public String toString() { return ToStringUtils.toSimpleString(this); } - public List getKfOnlineList() { - return this.kfOnlineList; - } - - public void setKfOnlineList(List kfOnlineList) { - this.kfOnlineList = kfOnlineList; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSession.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSession.java index b36edb9f2d..1611025412 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSession.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSession.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean.kefu.result; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import java.io.Serializable; @@ -8,6 +9,7 @@ /** * @author Binary Wang */ +@Data public class WxMpKfSession implements Serializable { private static final long serialVersionUID = 7804332813164994062L; @@ -42,35 +44,4 @@ public String toString() { return ToStringUtils.toSimpleString(this); } - public String getKfAccount() { - return this.kfAccount; - } - - public void setKfAccount(String kfAccount) { - this.kfAccount = kfAccount; - } - - public long getCreateTime() { - return this.createTime; - } - - public void setCreateTime(long createTime) { - this.createTime = createTime; - } - - public String getOpenid() { - return this.openid; - } - - public void setOpenid(String openid) { - this.openid = openid; - } - - public long getLatestTime() { - return this.latestTime; - } - - public void setLatestTime(long latestTime) { - this.latestTime = latestTime; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionGetResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionGetResult.java index d6ed763e9f..5f4b318c50 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionGetResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionGetResult.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean.kefu.result; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -9,6 +10,7 @@ /** * @author Binary Wang */ +@Data public class WxMpKfSessionGetResult implements Serializable { private static final long serialVersionUID = 8474846575200033152L; @@ -33,20 +35,4 @@ public String toString() { return ToStringUtils.toSimpleString(this); } - public String getKfAccount() { - return this.kfAccount; - } - - public void setKfAccount(String kfAccount) { - this.kfAccount = kfAccount; - } - - public long getCreateTime() { - return this.createTime; - } - - public void setCreateTime(long createTime) { - this.createTime = createTime; - } - } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionList.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionList.java index f1eb4dd7cb..e12def669c 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionList.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionList.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean.kefu.result; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -10,6 +11,7 @@ /** * @author Binary Wang */ +@Data public class WxMpKfSessionList implements Serializable { private static final long serialVersionUID = -7680371346226640206L; @@ -29,11 +31,4 @@ public String toString() { return ToStringUtils.toSimpleString(this); } - public List getKfSessionList() { - return this.kfSessionList; - } - - public void setKfSessionList(List kfSessionList) { - this.kfSessionList = kfSessionList; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionWaitCaseList.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionWaitCaseList.java index 7dd8def8cf..872ba7db3c 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionWaitCaseList.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionWaitCaseList.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean.kefu.result; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -10,6 +11,7 @@ /** * @author Binary Wang */ +@Data public class WxMpKfSessionWaitCaseList implements Serializable { private static final long serialVersionUID = 2432132626631361922L; @@ -35,12 +37,4 @@ public String toString() { return ToStringUtils.toSimpleString(this); } - public List getKfSessionWaitCaseList() { - return this.kfSessionWaitCaseList; - } - - public void setKfSessionWaitCaseList(List kfSessionWaitCaseList) { - this.kfSessionWaitCaseList = kfSessionWaitCaseList; - } - } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMediaImgUploadResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMediaImgUploadResult.java index 1110a1f16b..b60b2791c8 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMediaImgUploadResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMediaImgUploadResult.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean.material; +import lombok.Data; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.Serializable; @@ -7,6 +8,7 @@ /** * @author miller */ +@Data public class WxMediaImgUploadResult implements Serializable { private static final long serialVersionUID = 1996392453428768829L; private String url; @@ -15,11 +17,4 @@ public static WxMediaImgUploadResult fromJson(String json) { return WxMpGsonBuilder.create().fromJson(json, WxMediaImgUploadResult.class); } - public String getUrl() { - return this.url; - } - - public void setUrl(String url) { - this.url = url; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterial.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterial.java index e176620f43..a554834d01 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterial.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterial.java @@ -1,10 +1,13 @@ package me.chanjar.weixin.mp.bean.material; +import lombok.Data; + import java.io.File; import java.io.Serializable; import java.util.HashMap; import java.util.Map; +@Data public class WxMpMaterial implements Serializable { private static final long serialVersionUID = -1651816949780969485L; @@ -29,41 +32,4 @@ public Map getForm() { form.put("introduction", this.videoIntroduction); return form; } - - public String getVideoTitle() { - return this.videoTitle; - } - - public void setVideoTitle(String videoTitle) { - this.videoTitle = videoTitle; - } - - public String getVideoIntroduction() { - return this.videoIntroduction; - } - - public void setVideoIntroduction(String videoIntroduction) { - this.videoIntroduction = videoIntroduction; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public File getFile() { - return this.file; - } - - public void setFile(File file) { - this.file = file; - } - - @Override - public String toString() { - return "WxMpMaterial [" + "name=" + this.name + ", file=" + this.file + ", videoTitle=" + this.videoTitle + ", videoIntroduction=" + this.videoIntroduction + "]"; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialArticleUpdate.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialArticleUpdate.java index f2f7aa1201..13e7701bb7 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialArticleUpdate.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialArticleUpdate.java @@ -1,9 +1,11 @@ package me.chanjar.weixin.mp.bean.material; +import lombok.Data; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.Serializable; +@Data public class WxMpMaterialArticleUpdate implements Serializable { private static final long serialVersionUID = -7611963949517780270L; @@ -11,36 +13,7 @@ public class WxMpMaterialArticleUpdate implements Serializable { private int index; private WxMpMaterialNews.WxMpMaterialNewsArticle articles; - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } - - public int getIndex() { - return this.index; - } - - public void setIndex(int index) { - this.index = index; - } - - public WxMpMaterialNews.WxMpMaterialNewsArticle getArticles() { - return this.articles; - } - - public void setArticles(WxMpMaterialNews.WxMpMaterialNewsArticle articles) { - this.articles = articles; - } - public String toJson() { return WxMpGsonBuilder.create().toJson(this); } - - @Override - public String toString() { - return "WxMpMaterialArticleUpdate [" + "mediaId=" + this.mediaId + ", index=" + this.index + ", articles=" + this.articles + "]"; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialCountResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialCountResult.java index 4a74b6b64b..0bb3384154 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialCountResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialCountResult.java @@ -1,9 +1,11 @@ package me.chanjar.weixin.mp.bean.material; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import java.io.Serializable; +@Data public class WxMpMaterialCountResult implements Serializable { private static final long serialVersionUID = -5568772662085874138L; @@ -12,38 +14,6 @@ public class WxMpMaterialCountResult implements Serializable { private int imageCount; private int newsCount; - public int getVoiceCount() { - return this.voiceCount; - } - - public void setVoiceCount(int voiceCount) { - this.voiceCount = voiceCount; - } - - public int getVideoCount() { - return this.videoCount; - } - - public void setVideoCount(int videoCount) { - this.videoCount = videoCount; - } - - public int getImageCount() { - return this.imageCount; - } - - public void setImageCount(int imageCount) { - this.imageCount = imageCount; - } - - public int getNewsCount() { - return this.newsCount; - } - - public void setNewsCount(int newsCount) { - this.newsCount = newsCount; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialFileBatchGetResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialFileBatchGetResult.java index b08a0ce3c4..4f445a288b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialFileBatchGetResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialFileBatchGetResult.java @@ -1,11 +1,13 @@ package me.chanjar.weixin.mp.bean.material; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import java.io.Serializable; import java.util.Date; import java.util.List; +@Data public class WxMpMaterialFileBatchGetResult implements Serializable { private static final long serialVersionUID = -560388368297267884L; @@ -13,73 +15,18 @@ public class WxMpMaterialFileBatchGetResult implements Serializable { private int itemCount; private List items; - public int getTotalCount() { - return this.totalCount; - } - - public void setTotalCount(int totalCount) { - this.totalCount = totalCount; - } - - public int getItemCount() { - return this.itemCount; - } - - public void setItemCount(int itemCount) { - this.itemCount = itemCount; - } - - public List getItems() { - return this.items; - } - - public void setItems(List items) { - this.items = items; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); } + @Data public static class WxMaterialFileBatchGetNewsItem { private String mediaId; private Date updateTime; private String name; private String url; - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } - - public Date getUpdateTime() { - return this.updateTime; - } - - public void setUpdateTime(Date updateTime) { - this.updateTime = updateTime; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public String getUrl() { - return this.url; - } - - public void setUrl(String url) { - this.url = url; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialNews.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialNews.java index 51f2d0c6bd..2a2439da93 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialNews.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialNews.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean.material; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -8,6 +9,7 @@ import java.util.ArrayList; import java.util.List; +@Data public class WxMpMaterialNews implements Serializable { private static final long serialVersionUID = -3283203652013494976L; @@ -32,22 +34,6 @@ public boolean isEmpty() { return this.articles == null || this.articles.isEmpty(); } - public Date getCreatedTime() { - return this.createdTime; - } - - public void setCreatedTime(Date createdTime) { - this.createdTime = createdTime; - } - - public Date getUpdatedTime() { - return this.updatedTime; - } - - public void setUpdatedTime(Date updatedTime) { - this.updatedTime = updatedTime; - } - @Override public String toString() { return this.toJson(); @@ -70,6 +56,7 @@ public String toString() { * * @author chanjarster */ + @Data public static class WxMpMaterialNewsArticle { /** * (必填) 图文消息缩略图的media_id,可以在基础支持-上传多媒体文件接口中获得 @@ -121,94 +108,6 @@ public static class WxMpMaterialNewsArticle { */ private Boolean onlyFansCanComment; - public String getThumbMediaId() { - return this.thumbMediaId; - } - - public void setThumbMediaId(String thumbMediaId) { - this.thumbMediaId = thumbMediaId; - } - - public String getAuthor() { - return this.author; - } - - public void setAuthor(String author) { - this.author = author; - } - - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getContentSourceUrl() { - return this.contentSourceUrl; - } - - public void setContentSourceUrl(String contentSourceUrl) { - this.contentSourceUrl = contentSourceUrl; - } - - public String getContent() { - return this.content; - } - - public void setContent(String content) { - this.content = content; - } - - public String getDigest() { - return this.digest; - } - - public void setDigest(String digest) { - this.digest = digest; - } - - public boolean isShowCoverPic() { - return this.showCoverPic; - } - - public void setShowCoverPic(boolean showCoverPic) { - this.showCoverPic = showCoverPic; - } - - public String getUrl() { - return this.url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getThumbUrl() { - return this.thumbUrl; - } - - public void setThumbUrl(String thumbUrl) { - this.thumbUrl = thumbUrl; - } - - public Boolean getNeedOpenComment() { - return this.needOpenComment; - } - - public void setNeedOpenComment(Boolean needOpenComment) { - this.needOpenComment = needOpenComment; - } - - public Boolean getOnlyFansCanComment() { - return this.onlyFansCanComment; - } - - public void setOnlyFansCanComment(Boolean onlyFansCanComment) { - this.onlyFansCanComment = onlyFansCanComment; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialNewsBatchGetResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialNewsBatchGetResult.java index 03f0a6d854..77fe8b562d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialNewsBatchGetResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialNewsBatchGetResult.java @@ -1,11 +1,13 @@ package me.chanjar.weixin.mp.bean.material; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import java.io.Serializable; import java.util.Date; import java.util.List; +@Data public class WxMpMaterialNewsBatchGetResult implements Serializable { private static final long serialVersionUID = -1617952797921001666L; @@ -13,64 +15,17 @@ public class WxMpMaterialNewsBatchGetResult implements Serializable { private int itemCount; private List items; - public int getTotalCount() { - return this.totalCount; - } - - public void setTotalCount(int totalCount) { - this.totalCount = totalCount; - } - - public int getItemCount() { - return this.itemCount; - } - - public void setItemCount(int itemCount) { - this.itemCount = itemCount; - } - - public List getItems() { - return this.items; - } - - public void setItems(List items) { - this.items = items; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); } + @Data public static class WxMaterialNewsBatchGetNewsItem { private String mediaId; private Date updateTime; private WxMpMaterialNews content; - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } - - public Date getUpdateTime() { - return this.updateTime; - } - - public void setUpdateTime(Date updateTime) { - this.updateTime = updateTime; - } - - public WxMpMaterialNews getContent() { - return this.content; - } - - public void setContent(WxMpMaterialNews content) { - this.content = content; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialUploadResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialUploadResult.java index 0e5546b9aa..6a4630e567 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialUploadResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialUploadResult.java @@ -1,10 +1,12 @@ package me.chanjar.weixin.mp.bean.material; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.Serializable; +@Data public class WxMpMaterialUploadResult implements Serializable { private static final long serialVersionUID = -128818731449449537L; private String mediaId; @@ -16,38 +18,6 @@ public static WxMpMaterialUploadResult fromJson(String json) { return WxMpGsonBuilder.create().fromJson(json, WxMpMaterialUploadResult.class); } - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } - - public String getUrl() { - return this.url; - } - - public void setUrl(String url) { - this.url = url; - } - - public Integer getErrCode() { - return this.errCode; - } - - public void setErrCode(Integer errCode) { - this.errCode = errCode; - } - - public String getErrMsg() { - return this.errMsg; - } - - public void setErrMsg(String errMsg) { - this.errMsg = errMsg; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialVideoInfoResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialVideoInfoResult.java index e0558cc888..8a783e6809 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialVideoInfoResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialVideoInfoResult.java @@ -1,9 +1,11 @@ package me.chanjar.weixin.mp.bean.material; +import lombok.Data; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.Serializable; +@Data public class WxMpMaterialVideoInfoResult implements Serializable { private static final long serialVersionUID = 1269131745333792202L; @@ -15,33 +17,4 @@ public static WxMpMaterialVideoInfoResult fromJson(String json) { return WxMpGsonBuilder.create().fromJson(json, WxMpMaterialVideoInfoResult.class); } - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getDownUrl() { - return this.downUrl; - } - - public void setDownUrl(String downUrl) { - this.downUrl = downUrl; - } - - @Override - public String toString() { - return "WxMpMaterialVideoInfoResult [title=" + this.title + ", description=" + this.description + ", downUrl=" + this.downUrl + "]"; - } - } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/MemberCardUserInfo.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/MemberCardUserInfo.java index b9c771c487..c039d72a15 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/MemberCardUserInfo.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/MemberCardUserInfo.java @@ -1,10 +1,14 @@ package me.chanjar.weixin.mp.bean.membercard; +import lombok.Data; + import java.io.Serializable; /** - * Created by YuJian on 2017/7/11. + * @author YuJian + * @date 2017/7/11 */ +@Data public class MemberCardUserInfo implements Serializable { private static final long serialVersionUID = -4259196162619282129L; @@ -12,19 +16,4 @@ public class MemberCardUserInfo implements Serializable { private NameValues[] customFieldList; - public NameValues[] getCommonFieldList() { - return commonFieldList; - } - - public void setCommonFieldList(NameValues[] commonFieldList) { - this.commonFieldList = commonFieldList; - } - - public NameValues[] getCustomFieldList() { - return customFieldList; - } - - public void setCustomFieldList(NameValues[] customFieldList) { - this.customFieldList = customFieldList; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/NameValues.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/NameValues.java index a5c62e5e6a..f285855535 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/NameValues.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/NameValues.java @@ -1,10 +1,15 @@ package me.chanjar.weixin.mp.bean.membercard; +import lombok.Data; + import java.io.Serializable; /** - * Created by YuJian on 2017/7/11. + * + * @author YuJian + * @date 2017/7/11 */ +@Data public class NameValues implements Serializable{ private static final long serialVersionUID = -8529369702944594330L; @@ -14,27 +19,4 @@ public class NameValues implements Serializable{ private String[] valueList; - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - public String[] getValueList() { - return valueList; - } - - public void setValueList(String[] valueList) { - this.valueList = valueList; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/NotifyOptional.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/NotifyOptional.java index e44ec4b5ac..c4d25c97e8 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/NotifyOptional.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/NotifyOptional.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean.membercard; import com.google.gson.annotations.SerializedName; +import lombok.Data; import java.io.Serializable; @@ -15,6 +16,7 @@ * @author YuJian(mgcnrx11@gmail.com) * @version 2017/7/15 */ +@Data public class NotifyOptional implements Serializable { private static final long serialVersionUID = 4488842021504939176L; @@ -41,44 +43,4 @@ public class NotifyOptional implements Serializable { @SerializedName("is_notify_custom_field3") private Boolean isNotifyCustomField3; - - public Boolean getNotifyBonus() { - return isNotifyBonus; - } - - public void setNotifyBonus(Boolean notifyBonus) { - isNotifyBonus = notifyBonus; - } - - public Boolean getNotifyBalance() { - return isNotifyBalance; - } - - public void setNotifyBalance(Boolean notifyBalance) { - isNotifyBalance = notifyBalance; - } - - public Boolean getNotifyCustomField1() { - return isNotifyCustomField1; - } - - public void setNotifyCustomField1(Boolean notifyCustomField1) { - isNotifyCustomField1 = notifyCustomField1; - } - - public Boolean getNotifyCustomField2() { - return isNotifyCustomField2; - } - - public void setNotifyCustomField2(Boolean notifyCustomField2) { - isNotifyCustomField2 = notifyCustomField2; - } - - public Boolean getNotifyCustomField3() { - return isNotifyCustomField3; - } - - public void setNotifyCustomField3(Boolean notifyCustomField3) { - isNotifyCustomField3 = notifyCustomField3; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/WxMpMemberCardActivatedMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/WxMpMemberCardActivatedMessage.java index 0c782e3c51..d9232844dc 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/WxMpMemberCardActivatedMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/WxMpMemberCardActivatedMessage.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean.membercard; import com.google.gson.annotations.SerializedName; +import lombok.Data; import java.io.Serializable; @@ -10,6 +11,7 @@ * @author YuJian(mgcnrx11@hotmail.com) * @version 2017/7/8 */ +@Data public class WxMpMemberCardActivatedMessage implements Serializable { private static final long serialVersionUID = -5972713484594266480L; @@ -73,99 +75,4 @@ public class WxMpMemberCardActivatedMessage implements Serializable { @SerializedName("init_custom_field_value3") private String initCustomFieldValue3; - public String getMembershipNumber() { - return membershipNumber; - } - - public void setMembershipNumber(String membershipNumber) { - this.membershipNumber = membershipNumber; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getCardId() { - return cardId; - } - - public void setCardId(String cardId) { - this.cardId = cardId; - } - - public String getBackgroundPicUrl() { - return backgroundPicUrl; - } - - public void setBackgroundPicUrl(String backgroundPicUrl) { - this.backgroundPicUrl = backgroundPicUrl; - } - - public Integer getActivateBeginTime() { - return activateBeginTime; - } - - public void setActivateBeginTime(Integer activateBeginTime) { - this.activateBeginTime = activateBeginTime; - } - - public Integer getActivateEndTime() { - return activateEndTime; - } - - public void setActivateEndTime(Integer activateEndTime) { - this.activateEndTime = activateEndTime; - } - - public Integer getInitBonus() { - return initBonus; - } - - public void setInitBonus(Integer initBonus) { - this.initBonus = initBonus; - } - - public String getInitBonusRecord() { - return initBonusRecord; - } - - public void setInitBonusRecord(String initBonusRecord) { - this.initBonusRecord = initBonusRecord; - } - - public Integer getInitBalance() { - return initBalance; - } - - public void setInitBalance(Integer initBalance) { - this.initBalance = initBalance; - } - - public String getInitCustomFieldValue1() { - return initCustomFieldValue1; - } - - public void setInitCustomFieldValue1(String initCustomFieldValue1) { - this.initCustomFieldValue1 = initCustomFieldValue1; - } - - public String getInitCustomFieldValue2() { - return initCustomFieldValue2; - } - - public void setInitCustomFieldValue2(String initCustomFieldValue2) { - this.initCustomFieldValue2 = initCustomFieldValue2; - } - - public String getInitCustomFieldValue3() { - return initCustomFieldValue3; - } - - public void setInitCustomFieldValue3(String initCustomFieldValue3) { - this.initCustomFieldValue3 = initCustomFieldValue3; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/WxMpMemberCardUpdateMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/WxMpMemberCardUpdateMessage.java index 313ba66282..f666e65504 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/WxMpMemberCardUpdateMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/WxMpMemberCardUpdateMessage.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean.membercard; import com.google.gson.annotations.SerializedName; +import lombok.Data; import java.io.Serializable; @@ -16,6 +17,7 @@ * @author YuJian(mgcnrx11@gmail.com) * @version 2017/7/15 */ +@Data public class WxMpMemberCardUpdateMessage implements Serializable { private static final long serialVersionUID = 4953923160718911058L; @@ -75,107 +77,4 @@ public class WxMpMemberCardUpdateMessage implements Serializable { @SerializedName("notify_optional") private NotifyOptional notifyOptional; - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getCardId() { - return cardId; - } - - public void setCardId(String cardId) { - this.cardId = cardId; - } - - public String getBackgroundPicUrl() { - return backgroundPicUrl; - } - - public void setBackgroundPicUrl(String backgroundPicUrl) { - this.backgroundPicUrl = backgroundPicUrl; - } - - public Integer getBonus() { - return bonus; - } - - public void setBonus(Integer bonus) { - this.bonus = bonus; - } - - public Integer getAddBounus() { - return addBounus; - } - - public void setAddBounus(Integer addBounus) { - this.addBounus = addBounus; - } - - public String getRecordBonus() { - return recordBonus; - } - - public void setRecordBonus(String recordBonus) { - this.recordBonus = recordBonus; - } - - public Integer getBalance() { - return balance; - } - - public void setBalance(Integer balance) { - this.balance = balance; - } - - public Integer getAddBalance() { - return addBalance; - } - - public void setAddBalance(Integer addBalance) { - this.addBalance = addBalance; - } - - public String getRecordBalance() { - return recordBalance; - } - - public void setRecordBalance(String recordBalance) { - this.recordBalance = recordBalance; - } - - public String getCustomFieldValue1() { - return customFieldValue1; - } - - public void setCustomFieldValue1(String customFieldValue1) { - this.customFieldValue1 = customFieldValue1; - } - - public String getCustomFieldValue2() { - return customFieldValue2; - } - - public void setCustomFieldValue2(String customFieldValue2) { - this.customFieldValue2 = customFieldValue2; - } - - public String getCustomFieldValue3() { - return customFieldValue3; - } - - public void setCustomFieldValue3(String customFieldValue3) { - this.customFieldValue3 = customFieldValue3; - } - - public NotifyOptional getNotifyOptional() { - return notifyOptional; - } - - public void setNotifyOptional(NotifyOptional notifyOptional) { - this.notifyOptional = notifyOptional; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/WxMpMemberCardUpdateResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/WxMpMemberCardUpdateResult.java index 2cbe2efb2f..7ceac8e81c 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/WxMpMemberCardUpdateResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/WxMpMemberCardUpdateResult.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean.membercard; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -14,6 +15,7 @@ * @author YuJian(mgcnrx11@gmail.com) * @version 2017/7/15 */ +@Data public class WxMpMemberCardUpdateResult implements Serializable { private static final long serialVersionUID = 9084886191442098311L; @@ -28,46 +30,6 @@ public class WxMpMemberCardUpdateResult implements Serializable { private Integer resultBalance; - public String getErrorCode() { - return errorCode; - } - - public void setErrorCode(String errorCode) { - this.errorCode = errorCode; - } - - public String getErrorMsg() { - return errorMsg; - } - - public void setErrorMsg(String errorMsg) { - this.errorMsg = errorMsg; - } - - public String getOpenId() { - return openId; - } - - public void setOpenId(String openId) { - this.openId = openId; - } - - public Integer getResultBonus() { - return resultBonus; - } - - public void setResultBonus(Integer resultBonus) { - this.resultBonus = resultBonus; - } - - public Integer getResultBalance() { - return resultBalance; - } - - public void setResultBalance(Integer resultBalance) { - this.resultBalance = resultBalance; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/WxMpMemberCardUserInfoResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/WxMpMemberCardUserInfoResult.java index 82a24cd297..a0ad47f356 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/WxMpMemberCardUserInfoResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/membercard/WxMpMemberCardUserInfoResult.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean.membercard; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -15,6 +16,7 @@ * @author YuJian * @version 2017/7/9 */ +@Data public class WxMpMemberCardUserInfoResult implements Serializable { private static final long serialVersionUID = 9084777967442098311L; @@ -39,90 +41,6 @@ public class WxMpMemberCardUserInfoResult implements Serializable { private Boolean hasActive; - public static long getSerialVersionUID() { - return serialVersionUID; - } - - public String getErrorCode() { - return errorCode; - } - - public void setErrorCode(String errorCode) { - this.errorCode = errorCode; - } - - public String getErrorMsg() { - return errorMsg; - } - - public void setErrorMsg(String errorMsg) { - this.errorMsg = errorMsg; - } - - public String getOpenId() { - return openId; - } - - public void setOpenId(String openId) { - this.openId = openId; - } - - public String getNickname() { - return nickname; - } - - public void setNickname(String nickname) { - this.nickname = nickname; - } - - public String getMembershipNumber() { - return membershipNumber; - } - - public void setMembershipNumber(String membershipNumber) { - this.membershipNumber = membershipNumber; - } - - public Integer getBonus() { - return bonus; - } - - public void setBonus(Integer bonus) { - this.bonus = bonus; - } - - public String getSex() { - return sex; - } - - public void setSex(String sex) { - this.sex = sex; - } - - public MemberCardUserInfo getUserInfo() { - return userInfo; - } - - public void setUserInfo(MemberCardUserInfo userInfo) { - this.userInfo = userInfo; - } - - public String getUserCardStatus() { - return userCardStatus; - } - - public void setUserCardStatus(String userCardStatus) { - this.userCardStatus = userCardStatus; - } - - public Boolean getHasActive() { - return hasActive; - } - - public void setHasActive(Boolean hasActive) { - this.hasActive = hasActive; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpGetSelfMenuInfoResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpGetSelfMenuInfoResult.java index 295a782696..b8258b1d1c 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpGetSelfMenuInfoResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpGetSelfMenuInfoResult.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean.menu; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.common.util.json.WxGsonBuilder; @@ -9,9 +10,11 @@ /** *
  * Created by Binary Wang on 2016-11-25.
- * @author binarywang(Binary Wang)
  * 
+ * + * @author Binary Wang */ +@Data public class WxMpGetSelfMenuInfoResult implements Serializable { private static final long serialVersionUID = -5612495636936835166L; @@ -30,19 +33,4 @@ public String toString() { return ToStringUtils.toSimpleString(this); } - public WxMpSelfMenuInfo getSelfMenuInfo() { - return selfMenuInfo; - } - - public void setSelfMenuInfo(WxMpSelfMenuInfo selfMenuInfo) { - this.selfMenuInfo = selfMenuInfo; - } - - public Integer getIsMenuOpen() { - return isMenuOpen; - } - - public void setIsMenuOpen(Integer isMenuOpen) { - this.isMenuOpen = isMenuOpen; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpMenu.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpMenu.java index 5e93d7e0d6..1847be3f08 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpMenu.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpMenu.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean.menu; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.bean.menu.WxMenuButton; import me.chanjar.weixin.common.bean.menu.WxMenuRule; import me.chanjar.weixin.common.util.ToStringUtils; @@ -13,9 +14,11 @@ *
  *   公众号专用的菜单类,可能包含个性化菜单
  * Created by Binary Wang on 2017-1-17.
- * @author binarywang(Binary Wang)
  * 
+ * + * @author Binary Wang */ +@Data public class WxMpMenu implements Serializable { private static final long serialVersionUID = -5794350513426702252L; @@ -29,22 +32,6 @@ public static WxMpMenu fromJson(String json) { return WxGsonBuilder.create().fromJson(json, WxMpMenu.class); } - public WxMpConditionalMenu getMenu() { - return menu; - } - - public void setMenu(WxMpConditionalMenu menu) { - this.menu = menu; - } - - public List getConditionalMenu() { - return conditionalMenu; - } - - public void setConditionalMenu(List conditionalMenu) { - this.conditionalMenu = conditionalMenu; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); @@ -54,6 +41,7 @@ public String toJson() { return WxGsonBuilder.create().toJson(this); } + @Data public static class WxMpConditionalMenu implements Serializable { private static final long serialVersionUID = -2279946921755382289L; @@ -69,29 +57,6 @@ public String toString() { return ToStringUtils.toSimpleString(this); } - public List getButtons() { - return buttons; - } - - public void setButtons(List buttons) { - this.buttons = buttons; - } - - public WxMenuRule getRule() { - return rule; - } - - public void setRule(WxMenuRule rule) { - this.rule = rule; - } - - public String getMenuId() { - return menuId; - } - - public void setMenuId(String menuId) { - this.menuId = menuId; - } } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpSelfMenuInfo.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpSelfMenuInfo.java index c278bd4c1a..2532a092de 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpSelfMenuInfo.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpSelfMenuInfo.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean.menu; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import java.io.Serializable; @@ -10,9 +11,11 @@ /** *
  * Created by Binary Wang on 2016-11-25.
- * @author binarywang(Binary Wang)
  * 
+ * + * @author Binary Wang */ +@Data public class WxMpSelfMenuInfo implements Serializable { private static final long serialVersionUID = -81203094124202901L; @@ -27,15 +30,10 @@ public String toString() { return ToStringUtils.toSimpleString(this); } - public List getButtons() { - return this.buttons; - } - - public void setButtons(List buttons) { - this.buttons = buttons; - } + @Data + public static class WxMpSelfMenuButton implements Serializable { + private static final long serialVersionUID = -4426602953309048341L; - public static class WxMpSelfMenuButton { /** *
      * 菜单的类型,公众平台官网上能够设置的菜单类型有view(跳转网页)、text(返回文本,下同)、img、photo、video、voice。
@@ -92,63 +90,10 @@ public String toString() {
       return ToStringUtils.toSimpleString(this);
     }
 
-    public SubButtons getSubButtons() {
-      return subButtons;
-    }
+    @Data
+    public static class SubButtons implements Serializable {
+      private static final long serialVersionUID = 1763350658575521079L;
 
-    public void setSubButtons(SubButtons subButtons) {
-      this.subButtons = subButtons;
-    }
-
-    public String getType() {
-      return type;
-    }
-
-    public void setType(String type) {
-      this.type = type;
-    }
-
-    public String getName() {
-      return name;
-    }
-
-    public void setName(String name) {
-      this.name = name;
-    }
-
-    public String getKey() {
-      return key;
-    }
-
-    public void setKey(String key) {
-      this.key = key;
-    }
-
-    public String getUrl() {
-      return url;
-    }
-
-    public void setUrl(String url) {
-      this.url = url;
-    }
-
-    public String getValue() {
-      return value;
-    }
-
-    public void setValue(String value) {
-      this.value = value;
-    }
-
-    public NewsInfo getNewsInfo() {
-      return newsInfo;
-    }
-
-    public void setNewsInfo(NewsInfo newsInfo) {
-      this.newsInfo = newsInfo;
-    }
-
-    public static class SubButtons {
       @SerializedName("list")
       private List subButtons = new ArrayList<>();
 
@@ -156,17 +101,12 @@ public static class SubButtons {
       public String toString() {
         return ToStringUtils.toSimpleString(this);
       }
-
-      public List getSubButtons() {
-        return subButtons;
-      }
-
-      public void setSubButtons(List subButtons) {
-        this.subButtons = subButtons;
-      }
     }
 
-    public static class NewsInfo {
+    @Data
+    public static class NewsInfo implements Serializable {
+      private static final long serialVersionUID = 3449813746347818457L;
+
       @SerializedName("list")
       private List news = new ArrayList<>();
 
@@ -175,15 +115,10 @@ public String toString() {
         return ToStringUtils.toSimpleString(this);
       }
 
-      public List getNews() {
-        return news;
-      }
-
-      public void setNews(List news) {
-        this.news = news;
-      }
+      @Data
+      public static class NewsInButton  implements Serializable {
+        private static final long serialVersionUID = 8701455967664912972L;
 
-      public static class NewsInButton {
         /**
          * 图文消息的标题
          */
@@ -226,61 +161,6 @@ public String toString() {
           return ToStringUtils.toSimpleString(this);
         }
 
-        public String getTitle() {
-          return title;
-        }
-
-        public void setTitle(String title) {
-          this.title = title;
-        }
-
-        public String getDigest() {
-          return digest;
-        }
-
-        public void setDigest(String digest) {
-          this.digest = digest;
-        }
-
-        public String getAuthor() {
-          return author;
-        }
-
-        public void setAuthor(String author) {
-          this.author = author;
-        }
-
-        public Integer getShowCover() {
-          return showCover;
-        }
-
-        public void setShowCover(Integer showCover) {
-          this.showCover = showCover;
-        }
-
-        public String getCoverUrl() {
-          return coverUrl;
-        }
-
-        public void setCoverUrl(String coverUrl) {
-          this.coverUrl = coverUrl;
-        }
-
-        public String getContentUrl() {
-          return contentUrl;
-        }
-
-        public void setContentUrl(String contentUrl) {
-          this.contentUrl = contentUrl;
-        }
-
-        public String getSourceUrl() {
-          return sourceUrl;
-        }
-
-        public void setSourceUrl(String sourceUrl) {
-          this.sourceUrl = sourceUrl;
-        }
       }
     }
   }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/HardWare.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/HardWare.java
index 1ef3ee6b7c..6cef393eb5 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/HardWare.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/HardWare.java
@@ -2,6 +2,7 @@
 
 import com.thoughtworks.xstream.annotations.XStreamAlias;
 import com.thoughtworks.xstream.annotations.XStreamConverter;
+import lombok.Data;
 import me.chanjar.weixin.common.util.ToStringUtils;
 import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
 
@@ -15,6 +16,7 @@
  * @author Binary Wang
  */
 @XStreamAlias("HardWare")
+@Data
 public class HardWare implements Serializable{
   private static final long serialVersionUID = -1295785297354896461L;
 
@@ -35,20 +37,4 @@ public class HardWare implements Serializable{
   public String toString() {
     return ToStringUtils.toSimpleString(this);
   }
-
-  public String getMessageView() {
-    return messageView;
-  }
-
-  public void setMessageView(String messageView) {
-    this.messageView = messageView;
-  }
-
-  public String getMessageAction() {
-    return messageAction;
-  }
-
-  public void setMessageAction(String messageAction) {
-    this.messageAction = messageAction;
-  }
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/ScanCodeInfo.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/ScanCodeInfo.java
index c5c32cb522..630090c2f2 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/ScanCodeInfo.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/ScanCodeInfo.java
@@ -2,6 +2,7 @@
 
 import com.thoughtworks.xstream.annotations.XStreamAlias;
 import com.thoughtworks.xstream.annotations.XStreamConverter;
+import lombok.Data;
 import me.chanjar.weixin.common.util.ToStringUtils;
 import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
 
@@ -15,6 +16,7 @@
  * @author Binary Wang
  */
 @XStreamAlias("ScanCodeInfo")
+@Data
 public class ScanCodeInfo implements Serializable {
   private static final long serialVersionUID = 4745181270645050122L;
 
@@ -37,10 +39,6 @@ public String getScanType() {
     return this.scanType;
   }
 
-  public void setScanType(String scanType) {
-    this.scanType = scanType;
-  }
-
   /**
    * 扫描结果,即二维码对应的字符串信息
    */
@@ -48,8 +46,5 @@ public String getScanResult() {
     return this.scanResult;
   }
 
-  public void setScanResult(String scanResult) {
-    this.scanResult = scanResult;
-  }
 
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/SendLocationInfo.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/SendLocationInfo.java
index 8ecb3c8bff..c7c8fda6b8 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/SendLocationInfo.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/SendLocationInfo.java
@@ -2,6 +2,7 @@
 
 import com.thoughtworks.xstream.annotations.XStreamAlias;
 import com.thoughtworks.xstream.annotations.XStreamConverter;
+import lombok.Data;
 import me.chanjar.weixin.common.util.ToStringUtils;
 import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
 
@@ -15,6 +16,7 @@
  * @author Binary Wang
  */
 @XStreamAlias("SendLocationInfo")
+@Data
 public class SendLocationInfo implements Serializable {
   private static final long serialVersionUID = 6633214140499161130L;
 
@@ -36,50 +38,10 @@ public class SendLocationInfo implements Serializable {
 
   @XStreamAlias("Poiname")
   @XStreamConverter(value = XStreamCDataConverter.class)
-  private String poiname;
+  private String poiName;
 
   @Override
   public String toString() {
     return ToStringUtils.toSimpleString(this);
   }
-
-  public String getLocationX() {
-    return this.locationX;
-  }
-
-  public void setLocationX(String locationX) {
-    this.locationX = locationX;
-  }
-
-  public String getLocationY() {
-    return this.locationY;
-  }
-
-  public void setLocationY(String locationY) {
-    this.locationY = locationY;
-  }
-
-  public String getScale() {
-    return this.scale;
-  }
-
-  public void setScale(String scale) {
-    this.scale = scale;
-  }
-
-  public String getLabel() {
-    return this.label;
-  }
-
-  public void setLabel(String label) {
-    this.label = label;
-  }
-
-  public String getPoiname() {
-    return this.poiname;
-  }
-
-  public void setPoiname(String poiname) {
-    this.poiname = poiname;
-  }
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/SendPicsInfo.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/SendPicsInfo.java
index cf5c374edf..51806768a2 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/SendPicsInfo.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/SendPicsInfo.java
@@ -2,6 +2,7 @@
 
 import com.thoughtworks.xstream.annotations.XStreamAlias;
 import com.thoughtworks.xstream.annotations.XStreamConverter;
+import lombok.Data;
 import me.chanjar.weixin.common.util.ToStringUtils;
 import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
 
@@ -17,6 +18,7 @@
  * @author Binary Wang
  */
 @XStreamAlias("SendPicsInfo")
+@Data
 public class SendPicsInfo implements Serializable {
   private static final long serialVersionUID = -4572837013294199227L;
 
@@ -31,19 +33,8 @@ public String toString() {
     return ToStringUtils.toSimpleString(this);
   }
 
-  public Long getCount() {
-    return this.count;
-  }
-
-  public void setCount(Long count) {
-    this.count = count;
-  }
-
-  public List getPicList() {
-    return this.picList;
-  }
-
   @XStreamAlias("item")
+  @Data
   public static class Item implements Serializable {
     private static final long serialVersionUID = 7706235740094081194L;
 
@@ -56,12 +47,5 @@ public String toString() {
       return ToStringUtils.toSimpleString(this);
     }
 
-    public String getPicMd5Sum() {
-      return this.picMd5Sum;
-    }
-
-    public void setPicMd5Sum(String picMd5Sum) {
-      this.picMd5Sum = picMd5Sum;
-    }
   }
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java
index 2ea17b9e07..8c67e0368a 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java
@@ -2,6 +2,8 @@
 
 import com.thoughtworks.xstream.annotations.XStreamAlias;
 import com.thoughtworks.xstream.annotations.XStreamConverter;
+import lombok.Data;
+import me.chanjar.weixin.common.api.WxConsts;
 import me.chanjar.weixin.common.util.ToStringUtils;
 import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
 import me.chanjar.weixin.mp.api.WxMpConfigStorage;
@@ -24,6 +26,7 @@
  * @author chanjarster
  */
 @XStreamAlias("xml")
+@Data
 public class WxMpXmlMessage implements Serializable {
   private static final long serialVersionUID = -3586245291677274914L;
 
@@ -462,193 +465,16 @@ public static WxMpXmlMessage fromEncryptedXml(InputStream is,
     }
   }
 
-  public Integer getOpType() {
-    return opType;
-  }
-
-  public void setOpType(Integer opType) {
-    this.opType = opType;
-  }
-
-  public Integer getDeviceStatus() {
-
-    return deviceStatus;
-  }
-
-  public void setDeviceStatus(Integer deviceStatus) {
-    this.deviceStatus = deviceStatus;
-  }
-
-  public HardWare getHardWare() {
-    return hardWare;
-  }
-
-  public void setHardWare(HardWare hardWare) {
-    this.hardWare = hardWare;
-  }
-
-  public String getDeviceType() {
-    return deviceType;
-  }
-
-  public void setDeviceType(String deviceType) {
-    this.deviceType = deviceType;
-  }
-
-  public String getDeviceId() {
-    return deviceId;
-  }
-
-  public void setDeviceId(String deviceId) {
-    this.deviceId = deviceId;
-  }
-
-  public String getOpenId() {
-    return openId;
-  }
-
-  public void setOpenId(String openId) {
-    this.openId = openId;
-  }
-
-  public Long getExpiredTime() {
-    return this.expiredTime;
-  }
-
-  public void setExpiredTime(Long expiredTime) {
-    this.expiredTime = expiredTime;
-  }
-
-  public Long getFailTime() {
-    return this.failTime;
-  }
-
-  public void setFailTime(Long failTime) {
-    this.failTime = failTime;
-  }
-
-  public String getFailReason() {
-    return this.failReason;
-  }
-
-  public void setFailReason(String failReason) {
-    this.failReason = failReason;
-  }
-
-  public String getDetail() {
-    return detail;
-  }
-
-  public void setDetail(String detail) {
-    this.detail = detail;
-  }
-
-  public String getModifyBonus() {
-    return modifyBonus;
-  }
-
-  public void setModifyBonus(String modifyBonus) {
-    this.modifyBonus = modifyBonus;
-  }
-
-  public String getModifyBalance() {
-    return modifyBalance;
-  }
-
-  public void setModifyBalance(String modifyBalance) {
-    this.modifyBalance = modifyBalance;
-  }
-
-  public String getTransId() {
-    return transId;
-  }
-
-  public void setTransId(String transId) {
-    this.transId = transId;
-  }
-
-  public String getLocationId() {
-    return locationId;
-  }
-
-  public void setLocationId(String locationId) {
-    this.locationId = locationId;
-  }
-
-  public String getFee() {
-    return fee;
-  }
-
-  public void setFee(String fee) {
-    this.fee = fee;
-  }
-
-  public String getOriginalFee() {
-    return originalFee;
-  }
-
-  public void setOriginalFee(String originalFee) {
-    this.originalFee = originalFee;
-  }
-
-  public String getStoreUniqId() {
-    return this.storeUniqId;
-  }
-
-  public void setStoreUniqId(String storeUniqId) {
-    this.storeUniqId = storeUniqId;
-  }
-
-  public String getPoiId() {
-    return this.poiId;
-  }
-
-  public void setPoiId(String poiId) {
-    this.poiId = poiId;
-  }
-
-  public String getResult() {
-    return this.result;
-  }
-
-  public void setResult(String result) {
-    this.result = result;
-  }
-
-  public String getMsg() {
-    return this.msg;
-  }
-
-  public void setMsg(String msg) {
-    this.msg = msg;
-  }
-
-  public String getToUser() {
-    return this.toUser;
-  }
-
-  public void setToUser(String toUser) {
-    this.toUser = toUser;
-  }
-
-  public Long getCreateTime() {
-    return this.createTime;
-  }
-
-  public void setCreateTime(Long createTime) {
-    this.createTime = createTime;
-  }
-
   /**
    * 
    * 当接受用户消息时,可能会获得以下值:
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_TEXT}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_IMAGE}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_VOICE}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_VIDEO}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_LOCATION}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_LINK}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_EVENT}
+   * {@link WxConsts.XmlMsgType#TEXT}
+   * {@link WxConsts.XmlMsgType#IMAGE}
+   * {@link WxConsts.XmlMsgType#VOICE}
+   * {@link WxConsts.XmlMsgType#VIDEO}
+   * {@link WxConsts.XmlMsgType#LOCATION}
+   * {@link WxConsts.XmlMsgType#LINK}
+   * {@link WxConsts.XmlMsgType#EVENT}
    * 
*/ public String getMsgType() { @@ -658,405 +484,19 @@ public String getMsgType() { /** *
    * 当发送消息的时候使用:
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_TEXT}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_IMAGE}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_VOICE}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_VIDEO}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_NEWS}
-   * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_MUSIC}
+   * {@link WxConsts.XmlMsgType#TEXT}
+   * {@link WxConsts.XmlMsgType#IMAGE}
+   * {@link WxConsts.XmlMsgType#VOICE}
+   * {@link WxConsts.XmlMsgType#VIDEO}
+   * {@link WxConsts.XmlMsgType#NEWS}
+   * {@link WxConsts.XmlMsgType#MUSIC}
    * 
* - * @param msgType */ public void setMsgType(String msgType) { this.msgType = msgType; } - public String getContent() { - return this.content; - } - - public void setContent(String content) { - this.content = content; - } - - public Long getMsgId() { - return this.msgId; - } - - public void setMsgId(Long msgId) { - this.msgId = msgId; - } - - public String getPicUrl() { - return this.picUrl; - } - - public void setPicUrl(String picUrl) { - this.picUrl = picUrl; - } - - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } - - public String getFormat() { - return this.format; - } - - public void setFormat(String format) { - this.format = format; - } - - public String getThumbMediaId() { - return this.thumbMediaId; - } - - public void setThumbMediaId(String thumbMediaId) { - this.thumbMediaId = thumbMediaId; - } - - public Double getLocationX() { - return this.locationX; - } - - public void setLocationX(Double locationX) { - this.locationX = locationX; - } - - public Double getLocationY() { - return this.locationY; - } - - public void setLocationY(Double locationY) { - this.locationY = locationY; - } - - public Double getScale() { - return this.scale; - } - - public void setScale(Double scale) { - this.scale = scale; - } - - public String getLabel() { - return this.label; - } - - public void setLabel(String label) { - this.label = label; - } - - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getUrl() { - return this.url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getEvent() { - return this.event; - } - - public void setEvent(String event) { - this.event = event; - } - - public String getEventKey() { - return this.eventKey; - } - - public void setEventKey(String eventKey) { - this.eventKey = eventKey; - } - - public String getTicket() { - return this.ticket; - } - - public void setTicket(String ticket) { - this.ticket = ticket; - } - - public Double getLatitude() { - return this.latitude; - } - - public void setLatitude(Double latitude) { - this.latitude = latitude; - } - - public Double getLongitude() { - return this.longitude; - } - - public void setLongitude(Double longitude) { - this.longitude = longitude; - } - - public Double getPrecision() { - return this.precision; - } - - public void setPrecision(Double precision) { - this.precision = precision; - } - - public String getRecognition() { - return this.recognition; - } - - public void setRecognition(String recognition) { - this.recognition = recognition; - } - - public String getFromUser() { - return this.fromUser; - } - - public void setFromUser(String fromUser) { - this.fromUser = fromUser; - } - - public String getStatus() { - return this.status; - } - - public void setStatus(String status) { - this.status = status; - } - - public Integer getTotalCount() { - return this.totalCount; - } - - public void setTotalCount(Integer totalCount) { - this.totalCount = totalCount; - } - - public Integer getFilterCount() { - return this.filterCount; - } - - public void setFilterCount(Integer filterCount) { - this.filterCount = filterCount; - } - - public Integer getSentCount() { - return this.sentCount; - } - - public void setSentCount(Integer sentCount) { - this.sentCount = sentCount; - } - - public Integer getErrorCount() { - return this.errorCount; - } - - public void setErrorCount(Integer errorCount) { - this.errorCount = errorCount; - } - - public String getCardId() { - return this.cardId; - } - - public void setCardId(String cardId) { - this.cardId = cardId; - } - - public String getFriendUserName() { - return this.friendUserName; - } - - public void setFriendUserName(String friendUserName) { - this.friendUserName = friendUserName; - } - - public Integer getIsGiveByFriend() { - return this.isGiveByFriend; - } - - public void setIsGiveByFriend(Integer isGiveByFriend) { - this.isGiveByFriend = isGiveByFriend; - } - - public String getUserCardCode() { - return this.userCardCode; - } - - public void setUserCardCode(String userCardCode) { - this.userCardCode = userCardCode; - } - - public String getOldUserCardCode() { - return this.oldUserCardCode; - } - - public void setOldUserCardCode(String oldUserCardCode) { - this.oldUserCardCode = oldUserCardCode; - } - - public Integer getOuterId() { - return this.outerId; - } - - public void setOuterId(Integer outerId) { - this.outerId = outerId; - } - - public ScanCodeInfo getScanCodeInfo() { - return this.scanCodeInfo; - } - - public void setScanCodeInfo(ScanCodeInfo scanCodeInfo) { - this.scanCodeInfo = scanCodeInfo; - } - - public SendPicsInfo getSendPicsInfo() { - return this.sendPicsInfo; - } - - public void setSendPicsInfo(SendPicsInfo sendPicsInfo) { - this.sendPicsInfo = sendPicsInfo; - } - - public SendLocationInfo getSendLocationInfo() { - return this.sendLocationInfo; - } - - public void setSendLocationInfo( - SendLocationInfo sendLocationInfo) { - this.sendLocationInfo = sendLocationInfo; - } - - public Long getMenuId() { - return this.menuId; - } - - public void setMenuId(Long menuId) { - this.menuId = menuId; - } - - public String getKfAccount() { - return this.kfAccount; - } - - public void setKfAccount(String kfAccount) { - this.kfAccount = kfAccount; - } - - public String getToKfAccount() { - return this.toKfAccount; - } - - public void setToKfAccount(String toKfAccount) { - this.toKfAccount = toKfAccount; - } - - public String getFromKfAccount() { - return this.fromKfAccount; - } - - public void setFromKfAccount(String fromKfAccount) { - this.fromKfAccount = fromKfAccount; - } - - public String getIsRestoreMemberCard() { - return isRestoreMemberCard; - } - - public void setIsRestoreMemberCard(String isRestoreMemberCard) { - this.isRestoreMemberCard = isRestoreMemberCard; - } - - public String getOuterStr() { - return outerStr; - } - - public void setOuterStr(String outerStr) { - this.outerStr = outerStr; - } - - public String getIsReturnBack() { - return isReturnBack; - } - - public void setIsReturnBack(String isReturnBack) { - this.isReturnBack = isReturnBack; - } - - public String getIsChatRoom() { - return isChatRoom; - } - - public void setIsChatRoom(String isChatRoom) { - this.isChatRoom = isChatRoom; - } - - public String getConsumeSource() { - return this.consumeSource; - } - - public void setConsumeSource(String consumeSource) { - this.consumeSource = consumeSource; - } - - public String getLocationName() { - return this.locationName; - } - - public void setLocationName(String locationName) { - this.locationName = locationName; - } - - public String getStaffOpenId() { - return this.staffOpenId; - } - - public void setStaffOpenId(String staffOpenId) { - this.staffOpenId = staffOpenId; - } - - public String getVerifyCode() { - return this.verifyCode; - } - - public void setVerifyCode(String verifyCode) { - this.verifyCode = verifyCode; - } - - public String getRemarkAmount() { - return this.remarkAmount; - } - - public void setRemarkAmount(String remarkAmount) { - this.remarkAmount = remarkAmount; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutImageMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutImageMessage.java index c18508b527..dbb0ab90f9 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutImageMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutImageMessage.java @@ -2,10 +2,14 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamConverter; +import lombok.Data; +import lombok.EqualsAndHashCode; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.util.xml.XStreamMediaIdConverter; @XStreamAlias("xml") +@Data +@EqualsAndHashCode(callSuper = true) public class WxMpXmlOutImageMessage extends WxMpXmlOutMessage { private static final long serialVersionUID = -2684778597067990723L; @@ -14,15 +18,7 @@ public class WxMpXmlOutImageMessage extends WxMpXmlOutMessage { private String mediaId; public WxMpXmlOutImageMessage() { - this.msgType = WxConsts.XML_MSG_IMAGE; - } - - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; + this.msgType = WxConsts.XmlMsgType.IMAGE; } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMessage.java index c84cc665b9..b1940fc487 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMessage.java @@ -2,6 +2,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamConverter; +import lombok.Data; import me.chanjar.weixin.common.util.xml.XStreamCDataConverter; import me.chanjar.weixin.mp.api.WxMpConfigStorage; import me.chanjar.weixin.mp.builder.outxml.*; @@ -11,6 +12,7 @@ import java.io.Serializable; @XStreamAlias("xml") +@Data public abstract class WxMpXmlOutMessage implements Serializable { private static final long serialVersionUID = -381382011286216263L; @@ -78,38 +80,6 @@ public static TransferCustomerServiceBuilder TRANSFER_CUSTOMER_SERVICE() { return new TransferCustomerServiceBuilder(); } - public String getToUserName() { - return this.toUserName; - } - - public void setToUserName(String toUserName) { - this.toUserName = toUserName; - } - - public String getFromUserName() { - return this.fromUserName; - } - - public void setFromUserName(String fromUserName) { - this.fromUserName = fromUserName; - } - - public Long getCreateTime() { - return this.createTime; - } - - public void setCreateTime(Long createTime) { - this.createTime = createTime; - } - - public String getMsgType() { - return this.msgType; - } - - public void setMsgType(String msgType) { - this.msgType = msgType; - } - @SuppressWarnings("unchecked") public String toXml() { return XStreamTransformer.toXml((Class) this.getClass(), this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessage.java index 2676e69077..1124f45857 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessage.java @@ -2,10 +2,16 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamConverter; +import lombok.Data; +import lombok.EqualsAndHashCode; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.util.xml.XStreamCDataConverter; +import java.io.Serializable; + @XStreamAlias("xml") +@Data +@EqualsAndHashCode(callSuper = true) public class WxMpXmlOutMusicMessage extends WxMpXmlOutMessage { private static final long serialVersionUID = -4159937804975448945L; @@ -13,51 +19,13 @@ public class WxMpXmlOutMusicMessage extends WxMpXmlOutMessage { protected final Music music = new Music(); public WxMpXmlOutMusicMessage() { - this.msgType = WxConsts.XML_MSG_MUSIC; - } - - public String getTitle() { - return this.music.getTitle(); - } - - public void setTitle(String title) { - this.music.setTitle(title); - } - - public String getDescription() { - return this.music.getDescription(); - } - - public void setDescription(String description) { - this.music.setDescription(description); - } - - public String getThumbMediaId() { - return this.music.getThumbMediaId(); - } - - public void setThumbMediaId(String thumbMediaId) { - this.music.setThumbMediaId(thumbMediaId); - } - - public String getMusicUrl() { - return this.music.getMusicUrl(); - } - - public void setMusicUrl(String musicUrl) { - this.music.setMusicUrl(musicUrl); - } - - public String getHqMusicUrl() { - return this.music.getHqMusicUrl(); - } - - public void setHqMusicUrl(String hqMusicUrl) { - this.music.setHqMusicUrl(hqMusicUrl); + this.msgType = WxConsts.XmlMsgType.MUSIC; } @XStreamAlias("Music") - public static class Music { + @Data + public static class Music implements Serializable { + private static final long serialVersionUID = -5492592401691895334L; @XStreamAlias("Title") @XStreamConverter(value = XStreamCDataConverter.class) @@ -78,47 +46,46 @@ public static class Music { @XStreamAlias("HQMusicUrl") @XStreamConverter(value = XStreamCDataConverter.class) private String hqMusicUrl; + } - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } + public String getTitle() { + return this.music.title; + } - public String getDescription() { - return this.description; - } + public void setTitle(String title) { + this.music.title = title; + } - public void setDescription(String description) { - this.description = description; - } + public String getDescription() { + return this.music.description; + } - public String getThumbMediaId() { - return this.thumbMediaId; - } + public void setDescription(String description) { + this.music.description = description; + } - public void setThumbMediaId(String thumbMediaId) { - this.thumbMediaId = thumbMediaId; - } + public String getThumbMediaId() { + return this.music.thumbMediaId; + } - public String getMusicUrl() { - return this.musicUrl; - } + public void setThumbMediaId(String thumbMediaId) { + this.music.thumbMediaId = thumbMediaId; + } - public void setMusicUrl(String musicUrl) { - this.musicUrl = musicUrl; - } + public String getMusicUrl() { + return this.music.musicUrl; + } - public String getHqMusicUrl() { - return this.hqMusicUrl; - } + public void setMusicUrl(String musicUrl) { + this.music.musicUrl = musicUrl; + } - public void setHqMusicUrl(String hqMusicUrl) { - this.hqMusicUrl = hqMusicUrl; - } + public String getHqMusicUrl() { + return this.music.hqMusicUrl; + } + public void setHqMusicUrl(String hqMusicUrl) { + this.music.hqMusicUrl = hqMusicUrl; } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutNewsMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutNewsMessage.java index 797b042525..f7405600ef 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutNewsMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutNewsMessage.java @@ -2,6 +2,8 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamConverter; +import lombok.Data; +import lombok.EqualsAndHashCode; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.util.xml.XStreamCDataConverter; @@ -10,6 +12,8 @@ import java.util.List; @XStreamAlias("xml") +@Data +@EqualsAndHashCode(callSuper = true) public class WxMpXmlOutNewsMessage extends WxMpXmlOutMessage { private static final long serialVersionUID = -4604402850905714772L; @@ -19,11 +23,7 @@ public class WxMpXmlOutNewsMessage extends WxMpXmlOutMessage { protected int articleCount; public WxMpXmlOutNewsMessage() { - this.msgType = WxConsts.XML_MSG_NEWS; - } - - public int getArticleCount() { - return this.articleCount; + this.msgType = WxConsts.XmlMsgType.NEWS; } public void addArticle(Item item) { @@ -31,63 +31,26 @@ public void addArticle(Item item) { this.articleCount = this.articles.size(); } - public List getArticles() { - return this.articles; - } - - @XStreamAlias("item") + @Data public static class Item implements Serializable { - private static final long serialVersionUID = -4971456355028904754L; @XStreamAlias("Title") @XStreamConverter(value = XStreamCDataConverter.class) - private String Title; + private String title; @XStreamAlias("Description") @XStreamConverter(value = XStreamCDataConverter.class) - private String Description; + private String description; @XStreamAlias("PicUrl") @XStreamConverter(value = XStreamCDataConverter.class) - private String PicUrl; + private String picUrl; @XStreamAlias("Url") @XStreamConverter(value = XStreamCDataConverter.class) - private String Url; - - public String getTitle() { - return this.Title; - } - - public void setTitle(String title) { - this.Title = title; - } - - public String getDescription() { - return this.Description; - } - - public void setDescription(String description) { - this.Description = description; - } - - public String getPicUrl() { - return this.PicUrl; - } - - public void setPicUrl(String picUrl) { - this.PicUrl = picUrl; - } - - public String getUrl() { - return this.Url; - } - - public void setUrl(String url) { - this.Url = url; - } + private String url; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTextMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTextMessage.java index 7c98c625e7..cbaa05abc3 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTextMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTextMessage.java @@ -2,10 +2,14 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamConverter; +import lombok.Data; +import lombok.EqualsAndHashCode; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.util.xml.XStreamCDataConverter; @XStreamAlias("xml") +@Data +@EqualsAndHashCode(callSuper = true) public class WxMpXmlOutTextMessage extends WxMpXmlOutMessage { private static final long serialVersionUID = -3972786455288763361L; @@ -14,16 +18,7 @@ public class WxMpXmlOutTextMessage extends WxMpXmlOutMessage { private String content; public WxMpXmlOutTextMessage() { - this.msgType = WxConsts.XML_MSG_TEXT; + this.msgType = WxConsts.XmlMsgType.TEXT; } - public String getContent() { - return this.content; - } - - public void setContent(String content) { - this.content = content; - } - - } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTransferKefuMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTransferKefuMessage.java index 3a3cfc4b4c..5b0857830e 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTransferKefuMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTransferKefuMessage.java @@ -2,12 +2,16 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamConverter; +import lombok.Data; +import lombok.EqualsAndHashCode; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.util.xml.XStreamCDataConverter; import java.io.Serializable; @XStreamAlias("xml") +@Data +@EqualsAndHashCode(callSuper = true) public class WxMpXmlOutTransferKefuMessage extends WxMpXmlOutMessage { private static final long serialVersionUID = 1850903037285841322L; @@ -15,18 +19,11 @@ public class WxMpXmlOutTransferKefuMessage extends WxMpXmlOutMessage { protected TransInfo transInfo; public WxMpXmlOutTransferKefuMessage() { - this.msgType = WxConsts.CUSTOM_MSG_TRANSFER_CUSTOMER_SERVICE; - } - - public TransInfo getTransInfo() { - return this.transInfo; - } - - public void setTransInfo(TransInfo transInfo) { - this.transInfo = transInfo; + this.msgType = WxConsts.KefuMsgType.TRANSFER_CUSTOMER_SERVICE; } @XStreamAlias("TransInfo") + @Data public static class TransInfo implements Serializable { private static final long serialVersionUID = -6317885617135706056L; @@ -34,12 +31,5 @@ public static class TransInfo implements Serializable { @XStreamConverter(value = XStreamCDataConverter.class) private String kfAccount; - public String getKfAccount() { - return this.kfAccount; - } - - public void setKfAccount(String kfAccount) { - this.kfAccount = kfAccount; - } } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVideoMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVideoMessage.java index 346cd5b160..7f43a56809 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVideoMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVideoMessage.java @@ -2,12 +2,16 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamConverter; +import lombok.Data; +import lombok.EqualsAndHashCode; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.util.xml.XStreamCDataConverter; import java.io.Serializable; @XStreamAlias("xml") +@Data +@EqualsAndHashCode(callSuper = true) public class WxMpXmlOutVideoMessage extends WxMpXmlOutMessage { private static final long serialVersionUID = 1745902309380113978L; @@ -15,35 +19,11 @@ public class WxMpXmlOutVideoMessage extends WxMpXmlOutMessage { protected final Video video = new Video(); public WxMpXmlOutVideoMessage() { - this.msgType = WxConsts.XML_MSG_VIDEO; + this.msgType = WxConsts.XmlMsgType.VIDEO; } - public String getMediaId() { - return this.video.getMediaId(); - } - - public void setMediaId(String mediaId) { - this.video.setMediaId(mediaId); - } - - public String getTitle() { - return this.video.getTitle(); - } - - public void setTitle(String title) { - this.video.setTitle(title); - } - - public String getDescription() { - return this.video.getDescription(); - } - - public void setDescription(String description) { - this.video.setDescription(description); - } - - @XStreamAlias("Video") + @Data public static class Video implements Serializable { private static final long serialVersionUID = -6445448977569651183L; @@ -59,30 +39,29 @@ public static class Video implements Serializable { @XStreamConverter(value = XStreamCDataConverter.class) private String description; - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } + } - public String getTitle() { - return this.title; - } + public String getMediaId() { + return this.video.mediaId; + } - public void setTitle(String title) { - this.title = title; - } + public void setMediaId(String mediaId) { + this.video.mediaId = mediaId; + } - public String getDescription() { - return this.description; - } + public String getTitle() { + return this.video.title; + } - public void setDescription(String description) { - this.description = description; - } + public void setTitle(String title) { + this.video.title = title; + } + public String getDescription() { + return this.video.description; } + public void setDescription(String description) { + this.video.description = description; + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVoiceMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVoiceMessage.java index a810e5a0f1..bd91b861ee 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVoiceMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVoiceMessage.java @@ -2,10 +2,14 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamConverter; +import lombok.Data; +import lombok.EqualsAndHashCode; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.util.xml.XStreamMediaIdConverter; @XStreamAlias("xml") +@Data +@EqualsAndHashCode(callSuper = true) public class WxMpXmlOutVoiceMessage extends WxMpXmlOutMessage { private static final long serialVersionUID = 240367390249860551L; @@ -14,15 +18,7 @@ public class WxMpXmlOutVoiceMessage extends WxMpXmlOutMessage { private String mediaId; public WxMpXmlOutVoiceMessage() { - this.msgType = WxConsts.XML_MSG_VOICE; - } - - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; + this.msgType = WxConsts.XmlMsgType.VOICE; } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpCardResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpCardResult.java index 5684557bea..2f478a2053 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpCardResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpCardResult.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean.result; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.bean.WxMpCard; @@ -11,6 +12,7 @@ * @author YuJian * @version 15/11/11 */ +@Data public class WxMpCardResult implements Serializable { private static final long serialVersionUID = -7950878428289035637L; @@ -26,57 +28,9 @@ public class WxMpCardResult implements Serializable { private Boolean canConsume; - public String getErrorCode() { - return this.errorCode; - } - - public void setErrorCode(String errorCode) { - this.errorCode = errorCode; - } - - public String getErrorMsg() { - return this.errorMsg; - } - - public void setErrorMsg(String errorMsg) { - this.errorMsg = errorMsg; - } - - public String getOpenId() { - return this.openId; - } - - public void setOpenId(String openId) { - this.openId = openId; - } - - public WxMpCard getCard() { - return this.card; - } - - public void setCard(WxMpCard card) { - this.card = card; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); } - public String getUserCardStatus() { - return this.userCardStatus; - } - - public void setUserCardStatus(String userCardStatus) { - this.userCardStatus = userCardStatus; - } - - public Boolean getCanConsume() { - return this.canConsume; - } - - public void setCanConsume(Boolean canConsume) { - this.canConsume = canConsume; - } - } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpCurrentAutoReplyInfo.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpCurrentAutoReplyInfo.java index 563dc6aca8..52bebcf90d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpCurrentAutoReplyInfo.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpCurrentAutoReplyInfo.java @@ -2,6 +2,7 @@ import com.google.gson.annotations.JsonAdapter; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.common.util.json.WxBooleanTypeAdapter; import me.chanjar.weixin.common.util.json.WxDateTypeAdapter; @@ -18,6 +19,7 @@ * @author Binary Wang *
*/ +@Data public class WxMpCurrentAutoReplyInfo implements Serializable { private static final long serialVersionUID = 8294705001262751638L; @@ -47,46 +49,7 @@ public static WxMpCurrentAutoReplyInfo fromJson(String json) { @SerializedName("keyword_autoreply_info") private KeywordAutoReplyInfo keywordAutoReplyInfo; - public Boolean getAddFriendReplyOpen() { - return this.isAddFriendReplyOpen; - } - - public void setAddFriendReplyOpen(Boolean addFriendReplyOpen) { - isAddFriendReplyOpen = addFriendReplyOpen; - } - - public Boolean getAutoReplyOpen() { - return this.isAutoReplyOpen; - } - - public void setAutoReplyOpen(Boolean autoReplyOpen) { - isAutoReplyOpen = autoReplyOpen; - } - - public AutoReplyInfo getAddFriendAutoReplyInfo() { - return this.addFriendAutoReplyInfo; - } - - public void setAddFriendAutoReplyInfo(AutoReplyInfo addFriendAutoReplyInfo) { - this.addFriendAutoReplyInfo = addFriendAutoReplyInfo; - } - - public AutoReplyInfo getMessageDefaultAutoReplyInfo() { - return this.messageDefaultAutoReplyInfo; - } - - public void setMessageDefaultAutoReplyInfo(AutoReplyInfo messageDefaultAutoReplyInfo) { - this.messageDefaultAutoReplyInfo = messageDefaultAutoReplyInfo; - } - - public KeywordAutoReplyInfo getKeywordAutoReplyInfo() { - return this.keywordAutoReplyInfo; - } - - public void setKeywordAutoReplyInfo(KeywordAutoReplyInfo keywordAutoReplyInfo) { - this.keywordAutoReplyInfo = keywordAutoReplyInfo; - } - + @Data public static class AutoReplyRule implements Serializable { private static final long serialVersionUID = -6415971838145909046L; @@ -111,47 +74,9 @@ public String toString() { @SerializedName("reply_list_info") private List replyListInfo; - public String getRuleName() { - return this.ruleName; - } - - public void setRuleName(String ruleName) { - this.ruleName = ruleName; - } - - public Date getCreateTime() { - return this.createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } - - public String getReplyMode() { - return this.replyMode; - } - - public void setReplyMode(String replyMode) { - this.replyMode = replyMode; - } - - public List getKeywordListInfo() { - return this.keywordListInfo; - } - - public void setKeywordListInfo(List keywordListInfo) { - this.keywordListInfo = keywordListInfo; - } - - public List getReplyListInfo() { - return this.replyListInfo; - } - - public void setReplyListInfo(List replyListInfo) { - this.replyListInfo = replyListInfo; - } } + @Data public static class ReplyInfo implements Serializable { private static final long serialVersionUID = -3429575601599101690L; @@ -166,31 +91,9 @@ public String toString() { @SerializedName("news_info") private NewsInfo newsInfo; - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - - public String getContent() { - return this.content; - } - - public void setContent(String content) { - this.content = content; - } - - public NewsInfo getNewsInfo() { - return this.newsInfo; - } - - public void setNewsInfo(NewsInfo newsInfo) { - this.newsInfo = newsInfo; - } } + @Data public static class NewsInfo implements Serializable { private static final long serialVersionUID = 2958827725972593328L; @@ -201,15 +104,9 @@ public String toString() { private List list; - public List getList() { - return this.list; - } - - public void setList(List list) { - this.list = list; - } } + @Data public static class NewsItem implements Serializable { private static final long serialVersionUID = -680356309029767176L; @@ -231,63 +128,9 @@ public String toString() { private String sourceUrl; private String title; - public String getCoverUrl() { - return this.coverUrl; - } - - public void setCoverUrl(String coverUrl) { - this.coverUrl = coverUrl; - } - - public String getAuthor() { - return this.author; - } - - public void setAuthor(String author) { - this.author = author; - } - - public String getContentUrl() { - return this.contentUrl; - } - - public void setContentUrl(String contentUrl) { - this.contentUrl = contentUrl; - } - - public String getDigest() { - return this.digest; - } - - public void setDigest(String digest) { - this.digest = digest; - } - - public Boolean getShowCover() { - return this.showCover; - } - - public void setShowCover(Boolean showCover) { - this.showCover = showCover; - } - - public String getSourceUrl() { - return this.sourceUrl; - } - - public void setSourceUrl(String sourceUrl) { - this.sourceUrl = sourceUrl; - } - - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } } + @Data public static class KeywordInfo implements Serializable { private static final long serialVersionUID = 7720246983986706379L; @@ -301,31 +144,9 @@ public String toString() { private String matchMode; private String content; - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - - public String getMatchMode() { - return this.matchMode; - } - - public void setMatchMode(String matchMode) { - this.matchMode = matchMode; - } - - public String getContent() { - return this.content; - } - - public void setContent(String content) { - this.content = content; - } } + @Data public static class KeywordAutoReplyInfo implements Serializable { private static final long serialVersionUID = -8789197949404753083L; @@ -335,16 +156,9 @@ public String toString() { } private List list; - - public List getList() { - return this.list; - } - - public void setList(List list) { - this.list = list; - } } + @Data public static class AutoReplyInfo implements Serializable { private static final long serialVersionUID = 4993719555937843712L; @@ -355,22 +169,6 @@ public String toString() { private String type; private String content; - - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - - public String getContent() { - return this.content; - } - - public void setContent(String content) { - this.content = content; - } } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassSendResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassSendResult.java index 56cfd13d97..d0d2a9d82f 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassSendResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassSendResult.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean.result; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -16,6 +17,7 @@ * * @author chanjarster */ +@Data public class WxMpMassSendResult implements Serializable { private static final long serialVersionUID = -4816336807575562818L; @@ -28,38 +30,6 @@ public static WxMpMassSendResult fromJson(String json) { return WxMpGsonBuilder.create().fromJson(json, WxMpMassSendResult.class); } - public String getErrorCode() { - return this.errorCode; - } - - public void setErrorCode(String errorCode) { - this.errorCode = errorCode; - } - - public String getErrorMsg() { - return this.errorMsg; - } - - public void setErrorMsg(String errorMsg) { - this.errorMsg = errorMsg; - } - - public String getMsgId() { - return this.msgId; - } - - public void setMsgId(String msgId) { - this.msgId = msgId; - } - - public String getMsgDataId() { - return this.msgDataId; - } - - public void setMsgDataId(String msgDataId) { - this.msgDataId = msgDataId; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassUploadResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassUploadResult.java index f8ca889652..a13627257b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassUploadResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassUploadResult.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean.result; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -13,6 +14,7 @@ * * @author chanjarster */ +@Data public class WxMpMassUploadResult implements Serializable { private static final long serialVersionUID = 6568157943644994029L; @@ -24,30 +26,6 @@ public static WxMpMassUploadResult fromJson(String json) { return WxMpGsonBuilder.create().fromJson(json, WxMpMassUploadResult.class); } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - - public String getMediaId() { - return this.mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } - - public long getCreatedAt() { - return this.createdAt; - } - - public void setCreatedAt(long createdAt) { - this.createdAt = createdAt; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpOAuth2AccessToken.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpOAuth2AccessToken.java index 3f49397975..0193efee20 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpOAuth2AccessToken.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpOAuth2AccessToken.java @@ -1,10 +1,12 @@ package me.chanjar.weixin.mp.bean.result; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.Serializable; +@Data public class WxMpOAuth2AccessToken implements Serializable { private static final long serialVersionUID = -1345910558078620805L; @@ -24,54 +26,6 @@ public static WxMpOAuth2AccessToken fromJson(String json) { return WxMpGsonBuilder.create().fromJson(json, WxMpOAuth2AccessToken.class); } - public String getRefreshToken() { - return this.refreshToken; - } - - public void setRefreshToken(String refreshToken) { - this.refreshToken = refreshToken; - } - - public String getOpenId() { - return this.openId; - } - - public void setOpenId(String openId) { - this.openId = openId; - } - - public String getScope() { - return this.scope; - } - - public void setScope(String scope) { - this.scope = scope; - } - - public String getAccessToken() { - return this.accessToken; - } - - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } - - public int getExpiresIn() { - return this.expiresIn; - } - - public void setExpiresIn(int expiresIn) { - this.expiresIn = expiresIn; - } - - public String getUnionId() { - return this.unionId; - } - - public void setUnionId(String unionId) { - this.unionId = unionId; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpQrCodeTicket.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpQrCodeTicket.java index 7ba6151c3e..ee78096b33 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpQrCodeTicket.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpQrCodeTicket.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean.result; +import lombok.Data; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.Serializable; @@ -9,44 +10,21 @@ * * @author chanjarster */ +@Data public class WxMpQrCodeTicket implements Serializable { private static final long serialVersionUID = 5777119669111011584L; protected String ticket; - protected int expire_seconds = -1; + /** + * 如果为-1,说明是永久 + */ + protected int expireSeconds = -1; protected String url; public static WxMpQrCodeTicket fromJson(String json) { return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpQrCodeTicket.class); } - public String getTicket() { - return this.ticket; - } - - public void setTicket(String ticket) { - this.ticket = ticket; - } - - /** - * 如果返回-1说明是永久 - */ - public int getExpire_seconds() { - return this.expire_seconds; - } - - public void setExpire_seconds(int expire_seconds) { - this.expire_seconds = expire_seconds; - } - - public String getUrl() { - return this.url; - } - - public void setUrl(String url) { - this.url = url; - } - @Override public String toString() { return WxMpGsonBuilder.INSTANCE.create().toJson(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpSemanticQueryResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpSemanticQueryResult.java index 723ea7adc9..5c2962b82a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpSemanticQueryResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpSemanticQueryResult.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean.result; +import lombok.Data; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.Serializable; @@ -11,6 +12,7 @@ * * @author Daniel Qian */ +@Data public class WxMpSemanticQueryResult implements Serializable { private static final long serialVersionUID = 4811088544804441365L; @@ -25,52 +27,4 @@ public static WxMpSemanticQueryResult fromJson(String json) { return WxMpGsonBuilder.create().fromJson(json, WxMpSemanticQueryResult.class); } - public String getQuery() { - return this.query; - } - - public void setQuery(String query) { - this.query = query; - } - - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - - public String getSemantic() { - return this.semantic; - } - - public void setSemantic(String semantic) { - this.semantic = semantic; - } - - public String getResult() { - return this.result; - } - - public void setResult(String result) { - this.result = result; - } - - public String getAnswer() { - return this.answer; - } - - public void setAnswer(String answer) { - this.answer = answer; - } - - public String getText() { - return this.text; - } - - public void setText(String text) { - this.text = text; - } - } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUser.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUser.java index e9e2bae6c1..ec969e2872 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUser.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUser.java @@ -3,6 +3,7 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -15,6 +16,7 @@ * * @author chanjarster */ +@Data public class WxMpUser implements Serializable { private static final long serialVersionUID = 5788154322646488738L; @@ -28,6 +30,9 @@ public class WxMpUser implements Serializable { private String country; private String headImgUrl; private Long subscribeTime; + /** + * 只有在将公众号绑定到微信开放平台帐号后,才会出现该字段。 + */ private String unionId; private Integer sexId; private String remark; @@ -46,130 +51,6 @@ public static List fromJsonList(String json) { return gson.fromJson(jsonObject.get("user_info_list"), collectionType); } - public Boolean getSubscribe() { - return this.subscribe; - } - - public void setSubscribe(Boolean subscribe) { - this.subscribe = subscribe; - } - - public String getOpenId() { - return this.openId; - } - - public void setOpenId(String openId) { - this.openId = openId; - } - - public String getNickname() { - return this.nickname; - } - - public void setNickname(String nickname) { - this.nickname = nickname; - } - - public String getSex() { - return this.sex; - } - - public void setSex(String sex) { - this.sex = sex; - } - - public String getLanguage() { - return this.language; - } - - public void setLanguage(String language) { - this.language = language; - } - - public String getCity() { - return this.city; - } - - public void setCity(String city) { - this.city = city; - } - - public String getProvince() { - return this.province; - } - - public void setProvince(String province) { - this.province = province; - } - - public String getCountry() { - return this.country; - } - - public void setCountry(String country) { - this.country = country; - } - - public String getHeadImgUrl() { - return this.headImgUrl; - } - - public void setHeadImgUrl(String headImgUrl) { - this.headImgUrl = headImgUrl; - } - - public Long getSubscribeTime() { - return this.subscribeTime; - } - - public void setSubscribeTime(Long subscribeTime) { - this.subscribeTime = subscribeTime; - } - - /** - * 只有在将公众号绑定到微信开放平台帐号后,才会出现该字段。 - */ - public String getUnionId() { - return this.unionId; - } - - public void setUnionId(String unionId) { - this.unionId = unionId; - } - - public Integer getSexId() { - - return this.sexId; - } - - public void setSexId(Integer sexId) { - this.sexId = sexId; - } - - public String getRemark() { - return this.remark; - } - - public void setRemark(String remark) { - this.remark = remark; - } - - public Integer getGroupId() { - return this.groupId; - } - - public void setGroupId(Integer groupId) { - this.groupId = groupId; - } - - public Long[] getTagIds() { - return this.tagIds; - } - - public void setTagIds(Long[] tagIds) { - this.tagIds = tagIds; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserBlacklistGetResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserBlacklistGetResult.java index 5fe0a9448b..83e1e24424 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserBlacklistGetResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserBlacklistGetResult.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean.result; +import lombok.Data; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.Serializable; @@ -9,6 +10,7 @@ /** * @author miller */ +@Data public class WxMpUserBlacklistGetResult implements Serializable { private static final long serialVersionUID = -8780216463588687626L; @@ -21,38 +23,6 @@ public static WxMpUserBlacklistGetResult fromJson(String json) { return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpUserBlacklistGetResult.class); } - public int getTotal() { - return this.total; - } - - public void setTotal(int total) { - this.total = total; - } - - public int getCount() { - return this.count; - } - - public void setCount(int count) { - this.count = count; - } - - public List getOpenidList() { - return this.openidList; - } - - public void setOpenidList(List openidList) { - this.openidList = openidList; - } - - public String getNextOpenid() { - return this.nextOpenid; - } - - public void setNextOpenid(String nextOpenid) { - this.nextOpenid = nextOpenid; - } - @Override public String toString() { return WxMpGsonBuilder.INSTANCE.create().toJson(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserList.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserList.java index 6e367aeca1..5f816456e1 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserList.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserList.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean.result; +import lombok.Data; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.Serializable; @@ -11,6 +12,7 @@ * * @author chanjarster */ +@Data public class WxMpUserList implements Serializable { private static final long serialVersionUID = 1389073042674901032L; @@ -23,38 +25,6 @@ public static WxMpUserList fromJson(String json) { return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpUserList.class); } - public long getTotal() { - return this.total; - } - - public void setTotal(long total) { - this.total = total; - } - - public int getCount() { - return this.count; - } - - public void setCount(int count) { - this.count = count; - } - - public List getOpenids() { - return this.openids; - } - - public void setOpenids(List openids) { - this.openids = openids; - } - - public String getNextOpenid() { - return this.nextOpenid; - } - - public void setNextOpenid(String nextOpenid) { - this.nextOpenid = nextOpenid; - } - @Override public String toString() { return WxMpGsonBuilder.INSTANCE.create().toJson(this); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpDeviceIdentifier.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpDeviceIdentifier.java new file mode 100644 index 0000000000..e93bf75cf9 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpDeviceIdentifier.java @@ -0,0 +1,23 @@ +package me.chanjar.weixin.mp.bean.shake; + +import com.google.gson.JsonObject; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class WxMpDeviceIdentifier implements Serializable { + private Integer device_id; + private String uuid; + private Integer page_id; + private Integer major; + private Integer minor; + public JsonObject toJsonObject(){ + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("device_id", device_id); + jsonObject.addProperty("uuid", uuid); + jsonObject.addProperty("major", major); + jsonObject.addProperty("minor", minor); + return jsonObject; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundDeviceBindPageQuery.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundDeviceBindPageQuery.java new file mode 100644 index 0000000000..71da0b1c65 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundDeviceBindPageQuery.java @@ -0,0 +1,23 @@ +package me.chanjar.weixin.mp.bean.shake; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import lombok.Data; + +import java.util.Collection; + +@Data +public class WxMpShakeAroundDeviceBindPageQuery { + private WxMpDeviceIdentifier deviceIdentifier; + private Collection pageIds; + public String toJsonString(){ + JsonObject jsonObject = new JsonObject(); + jsonObject.add("device_identifier", deviceIdentifier.toJsonObject()); + JsonArray jsonArray = new JsonArray(); + for(Integer pageid: pageIds){ + jsonArray.add(pageid); + } + jsonObject.add("page_ids", jsonArray); + return jsonObject.toString(); + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundPageAddQuery.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundPageAddQuery.java new file mode 100644 index 0000000000..b04ced93bd --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundPageAddQuery.java @@ -0,0 +1,23 @@ +package me.chanjar.weixin.mp.bean.shake; + +import com.google.gson.JsonObject; +import lombok.Data; + +import java.io.Serializable; +@Data +public class WxMpShakeAroundPageAddQuery implements Serializable { + private String title; + private String description; + private String pageUrl; + private String comment; + private String iconUrl; + public String toJsonString(){ + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("title", title); + jsonObject.addProperty("description", description); + jsonObject.addProperty("page_url", pageUrl); + jsonObject.addProperty("comment", comment); + jsonObject.addProperty("icon_url", iconUrl); + return jsonObject.toString(); + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundPageAddResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundPageAddResult.java new file mode 100644 index 0000000000..632fe4f351 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundPageAddResult.java @@ -0,0 +1,26 @@ +package me.chanjar.weixin.mp.bean.shake; + +import com.google.gson.JsonObject; +import lombok.Data; +import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; + +import java.io.Serializable; + +@Data +public class WxMpShakeAroundPageAddResult implements Serializable { + private Integer errorCode; + private String errorMsg; + private Integer pageId; + public static WxMpShakeAroundPageAddResult fromJson(String json) { + JsonObject jsonObject = WxMpGsonBuilder.INSTANCE.create().fromJson(json, JsonObject.class); + WxMpShakeAroundPageAddResult result = new WxMpShakeAroundPageAddResult(); + result.setErrorCode(GsonHelper.getInteger(jsonObject, "errcode")); + result.setErrorMsg(GsonHelper.getString(jsonObject, "errmsg")); + jsonObject = jsonObject.getAsJsonObject("data"); + if(jsonObject != null){ + result.setPageId(GsonHelper.getInteger(jsonObject, "page_id")); + } + return result; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundRelationSearchQuery.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundRelationSearchQuery.java new file mode 100644 index 0000000000..390fe50964 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundRelationSearchQuery.java @@ -0,0 +1,32 @@ +package me.chanjar.weixin.mp.bean.shake; + +import com.google.gson.JsonObject; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class WxMpShakeAroundRelationSearchQuery implements Serializable { + private int type; + private Integer pageId; + private Integer begin; + private Integer count; + private WxMpDeviceIdentifier deviceIdentifier; + public String toJsonString(){ + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("type", type); + switch (type){ + case 1: + jsonObject.add("device_identifier", deviceIdentifier.toJsonObject()); + break; + case 2: + jsonObject.addProperty("page_id", pageId); + jsonObject.addProperty("begin", begin); + jsonObject.addProperty("count", count); + break; + default: + throw new IllegalArgumentException("type error"); + } + return jsonObject.toString(); + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundRelationSearchResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundRelationSearchResult.java new file mode 100644 index 0000000000..2b7269e572 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundRelationSearchResult.java @@ -0,0 +1,22 @@ +package me.chanjar.weixin.mp.bean.shake; + +import lombok.Data; +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; + +import java.io.Serializable; +import java.util.List; + +@Data +public class WxMpShakeAroundRelationSearchResult implements Serializable { + private Integer errcode; + private String errmsg; + private WxMpShakeAcoundRelationSearch data; + public static WxMpShakeAroundRelationSearchResult fromJson(String json) { + return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpShakeAroundRelationSearchResult.class); + } + @Data + public static class WxMpShakeAcoundRelationSearch implements Serializable{ + private List relations; + private Integer total_count; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreBaseInfo.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreBaseInfo.java index 155942a79b..007826bb67 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreBaseInfo.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreBaseInfo.java @@ -3,6 +3,8 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; import me.chanjar.weixin.common.annotation.Required; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -17,8 +19,10 @@ * Created by Binary Wang on 2016-09-23. * * - * @author binarywang(Binary Wang) + * @author Binary Wang */ +@Data +@Builder public class WxMpStoreBaseInfo implements Serializable { private static final long serialVersionUID = 829577606838118218L; @@ -96,7 +100,8 @@ public class WxMpStoreBaseInfo implements Serializable { */ @Required @SerializedName("offset_type") - private Integer offsetType = 1; + @Builder.Default + private final Integer offsetType = 1; /** * longitude * 门店所在地理位置的经度 @@ -170,192 +175,21 @@ public static WxMpStoreBaseInfo fromJson(String json) { return WxMpGsonBuilder.create().fromJson(json, WxMpStoreBaseInfo.class); } - public static WxMpStoreBaseInfoBuilder builder() { - return new WxMpStoreBaseInfoBuilder(); - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); } public String toJson() { - JsonElement base_info = WxMpGsonBuilder.create().toJsonTree(this); + JsonElement baseInfo = WxMpGsonBuilder.create().toJsonTree(this); JsonObject jsonObject = new JsonObject(); - jsonObject.add("base_info", base_info); + jsonObject.add("base_info", baseInfo); JsonObject business = new JsonObject(); business.add("business", jsonObject); return business.toString(); } - public String getSid() { - return this.sid; - } - - public void setSid(String sid) { - this.sid = sid; - } - - public String getBusinessName() { - return this.businessName; - } - - public void setBusinessName(String businessName) { - this.businessName = businessName; - } - - public String getBranchName() { - return this.branchName; - } - - public void setBranchName(String branchName) { - this.branchName = branchName; - } - - public String getProvince() { - return this.province; - } - - public void setProvince(String province) { - this.province = province; - } - - public String getCity() { - return this.city; - } - - public void setCity(String city) { - this.city = city; - } - - public String getDistrict() { - return this.district; - } - - public void setDistrict(String district) { - this.district = district; - } - - public String getAddress() { - return this.address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getTelephone() { - return this.telephone; - } - - public void setTelephone(String telephone) { - this.telephone = telephone; - } - - public String[] getCategories() { - return this.categories; - } - - public void setCategories(String[] categories) { - this.categories = categories; - } - - public Integer getOffsetType() { - return this.offsetType; - } - - public void setOffsetType(Integer offsetType) { - this.offsetType = offsetType; - } - - public BigDecimal getLongitude() { - return this.longitude; - } - - public void setLongitude(BigDecimal longitude) { - this.longitude = longitude; - } - - public BigDecimal getLatitude() { - return this.latitude; - } - - public void setLatitude(BigDecimal latitude) { - this.latitude = latitude; - } - - public List getPhotos() { - return this.photos; - } - - public void setPhotos(List photos) { - this.photos = photos; - } - - public String getRecommend() { - return this.recommend; - } - - public void setRecommend(String recommend) { - this.recommend = recommend; - } - - public String getSpecial() { - return this.special; - } - - public void setSpecial(String special) { - this.special = special; - } - - public String getIntroduction() { - return this.introduction; - } - - public void setIntroduction(String introduction) { - this.introduction = introduction; - } - - public String getOpenTime() { - return this.openTime; - } - - public void setOpenTime(String openTime) { - this.openTime = openTime; - } - - public Integer getAvgPrice() { - return this.avgPrice; - } - - public void setAvgPrice(Integer avgPrice) { - this.avgPrice = avgPrice; - } - - public Integer getAvailableState() { - return this.availableState; - } - - public void setAvailableState(Integer availableState) { - this.availableState = availableState; - } - - public Integer getUpdateStatus() { - return this.updateStatus; - } - - public void setUpdateStatus(Integer updateStatus) { - this.updateStatus = updateStatus; - } - - public String getPoiId() { - return this.poiId; - } - - public void setPoiId(String poiId) { - this.poiId = poiId; - } - + @Data public static class WxMpStorePhoto implements Serializable { private static final long serialVersionUID = -2942447907614186861L; /** @@ -364,193 +198,6 @@ public static class WxMpStorePhoto implements Serializable { @SerializedName("photo_url") private String photoUrl; - public String getPhotoUrl() { - return photoUrl; - } - - public void setPhotoUrl(String photoUrl) { - this.photoUrl = photoUrl; - } - } - - public static class WxMpStoreBaseInfoBuilder { - private String sid; - private String businessName; - private String branchName; - private String province; - private String city; - private String district; - private String address; - private String telephone; - private String[] categories; - private Integer offsetType; - private BigDecimal longitude; - private BigDecimal latitude; - private List photos; - private String recommend; - private String special; - private String introduction; - private String openTime; - private Integer avgPrice; - private Integer availableState; - private Integer updateStatus; - private String poiId; - - public WxMpStoreBaseInfoBuilder sid(String sid) { - this.sid = sid; - return this; - } - - public WxMpStoreBaseInfoBuilder businessName(String businessName) { - this.businessName = businessName; - return this; - } - - public WxMpStoreBaseInfoBuilder branchName(String branchName) { - this.branchName = branchName; - return this; - } - - public WxMpStoreBaseInfoBuilder province(String province) { - this.province = province; - return this; - } - - public WxMpStoreBaseInfoBuilder city(String city) { - this.city = city; - return this; - } - - public WxMpStoreBaseInfoBuilder district(String district) { - this.district = district; - return this; - } - - public WxMpStoreBaseInfoBuilder address(String address) { - this.address = address; - return this; - } - - public WxMpStoreBaseInfoBuilder telephone(String telephone) { - this.telephone = telephone; - return this; - } - - public WxMpStoreBaseInfoBuilder categories(String[] categories) { - this.categories = categories; - return this; - } - - public WxMpStoreBaseInfoBuilder offsetType(Integer offsetType) { - this.offsetType = offsetType; - return this; - } - - public WxMpStoreBaseInfoBuilder longitude(BigDecimal longitude) { - this.longitude = longitude; - return this; - } - - public WxMpStoreBaseInfoBuilder latitude(BigDecimal latitude) { - this.latitude = latitude; - return this; - } - - public WxMpStoreBaseInfoBuilder photos(List photos) { - this.photos = photos; - return this; - } - - public WxMpStoreBaseInfoBuilder recommend(String recommend) { - this.recommend = recommend; - return this; - } - - public WxMpStoreBaseInfoBuilder special(String special) { - this.special = special; - return this; - } - - public WxMpStoreBaseInfoBuilder introduction(String introduction) { - this.introduction = introduction; - return this; - } - - public WxMpStoreBaseInfoBuilder openTime(String openTime) { - this.openTime = openTime; - return this; - } - - public WxMpStoreBaseInfoBuilder avgPrice(Integer avgPrice) { - this.avgPrice = avgPrice; - return this; - } - - public WxMpStoreBaseInfoBuilder availableState(Integer availableState) { - this.availableState = availableState; - return this; - } - - public WxMpStoreBaseInfoBuilder updateStatus(Integer updateStatus) { - this.updateStatus = updateStatus; - return this; - } - - public WxMpStoreBaseInfoBuilder poiId(String poiId) { - this.poiId = poiId; - return this; - } - - public WxMpStoreBaseInfoBuilder from(WxMpStoreBaseInfo origin) { - this.sid(origin.sid); - this.businessName(origin.businessName); - this.branchName(origin.branchName); - this.province(origin.province); - this.city(origin.city); - this.district(origin.district); - this.address(origin.address); - this.telephone(origin.telephone); - this.categories(origin.categories); - this.offsetType(origin.offsetType); - this.longitude(origin.longitude); - this.latitude(origin.latitude); - this.photos(origin.photos); - this.recommend(origin.recommend); - this.special(origin.special); - this.introduction(origin.introduction); - this.openTime(origin.openTime); - this.avgPrice(origin.avgPrice); - this.availableState(origin.availableState); - this.updateStatus(origin.updateStatus); - this.poiId(origin.poiId); - return this; - } - - public WxMpStoreBaseInfo build() { - WxMpStoreBaseInfo m = new WxMpStoreBaseInfo(); - m.sid = this.sid; - m.businessName = this.businessName; - m.branchName = this.branchName; - m.province = this.province; - m.city = this.city; - m.district = this.district; - m.address = this.address; - m.telephone = this.telephone; - m.categories = this.categories; - m.offsetType = this.offsetType; - m.longitude = this.longitude; - m.latitude = this.latitude; - m.photos = this.photos; - m.recommend = this.recommend; - m.special = this.special; - m.introduction = this.introduction; - m.openTime = this.openTime; - m.avgPrice = this.avgPrice; - m.availableState = this.availableState; - m.updateStatus = this.updateStatus; - m.poiId = this.poiId; - return m; - } } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreInfo.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreInfo.java index fcbb9aa5ea..a72fb5d46f 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreInfo.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreInfo.java @@ -1,10 +1,12 @@ package me.chanjar.weixin.mp.bean.store; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import java.io.Serializable; +@Data public class WxMpStoreInfo implements Serializable{ private static final long serialVersionUID = 7300598931768355461L; @@ -15,13 +17,4 @@ public class WxMpStoreInfo implements Serializable{ public String toString() { return ToStringUtils.toSimpleString(this); } - - public WxMpStoreBaseInfo getBaseInfo() { - return this.baseInfo; - } - - public void setBaseInfo(WxMpStoreBaseInfo baseInfo) { - this.baseInfo = baseInfo; - } - } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreListResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreListResult.java index 6ebb58901f..5fdfa94483 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreListResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreListResult.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean.store; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -13,8 +14,9 @@ * Created by Binary Wang on 2016-09-27. * * - * @author binarywang(Binary Wang) + * @author Binary Wang */ +@Data public class WxMpStoreListResult implements Serializable { private static final long serialVersionUID = 5388907559949538663L; @@ -48,36 +50,4 @@ public String toString() { return ToStringUtils.toSimpleString(this); } - public Integer getTotalCount() { - return this.totalCount; - } - - public void setTotalCount(Integer totalCount) { - this.totalCount = totalCount; - } - - public Integer getErrCode() { - return this.errCode; - } - - public void setErrCode(Integer errCode) { - this.errCode = errCode; - } - - public String getErrMsg() { - return this.errMsg; - } - - public void setErrMsg(String errMsg) { - this.errMsg = errMsg; - } - - public List getBusinessList() { - return this.businessList; - } - - public void setBusinessList(List businessList) { - this.businessList = businessList; - } - } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxTagListUser.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxTagListUser.java index a1bd50660e..f969792355 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxTagListUser.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxTagListUser.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean.tag; import com.google.gson.annotations.SerializedName; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -13,8 +14,9 @@ * Created by Binary Wang on 2016-09-19. * * - * @author binarywang(Binary Wang) + * @author Binary Wang */ +@Data public class WxTagListUser implements Serializable { private static final long serialVersionUID = -4551768374200676112L; @@ -47,30 +49,7 @@ public String toString() { return ToStringUtils.toSimpleString(this); } - public Integer getCount() { - return this.count; - } - - public void setCount(Integer count) { - this.count = count; - } - - public WxTagListUserData getData() { - return this.data; - } - - public void setData(WxTagListUserData data) { - this.data = data; - } - - public String getNextOpenid() { - return this.nextOpenid; - } - - public void setNextOpenid(String nextOpenid) { - this.nextOpenid = nextOpenid; - } - + @Data public static class WxTagListUserData implements Serializable { private static final long serialVersionUID = -8584537400336245701L; @@ -84,13 +63,5 @@ public static class WxTagListUserData implements Serializable { public String toString() { return ToStringUtils.toSimpleString(this); } - - public List getOpenidList() { - return this.openidList; - } - - public void setOpenidList(List openidList) { - this.openidList = openidList; - } } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java index a06a1ce40a..a54199efa4 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java @@ -2,6 +2,7 @@ import com.google.gson.JsonParser; import com.google.gson.reflect.TypeToken; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -14,8 +15,9 @@ * Created by Binary Wang on 2016/9/2. * * - * @author binarywang(Binary Wang) + * @author Binary Wang */ +@Data public class WxUserTag implements Serializable { private static final long serialVersionUID = -7722428695667031252L; @@ -47,30 +49,6 @@ public static List listFromJson(String json) { }.getType()); } - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public Integer getCount() { - return this.count; - } - - public void setCount(Integer count) { - this.count = count; - } - - public Long getId() { - return this.id; - } - - public void setId(Long id) { - this.id = id; - } - public String toJson() { return WxMpGsonBuilder.create().toJson(this); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplate.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplate.java index 079210775a..c9b12cdf28 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplate.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplate.java @@ -3,6 +3,7 @@ import com.google.gson.JsonParser; import com.google.gson.annotations.SerializedName; import com.google.gson.reflect.TypeToken; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -15,8 +16,9 @@ * Created by Binary Wang on 2016-10-17. * * - * @author binarywang(Binary Wang) + * @author Binary Wang */ +@Data public class WxMpTemplate implements Serializable { private static final JsonParser JSON_PARSER = new JsonParser(); private static final long serialVersionUID = -7366474522571199372L; @@ -69,52 +71,4 @@ public String toString() { return ToStringUtils.toSimpleString(this); } - public String getTemplateId() { - return this.templateId; - } - - public void setTemplateId(String templateId) { - this.templateId = templateId; - } - - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getPrimaryIndustry() { - return this.primaryIndustry; - } - - public void setPrimaryIndustry(String primaryIndustry) { - this.primaryIndustry = primaryIndustry; - } - - public String getDeputyIndustry() { - return this.deputyIndustry; - } - - public void setDeputyIndustry(String deputyIndustry) { - this.deputyIndustry = deputyIndustry; - } - - public String getContent() { - return this.content; - } - - public void setContent(String content) { - this.content = content; - } - - public String getExample() { - return this.example; - } - - public void setExample(String example) { - this.example = example; - } - } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateData.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateData.java index f9d81e4028..ada9952040 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateData.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateData.java @@ -1,10 +1,13 @@ package me.chanjar.weixin.mp.bean.template; +import lombok.Data; + import java.io.Serializable; /** * @author Daniel Qian */ +@Data public class WxMpTemplateData implements Serializable { private static final long serialVersionUID = 6301835292940277870L; @@ -26,28 +29,4 @@ public WxMpTemplateData(String name, String value, String color) { this.color = color; } - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public String getValue() { - return this.value; - } - - public void setValue(String value) { - this.value = value; - } - - public String getColor() { - return this.color; - } - - public void setColor(String color) { - this.color = color; - } - } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateIndustry.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateIndustry.java index b142c3f70f..363ddad7ce 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateIndustry.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateIndustry.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean.template; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -9,6 +10,7 @@ /** * @author miller */ +@Data public class WxMpTemplateIndustry implements Serializable { private static final long serialVersionUID = -7700398224795914722L; @@ -36,26 +38,11 @@ public String toJson() { return WxMpGsonBuilder.create().toJson(this); } - public Industry getPrimaryIndustry() { - return this.primaryIndustry; - } - - public void setPrimaryIndustry(Industry primaryIndustry) { - this.primaryIndustry = primaryIndustry; - } - - public Industry getSecondIndustry() { - return this.secondIndustry; - } - - public void setSecondIndustry(Industry secondIndustry) { - this.secondIndustry = secondIndustry; - } - /** * @author miller * 官方文档中,创建和获取的数据结构不一样。所以采用冗余字段的方式,实现相应的接口 */ + @Data public static class Industry implements Serializable { private static final long serialVersionUID = -1707184885588012142L; private String id; @@ -80,28 +67,5 @@ public String toString() { return ToStringUtils.toSimpleString(this); } - public String getId() { - return this.id; - } - - public void setId(String id) { - this.id = id; - } - - public String getFirstClass() { - return this.firstClass; - } - - public void setFirstClass(String firstClass) { - this.firstClass = firstClass; - } - - public String getSecondClass() { - return this.secondClass; - } - - public void setSecondClass(String secondClass) { - this.secondClass = secondClass; - } } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateMessage.java index 95d619a486..aa5a180487 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateMessage.java @@ -1,5 +1,7 @@ package me.chanjar.weixin.mp.bean.template; +import lombok.Builder; +import lombok.Data; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.Serializable; @@ -9,6 +11,8 @@ /** * 参考 http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN 发送模板消息接口部分 */ +@Data +@Builder public class WxMpTemplateMessage implements Serializable { private static final long serialVersionUID = 5063374783759519418L; @@ -40,143 +44,29 @@ public class WxMpTemplateMessage implements Serializable { /** * 模板数据 */ - private List data = new ArrayList<>(); - - public WxMpTemplateMessage() { - } - - public static WxMpTemplateMessageBuilder builder() { - return new WxMpTemplateMessageBuilder(); - } - - public String getToUser() { - return this.toUser; - } - - public void setToUser(String toUser) { - this.toUser = toUser; - } - - public String getTemplateId() { - return this.templateId; - } - - public void setTemplateId(String templateId) { - this.templateId = templateId; - } - - public String getUrl() { - return this.url; - } - - public void setUrl(String url) { - this.url = url; - } - - public List getData() { - return this.data; - } - - public void setData(List data) { - this.data = data; - } + @Builder.Default + private final List data = new ArrayList<>(); public void addWxMpTemplateData(WxMpTemplateData datum) { this.data.add(datum); } - public MiniProgram getMiniProgram() { - return this.miniProgram; - } - - public void setMiniProgram(MiniProgram miniProgram) { - this.miniProgram = miniProgram; - } - public String toJson() { return WxMpGsonBuilder.INSTANCE.create().toJson(this); } + @Data public static class MiniProgram implements Serializable { private static final long serialVersionUID = -7945254706501974849L; private String appid; private String pagePath; - public MiniProgram() { - } - public MiniProgram(String appid, String pagePath) { this.appid = appid; this.pagePath = pagePath; } - public String getAppid() { - return this.appid; - } - - public void setAppid(String appid) { - this.appid = appid; - } - - public String getPagePath() { - return this.pagePath; - } - - public void setPagePath(String pagePath) { - this.pagePath = pagePath; - } - } - - public static class WxMpTemplateMessageBuilder { - private String toUser; - private String templateId; - private String url; - private List data = new ArrayList<>(); - private MiniProgram miniProgram; - - public WxMpTemplateMessageBuilder toUser(String toUser) { - this.toUser = toUser; - return this; - } - - public WxMpTemplateMessageBuilder templateId(String templateId) { - this.templateId = templateId; - return this; - } - - public WxMpTemplateMessageBuilder url(String url) { - this.url = url; - return this; - } - - public WxMpTemplateMessageBuilder data(List data) { - this.data = data; - return this; - } - - public WxMpTemplateMessageBuilder from(WxMpTemplateMessage origin) { - this.toUser(origin.toUser); - this.templateId(origin.templateId); - this.url(origin.url); - this.data(origin.data); - return this; - } - - public WxMpTemplateMessageBuilder miniProgram(MiniProgram miniProgram) { - this.miniProgram = miniProgram; - return this; - } - - public WxMpTemplateMessage build() { - WxMpTemplateMessage m = new WxMpTemplateMessage(); - m.toUser = this.toUser; - m.templateId = this.templateId; - m.url = this.url; - m.data = this.data; - m.miniProgram = this.miniProgram; - return m; - } } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/ImageBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/ImageBuilder.java index 24d8aabab9..438b0a98a1 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/ImageBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/ImageBuilder.java @@ -15,7 +15,7 @@ public final class ImageBuilder extends BaseBuilder { private String mediaId; public ImageBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_IMAGE; + this.msgType = WxConsts.KefuMsgType.IMAGE; } public ImageBuilder mediaId(String media_id) { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/MpNewsBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/MpNewsBuilder.java index b8fac10258..0d520132f4 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/MpNewsBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/MpNewsBuilder.java @@ -16,7 +16,7 @@ public final class MpNewsBuilder extends BaseBuilder { private String mediaId; public MpNewsBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_MPNEWS; + this.msgType = WxConsts.KefuMsgType.MPNEWS; } public MpNewsBuilder mediaId(String mediaId) { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/MusicBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/MusicBuilder.java index 8d23bacd4e..0cd40db438 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/MusicBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/MusicBuilder.java @@ -24,7 +24,7 @@ public final class MusicBuilder extends BaseBuilder { private String hqMusicUrl; public MusicBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_MUSIC; + this.msgType = WxConsts.KefuMsgType.MUSIC; } public MusicBuilder musicUrl(String musicurl) { @@ -47,8 +47,8 @@ public MusicBuilder description(String description) { return this; } - public MusicBuilder thumbMediaId(String thumb_media_id) { - this.thumbMediaId = thumb_media_id; + public MusicBuilder thumbMediaId(String thumbMediaId) { + this.thumbMediaId = thumbMediaId; return this; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/NewsBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/NewsBuilder.java index 11e866e84a..3c00303557 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/NewsBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/NewsBuilder.java @@ -20,7 +20,7 @@ public final class NewsBuilder extends BaseBuilder { private List articles = new ArrayList<>(); public NewsBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_NEWS; + this.msgType = WxConsts.KefuMsgType.NEWS; } public NewsBuilder addArticle(WxMpKefuMessage.WxArticle... articles) { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/TextBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/TextBuilder.java index 6d9100e94a..b8f58bdd34 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/TextBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/TextBuilder.java @@ -15,7 +15,7 @@ public final class TextBuilder extends BaseBuilder { private String content; public TextBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_TEXT; + this.msgType = WxConsts.KefuMsgType.TEXT; } public TextBuilder content(String content) { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/VideoBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/VideoBuilder.java index d7d3772bda..e9276637d3 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/VideoBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/VideoBuilder.java @@ -24,7 +24,7 @@ public final class VideoBuilder extends BaseBuilder { private String thumbMediaId; public VideoBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_VIDEO; + this.msgType = WxConsts.KefuMsgType.VIDEO; } public VideoBuilder mediaId(String mediaId) { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/VoiceBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/VoiceBuilder.java index 9fa92f21c8..a5211548cb 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/VoiceBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/VoiceBuilder.java @@ -15,7 +15,7 @@ public final class VoiceBuilder extends BaseBuilder { private String mediaId; public VoiceBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_VOICE; + this.msgType = WxConsts.KefuMsgType.VOICE; } public VoiceBuilder mediaId(String media_id) { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/WxCardBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/WxCardBuilder.java index c9eacf0c13..64cb067206 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/WxCardBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/WxCardBuilder.java @@ -15,7 +15,7 @@ public final class WxCardBuilder extends BaseBuilder { private String cardId; public WxCardBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_WXCARD; + this.msgType = WxConsts.KefuMsgType.WXCARD; } public WxCardBuilder cardId(String cardId) { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/VideoBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/VideoBuilder.java index e9f7c85b42..9a965f5b78 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/VideoBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/VideoBuilder.java @@ -32,9 +32,9 @@ public VideoBuilder mediaId(String mediaId) { public WxMpXmlOutVideoMessage build() { WxMpXmlOutVideoMessage m = new WxMpXmlOutVideoMessage(); setCommon(m); - m.setTitle(this.title); - m.setDescription(this.description); - m.setMediaId(this.mediaId); + m.getVideo().setTitle(this.title); + m.getVideo().setDescription(this.description); + m.getVideo().setMediaId(this.mediaId); return m; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/constant/WxMpEventConstants.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/constant/WxMpEventConstants.java index 503367cfd7..df1790e3da 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/constant/WxMpEventConstants.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/constant/WxMpEventConstants.java @@ -4,8 +4,9 @@ *
  * 微信公众号事件的相关常量
  * Created by Binary Wang on 2017-5-10.
- * @author binarywang(Binary Wang)
  * 
+ * + * @author Binary Wang */ public class WxMpEventConstants { /** diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVoiceAndImageDownloadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVoiceAndImageDownloadRequestExecutor.java index 09cb70d0f5..8a4f7462f7 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVoiceAndImageDownloadRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVoiceAndImageDownloadRequestExecutor.java @@ -9,7 +9,8 @@ import java.io.File; import java.io.InputStream; -public abstract class MaterialVoiceAndImageDownloadRequestExecutor implements RequestExecutor { +public abstract class MaterialVoiceAndImageDownloadRequestExecutor + implements RequestExecutor { protected RequestHttp requestHttp; protected File tmpDirFile; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/QrCodeRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/QrCodeRequestExecutor.java index 87c1920cd8..af2e025796 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/QrCodeRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/QrCodeRequestExecutor.java @@ -1,5 +1,7 @@ package me.chanjar.weixin.mp.util.http; +import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; @@ -21,7 +23,7 @@ public QrCodeRequestExecutor(RequestHttp requestHttp) { this.requestHttp = requestHttp; } - public static RequestExecutor create(RequestHttp requestHttp) { + public static RequestExecutor create(RequestHttp requestHttp) throws WxErrorException { switch (requestHttp.getRequestType()) { case APACHE_HTTP: return new ApacheQrCodeRequestExecutor(requestHttp); @@ -30,8 +32,7 @@ public static RequestExecutor create(RequestHttp request case OK_HTTP: return new OkhttpQrCodeRequestExecutor(requestHttp); default: - //TODO 需要优化,最好抛出异常 - return null; + throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("不支持的http框架").build()); } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialNewsInfoRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialNewsInfoRequestExecutor.java index 5298160f35..baab51b591 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialNewsInfoRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialNewsInfoRequestExecutor.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.util.http.apache; +import com.google.common.collect.ImmutableMap; import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; @@ -22,9 +23,13 @@ import java.util.Map; /** - * Created by ecoolper on 2017/5/5. + * httpclient 实现的素材请求执行器. + * + * @author ecoolper + * @date 2017/5/5 */ -public class ApacheMaterialNewsInfoRequestExecutor extends MaterialNewsInfoRequestExecutor { +public class ApacheMaterialNewsInfoRequestExecutor + extends MaterialNewsInfoRequestExecutor { private final Logger logger = LoggerFactory.getLogger(this.getClass()); public ApacheMaterialNewsInfoRequestExecutor(RequestHttp requestHttp) { @@ -39,9 +44,7 @@ public WxMpMaterialNews execute(String uri, String materialId) throws WxErrorExc httpPost.setConfig(config); } - Map params = new HashMap<>(); - params.put("media_id", materialId); - httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params))); + httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(ImmutableMap.of("media_id", materialId)))); try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) { String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); this.logger.debug("响应原始数据:{}", responseContent); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialUploadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialUploadRequestExecutor.java index 445ff2736e..9ddd61f9a9 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialUploadRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialUploadRequestExecutor.java @@ -41,7 +41,7 @@ public WxMpMaterialUploadResult execute(String uri, WxMpMaterial material) throw } if (material == null) { - throw new WxErrorException(WxError.newBuilder().setErrorMsg("非法请求,material参数为空").build()); + throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("非法请求,material参数为空").build()); } File file = material.getFile(); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMediaImgUploadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMediaImgUploadRequestExecutor.java index 63e278e43c..d001876d6d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMediaImgUploadRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMediaImgUploadRequestExecutor.java @@ -30,7 +30,7 @@ public ApacheMediaImgUploadRequestExecutor(RequestHttp requestHttp) { @Override public WxMediaImgUploadResult execute(String uri, File data) throws WxErrorException, IOException { if (data == null) { - throw new WxErrorException(WxError.newBuilder().setErrorMsg("文件对象为空").build()); + throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("文件对象为空").build()); } HttpPost httpPost = new HttpPost(uri); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheQrCodeRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheQrCodeRequestExecutor.java index d7bfe637c5..59874ee2bd 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheQrCodeRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheQrCodeRequestExecutor.java @@ -52,7 +52,8 @@ public File execute(String uri, WxMpQrCodeTicket ticket) throws WxErrorException Header[] contentTypeHeader = response.getHeaders("Content-Type"); if (contentTypeHeader != null && contentTypeHeader.length > 0) { // 出错 - if (ContentType.TEXT_PLAIN.getMimeType().equals(contentTypeHeader[0].getValue())) { + if (ContentType.TEXT_PLAIN.getMimeType() + .equals(ContentType.parse(contentTypeHeader[0].getValue()).getMimeType())) { String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); throw new WxErrorException(WxError.fromJson(responseContent)); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialNewsInfoRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialNewsInfoRequestExecutor.java index 181a640787..2bce6ee4f6 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialNewsInfoRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialNewsInfoRequestExecutor.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.util.http.jodd; +import com.google.common.collect.ImmutableMap; import jodd.http.HttpConnectionProvider; import jodd.http.HttpRequest; import jodd.http.HttpResponse; @@ -9,6 +10,7 @@ import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -28,13 +30,13 @@ public JoddMaterialNewsInfoRequestExecutor(RequestHttp requestHttp) { @Override public WxMpMaterialNews execute(String uri, String materialId) throws WxErrorException, IOException { - HttpRequest request = HttpRequest.post(uri); if (requestHttp.getRequestHttpProxy() != null) { requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy()); } - request.withConnectionProvider(requestHttp.getRequestHttpClient()); - request.query("media_id", materialId); + HttpRequest request = HttpRequest.post(uri) + .withConnectionProvider(requestHttp.getRequestHttpClient()) + .body(WxGsonBuilder.create().toJson(ImmutableMap.of("media_id", materialId))); HttpResponse response = request.send(); response.charset(StringPool.UTF_8); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialUploadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialUploadRequestExecutor.java index ce30323695..a7a5509c08 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialUploadRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialUploadRequestExecutor.java @@ -36,7 +36,7 @@ public WxMpMaterialUploadResult execute(String uri, WxMpMaterial material) throw request.withConnectionProvider(requestHttp.getRequestHttpClient()); if (material == null) { - throw new WxErrorException(WxError.newBuilder().setErrorMsg("非法请求,material参数为空").build()); + throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("非法请求,material参数为空").build()); } File file = material.getFile(); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMediaImgUploadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMediaImgUploadRequestExecutor.java index d0fdbfb856..b66a793365 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMediaImgUploadRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMediaImgUploadRequestExecutor.java @@ -26,7 +26,7 @@ public JoddMediaImgUploadRequestExecutor(RequestHttp requestHttp) { @Override public WxMediaImgUploadResult execute(String uri, File data) throws WxErrorException, IOException { if (data == null) { - throw new WxErrorException(WxError.newBuilder().setErrorMsg("文件对象为空").build()); + throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("文件对象为空").build()); } HttpRequest request = HttpRequest.post(uri); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialNewsInfoRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialNewsInfoRequestExecutor.java index 3f46ab7880..e8bd9beea6 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialNewsInfoRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialNewsInfoRequestExecutor.java @@ -1,9 +1,11 @@ package me.chanjar.weixin.mp.util.http.okhttp; +import com.google.common.collect.ImmutableMap; import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -28,7 +30,8 @@ public WxMpMaterialNews execute(String uri, String materialId) throws WxErrorExc //得到httpClient OkHttpClient client = requestHttp.getRequestHttpClient(); - RequestBody requestBody = new FormBody.Builder().add("media_id", materialId).build(); + RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), + WxGsonBuilder.create().toJson(ImmutableMap.of("media_id", materialId))); Request request = new Request.Builder().url(uri).post(requestBody).build(); Response response = client.newCall(request).execute(); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialUploadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialUploadRequestExecutor.java index ef4bcbb299..766d239565 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialUploadRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialUploadRequestExecutor.java @@ -31,7 +31,7 @@ public OkhttpMaterialUploadRequestExecutor(RequestHttp requestHttp) { public WxMpMaterialUploadResult execute(String uri, WxMpMaterial material) throws WxErrorException, IOException { logger.debug("OkhttpMaterialUploadRequestExecutor is running"); if (material == null) { - throw new WxErrorException(WxError.newBuilder().setErrorMsg("非法请求,material参数为空").build()); + throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("非法请求,material参数为空").build()); } File file = material.getFile(); if (file == null || !file.exists()) { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpQrCodeRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpQrCodeRequestExecutor.java index 6feb137925..79fd294e24 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpQrCodeRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpQrCodeRequestExecutor.java @@ -7,21 +7,22 @@ import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo; import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor; - -import okhttp3.*; -import okio.BufferedSink; -import okio.Okio; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.URLEncoder; import java.util.UUID; /** - * Created by ecoolper on 2017/5/5. + * + * @author ecoolper + * @date 2017/5/5 */ public class OkhttpQrCodeRequestExecutor extends QrCodeRequestExecutor { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -31,9 +32,18 @@ public OkhttpQrCodeRequestExecutor(RequestHttp requestHttp) { } @Override - public File execute(String uri, WxMpQrCodeTicket data) throws WxErrorException, IOException { + public File execute(String uri, WxMpQrCodeTicket ticket) throws WxErrorException, IOException { logger.debug("OkhttpQrCodeRequestExecutor is running"); - //得到httpClient + + if (ticket != null) { + if (uri.indexOf('?') == -1) { + uri += '?'; + } + uri += uri.endsWith("?") + ? "ticket=" + URLEncoder.encode(ticket.getTicket(), "UTF-8") + : "&ticket=" + URLEncoder.encode(ticket.getTicket(), "UTF-8"); + } + OkHttpClient client = requestHttp.getRequestHttpClient(); Request request = new Request.Builder().url(uri).get().build(); Response response = client.newCall(request).execute(); @@ -42,12 +52,10 @@ public File execute(String uri, WxMpQrCodeTicket data) throws WxErrorException, String responseContent = response.body().string(); throw new WxErrorException(WxError.fromJson(responseContent)); } - File temp = File.createTempFile(UUID.randomUUID().toString(), ".png"); - try (BufferedSink sink = Okio.buffer(Okio.sink(temp))) { - sink.writeAll(response.body().source()); + + try (InputStream inputStream = response.body().byteStream()) { + return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg"); } - temp.deleteOnExit(); - return temp; } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpKefuMessageGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpKefuMessageGsonAdapter.java index 56297ce2bd..34b91e5a98 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpKefuMessageGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpKefuMessageGsonAdapter.java @@ -23,25 +23,25 @@ public JsonElement serialize(WxMpKefuMessage message, Type typeOfSrc, JsonSerial messageJson.addProperty("touser", message.getToUser()); messageJson.addProperty("msgtype", message.getMsgType()); - if (WxConsts.CUSTOM_MSG_TEXT.equals(message.getMsgType())) { + if (WxConsts.KefuMsgType.TEXT.equals(message.getMsgType())) { JsonObject text = new JsonObject(); text.addProperty("content", message.getContent()); messageJson.add("text", text); } - if (WxConsts.CUSTOM_MSG_IMAGE.equals(message.getMsgType())) { + if (WxConsts.KefuMsgType.IMAGE.equals(message.getMsgType())) { JsonObject image = new JsonObject(); image.addProperty("media_id", message.getMediaId()); messageJson.add("image", image); } - if (WxConsts.CUSTOM_MSG_VOICE.equals(message.getMsgType())) { + if (WxConsts.KefuMsgType.VOICE.equals(message.getMsgType())) { JsonObject voice = new JsonObject(); voice.addProperty("media_id", message.getMediaId()); messageJson.add("voice", voice); } - if (WxConsts.CUSTOM_MSG_VIDEO.equals(message.getMsgType())) { + if (WxConsts.KefuMsgType.VIDEO.equals(message.getMsgType())) { JsonObject video = new JsonObject(); video.addProperty("media_id", message.getMediaId()); video.addProperty("thumb_media_id", message.getThumbMediaId()); @@ -50,7 +50,7 @@ public JsonElement serialize(WxMpKefuMessage message, Type typeOfSrc, JsonSerial messageJson.add("video", video); } - if (WxConsts.CUSTOM_MSG_MUSIC.equals(message.getMsgType())) { + if (WxConsts.KefuMsgType.MUSIC.equals(message.getMsgType())) { JsonObject music = new JsonObject(); music.addProperty("title", message.getTitle()); music.addProperty("description", message.getDescription()); @@ -60,7 +60,7 @@ public JsonElement serialize(WxMpKefuMessage message, Type typeOfSrc, JsonSerial messageJson.add("music", music); } - if (WxConsts.CUSTOM_MSG_NEWS.equals(message.getMsgType())) { + if (WxConsts.KefuMsgType.NEWS.equals(message.getMsgType())) { JsonObject newsJsonObject = new JsonObject(); JsonArray articleJsonArray = new JsonArray(); for (WxMpKefuMessage.WxArticle article : message.getArticles()) { @@ -75,13 +75,13 @@ public JsonElement serialize(WxMpKefuMessage message, Type typeOfSrc, JsonSerial messageJson.add("news", newsJsonObject); } - if (WxConsts.CUSTOM_MSG_MPNEWS.equals(message.getMsgType())) { + if (WxConsts.KefuMsgType.MPNEWS.equals(message.getMsgType())) { JsonObject json = new JsonObject(); json.addProperty("media_id", message.getMpNewsMediaId()); messageJson.add("mpnews", json); } - if (WxConsts.CUSTOM_MSG_WXCARD.equals(message.getMsgType())) { + if (WxConsts.KefuMsgType.WXCARD.equals(message.getMsgType())) { JsonObject wxcard = new JsonObject(); wxcard.addProperty("card_id", message.getCardId()); messageJson.add("wxcard", wxcard); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassOpenIdsMessageGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassOpenIdsMessageGsonAdapter.java index 64dfbb1234..cbb5bf6b35 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassOpenIdsMessageGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassOpenIdsMessageGsonAdapter.java @@ -26,30 +26,30 @@ public JsonElement serialize(WxMpMassOpenIdsMessage message, Type typeOfSrc, Jso } messageJson.add("touser", toUsers); - if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgType())) { + if (WxConsts.MassMsgType.MPNEWS.equals(message.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", message.getMediaId()); - messageJson.add(WxConsts.MASS_MSG_NEWS, sub); + messageJson.add(WxConsts.MassMsgType.MPNEWS, sub); } - if (WxConsts.MASS_MSG_TEXT.equals(message.getMsgType())) { + if (WxConsts.MassMsgType.TEXT.equals(message.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("content", message.getContent()); - messageJson.add(WxConsts.MASS_MSG_TEXT, sub); + messageJson.add(WxConsts.MassMsgType.TEXT, sub); } - if (WxConsts.MASS_MSG_VOICE.equals(message.getMsgType())) { + if (WxConsts.MassMsgType.VOICE.equals(message.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", message.getMediaId()); - messageJson.add(WxConsts.MASS_MSG_VOICE, sub); + messageJson.add(WxConsts.MassMsgType.VOICE, sub); } - if (WxConsts.MASS_MSG_IMAGE.equals(message.getMsgType())) { + if (WxConsts.MassMsgType.IMAGE.equals(message.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", message.getMediaId()); - messageJson.add(WxConsts.MASS_MSG_IMAGE, sub); + messageJson.add(WxConsts.MassMsgType.IMAGE, sub); } - if (WxConsts.MASS_MSG_VIDEO.equals(message.getMsgType())) { + if (WxConsts.MassMsgType.MPVIDEO.equals(message.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", message.getMediaId()); - messageJson.add(WxConsts.MASS_MSG_VIDEO, sub); + messageJson.add(WxConsts.MassMsgType.MPVIDEO, sub); } messageJson.addProperty("msgtype", message.getMsgType()); messageJson.addProperty("send_ignore_reprint", message.isSendIgnoreReprint() ? 0 : 1); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassPreviewMessageGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassPreviewMessageGsonAdapter.java index fd210fb33a..bd8ede336d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassPreviewMessageGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassPreviewMessageGsonAdapter.java @@ -18,30 +18,30 @@ public JsonElement serialize(WxMpMassPreviewMessage wxMpMassPreviewMessage, Type JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("towxname", wxMpMassPreviewMessage.getToWxUserName()); jsonObject.addProperty("touser", wxMpMassPreviewMessage.getToWxUserOpenid()); - if (WxConsts.MASS_MSG_NEWS.equals(wxMpMassPreviewMessage.getMsgType())) { + if (WxConsts.MassMsgType.MPNEWS.equals(wxMpMassPreviewMessage.getMsgType())) { JsonObject news = new JsonObject(); news.addProperty("media_id", wxMpMassPreviewMessage.getMediaId()); - jsonObject.add(WxConsts.MASS_MSG_NEWS, news); + jsonObject.add(WxConsts.MassMsgType.MPNEWS, news); } - if (WxConsts.MASS_MSG_TEXT.equals(wxMpMassPreviewMessage.getMsgType())) { + if (WxConsts.MassMsgType.TEXT.equals(wxMpMassPreviewMessage.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("content", wxMpMassPreviewMessage.getContent()); - jsonObject.add(WxConsts.MASS_MSG_TEXT, sub); + jsonObject.add(WxConsts.MassMsgType.TEXT, sub); } - if (WxConsts.MASS_MSG_VOICE.equals(wxMpMassPreviewMessage.getMsgType())) { + if (WxConsts.MassMsgType.VOICE.equals(wxMpMassPreviewMessage.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", wxMpMassPreviewMessage.getMediaId()); - jsonObject.add(WxConsts.MASS_MSG_VOICE, sub); + jsonObject.add(WxConsts.MassMsgType.VOICE, sub); } - if (WxConsts.MASS_MSG_IMAGE.equals(wxMpMassPreviewMessage.getMsgType())) { + if (WxConsts.MassMsgType.IMAGE.equals(wxMpMassPreviewMessage.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", wxMpMassPreviewMessage.getMediaId()); - jsonObject.add(WxConsts.MASS_MSG_IMAGE, sub); + jsonObject.add(WxConsts.MassMsgType.IMAGE, sub); } - if (WxConsts.MASS_MSG_VIDEO.equals(wxMpMassPreviewMessage.getMsgType())) { + if (WxConsts.MassMsgType.MPVIDEO.equals(wxMpMassPreviewMessage.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", wxMpMassPreviewMessage.getMediaId()); - jsonObject.add(WxConsts.MASS_MSG_VIDEO, sub); + jsonObject.add(WxConsts.MassMsgType.MPVIDEO, sub); } jsonObject.addProperty("msgtype", wxMpMassPreviewMessage.getMsgType()); return jsonObject; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassTagMessageGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassTagMessageGsonAdapter.java index 5b133b0ed1..75c7f4d6fe 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassTagMessageGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassTagMessageGsonAdapter.java @@ -32,30 +32,30 @@ public JsonElement serialize(WxMpMassTagMessage message, Type typeOfSrc, JsonSer } messageJson.add("filter", filter); - if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgType())) { + if (WxConsts.MassMsgType.MPNEWS.equals(message.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", message.getMediaId()); - messageJson.add(WxConsts.MASS_MSG_NEWS, sub); + messageJson.add(WxConsts.MassMsgType.MPNEWS, sub); } - if (WxConsts.MASS_MSG_TEXT.equals(message.getMsgType())) { + if (WxConsts.MassMsgType.TEXT.equals(message.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("content", message.getContent()); - messageJson.add(WxConsts.MASS_MSG_TEXT, sub); + messageJson.add(WxConsts.MassMsgType.TEXT, sub); } - if (WxConsts.MASS_MSG_VOICE.equals(message.getMsgType())) { + if (WxConsts.MassMsgType.VOICE.equals(message.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", message.getMediaId()); - messageJson.add(WxConsts.MASS_MSG_VOICE, sub); + messageJson.add(WxConsts.MassMsgType.VOICE, sub); } - if (WxConsts.MASS_MSG_IMAGE.equals(message.getMsgType())) { + if (WxConsts.MassMsgType.IMAGE.equals(message.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", message.getMediaId()); - messageJson.add(WxConsts.MASS_MSG_IMAGE, sub); + messageJson.add(WxConsts.MassMsgType.IMAGE, sub); } - if (WxConsts.MASS_MSG_VIDEO.equals(message.getMsgType())) { + if (WxConsts.MassMsgType.MPVIDEO.equals(message.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", message.getMediaId()); - messageJson.add(WxConsts.MASS_MSG_VIDEO, sub); + messageJson.add(WxConsts.MassMsgType.MPVIDEO, sub); } messageJson.addProperty("msgtype", message.getMsgType()); messageJson.addProperty("send_ignore_reprint", message.isSendIgnoreReprint() ? 0 : 1); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialFileBatchGetGsonItemAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialFileBatchGetGsonItemAdapter.java index 7b4bee2e00..7d73ca8343 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialFileBatchGetGsonItemAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialFileBatchGetGsonItemAdapter.java @@ -10,29 +10,29 @@ import com.google.gson.*; import me.chanjar.weixin.common.util.json.GsonHelper; -import me.chanjar.weixin.mp.bean.material.WxMpMaterialFileBatchGetResult; +import me.chanjar.weixin.mp.bean.material.WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem; import java.lang.reflect.Type; import java.util.Date; -public class WxMpMaterialFileBatchGetGsonItemAdapter implements JsonDeserializer { +public class WxMpMaterialFileBatchGetGsonItemAdapter implements JsonDeserializer { @Override - public WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { - WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem wxMaterialFileBatchGetNewsItem = new WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem(); + public WxMaterialFileBatchGetNewsItem deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + WxMaterialFileBatchGetNewsItem newsItem = new WxMaterialFileBatchGetNewsItem(); JsonObject json = jsonElement.getAsJsonObject(); if (json.get("media_id") != null && !json.get("media_id").isJsonNull()) { - wxMaterialFileBatchGetNewsItem.setMediaId(GsonHelper.getAsString(json.get("media_id"))); + newsItem.setMediaId(GsonHelper.getAsString(json.get("media_id"))); } if (json.get("update_time") != null && !json.get("update_time").isJsonNull()) { - wxMaterialFileBatchGetNewsItem.setUpdateTime(new Date(1000 * GsonHelper.getAsLong(json.get("update_time")))); + newsItem.setUpdateTime(new Date(1000 * GsonHelper.getAsLong(json.get("update_time")))); } if (json.get("name") != null && !json.get("name").isJsonNull()) { - wxMaterialFileBatchGetNewsItem.setName(GsonHelper.getAsString(json.get("name"))); + newsItem.setName(GsonHelper.getAsString(json.get("name"))); } if (json.get("url") != null && !json.get("url").isJsonNull()) { - wxMaterialFileBatchGetNewsItem.setUrl(GsonHelper.getAsString(json.get("url"))); + newsItem.setUrl(GsonHelper.getAsString(json.get("url"))); } - return wxMaterialFileBatchGetNewsItem; + return newsItem; } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxQrCodeTicketAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxQrCodeTicketAdapter.java index bd1bbd90ff..80b5bc90ed 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxQrCodeTicketAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxQrCodeTicketAdapter.java @@ -28,7 +28,7 @@ public WxMpQrCodeTicket deserialize(JsonElement json, Type typeOfT, JsonDeserial ticket.setTicket(GsonHelper.getAsString(ticketJsonObject.get("ticket"))); } if (ticketJsonObject.get("expire_seconds") != null && !ticketJsonObject.get("expire_seconds").isJsonNull()) { - ticket.setExpire_seconds(GsonHelper.getAsPrimitiveInt(ticketJsonObject.get("expire_seconds"))); + ticket.setExpireSeconds(GsonHelper.getAsPrimitiveInt(ticketJsonObject.get("expire_seconds"))); } if (ticketJsonObject.get("url") != null && !ticketJsonObject.get("url").isJsonNull()) { ticket.setUrl(GsonHelper.getAsString(ticketJsonObject.get("url"))); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/XStreamTransformer.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/XStreamTransformer.java index 6835fa47a9..68cd475c38 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/XStreamTransformer.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/XStreamTransformer.java @@ -60,6 +60,8 @@ private static void register(Class clz, XStream xStream) { */ private static void registerClass(Class clz) { XStream xstream = XStreamInitializer.getInstance(); + xstream.setClassLoader(Thread.currentThread().getContextClassLoader()); + xstream.processAnnotations(clz); xstream.processAnnotations(getInnerClasses(clz)); if (clz.equals(WxMpXmlMessage.class)) { diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java index fc0f70b776..e8630dbc5a 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java @@ -23,9 +23,7 @@ public synchronized T executeInternal( RequestExecutor executor, String uri, E data) throws WxErrorException { this.log.info("Executed"); - WxError error = new WxError(); - error.setErrorCode(-1); - throw new WxErrorException(error); + throw new WxErrorException(WxError.builder().errorCode(-1).build()); } }; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java index 35d13ee1e9..ba35e11045 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java @@ -23,21 +23,21 @@ public void prepare(boolean async, StringBuffer sb, WxMpMessageRouter router) { router .rule() .async(async) - .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1") + .msgType(WxConsts.XmlMsgType.TEXT).event(WxConsts.EventType.CLICK).eventKey("KEY_1").content("CONTENT_1") .handler(new WxEchoMpMessageHandler(sb, "COMBINE_4")) .end() .rule() .async(async) - .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1") + .msgType(WxConsts.XmlMsgType.TEXT).event(WxConsts.EventType.CLICK).eventKey("KEY_1") .handler(new WxEchoMpMessageHandler(sb, "COMBINE_3")) .end() .rule() .async(async) - .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK) + .msgType(WxConsts.XmlMsgType.TEXT).event(WxConsts.EventType.CLICK) .handler(new WxEchoMpMessageHandler(sb, "COMBINE_2")) .end() - .rule().async(async).msgType(WxConsts.XML_MSG_TEXT).handler(new WxEchoMpMessageHandler(sb, WxConsts.XML_MSG_TEXT)).end() - .rule().async(async).event(WxConsts.EVT_CLICK).handler(new WxEchoMpMessageHandler(sb, WxConsts.EVT_CLICK)).end() + .rule().async(async).msgType(WxConsts.XmlMsgType.TEXT).handler(new WxEchoMpMessageHandler(sb, WxConsts.XmlMsgType.TEXT)).end() + .rule().async(async).event(WxConsts.EventType.CLICK).handler(new WxEchoMpMessageHandler(sb, WxConsts.EventType.CLICK)).end() .rule().async(async).eventKey("KEY_1").handler(new WxEchoMpMessageHandler(sb, "KEY_1")).end() .rule().async(async).eventKeyRegex("KEY_1*").handler(new WxEchoMpMessageHandler(sb, "KEY_123")).end() .rule().async(async).content("CONTENT_1").handler(new WxEchoMpMessageHandler(sb, "CONTENT_1")).end() @@ -101,10 +101,10 @@ public void run() { @DataProvider(name = "messages-1") public Object[][] messages2() { WxMpXmlMessage message1 = new WxMpXmlMessage(); - message1.setMsgType(WxConsts.XML_MSG_TEXT); + message1.setMsgType(WxConsts.XmlMsgType.TEXT); WxMpXmlMessage message2 = new WxMpXmlMessage(); - message2.setEvent(WxConsts.EVT_CLICK); + message2.setEvent(WxConsts.EventType.CLICK); WxMpXmlMessage message3 = new WxMpXmlMessage(); message3.setEventKey("KEY_1"); @@ -122,23 +122,23 @@ public Object[][] messages2() { message7.setFormat("strangeformat"); WxMpXmlMessage c2 = new WxMpXmlMessage(); - c2.setMsgType(WxConsts.XML_MSG_TEXT); - c2.setEvent(WxConsts.EVT_CLICK); + c2.setMsgType(WxConsts.XmlMsgType.TEXT); + c2.setEvent(WxConsts.EventType.CLICK); WxMpXmlMessage c3 = new WxMpXmlMessage(); - c3.setMsgType(WxConsts.XML_MSG_TEXT); - c3.setEvent(WxConsts.EVT_CLICK); + c3.setMsgType(WxConsts.XmlMsgType.TEXT); + c3.setEvent(WxConsts.EventType.CLICK); c3.setEventKey("KEY_1"); WxMpXmlMessage c4 = new WxMpXmlMessage(); - c4.setMsgType(WxConsts.XML_MSG_TEXT); - c4.setEvent(WxConsts.EVT_CLICK); + c4.setMsgType(WxConsts.XmlMsgType.TEXT); + c4.setEvent(WxConsts.EventType.CLICK); c4.setEventKey("KEY_1"); c4.setContent("CONTENT_1"); return new Object[][]{ - new Object[]{message1, WxConsts.XML_MSG_TEXT + ","}, - new Object[]{message2, WxConsts.EVT_CLICK + ","}, + new Object[]{message1, WxConsts.XmlMsgType.TEXT + ","}, + new Object[]{message2, WxConsts.EventType.CLICK + ","}, new Object[]{message3, "KEY_1,"}, new Object[]{message4, "CONTENT_1,"}, new Object[]{message5, "ALL,"}, diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java index 2bf5de1dc4..309d381804 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java @@ -32,7 +32,7 @@ public void testSendKefuMpNewsMessage() throws WxErrorException { TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); - message.setMsgType(WxConsts.CUSTOM_MSG_MPNEWS); + message.setMsgType(WxConsts.KefuMsgType.MPNEWS); message.setToUser(configStorage.getOpenid()); message.setMpNewsMediaId("52R6dL2FxDpM9N1rCY3sYBqHwq-L7K_lz1sPI71idMg"); @@ -43,7 +43,7 @@ public void testSendKefuMessage() throws WxErrorException { TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); - message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); + message.setMsgType(WxConsts.KefuMsgType.TEXT); message.setToUser(configStorage.getOpenid()); message.setContent( "欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); @@ -55,7 +55,7 @@ public void testSendKefuMessageWithKfAccount() throws WxErrorException { TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); - message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); + message.setMsgType(WxConsts.KefuMsgType.TEXT); message.setToUser(configStorage.getOpenid()); message.setKfAccount(configStorage.getKfAccount()); message.setContent( diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMassMessageServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMassMessageServiceImplTest.java index 3b6c048981..92667e95b7 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMassMessageServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMassMessageServiceImplTest.java @@ -38,7 +38,7 @@ public void testTextMassOpenIdsMessageSend() throws WxErrorException { TestConfigStorage configProvider = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); - massMessage.setMsgType(WxConsts.MASS_MSG_TEXT); + massMessage.setMsgType(WxConsts.MassMsgType.TEXT); massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); massMessage.getToUsers().add(configProvider.getOpenid()); @@ -67,7 +67,7 @@ public void testMediaMassOpenIdsMessageSend(String massMsgType, String mediaId) @Test public void testTextMassGroupMessageSend() throws WxErrorException { WxMpMassTagMessage massMessage = new WxMpMassTagMessage(); - massMessage.setMsgType(WxConsts.MASS_MSG_TEXT); + massMessage.setMsgType(WxConsts.MassMsgType.TEXT); massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); massMessage .setTagId(this.wxService.getUserTagService().tagGet().get(0).getId()); @@ -103,7 +103,7 @@ public Object[][] massMessages() throws WxErrorException, IOException { .getSystemResourceAsStream("mm.mp4")) { // 上传视频到媒体库 WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService() - .mediaUpload(WxConsts.MEDIA_VIDEO, TestConstants.FILE_MP4, inputStream); + .mediaUpload(WxConsts.MediaFileType.VIDEO, TestConstants.FILE_MP4, inputStream); assertNotNull(uploadMediaRes); assertNotNull(uploadMediaRes.getMediaId()); @@ -115,7 +115,7 @@ public Object[][] massMessages() throws WxErrorException, IOException { WxMpMassUploadResult uploadResult = this.wxService.getMassMessageService().massVideoUpload(video); assertNotNull(uploadResult); assertNotNull(uploadResult.getMediaId()); - messages[0] = new Object[]{WxConsts.MASS_MSG_VIDEO, uploadResult.getMediaId()}; + messages[0] = new Object[]{WxConsts.MassMsgType.MPVIDEO, uploadResult.getMediaId()}; } /* @@ -124,10 +124,10 @@ public Object[][] massMessages() throws WxErrorException, IOException { try (InputStream inputStream = ClassLoader .getSystemResourceAsStream("mm.jpeg")) { WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService() - .mediaUpload(WxConsts.MEDIA_IMAGE, TestConstants.FILE_JPG, inputStream); + .mediaUpload(WxConsts.MediaFileType.IMAGE, TestConstants.FILE_JPG, inputStream); assertNotNull(uploadMediaRes); assertNotNull(uploadMediaRes.getMediaId()); - messages[1] = new Object[]{WxConsts.MASS_MSG_IMAGE, uploadMediaRes.getMediaId()}; + messages[1] = new Object[]{WxConsts.MassMsgType.IMAGE, uploadMediaRes.getMediaId()}; } /* @@ -136,10 +136,10 @@ public Object[][] massMessages() throws WxErrorException, IOException { try (InputStream inputStream = ClassLoader .getSystemResourceAsStream("mm.mp3")) { WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService() - .mediaUpload(WxConsts.MEDIA_VOICE, TestConstants.FILE_MP3, inputStream); + .mediaUpload(WxConsts.MediaFileType.VOICE, TestConstants.FILE_MP3, inputStream); assertNotNull(uploadMediaRes); assertNotNull(uploadMediaRes.getMediaId()); - messages[2] = new Object[]{WxConsts.MASS_MSG_VOICE, uploadMediaRes.getMediaId()}; + messages[2] = new Object[]{WxConsts.MassMsgType.VOICE, uploadMediaRes.getMediaId()}; } /* @@ -149,7 +149,7 @@ public Object[][] massMessages() throws WxErrorException, IOException { .getSystemResourceAsStream("mm.jpeg")) { // 上传照片到媒体库 WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService() - .mediaUpload(WxConsts.MEDIA_IMAGE, TestConstants.FILE_JPG, inputStream); + .mediaUpload(WxConsts.MediaFileType.IMAGE, TestConstants.FILE_JPG, inputStream); assertNotNull(uploadMediaRes); assertNotNull(uploadMediaRes.getMediaId()); @@ -175,7 +175,7 @@ public Object[][] massMessages() throws WxErrorException, IOException { .massNewsUpload(news); assertNotNull(massUploadResult); assertNotNull(uploadMediaRes.getMediaId()); - messages[3] = new Object[]{WxConsts.MASS_MSG_NEWS, massUploadResult.getMediaId()}; + messages[3] = new Object[]{WxConsts.MassMsgType.MPNEWS, massUploadResult.getMediaId()}; } return messages; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java index 309c4e0e47..919b4cb43b 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java @@ -48,10 +48,10 @@ public class WxMpMaterialServiceImplTest { @DataProvider public Object[][] mediaFiles() { return new Object[][]{ - new Object[]{WxConsts.MEDIA_IMAGE, TestConstants.FILE_JPG, "mm.jpeg"}, - new Object[]{WxConsts.MEDIA_VOICE, TestConstants.FILE_MP3, "mm.mp3"}, - new Object[]{WxConsts.MEDIA_VIDEO, TestConstants.FILE_MP4, "mm.mp4"}, - new Object[]{WxConsts.MEDIA_THUMB, TestConstants.FILE_JPG, "mm.jpeg"} + new Object[]{WxConsts.MediaFileType.IMAGE, TestConstants.FILE_JPG, "mm.jpeg"}, + new Object[]{WxConsts.MediaFileType.VOICE, TestConstants.FILE_MP3, "mm.mp3"}, + new Object[]{WxConsts.MediaFileType.VIDEO, TestConstants.FILE_MP4, "mm.mp4"}, + new Object[]{WxConsts.MediaFileType.THUMB, TestConstants.FILE_JPG, "mm.jpeg"} }; } @@ -69,7 +69,7 @@ public void testUploadMaterial(String mediaType, String fileType, String fileNam WxMpMaterial wxMaterial = new WxMpMaterial(); wxMaterial.setFile(tempFile); wxMaterial.setName(fileName); - if (WxConsts.MEDIA_VIDEO.equals(mediaType)) { + if (WxConsts.MediaFileType.VIDEO.equals(mediaType)) { wxMaterial.setVideoTitle("title"); wxMaterial.setVideoIntroduction("test video description"); } @@ -78,12 +78,12 @@ public void testUploadMaterial(String mediaType, String fileType, String fileNam .materialFileUpload(mediaType, wxMaterial); assertNotNull(res.getMediaId()); - if (WxConsts.MEDIA_IMAGE.equals(mediaType) - || WxConsts.MEDIA_THUMB.equals(mediaType)) { + if (WxConsts.MediaFileType.IMAGE.equals(mediaType) + || WxConsts.MediaFileType.THUMB.equals(mediaType)) { assertNotNull(res.getUrl()); } - if (WxConsts.MEDIA_THUMB.equals(mediaType)) { + if (WxConsts.MediaFileType.THUMB.equals(mediaType)) { this.thumbMediaId = res.getMediaId(); } @@ -231,11 +231,11 @@ public void testMaterialNewsList() throws WxErrorException { assertNotNull(wxMpMaterialNewsBatchGetResult); } - @Test(dependsOnMethods = {"testMaterialNewsList"}) + @Test//(dependsOnMethods = {"testMaterialNewsList"}) public void testMaterialFileList() throws WxErrorException { - WxMpMaterialFileBatchGetResult wxMpMaterialVoiceBatchGetResult = this.wxService.getMaterialService().materialFileBatchGet(WxConsts.MATERIAL_VOICE, 0, 20); - WxMpMaterialFileBatchGetResult wxMpMaterialVideoBatchGetResult = this.wxService.getMaterialService().materialFileBatchGet(WxConsts.MATERIAL_VIDEO, 0, 20); - WxMpMaterialFileBatchGetResult wxMpMaterialImageBatchGetResult = this.wxService.getMaterialService().materialFileBatchGet(WxConsts.MATERIAL_IMAGE, 0, 20); + WxMpMaterialFileBatchGetResult wxMpMaterialVoiceBatchGetResult = this.wxService.getMaterialService().materialFileBatchGet(WxConsts.MaterialType.VOICE, 0, 20); + WxMpMaterialFileBatchGetResult wxMpMaterialVideoBatchGetResult = this.wxService.getMaterialService().materialFileBatchGet(WxConsts.MaterialType.VIDEO, 0, 20); + WxMpMaterialFileBatchGetResult wxMpMaterialImageBatchGetResult = this.wxService.getMaterialService().materialFileBatchGet(WxConsts.MaterialType.IMAGE, 0, 20); assertNotNull(wxMpMaterialVoiceBatchGetResult); assertNotNull(wxMpMaterialVideoBatchGetResult); assertNotNull(wxMpMaterialImageBatchGetResult); @@ -277,7 +277,7 @@ public void testUploadMedia(String mediaType, String fileType, String fileName) assertNotNull(res.getCreatedAt()); assertTrue(res.getMediaId() != null || res.getThumbMediaId() != null); - if (res.getMediaId() != null && !mediaType.equals(WxConsts.MEDIA_VIDEO)) { + if (res.getMediaId() != null && !mediaType.equals(WxConsts.MediaFileType.VIDEO)) { //video 不支持下载,所以不加入 this.mediaIdsToDownload.add(res.getMediaId()); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java index 8846809001..ff00d474a7 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java @@ -9,9 +9,10 @@ import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult; import me.chanjar.weixin.mp.bean.menu.WxMpMenu; -import org.testng.*; import org.testng.annotations.*; +import static org.testng.Assert.*; + /** * 测试菜单 * @@ -87,6 +88,14 @@ public void testCreateConditionalMenu() throws WxErrorException { System.out.println(this.menuId); } + @Test(dependsOnMethods = {"testCreateConditionalMenu"}) + public void testMenuGet_AfterCreateConditionalMenu() throws WxErrorException { + WxMpMenu wxMenu = this.wxService.getMenuService().menuGet(); + assertNotNull(wxMenu); + System.out.println(wxMenu.toJson()); + assertNotNull(wxMenu.getConditionalMenu().get(0).getRule().getTagId()); + } + @Test(dependsOnMethods = {"testCreateConditionalMenu"}) public void testDeleteConditionalMenu() throws WxErrorException { this.wxService.getMenuService().menuDelete(menuId); @@ -134,7 +143,7 @@ public void testCreateMenu_by_json() throws WxErrorException { @Test(dependsOnMethods = {"testMenuCreate"}) public void testMenuGet() throws WxErrorException { WxMpMenu wxMenu = this.wxService.getMenuService().menuGet(); - Assert.assertNotNull(wxMenu); + assertNotNull(wxMenu); System.out.println(wxMenu.toJson()); } @@ -147,12 +156,12 @@ public void testMenuDelete() throws WxErrorException { public Object[][] getMenu() { WxMenu menu = new WxMenu(); WxMenuButton button1 = new WxMenuButton(); - button1.setType(WxConsts.BUTTON_CLICK); + button1.setType(WxConsts.MenuButtonType.CLICK); button1.setName("今日歌曲"); button1.setKey("V1001_TODAY_MUSIC"); // WxMenuButton button2 = new WxMenuButton(); -// button2.setType(WxConsts.BUTTON_MINIPROGRAM); +// button2.setType(WxConsts.MenuButtonType.MINIPROGRAM); // button2.setName("小程序"); // button2.setAppId("wx286b93c14bbf93aa"); // button2.setPagePath("pages/lunar/index.html"); @@ -166,17 +175,17 @@ public Object[][] getMenu() { menu.getButtons().add(button3); WxMenuButton button31 = new WxMenuButton(); - button31.setType(WxConsts.BUTTON_VIEW); + button31.setType(WxConsts.MenuButtonType.VIEW); button31.setName("搜索"); button31.setUrl("http://www.soso.com/"); WxMenuButton button32 = new WxMenuButton(); - button32.setType(WxConsts.BUTTON_VIEW); + button32.setType(WxConsts.MenuButtonType.VIEW); button32.setName("视频"); button32.setUrl("http://v.qq.com/"); WxMenuButton button33 = new WxMenuButton(); - button33.setType(WxConsts.BUTTON_CLICK); + button33.setType(WxConsts.MenuButtonType.CLICK); button33.setName("赞一下我们"); button33.setKey("V1001_GOOD"); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java index 216eec77f0..75eb291a04 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java @@ -5,11 +5,13 @@ import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.RandomStringUtils; import org.testng.*; import org.testng.annotations.*; import java.io.File; +import java.io.IOException; /** * 测试用户相关的接口 @@ -37,7 +39,7 @@ public void testQrCodeCreateTmpTicket(int sceneId) throws WxErrorException { WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateTmpTicket(sceneId, null); Assert.assertNotNull(ticket.getUrl()); Assert.assertNotNull(ticket.getTicket()); - Assert.assertTrue(ticket.getExpire_seconds() != -1); + Assert.assertTrue(ticket.getExpireSeconds() != -1); System.out.println(ticket); } @@ -47,7 +49,7 @@ public void testQrCodeCreateTmpTicketWithSceneStr(String sceneStr) throws WxErro WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateTmpTicket(sceneStr, null); Assert.assertNotNull(ticket.getUrl()); Assert.assertNotNull(ticket.getTicket()); - Assert.assertTrue(ticket.getExpire_seconds() != -1); + Assert.assertTrue(ticket.getExpireSeconds() != -1); System.out.println(ticket); } @@ -56,7 +58,7 @@ public void testQrCodeCreateLastTicket(int sceneId) throws WxErrorException { WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateLastTicket(sceneId); Assert.assertNotNull(ticket.getUrl()); Assert.assertNotNull(ticket.getTicket()); - Assert.assertTrue(ticket.getExpire_seconds() == -1); + Assert.assertTrue(ticket.getExpireSeconds() == -1); System.out.println(ticket); } @@ -65,6 +67,12 @@ public void testQrCodePicture() throws WxErrorException { File file = this.wxService.getQrcodeService().qrCodePicture(ticket); Assert.assertNotNull(file); System.out.println(file.getAbsolutePath()); + + try { + FileUtils.copyFile(file,new File("d:\\t.jpg")); + } catch (IOException e) { + e.printStackTrace(); + } } public void testQrCodePictureUrl() throws WxErrorException { diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java index c3f9f69d7b..89060a6ef1 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java @@ -15,7 +15,6 @@ @Test @Guice(modules = ApiTestModule.class) public class WxMpServiceImplTest { - @Inject private WxMpService wxService; @@ -28,137 +27,17 @@ public void testGetCurrentAutoReplyInfo() throws WxErrorException { } @Test - public void testCheckSignature() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testGetAccessToken() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testGetAccessTokenBoolean() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testGetJsapiTicket() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testGetJsapiTicketBoolean() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testCreateJsapiSignature() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testCustomMessageSend() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testMassNewsUpload() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testMassVideoUpload() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testMassGroupMessageSend() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testMassOpenIdsMessageSend() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testMassMessagePreview() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testShortUrl() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testSetIndustry() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testGetIndustry() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testSemanticQuery() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testOauth2buildAuthorizationUrl() { - Assert.fail("Not yet implemented"); + public void testClearQuota() throws WxErrorException { + this.wxService.clearQuota(wxService.getWxMpConfigStorage().getAppId()); } @Test public void testBuildQrConnectUrl() { String qrconnectRedirectUrl = ((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getQrconnectRedirectUrl(); String qrConnectUrl = this.wxService.buildQrConnectUrl(qrconnectRedirectUrl, - WxConsts.QRCONNECT_SCOPE_SNSAPI_LOGIN, null); + WxConsts.QrConnectScope.SNSAPI_LOGIN, null); Assert.assertNotNull(qrConnectUrl); System.out.println(qrConnectUrl); } - @Test - public void testOauth2getAccessToken() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testOauth2refreshAccessToken() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testOauth2getUserInfo() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testOauth2validateAccessToken() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testGetCallbackIP() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testGet() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testPost() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testExecute() { - Assert.fail("Not yet implemented"); - } - } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java index ed5845088b..e6f4c15570 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java @@ -12,11 +12,12 @@ import java.math.BigDecimal; import java.util.List; -import static org.testng.AssertJUnit.assertNotNull; +import static org.testng.AssertJUnit.*; /** - * @author binarywang(Binary Wang) - * Created by Binary Wang on 2016-09-23. + * Created by Binary Wang on 2016-09-23. + * + * @author Binary Wang */ @Test @Guice(modules = ApiTestModule.class) @@ -25,25 +26,36 @@ public class WxMpStoreServiceImplTest { private WxMpService wxMpService; /** - * Test method for {@link WxMpStoreServiceImpl#add(me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo)}. - * - * @throws WxErrorException + * Test method for {@link WxMpStoreServiceImpl#add(WxMpStoreBaseInfo)}. */ public void testAdd() throws WxErrorException { - this.wxMpService.getStoreService().add(WxMpStoreBaseInfo.builder().build()); this.wxMpService.getStoreService() - .add(WxMpStoreBaseInfo.builder().businessName("haha").branchName("abc") - .province("aaa").district("aaa").telephone("122").address("abc").categories(new String[]{"美食,江浙菜"}) + .add(WxMpStoreBaseInfo.builder() + .businessName("haha") + .branchName("abc") + .province("aaa") + .district("aaa") + .telephone("122") + .address("abc") + .categories(new String[]{"美食,江浙菜"}) .longitude(new BigDecimal("115.32375")) - .latitude(new BigDecimal("25.097486")).city("aaa").offsetType(1) + .latitude(new BigDecimal("25.097486")) + .city("aaa") .build()); + // 以下运行会抛异常 + this.wxMpService.getStoreService().add(WxMpStoreBaseInfo.builder().build()); } public void testUpdate() throws WxErrorException { this.wxMpService.getStoreService() - .update(WxMpStoreBaseInfo.builder().poiId("291503654").telephone("020-12345678") - .sid("aaa").avgPrice(35).openTime("8:00-20:00").special("免费wifi,外卖服务") - .introduction("麦当劳是全球大型跨国连锁餐厅,1940 年创立于美国,在世界上大约拥有3 万间分店。主要售卖汉堡包,以及薯条、炸鸡、汽水、冰品、沙拉、水果等快餐食品").offsetType(1) + .update(WxMpStoreBaseInfo.builder() + .poiId("291503654") + .telephone("020-12345678") + .sid("aaa") + .avgPrice(35) + .openTime("8:00-20:00") + .special("免费wifi,外卖服务") + .introduction("麦当劳是全球大型跨国连锁餐厅,1940 年创立于美国,在世界上大约拥有3 万间分店。主要售卖汉堡包,以及薯条、炸鸡、汽水、冰品、沙拉、水果等快餐食品") .build()); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java index 2c348702ca..96cab2c1ae 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java @@ -20,8 +20,9 @@ /** *
  * Created by Binary Wang on 2016-10-14.
- * @author binarywang(Binary Wang)
  * 
+ * + * @author Binary Wang */ @Guice(modules = ApiTestModule.class) public class WxMpTemplateMsgServiceImplTest { diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java index cc8676d477..1a96ba510a 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java @@ -12,8 +12,9 @@ import java.util.List; /** - * @author binarywang(Binary Wang) - * Created by Binary Wang on 2016/9/2. + * Created by Binary Wang on 2016/9/2. + * + * @author Binary Wang */ @Test @Guice(modules = ApiTestModule.class) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/ApiTestModule.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/ApiTestModule.java index 2a9421a499..030da968e9 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/ApiTestModule.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/ApiTestModule.java @@ -6,7 +6,6 @@ import me.chanjar.weixin.common.util.xml.XStreamInitializer; import me.chanjar.weixin.mp.api.WxMpConfigStorage; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.api.impl.WxMpServiceApacheHttpClientImpl; import me.chanjar.weixin.mp.api.impl.WxMpServiceOkHttpImpl; import java.io.IOException; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessageTest.java index c25c502495..bfeb84c119 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessageTest.java @@ -11,7 +11,7 @@ public class WxMpKefuMessageTest { public void testTextReply() { WxMpKefuMessage reply = new WxMpKefuMessage(); reply.setToUser("OPENID"); - reply.setMsgType(WxConsts.CUSTOM_MSG_TEXT); + reply.setMsgType(WxConsts.KefuMsgType.TEXT); reply.setContent("sfsfdsdf"); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}"); } @@ -24,7 +24,7 @@ public void testTextBuild() { public void testImageReply() { WxMpKefuMessage reply = new WxMpKefuMessage(); reply.setToUser("OPENID"); - reply.setMsgType(WxConsts.CUSTOM_MSG_IMAGE); + reply.setMsgType(WxConsts.KefuMsgType.IMAGE); reply.setMediaId("MEDIA_ID"); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}"); } @@ -37,7 +37,7 @@ public void testImageBuild() { public void testVoiceReply() { WxMpKefuMessage reply = new WxMpKefuMessage(); reply.setToUser("OPENID"); - reply.setMsgType(WxConsts.CUSTOM_MSG_VOICE); + reply.setMsgType(WxConsts.KefuMsgType.VOICE); reply.setMediaId("MEDIA_ID"); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}"); } @@ -50,7 +50,7 @@ public void testVoiceBuild() { public void testVideoReply() { WxMpKefuMessage reply = new WxMpKefuMessage(); reply.setToUser("OPENID"); - reply.setMsgType(WxConsts.CUSTOM_MSG_VIDEO); + reply.setMsgType(WxConsts.KefuMsgType.VIDEO); reply.setMediaId("MEDIA_ID"); reply.setThumbMediaId("MEDIA_ID"); reply.setTitle("TITLE"); @@ -66,7 +66,7 @@ public void testVideoBuild() { public void testMusicReply() { WxMpKefuMessage reply = new WxMpKefuMessage(); reply.setToUser("OPENID"); - reply.setMsgType(WxConsts.CUSTOM_MSG_MUSIC); + reply.setMsgType(WxConsts.KefuMsgType.MUSIC); reply.setThumbMediaId("MEDIA_ID"); reply.setDescription("DESCRIPTION"); reply.setTitle("TITLE"); @@ -90,7 +90,7 @@ public void testMusicBuild() { public void testNewsReply() { WxMpKefuMessage reply = new WxMpKefuMessage(); reply.setToUser("OPENID"); - reply.setMsgType(WxConsts.CUSTOM_MSG_NEWS); + reply.setMsgType(WxConsts.KefuMsgType.NEWS); WxArticle article1 = new WxArticle(); article1.setUrl("URL"); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java index 9c2bbf56ac..2224329b26 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java @@ -58,7 +58,7 @@ public void testFromXml() { assertEquals(wxMessage.getToUser(), "toUser"); assertEquals(wxMessage.getFromUser(), "fromUser"); assertEquals(wxMessage.getCreateTime(), new Long(1348831860L)); - assertEquals(wxMessage.getMsgType(), WxConsts.XML_MSG_TEXT); + assertEquals(wxMessage.getMsgType(), WxConsts.XmlMsgType.TEXT); assertEquals(wxMessage.getContent(), "this is a test"); assertEquals(wxMessage.getMsgId(), new Long(1234567890123456L)); assertEquals(wxMessage.getPicUrl(), "this is a url"); @@ -86,7 +86,7 @@ public void testFromXml() { assertEquals(wxMessage.getSendLocationInfo().getLocationY(), "113"); assertEquals(wxMessage.getSendLocationInfo().getScale(), "15"); assertEquals(wxMessage.getSendLocationInfo().getLabel(), " 广州市海珠区客村艺苑路 106号"); - assertEquals(wxMessage.getSendLocationInfo().getPoiname(), "wo de poi"); + assertEquals(wxMessage.getSendLocationInfo().getPoiName(), "wo de poi"); } public void testFromXml2() { @@ -139,7 +139,7 @@ public void testFromXml2() { assertEquals(wxMessage.getToUser(), "toUser"); assertEquals(wxMessage.getFromUser(), "fromUser"); assertEquals(wxMessage.getCreateTime(), new Long(1348831860L)); - assertEquals(wxMessage.getMsgType(), WxConsts.XML_MSG_TEXT); + assertEquals(wxMessage.getMsgType(), WxConsts.XmlMsgType.TEXT); assertEquals(wxMessage.getContent(), "this is a test"); assertEquals(wxMessage.getMsgId(), new Long(1234567890123456L)); assertEquals(wxMessage.getPicUrl(), "this is a url"); @@ -167,7 +167,7 @@ public void testFromXml2() { assertEquals(wxMessage.getSendLocationInfo().getLocationY(), "113"); assertEquals(wxMessage.getSendLocationInfo().getScale(), "15"); assertEquals(wxMessage.getSendLocationInfo().getLabel(), " 广州市海珠区客村艺苑路 106号"); - assertEquals(wxMessage.getSendLocationInfo().getPoiname(), "wo de poi"); + assertEquals(wxMessage.getSendLocationInfo().getPoiName(), "wo de poi"); } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessageTest.java index f75e6321e6..592a6a50ed 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessageTest.java @@ -13,7 +13,7 @@ public void test() { m.setHqMusicUrl("hQMusicUrl"); m.setMusicUrl("musicUrl"); m.setThumbMediaId("thumbMediaId"); - m.setCreateTime(1122l); + m.setCreateTime(1122L); m.setFromUserName("fromUser"); m.setToUserName("toUser"); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/result/WxMpCurrentAutoReplyInfoTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/result/WxMpCurrentAutoReplyInfoTest.java index da2cddff40..dbed60bac9 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/result/WxMpCurrentAutoReplyInfoTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/result/WxMpCurrentAutoReplyInfoTest.java @@ -145,8 +145,8 @@ public void testFromJson() throws Exception { WxMpCurrentAutoReplyInfo autoReplyInfo = WxMpCurrentAutoReplyInfo.fromJson(json); assertNotNull(autoReplyInfo); - assertTrue(autoReplyInfo.getAddFriendReplyOpen()); - assertTrue(autoReplyInfo.getAutoReplyOpen()); + assertTrue(autoReplyInfo.getIsAddFriendReplyOpen()); + assertTrue(autoReplyInfo.getIsAutoReplyOpen()); assertNotNull(autoReplyInfo.getAddFriendAutoReplyInfo()); assertNotNull(autoReplyInfo.getMessageDefaultAutoReplyInfo()); assertTrue(autoReplyInfo.getKeywordAutoReplyInfo().getList().size() > 0); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateMessageTest.java index ac415ff454..3bb804d5c8 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateMessageTest.java @@ -7,8 +7,9 @@ /** *
  * Created by Binary Wang on 2017-3-30.
- * @author binarywang(Binary Wang)
  * 
+ * + * @author Binary Wang */ public class WxMpTemplateMessageTest { @Test diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoImageHandler.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoImageHandler.java index 2390071b6c..5578f637be 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoImageHandler.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoImageHandler.java @@ -19,7 +19,7 @@ public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map co WxMpService wxMpService, WxSessionManager sessionManager) { try { WxMediaUploadResult wxMediaUploadResult = wxMpService.getMaterialService() - .mediaUpload(WxConsts.MEDIA_IMAGE, TestConstants.FILE_JPG, ClassLoader.getSystemResourceAsStream("mm.jpeg")); + .mediaUpload(WxConsts.MediaFileType.IMAGE, TestConstants.FILE_JPG, ClassLoader.getSystemResourceAsStream("mm.jpeg")); WxMpXmlOutImageMessage m = WxMpXmlOutMessage .IMAGE() diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoOAuth2Handler.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoOAuth2Handler.java index 6460f851d0..91020c4ece 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoOAuth2Handler.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoOAuth2Handler.java @@ -19,7 +19,7 @@ public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, WxSessionManager sessionManager) { String href = "测试oauth2"; + WxConsts.OAuth2Scope.SNSAPI_USERINFO, null) + "\">测试oauth2"; return WxMpXmlOutMessage.TEXT().content(href) .fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()) .build(); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServer.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServer.java index 3e16042d7f..2f5f25eea7 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServer.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServer.java @@ -58,7 +58,7 @@ private static void initWeixin() { wxMpMessageRouter = new WxMpMessageRouter(wxMpService); wxMpMessageRouter.rule().handler(logHandler).next().rule() - .msgType(WxConsts.XML_MSG_TEXT).matcher(guessNumberHandler) + .msgType(WxConsts.XmlMsgType.TEXT).matcher(guessNumberHandler) .handler(guessNumberHandler).end().rule().async(false).content("哈哈") .handler(textHandler).end().rule().async(false).content("图片") .handler(imageHandler).end().rule().async(false).content("oauth") diff --git a/weixin-java-open/README.md b/weixin-java-open/README.md new file mode 100644 index 0000000000..1f935a9713 --- /dev/null +++ b/weixin-java-open/README.md @@ -0,0 +1,88 @@ +消息机制未实现,下面为通知回调中设置的代码部分 + +以下代码可通过腾讯全网发布测试用例 +``` +@RestController +@RequestMapping("notify") +public class NotifyController extends WechatThridBaseController { + @Autowired + protected WxOpenServiceDemo wxOpenService; + @RequestMapping("receive_ticket") + public Object receiveTicket(@RequestBody(required = false) String requestBody, @RequestParam("timestamp") String timestamp, + @RequestParam("nonce") String nonce, @RequestParam("signature") String signature, + @RequestParam(name = "encrypt_type", required = false) String encType, + @RequestParam(name = "msg_signature", required = false) String msgSignature) { + this.logger.info( + "\n接收微信请求:[signature=[{}], encType=[{}], msgSignature=[{}]," + + " timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ", + signature, encType, msgSignature, timestamp, nonce, requestBody); + + if (!StringUtils.equalsIgnoreCase("aes", encType) || !wxOpenService.getWxOpenComponentService().checkSignature(timestamp, nonce, signature)) { + throw new IllegalArgumentException("非法请求,可能属于伪造的请求!"); + } + + // aes加密的消息 + WxOpenXmlMessage inMessage = WxOpenXmlMessage.fromEncryptedXml(requestBody, wxOpenService.getWxOpenConfigStorage(), timestamp, nonce, msgSignature); + this.logger.debug("\n消息解密后内容为:\n{} ", inMessage.toString()); + String out = null; + try { + out = wxOpenService.getWxOpenComponentService().route(inMessage); + } catch (WxErrorException e) { + throw new ResponseException(ErrorCodeEnum.ERROR, e); + } + + this.logger.debug("\n组装回复信息:{}", out); + + return out; + } + @RequestMapping("{appId}/callback") + public Object callback(@RequestBody(required = false)String requestBody, + @PathVariable ("appId") String appId, + @RequestParam("signature") String signature, + @RequestParam("timestamp") String timestamp, + @RequestParam("nonce") String nonce, + @RequestParam("openid") String openid, + @RequestParam("encrypt_type") String encType, + @RequestParam("msg_signature") String msgSignature) { + this.logger.info( + "\n接收微信请求:[appId=[{}], openid=[{}], signature=[{}], encType=[{}], msgSignature=[{}]," + + " timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ", + appId, openid, signature, encType, msgSignature, timestamp, nonce, requestBody); + logger.info("query:"+getHttpServletRequest().getQueryString()+"\nbody:"+requestBody); + if (!StringUtils.equalsIgnoreCase("aes", encType) || !wxOpenService.getWxOpenComponentService().checkSignature(timestamp, nonce, signature)) { + throw new IllegalArgumentException("非法请求,可能属于伪造的请求!"); + } + + String out = ""; + // aes加密的消息 + WxMpXmlMessage inMessage = WxOpenXmlMessage.fromEncryptedMpXml(requestBody, wxOpenService.getWxOpenConfigStorage(), timestamp, nonce, msgSignature); + this.logger.debug("\n消息解密后内容为:\n{} ", inMessage.toString()); + // 全网发布测试用例 + if (StringUtils.equalsAnyIgnoreCase(appId, "wxd101a85aa106f53e", "wx570bc396a51b8ff8")) { + try { + if (StringUtils.equals(inMessage.getMsgType(), "text")) { + if (StringUtils.equals(inMessage.getContent(), "TESTCOMPONENT_MSG_TYPE_TEXT")) { + out = new WxOpenCryptUtil(wxOpenService.getWxOpenConfigStorage()).encrypt( + WxMpXmlOutMessage.TEXT().content("TESTCOMPONENT_MSG_TYPE_TEXT_callback") + .fromUser(inMessage.getToUser()) + .toUser(inMessage.getFromUser()) + .build() + .toXml() + ); + } else if (StringUtils.startsWith(inMessage.getContent(), "QUERY_AUTH_CODE:")) { + String msg = inMessage.getContent().replace("QUERY_AUTH_CODE:", "") + "_from_api"; + WxMpKefuMessage kefuMessage = WxMpKefuMessage.TEXT().content(msg).toUser(inMessage.getFromUser()).build(); + wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(appId).getKefuService().sendKefuMessage(kefuMessage); + } + } else if (StringUtils.equals(inMessage.getMsgType(), "event")) { + WxMpKefuMessage kefuMessage = WxMpKefuMessage.TEXT().content(inMessage.getEvent() + "from_callback").toUser(inMessage.getFromUser()).build(); + wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(appId).getKefuService().sendKefuMessage(kefuMessage); + } + } catch (WxErrorException e) { + logger.error("callback", e); + } + } + return out; + } +} +``` diff --git a/weixin-java-open/pom.xml b/weixin-java-open/pom.xml new file mode 100644 index 0000000000..5dfd4308e9 --- /dev/null +++ b/weixin-java-open/pom.xml @@ -0,0 +1,97 @@ + + + + 4.0.0 + + com.github.binarywang + weixin-java-parent + 2.9.0 + + weixin-java-open + WeiXin Java Tools - Open + 微信开放平台Java SDK + + + 007 + 007gzs@gmail.com + https://github.com/007gzs + + + + + com.github.binarywang + weixin-java-common + ${project.version} + + + com.github.binarywang + weixin-java-mp + ${project.version} + + + + org.jodd + jodd-http + provided + + + com.squareup.okhttp3 + okhttp + provided + + + + org.testng + testng + test + + + com.google.inject + guice + test + + + org.eclipse.jetty + jetty-server + test + + + org.eclipse.jetty + jetty-servlet + test + + + joda-time + joda-time + test + + + redis.clients + jedis + + + ch.qos.logback + logback-classic + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/resources/testng.xml + + + + + + + + diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java new file mode 100644 index 0000000000..9dc5a6d3d1 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java @@ -0,0 +1,83 @@ +package me.chanjar.weixin.open.api; + +import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; +import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; +import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult; +import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerOptionResult; +import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult; + +/** + * @author 007 + */ +public interface WxOpenComponentService { + + String API_COMPONENT_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/component/api_component_token"; + String API_CREATE_PREAUTHCODE_URL = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode"; + String API_QUERY_AUTH_URL = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth"; + String API_AUTHORIZER_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token"; + String API_GET_AUTHORIZER_INFO_URL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info"; + String API_GET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_option"; + String API_SET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/api_set_authorizer_option"; + + + String COMPONENT_LOGIN_PAGE_URL = "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=%s&pre_auth_code=%s&redirect_uri=%s"; + String CONNECT_OAUTH2_AUTHORIZE_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s&component_appid=%s#wechat_redirect"; + + /** + * 用code换取oauth2的access token + */ + String OAUTH2_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/component/access_token?appid=%s&code=%s&grant_type=authorization_code&component_appid=%s"; + /** + * 刷新oauth2的access token + */ + String OAUTH2_REFRESH_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/component/refresh_token?appid=%s&grant_type=refresh_token&refresh_token=%s&component_appid==%s"; + + WxMpService getWxMpServiceByAppid(String appid); + + WxOpenConfigStorage getWxOpenConfigStorage(); + + boolean checkSignature(String timestamp, String nonce, String signature); + + String getComponentAccessToken(boolean forceRefresh) throws WxErrorException; + + /** + * 获取用户授权页URL(来路URL和成功跳转URL 的域名都需要为三方平台设置的 登录授权的发起页域名) + */ + String getPreAuthUrl(String redirectURI) throws WxErrorException; + + String route(WxOpenXmlMessage wxMessage) throws WxErrorException; + + /** + * 使用授权码换取公众号或小程序的接口调用凭据和授权信息 + */ + WxOpenQueryAuthResult getQueryAuth(String authorizationCode) throws WxErrorException; + + /** + * 获取授权方的帐号基本信息 + */ + WxOpenAuthorizerInfoResult getAuthorizerInfo(String authorizerAppid) throws WxErrorException; + + /** + * 获取授权方的选项设置信息 + */ + WxOpenAuthorizerOptionResult getAuthorizerOption(String authorizerAppid, String optionName) throws WxErrorException; + + /** + * 设置授权方的选项信息 + */ + WxError setAuthorizerOption(String authorizerAppid, String optionName, String optionValue) throws WxErrorException; + + String getAuthorizerAccessToken(String appid, boolean forceRefresh) throws WxErrorException; + + WxMpOAuth2AccessToken oauth2getAccessToken(String appid, String code) throws WxErrorException; + + boolean checkSignature(String appId, String timestamp, String nonce, String signature); + + WxMpOAuth2AccessToken oauth2refreshAccessToken(String appid, String refreshToken) throws WxErrorException; + + String oauth2buildAuthorizationUrl(String appid, String redirectURI, String scope, String state); + +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java new file mode 100644 index 0000000000..7e548253e8 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java @@ -0,0 +1,118 @@ +package me.chanjar.weixin.open.api; + +import me.chanjar.weixin.mp.api.WxMpConfigStorage; +import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken; +import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken; + +/** + * @author 007 + */ +public interface WxOpenConfigStorage { + + String getComponentAppId(); + + void setComponentAppId(String componentAppId); + + String getComponentAppSecret(); + + void setComponentAppSecret(String componentAppSecret); + + String getComponentToken(); + + void setComponentToken(String componentToken); + + String getComponentAesKey(); + + void setComponentAesKey(String componentAesKey); + + String getComponentVerifyTicket(); + + void setComponentVerifyTicket(String componentVerifyTicket); + + String getComponentAccessToken(); + + boolean isComponentAccessTokenExpired(); + + void updateComponentAccessTokent(WxOpenComponentAccessToken componentAccessToken); + + WxMpConfigStorage getWxMpConfigStorage(String appId); + + /** + * 应该是线程安全的 + * + * @param componentAccessToken 新的accessToken值 + * @param expiresInSeconds 过期时间,以秒为单位 + */ + void updateComponentAccessTokent(String componentAccessToken, int expiresInSeconds); + + /** + * 是否自动刷新token + */ + boolean autoRefreshToken(); + + + String getAuthorizerRefreshToken(String appId); + + void setAuthorizerRefreshToken(String appId, String authorizerRefreshToken); + + String getAuthorizerAccessToken(String appId); + + + boolean isAuthorizerAccessTokenExpired(String appId); + + /** + * 强制将access token过期掉 + */ + void expireAuthorizerAccessToken(String appId); + + /** + * 应该是线程安全的 + * + * @param authorizerAccessToken 要更新的WxAccessToken对象 + */ + void updateAuthorizerAccessToken(String appId, WxOpenAuthorizerAccessToken authorizerAccessToken); + + /** + * 应该是线程安全的 + * + * @param authorizerAccessToken 新的accessToken值 + * @param expiresInSeconds 过期时间,以秒为单位 + */ + void updateAuthorizerAccessToken(String appId, String authorizerAccessToken, int expiresInSeconds); + + String getJsapiTicket(String appId); + + boolean isJsapiTicketExpired(String appId); + + /** + * 强制将jsapi ticket过期掉 + */ + void expireJsapiTicket(String appId); + + /** + * 应该是线程安全的 + * + * @param jsapiTicket 新的jsapi ticket值 + * @param expiresInSeconds 过期时间,以秒为单位 + */ + void updateJsapiTicket(String appId, String jsapiTicket, int expiresInSeconds); + + String getCardApiTicket(String appId); + + + boolean isCardApiTicketExpired(String appId); + + /** + * 强制将卡券api ticket过期掉 + */ + void expireCardApiTicket(String appId); + + /** + * 应该是线程安全的 + * + * @param cardApiTicket 新的cardApi ticket值 + * @param expiresInSeconds 过期时间,以秒为单位 + */ + void updateCardApiTicket(String appId, String cardApiTicket, int expiresInSeconds); + +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenService.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenService.java new file mode 100644 index 0000000000..e11296e6c8 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenService.java @@ -0,0 +1,25 @@ +package me.chanjar.weixin.open.api; + +import me.chanjar.weixin.common.exception.WxErrorException; + +/** + * @author 007 + */ +public interface WxOpenService { + WxOpenComponentService getWxOpenComponentService(); + + WxOpenConfigStorage getWxOpenConfigStorage(); + + void setWxOpenConfigStorage(WxOpenConfigStorage wxOpenConfigStorage); + + /** + * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求 + */ + String get(String url, String queryParam) throws WxErrorException; + + /** + * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的POST请求 + */ + String post(String url, String postData) throws WxErrorException; + +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java new file mode 100644 index 0000000000..45de69b1e6 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java @@ -0,0 +1,223 @@ +package me.chanjar.weixin.open.api.impl; + +import com.google.gson.JsonObject; +import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.util.crypto.SHA1; +import me.chanjar.weixin.common.util.http.URIUtil; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; +import me.chanjar.weixin.open.api.WxOpenComponentService; +import me.chanjar.weixin.open.api.WxOpenConfigStorage; +import me.chanjar.weixin.open.api.WxOpenService; +import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken; +import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken; +import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo; +import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; +import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult; +import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerOptionResult; +import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult; +import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Hashtable; +import java.util.Map; + +/** + * @author 007 + */ +public class WxOpenComponentServiceImpl implements WxOpenComponentService { + private static final Map wxOpenMpServiceMap = new Hashtable<>(); + protected final Logger log = LoggerFactory.getLogger(this.getClass()); + private WxOpenService wxOpenService; + + public WxOpenComponentServiceImpl(WxOpenService wxOpenService) { + this.wxOpenService = wxOpenService; + } + + @Override + public WxMpService getWxMpServiceByAppid(String appId) { + WxMpService wxMpService = wxOpenMpServiceMap.get(appId); + if (wxMpService == null) { + synchronized (wxOpenMpServiceMap) { + wxMpService = wxOpenMpServiceMap.get(appId); + if (wxMpService == null) { + wxMpService = new WxOpenMpServiceImpl(this, appId, getWxOpenConfigStorage().getWxMpConfigStorage(appId)); + + wxOpenMpServiceMap.put(appId, wxMpService); + } + } + } + return wxMpService; + } + + public WxOpenService getWxOpenService() { + return wxOpenService; + } + + @Override + public WxOpenConfigStorage getWxOpenConfigStorage() { + return wxOpenService.getWxOpenConfigStorage(); + } + + @Override + public boolean checkSignature(String timestamp, String nonce, String signature) { + try { + return SHA1.gen(getWxOpenConfigStorage().getComponentToken(), timestamp, nonce) + .equals(signature); + } catch (Exception e) { + this.log.error("Checking signature failed, and the reason is :" + e.getMessage()); + return false; + } + } + + @Override + public String getComponentAccessToken(boolean forceRefresh) throws WxErrorException { + + if (this.getWxOpenConfigStorage().isComponentAccessTokenExpired() || forceRefresh) { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId()); + jsonObject.addProperty("component_appsecret", getWxOpenConfigStorage().getComponentAppSecret()); + jsonObject.addProperty("component_verify_ticket", getWxOpenConfigStorage().getComponentVerifyTicket()); + + String responseContent = this.getWxOpenService().post(API_COMPONENT_TOKEN_URL, jsonObject.toString()); + WxOpenComponentAccessToken componentAccessToken = WxOpenComponentAccessToken.fromJson(responseContent); + getWxOpenConfigStorage().updateComponentAccessTokent(componentAccessToken); + } + return this.getWxOpenConfigStorage().getComponentAccessToken(); + } + + private String post(String uri, String postData) throws WxErrorException { + String componentAccessToken = getComponentAccessToken(false); + String uriWithComponentAccessToken = uri + (uri.contains("?") ? "&" : "?") + "component_access_token=" + componentAccessToken; + return getWxOpenService().post(uriWithComponentAccessToken, postData); + } + + private String get(String uri) throws WxErrorException { + String componentAccessToken = getComponentAccessToken(false); + String uriWithComponentAccessToken = uri + (uri.contains("?") ? "&" : "?") + "component_access_token=" + componentAccessToken; + return getWxOpenService().get(uriWithComponentAccessToken, null); + } + + @Override + public String getPreAuthUrl(String redirectURI) throws WxErrorException { + + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId()); + String responseContent = post(API_CREATE_PREAUTHCODE_URL, jsonObject.toString()); + jsonObject = WxGsonBuilder.create().fromJson(responseContent, JsonObject.class); + return String.format(COMPONENT_LOGIN_PAGE_URL, getWxOpenConfigStorage().getComponentAppId(), jsonObject.get("pre_auth_code").getAsString(), URIUtil.encodeURIComponent(redirectURI)); + } + + @Override + public String route(final WxOpenXmlMessage wxMessage) throws WxErrorException { + if (wxMessage == null) { + throw new NullPointerException("message is empty"); + } + if (StringUtils.equalsIgnoreCase(wxMessage.getInfoType(), "component_verify_ticket")) { + getWxOpenConfigStorage().setComponentVerifyTicket(wxMessage.getComponentVerifyTicket()); + return "success"; + } + //新增、跟新授权 + if (StringUtils.equalsAnyIgnoreCase(wxMessage.getInfoType(), "authorized", "updateauthorized")) { + WxOpenQueryAuthResult queryAuth = wxOpenService.getWxOpenComponentService().getQueryAuth(wxMessage.getAuthorizationCode()); + if (queryAuth == null || queryAuth.getAuthorizationInfo() == null || queryAuth.getAuthorizationInfo().getAuthorizerAppid() == null) { + throw new NullPointerException("getQueryAuth"); + } + WxOpenAuthorizationInfo authorizationInfo = queryAuth.getAuthorizationInfo(); + if (authorizationInfo.getAuthorizerAccessToken() != null) { + getWxOpenConfigStorage().updateAuthorizerAccessToken(authorizationInfo.getAuthorizerAppid(), + authorizationInfo.getAuthorizerAccessToken(), authorizationInfo.getExpiresIn()); + } + if (authorizationInfo.getAuthorizerRefreshToken() != null) { + getWxOpenConfigStorage().setAuthorizerRefreshToken(authorizationInfo.getAuthorizerAppid(), authorizationInfo.getAuthorizerRefreshToken()); + } + return "success"; + } + return null; + } + + @Override + public WxOpenQueryAuthResult getQueryAuth(String authorizationCode) throws WxErrorException { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId()); + jsonObject.addProperty("authorization_code", authorizationCode); + String responseContent = post(API_QUERY_AUTH_URL, jsonObject.toString()); + return WxOpenGsonBuilder.create().fromJson(responseContent, WxOpenQueryAuthResult.class); + } + + @Override + public WxOpenAuthorizerInfoResult getAuthorizerInfo(String authorizerAppid) throws WxErrorException { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId()); + jsonObject.addProperty("authorizer_appid", authorizerAppid); + String responseContent = post(API_GET_AUTHORIZER_INFO_URL, jsonObject.toString()); + return WxOpenGsonBuilder.create().fromJson(responseContent, WxOpenAuthorizerInfoResult.class); + } + + @Override + public WxOpenAuthorizerOptionResult getAuthorizerOption(String authorizerAppid, String optionName) throws WxErrorException { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId()); + jsonObject.addProperty("authorizer_appid", authorizerAppid); + jsonObject.addProperty("option_name", optionName); + String responseContent = post(API_GET_AUTHORIZER_OPTION_URL, jsonObject.toString()); + return WxOpenGsonBuilder.create().fromJson(responseContent, WxOpenAuthorizerOptionResult.class); + } + + @Override + public WxError setAuthorizerOption(String authorizerAppid, String optionName, String optionValue) throws WxErrorException { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId()); + jsonObject.addProperty("authorizer_appid", authorizerAppid); + jsonObject.addProperty("option_name", optionName); + jsonObject.addProperty("option_value", optionValue); + String responseContent = post(API_SET_AUTHORIZER_OPTION_URL, jsonObject.toString()); + return WxGsonBuilder.create().fromJson(responseContent, WxError.class); + } + + @Override + public String getAuthorizerAccessToken(String appId, boolean forceRefresh) throws WxErrorException { + + if (this.getWxOpenConfigStorage().isAuthorizerAccessTokenExpired(appId) || forceRefresh) { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId()); + jsonObject.addProperty("authorizer_appid", appId); + jsonObject.addProperty("authorizer_refresh_token", getWxOpenConfigStorage().getAuthorizerRefreshToken(appId)); + String responseContent = post(API_AUTHORIZER_TOKEN_URL, jsonObject.toString()); + + WxOpenAuthorizerAccessToken wxOpenAuthorizerAccessToken = WxOpenAuthorizerAccessToken.fromJson(responseContent); + getWxOpenConfigStorage().updateAuthorizerAccessToken(appId, wxOpenAuthorizerAccessToken); + } + return this.getWxOpenConfigStorage().getAuthorizerAccessToken(appId); + } + + @Override + public WxMpOAuth2AccessToken oauth2getAccessToken(String appId, String code) throws WxErrorException { + String url = String.format(OAUTH2_ACCESS_TOKEN_URL, appId, code, getWxOpenConfigStorage().getComponentAppId()); + String responseContent = get(url); + return WxMpOAuth2AccessToken.fromJson(responseContent); + } + + @Override + public boolean checkSignature(String appid, String timestamp, String nonce, String signature) { + return false; + } + + @Override + public WxMpOAuth2AccessToken oauth2refreshAccessToken(String appId, String refreshToken) throws WxErrorException { + String url = String.format(OAUTH2_REFRESH_TOKEN_URL, appId, refreshToken, getWxOpenConfigStorage().getComponentAppId()); + String responseContent = get(url); + return WxMpOAuth2AccessToken.fromJson(responseContent); + } + + @Override + public String oauth2buildAuthorizationUrl(String appId, String redirectURI, String scope, String state) { + return String.format(CONNECT_OAUTH2_AUTHORIZE_URL, + appId, URIUtil.encodeURIComponent(redirectURI), scope, StringUtils.trimToEmpty(state), getWxOpenConfigStorage().getComponentAppId()); + } + +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java new file mode 100644 index 0000000000..50cf8b6e74 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java @@ -0,0 +1,392 @@ +package me.chanjar.weixin.open.api.impl; + + +import me.chanjar.weixin.common.bean.WxAccessToken; +import me.chanjar.weixin.common.util.ToStringUtils; +import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder; +import me.chanjar.weixin.mp.api.WxMpConfigStorage; +import me.chanjar.weixin.open.api.WxOpenConfigStorage; +import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken; +import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken; + +import java.io.File; +import java.util.Hashtable; +import java.util.Map; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +/** + * 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化 + * + * @author 007 + */ +public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage { + private String componentAppId; + private String componentAppSecret; + private String componentToken; + private String componentAesKey; + private String componentVerifyTicket; + private String componentAccessToken; + private long componentExpiresTime; + + private Map authorizerRefreshTokens = new Hashtable<>(); + private Map authorizerAccessTokens = new Hashtable<>(); + private Map jsapiTickets = new Hashtable<>(); + private Map cardApiTickets = new Hashtable<>(); + + @Override + public String getComponentAppId() { + return componentAppId; + } + + @Override + public void setComponentAppId(String componentAppId) { + this.componentAppId = componentAppId; + } + + @Override + public String getComponentAppSecret() { + return componentAppSecret; + } + + @Override + public void setComponentAppSecret(String componentAppSecret) { + this.componentAppSecret = componentAppSecret; + } + + @Override + public String getComponentToken() { + return componentToken; + } + + @Override + public void setComponentToken(String componentToken) { + this.componentToken = componentToken; + } + + @Override + public String getComponentAesKey() { + return componentAesKey; + } + + @Override + public void setComponentAesKey(String componentAesKey) { + this.componentAesKey = componentAesKey; + } + + @Override + public String getComponentVerifyTicket() { + return componentVerifyTicket; + } + + @Override + public void setComponentVerifyTicket(String componentVerifyTicket) { + this.componentVerifyTicket = componentVerifyTicket; + } + + @Override + public String getComponentAccessToken() { + return componentAccessToken; + } + + @Override + public boolean isComponentAccessTokenExpired() { + return System.currentTimeMillis() > componentExpiresTime; + } + + @Override + public void updateComponentAccessTokent(WxOpenComponentAccessToken componentAccessToken) { + updateComponentAccessTokent(componentAccessToken.getComponentAccessToken(), componentAccessToken.getExpiresIn()); + } + + @Override + public WxMpConfigStorage getWxMpConfigStorage(String appId) { + return new WxOpenMpConfigStorage(this, appId); + } + + @Override + public void updateComponentAccessTokent(String componentAccessToken, int expiresInSeconds) { + this.componentAccessToken = componentAccessToken; + this.componentExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L; + } + + @Override + public boolean autoRefreshToken() { + return true; + } + + private String getTokenString(Map map, String key) { + Token token = map.get(key); + if (token == null || (token.expiresTime != null && System.currentTimeMillis() > token.expiresTime)) { + return null; + } + return token.token; + } + + private void expireToken(Map map, String key) { + Token token = map.get(key); + if (token != null) { + token.expiresTime = 0L; + } + } + + private void updateToken(Map map, String key, String tokenString, Integer expiresInSeconds) { + Token token = map.get(key); + if (token == null) { + token = new Token(); + map.put(key, token); + } + token.token = tokenString; + if (expiresInSeconds != null) { + token.expiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L; + } + } + + @Override + public String getAuthorizerRefreshToken(String appId) { + return getTokenString(authorizerRefreshTokens, appId); + } + + @Override + public void setAuthorizerRefreshToken(String appId, String authorizerRefreshToken) { + updateToken(authorizerRefreshTokens, appId, authorizerRefreshToken, null); + } + + @Override + public String getAuthorizerAccessToken(String appId) { + return getTokenString(authorizerAccessTokens, appId); + } + + + @Override + public boolean isAuthorizerAccessTokenExpired(String appId) { + return getTokenString(authorizerAccessTokens, appId) == null; + } + + @Override + public void expireAuthorizerAccessToken(String appId) { + expireToken(authorizerAccessTokens, appId); + } + + @Override + public void updateAuthorizerAccessToken(String appId, WxOpenAuthorizerAccessToken authorizerAccessToken) { + updateAuthorizerAccessToken(appId, authorizerAccessToken.getAuthorizerAccessToken(), authorizerAccessToken.getExpiresIn()); + } + + @Override + public void updateAuthorizerAccessToken(String appId, String authorizerAccessToken, int expiresInSeconds) { + updateToken(authorizerAccessTokens, appId, authorizerAccessToken, expiresInSeconds); + } + + @Override + public String getJsapiTicket(String appId) { + return getTokenString(jsapiTickets, appId); + } + + @Override + public boolean isJsapiTicketExpired(String appId) { + return getTokenString(jsapiTickets, appId) == null; + } + + @Override + public void expireJsapiTicket(String appId) { + expireToken(jsapiTickets, appId); + } + + @Override + public void updateJsapiTicket(String appId, String jsapiTicket, int expiresInSeconds) { + updateToken(jsapiTickets, appId, jsapiTicket, expiresInSeconds); + } + + @Override + public String getCardApiTicket(String appId) { + return getTokenString(cardApiTickets, appId); + } + + @Override + public boolean isCardApiTicketExpired(String appId) { + return getTokenString(cardApiTickets, appId) == null; + } + + @Override + public void expireCardApiTicket(String appId) { + expireToken(cardApiTickets, appId); + } + + @Override + public void updateCardApiTicket(String appId, String cardApiTicket, int expiresInSeconds) { + updateToken(cardApiTickets, appId, cardApiTicket, expiresInSeconds); + } + + private static class Token { + private String token; + private Long expiresTime; + } + + private static class WxOpenMpConfigStorage implements WxMpConfigStorage { + private WxOpenConfigStorage wxOpenConfigStorage; + private String appId; + private Lock accessTokenLock = new ReentrantLock(); + private Lock jsapiTicketLock = new ReentrantLock(); + private Lock cardApiTicketLock = new ReentrantLock(); + private WxOpenMpConfigStorage(WxOpenConfigStorage wxOpenConfigStorage, String appId) { + this.wxOpenConfigStorage = wxOpenConfigStorage; + this.appId = appId; + } + + @Override + public String getAccessToken() { + return wxOpenConfigStorage.getAuthorizerAccessToken(appId); + } + + @Override + public Lock getAccessTokenLock() { + return this.accessTokenLock; + } + + @Override + public boolean isAccessTokenExpired() { + return wxOpenConfigStorage.isAuthorizerAccessTokenExpired(appId); + } + + @Override + public synchronized void updateAccessToken(WxAccessToken accessToken) { + updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn()); + } + + @Override + public synchronized void updateAccessToken(String accessToken, int expiresInSeconds) { + wxOpenConfigStorage.updateAuthorizerAccessToken(appId, accessToken, expiresInSeconds); + } + + @Override + public void expireAccessToken() { + wxOpenConfigStorage.expireAuthorizerAccessToken(appId); + } + + @Override + public String getJsapiTicket() { + return wxOpenConfigStorage.getJsapiTicket(appId); + } + + @Override + public Lock getJsapiTicketLock() { + return this.jsapiTicketLock; + } + + @Override + public boolean isJsapiTicketExpired() { + return wxOpenConfigStorage.isJsapiTicketExpired(appId); + } + + @Override + public synchronized void updateJsapiTicket(String jsapiTicket, int expiresInSeconds) { + wxOpenConfigStorage.updateJsapiTicket(appId, jsapiTicket, expiresInSeconds); + } + + @Override + public void expireJsapiTicket() { + wxOpenConfigStorage.expireJsapiTicket(appId); + } + + /** + * 卡券api_ticket + */ + @Override + public String getCardApiTicket() { + return wxOpenConfigStorage.getCardApiTicket(appId); + } + + @Override + public Lock getCardApiTicketLock() { + return this.cardApiTicketLock; + } + + @Override + public boolean isCardApiTicketExpired() { + return wxOpenConfigStorage.isCardApiTicketExpired(appId); + } + + @Override + public synchronized void updateCardApiTicket(String cardApiTicket, int expiresInSeconds) { + wxOpenConfigStorage.updateCardApiTicket(appId, cardApiTicket, expiresInSeconds); + } + + @Override + public void expireCardApiTicket() { + wxOpenConfigStorage.expireCardApiTicket(appId); + } + + @Override + public String getAppId() { + return this.appId; + } + + @Override + public String getSecret() { + return null; + } + + @Override + public String getToken() { + return wxOpenConfigStorage.getComponentToken(); + } + + @Override + public long getExpiresTime() { + return 0; + } + + + @Override + public String getAesKey() { + return wxOpenConfigStorage.getComponentAesKey(); + } + + @Override + public String getOauth2redirectUri() { + return null; + } + + @Override + public String getHttpProxyHost() { + return null; + } + + @Override + public int getHttpProxyPort() { + return 0; + } + + @Override + public String getHttpProxyUsername() { + return null; + } + + @Override + public String getHttpProxyPassword() { + return null; + } + + @Override + public String toString() { + return ToStringUtils.toSimpleString(this); + } + + @Override + public File getTmpDirFile() { + return null; + } + + @Override + public ApacheHttpClientBuilder getApacheHttpClientBuilder() { + return null; + } + + + @Override + public boolean autoRefreshToken() { + return true; + } + } +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInRedisConfigStorage.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInRedisConfigStorage.java new file mode 100644 index 0000000000..c3bd6a2b6f --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInRedisConfigStorage.java @@ -0,0 +1,180 @@ +package me.chanjar.weixin.open.api.impl; + +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * @author 007 + */ +public class WxOpenInRedisConfigStorage extends WxOpenInMemoryConfigStorage { + + private final static String COMPONENT_VERIFY_TICKET_KEY = "wechat_component_verify_ticket:"; + private final static String COMPONENT_ACCESS_TOKEN_KEY = "wechat_component_access_token:"; + + private final static String AUTHORIZER_REFRESH_TOKEN_KEY = "wechat_authorizer_refresh_token:"; + private final static String AUTHORIZER_ACCESS_TOKEN_KEY = "wechat_authorizer_access_token:"; + private final static String JSAPI_TICKET_KEY = "wechat_jsapi_ticket:"; + private final static String CARD_API_TICKET_KEY = "wechat_card_api_ticket:"; + + + protected final JedisPool jedisPool; + private String componentVerifyTicketKey; + private String componentAccessTokenKey; + private String authorizerRefreshTokenKey; + private String authorizerAccessTokenKey; + private String jsapiTicketKey; + private String cardApiTicket; + + public WxOpenInRedisConfigStorage(JedisPool jedisPool) { + this.jedisPool = jedisPool; + } + + @Override + public void setComponentAppId(String componentAppId) { + super.setComponentAppId(componentAppId); + componentVerifyTicketKey = COMPONENT_VERIFY_TICKET_KEY.concat(componentAppId); + componentAccessTokenKey = COMPONENT_ACCESS_TOKEN_KEY.concat(componentAppId); + authorizerRefreshTokenKey = AUTHORIZER_REFRESH_TOKEN_KEY.concat(componentAppId); + authorizerAccessTokenKey = AUTHORIZER_ACCESS_TOKEN_KEY.concat(componentAppId); + jsapiTicketKey = JSAPI_TICKET_KEY.concat(componentAppId); + cardApiTicket = CARD_API_TICKET_KEY.concat(componentAppId); + } + + @Override + public String getComponentVerifyTicket() { + try (Jedis jedis = jedisPool.getResource()) { + return jedis.get(componentVerifyTicketKey); + } + } + + @Override + public void setComponentVerifyTicket(String componentVerifyTicket) { + try (Jedis jedis = jedisPool.getResource()) { + jedis.set(componentVerifyTicketKey, componentVerifyTicket); + } + } + + @Override + public String getComponentAccessToken() { + try (Jedis jedis = jedisPool.getResource()) { + return jedis.get(componentAccessTokenKey); + } + } + + @Override + public boolean isComponentAccessTokenExpired() { + try (Jedis jedis = jedisPool.getResource()) { + return jedis.ttl(componentAccessTokenKey) < 2; + } + } + + @Override + public void updateComponentAccessTokent(String componentAccessToken, int expiresInSeconds) { + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.setex(componentAccessTokenKey, expiresInSeconds - 200, componentAccessToken); + } + } + + private String getKey(String prefix, String appId) { + return prefix.endsWith(":") ? prefix.concat(appId) : prefix.concat(":").concat(appId); + } + + @Override + public String getAuthorizerRefreshToken(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.get(getKey(authorizerRefreshTokenKey, appId)); + } + } + + @Override + public void setAuthorizerRefreshToken(String appId, String authorizerRefreshToken) { + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.set(getKey(authorizerRefreshTokenKey, appId), authorizerRefreshToken); + } + } + + @Override + public String getAuthorizerAccessToken(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.get(getKey(authorizerAccessTokenKey, appId)); + } + } + + + @Override + public boolean isAuthorizerAccessTokenExpired(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.ttl(getKey(authorizerAccessTokenKey, appId)) < 2; + } + } + + @Override + public void expireAuthorizerAccessToken(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.expire(getKey(authorizerAccessTokenKey, appId), 0); + } + } + + @Override + public void updateAuthorizerAccessToken(String appId, String authorizerAccessToken, int expiresInSeconds) { + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.setex(getKey(authorizerAccessTokenKey, appId), expiresInSeconds - 200, authorizerAccessToken); + } + } + + @Override + public String getJsapiTicket(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.get(getKey(jsapiTicketKey, appId)); + } + } + + @Override + public boolean isJsapiTicketExpired(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.ttl(getKey(jsapiTicketKey, appId)) < 2; + } + } + + @Override + public void expireJsapiTicket(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.expire(getKey(jsapiTicketKey, appId), 0); + } + } + + @Override + public void updateJsapiTicket(String appId, String jsapiTicket, int expiresInSeconds) { + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.setex(getKey(jsapiTicketKey, appId), expiresInSeconds - 200, jsapiTicket); + } + } + + @Override + public String getCardApiTicket(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.get(getKey(jsapiTicketKey, appId)); + } + } + + @Override + public boolean isCardApiTicketExpired(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.ttl(getKey(cardApiTicket, appId)) < 2; + } + } + + @Override + public void expireCardApiTicket(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.expire(getKey(cardApiTicket, appId), 0); + } + } + + @Override + public void updateCardApiTicket(String appId, String cardApiTicket, int expiresInSeconds) { + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.setex(getKey(cardApiTicket, appId), expiresInSeconds - 200, cardApiTicket); + } + } +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMpServiceImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMpServiceImpl.java new file mode 100644 index 0000000000..9c537bc93e --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMpServiceImpl.java @@ -0,0 +1,53 @@ +package me.chanjar.weixin.open.api.impl; + +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.api.WxMpConfigStorage; +import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; +import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; +import me.chanjar.weixin.open.api.WxOpenComponentService; + +/** + * @author 007 + */ +/* package */ class WxOpenMpServiceImpl extends WxMpServiceImpl { + private WxOpenComponentService wxOpenComponentService; + private WxMpConfigStorage wxMpConfigStorage; + private String appId; + + public WxOpenMpServiceImpl(WxOpenComponentService wxOpenComponentService, String appId, WxMpConfigStorage wxMpConfigStorage) { + this.wxOpenComponentService = wxOpenComponentService; + this.appId = appId; + this.wxMpConfigStorage = wxMpConfigStorage; + initHttp(); + } + + @Override + public WxMpConfigStorage getWxMpConfigStorage() { + return wxMpConfigStorage; + } + + @Override + public String getAccessToken(boolean forceRefresh) throws WxErrorException { + return wxOpenComponentService.getAuthorizerAccessToken(appId, forceRefresh); + } + + @Override + public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException { + return wxOpenComponentService.oauth2getAccessToken(appId, code); + } + +// @Override +// public boolean checkSignature(String timestamp, String nonce, String signature) { +// return wxOpenComponentService.checkSignature(appId, timestamp, nonce, signature); +// } + + @Override + public WxMpOAuth2AccessToken oauth2refreshAccessToken(String refreshToken) throws WxErrorException { + return wxOpenComponentService.oauth2refreshAccessToken(appId, refreshToken); + } + + @Override + public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state) { + return wxOpenComponentService.oauth2buildAuthorizationUrl(appId, redirectURI, scope, state); + } +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceAbstractImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceAbstractImpl.java new file mode 100644 index 0000000000..3276c429b4 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceAbstractImpl.java @@ -0,0 +1,66 @@ +package me.chanjar.weixin.open.api.impl; + +import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.util.http.RequestExecutor; +import me.chanjar.weixin.common.util.http.RequestHttp; +import me.chanjar.weixin.open.api.WxOpenComponentService; +import me.chanjar.weixin.open.api.WxOpenConfigStorage; +import me.chanjar.weixin.open.api.WxOpenService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +/** + * @author 007 + */ +public abstract class WxOpenServiceAbstractImpl implements WxOpenService, RequestHttp { + protected final Logger log = LoggerFactory.getLogger(this.getClass()); + protected WxOpenComponentService wxOpenComponentService = new WxOpenComponentServiceImpl(this); + private WxOpenConfigStorage wxOpenConfigStorage; + + @Override + public WxOpenComponentService getWxOpenComponentService() { + return wxOpenComponentService; + } + + @Override + public WxOpenConfigStorage getWxOpenConfigStorage() { + return wxOpenConfigStorage; + } + + public void setWxOpenConfigStorage(WxOpenConfigStorage wxOpenConfigStorage) { + this.wxOpenConfigStorage = wxOpenConfigStorage; + } + + protected synchronized T execute(RequestExecutor executor, String uri, E data) throws WxErrorException { + try { + T result = executor.execute(uri, data); + this.log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uri, data, result); + return result; + } catch (WxErrorException e) { + WxError error = e.getError(); +// /* +// * 发生以下情况时尝试刷新access_token +// * 40001 获取access_token时AppSecret错误,或者access_token无效 +// * 42001 access_token超时 +// * 40014 不合法的access_token,请开发者认真比对access_token的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口 +// */ +// if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001 || error.getErrorCode() == 40014) { +// // 强制设置wxCpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token +// this.configStorage.expireAccessToken(); +// return execute(executor, uri, data); +// } + + if (error.getErrorCode() != 0) { + this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uri, data, error); + throw new WxErrorException(error, e); + } + return null; + } catch (IOException e) { + this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uri, data, e.getMessage()); + throw new RuntimeException(e); + } + } +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceApacheHttpClientImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceApacheHttpClientImpl.java new file mode 100644 index 0000000000..58921e6957 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceApacheHttpClientImpl.java @@ -0,0 +1,45 @@ +package me.chanjar.weixin.open.api.impl; + +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.util.http.HttpType; +import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; +import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; +import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder; +import org.apache.http.HttpHost; +import org.apache.http.impl.client.CloseableHttpClient; + +/** + * apache-http方式实现 + * + * @author 007 + */ +public class WxOpenServiceApacheHttpClientImpl extends WxOpenServiceAbstractImpl { + private CloseableHttpClient httpClient = DefaultApacheHttpClientBuilder.get().build(); + private HttpHost httpProxy = null; + + @Override + public CloseableHttpClient getRequestHttpClient() { + return httpClient; + } + + @Override + public HttpHost getRequestHttpProxy() { + return httpProxy; + } + + @Override + public HttpType getRequestType() { + return HttpType.APACHE_HTTP; + } + + @Override + public String get(String url, String queryParam) throws WxErrorException { + return execute(SimpleGetRequestExecutor.create(this), url, queryParam); + } + + @Override + public String post(String url, String postData) throws WxErrorException { + return execute(SimplePostRequestExecutor.create(this), url, postData); + } + +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceImpl.java new file mode 100644 index 0000000000..c807ccdf99 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceImpl.java @@ -0,0 +1,8 @@ +package me.chanjar.weixin.open.api.impl; + +/** + * @author 007 + */ +public class WxOpenServiceImpl extends WxOpenServiceApacheHttpClientImpl { + +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/WxOpenAuthorizerAccessToken.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/WxOpenAuthorizerAccessToken.java new file mode 100644 index 0000000000..9b86412bb3 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/WxOpenAuthorizerAccessToken.java @@ -0,0 +1,36 @@ +package me.chanjar.weixin.open.bean; + +import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder; + +import java.io.Serializable; + +/** + * @author 007 + */ +public class WxOpenAuthorizerAccessToken implements Serializable { + private static final long serialVersionUID = -4069745419280727420L; + + private String authorizerAccessToken; + + private int expiresIn = -1; + + public static WxOpenAuthorizerAccessToken fromJson(String json) { + return WxOpenGsonBuilder.create().fromJson(json, WxOpenAuthorizerAccessToken.class); + } + + public String getAuthorizerAccessToken() { + return authorizerAccessToken; + } + + public void setAuthorizerAccessToken(String authorizerAccessToken) { + this.authorizerAccessToken = authorizerAccessToken; + } + + public int getExpiresIn() { + return expiresIn; + } + + public void setExpiresIn(int expiresIn) { + this.expiresIn = expiresIn; + } +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/WxOpenComponentAccessToken.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/WxOpenComponentAccessToken.java new file mode 100644 index 0000000000..8a97c24dfb --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/WxOpenComponentAccessToken.java @@ -0,0 +1,36 @@ +package me.chanjar.weixin.open.bean; + +import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder; + +import java.io.Serializable; + +/** + * @author 007 + */ +public class WxOpenComponentAccessToken implements Serializable { + private static final long serialVersionUID = 2134550135400443725L; + + private String componentAccessToken; + + private int expiresIn = -1; + + public static WxOpenComponentAccessToken fromJson(String json) { + return WxOpenGsonBuilder.create().fromJson(json, WxOpenComponentAccessToken.class); + } + + public String getComponentAccessToken() { + return componentAccessToken; + } + + public void setComponentAccessToken(String componentAccessToken) { + this.componentAccessToken = componentAccessToken; + } + + public int getExpiresIn() { + return expiresIn; + } + + public void setExpiresIn(int expiresIn) { + this.expiresIn = expiresIn; + } +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/auth/WxOpenAuthorizationInfo.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/auth/WxOpenAuthorizationInfo.java new file mode 100644 index 0000000000..23e8f1497e --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/auth/WxOpenAuthorizationInfo.java @@ -0,0 +1,20 @@ +package me.chanjar.weixin.open.bean.auth; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * @author 007 + */ +@Data +public class WxOpenAuthorizationInfo implements Serializable { + private static final long serialVersionUID = -8713680081354754208L; + + private String authorizerAppid; + private String authorizerAccessToken; + private int expiresIn; + private String authorizerRefreshToken; + private List funcInfo; +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/auth/WxOpenAuthorizerInfo.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/auth/WxOpenAuthorizerInfo.java new file mode 100644 index 0000000000..864724035d --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/auth/WxOpenAuthorizerInfo.java @@ -0,0 +1,24 @@ +package me.chanjar.weixin.open.bean.auth; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Map; + +/** + * @author 007 + */ +@Data +public class WxOpenAuthorizerInfo implements Serializable { + private static final long serialVersionUID = -5327886953416394738L; + + private String nickName; + private String headImg; + private Integer serviceTypeInfo; + private Integer verifyTypeInfo; + private String userName; + private String principalName; + private Map businessInfo; + private String alias; + private String qrcodeUrl; +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/message/WxOpenXmlMessage.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/message/WxOpenXmlMessage.java new file mode 100644 index 0000000000..8cb245ba3e --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/message/WxOpenXmlMessage.java @@ -0,0 +1,109 @@ +package me.chanjar.weixin.open.bean.message; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import com.thoughtworks.xstream.annotations.XStreamConverter; +import lombok.Data; +import me.chanjar.weixin.common.util.xml.XStreamCDataConverter; +import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; +import me.chanjar.weixin.open.api.WxOpenConfigStorage; +import me.chanjar.weixin.open.util.WxOpenCryptUtil; +import me.chanjar.weixin.open.util.xml.XStreamTransformer; +import org.apache.commons.io.IOUtils; + +import java.io.IOException; +import java.io.InputStream; +import java.io.Serializable; + +/** + * @author 007 + */ +@XStreamAlias("xml") +@Data +public class WxOpenXmlMessage implements Serializable { + private static final long serialVersionUID = -5641769554709507771L; + + @XStreamAlias("AppId") + @XStreamConverter(value = XStreamCDataConverter.class) + private String appId; + + @XStreamAlias("CreateTime") + private Long createTime; + + @XStreamAlias("InfoType") + @XStreamConverter(value = XStreamCDataConverter.class) + private String infoType; + + @XStreamAlias("ComponentVerifyTicket") + @XStreamConverter(value = XStreamCDataConverter.class) + private String componentVerifyTicket; + + @XStreamAlias("AuthorizerAppid") + @XStreamConverter(value = XStreamCDataConverter.class) + private String authorizerAppid; + + @XStreamAlias("AuthorizationCode") + @XStreamConverter(value = XStreamCDataConverter.class) + private String authorizationCode; + + @XStreamAlias("AuthorizationCodeExpiredTime") + private Long authorizationCodeExpiredTime; + + @XStreamAlias("PreAuthCode") + @XStreamConverter(value = XStreamCDataConverter.class) + private String preAuthCode; + + public static String wxMpOutXmlMessageToEncryptedXml(WxMpXmlOutMessage message, WxOpenConfigStorage wxOpenConfigStorage){ + String plainXml = message.toXml(); + WxOpenCryptUtil pc = new WxOpenCryptUtil(wxOpenConfigStorage); + return pc.encrypt(plainXml); + } + + public static WxOpenXmlMessage fromXml(String xml) { + //修改微信变态的消息内容格式,方便解析 + xml = xml.replace("", ""); + return XStreamTransformer.fromXml(WxOpenXmlMessage.class, xml); + } + + public static WxOpenXmlMessage fromXml(InputStream is) { + return XStreamTransformer.fromXml(WxOpenXmlMessage.class, is); + } + + /** + * 从加密字符串转换 + * + * @param encryptedXml 密文 + * @param wxOpenConfigStorage 配置存储器对象 + * @param timestamp 时间戳 + * @param nonce 随机串 + * @param msgSignature 签名串 + */ + public static WxOpenXmlMessage fromEncryptedXml(String encryptedXml, + WxOpenConfigStorage wxOpenConfigStorage, String timestamp, String nonce, + String msgSignature) { + WxOpenCryptUtil cryptUtil = new WxOpenCryptUtil(wxOpenConfigStorage); + String plainText = cryptUtil.decrypt(msgSignature, timestamp, nonce, + encryptedXml); + return fromXml(plainText); + } + + public static WxMpXmlMessage fromEncryptedMpXml(String encryptedXml, + WxOpenConfigStorage wxOpenConfigStorage, String timestamp, String nonce, + String msgSignature) { + WxOpenCryptUtil cryptUtil = new WxOpenCryptUtil(wxOpenConfigStorage); + String plainText = cryptUtil.decrypt(msgSignature, timestamp, nonce, + encryptedXml); + return WxMpXmlMessage.fromXml(plainText); + } + + public static WxOpenXmlMessage fromEncryptedXml(InputStream is, + WxOpenConfigStorage wxOpenConfigStorage, String timestamp, String nonce, + String msgSignature) { + try { + return fromEncryptedXml(IOUtils.toString(is, "UTF-8"), wxOpenConfigStorage, + timestamp, nonce, msgSignature); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/result/WxOpenAuthorizerInfoResult.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/result/WxOpenAuthorizerInfoResult.java new file mode 100644 index 0000000000..7bccff5c3c --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/result/WxOpenAuthorizerInfoResult.java @@ -0,0 +1,18 @@ +package me.chanjar.weixin.open.bean.result; + +import lombok.Data; +import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo; +import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizerInfo; + +import java.io.Serializable; + +/** + * @author 007 + */ +@Data +public class WxOpenAuthorizerInfoResult implements Serializable { + private static final long serialVersionUID = 3166298050833019785L; + + private WxOpenAuthorizationInfo authorizationInfo; + private WxOpenAuthorizerInfo authorizerInfo; +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/result/WxOpenAuthorizerOptionResult.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/result/WxOpenAuthorizerOptionResult.java new file mode 100644 index 0000000000..c0ccf008ad --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/result/WxOpenAuthorizerOptionResult.java @@ -0,0 +1,17 @@ +package me.chanjar.weixin.open.bean.result; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author 007 + */ +@Data +public class WxOpenAuthorizerOptionResult implements Serializable { + private static final long serialVersionUID = 4477837353654658179L; + + String authorizerAppid; + String optionName; + String optionValue; +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/result/WxOpenQueryAuthResult.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/result/WxOpenQueryAuthResult.java new file mode 100644 index 0000000000..5da7b6e6cf --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/result/WxOpenQueryAuthResult.java @@ -0,0 +1,16 @@ +package me.chanjar.weixin.open.bean.result; + +import lombok.Data; +import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo; + +import java.io.Serializable; + +/** + * @author 007 + */ +@Data +public class WxOpenQueryAuthResult implements Serializable { + private static final long serialVersionUID = 2394736235020206855L; + + private WxOpenAuthorizationInfo authorizationInfo; +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/WxOpenCryptUtil.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/WxOpenCryptUtil.java new file mode 100644 index 0000000000..a27b6fe636 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/WxOpenCryptUtil.java @@ -0,0 +1,29 @@ +package me.chanjar.weixin.open.util; + +import me.chanjar.weixin.open.api.WxOpenConfigStorage; +import org.apache.commons.codec.binary.Base64; + +/** + * @author 007 + */ +public class WxOpenCryptUtil extends me.chanjar.weixin.common.util.crypto.WxCryptUtil { + /** + * 构造函数 + * + * @param wxOpenConfigStorage + */ + public WxOpenCryptUtil(WxOpenConfigStorage wxOpenConfigStorage) { + /* + * @param token 公众平台上,开发者设置的token + * @param encodingAesKey 公众平台上,开发者设置的EncodingAESKey + * @param appId 公众平台appid + */ + String encodingAesKey = wxOpenConfigStorage.getComponentAesKey(); + String token = wxOpenConfigStorage.getComponentToken(); + String appId = wxOpenConfigStorage.getComponentAppId(); + + this.token = token; + this.appidOrCorpid = appId; + this.aesKey = Base64.decodeBase64(encodingAesKey + "="); + } +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizationInfoGsonAdapter.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizationInfoGsonAdapter.java new file mode 100644 index 0000000000..69df0647c8 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizationInfoGsonAdapter.java @@ -0,0 +1,45 @@ +package me.chanjar.weixin.open.util.json; + +import com.google.gson.*; +import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +/** + * @author 007 + */ +public class WxOpenAuthorizationInfoGsonAdapter implements JsonDeserializer { + @Override + public WxOpenAuthorizationInfo deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + WxOpenAuthorizationInfo authorizationInfo = new WxOpenAuthorizationInfo(); + JsonObject jsonObject = jsonElement.getAsJsonObject(); + authorizationInfo.setAuthorizerAppid(GsonHelper.getString(jsonObject, "authorizer_appid")); + authorizationInfo.setAuthorizerAccessToken(GsonHelper.getString(jsonObject, "authorizer_access_token")); + authorizationInfo.setExpiresIn(GsonHelper.getPrimitiveInteger(jsonObject, "expires_in")); + authorizationInfo.setAuthorizerRefreshToken(GsonHelper.getString(jsonObject, "authorizer_refresh_token")); + List funcInfo = new ArrayList<>(); + JsonArray jsonArray = GsonHelper.getAsJsonArray(jsonObject.get("func_info")); + if (jsonArray != null && !jsonArray.isJsonNull()) { + for (int i = 0; i < jsonArray.size(); i++) { + jsonObject = jsonArray.get(i).getAsJsonObject(); + if (jsonObject == null || jsonObject.isJsonNull()) { + continue; + } + jsonObject = jsonObject.getAsJsonObject("funcscope_category"); + if (jsonObject == null || jsonObject.isJsonNull()) { + continue; + } + Integer id = GsonHelper.getInteger(jsonObject, "id"); + if (id == null) { + continue; + } + funcInfo.add(id); + } + } + authorizationInfo.setFuncInfo(funcInfo); + return authorizationInfo; + } +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerAccessTokenGsonAdapter.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerAccessTokenGsonAdapter.java new file mode 100644 index 0000000000..82a04b9ba8 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerAccessTokenGsonAdapter.java @@ -0,0 +1,21 @@ +package me.chanjar.weixin.open.util.json; + +import com.google.gson.*; +import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken; + +import java.lang.reflect.Type; + +/** + * @author 007 + */ +public class WxOpenAuthorizerAccessTokenGsonAdapter implements JsonDeserializer { + @Override + public WxOpenAuthorizerAccessToken deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + WxOpenAuthorizerAccessToken authorizerAccessToken = new WxOpenAuthorizerAccessToken(); + JsonObject jsonObject = jsonElement.getAsJsonObject(); + authorizerAccessToken.setAuthorizerAccessToken(GsonHelper.getString(jsonObject, "authorizer_access_token")); + authorizerAccessToken.setExpiresIn(GsonHelper.getPrimitiveInteger(jsonObject, "expires_in")); + return authorizerAccessToken; + } +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerInfoGsonAdapter.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerInfoGsonAdapter.java new file mode 100644 index 0000000000..cc03a82e1c --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerInfoGsonAdapter.java @@ -0,0 +1,38 @@ +package me.chanjar.weixin.open.util.json; + +import com.google.gson.*; +import com.google.gson.reflect.TypeToken; +import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizerInfo; + +import java.lang.reflect.Type; +import java.util.Map; + +/** + * @author 007 + */ +public class WxOpenAuthorizerInfoGsonAdapter implements JsonDeserializer { + @Override + public WxOpenAuthorizerInfo deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + WxOpenAuthorizerInfo authorizationInfo = new WxOpenAuthorizerInfo(); + JsonObject jsonObject = jsonElement.getAsJsonObject(); + + authorizationInfo.setNickName(GsonHelper.getString(jsonObject, "nick_name")); + authorizationInfo.setHeadImg(GsonHelper.getString(jsonObject, "head_img")); + authorizationInfo.setUserName(GsonHelper.getString(jsonObject, "user_name")); + authorizationInfo.setPrincipalName(GsonHelper.getString(jsonObject, "principal_name")); + authorizationInfo.setAlias(GsonHelper.getString(jsonObject, "alias")); + authorizationInfo.setQrcodeUrl(GsonHelper.getString(jsonObject, "qrcode_url")); + if (jsonObject.has("service_type_info")) { + authorizationInfo.setServiceTypeInfo(GsonHelper.getInteger(jsonObject.getAsJsonObject("service_type_info"), "id")); + } + if (jsonObject.has("verify_type_info")) { + authorizationInfo.setVerifyTypeInfo(GsonHelper.getInteger(jsonObject.getAsJsonObject("verify_type_info"), "id")); + } + Map businessInfo = WxOpenGsonBuilder.create().fromJson(jsonObject.get("business_info"), + new TypeToken>() { + }.getType()); + authorizationInfo.setBusinessInfo(businessInfo); + return authorizationInfo; + } +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerInfoResultGsonAdapter.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerInfoResultGsonAdapter.java new file mode 100644 index 0000000000..1cef0ff411 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerInfoResultGsonAdapter.java @@ -0,0 +1,32 @@ +package me.chanjar.weixin.open.util.json; + +import com.google.gson.*; +import com.google.gson.reflect.TypeToken; +import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo; +import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizerInfo; +import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult; + +import java.lang.reflect.Type; + +/** + * @author 007 + */ +public class WxOpenAuthorizerInfoResultGsonAdapter implements JsonDeserializer { + @Override + public WxOpenAuthorizerInfoResult deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + WxOpenAuthorizerInfoResult authorizerInfoResult = new WxOpenAuthorizerInfoResult(); + JsonObject jsonObject = jsonElement.getAsJsonObject(); + + WxOpenAuthorizationInfo authorizationInfo = WxOpenGsonBuilder.INSTANCE.create().fromJson(jsonObject.get("authorization_info"), + new TypeToken() { + }.getType()); + + authorizerInfoResult.setAuthorizationInfo(authorizationInfo); + WxOpenAuthorizerInfo authorizerInfo = WxOpenGsonBuilder.INSTANCE.create().fromJson(jsonObject.get("authorizer_info"), + new TypeToken() { + }.getType()); + + authorizerInfoResult.setAuthorizerInfo(authorizerInfo); + return authorizerInfoResult; + } +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerOptionResultGsonAdapter.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerOptionResultGsonAdapter.java new file mode 100644 index 0000000000..8a2d379c31 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerOptionResultGsonAdapter.java @@ -0,0 +1,22 @@ +package me.chanjar.weixin.open.util.json; + +import com.google.gson.*; +import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerOptionResult; + +import java.lang.reflect.Type; + +/** + * @author 007 + */ +public class WxOpenAuthorizerOptionResultGsonAdapter implements JsonDeserializer { + @Override + public WxOpenAuthorizerOptionResult deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + WxOpenAuthorizerOptionResult authorizerOptionResult = new WxOpenAuthorizerOptionResult(); + JsonObject jsonObject = jsonElement.getAsJsonObject(); + authorizerOptionResult.setAuthorizerAppid(GsonHelper.getString(jsonObject, "authorizer_appid")); + authorizerOptionResult.setOptionName(GsonHelper.getString(jsonObject, "option_name")); + authorizerOptionResult.setOptionValue(GsonHelper.getString(jsonObject, "option_value")); + return authorizerOptionResult; + } +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenComponentAccessTokenGsonAdapter.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenComponentAccessTokenGsonAdapter.java new file mode 100644 index 0000000000..10ed85083c --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenComponentAccessTokenGsonAdapter.java @@ -0,0 +1,21 @@ +package me.chanjar.weixin.open.util.json; + +import com.google.gson.*; +import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken; + +import java.lang.reflect.Type; + +/** + * @author 007 + */ +public class WxOpenComponentAccessTokenGsonAdapter implements JsonDeserializer { + @Override + public WxOpenComponentAccessToken deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + WxOpenComponentAccessToken componentAccessToken = new WxOpenComponentAccessToken(); + JsonObject jsonObject = jsonElement.getAsJsonObject(); + componentAccessToken.setComponentAccessToken(GsonHelper.getString(jsonObject, "component_access_token")); + componentAccessToken.setExpiresIn(GsonHelper.getPrimitiveInteger(jsonObject, "expires_in")); + return componentAccessToken; + } +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenGsonBuilder.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenGsonBuilder.java new file mode 100644 index 0000000000..2b390adef3 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenGsonBuilder.java @@ -0,0 +1,36 @@ +package me.chanjar.weixin.open.util.json; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken; +import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken; +import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo; +import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizerInfo; +import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult; +import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerOptionResult; +import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult; + +/** + * @author 007 + */ +public class WxOpenGsonBuilder { + + public static final GsonBuilder INSTANCE = new GsonBuilder(); + + static { + INSTANCE.disableHtmlEscaping(); + INSTANCE.registerTypeAdapter(WxOpenComponentAccessToken.class, new WxOpenComponentAccessTokenGsonAdapter()); + INSTANCE.registerTypeAdapter(WxOpenAuthorizerAccessToken.class, new WxOpenAuthorizerAccessTokenGsonAdapter()); + INSTANCE.registerTypeAdapter(WxOpenAuthorizationInfo.class, new WxOpenAuthorizationInfoGsonAdapter()); + INSTANCE.registerTypeAdapter(WxOpenAuthorizerInfo.class, new WxOpenAuthorizerInfoGsonAdapter()); + INSTANCE.registerTypeAdapter(WxOpenQueryAuthResult.class, new WxOpenQueryAuthResultGsonAdapter()); + INSTANCE.registerTypeAdapter(WxOpenAuthorizerInfoResult.class, new WxOpenAuthorizerInfoResultGsonAdapter()); + INSTANCE.registerTypeAdapter(WxOpenAuthorizerOptionResult.class, new WxOpenAuthorizerOptionResultGsonAdapter()); + + } + + public static Gson create() { + return INSTANCE.create(); + } + +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenQueryAuthResultGsonAdapter.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenQueryAuthResultGsonAdapter.java new file mode 100644 index 0000000000..8868d0fef7 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenQueryAuthResultGsonAdapter.java @@ -0,0 +1,26 @@ +package me.chanjar.weixin.open.util.json; + +import com.google.gson.*; +import com.google.gson.reflect.TypeToken; +import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo; +import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult; + +import java.lang.reflect.Type; + +/** + * @author 007 + */ +public class WxOpenQueryAuthResultGsonAdapter implements JsonDeserializer { + @Override + public WxOpenQueryAuthResult deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + WxOpenQueryAuthResult queryAuthResult = new WxOpenQueryAuthResult(); + JsonObject jsonObject = jsonElement.getAsJsonObject(); + + WxOpenAuthorizationInfo authorizationInfo = WxOpenGsonBuilder.INSTANCE.create().fromJson(jsonObject.get("authorization_info"), + new TypeToken() { + }.getType()); + + queryAuthResult.setAuthorizationInfo(authorizationInfo); + return queryAuthResult; + } +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/xml/XStreamTransformer.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/xml/XStreamTransformer.java new file mode 100644 index 0000000000..515c90def0 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/xml/XStreamTransformer.java @@ -0,0 +1,90 @@ +package me.chanjar.weixin.open.util.xml; + +import com.thoughtworks.xstream.XStream; +import me.chanjar.weixin.common.util.xml.XStreamInitializer; +import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; + +import java.io.InputStream; +import java.util.*; + +/** + * @author 007 + */ +public class XStreamTransformer { + private static final Map, XStream> CLASS_2_XSTREAM_INSTANCE = new HashMap<>(); + + static { + registerClass(WxOpenXmlMessage.class); + } + + /** + * xml -> pojo + */ + @SuppressWarnings("unchecked") + public static T fromXml(Class clazz, String xml) { + T object = (T) CLASS_2_XSTREAM_INSTANCE.get(clazz).fromXML(xml); + return object; + } + + @SuppressWarnings("unchecked") + public static T fromXml(Class clazz, InputStream is) { + T object = (T) CLASS_2_XSTREAM_INSTANCE.get(clazz).fromXML(is); + return object; + } + + /** + * pojo -> xml + */ + public static String toXml(Class clazz, T object) { + return CLASS_2_XSTREAM_INSTANCE.get(clazz).toXML(object); + } + + /** + * 注册扩展消息的解析器 + * + * @param clz 类型 + * @param xStream xml解析器 + */ + private static void register(Class clz, XStream xStream) { + CLASS_2_XSTREAM_INSTANCE.put(clz, xStream); + } + + /** + * 会自动注册该类及其子类 + * + * @param clz 要注册的类 + */ + private static void registerClass(Class clz) { + XStream xstream = XStreamInitializer.getInstance(); + xstream.setClassLoader(Thread.currentThread().getContextClassLoader()); + + xstream.processAnnotations(clz); + xstream.processAnnotations(getInnerClasses(clz)); + if (clz.equals(WxOpenXmlMessage.class)) { + // 操蛋的微信,模板消息推送成功的消息是MsgID,其他消息推送过来是MsgId + xstream.aliasField("MsgID", WxOpenXmlMessage.class, "msgId"); + } + + register(clz, xstream); + } + + private static Class[] getInnerClasses(Class clz) { + Class[] innerClasses = clz.getClasses(); + if (innerClasses == null) { + return null; + } + + List> result = new ArrayList<>(); + result.addAll(Arrays.asList(innerClasses)); + for (Class inner : innerClasses) { + Class[] innerClz = getInnerClasses(inner); + if (innerClz == null) { + continue; + } + + result.addAll(Arrays.asList(innerClz)); + } + + return result.toArray(new Class[0]); + } +} diff --git a/weixin-java-pay/pom.xml b/weixin-java-pay/pom.xml index 05aa6c5f8f..f245bff227 100644 --- a/weixin-java-pay/pom.xml +++ b/weixin-java-pay/pom.xml @@ -5,7 +5,7 @@ weixin-java-parent com.github.binarywang - 2.8.0 + 2.9.0 4.0.0 @@ -30,6 +30,11 @@ provided
+ + org.apache.commons + commons-lang3 + + ch.qos.logback logback-classic diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/WxPayApiData.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/WxPayApiData.java index ab1dec718c..db9a8833db 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/WxPayApiData.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/WxPayApiData.java @@ -1,5 +1,8 @@ package com.github.binarywang.wxpay.bean; +import lombok.Data; +import lombok.NoArgsConstructor; + /** *
  * 微信支付接口请求数据封装对象
@@ -8,6 +11,8 @@
  *
  * @author Binary Wang
  */
+@Data
+@NoArgsConstructor
 public class WxPayApiData {
   /**
    * 接口请求地址
@@ -42,38 +47,6 @@ public WxPayApiData(String url, String requestData, String responseData, String
     this.exceptionMsg = exceptionMsg;
   }
 
-  public String getUrl() {
-    return this.url;
-  }
-
-  public void setUrl(String url) {
-    this.url = url;
-  }
-
-  public String getRequestData() {
-    return this.requestData;
-  }
-
-  public void setRequestData(String requestData) {
-    this.requestData = requestData;
-  }
-
-  public String getResponseData() {
-    return this.responseData;
-  }
-
-  public void setResponseData(String responseData) {
-    this.responseData = responseData;
-  }
-
-  public String getExceptionMsg() {
-    return this.exceptionMsg;
-  }
-
-  public void setExceptionMsg(String exceptionMsg) {
-    this.exceptionMsg = exceptionMsg;
-  }
-
   @Override
   public String toString() {
     if (this.exceptionMsg != null) {
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponInfoQueryRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponInfoQueryRequest.java
index 3d83d0a6c6..54d16bd96a 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponInfoQueryRequest.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponInfoQueryRequest.java
@@ -2,6 +2,7 @@
 
 import com.github.binarywang.wxpay.bean.request.WxPayBaseRequest;
 import com.thoughtworks.xstream.annotations.XStreamAlias;
+import lombok.*;
 import me.chanjar.weixin.common.annotation.Required;
 
 /**
@@ -12,8 +13,13 @@
  *
  * @author Binary Wang
  */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@Builder(builderMethodName = "newBuilder")
+@NoArgsConstructor
+@AllArgsConstructor
 @XStreamAlias("xml")
-public class WxPayCouponInfoQueryRequest  extends WxPayBaseRequest {
+public class WxPayCouponInfoQueryRequest extends WxPayBaseRequest {
   /**
    * 
    * 字段名:代金券id
@@ -108,173 +114,10 @@ public class WxPayCouponInfoQueryRequest  extends WxPayBaseRequest {
   @XStreamAlias("type")
   private String type;
 
-  private WxPayCouponInfoQueryRequest(Builder builder) {
-    setAppid(builder.appid);
-    setMchId(builder.mchId);
-    setSubAppId(builder.subAppId);
-    setSubMchId(builder.subMchId);
-    setNonceStr(builder.nonceStr);
-    setSign(builder.sign);
-    setCouponId(builder.couponId);
-    setStockId(builder.stockId);
-    setOpenid(builder.openid);
-    setOpUserId(builder.opUserId);
-    setDeviceInfo(builder.deviceInfo);
-    setVersion(builder.version);
-    setType(builder.type);
-  }
-
-  public static Builder newBuilder() {
-    return new Builder();
-  }
-
-  public String getCouponId() {
-    return this.couponId;
-  }
-
-  public void setCouponId(String couponId) {
-    this.couponId = couponId;
-  }
-
-  public String getStockId() {
-    return this.stockId;
-  }
-
-  public void setStockId(String stockId) {
-    this.stockId = stockId;
-  }
-
-  public String getOpenid() {
-    return this.openid;
-  }
-
-  public void setOpenid(String openid) {
-    this.openid = openid;
-  }
-
-  public String getOpUserId() {
-    return this.opUserId;
-  }
-
-  public void setOpUserId(String opUserId) {
-    this.opUserId = opUserId;
-  }
-
-  public String getDeviceInfo() {
-    return this.deviceInfo;
-  }
-
-  public void setDeviceInfo(String deviceInfo) {
-    this.deviceInfo = deviceInfo;
-  }
-
-  public String getVersion() {
-    return this.version;
-  }
-
-  public void setVersion(String version) {
-    this.version = version;
-  }
-
-  public String getType() {
-    return this.type;
-  }
-
-  public void setType(String type) {
-    this.type = type;
-  }
 
   @Override
   protected void checkConstraints() {
     //do nothing
   }
 
-
-  public static final class Builder {
-    private String appid;
-    private String mchId;
-    private String subAppId;
-    private String subMchId;
-    private String nonceStr;
-    private String sign;
-    private String couponId;
-    private String stockId;
-    private String openid;
-    private String opUserId;
-    private String deviceInfo;
-    private String version;
-    private String type;
-
-    private Builder() {
-    }
-
-    public Builder appid(String appid) {
-      this.appid = appid;
-      return this;
-    }
-
-    public Builder mchId(String mchId) {
-      this.mchId = mchId;
-      return this;
-    }
-
-    public Builder subAppId(String subAppId) {
-      this.subAppId = subAppId;
-      return this;
-    }
-
-    public Builder subMchId(String subMchId) {
-      this.subMchId = subMchId;
-      return this;
-    }
-
-    public Builder nonceStr(String nonceStr) {
-      this.nonceStr = nonceStr;
-      return this;
-    }
-
-    public Builder sign(String sign) {
-      this.sign = sign;
-      return this;
-    }
-
-    public Builder couponId(String couponId) {
-      this.couponId = couponId;
-      return this;
-    }
-
-    public Builder stockId(String stockId) {
-      this.stockId = stockId;
-      return this;
-    }
-
-    public Builder openid(String openid) {
-      this.openid = openid;
-      return this;
-    }
-
-    public Builder opUserId(String opUserId) {
-      this.opUserId = opUserId;
-      return this;
-    }
-
-    public Builder deviceInfo(String deviceInfo) {
-      this.deviceInfo = deviceInfo;
-      return this;
-    }
-
-    public Builder version(String version) {
-      this.version = version;
-      return this;
-    }
-
-    public Builder type(String type) {
-      this.type = type;
-      return this;
-    }
-
-    public WxPayCouponInfoQueryRequest build() {
-      return new WxPayCouponInfoQueryRequest(this);
-    }
-  }
 }
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponInfoQueryResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponInfoQueryResult.java
index bec1c9e10a..f7d9138392 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponInfoQueryResult.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponInfoQueryResult.java
@@ -2,6 +2,9 @@
 
 import com.github.binarywang.wxpay.bean.result.WxPayBaseResult;
 import com.thoughtworks.xstream.annotations.XStreamAlias;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
 
 /**
  * 
@@ -11,11 +14,14 @@
  *
  * @author Binary Wang
  */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@NoArgsConstructor
 @XStreamAlias("xml")
 public class WxPayCouponInfoQueryResult extends WxPayBaseResult {
   /**
    * 
-   * 字段名:设备号
+   * 字段名:设备号.
    * 变量名:device_info
    * 是否必填:否
    * 示例值:123456sb
@@ -28,7 +34,7 @@ public class WxPayCouponInfoQueryResult extends WxPayBaseResult {
 
   /**
    * 
-   * 字段名:批次ID
+   * 字段名:批次ID.
    * 变量名:coupon_stock_id
    * 是否必填:是
    * 示例值:1567
@@ -41,7 +47,7 @@ public class WxPayCouponInfoQueryResult extends WxPayBaseResult {
 
   /**
    * 
-   * 字段名:代金券id
+   * 字段名:代金券id.
    * 变量名:coupon_id
    * 是否必填:是
    * 示例值:4242
@@ -54,7 +60,7 @@ public class WxPayCouponInfoQueryResult extends WxPayBaseResult {
 
   /**
    * 
-   * 字段名:代金券面额
+   * 字段名:代金券面额.
    * 变量名:coupon_value
    * 是否必填:是
    * 示例值:4
@@ -67,7 +73,7 @@ public class WxPayCouponInfoQueryResult extends WxPayBaseResult {
 
   /**
    * 
-   * 字段名:代金券使用门槛
+   * 字段名:代金券使用门槛.
    * 变量名:coupon_mininum
    * 是否必填:是
    * 示例值:10
@@ -80,7 +86,7 @@ public class WxPayCouponInfoQueryResult extends WxPayBaseResult {
 
   /**
    * 
-   * 字段名:代金券名称
+   * 字段名:代金券名称.
    * 变量名:coupon_name
    * 是否必填:是
    * 示例值:测试代金券
@@ -93,20 +99,20 @@ public class WxPayCouponInfoQueryResult extends WxPayBaseResult {
 
   /**
    * 
-   * 字段名:代金券状态
+   * 字段名:代金券状态.
    * 变量名:coupon_state
    * 是否必填:是
    * 示例值:SENDED
-   * 类型:int
+   * 类型:String
    * 说明:代金券状态:SENDED-可用,USED-已实扣,EXPIRED-已过期
    * 
*/ @XStreamAlias("coupon_state") - private Integer couponState; + private String couponState; /** *
-   * 字段名:代金券描述
+   * 字段名:代金券描述.
    * 变量名:coupon_desc
    * 是否必填:是
    * 示例值:微信支付-代金券
@@ -119,7 +125,7 @@ public class WxPayCouponInfoQueryResult extends WxPayBaseResult {
 
   /**
    * 
-   * 字段名:实际优惠金额
+   * 字段名:实际优惠金额.
    * 变量名:coupon_use_value
    * 是否必填:是
    * 示例值:0
@@ -132,7 +138,7 @@ public class WxPayCouponInfoQueryResult extends WxPayBaseResult {
 
   /**
    * 
-   * 字段名:优惠剩余可用额
+   * 字段名:优惠剩余可用额.
    * 变量名:coupon_remain_value
    * 是否必填:是
    * 示例值:4
@@ -145,7 +151,7 @@ public class WxPayCouponInfoQueryResult extends WxPayBaseResult {
 
   /**
    * 
-   * 字段名:生效开始时间
+   * 字段名:生效开始时间.
    * 变量名:begin_time
    * 是否必填:是
    * 示例值:1943787483
@@ -158,7 +164,7 @@ public class WxPayCouponInfoQueryResult extends WxPayBaseResult {
 
   /**
    * 
-   * 字段名:生效结束时间
+   * 字段名:生效结束时间.
    * 变量名:end_time
    * 是否必填:是
    * 示例值:1943787484
@@ -171,7 +177,7 @@ public class WxPayCouponInfoQueryResult extends WxPayBaseResult {
 
   /**
    * 
-   * 字段名:发放时间
+   * 字段名:发放时间.
    * 变量名:send_time
    * 是否必填:是
    * 示例值:1943787420
@@ -184,7 +190,7 @@ public class WxPayCouponInfoQueryResult extends WxPayBaseResult {
 
   /**
    * 
-   * 字段名:消耗方商户id
+   * 字段名:消耗方商户id.
    * 变量名:consumer_mch_id
    * 是否必填:否
    * 示例值:10000098
@@ -197,7 +203,7 @@ public class WxPayCouponInfoQueryResult extends WxPayBaseResult {
 
   /**
    * 
-   * 字段名:发放来源
+   * 字段名:发放来源.
    * 变量名:send_source
    * 是否必填:是
    * 示例值:FULL_SEND
@@ -210,7 +216,7 @@ public class WxPayCouponInfoQueryResult extends WxPayBaseResult {
 
   /**
    * 
-   * 字段名:是否允许部分使用
+   * 字段名:是否允许部分使用.
    * 变量名:is_partial_use
    * 是否必填:否
    * 示例值:1
@@ -221,131 +227,4 @@ public class WxPayCouponInfoQueryResult extends WxPayBaseResult {
   @XStreamAlias("is_partial_use")
   private String isPartialUse;
 
-  public String getDeviceInfo() {
-    return this.deviceInfo;
-  }
-
-  public void setDeviceInfo(String deviceInfo) {
-    this.deviceInfo = deviceInfo;
-  }
-
-  public String getCouponStockId() {
-    return this.couponStockId;
-  }
-
-  public void setCouponStockId(String couponStockId) {
-    this.couponStockId = couponStockId;
-  }
-
-  public String getCouponId() {
-    return this.couponId;
-  }
-
-  public void setCouponId(String couponId) {
-    this.couponId = couponId;
-  }
-
-  public Integer getCouponValue() {
-    return this.couponValue;
-  }
-
-  public void setCouponValue(Integer couponValue) {
-    this.couponValue = couponValue;
-  }
-
-  public Integer getCouponMininum() {
-    return this.couponMininum;
-  }
-
-  public void setCouponMininum(Integer couponMininum) {
-    this.couponMininum = couponMininum;
-  }
-
-  public String getCouponName() {
-    return this.couponName;
-  }
-
-  public void setCouponName(String couponName) {
-    this.couponName = couponName;
-  }
-
-  public Integer getCouponState() {
-    return this.couponState;
-  }
-
-  public void setCouponState(Integer couponState) {
-    this.couponState = couponState;
-  }
-
-  public String getCouponDesc() {
-    return this.couponDesc;
-  }
-
-  public void setCouponDesc(String couponDesc) {
-    this.couponDesc = couponDesc;
-  }
-
-  public Integer getCouponUseValue() {
-    return this.couponUseValue;
-  }
-
-  public void setCouponUseValue(Integer couponUseValue) {
-    this.couponUseValue = couponUseValue;
-  }
-
-  public Integer getCouponRemainValue() {
-    return this.couponRemainValue;
-  }
-
-  public void setCouponRemainValue(Integer couponRemainValue) {
-    this.couponRemainValue = couponRemainValue;
-  }
-
-  public String getBeginTime() {
-    return this.beginTime;
-  }
-
-  public void setBeginTime(String beginTime) {
-    this.beginTime = beginTime;
-  }
-
-  public String getEndTime() {
-    return this.endTime;
-  }
-
-  public void setEndTime(String endTime) {
-    this.endTime = endTime;
-  }
-
-  public String getSendTime() {
-    return this.sendTime;
-  }
-
-  public void setSendTime(String sendTime) {
-    this.sendTime = sendTime;
-  }
-
-  public String getConsumerMchId() {
-    return this.consumerMchId;
-  }
-
-  public void setConsumerMchId(String consumerMchId) {
-    this.consumerMchId = consumerMchId;
-  }
-
-  public String getSendSource() {
-    return this.sendSource;
-  }
-
-  public void setSendSource(String sendSource) {
-    this.sendSource = sendSource;
-  }
-
-  public String getIsPartialUse() {
-    return this.isPartialUse;
-  }
-
-  public void setIsPartialUse(String isPartialUse) {
-    this.isPartialUse = isPartialUse;
-  }
 }
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponSendRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponSendRequest.java
index 9a98fd64a2..63b891d8bc 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponSendRequest.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponSendRequest.java
@@ -2,6 +2,7 @@
 
 import com.github.binarywang.wxpay.bean.request.WxPayBaseRequest;
 import com.thoughtworks.xstream.annotations.XStreamAlias;
+import lombok.*;
 import me.chanjar.weixin.common.annotation.Required;
 
 /**
@@ -12,6 +13,12 @@
  *
  * @author Binary Wang
  */
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+@Builder(builderMethodName = "newBuilder")
+@NoArgsConstructor
+@AllArgsConstructor
 @XStreamAlias("xml")
 public class WxPayCouponSendRequest extends WxPayBaseRequest {
   /**
@@ -122,190 +129,8 @@ public class WxPayCouponSendRequest extends WxPayBaseRequest {
   @XStreamAlias("type")
   private String type;
 
-  public WxPayCouponSendRequest() {
-  }
-
-  private WxPayCouponSendRequest(Builder builder) {
-    setAppid(builder.appid);
-    setMchId(builder.mchId);
-    setSubAppId(builder.subAppId);
-    setSubMchId(builder.subMchId);
-    setNonceStr(builder.nonceStr);
-    setSign(builder.sign);
-    setCouponStockId(builder.couponStockId);
-    setOpenidCount(builder.openidCount);
-    setPartnerTradeNo(builder.partnerTradeNo);
-    setOpenid(builder.openid);
-    setOpUserId(builder.opUserId);
-    setDeviceInfo(builder.deviceInfo);
-    setVersion(builder.version);
-    setType(builder.type);
-  }
-
-  public static Builder newBuilder() {
-    return new Builder();
-  }
-
-  public String getCouponStockId() {
-    return this.couponStockId;
-  }
-
-  public void setCouponStockId(String couponStockId) {
-    this.couponStockId = couponStockId;
-  }
-
-  public Integer getOpenidCount() {
-    return this.openidCount;
-  }
-
-  public void setOpenidCount(Integer openidCount) {
-    this.openidCount = openidCount;
-  }
-
-  public String getPartnerTradeNo() {
-    return this.partnerTradeNo;
-  }
-
-  public void setPartnerTradeNo(String partnerTradeNo) {
-    this.partnerTradeNo = partnerTradeNo;
-  }
-
-  public String getOpenid() {
-    return this.openid;
-  }
-
-  public void setOpenid(String openid) {
-    this.openid = openid;
-  }
-
-  public String getOpUserId() {
-    return this.opUserId;
-  }
-
-  public void setOpUserId(String opUserId) {
-    this.opUserId = opUserId;
-  }
-
-  public String getDeviceInfo() {
-    return this.deviceInfo;
-  }
-
-  public void setDeviceInfo(String deviceInfo) {
-    this.deviceInfo = deviceInfo;
-  }
-
-  public String getVersion() {
-    return this.version;
-  }
-
-  public void setVersion(String version) {
-    this.version = version;
-  }
-
-  public String getType() {
-    return this.type;
-  }
-
-  public void setType(String type) {
-    this.type = type;
-  }
-
   @Override
   protected void checkConstraints() {
     //do nothing
   }
-
-  public static final class Builder {
-    private String appid;
-    private String mchId;
-    private String subAppId;
-    private String subMchId;
-    private String nonceStr;
-    private String sign;
-    private String couponStockId;
-    private Integer openidCount;
-    private String partnerTradeNo;
-    private String openid;
-    private String opUserId;
-    private String deviceInfo;
-    private String version;
-    private String type;
-
-    private Builder() {
-    }
-
-    public Builder appid(String appid) {
-      this.appid = appid;
-      return this;
-    }
-
-    public Builder mchId(String mchId) {
-      this.mchId = mchId;
-      return this;
-    }
-
-    public Builder subAppId(String subAppId) {
-      this.subAppId = subAppId;
-      return this;
-    }
-
-    public Builder subMchId(String subMchId) {
-      this.subMchId = subMchId;
-      return this;
-    }
-
-    public Builder nonceStr(String nonceStr) {
-      this.nonceStr = nonceStr;
-      return this;
-    }
-
-    public Builder sign(String sign) {
-      this.sign = sign;
-      return this;
-    }
-
-    public Builder couponStockId(String couponStockId) {
-      this.couponStockId = couponStockId;
-      return this;
-    }
-
-    public Builder openidCount(Integer openidCount) {
-      this.openidCount = openidCount;
-      return this;
-    }
-
-    public Builder partnerTradeNo(String partnerTradeNo) {
-      this.partnerTradeNo = partnerTradeNo;
-      return this;
-    }
-
-    public Builder openid(String openid) {
-      this.openid = openid;
-      return this;
-    }
-
-    public Builder opUserId(String opUserId) {
-      this.opUserId = opUserId;
-      return this;
-    }
-
-    public Builder deviceInfo(String deviceInfo) {
-      this.deviceInfo = deviceInfo;
-      return this;
-    }
-
-    public Builder version(String version) {
-      this.version = version;
-      return this;
-    }
-
-    public Builder type(String type) {
-      this.type = type;
-      return this;
-    }
-
-    public WxPayCouponSendRequest build() {
-      return new WxPayCouponSendRequest(this);
-    }
-  }
 }
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponSendResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponSendResult.java
index 1c562adae2..fe26342e7b 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponSendResult.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponSendResult.java
@@ -2,6 +2,9 @@
 
 import com.github.binarywang.wxpay.bean.result.WxPayBaseResult;
 import com.thoughtworks.xstream.annotations.XStreamAlias;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
 
 /**
  * 
@@ -11,6 +14,9 @@
  *
  * @author Binary Wang
  */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@NoArgsConstructor
 @XStreamAlias("xml")
 public class WxPayCouponSendResult extends WxPayBaseResult {
   /**
@@ -130,75 +136,4 @@ public class WxPayCouponSendResult extends WxPayBaseResult {
   @XStreamAlias("ret_msg")
   private String retMsg;
 
-  public String getDeviceInfo() {
-    return this.deviceInfo;
-  }
-
-  public void setDeviceInfo(String deviceInfo) {
-    this.deviceInfo = deviceInfo;
-  }
-
-  public String getCouponStockId() {
-    return this.couponStockId;
-  }
-
-  public void setCouponStockId(String couponStockId) {
-    this.couponStockId = couponStockId;
-  }
-
-  public Integer getRespCount() {
-    return this.respCount;
-  }
-
-  public void setRespCount(Integer respCount) {
-    this.respCount = respCount;
-  }
-
-  public Integer getSuccessCount() {
-    return this.successCount;
-  }
-
-  public void setSuccessCount(Integer successCount) {
-    this.successCount = successCount;
-  }
-
-  public Integer getFailedCount() {
-    return this.failedCount;
-  }
-
-  public void setFailedCount(Integer failedCount) {
-    this.failedCount = failedCount;
-  }
-
-  public String getOpenid() {
-    return this.openid;
-  }
-
-  public void setOpenid(String openid) {
-    this.openid = openid;
-  }
-
-  public String getRetCode() {
-    return this.retCode;
-  }
-
-  public void setRetCode(String retCode) {
-    this.retCode = retCode;
-  }
-
-  public String getCouponId() {
-    return this.couponId;
-  }
-
-  public void setCouponId(String couponId) {
-    this.couponId = couponId;
-  }
-
-  public String getRetMsg() {
-    return this.retMsg;
-  }
-
-  public void setRetMsg(String retMsg) {
-    this.retMsg = retMsg;
-  }
 }
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponStockQueryRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponStockQueryRequest.java
index 24cec5523c..c7b812d857 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponStockQueryRequest.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponStockQueryRequest.java
@@ -2,6 +2,7 @@
 
 import com.github.binarywang.wxpay.bean.request.WxPayBaseRequest;
 import com.thoughtworks.xstream.annotations.XStreamAlias;
+import lombok.*;
 import me.chanjar.weixin.common.annotation.Required;
 
 /**
@@ -12,6 +13,12 @@
  *
  * @author Binary Wang
  */
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+@Builder(builderMethodName = "newBuilder")
+@NoArgsConstructor
+@AllArgsConstructor
 @XStreamAlias("xml")
 public class WxPayCouponStockQueryRequest extends WxPayBaseRequest {
   /**
@@ -80,142 +87,9 @@ public class WxPayCouponStockQueryRequest extends WxPayBaseRequest {
   @XStreamAlias("type")
   private String type;
 
-  private WxPayCouponStockQueryRequest(Builder builder) {
-    setAppid(builder.appid);
-    setMchId(builder.mchId);
-    setSubAppId(builder.subAppId);
-    setSubMchId(builder.subMchId);
-    setNonceStr(builder.nonceStr);
-    setSign(builder.sign);
-    setCouponStockId(builder.couponStockId);
-    setOpUserId(builder.opUserId);
-    setDeviceInfo(builder.deviceInfo);
-    setVersion(builder.version);
-    setType(builder.type);
-  }
-
-  public static Builder newBuilder() {
-    return new Builder();
-  }
-
-  public String getCouponStockId() {
-    return this.couponStockId;
-  }
-
-  public void setCouponStockId(String couponStockId) {
-    this.couponStockId = couponStockId;
-  }
-
-  public String getOpUserId() {
-    return this.opUserId;
-  }
-
-  public void setOpUserId(String opUserId) {
-    this.opUserId = opUserId;
-  }
-
-  public String getDeviceInfo() {
-    return this.deviceInfo;
-  }
-
-  public void setDeviceInfo(String deviceInfo) {
-    this.deviceInfo = deviceInfo;
-  }
-
-  public String getVersion() {
-    return this.version;
-  }
-
-  public void setVersion(String version) {
-    this.version = version;
-  }
-
-  public String getType() {
-    return this.type;
-  }
-
-  public void setType(String type) {
-    this.type = type;
-  }
-
   @Override
   protected void checkConstraints() {
     //do nothing
   }
 
-  public static final class Builder {
-    private String appid;
-    private String mchId;
-    private String subAppId;
-    private String subMchId;
-    private String nonceStr;
-    private String sign;
-    private String couponStockId;
-    private String opUserId;
-    private String deviceInfo;
-    private String version;
-    private String type;
-
-    private Builder() {
-    }
-
-    public Builder appid(String appid) {
-      this.appid = appid;
-      return this;
-    }
-
-    public Builder mchId(String mchId) {
-      this.mchId = mchId;
-      return this;
-    }
-
-    public Builder subAppId(String subAppId) {
-      this.subAppId = subAppId;
-      return this;
-    }
-
-    public Builder subMchId(String subMchId) {
-      this.subMchId = subMchId;
-      return this;
-    }
-
-    public Builder nonceStr(String nonceStr) {
-      this.nonceStr = nonceStr;
-      return this;
-    }
-
-    public Builder sign(String sign) {
-      this.sign = sign;
-      return this;
-    }
-
-    public Builder couponStockId(String couponStockId) {
-      this.couponStockId = couponStockId;
-      return this;
-    }
-
-    public Builder opUserId(String opUserId) {
-      this.opUserId = opUserId;
-      return this;
-    }
-
-    public Builder deviceInfo(String deviceInfo) {
-      this.deviceInfo = deviceInfo;
-      return this;
-    }
-
-    public Builder version(String version) {
-      this.version = version;
-      return this;
-    }
-
-    public Builder type(String type) {
-      this.type = type;
-      return this;
-    }
-
-    public WxPayCouponStockQueryRequest build() {
-      return new WxPayCouponStockQueryRequest(this);
-    }
-  }
 }
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponStockQueryResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponStockQueryResult.java
index 065c3f606d..2f97618e1d 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponStockQueryResult.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/coupon/WxPayCouponStockQueryResult.java
@@ -2,6 +2,10 @@
 
 import com.github.binarywang.wxpay.bean.result.WxPayBaseResult;
 import com.thoughtworks.xstream.annotations.XStreamAlias;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
 
 /**
  * 
@@ -11,6 +15,10 @@
  *
  * @author Binary Wang
  */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@NoArgsConstructor
+@AllArgsConstructor
 @XStreamAlias("xml")
 public class WxPayCouponStockQueryResult extends WxPayBaseResult {
   /**
@@ -182,107 +190,4 @@ public class WxPayCouponStockQueryResult extends WxPayBaseResult {
   @XStreamAlias("coupon_budget")
   private Integer couponBudget;
 
-  public String getDeviceInfo() {
-    return this.deviceInfo;
-  }
-
-  public void setDeviceInfo(String deviceInfo) {
-    this.deviceInfo = deviceInfo;
-  }
-
-  public String getCouponStockId() {
-    return this.couponStockId;
-  }
-
-  public void setCouponStockId(String couponStockId) {
-    this.couponStockId = couponStockId;
-  }
-
-  public String getCouponName() {
-    return this.couponName;
-  }
-
-  public void setCouponName(String couponName) {
-    this.couponName = couponName;
-  }
-
-  public Integer getCouponValue() {
-    return this.couponValue;
-  }
-
-  public void setCouponValue(Integer couponValue) {
-    this.couponValue = couponValue;
-  }
-
-  public Integer getCouponMininumn() {
-    return this.couponMininumn;
-  }
-
-  public void setCouponMininumn(Integer couponMininumn) {
-    this.couponMininumn = couponMininumn;
-  }
-
-  public Integer getCouponStockStatus() {
-    return this.couponStockStatus;
-  }
-
-  public void setCouponStockStatus(Integer couponStockStatus) {
-    this.couponStockStatus = couponStockStatus;
-  }
-
-  public Integer getCouponTotal() {
-    return this.couponTotal;
-  }
-
-  public void setCouponTotal(Integer couponTotal) {
-    this.couponTotal = couponTotal;
-  }
-
-  public Integer getMaxQuota() {
-    return this.maxQuota;
-  }
-
-  public void setMaxQuota(Integer maxQuota) {
-    this.maxQuota = maxQuota;
-  }
-
-  public Integer getIsSendNum() {
-    return this.isSendNum;
-  }
-
-  public void setIsSendNum(Integer isSendNum) {
-    this.isSendNum = isSendNum;
-  }
-
-  public String getBeginTime() {
-    return this.beginTime;
-  }
-
-  public void setBeginTime(String beginTime) {
-    this.beginTime = beginTime;
-  }
-
-  public String getEndTime() {
-    return this.endTime;
-  }
-
-  public void setEndTime(String endTime) {
-    this.endTime = endTime;
-  }
-
-  public String getCreateTime() {
-    return this.createTime;
-  }
-
-  public void setCreateTime(String createTime) {
-    this.createTime = createTime;
-  }
-
-  public Integer getCouponBudget() {
-    return this.couponBudget;
-  }
-
-  public void setCouponBudget(Integer couponBudget) {
-    this.couponBudget = couponBudget;
-  }
 }
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayNotifyResponse.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayNotifyResponse.java
index e7a7ea9099..c7adf850af 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayNotifyResponse.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayNotifyResponse.java
@@ -4,12 +4,20 @@
 import com.thoughtworks.xstream.annotations.XStreamAlias;
 import com.thoughtworks.xstream.annotations.XStreamConverter;
 import com.thoughtworks.xstream.annotations.XStreamOmitField;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
 import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
 import me.chanjar.weixin.common.util.xml.XStreamInitializer;
 
 /**
  * 微信支付订单和退款的异步通知共用的响应类
  */
+@Data
+@Builder(builderMethodName = "newBuilder")
+@NoArgsConstructor
+@AllArgsConstructor
 @XStreamAlias("xml")
 public class WxPayNotifyResponse {
   @XStreamOmitField
@@ -24,16 +32,6 @@ public class WxPayNotifyResponse {
   @XStreamAlias("return_msg")
   private String returnMsg;
 
-  public WxPayNotifyResponse() {
-    super();
-  }
-
-  public WxPayNotifyResponse(String returnCode, String returnMsg) {
-    super();
-    this.returnCode = returnCode;
-    this.returnMsg = returnMsg;
-  }
-
   public static String fail(String msg) {
     WxPayNotifyResponse response = new WxPayNotifyResponse(FAIL, msg);
     XStream xstream = XStreamInitializer.getInstance();
@@ -48,19 +46,4 @@ public static String success(String msg) {
     return xstream.toXML(response);
   }
 
-  public String getReturnCode() {
-    return returnCode;
-  }
-
-  public void setReturnCode(String returnCode) {
-    this.returnCode = returnCode;
-  }
-
-  public String getReturnMsg() {
-    return returnMsg;
-  }
-
-  public void setReturnMsg(String returnMsg) {
-    this.returnMsg = returnMsg;
-  }
 }
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayOrderNotifyCoupon.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayOrderNotifyCoupon.java
index cd948dfbac..80da09e6f9 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayOrderNotifyCoupon.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayOrderNotifyCoupon.java
@@ -1,7 +1,8 @@
 package com.github.binarywang.wxpay.bean.notify;
 
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import me.chanjar.weixin.common.util.ToStringUtils;
 
 import java.io.Serializable;
 import java.util.HashMap;
@@ -10,6 +11,8 @@
 /**
  * 支付异步通知代金券详细
  */
+@Data
+@NoArgsConstructor
 public class WxPayOrderNotifyCoupon implements Serializable {
   private static final long serialVersionUID = -4165343733538156097L;
 
@@ -17,30 +20,6 @@ public class WxPayOrderNotifyCoupon implements Serializable {
   private String couponType;
   private Integer couponFee;
 
-  public String getCouponId() {
-    return couponId;
-  }
-
-  public void setCouponId(String couponId) {
-    this.couponId = couponId;
-  }
-
-  public String getCouponType() {
-    return couponType;
-  }
-
-  public void setCouponType(String couponType) {
-    this.couponType = couponType;
-  }
-
-  public Integer getCouponFee() {
-    return couponFee;
-  }
-
-  public void setCouponFee(Integer couponFee) {
-    this.couponFee = couponFee;
-  }
-
   public Map toMap(int index) {
     Map map = new HashMap<>();
     map.put("coupon_id_" + index, this.getCouponId());
@@ -51,6 +30,6 @@ public Map toMap(int index) {
 
   @Override
   public String toString() {
-    return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
+    return ToStringUtils.toSimpleString(this);
   }
 }
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayOrderNotifyResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayOrderNotifyResult.java
index 54657ac6ae..8cb94ee03e 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayOrderNotifyResult.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayOrderNotifyResult.java
@@ -4,6 +4,9 @@
 import com.github.binarywang.wxpay.converter.WxPayOrderNotifyResultConverter;
 import com.thoughtworks.xstream.XStream;
 import com.thoughtworks.xstream.annotations.XStreamAlias;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
 import me.chanjar.weixin.common.util.BeanUtils;
 import me.chanjar.weixin.common.util.ToStringUtils;
 import me.chanjar.weixin.common.util.xml.XStreamInitializer;
@@ -18,6 +21,9 @@
  * @author aimilin6688
  * @since 2.5.0
  */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@NoArgsConstructor
 @XStreamAlias("xml")
 public class WxPayOrderNotifyResult extends WxPayBaseResult implements Serializable {
   private static final long serialVersionUID = 5389718115223345496L;
@@ -262,158 +268,6 @@ public static WxPayOrderNotifyResult fromXML(String xmlString) {
     return result;
   }
 
-  public Integer getCouponCount() {
-    return couponCount;
-  }
-
-  public void setCouponCount(Integer couponCount) {
-    this.couponCount = couponCount;
-  }
-
-  public List getCouponList() {
-    return couponList;
-  }
-
-  public void setCouponList(List couponList) {
-    this.couponList = couponList;
-  }
-
-  public String getDeviceInfo() {
-    return deviceInfo;
-  }
-
-  public void setDeviceInfo(String deviceInfo) {
-    this.deviceInfo = deviceInfo;
-  }
-
-  public String getOpenid() {
-    return openid;
-  }
-
-  public void setOpenid(String openid) {
-    this.openid = openid;
-  }
-
-  public String getIsSubscribe() {
-    return isSubscribe;
-  }
-
-  public void setIsSubscribe(String isSubscribe) {
-    this.isSubscribe = isSubscribe;
-  }
-
-  public String getTradeType() {
-    return tradeType;
-  }
-
-  public void setTradeType(String tradeType) {
-    this.tradeType = tradeType;
-  }
-
-  public String getBankType() {
-    return bankType;
-  }
-
-  public void setBankType(String bankType) {
-    this.bankType = bankType;
-  }
-
-  public Integer getTotalFee() {
-    return totalFee;
-  }
-
-  public void setTotalFee(Integer totalFee) {
-    this.totalFee = totalFee;
-  }
-
-  public Integer getSettlementTotalFee() {
-    return settlementTotalFee;
-  }
-
-  public void setSettlementTotalFee(Integer settlementTotalFee) {
-    this.settlementTotalFee = settlementTotalFee;
-  }
-
-  public String getFeeType() {
-    return feeType;
-  }
-
-  public void setFeeType(String feeType) {
-    this.feeType = feeType;
-  }
-
-  public Integer getCashFee() {
-    return cashFee;
-  }
-
-  public void setCashFee(Integer cashFee) {
-    this.cashFee = cashFee;
-  }
-
-  public String getCashFeeType() {
-    return cashFeeType;
-  }
-
-  public void setCashFeeType(String cashFeeType) {
-    this.cashFeeType = cashFeeType;
-  }
-
-  public Integer getCouponFee() {
-    return couponFee;
-  }
-
-  public void setCouponFee(Integer couponFee) {
-    this.couponFee = couponFee;
-  }
-
-  public String getTransactionId() {
-    return transactionId;
-  }
-
-  public void setTransactionId(String transactionId) {
-    this.transactionId = transactionId;
-  }
-
-  public String getOutTradeNo() {
-    return outTradeNo;
-  }
-
-  public void setOutTradeNo(String outTradeNo) {
-    this.outTradeNo = outTradeNo;
-  }
-
-  public String getAttach() {
-    return attach;
-  }
-
-  public void setAttach(String attach) {
-    this.attach = attach;
-  }
-
-  public String getTimeEnd() {
-    return timeEnd;
-  }
-
-  public void setTimeEnd(String timeEnd) {
-    this.timeEnd = timeEnd;
-  }
-
-  public String getSubOpenid() {
-    return this.subOpenid;
-  }
-
-  public void setSubOpenid(String subOpenid) {
-    this.subOpenid = subOpenid;
-  }
-
-  public String getSubIsSubscribe() {
-    return this.subIsSubscribe;
-  }
-
-  public void setSubIsSubscribe(String subIsSubscribe) {
-    this.subIsSubscribe = subIsSubscribe;
-  }
-
   @Override
   public Map toMap() {
     Map resultMap = BeanUtils.xmlBean2Map(this);
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayRefundNotifyResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayRefundNotifyResult.java
index 392c10144c..7006c75215 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayRefundNotifyResult.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayRefundNotifyResult.java
@@ -4,6 +4,10 @@
 import com.github.binarywang.wxpay.exception.WxPayException;
 import com.thoughtworks.xstream.XStream;
 import com.thoughtworks.xstream.annotations.XStreamAlias;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
 import me.chanjar.weixin.common.util.ToStringUtils;
 import me.chanjar.weixin.common.util.xml.XStreamInitializer;
 import org.apache.commons.codec.binary.Base64;
@@ -22,6 +26,10 @@
  *
  * @author Binary Wang
  */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@NoArgsConstructor
+@AllArgsConstructor
 @XStreamAlias("xml")
 public class WxPayRefundNotifyResult extends WxPayBaseResult implements Serializable {
   private static final long serialVersionUID = 4651725860079259186L;
@@ -68,6 +76,8 @@ public static WxPayRefundNotifyResult fromXML(String xmlString, String mchKey) t
   /**
    * 加密信息字段解密后的内容
    */
+  @Data
+  @NoArgsConstructor
   @XStreamAlias("root")
   public static class ReqInfo {
     @Override
@@ -243,110 +253,6 @@ public String toString() {
     @XStreamAlias("refund_request_source")
     private String refundRequestSource;
 
-    public String getTransactionId() {
-      return transactionId;
-    }
-
-    public void setTransactionId(String transactionId) {
-      this.transactionId = transactionId;
-    }
-
-    public String getOutTradeNo() {
-      return outTradeNo;
-    }
-
-    public void setOutTradeNo(String outTradeNo) {
-      this.outTradeNo = outTradeNo;
-    }
-
-    public String getRefundId() {
-      return refundId;
-    }
-
-    public void setRefundId(String refundId) {
-      this.refundId = refundId;
-    }
-
-    public String getOutRefundNo() {
-      return outRefundNo;
-    }
-
-    public void setOutRefundNo(String outRefundNo) {
-      this.outRefundNo = outRefundNo;
-    }
-
-    public Integer getTotalFee() {
-      return totalFee;
-    }
-
-    public void setTotalFee(Integer totalFee) {
-      this.totalFee = totalFee;
-    }
-
-    public Integer getSettlementTotalFee() {
-      return settlementTotalFee;
-    }
-
-    public void setSettlementTotalFee(Integer settlementTotalFee) {
-      this.settlementTotalFee = settlementTotalFee;
-    }
-
-    public Integer getRefundFee() {
-      return refundFee;
-    }
-
-    public void setRefundFee(Integer refundFee) {
-      this.refundFee = refundFee;
-    }
-
-    public Integer getSettlementRefundFee() {
-      return settlementRefundFee;
-    }
-
-    public void setSettlementRefundFee(Integer settlementRefundFee) {
-      this.settlementRefundFee = settlementRefundFee;
-    }
-
-    public String getRefundStatus() {
-      return refundStatus;
-    }
-
-    public void setRefundStatus(String refundStatus) {
-      this.refundStatus = refundStatus;
-    }
-
-    public String getSuccessTime() {
-      return successTime;
-    }
-
-    public void setSuccessTime(String successTime) {
-      this.successTime = successTime;
-    }
-
-    public String getRefundRecvAccout() {
-      return refundRecvAccout;
-    }
-
-    public void setRefundRecvAccout(String refundRecvAccout) {
-      this.refundRecvAccout = refundRecvAccout;
-    }
-
-    public String getRefundAccount() {
-      return refundAccount;
-    }
-
-    public void setRefundAccount(String refundAccount) {
-      this.refundAccount = refundAccount;
-    }
-
-    public String getRefundRequestSource() {
-      return refundRequestSource;
-    }
-
-    public void setRefundRequestSource(String refundRequestSource) {
-      this.refundRequestSource = refundRequestSource;
-    }
-
     public static ReqInfo fromXML(String xmlString) {
       XStream xstream = XStreamInitializer.getInstance();
       xstream.processAnnotations(ReqInfo.class);
@@ -354,19 +260,4 @@ public static ReqInfo fromXML(String xmlString) {
     }
   }
 
-  public String getReqInfoString() {
-    return reqInfoString;
-  }
-
-  public void setReqInfoString(String reqInfoString) {
-    this.reqInfoString = reqInfoString;
-  }
-
-  public ReqInfo getReqInfo() {
-    return reqInfo;
-  }
-
-  public void setReqInfo(ReqInfo reqInfo) {
-    this.reqInfo = reqInfo;
-  }
 }
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxScanPayNotifyResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxScanPayNotifyResult.java
similarity index 56%
rename from weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxScanPayNotifyResult.java
rename to weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxScanPayNotifyResult.java
index cdb94a9b79..6d08136d99 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxScanPayNotifyResult.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxScanPayNotifyResult.java
@@ -1,9 +1,16 @@
-package com.github.binarywang.wxpay.bean.result;
+package com.github.binarywang.wxpay.bean.notify;
 
+import com.github.binarywang.wxpay.bean.result.WxPayBaseResult;
 import com.thoughtworks.xstream.annotations.XStreamAlias;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
 
 import java.io.Serializable;
 
+@Data
+@EqualsAndHashCode(callSuper = true)
+@NoArgsConstructor
 public class WxScanPayNotifyResult extends WxPayBaseResult implements Serializable {
   private static final long serialVersionUID = 3381324564266118986L;
 
@@ -13,12 +20,4 @@ public class WxScanPayNotifyResult extends WxPayBaseResult implements Serializab
   @XStreamAlias("prepay_id")
   private String prepayId;
 
-  public String getPrepayId() {
-    return prepayId;
-  }
-
-  public void setPrepayId(String prepayId) {
-    this.prepayId = prepayId;
-  }
-
 }
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/order/WxPayAppOrderResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/order/WxPayAppOrderResult.java
index 6688d602c9..9e405aa0f9 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/order/WxPayAppOrderResult.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/order/WxPayAppOrderResult.java
@@ -1,5 +1,8 @@
 package com.github.binarywang.wxpay.bean.order;
 
+import lombok.Builder;
+import lombok.Data;
+
 /**
  * 
  * APP支付调用统一下单接口后的组装所需参数的实现类
@@ -9,6 +12,8 @@
  *
  * @author Binary Wang
  */
+@Data
+@Builder
 public class WxPayAppOrderResult {
   private String sign;
   private String prepayId;
@@ -17,129 +22,4 @@ public class WxPayAppOrderResult {
   private String packageValue;
   private String timeStamp;
   private String nonceStr;
-
-  public WxPayAppOrderResult() {
-  }
-
-  private WxPayAppOrderResult(Builder builder) {
-    setSign(builder.sign);
-    setPrepayId(builder.prepayId);
-    setPartnerId(builder.partnerId);
-    setAppId(builder.appId);
-    setPackageValue(builder.packageValue);
-    setTimeStamp(builder.timeStamp);
-    setNonceStr(builder.nonceStr);
-  }
-
-  public static Builder newBuilder() {
-    return new Builder();
-  }
-
-  public String getSign() {
-    return this.sign;
-  }
-
-  public void setSign(String sign) {
-    this.sign = sign;
-  }
-
-  public String getPrepayId() {
-    return this.prepayId;
-  }
-
-  public void setPrepayId(String prepayId) {
-    this.prepayId = prepayId;
-  }
-
-  public String getPartnerId() {
-    return this.partnerId;
-  }
-
-  public void setPartnerId(String partnerId) {
-    this.partnerId = partnerId;
-  }
-
-  public String getAppId() {
-    return this.appId;
-  }
-
-  public void setAppId(String appId) {
-    this.appId = appId;
-  }
-
-  public String getPackageValue() {
-    return this.packageValue;
-  }
-
-  public void setPackageValue(String packageValue) {
-    this.packageValue = packageValue;
-  }
-
-  public String getTimeStamp() {
-    return this.timeStamp;
-  }
-
-  public void setTimeStamp(String timeStamp) {
-    this.timeStamp = timeStamp;
-  }
-
-  public String getNonceStr() {
-    return this.nonceStr;
-  }
-
-  public void setNonceStr(String nonceStr) {
-    this.nonceStr = nonceStr;
-  }
-
-  public static final class Builder {
-    private String sign;
-    private String prepayId;
-    private String partnerId;
-    private String appId;
-    private String packageValue;
-    private String timeStamp;
-    private String nonceStr;
-
-    private Builder() {
-    }
-
-    public Builder sign(String sign) {
-      this.sign = sign;
-      return this;
-    }
-
-    public Builder prepayId(String prepayId) {
-      this.prepayId = prepayId;
-      return this;
-    }
-
-    public Builder partnerId(String partnerId) {
-      this.partnerId = partnerId;
-      return this;
-    }
-
-    public Builder appId(String appId) {
-      this.appId = appId;
-      return this;
-    }
-
-    public Builder packageValue(String packageValue) {
-      this.packageValue = packageValue;
-      return this;
-    }
-
-    public Builder timeStamp(String timeStamp) {
-      this.timeStamp = timeStamp;
-      return this;
-    }
-
-    public Builder nonceStr(String nonceStr) {
-      this.nonceStr = nonceStr;
-      return this;
-    }
-
-    public WxPayAppOrderResult build() {
-      return new WxPayAppOrderResult(this);
-    }
-  }
 }
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/order/WxPayMpOrderResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/order/WxPayMpOrderResult.java
index d1ebdee051..4fded06fdf 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/order/WxPayMpOrderResult.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/order/WxPayMpOrderResult.java
@@ -1,5 +1,9 @@
 package com.github.binarywang.wxpay.bean.order;
 
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import lombok.Builder;
+import lombok.Data;
+
 /**
  * 
  * 微信公众号支付进行统一下单后组装所需参数的类
@@ -9,6 +13,8 @@
  *
  * @author Binary Wang
  */
+@Data
+@Builder
 public class WxPayMpOrderResult {
   private String appId;
   private String timeStamp;
@@ -16,118 +22,8 @@ public class WxPayMpOrderResult {
   /**
    * 由于package为java保留关键字,因此改为packageValue
    */
+  @XStreamAlias("package")
   private String packageValue;
   private String signType;
   private String paySign;
-
-  private WxPayMpOrderResult(Builder builder) {
-    setAppId(builder.appId);
-    setTimeStamp(builder.timeStamp);
-    setNonceStr(builder.nonceStr);
-    setPackageValue(builder.packageValue);
-    setSignType(builder.signType);
-    setPaySign(builder.paySign);
-  }
-
-  public static Builder newBuilder() {
-    return new Builder();
-  }
-
-  public String getAppId() {
-    return this.appId;
-  }
-
-  public void setAppId(String appId) {
-    this.appId = appId;
-  }
-
-  public String getTimeStamp() {
-    return this.timeStamp;
-  }
-
-  public void setTimeStamp(String timeStamp) {
-    this.timeStamp = timeStamp;
-  }
-
-  public String getNonceStr() {
-    return this.nonceStr;
-  }
-
-  public void setNonceStr(String nonceStr) {
-    this.nonceStr = nonceStr;
-  }
-
-  public String getPackageValue() {
-    return this.packageValue;
-  }
-
-  public void setPackageValue(String packageValue) {
-    this.packageValue = packageValue;
-  }
-
-  public String getSignType() {
-    return this.signType;
-  }
-
-  public void setSignType(String signType) {
-    this.signType = signType;
-  }
-
-  public String getPaySign() {
-    return this.paySign;
-  }
-
-  public void setPaySign(String paySign) {
-    this.paySign = paySign;
-  }
-
-  public WxPayMpOrderResult() {
-  }
-
-
-  public static final class Builder {
-    private String appId;
-    private String timeStamp;
-    private String nonceStr;
-    private String packageValue;
-    private String signType;
-    private String paySign;
-
-    private Builder() {
-    }
-
-    public Builder appId(String appId) {
-      this.appId = appId;
-      return this;
-    }
-
-    public Builder timeStamp(String timeStamp) {
-      this.timeStamp = timeStamp;
-      return this;
-    }
-
-    public Builder nonceStr(String nonceStr) {
-      this.nonceStr = nonceStr;
-      return this;
-    }
-
-    public Builder packageValue(String packageValue) {
-      this.packageValue = packageValue;
-      return this;
-    }
-
-    public Builder signType(String signType) {
-      this.signType = signType;
-      return this;
-    }
-
-    public Builder paySign(String paySign) {
-      this.paySign = paySign;
-      return this;
-    }
-
-    public WxPayMpOrderResult build() {
-      return new WxPayMpOrderResult(this);
-    }
-  }
 }
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/order/WxPayNativeOrderResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/order/WxPayNativeOrderResult.java
index 3eb0e3748a..99788c2bc9 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/order/WxPayNativeOrderResult.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/order/WxPayNativeOrderResult.java
@@ -1,5 +1,8 @@
 package com.github.binarywang.wxpay.bean.order;
 
+import lombok.Builder;
+import lombok.Data;
+
 /**
  * 
  * 微信扫码支付统一下单后发起支付拼接所需参数实现类
@@ -8,41 +11,8 @@
  *
  * @author Binary Wang
  */
+@Data
+@Builder
 public class WxPayNativeOrderResult {
   private String codeUrl;
-
-  private WxPayNativeOrderResult(Builder builder) {
-    setCodeUrl(builder.codeUrl);
-  }
-
-  public static Builder newBuilder() {
-    return new Builder();
-  }
-
-  public String getCodeUrl() {
-    return this.codeUrl;
-  }
-
-  public void setCodeUrl(String codeUrl) {
-    this.codeUrl = codeUrl;
-  }
-
-  public WxPayNativeOrderResult() {
-  }
-
-  public static final class Builder {
-    private String codeUrl;
-
-    private Builder() {
-    }
-
-    public Builder codeUrl(String codeUrl) {
-      this.codeUrl = codeUrl;
-      return this;
-    }
-
-    public WxPayNativeOrderResult build() {
-      return new WxPayNativeOrderResult(this);
-    }
-  }
 }
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxEntPayQueryRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxEntPayQueryRequest.java
index f9135c34df..5d48bb4463 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxEntPayQueryRequest.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxEntPayQueryRequest.java
@@ -1,6 +1,7 @@
 package com.github.binarywang.wxpay.bean.request;
 
 import com.thoughtworks.xstream.annotations.XStreamAlias;
+import lombok.*;
 import me.chanjar.weixin.common.annotation.Required;
 import me.chanjar.weixin.common.util.ToStringUtils;
 
@@ -17,8 +18,13 @@
  * 
* Created by Binary Wang on 2016/10/19. * - * @author binarywang (https://github.com/binarywang) + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@Builder(builderMethodName = "newBuilder") +@NoArgsConstructor +@AllArgsConstructor @XStreamAlias("xml") public class WxEntPayQueryRequest extends WxPayBaseRequest { /** @@ -35,14 +41,6 @@ public class WxEntPayQueryRequest extends WxPayBaseRequest { @XStreamAlias("partner_trade_no") private String partnerTradeNo; - public String getPartnerTradeNo() { - return this.partnerTradeNo; - } - - public void setPartnerTradeNo(String partnerTradeNo) { - this.partnerTradeNo = partnerTradeNo; - } - @Override protected void checkConstraints() { //do nothing diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxEntPayRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxEntPayRequest.java index 7897ad02da..ac588aa55f 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxEntPayRequest.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxEntPayRequest.java @@ -1,6 +1,7 @@ package com.github.binarywang.wxpay.bean.request; import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.*; import me.chanjar.weixin.common.annotation.Required; import me.chanjar.weixin.common.util.ToStringUtils; @@ -10,8 +11,14 @@ *
* Created by Binary Wang on 2016/10/02. * - * @author binarywang (https://github.com/binarywang) + * @author Binary Wang */ + +@Data +@EqualsAndHashCode(callSuper = true) +@Builder(builderMethodName = "newBuilder") +@NoArgsConstructor +@AllArgsConstructor @XStreamAlias("xml") public class WxEntPayRequest extends WxPayBaseRequest { /** @@ -153,32 +160,6 @@ public class WxEntPayRequest extends WxPayBaseRequest { @XStreamAlias("spbill_create_ip") private String spbillCreateIp; - public WxEntPayRequest() { - } - - private WxEntPayRequest(Builder builder) { - setAppid(builder.appid); - setMchId(builder.mchId); - setSubAppId(builder.subAppId); - setSubMchId(builder.subMchId); - setNonceStr(builder.nonceStr); - setSign(builder.sign); - mchAppid = builder.mchAppid; - setMchId(builder.mchId); - setDeviceInfo(builder.deviceInfo); - setPartnerTradeNo(builder.partnerTradeNo); - setOpenid(builder.openid); - setCheckName(builder.checkName); - setReUserName(builder.reUserName); - setAmount(builder.amount); - setDescription(builder.description); - setSpbillCreateIp(builder.spbillCreateIp); - } - - public static Builder newBuilder() { - return new Builder(); - } - @Override protected void checkConstraints() { @@ -204,172 +185,9 @@ public void setMchId(String mchId) { this.mchId = mchId; } - public String getDeviceInfo() { - return this.deviceInfo; - } - - public void setDeviceInfo(String deviceInfo) { - this.deviceInfo = deviceInfo; - } - - public String getPartnerTradeNo() { - return this.partnerTradeNo; - } - - public void setPartnerTradeNo(String partnerTradeNo) { - this.partnerTradeNo = partnerTradeNo; - } - - public String getOpenid() { - return this.openid; - } - - public void setOpenid(String openid) { - this.openid = openid; - } - - public String getCheckName() { - return this.checkName; - } - - public void setCheckName(String checkName) { - this.checkName = checkName; - } - - public String getReUserName() { - return this.reUserName; - } - - public void setReUserName(String reUserName) { - this.reUserName = reUserName; - } - - public Integer getAmount() { - return this.amount; - } - - public void setAmount(Integer amount) { - this.amount = amount; - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getSpbillCreateIp() { - return this.spbillCreateIp; - } - - public void setSpbillCreateIp(String spbillCreateIp) { - this.spbillCreateIp = spbillCreateIp; - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); } - public static final class Builder { - private String appid; - private String mchId; - private String deviceInfo; - private String partnerTradeNo; - private String openid; - private String checkName; - private String reUserName; - private Integer amount; - private String description; - private String spbillCreateIp; - private String subAppId; - private String subMchId; - private String nonceStr; - private String sign; - private String mchAppid; - - private Builder() { - } - - public Builder appid(String appid) { - this.appid = appid; - return this; - } - - public Builder mchId(String mchId) { - this.mchId = mchId; - return this; - } - - public Builder deviceInfo(String deviceInfo) { - this.deviceInfo = deviceInfo; - return this; - } - - public Builder partnerTradeNo(String partnerTradeNo) { - this.partnerTradeNo = partnerTradeNo; - return this; - } - - public Builder openid(String openid) { - this.openid = openid; - return this; - } - - public Builder checkName(String checkName) { - this.checkName = checkName; - return this; - } - - public Builder reUserName(String reUserName) { - this.reUserName = reUserName; - return this; - } - - public Builder amount(Integer amount) { - this.amount = amount; - return this; - } - - public Builder description(String description) { - this.description = description; - return this; - } - - public Builder spbillCreateIp(String spbillCreateIp) { - this.spbillCreateIp = spbillCreateIp; - return this; - } - - public WxEntPayRequest build() { - return new WxEntPayRequest(this); - } - - public Builder subAppId(String subAppId) { - this.subAppId = subAppId; - return this; - } - - public Builder subMchId(String subMchId) { - this.subMchId = subMchId; - return this; - } - - public Builder nonceStr(String nonceStr) { - this.nonceStr = nonceStr; - return this; - } - - public Builder sign(String sign) { - this.sign = sign; - return this; - } - - public Builder mchAppid(String mchAppid) { - this.mchAppid = mchAppid; - return this; - } - } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayAuthcode2OpenidRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayAuthcode2OpenidRequest.java index 594fa4960d..1187bf8df5 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayAuthcode2OpenidRequest.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayAuthcode2OpenidRequest.java @@ -1,14 +1,21 @@ package com.github.binarywang.wxpay.bean.request; import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.*; /** *
  * 授权码查询openid接口请求对象类
  * Created by Binary Wang on 2017-3-27.
- * @author binarywang(Binary Wang)
  * 
+ * + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@Builder(builderMethodName = "newBuilder") +@NoArgsConstructor +@AllArgsConstructor @XStreamAlias("xml") public class WxPayAuthcode2OpenidRequest extends WxPayBaseRequest { @@ -24,21 +31,6 @@ public class WxPayAuthcode2OpenidRequest extends WxPayBaseRequest { @XStreamAlias("auth_code") private String authCode; - public WxPayAuthcode2OpenidRequest() { - } - - public WxPayAuthcode2OpenidRequest(String authCode) { - this.authCode = authCode; - } - - public String getAuthCode() { - return this.authCode; - } - - public void setAuthCode(String authCode) { - this.authCode = authCode; - } - @Override protected void checkConstraints() { // nothing to do diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayBaseRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayBaseRequest.java index 41a98d0ae4..7147adfec7 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayBaseRequest.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayBaseRequest.java @@ -5,6 +5,7 @@ import com.github.binarywang.wxpay.util.SignUtils; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.Data; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.BeanUtils; import me.chanjar.weixin.common.util.ToStringUtils; @@ -13,14 +14,17 @@ import java.math.BigDecimal; +import static com.github.binarywang.wxpay.constant.WxPayConstants.SignType.ALL_SIGN_TYPES; + /** *
  * Created by Binary Wang on 2016-10-24.
  *  微信支付请求对象共用的参数存放类
  * 
* - * @author binarywang(Binary Wang) + * @author Binary Wang */ +@Data public abstract class WxPayBaseRequest { /** *
@@ -120,7 +124,7 @@ public static Integer yuanToFee(String yuan) {
   /**
    * 检查请求参数内容,包括必填参数以及特殊约束
    */
-  protected void checkFields() throws WxPayException {
+  private void checkFields() throws WxPayException {
     //check required fields
     try {
       BeanUtils.checkRequiredFields(this);
@@ -137,10 +141,6 @@ protected void checkFields() throws WxPayException {
    */
   protected abstract void checkConstraints() throws WxPayException;
 
-  public String getAppid() {
-    return this.appid;
-  }
-
   /**
    * 如果配置中已经设置,可以不设置值
    *
@@ -150,10 +150,6 @@ public void setAppid(String appid) {
     this.appid = appid;
   }
 
-  public String getMchId() {
-    return this.mchId;
-  }
-
   /**
    * 如果配置中已经设置,可以不设置值
    *
@@ -163,10 +159,6 @@ public void setMchId(String mchId) {
     this.mchId = mchId;
   }
 
-  public String getNonceStr() {
-    return this.nonceStr;
-  }
-
   /**
    * 默认采用时间戳为随机字符串,可以不设置
    *
@@ -176,38 +168,6 @@ public void setNonceStr(String nonceStr) {
     this.nonceStr = nonceStr;
   }
 
-  public String getSign() {
-    return this.sign;
-  }
-
-  public void setSign(String sign) {
-    this.sign = sign;
-  }
-
-  public String getSubAppId() {
-    return subAppId;
-  }
-
-  public void setSubAppId(String subAppId) {
-    this.subAppId = subAppId;
-  }
-
-  public String getSubMchId() {
-    return subMchId;
-  }
-
-  public void setSubMchId(String subMchId) {
-    this.subMchId = subMchId;
-  }
-
-  public String getSignType() {
-    return signType;
-  }
-
-  public void setSignType(String signType) {
-    this.signType = signType;
-  }
-
   @Override
   public String toString() {
     return ToStringUtils.toSimpleString(this);
@@ -215,6 +175,9 @@ public String toString() {
 
   public String toXML() {
     XStream xstream = XStreamInitializer.getInstance();
+    //涉及到服务商模式的两个参数,在为空值时置为null,以免在请求时将空值传给微信服务器
+    this.setSubAppId(StringUtils.trimToNull(this.getSubAppId()));
+    this.setSubMchId(StringUtils.trimToNull(this.getSubMchId()));
     xstream.processAnnotations(this.getClass());
     return xstream.toXML(this);
   }
@@ -227,9 +190,10 @@ public String toXML() {
    * 3、生成签名,并设置进去
    * 
* - * @param config 支付配置对象,用于读取相应系统配置信息 + * @param config 支付配置对象,用于读取相应系统配置信息 + * @param isIgnoreSignType 签名时,是否忽略signType */ - public void checkAndSign(WxPayConfig config) throws WxPayException { + public void checkAndSign(WxPayConfig config, boolean isIgnoreSignType) throws WxPayException { this.checkFields(); if (StringUtils.isBlank(getAppid())) { @@ -248,11 +212,24 @@ public void checkAndSign(WxPayConfig config) throws WxPayException { this.setSubMchId(config.getSubMchId()); } + if (StringUtils.isBlank(getSignType())) { + if (config.getSignType() != null && !ALL_SIGN_TYPES.contains(config.getSignType())) { + throw new WxPayException("非法的signType配置:" + config.getSignType() + ",请检查配置!"); + } + this.setSignType(StringUtils.trimToNull(config.getSignType())); + } else { + if (!ALL_SIGN_TYPES.contains(this.getSignType())) { + throw new WxPayException("非法的sign_type参数:" + this.getSignType()); + } + } + if (StringUtils.isBlank(getNonceStr())) { this.setNonceStr(String.valueOf(System.currentTimeMillis())); } + //设置签名字段的值 - this.setSign(SignUtils.createSign(this, config.getMchKey(), this.signType)); + this.setSign(SignUtils.createSign(this, this.getSignType(), config.getMchKey(), + isIgnoreSignType)); } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayDownloadBillRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayDownloadBillRequest.java index 33e410cdd8..6dc7264b33 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayDownloadBillRequest.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayDownloadBillRequest.java @@ -3,6 +3,7 @@ import com.github.binarywang.wxpay.constant.WxPayConstants.BillType; import com.github.binarywang.wxpay.exception.WxPayException; import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.*; import me.chanjar.weixin.common.annotation.Required; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; @@ -13,9 +14,15 @@ *
  *   微信支付下载对账单请求参数类
  * Created by Binary Wang on 2017-01-11.
- * @author binarywang(Binary Wang)
  * 
+ * + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@Builder(builderMethodName = "newBuilder") +@NoArgsConstructor +@AllArgsConstructor @XStreamAlias("xml") public class WxPayDownloadBillRequest extends WxPayBaseRequest { private static final String[] BILL_TYPES = new String[]{BillType.ALL, BillType.SUCCESS, BillType.REFUND, BillType.RECHARGE_REFUND}; @@ -34,19 +41,6 @@ public class WxPayDownloadBillRequest extends WxPayBaseRequest { @XStreamAlias("device_info") private String deviceInfo; - /** - *
-   * 签名类型
-   * sign_type
-   * 否
-   * String(32)
-   * HMAC-SHA256
-   * 签名类型,目前支持HMAC-SHA256和MD5,默认为MD5
-   * 
- */ - @XStreamAlias("sign_type") - private String signType; - /** *
    * 账单类型
@@ -90,46 +84,6 @@ public class WxPayDownloadBillRequest extends WxPayBaseRequest {
   @XStreamAlias("tar_type")
   private String tarType;
 
-  public String getDeviceInfo() {
-    return deviceInfo;
-  }
-
-  public void setDeviceInfo(String deviceInfo) {
-    this.deviceInfo = deviceInfo;
-  }
-
-  public String getSignType() {
-    return signType;
-  }
-
-  public void setSignType(String signType) {
-    this.signType = signType;
-  }
-
-  public String getBillType() {
-    return billType;
-  }
-
-  public void setBillType(String billType) {
-    this.billType = billType;
-  }
-
-  public String getBillDate() {
-    return billDate;
-  }
-
-  public void setBillDate(String billDate) {
-    this.billDate = billDate;
-  }
-
-  public String getTarType() {
-    return tarType;
-  }
-
-  public void setTarType(String tarType) {
-    this.tarType = tarType;
-  }
-
   @Override
   protected void checkConstraints() throws WxPayException {
     if (StringUtils.isNotBlank(this.getTarType()) && !TAR_TYPE_GZIP.equals(this.getTarType())) {
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayMicropayRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayMicropayRequest.java
index a025337806..ed85fe76cf 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayMicropayRequest.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayMicropayRequest.java
@@ -1,29 +1,24 @@
 package com.github.binarywang.wxpay.bean.request;
 
 import com.thoughtworks.xstream.annotations.XStreamAlias;
+import lombok.*;
 import me.chanjar.weixin.common.annotation.Required;
 
 /**
  * 
  *  提交刷卡支付请求对象类
  * Created by Binary Wang on 2017-3-23.
- * @author binarywang(Binary Wang)
  * 
+ * + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@Builder(builderMethodName = "newBuilder") +@NoArgsConstructor +@AllArgsConstructor @XStreamAlias("xml") public class WxPayMicropayRequest extends WxPayBaseRequest { - /** - *
-   * 签名类型
-   * sign_type
-   * 否
-   * String(32)
-   * HMAC-SHA256
-   * 签名类型,目前支持HMAC-SHA256和MD5,默认为MD5
-   **/
-  @XStreamAlias("sign_type")
-  private String signType;
-
   /**
    * 
    * 商品描述
@@ -149,232 +144,9 @@ public class WxPayMicropayRequest extends WxPayBaseRequest {
   @XStreamAlias("auth_code")
   private String authCode;
 
-  private WxPayMicropayRequest(Builder builder) {
-    setSignType(builder.signType);
-    setBody(builder.body);
-    setAppid(builder.appid);
-    setDetail(builder.detail);
-    setMchId(builder.mchId);
-    setAttach(builder.attach);
-    setSubAppId(builder.subAppId);
-    setOutTradeNo(builder.outTradeNo);
-    setSubMchId(builder.subMchId);
-    setTotalFee(builder.totalFee);
-    setNonceStr(builder.nonceStr);
-    setFeeType(builder.feeType);
-    setSign(builder.sign);
-    setSpbillCreateIp(builder.spbillCreateIp);
-    setGoodsTag(builder.goodsTag);
-    setLimitPay(builder.limitPay);
-    setAuthCode(builder.authCode);
-  }
-
-  public static Builder newBuilder() {
-    return new Builder();
-  }
-
-  public String getSignType() {
-    return this.signType;
-  }
-
-  public void setSignType(String signType) {
-    this.signType = signType;
-  }
-
-  public String getBody() {
-    return this.body;
-  }
-
-  public void setBody(String body) {
-    this.body = body;
-  }
-
-  public String getDetail() {
-    return this.detail;
-  }
-
-  public void setDetail(String detail) {
-    this.detail = detail;
-  }
-
-  public String getAttach() {
-    return this.attach;
-  }
-
-  public void setAttach(String attach) {
-    this.attach = attach;
-  }
-
-  public String getOutTradeNo() {
-    return this.outTradeNo;
-  }
-
-  public void setOutTradeNo(String outTradeNo) {
-    this.outTradeNo = outTradeNo;
-  }
-
-  public Integer getTotalFee() {
-    return this.totalFee;
-  }
-
-  public void setTotalFee(Integer totalFee) {
-    this.totalFee = totalFee;
-  }
-
-  public String getFeeType() {
-    return this.feeType;
-  }
-
-  public void setFeeType(String feeType) {
-    this.feeType = feeType;
-  }
-
-  public String getSpbillCreateIp() {
-    return this.spbillCreateIp;
-  }
-
-  public void setSpbillCreateIp(String spbillCreateIp) {
-    this.spbillCreateIp = spbillCreateIp;
-  }
-
-  public String getGoodsTag() {
-    return this.goodsTag;
-  }
-
-  public void setGoodsTag(String goodsTag) {
-    this.goodsTag = goodsTag;
-  }
-
-  public String getLimitPay() {
-    return this.limitPay;
-  }
-
-  public void setLimitPay(String limitPay) {
-    this.limitPay = limitPay;
-  }
-
-  public String getAuthCode() {
-    return this.authCode;
-  }
-
-  public void setAuthCode(String authCode) {
-    this.authCode = authCode;
-  }
-
   @Override
   protected void checkConstraints() {
     //do nothing
   }
 
-  public static final class Builder {
-    private String signType;
-    private String body;
-    private String appid;
-    private String detail;
-    private String mchId;
-    private String attach;
-    private String subAppId;
-    private String outTradeNo;
-    private String subMchId;
-    private Integer totalFee;
-    private String nonceStr;
-    private String feeType;
-    private String sign;
-    private String spbillCreateIp;
-    private String goodsTag;
-    private String limitPay;
-    private String authCode;
-
-    private Builder() {
-    }
-
-    public Builder signType(String signType) {
-      this.signType = signType;
-      return this;
-    }
-
-    public Builder body(String body) {
-      this.body = body;
-      return this;
-    }
-
-    public Builder appid(String appid) {
-      this.appid = appid;
-      return this;
-    }
-
-    public Builder detail(String detail) {
-      this.detail = detail;
-      return this;
-    }
-
-    public Builder mchId(String mchId) {
-      this.mchId = mchId;
-      return this;
-    }
-
-    public Builder attach(String attach) {
-      this.attach = attach;
-      return this;
-    }
-
-    public Builder subAppId(String subAppId) {
-      this.subAppId = subAppId;
-      return this;
-    }
-
-    public Builder outTradeNo(String outTradeNo) {
-      this.outTradeNo = outTradeNo;
-      return this;
-    }
-
-    public Builder subMchId(String subMchId) {
-      this.subMchId = subMchId;
-      return this;
-    }
-
-    public Builder totalFee(Integer totalFee) {
-      this.totalFee = totalFee;
-      return this;
-    }
-
-    public Builder nonceStr(String nonceStr) {
-      this.nonceStr = nonceStr;
-      return this;
-    }
-
-    public Builder feeType(String feeType) {
-      this.feeType = feeType;
-      return this;
-    }
-
-    public Builder sign(String sign) {
-      this.sign = sign;
-      return this;
-    }
-
-    public Builder spbillCreateIp(String spbillCreateIp) {
-      this.spbillCreateIp = spbillCreateIp;
-      return this;
-    }
-
-    public Builder goodsTag(String goodsTag) {
-      this.goodsTag = goodsTag;
-      return this;
-    }
-
-    public Builder limitPay(String limitPay) {
-      this.limitPay = limitPay;
-      return this;
-    }
-
-    public Builder authCode(String authCode) {
-      this.authCode = authCode;
-      return this;
-    }
-
-    public WxPayMicropayRequest build() {
-      return new WxPayMicropayRequest(this);
-    }
-  }
 }
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayOrderCloseRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayOrderCloseRequest.java
index 21968ac983..29650537c3 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayOrderCloseRequest.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayOrderCloseRequest.java
@@ -1,14 +1,21 @@
 package com.github.binarywang.wxpay.bean.request;
 
 import com.thoughtworks.xstream.annotations.XStreamAlias;
+import lombok.*;
 
 /**
  * 
  *  关闭订单请求对象类
  * Created by Binary Wang on 2016-10-27.
- * @author binarywang(Binary Wang)
  * 
+ * + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@Builder(builderMethodName = "newBuilder") +@NoArgsConstructor +@AllArgsConstructor @XStreamAlias("xml") public class WxPayOrderCloseRequest extends WxPayBaseRequest { @@ -25,14 +32,6 @@ public class WxPayOrderCloseRequest extends WxPayBaseRequest { @XStreamAlias("out_trade_no") private String outTradeNo; - public String getOutTradeNo() { - return this.outTradeNo; - } - - public void setOutTradeNo(String outTradeNo) { - this.outTradeNo = outTradeNo; - } - @Override protected void checkConstraints() { diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayOrderQueryRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayOrderQueryRequest.java index e7767da607..4342fb9519 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayOrderQueryRequest.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayOrderQueryRequest.java @@ -2,6 +2,7 @@ import com.github.binarywang.wxpay.exception.WxPayException; import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.*; import org.apache.commons.lang3.StringUtils; /** @@ -17,8 +18,13 @@ *
  • 描述 *
  • * - * @author binarywang(Binary Wang) + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@Builder(builderMethodName = "newBuilder") +@NoArgsConstructor +@AllArgsConstructor @XStreamAlias("xml") public class WxPayOrderQueryRequest extends WxPayBaseRequest { @@ -48,22 +54,6 @@ public class WxPayOrderQueryRequest extends WxPayBaseRequest { @XStreamAlias("out_trade_no") private String outTradeNo; - public String getTransactionId() { - return this.transactionId; - } - - public void setTransactionId(String transactionId) { - this.transactionId = transactionId; - } - - public String getOutTradeNo() { - return this.outTradeNo; - } - - public void setOutTradeNo(String outTradeNo) { - this.outTradeNo = outTradeNo; - } - @Override protected void checkConstraints() throws WxPayException { if ((StringUtils.isBlank(transactionId) && StringUtils.isBlank(outTradeNo)) || diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayOrderReverseRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayOrderReverseRequest.java index 075295238e..db68179188 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayOrderReverseRequest.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayOrderReverseRequest.java @@ -2,15 +2,22 @@ import com.github.binarywang.wxpay.exception.WxPayException; import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.*; import org.apache.commons.lang3.StringUtils; /** *
      * 撤销订单请求类
      * Created by Binary Wang on 2017-3-23.
    - * @author binarywang(Binary Wang)
      * 
    + * + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@Builder(builderMethodName = "newBuilder") +@NoArgsConstructor +@AllArgsConstructor @XStreamAlias("xml") public class WxPayOrderReverseRequest extends WxPayBaseRequest { @@ -39,58 +46,6 @@ public class WxPayOrderReverseRequest extends WxPayBaseRequest { @XStreamAlias("out_trade_no") private String outTradeNo; - /** - *
    -   * 签名类型
    -   * sign_type
    -   * 否
    -   * String(32)
    -   * HMAC-SHA256
    -   * 签名类型,目前支持HMAC-SHA256和MD5,默认为MD5
    -   **/
    -  @XStreamAlias("sign_type")
    -  private String signType;
    -
    -  private WxPayOrderReverseRequest(Builder builder) {
    -    setTransactionId(builder.transactionId);
    -    setAppid(builder.appid);
    -    setOutTradeNo(builder.outTradeNo);
    -    setMchId(builder.mchId);
    -    setSignType(builder.signType);
    -    setSubAppId(builder.subAppId);
    -    setSubMchId(builder.subMchId);
    -    setNonceStr(builder.nonceStr);
    -    setSign(builder.sign);
    -  }
    -
    -  public static Builder newBuilder() {
    -    return new Builder();
    -  }
    -
    -  public String getTransactionId() {
    -    return this.transactionId;
    -  }
    -
    -  public void setTransactionId(String transactionId) {
    -    this.transactionId = transactionId;
    -  }
    -
    -  public String getOutTradeNo() {
    -    return this.outTradeNo;
    -  }
    -
    -  public void setOutTradeNo(String outTradeNo) {
    -    this.outTradeNo = outTradeNo;
    -  }
    -
    -  public String getSignType() {
    -    return this.signType;
    -  }
    -
    -  public void setSignType(String signType) {
    -    this.signType = signType;
    -  }
    -
       @Override
       protected void checkConstraints() throws WxPayException {
         if (StringUtils.isBlank(transactionId) && StringUtils.isBlank(outTradeNo)) {
    @@ -98,67 +53,4 @@ protected void checkConstraints() throws WxPayException {
         }
       }
     
    -  public static final class Builder {
    -    private String transactionId;
    -    private String appid;
    -    private String outTradeNo;
    -    private String mchId;
    -    private String signType;
    -    private String subAppId;
    -    private String subMchId;
    -    private String nonceStr;
    -    private String sign;
    -
    -    private Builder() {
    -    }
    -
    -    public Builder transactionId(String transactionId) {
    -      this.transactionId = transactionId;
    -      return this;
    -    }
    -
    -    public Builder appid(String appid) {
    -      this.appid = appid;
    -      return this;
    -    }
    -
    -    public Builder outTradeNo(String outTradeNo) {
    -      this.outTradeNo = outTradeNo;
    -      return this;
    -    }
    -
    -    public Builder mchId(String mchId) {
    -      this.mchId = mchId;
    -      return this;
    -    }
    -
    -    public Builder signType(String signType) {
    -      this.signType = signType;
    -      return this;
    -    }
    -
    -    public Builder subAppId(String subAppId) {
    -      this.subAppId = subAppId;
    -      return this;
    -    }
    -
    -    public Builder subMchId(String subMchId) {
    -      this.subMchId = subMchId;
    -      return this;
    -    }
    -
    -    public Builder nonceStr(String nonceStr) {
    -      this.nonceStr = nonceStr;
    -      return this;
    -    }
    -
    -    public Builder sign(String sign) {
    -      this.sign = sign;
    -      return this;
    -    }
    -
    -    public WxPayOrderReverseRequest build() {
    -      return new WxPayOrderReverseRequest(this);
    -    }
    -  }
     }
    diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayQueryCommentRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayQueryCommentRequest.java
    index 1bdbf9bf4e..e1117b0be2 100644
    --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayQueryCommentRequest.java
    +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayQueryCommentRequest.java
    @@ -2,6 +2,7 @@
     
     import com.github.binarywang.wxpay.exception.WxPayException;
     import com.thoughtworks.xstream.annotations.XStreamAlias;
    +import lombok.*;
     import me.chanjar.weixin.common.annotation.Required;
     
     /**
    @@ -12,6 +13,11 @@
      *
      * @author Binary Wang
      */
    +@Data
    +@EqualsAndHashCode(callSuper = true)
    +@Builder(builderMethodName = "newBuilder")
    +@NoArgsConstructor
    +@AllArgsConstructor
     @XStreamAlias("xml")
     public class WxPayQueryCommentRequest extends WxPayBaseRequest {
       /**
    @@ -77,36 +83,4 @@ protected void checkConstraints() throws WxPayException {
     
       }
     
    -  public String getBeginTime() {
    -    return beginTime;
    -  }
    -
    -  public void setBeginTime(String beginTime) {
    -    this.beginTime = beginTime;
    -  }
    -
    -  public String getEndTime() {
    -    return endTime;
    -  }
    -
    -  public void setEndTime(String endTime) {
    -    this.endTime = endTime;
    -  }
    -
    -  public Integer getOffset() {
    -    return offset;
    -  }
    -
    -  public void setOffset(Integer offset) {
    -    this.offset = offset;
    -  }
    -
    -  public Integer getLimit() {
    -    return limit;
    -  }
    -
    -  public void setLimit(Integer limit) {
    -    this.limit = limit;
    -  }
    -
     }
    diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRedpackQueryRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRedpackQueryRequest.java
    index 191db46975..e7b5f9c134 100644
    --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRedpackQueryRequest.java
    +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRedpackQueryRequest.java
    @@ -1,6 +1,7 @@
     package com.github.binarywang.wxpay.bean.request;
     
     import com.thoughtworks.xstream.annotations.XStreamAlias;
    +import lombok.*;
     
     /**
      * 
    @@ -12,9 +13,15 @@
      *   类型
      *   说明
      * Created by Binary Wang on 2016-11-28.
    - * @author binarywang(Binary Wang)
      * 
    + * + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@Builder(builderMethodName = "newBuilder") +@NoArgsConstructor +@AllArgsConstructor @XStreamAlias("xml") public class WxPayRedpackQueryRequest extends WxPayBaseRequest { /** @@ -39,22 +46,6 @@ public class WxPayRedpackQueryRequest extends WxPayBaseRequest { @XStreamAlias("bill_type") private String billType; - public String getBillType() { - return billType; - } - - public void setBillType(String billType) { - this.billType = billType; - } - - public String getMchBillNo() { - return mchBillNo; - } - - public void setMchBillNo(String mchBillNo) { - this.mchBillNo = mchBillNo; - } - @Override protected void checkConstraints() { diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRefundQueryRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRefundQueryRequest.java index 00545f004c..e413377f34 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRefundQueryRequest.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRefundQueryRequest.java @@ -2,14 +2,21 @@ import com.github.binarywang.wxpay.exception.WxPayException; import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.*; import org.apache.commons.lang3.StringUtils; /** *
      * Created by Binary Wang on 2016-11-24.
    - * @author binarywang(Binary Wang)
      * 
    + * + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@Builder(builderMethodName = "newBuilder") +@NoArgsConstructor +@AllArgsConstructor @XStreamAlias("xml") public class WxPayRefundQueryRequest extends WxPayBaseRequest { /** @@ -25,19 +32,6 @@ public class WxPayRefundQueryRequest extends WxPayBaseRequest { @XStreamAlias("device_info") private String deviceInfo; - /** - *
    -   * 签名类型
    -   * sign_type
    -   * 否
    -   * String(32)
    -   * HMAC-SHA256
    -   * 签名类型,目前支持HMAC-SHA256和MD5,默认为MD5
    -   * 
    - */ - @XStreamAlias("sign_type") - private String signType; - //************以下四选一************ /** *
    @@ -87,54 +81,6 @@ public class WxPayRefundQueryRequest extends WxPayBaseRequest {
       @XStreamAlias("refund_id")
       private String refundId;
     
    -  public String getDeviceInfo() {
    -    return deviceInfo;
    -  }
    -
    -  public void setDeviceInfo(String deviceInfo) {
    -    this.deviceInfo = deviceInfo;
    -  }
    -
    -  public String getSignType() {
    -    return signType;
    -  }
    -
    -  public void setSignType(String signType) {
    -    this.signType = signType;
    -  }
    -
    -  public String getTransactionId() {
    -    return transactionId;
    -  }
    -
    -  public void setTransactionId(String transactionId) {
    -    this.transactionId = transactionId;
    -  }
    -
    -  public String getOutTradeNo() {
    -    return outTradeNo;
    -  }
    -
    -  public void setOutTradeNo(String outTradeNo) {
    -    this.outTradeNo = outTradeNo;
    -  }
    -
    -  public String getOutRefundNo() {
    -    return outRefundNo;
    -  }
    -
    -  public void setOutRefundNo(String outRefundNo) {
    -    this.outRefundNo = outRefundNo;
    -  }
    -
    -  public String getRefundId() {
    -    return refundId;
    -  }
    -
    -  public void setRefundId(String refundId) {
    -    this.refundId = refundId;
    -  }
    -
       @Override
       protected void checkConstraints() throws WxPayException {
         if ((StringUtils.isBlank(transactionId) && StringUtils.isBlank(outTradeNo)
    diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRefundRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRefundRequest.java
    index 66808738ca..1a3b85e83a 100644
    --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRefundRequest.java
    +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRefundRequest.java
    @@ -1,8 +1,10 @@
     package com.github.binarywang.wxpay.bean.request;
     
     import com.github.binarywang.wxpay.config.WxPayConfig;
    +import com.github.binarywang.wxpay.constant.WxPayConstants.RefundAccountSource;
     import com.github.binarywang.wxpay.exception.WxPayException;
     import com.thoughtworks.xstream.annotations.XStreamAlias;
    +import lombok.*;
     import me.chanjar.weixin.common.annotation.Required;
     import org.apache.commons.lang3.ArrayUtils;
     import org.apache.commons.lang3.StringUtils;
    @@ -22,12 +24,19 @@
      * Created by Binary Wang on 2016-10-08.
      * 
    * - * @author binarywang(Binary Wang) + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@Builder(builderMethodName = "newBuilder") +@NoArgsConstructor +@AllArgsConstructor @XStreamAlias("xml") public class WxPayRefundRequest extends WxPayBaseRequest { - private static final String[] REFUND_ACCOUNT = new String[]{"REFUND_SOURCE_RECHARGE_FUNDS", - "REFUND_SOURCE_UNSETTLED_FUNDS"}; + private static final String[] REFUND_ACCOUNT = new String[]{ + RefundAccountSource.RECHARGE_FUNDS, + RefundAccountSource.UNSETTLED_FUNDS + }; /** *
        * 设备号
    @@ -155,119 +164,13 @@ public class WxPayRefundRequest extends WxPayBaseRequest {
       @XStreamAlias("refund_desc")
       private String refundDesc;
     
    -  private WxPayRefundRequest(Builder builder) {
    -    setDeviceInfo(builder.deviceInfo);
    -    setAppid(builder.appid);
    -    setTransactionId(builder.transactionId);
    -    setMchId(builder.mchId);
    -    setSubAppId(builder.subAppId);
    -    setOutTradeNo(builder.outTradeNo);
    -    setSubMchId(builder.subMchId);
    -    setOutRefundNo(builder.outRefundNo);
    -    setNonceStr(builder.nonceStr);
    -    setTotalFee(builder.totalFee);
    -    setSign(builder.sign);
    -    setRefundFee(builder.refundFee);
    -    setRefundFeeType(builder.refundFeeType);
    -    setOpUserId(builder.opUserId);
    -    setRefundAccount(builder.refundAccount);
    -    setRefundDesc(builder.refundDesc);
    -  }
    -
    -  public static Builder newBuilder() {
    -    return new Builder();
    -  }
    -
    -  public String getDeviceInfo() {
    -    return this.deviceInfo;
    -  }
    -
    -  public void setDeviceInfo(String deviceInfo) {
    -    this.deviceInfo = deviceInfo;
    -  }
    -
    -  public String getTransactionId() {
    -    return this.transactionId;
    -  }
    -
    -  public void setTransactionId(String transactionId) {
    -    this.transactionId = transactionId;
    -  }
    -
    -  public String getOutTradeNo() {
    -    return this.outTradeNo;
    -  }
    -
    -  public void setOutTradeNo(String outTradeNo) {
    -    this.outTradeNo = outTradeNo;
    -  }
    -
    -  public String getOutRefundNo() {
    -    return this.outRefundNo;
    -  }
    -
    -  public void setOutRefundNo(String outRefundNo) {
    -    this.outRefundNo = outRefundNo;
    -  }
    -
    -  public Integer getTotalFee() {
    -    return this.totalFee;
    -  }
    -
    -  public void setTotalFee(Integer totalFee) {
    -    this.totalFee = totalFee;
    -  }
    -
    -  public Integer getRefundFee() {
    -    return this.refundFee;
    -  }
    -
    -  public void setRefundFee(Integer refundFee) {
    -    this.refundFee = refundFee;
    -  }
    -
    -  public String getRefundFeeType() {
    -    return this.refundFeeType;
    -  }
    -
    -  public void setRefundFeeType(String refundFeeType) {
    -    this.refundFeeType = refundFeeType;
    -  }
    -
    -  public String getOpUserId() {
    -    return this.opUserId;
    -  }
    -
    -  public void setOpUserId(String opUserId) {
    -    this.opUserId = opUserId;
    -  }
    -
    -  public String getRefundAccount() {
    -    return this.refundAccount;
    -  }
    -
    -  public void setRefundAccount(String refundAccount) {
    -    this.refundAccount = refundAccount;
    -  }
    -
    -  public String getRefundDesc() {
    -    return this.refundDesc;
    -  }
    -
    -  public void setRefundDesc(String refundDesc) {
    -    this.refundDesc = refundDesc;
    -  }
    -
    -  public WxPayRefundRequest() {
    -  }
    -
       @Override
    -  public void checkAndSign(WxPayConfig config) throws WxPayException {
    +  public void checkAndSign(WxPayConfig config, boolean isIgnoreSignType) throws WxPayException {
         if (StringUtils.isBlank(this.getOpUserId())) {
           this.setOpUserId(config.getMchId());
         }
     
    -    super.checkAndSign(config);
    +    super.checkAndSign(config, isIgnoreSignType);
       }
     
       @Override
    @@ -284,109 +187,4 @@ protected void checkConstraints() throws WxPayException {
         }
       }
     
    -  public static final class Builder {
    -    private String deviceInfo;
    -    private String appid;
    -    private String transactionId;
    -    private String mchId;
    -    private String subAppId;
    -    private String outTradeNo;
    -    private String subMchId;
    -    private String outRefundNo;
    -    private String nonceStr;
    -    private Integer totalFee;
    -    private String sign;
    -    private Integer refundFee;
    -    private String refundFeeType;
    -    private String opUserId;
    -    private String refundAccount;
    -    private String refundDesc;
    -
    -    private Builder() {
    -    }
    -
    -    public Builder deviceInfo(String deviceInfo) {
    -      this.deviceInfo = deviceInfo;
    -      return this;
    -    }
    -
    -    public Builder appid(String appid) {
    -      this.appid = appid;
    -      return this;
    -    }
    -
    -    public Builder transactionId(String transactionId) {
    -      this.transactionId = transactionId;
    -      return this;
    -    }
    -
    -    public Builder mchId(String mchId) {
    -      this.mchId = mchId;
    -      return this;
    -    }
    -
    -    public Builder subAppId(String subAppId) {
    -      this.subAppId = subAppId;
    -      return this;
    -    }
    -
    -    public Builder outTradeNo(String outTradeNo) {
    -      this.outTradeNo = outTradeNo;
    -      return this;
    -    }
    -
    -    public Builder subMchId(String subMchId) {
    -      this.subMchId = subMchId;
    -      return this;
    -    }
    -
    -    public Builder outRefundNo(String outRefundNo) {
    -      this.outRefundNo = outRefundNo;
    -      return this;
    -    }
    -
    -    public Builder nonceStr(String nonceStr) {
    -      this.nonceStr = nonceStr;
    -      return this;
    -    }
    -
    -    public Builder totalFee(Integer totalFee) {
    -      this.totalFee = totalFee;
    -      return this;
    -    }
    -
    -    public Builder sign(String sign) {
    -      this.sign = sign;
    -      return this;
    -    }
    -
    -    public Builder refundFee(Integer refundFee) {
    -      this.refundFee = refundFee;
    -      return this;
    -    }
    -
    -    public Builder refundFeeType(String refundFeeType) {
    -      this.refundFeeType = refundFeeType;
    -      return this;
    -    }
    -
    -    public Builder opUserId(String opUserId) {
    -      this.opUserId = opUserId;
    -      return this;
    -    }
    -
    -    public Builder refundAccount(String refundAccount) {
    -      this.refundAccount = refundAccount;
    -      return this;
    -    }
    -
    -    public Builder refundDesc(String refundDesc) {
    -      this.refundDesc = refundDesc;
    -      return this;
    -    }
    -
    -    public WxPayRefundRequest build() {
    -      return new WxPayRefundRequest(this);
    -    }
    -  }
     }
    diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayReportRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayReportRequest.java
    index 8b3f88b9c9..88532ad2b5 100644
    --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayReportRequest.java
    +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayReportRequest.java
    @@ -1,6 +1,7 @@
     package com.github.binarywang.wxpay.bean.request;
     
     import com.thoughtworks.xstream.annotations.XStreamAlias;
    +import lombok.*;
     import me.chanjar.weixin.common.annotation.Required;
     
     /**
    @@ -15,8 +16,13 @@
      * 
  • 描述 *
  • * - * @author binarywang(Binary Wang) + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@Builder(builderMethodName = "newBuilder") +@NoArgsConstructor +@AllArgsConstructor @XStreamAlias("xml") public class WxPayReportRequest extends WxPayBaseRequest { /** @@ -32,19 +38,6 @@ public class WxPayReportRequest extends WxPayBaseRequest { @XStreamAlias("device_info") private String deviceInfo; - /** - *
    -   * 签名类型
    -   * sign_type
    -   * 否
    -   * String(32)
    -   * HMAC-SHA256
    -   * 签名类型,目前支持HMAC-SHA256和MD5,默认为MD5
    -   * 
    - */ - @XStreamAlias("sign_type") - private String signType; - /** *
        * 接口URL
    @@ -175,102 +168,6 @@ public class WxPayReportRequest extends WxPayBaseRequest {
       @XStreamAlias("time")
       private String time;
     
    -  public String getDeviceInfo() {
    -    return deviceInfo;
    -  }
    -
    -  public void setDeviceInfo(String deviceInfo) {
    -    this.deviceInfo = deviceInfo;
    -  }
    -
    -  public String getSignType() {
    -    return signType;
    -  }
    -
    -  public void setSignType(String signType) {
    -    this.signType = signType;
    -  }
    -
    -  public String getInterfaceUrl() {
    -    return interfaceUrl;
    -  }
    -
    -  public void setInterfaceUrl(String interfaceUrl) {
    -    this.interfaceUrl = interfaceUrl;
    -  }
    -
    -  public Integer getExecuteTime() {
    -    return executeTime;
    -  }
    -
    -  public void setExecuteTime(Integer executeTime) {
    -    this.executeTime = executeTime;
    -  }
    -
    -  public String getReturnCode() {
    -    return returnCode;
    -  }
    -
    -  public void setReturnCode(String returnCode) {
    -    this.returnCode = returnCode;
    -  }
    -
    -  public String getReturnMsg() {
    -    return returnMsg;
    -  }
    -
    -  public void setReturnMsg(String returnMsg) {
    -    this.returnMsg = returnMsg;
    -  }
    -
    -  public String getResultCode() {
    -    return resultCode;
    -  }
    -
    -  public void setResultCode(String resultCode) {
    -    this.resultCode = resultCode;
    -  }
    -
    -  public String getErrCode() {
    -    return errCode;
    -  }
    -
    -  public void setErrCode(String errCode) {
    -    this.errCode = errCode;
    -  }
    -
    -  public String getErrCodeDes() {
    -    return errCodeDes;
    -  }
    -
    -  public void setErrCodeDes(String errCodeDes) {
    -    this.errCodeDes = errCodeDes;
    -  }
    -
    -  public String getOutTradeNo() {
    -    return outTradeNo;
    -  }
    -
    -  public void setOutTradeNo(String outTradeNo) {
    -    this.outTradeNo = outTradeNo;
    -  }
    -
    -  public String getUserIp() {
    -    return userIp;
    -  }
    -
    -  public void setUserIp(String userIp) {
    -    this.userIp = userIp;
    -  }
    -
    -  public String getTime() {
    -    return time;
    -  }
    -
    -  public void setTime(String time) {
    -    this.time = time;
    -  }
    -
       @Override
       protected void checkConstraints() {
         //do nothing
    diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPaySendRedpackRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPaySendRedpackRequest.java
    index f7082fc3da..bc621fc011 100644
    --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPaySendRedpackRequest.java
    +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPaySendRedpackRequest.java
    @@ -1,13 +1,19 @@
     package com.github.binarywang.wxpay.bean.request;
     
     import com.thoughtworks.xstream.annotations.XStreamAlias;
    +import lombok.*;
     
     /**
      * 发送红包请求参数对象
      * Created by Binary Wang on 2016/9/24.
      *
    - * @author binarywang (https://github.com/binarywang)
    + * @author Binary Wang
      */
    +@Data
    +@EqualsAndHashCode(callSuper = true)
    +@Builder(builderMethodName = "newBuilder")
    +@NoArgsConstructor
    +@AllArgsConstructor
     @XStreamAlias("xml")
     public class WxPaySendRedpackRequest extends WxPayBaseRequest {
       /**
    @@ -137,85 +143,6 @@ public class WxPaySendRedpackRequest extends WxPayBaseRequest {
       @XStreamAlias("consume_mch_id")
       private String consumeMchId;
     
    -  public String getMchBillNo() {
    -    return mchBillNo;
    -  }
    -
    -  public void setMchBillNo(String mchBillNo) {
    -    this.mchBillNo = mchBillNo;
    -  }
    -
    -  public String getSendName() {
    -    return this.sendName;
    -  }
    -
    -  public void setSendName(String sendName) {
    -    this.sendName = sendName;
    -  }
    -
    -  public String getReOpenid() {
    -    return this.reOpenid;
    -  }
    -
    -  public void setReOpenid(String reOpenid) {
    -    this.reOpenid = reOpenid;
    -  }
    -
    -  public Integer getTotalAmount() {
    -    return this.totalAmount;
    -  }
    -
    -  public void setTotalAmount(Integer totalAmount) {
    -    this.totalAmount = totalAmount;
    -  }
    -
    -  public Integer getTotalNum() {
    -    return this.totalNum;
    -  }
    -
    -  public void setTotalNum(Integer totalNum) {
    -    this.totalNum = totalNum;
    -  }
    -
    -  public String getAmtType() {
    -    return this.amtType;
    -  }
    -
    -  public void setAmtType(String amtType) {
    -    this.amtType = amtType;
    -  }
    -
    -  public String getWishing() {
    -    return this.wishing;
    -  }
    -
    -  public void setWishing(String wishing) {
    -    this.wishing = wishing;
    -  }
    -
    -  public String getClientIp() {
    -    return this.clientIp;
    -  }
    -
    -  public void setClientIp(String clientIp) {
    -    this.clientIp = clientIp;
    -  }
    -
    -  public String getActName() {
    -    return this.actName;
    -  }
    -
    -  public void setActName(String actName) {
    -    this.actName = actName;
    -  }
    -
    -  public String getRemark() {
    -    return this.remark;
    -  }
    -
    -  public void setRemark(String remark) {
    -    this.remark = remark;
    -  }
     
       @Override
       protected void checkConstraints() {
    @@ -232,28 +159,4 @@ public void setAppid(String appid) {
         this.wxAppid = appid;
       }
     
    -  public String getSceneId() {
    -    return this.sceneId;
    -  }
    -
    -  public void setSceneId(String sceneId) {
    -    this.sceneId = sceneId;
    -  }
    -
    -  public String getRiskInfo() {
    -    return this.riskInfo;
    -  }
    -
    -  public void setRiskInfo(String riskInfo) {
    -    this.riskInfo = riskInfo;
    -  }
    -
    -  public String getConsumeMchId() {
    -    return this.consumeMchId;
    -  }
    -
    -  public void setConsumeMchId(String consumeMchId) {
    -    this.consumeMchId = consumeMchId;
    -  }
    -
     }
    diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayShorturlRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayShorturlRequest.java
    index 714e07ea43..3cc9302bcc 100644
    --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayShorturlRequest.java
    +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayShorturlRequest.java
    @@ -1,14 +1,21 @@
     package com.github.binarywang.wxpay.bean.request;
     
     import com.thoughtworks.xstream.annotations.XStreamAlias;
    +import lombok.*;
     
     /**
      * 
      * 转换短链接请求对象类
      * Created by Binary Wang on 2017-3-27.
    - * @author binarywang(Binary Wang)
      * 
    + * + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@Builder(builderMethodName = "newBuilder") +@NoArgsConstructor +@AllArgsConstructor @XStreamAlias("xml") public class WxPayShorturlRequest extends WxPayBaseRequest { /** @@ -24,21 +31,6 @@ public class WxPayShorturlRequest extends WxPayBaseRequest { @XStreamAlias("long_url") private String longUrl; - public WxPayShorturlRequest() { - } - - public WxPayShorturlRequest(String longUrl) { - this.longUrl = longUrl; - } - - public String getLongUrl() { - return this.longUrl; - } - - public void setLongUrl(String longUrl) { - this.longUrl = longUrl; - } - @Override protected void checkConstraints() { //do nothing diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayUnifiedOrderRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayUnifiedOrderRequest.java index 8061556cc7..c2bc9f45fb 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayUnifiedOrderRequest.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayUnifiedOrderRequest.java @@ -1,8 +1,10 @@ package com.github.binarywang.wxpay.bean.request; import com.github.binarywang.wxpay.config.WxPayConfig; +import com.github.binarywang.wxpay.constant.WxPayConstants.TradeType; import com.github.binarywang.wxpay.exception.WxPayException; import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.*; import me.chanjar.weixin.common.annotation.Required; import org.apache.commons.lang3.StringUtils; @@ -10,15 +12,18 @@ *
      * 统一下单请求参数对象
      * 参考文档:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1
    - * 
    * Created by Binary Wang on 2016/9/25. + *
    * - * @author binarywang (https://github.com/binarywang) + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@Builder(builderMethodName = "newBuilder") +@NoArgsConstructor +@AllArgsConstructor @XStreamAlias("xml") public class WxPayUnifiedOrderRequest extends WxPayBaseRequest { - private static final String[] TRADE_TYPES = new String[]{"JSAPI", "NATIVE", "APP", "MWEB"}; - /** *
        * 字段名:设备号
    @@ -310,146 +315,13 @@ public class WxPayUnifiedOrderRequest extends WxPayBaseRequest {
       @XStreamAlias("fingerprint")
       private String fingerprint;
     
    -  public WxPayUnifiedOrderRequest() {
    -  }
    -
    -  private WxPayUnifiedOrderRequest(Builder builder) {
    -    setDeviceInfo(builder.deviceInfo);
    -    setAppid(builder.appid);
    -    setBody(builder.body);
    -    setMchId(builder.mchId);
    -    setSubAppId(builder.subAppId);
    -    setSubMchId(builder.subMchId);
    -    setNonceStr(builder.nonceStr);
    -    setSign(builder.sign);
    -    setDetail(builder.detail);
    -    setAttach(builder.attach);
    -    setOutTradeNo(builder.outTradeNo);
    -    setFeeType(builder.feeType);
    -    setTotalFee(builder.totalFee);
    -    setSpbillCreateIp(builder.spbillCreateIp);
    -    setTimeStart(builder.timeStart);
    -    setTimeExpire(builder.timeExpire);
    -    setGoodsTag(builder.goodsTag);
    -    setNotifyURL(builder.notifyURL);
    -    setTradeType(builder.tradeType);
    -    setProductId(builder.productId);
    -    setLimitPay(builder.limitPay);
    -    setOpenid(builder.openid);
    -    setSubOpenid(builder.subOpenid);
    -    setSceneInfo(builder.sceneInfo);
    -    fingerprint = builder.fingerprint;
    -  }
    -
    -  public static Builder newBuilder() {
    -    return new Builder();
    -  }
    -
    -  public String getDeviceInfo() {
    -    return this.deviceInfo;
    -  }
    -
    -  public void setDeviceInfo(String deviceInfo) {
    -    this.deviceInfo = deviceInfo;
    -  }
    -
    -  public String getBody() {
    -    return this.body;
    -  }
    -
    -  public void setBody(String body) {
    -    this.body = body;
    -  }
    -
    -  public String getDetail() {
    -    return this.detail;
    -  }
    -
    -  public void setDetail(String detail) {
    -    this.detail = detail;
    -  }
    -
    -  public String getAttach() {
    -    return this.attach;
    -  }
    -
    -  public void setAttach(String attach) {
    -    this.attach = attach;
    -  }
    -
    -  public String getOutTradeNo() {
    -    return this.outTradeNo;
    -  }
    -
    -  public void setOutTradeNo(String outTradeNo) {
    -    this.outTradeNo = outTradeNo;
    -  }
    -
    -  public String getFeeType() {
    -    return this.feeType;
    -  }
    -
    -  public void setFeeType(String feeType) {
    -    this.feeType = feeType;
    -  }
    -
    -  public Integer getTotalFee() {
    -    return this.totalFee;
    -  }
    -
    -  public void setTotalFee(Integer totalFee) {
    -    this.totalFee = totalFee;
    -  }
    -
    -  public String getSpbillCreateIp() {
    -    return this.spbillCreateIp;
    -  }
    -
    -  public void setSpbillCreateIp(String spbillCreateIp) {
    -    this.spbillCreateIp = spbillCreateIp;
    -  }
    -
    -  public String getTimeStart() {
    -    return this.timeStart;
    -  }
    -
    -  public void setTimeStart(String timeStart) {
    -    this.timeStart = timeStart;
    -  }
    -
    -  public String getTimeExpire() {
    -    return this.timeExpire;
    -  }
    -
    -  public void setTimeExpire(String timeExpire) {
    -    this.timeExpire = timeExpire;
    -  }
    -
    -  public String getGoodsTag() {
    -    return this.goodsTag;
    -  }
    -
    -  public void setGoodsTag(String goodsTag) {
    -    this.goodsTag = goodsTag;
    -  }
    -
    -  public String getNotifyURL() {
    -    return this.notifyURL;
    -  }
    -
       /**
        * 如果配置中已经设置,可以不设置值
    -   *
    -   * @param notifyURL
        */
       public void setNotifyURL(String notifyURL) {
         this.notifyURL = notifyURL;
       }
     
    -  public String getTradeType() {
    -    return this.tradeType;
    -  }
    -
       /**
        * 如果配置中已经设置,可以不设置值
        *
    @@ -459,64 +331,25 @@ public void setTradeType(String tradeType) {
         this.tradeType = tradeType;
       }
     
    -  public String getProductId() {
    -    return this.productId;
    -  }
    -
    -  public void setProductId(String productId) {
    -    this.productId = productId;
    -  }
    -
    -  public String getLimitPay() {
    -    return this.limitPay;
    -  }
    -
    -  public void setLimitPay(String limitPay) {
    -    this.limitPay = limitPay;
    -  }
    -
    -  public String getOpenid() {
    -    return this.openid;
    -  }
    -
    -  public void setOpenid(String openid) {
    -    this.openid = openid;
    -  }
    -
    -  public String getSubOpenid() {
    -    return this.subOpenid;
    -  }
    -
    -  public void setSubOpenid(String subOpenid) {
    -    this.subOpenid = subOpenid;
    -  }
    -
    -  public String getSceneInfo() {
    -    return this.sceneInfo;
    -  }
    -
    -  public void setSceneInfo(String sceneInfo) {
    -    this.sceneInfo = sceneInfo;
    -  }
    -
       @Override
       protected void checkConstraints() throws WxPayException {
    -//    if (!ArrayUtils.contains(TRADE_TYPES, this.getTradeType())) {
    -//      throw new WxPayException(String.format("trade_type目前必须为%s其中之一,实际值:%s",
    -//        Arrays.toString(TRADE_TYPES), this.getTradeType()));
    -//    }
    -
    -    if ("JSAPI".equals(this.getTradeType()) && this.getOpenid() == null) {
    -      throw new WxPayException("当 trade_type是'JSAPI'时未指定openid");
    +    if (TradeType.JSAPI.equals(this.getTradeType())) {
    +      if (StringUtils.isBlank(this.getSubAppId()) && StringUtils.isBlank(this.getOpenid())) {
    +        throw new WxPayException("当trade_type是'JSAPI'时,需指定非空的openid值");
    +      }
    +
    +      if (StringUtils.isNotBlank(this.getSubAppId()) && StringUtils.isBlank(this.getSubOpenid())) {
    +        throw new WxPayException("在服务商模式下,当trade_type是'JSAPI'时,需指定非空的sub_openid值");
    +      }
         }
     
    -    if ("NATIVE".equals(this.getTradeType()) && this.getProductId() == null) {
    -      throw new WxPayException("当 trade_type是'NATIVE'时未指定product_id");
    +    if (TradeType.NATIVE.equals(this.getTradeType()) && StringUtils.isBlank(this.getProductId())) {
    +      throw new WxPayException("当trade_type是'NATIVE'时,需指定非空的product_id值");
         }
       }
     
       @Override
    -  public void checkAndSign(WxPayConfig config) throws WxPayException {
    +  public void checkAndSign(WxPayConfig config, boolean isIgnoreSignType) throws WxPayException {
         if (StringUtils.isBlank(this.getNotifyURL())) {
           this.setNotifyURL(config.getNotifyUrl());
         }
    @@ -525,166 +358,7 @@ public void checkAndSign(WxPayConfig config) throws WxPayException {
           this.setTradeType(config.getTradeType());
         }
     
    -    super.checkAndSign(config);
    +    super.checkAndSign(config, isIgnoreSignType);
       }
     
    -  public static final class Builder {
    -    private String appid;
    -    private String mchId;
    -    private String subAppId;
    -    private String subMchId;
    -    private String nonceStr;
    -    private String sign;
    -    private String deviceInfo;
    -    private String body;
    -    private String detail;
    -    private String attach;
    -    private String outTradeNo;
    -    private String feeType;
    -    private Integer totalFee;
    -    private String spbillCreateIp;
    -    private String timeStart;
    -    private String timeExpire;
    -    private String goodsTag;
    -    private String notifyURL;
    -    private String tradeType;
    -    private String productId;
    -    private String limitPay;
    -    private String openid;
    -    private String subOpenid;
    -    private String sceneInfo;
    -    private String fingerprint;
    -
    -    private Builder() {
    -    }
    -
    -    public Builder appid(String appid) {
    -      this.appid = appid;
    -      return this;
    -    }
    -
    -    public Builder mchId(String mchId) {
    -      this.mchId = mchId;
    -      return this;
    -    }
    -
    -    public Builder subAppId(String subAppId) {
    -      this.subAppId = subAppId;
    -      return this;
    -    }
    -
    -    public Builder subMchId(String subMchId) {
    -      this.subMchId = subMchId;
    -      return this;
    -    }
    -
    -    public Builder nonceStr(String nonceStr) {
    -      this.nonceStr = nonceStr;
    -      return this;
    -    }
    -
    -    public Builder sign(String sign) {
    -      this.sign = sign;
    -      return this;
    -    }
    -
    -    public Builder deviceInfo(String deviceInfo) {
    -      this.deviceInfo = deviceInfo;
    -      return this;
    -    }
    -
    -    public Builder body(String body) {
    -      this.body = body;
    -      return this;
    -    }
    -
    -    public Builder detail(String detail) {
    -      this.detail = detail;
    -      return this;
    -    }
    -
    -    public Builder attach(String attach) {
    -      this.attach = attach;
    -      return this;
    -    }
    -
    -    public Builder outTradeNo(String outTradeNo) {
    -      this.outTradeNo = outTradeNo;
    -      return this;
    -    }
    -
    -    public Builder feeType(String feeType) {
    -      this.feeType = feeType;
    -      return this;
    -    }
    -
    -    public Builder totalFee(Integer totalFee) {
    -      this.totalFee = totalFee;
    -      return this;
    -    }
    -
    -    public Builder spbillCreateIp(String spbillCreateIp) {
    -      this.spbillCreateIp = spbillCreateIp;
    -      return this;
    -    }
    -
    -    public Builder timeStart(String timeStart) {
    -      this.timeStart = timeStart;
    -      return this;
    -    }
    -
    -    public Builder timeExpire(String timeExpire) {
    -      this.timeExpire = timeExpire;
    -      return this;
    -    }
    -
    -    public Builder goodsTag(String goodsTag) {
    -      this.goodsTag = goodsTag;
    -      return this;
    -    }
    -
    -    public Builder notifyURL(String notifyURL) {
    -      this.notifyURL = notifyURL;
    -      return this;
    -    }
    -
    -    public Builder tradeType(String tradeType) {
    -      this.tradeType = tradeType;
    -      return this;
    -    }
    -
    -    public Builder productId(String productId) {
    -      this.productId = productId;
    -      return this;
    -    }
    -
    -    public Builder limitPay(String limitPay) {
    -      this.limitPay = limitPay;
    -      return this;
    -    }
    -
    -    public Builder openid(String openid) {
    -      this.openid = openid;
    -      return this;
    -    }
    -
    -    public Builder subOpenid(String subOpenid) {
    -      this.subOpenid = subOpenid;
    -      return this;
    -    }
    -
    -    public Builder sceneInfo(String sceneInfo) {
    -      this.sceneInfo = sceneInfo;
    -      return this;
    -    }
    -
    -    public Builder fingerprint(String fingerprint) {
    -      this.fingerprint = fingerprint;
    -      return this;
    -    }
    -
    -    public WxPayUnifiedOrderRequest build() {
    -      return new WxPayUnifiedOrderRequest(this);
    -    }
    -  }
     }
    diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxEntPayQueryResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxEntPayQueryResult.java
    index dac69e17c4..b5a0e04345 100644
    --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxEntPayQueryResult.java
    +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxEntPayQueryResult.java
    @@ -1,13 +1,19 @@
     package com.github.binarywang.wxpay.bean.result;
     
     import com.thoughtworks.xstream.annotations.XStreamAlias;
    +import lombok.Data;
    +import lombok.EqualsAndHashCode;
    +import lombok.NoArgsConstructor;
     
     /**
      * 企业付款查询返回结果
      * Created by Binary Wang on 2016/10/19.
      *
    - * @author binarywang (https://github.com/binarywang)
    + * @author Binary Wang
      */
    +@Data
    +@EqualsAndHashCode(callSuper = true)
    +@NoArgsConstructor
     @XStreamAlias("xml")
     public class WxEntPayQueryResult extends WxPayBaseResult {
     
    @@ -65,75 +71,4 @@ public class WxEntPayQueryResult extends WxPayBaseResult {
       @XStreamAlias("desc")
       private String desc;
     
    -  public String getPartnerTradeNo() {
    -    return this.partnerTradeNo;
    -  }
    -
    -  public void setPartnerTradeNo(String partnerTradeNo) {
    -    this.partnerTradeNo = partnerTradeNo;
    -  }
    -
    -  public String getDetailId() {
    -    return this.detailId;
    -  }
    -
    -  public void setDetailId(String detailId) {
    -    this.detailId = detailId;
    -  }
    -
    -  public String getStatus() {
    -    return this.status;
    -  }
    -
    -  public void setStatus(String status) {
    -    this.status = status;
    -  }
    -
    -  public String getReason() {
    -    return this.reason;
    -  }
    -
    -  public void setReason(String reason) {
    -    this.reason = reason;
    -  }
    -
    -  public String getOpenid() {
    -    return this.openid;
    -  }
    -
    -  public void setOpenid(String openid) {
    -    this.openid = openid;
    -  }
    -
    -  public String getTransferName() {
    -    return this.transferName;
    -  }
    -
    -  public void setTransferName(String transferName) {
    -    this.transferName = transferName;
    -  }
    -
    -  public Integer getPaymentAmount() {
    -    return this.paymentAmount;
    -  }
    -
    -  public void setPaymentAmount(Integer paymentAmount) {
    -    this.paymentAmount = paymentAmount;
    -  }
    -
    -  public String getTransferTime() {
    -    return this.transferTime;
    -  }
    -
    -  public void setTransferTime(String transferTime) {
    -    this.transferTime = transferTime;
    -  }
    -
    -  public String getDesc() {
    -    return this.desc;
    -  }
    -
    -  public void setDesc(String desc) {
    -    this.desc = desc;
    -  }
     }
    diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxEntPayResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxEntPayResult.java
    index fa0a4e5fdc..033f6e9639 100644
    --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxEntPayResult.java
    +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxEntPayResult.java
    @@ -1,13 +1,19 @@
     package com.github.binarywang.wxpay.bean.result;
     
     import com.thoughtworks.xstream.annotations.XStreamAlias;
    +import lombok.Data;
    +import lombok.EqualsAndHashCode;
    +import lombok.NoArgsConstructor;
     
     /**
      * 企业付款返回结果
      * Created by Binary Wang on 2016/10/02.
      *
    - * @author binarywang (https://github.com/binarywang)
    + * @author Binary Wang
      */
    +@Data
    +@EqualsAndHashCode(callSuper = true)
    +@NoArgsConstructor
     @XStreamAlias("xml")
     public class WxEntPayResult extends WxPayBaseResult {
     
    @@ -42,43 +48,4 @@ public class WxEntPayResult extends WxPayBaseResult {
       @XStreamAlias("payment_time")
       private String paymentTime;
     
    -  public String getMchAppid() {
    -    return this.mchAppid;
    -  }
    -
    -  public void setMchAppid(String mchAppid) {
    -    this.mchAppid = mchAppid;
    -  }
    -
    -  public String getDeviceInfo() {
    -    return this.deviceInfo;
    -  }
    -
    -  public void setDeviceInfo(String deviceInfo) {
    -    this.deviceInfo = deviceInfo;
    -  }
    -
    -  public String getPartnerTradeNo() {
    -    return this.partnerTradeNo;
    -  }
    -
    -  public void setPartnerTradeNo(String partnerTradeNo) {
    -    this.partnerTradeNo = partnerTradeNo;
    -  }
    -
    -  public String getPaymentNo() {
    -    return this.paymentNo;
    -  }
    -
    -  public void setPaymentNo(String paymentNo) {
    -    this.paymentNo = paymentNo;
    -  }
    -
    -  public String getPaymentTime() {
    -    return this.paymentTime;
    -  }
    -
    -  public void setPaymentTime(String paymentTime) {
    -    this.paymentTime = paymentTime;
    -  }
     }
    diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayAuthcode2OpenidResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayAuthcode2OpenidResult.java
    index f56c61a77f..3f1d53a78e 100644
    --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayAuthcode2OpenidResult.java
    +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayAuthcode2OpenidResult.java
    @@ -1,14 +1,21 @@
     package com.github.binarywang.wxpay.bean.result;
     
     import com.thoughtworks.xstream.annotations.XStreamAlias;
    +import lombok.Data;
    +import lombok.EqualsAndHashCode;
    +import lombok.NoArgsConstructor;
     
     /**
      * 
      *  授权码查询openid接口请求结果类
      * Created by Binary Wang on 2017-3-27.
    - * @author binarywang(Binary Wang)
      * 
    + * + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor @XStreamAlias("xml") public class WxPayAuthcode2OpenidResult extends WxPayBaseResult { /** @@ -23,18 +30,4 @@ public class WxPayAuthcode2OpenidResult extends WxPayBaseResult { @XStreamAlias("openid") private String openid; - public WxPayAuthcode2OpenidResult() { - } - - public WxPayAuthcode2OpenidResult(String openid) { - this.openid = openid; - } - - public String getOpenid() { - return this.openid; - } - - public void setOpenid(String openid) { - this.openid = openid; - } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBaseResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBaseResult.java index d4b96dc408..1e0527ebda 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBaseResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBaseResult.java @@ -4,9 +4,11 @@ import com.github.binarywang.wxpay.service.impl.WxPayServiceAbstractImpl; import com.github.binarywang.wxpay.util.SignUtils; import com.google.common.base.Joiner; +import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.Data; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.common.util.xml.XStreamInitializer; import org.apache.commons.lang3.StringUtils; @@ -24,15 +26,18 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.math.BigDecimal; +import java.util.List; import java.util.Map; /** *
      * 微信支付结果共用属性类
      * Created by Binary Wang on 2016-10-24.
    - * @author binarywang(Binary Wang)
      * 
    + * + * @author Binary Wang */ +@Data public abstract class WxPayBaseResult { /** * 返回状态码 @@ -124,14 +129,6 @@ public static T fromXML(String xmlString, Class c return result; } - public String getXmlString() { - return this.xmlString; - } - - public void setXmlString(String xmlString) { - this.xmlString = xmlString; - } - protected Logger getLogger() { return LoggerFactory.getLogger(this.getClass()); } @@ -141,94 +138,6 @@ public String toString() { return ToStringUtils.toSimpleString(this); } - public String getReturnCode() { - return this.returnCode; - } - - public void setReturnCode(String returnCode) { - this.returnCode = returnCode; - } - - public String getReturnMsg() { - return this.returnMsg; - } - - public void setReturnMsg(String returnMsg) { - this.returnMsg = returnMsg; - } - - public String getResultCode() { - return this.resultCode; - } - - public void setResultCode(String resultCode) { - this.resultCode = resultCode; - } - - public String getErrCode() { - return this.errCode; - } - - public void setErrCode(String errCode) { - this.errCode = errCode; - } - - public String getErrCodeDes() { - return this.errCodeDes; - } - - public void setErrCodeDes(String errCodeDes) { - this.errCodeDes = errCodeDes; - } - - public String getAppid() { - return this.appid; - } - - public void setAppid(String appid) { - this.appid = appid; - } - - public String getMchId() { - return this.mchId; - } - - public void setMchId(String mchId) { - this.mchId = mchId; - } - - public String getNonceStr() { - return this.nonceStr; - } - - public void setNonceStr(String nonceStr) { - this.nonceStr = nonceStr; - } - - public String getSign() { - return this.sign; - } - - public void setSign(String sign) { - this.sign = sign; - } - - public String getSubAppId() { - return subAppId; - } - - public void setSubAppId(String subAppId) { - this.subAppId = subAppId; - } - - public String getSubMchId() { - return subMchId; - } - - public void setSubMchId(String subMchId) { - this.subMchId = subMchId; - } - /** * 将bean通过保存的xml字符串转换成map */ @@ -306,37 +215,43 @@ protected Integer getXmlValueAsInt(String... path) { /** * 校验返回结果签名 + * + * @param signType 签名类型 + * @param checkSuccess 是否同时检查结果是否成功 */ - public void checkResult(WxPayServiceAbstractImpl wxPayService) throws WxPayException { + public void checkResult(WxPayServiceAbstractImpl wxPayService, String signType, boolean checkSuccess) throws WxPayException { //校验返回结果签名 Map map = toMap(); - if (getSign() != null && !SignUtils.checkSign(map, wxPayService.getConfig().getMchKey())) { + if (getSign() != null && !SignUtils.checkSign(map, signType, wxPayService.getConfig().getMchKey())) { this.getLogger().debug("校验结果签名失败,参数:{}", map); throw new WxPayException("参数格式校验错误!"); } //校验结果是否成功 - if (!StringUtils.equalsAny(StringUtils.trimToEmpty(getReturnCode()).toUpperCase(), "SUCCESS", "") - || !StringUtils.equalsAny(StringUtils.trimToEmpty(getResultCode()).toUpperCase(), "SUCCESS", "")) { - StringBuilder errorMsg = new StringBuilder(); - if (getReturnCode() != null) { - errorMsg.append("返回代码:").append(getReturnCode()); - } - if (getReturnMsg() != null) { - errorMsg.append(",返回信息:").append(getReturnMsg()); - } - if (getResultCode() != null) { - errorMsg.append(",结果代码:").append(getResultCode()); + if (checkSuccess) { + List successStrings = Lists.newArrayList("SUCCESS", ""); + if (!successStrings.contains(StringUtils.trimToEmpty(getReturnCode()).toUpperCase()) + || !successStrings.contains(StringUtils.trimToEmpty(getResultCode()).toUpperCase())) { + StringBuilder errorMsg = new StringBuilder(); + if (getReturnCode() != null) { + errorMsg.append("返回代码:").append(getReturnCode()); + } + if (getReturnMsg() != null) { + errorMsg.append(",返回信息:").append(getReturnMsg()); + } + if (getResultCode() != null) { + errorMsg.append(",结果代码:").append(getResultCode()); + } + if (getErrCode() != null) { + errorMsg.append(",错误代码:").append(getErrCode()); + } + if (getErrCodeDes() != null) { + errorMsg.append(",错误详情:").append(getErrCodeDes()); + } + + this.getLogger().error("\n结果业务代码异常,返回结果:{},\n{}", map, errorMsg.toString()); + throw WxPayException.from(this); } - if (getErrCode() != null) { - errorMsg.append(",错误代码:").append(getErrCode()); - } - if (getErrCodeDes() != null) { - errorMsg.append(",错误详情:").append(getErrCodeDes()); - } - - this.getLogger().error("\n结果业务代码异常,返回結果:{},\n{}", map, errorMsg.toString()); - throw WxPayException.from(this); } } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBillBaseResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBillBaseResult.java index e469ff4538..28ed6e7f18 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBillBaseResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBillBaseResult.java @@ -1,14 +1,26 @@ package com.github.binarywang.wxpay.bean.result; +import lombok.Data; +import lombok.NoArgsConstructor; +import me.chanjar.weixin.common.util.ToStringUtils; + import java.io.Serializable; +/** + * 交易时间:2017-04-06 01:00:02 公众账号ID: 商户号: 子商户号:0 设备号:WEB 微信订单号: 商户订单号:2017040519091071873216 用户标识: 交易类型:NATIVE + * 交易状态:REFUND 付款银行:CFT 货币种类:CNY 总金额:0.00 企业红包金额:0.00 微信退款单号: 商户退款单号:20170406010000933 退款金额:0.01 企业红包退款金额:0.00 + * 退款类型:ORIGINAL 退款状态:SUCCESS 商品名称: 商户数据包: 手续费:0.00000 费率 :0.60% + */ +@Data +@NoArgsConstructor public class WxPayBillBaseResult implements Serializable { - /* - * 交易时间:2017-04-06 01:00:02 公众账号ID: 商户号: 子商户号:0 设备号:WEB 微信订单号: 商户订单号:2017040519091071873216 用户标识: 交易类型:NATIVE - * 交易状态:REFUND 付款银行:CFT 货币种类:CNY 总金额:0.00 企业红包金额:0.00 微信退款单号: 商户退款单号:20170406010000933 退款金额:0.01 企业红包退款金额:0.00 - * 退款类型:ORIGINAL 退款状态:SUCCESS 商品名称: 商户数据包: 手续费:0.00000 费率 :0.60% - */ - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 2226245109137435453L; + + @Override + public String toString() { + return ToStringUtils.toSimpleString(this); + } + /** * 交易时间 */ @@ -32,7 +44,7 @@ public class WxPayBillBaseResult implements Serializable { /** * 微信订单号 */ - private String transationId; + private String transactionId; /** * 商户订单号 */ @@ -106,200 +118,4 @@ public class WxPayBillBaseResult implements Serializable { */ private String poundageRate; - public static long getSerialversionuid() { - return serialVersionUID; - } - - public String getTradeTime() { - return tradeTime; - } - - public void setTradeTime(String tradeTime) { - this.tradeTime = tradeTime; - } - - public String getAppId() { - return appId; - } - - public void setAppId(String appId) { - this.appId = appId; - } - - public String getMchId() { - return mchId; - } - - public void setMchId(String mchId) { - this.mchId = mchId; - } - - public String getSubMchId() { - return subMchId; - } - - public void setSubMchId(String subMchId) { - this.subMchId = subMchId; - } - - public String getDeviceInfo() { - return deviceInfo; - } - - public void setDeviceInfo(String deviceInfo) { - this.deviceInfo = deviceInfo; - } - - public String getTransationId() { - return transationId; - } - - public void setTransationId(String transationId) { - this.transationId = transationId; - } - - public String getOutTradeNo() { - return outTradeNo; - } - - public void setOutTradeNo(String outTradeNo) { - this.outTradeNo = outTradeNo; - } - - public String getOpenId() { - return openId; - } - - public void setOpenId(String openId) { - this.openId = openId; - } - - public String getTradeType() { - return tradeType; - } - - public void setTradeType(String tradeType) { - this.tradeType = tradeType; - } - - public String getTradeState() { - return tradeState; - } - - public void setTradeState(String tradeState) { - this.tradeState = tradeState; - } - - public String getBankType() { - return bankType; - } - - public void setBankType(String bankType) { - this.bankType = bankType; - } - - public String getFeeType() { - return feeType; - } - - public void setFeeType(String feeType) { - this.feeType = feeType; - } - - public String getTotalFee() { - return totalFee; - } - - public void setTotalFee(String totalFee) { - this.totalFee = totalFee; - } - - public String getCouponFee() { - return couponFee; - } - - public void setCouponFee(String couponFee) { - this.couponFee = couponFee; - } - - public String getRefundId() { - return refundId; - } - - public void setRefundId(String refundId) { - this.refundId = refundId; - } - - public String getOutRefundNo() { - return outRefundNo; - } - - public void setOutRefundNo(String outRefundNo) { - this.outRefundNo = outRefundNo; - } - - public String getSettlementRefundFee() { - return settlementRefundFee; - } - - public void setSettlementRefundFee(String settlementRefundFee) { - this.settlementRefundFee = settlementRefundFee; - } - - public String getCouponRefundFee() { - return couponRefundFee; - } - - public void setCouponRefundFee(String couponRefundFee) { - this.couponRefundFee = couponRefundFee; - } - - public String getRefundChannel() { - return refundChannel; - } - - public void setRefundChannel(String refundChannel) { - this.refundChannel = refundChannel; - } - - public String getRefundState() { - return refundState; - } - - public void setRefundState(String refundState) { - this.refundState = refundState; - } - - public String getBody() { - return body; - } - - public void setBody(String body) { - this.body = body; - } - - public String getAttach() { - return attach; - } - - public void setAttach(String attach) { - this.attach = attach; - } - - public String getPoundage() { - return poundage; - } - - public void setPoundage(String poundage) { - this.poundage = poundage; - } - - public String getPoundageRate() { - return poundageRate; - } - - public void setPoundageRate(String poundageRate) { - this.poundageRate = poundageRate; - } - } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBillResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBillResult.java index a7fb25bef2..0a1a4b2583 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBillResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBillResult.java @@ -1,14 +1,25 @@ package com.github.binarywang.wxpay.bean.result; +import lombok.Data; +import lombok.NoArgsConstructor; +import me.chanjar.weixin.common.util.ToStringUtils; + import java.io.Serializable; import java.util.List; +@Data +@NoArgsConstructor public class WxPayBillResult implements Serializable { + private static final long serialVersionUID = -7687458652694204070L; + + @Override + public String toString() { + return ToStringUtils.toSimpleString(this); + } + /** * 对账返回对象 */ - private static final long serialVersionUID = 1L; - private List wxPayBillBaseResultLst; /** * 总交易单数 @@ -31,53 +42,4 @@ public class WxPayBillResult implements Serializable { */ private String totalPoundageFee; - public List getWxPayBillBaseResultLst() { - return wxPayBillBaseResultLst; - } - - public void setWxPayBillBaseResultLst(List wxPayBillBaseResultLst) { - this.wxPayBillBaseResultLst = wxPayBillBaseResultLst; - } - - public String getTotalRecord() { - return totalRecord; - } - - public void setTotalRecord(String totalRecord) { - this.totalRecord = totalRecord; - } - - public String getTotalFee() { - return totalFee; - } - - public void setTotalFee(String totalFee) { - this.totalFee = totalFee; - } - - public String getTotalRefundFee() { - return totalRefundFee; - } - - public void setTotalRefundFee(String totalRefundFee) { - this.totalRefundFee = totalRefundFee; - } - - public String getTotalCouponFee() { - return totalCouponFee; - } - - public void setTotalCouponFee(String totalCouponFee) { - this.totalCouponFee = totalCouponFee; - } - - public String getTotalPoundageFee() { - return totalPoundageFee; - } - - public void setTotalPoundageFee(String totalPoundageFee) { - this.totalPoundageFee = totalPoundageFee; - } - - } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayCommonResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayCommonResult.java index 1fc4d30940..8c99c9df37 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayCommonResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayCommonResult.java @@ -6,8 +6,9 @@ *
      * 微信支付结果仅包含有return 和result等相关信息的的属性类
      * Created by Binary Wang on 2017-01-09.
    - * @author binarywang(Binary Wang)
      * 
    + * + * @author Binary Wang */ @XStreamAlias("xml") diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayMicropayResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayMicropayResult.java index 2f8842af82..4f6b04cf3c 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayMicropayResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayMicropayResult.java @@ -1,14 +1,21 @@ package com.github.binarywang.wxpay.bean.result; import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; /** *
      * 提交刷卡支付接口响应结果对象类
      * Created by Binary Wang on 2017-3-23.
    - * @author binarywang(Binary Wang)
      * 
    + * + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor @XStreamAlias("xml") public class WxPayMicropayResult extends WxPayBaseResult { /** @@ -206,123 +213,4 @@ public class WxPayMicropayResult extends WxPayBaseResult { @XStreamAlias("promotion_detail") private String promotionDetail; - public String getOpenid() { - return this.openid; - } - - public void setOpenid(String openid) { - this.openid = openid; - } - - public String getIsSubscribe() { - return this.isSubscribe; - } - - public void setIsSubscribe(String isSubscribe) { - this.isSubscribe = isSubscribe; - } - - public String getTradeType() { - return this.tradeType; - } - - public void setTradeType(String tradeType) { - this.tradeType = tradeType; - } - - public String getBankType() { - return this.bankType; - } - - public void setBankType(String bankType) { - this.bankType = bankType; - } - - public String getFeeType() { - return this.feeType; - } - - public void setFeeType(String feeType) { - this.feeType = feeType; - } - - public String getTotalFee() { - return this.totalFee; - } - - public void setTotalFee(String totalFee) { - this.totalFee = totalFee; - } - - public Integer getSettlementTotalFee() { - return this.settlementTotalFee; - } - - public void setSettlementTotalFee(Integer settlementTotalFee) { - this.settlementTotalFee = settlementTotalFee; - } - - public Integer getCouponFee() { - return this.couponFee; - } - - public void setCouponFee(Integer couponFee) { - this.couponFee = couponFee; - } - - public String getCashFeeType() { - return this.cashFeeType; - } - - public void setCashFeeType(String cashFeeType) { - this.cashFeeType = cashFeeType; - } - - public Integer getCashFee() { - return this.cashFee; - } - - public void setCashFee(Integer cashFee) { - this.cashFee = cashFee; - } - - public String getTransactionId() { - return this.transactionId; - } - - public void setTransactionId(String transactionId) { - this.transactionId = transactionId; - } - - public String getOutTradeNo() { - return this.outTradeNo; - } - - public void setOutTradeNo(String outTradeNo) { - this.outTradeNo = outTradeNo; - } - - public String getAttach() { - return this.attach; - } - - public void setAttach(String attach) { - this.attach = attach; - } - - public String getTimeEnd() { - return this.timeEnd; - } - - public void setTimeEnd(String timeEnd) { - this.timeEnd = timeEnd; - } - - public String getPromotionDetail() { - return this.promotionDetail; - } - - public void setPromotionDetail(String promotionDetail) { - this.promotionDetail = promotionDetail; - } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayOrderCloseResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayOrderCloseResult.java index 7221251f10..5451c8535d 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayOrderCloseResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayOrderCloseResult.java @@ -1,14 +1,21 @@ package com.github.binarywang.wxpay.bean.result; import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; /** *
      * 关闭订单结果对象类
      * Created by Binary Wang on 2016-10-27.
    - * @author binarywang(Binary Wang)
      * 
    + * + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor @XStreamAlias("xml") public class WxPayOrderCloseResult extends WxPayBaseResult { @@ -18,11 +25,4 @@ public class WxPayOrderCloseResult extends WxPayBaseResult { @XStreamAlias("result_msg") private String resultMsg; - public String getResultMsg() { - return this.resultMsg; - } - - public void setResultMsg(String resultMsg) { - this.resultMsg = resultMsg; - } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayOrderQueryResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayOrderQueryResult.java index ff087bf010..9da15f5a6f 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayOrderQueryResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayOrderQueryResult.java @@ -2,6 +2,7 @@ import com.google.common.collect.Lists; import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.*; import java.util.List; @@ -18,8 +19,11 @@ *
  • 描述 *
  • * - * @author binarywang(Binary Wang) + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor @XStreamAlias("xml") public class WxPayOrderQueryResult extends WxPayBaseResult { @@ -236,158 +240,6 @@ public class WxPayOrderQueryResult extends WxPayBaseResult { @XStreamAlias("trade_state_desc") private String tradeStateDesc; - public String getDeviceInfo() { - return this.deviceInfo; - } - - public void setDeviceInfo(String deviceInfo) { - this.deviceInfo = deviceInfo; - } - - public String getOpenid() { - return this.openid; - } - - public void setOpenid(String openid) { - this.openid = openid; - } - - public String getIsSubscribe() { - return this.isSubscribe; - } - - public void setIsSubscribe(String isSubscribe) { - this.isSubscribe = isSubscribe; - } - - public String getTradeType() { - return this.tradeType; - } - - public void setTradeType(String tradeType) { - this.tradeType = tradeType; - } - - public String getTradeState() { - return this.tradeState; - } - - public void setTradeState(String tradeState) { - this.tradeState = tradeState; - } - - public String getBankType() { - return this.bankType; - } - - public void setBankType(String bankType) { - this.bankType = bankType; - } - - public Integer getTotalFee() { - return this.totalFee; - } - - public void setTotalFee(Integer totalFee) { - this.totalFee = totalFee; - } - - public Integer getSettlementTotalFee() { - return this.settlementTotalFee; - } - - public void setSettlementTotalFee(Integer settlementTotalFee) { - this.settlementTotalFee = settlementTotalFee; - } - - public String getFeeType() { - return this.feeType; - } - - public void setFeeType(String feeType) { - this.feeType = feeType; - } - - public Integer getCashFee() { - return this.cashFee; - } - - public void setCashFee(Integer cashFee) { - this.cashFee = cashFee; - } - - public String getCashFeeType() { - return this.cashFeeType; - } - - public void setCashFeeType(String cashFeeType) { - this.cashFeeType = cashFeeType; - } - - public Integer getCouponFee() { - return this.couponFee; - } - - public void setCouponFee(Integer couponFee) { - this.couponFee = couponFee; - } - - public Integer getCouponCount() { - return this.couponCount; - } - - public void setCouponCount(Integer couponCount) { - this.couponCount = couponCount; - } - - public List getCoupons() { - return this.coupons; - } - - public void setCoupons(List coupons) { - this.coupons = coupons; - } - - public String getTransactionId() { - return this.transactionId; - } - - public void setTransactionId(String transactionId) { - this.transactionId = transactionId; - } - - public String getOutTradeNo() { - return this.outTradeNo; - } - - public void setOutTradeNo(String outTradeNo) { - this.outTradeNo = outTradeNo; - } - - public String getAttach() { - return this.attach; - } - - public void setAttach(String attach) { - this.attach = attach; - } - - public String getTimeEnd() { - return this.timeEnd; - } - - public void setTimeEnd(String timeEnd) { - this.timeEnd = timeEnd; - } - - public String getTradeStateDesc() { - return this.tradeStateDesc; - } - - public void setTradeStateDesc(String tradeStateDesc) { - this.tradeStateDesc = tradeStateDesc; - } - /** * 通过xml组装coupons属性内容 */ @@ -402,6 +254,9 @@ public void composeCoupons() { } } + @Data + @Builder(builderMethodName = "newBuilder") + @AllArgsConstructor public static class Coupon { /** *
    代金券类型
    @@ -438,35 +293,5 @@ public static class Coupon {
          */
         private Integer couponFee;
     
    -    public Coupon(String couponType, String couponId, Integer couponFee) {
    -      this.couponType = couponType;
    -      this.couponId = couponId;
    -      this.couponFee = couponFee;
    -    }
    -
    -    public String getCouponType() {
    -      return this.couponType;
    -    }
    -
    -    public void setCouponType(String couponType) {
    -      this.couponType = couponType;
    -    }
    -
    -    public String getCouponId() {
    -      return this.couponId;
    -    }
    -
    -    public void setCouponId(String couponId) {
    -      this.couponId = couponId;
    -    }
    -
    -    public Integer getCouponFee() {
    -      return this.couponFee;
    -    }
    -
    -    public void setCouponFee(Integer couponFee) {
    -      this.couponFee = couponFee;
    -    }
    -
       }
     }
    diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayOrderReverseResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayOrderReverseResult.java
    index c80b72d216..bf36764f6e 100644
    --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayOrderReverseResult.java
    +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayOrderReverseResult.java
    @@ -1,14 +1,21 @@
     package com.github.binarywang.wxpay.bean.result;
     
     import com.thoughtworks.xstream.annotations.XStreamAlias;
    +import lombok.Data;
    +import lombok.EqualsAndHashCode;
    +import lombok.NoArgsConstructor;
     
     /**
      * 
      * 撤销订单响应结果类
      * Created by Binary Wang on 2017-3-23.
    - * @author binarywang(Binary Wang)
      * 
    + * + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor @XStreamAlias("xml") public class WxPayOrderReverseResult extends WxPayBaseResult { @@ -25,11 +32,4 @@ public class WxPayOrderReverseResult extends WxPayBaseResult { @XStreamAlias("recall") private String isRecall; - public String getIsRecall() { - return this.isRecall; - } - - public void setIsRecall(String isRecall) { - this.isRecall = isRecall; - } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayRedpackQueryResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayRedpackQueryResult.java index e0b86732fd..84030f172f 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayRedpackQueryResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayRedpackQueryResult.java @@ -1,6 +1,9 @@ package com.github.binarywang.wxpay.bean.result; import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; /** *
    @@ -12,9 +15,13 @@
      *   类型
      *   说明
      * Created by Binary Wang on 2016-11-28.
    - * @author binarywang(Binary Wang)
      * 
    + * + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor @XStreamAlias("xml") public class WxPayRedpackQueryResult extends WxPayBaseResult { @@ -259,148 +266,4 @@ public class WxPayRedpackQueryResult extends WxPayBaseResult { */ @XStreamAlias("rcv_time") private String receiveTime; - - public String getMchBillNo() { - return mchBillNo; - } - - public void setMchBillNo(String mchBillNo) { - this.mchBillNo = mchBillNo; - } - - public String getDetailId() { - return detailId; - } - - public void setDetailId(String detailId) { - this.detailId = detailId; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getSendType() { - return sendType; - } - - public void setSendType(String sendType) { - this.sendType = sendType; - } - - public String getHbType() { - return hbType; - } - - public void setHbType(String hbType) { - this.hbType = hbType; - } - - public Integer getTotalNum() { - return totalNum; - } - - public void setTotalNum(Integer totalNum) { - this.totalNum = totalNum; - } - - public Integer getTotalAmount() { - return totalAmount; - } - - public void setTotalAmount(Integer totalAmount) { - this.totalAmount = totalAmount; - } - - public String getReason() { - return reason; - } - - public void setReason(String reason) { - this.reason = reason; - } - - public String getSendTime() { - return sendTime; - } - - public void setSendTime(String sendTime) { - this.sendTime = sendTime; - } - - public String getRefundTime() { - return refundTime; - } - - public void setRefundTime(String refundTime) { - this.refundTime = refundTime; - } - - public Integer getRefundAmount() { - return refundAmount; - } - - public void setRefundAmount(Integer refundAmount) { - this.refundAmount = refundAmount; - } - - public String getWishing() { - return wishing; - } - - public void setWishing(String wishing) { - this.wishing = wishing; - } - - public String getRemark() { - return remark; - } - - public void setRemark(String remark) { - this.remark = remark; - } - - public String getActName() { - return actName; - } - - public void setActName(String actName) { - this.actName = actName; - } - - public String getHblist() { - return hblist; - } - - public void setHblist(String hblist) { - this.hblist = hblist; - } - - public String getOpenid() { - return openid; - } - - public void setOpenid(String openid) { - this.openid = openid; - } - - public Integer getAmount() { - return amount; - } - - public void setAmount(Integer amount) { - this.amount = amount; - } - - public String getReceiveTime() { - return receiveTime; - } - - public void setReceiveTime(String receiveTime) { - this.receiveTime = receiveTime; - } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayRefundQueryResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayRefundQueryResult.java index 1916fdb9e7..f97336015a 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayRefundQueryResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayRefundQueryResult.java @@ -2,15 +2,20 @@ import com.google.common.collect.Lists; import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.*; import java.util.List; /** *
      * Created by Binary Wang on 2016-11-24.
    - * @author binarywang(Binary Wang)
      * 
    + * + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor @XStreamAlias("xml") public class WxPayRefundQueryResult extends WxPayBaseResult { /** @@ -111,78 +116,6 @@ public class WxPayRefundQueryResult extends WxPayBaseResult { private List refundRecords; - public String getDeviceInfo() { - return deviceInfo; - } - - public void setDeviceInfo(String deviceInfo) { - this.deviceInfo = deviceInfo; - } - - public String getTransactionId() { - return transactionId; - } - - public void setTransactionId(String transactionId) { - this.transactionId = transactionId; - } - - public String getOutTradeNo() { - return outTradeNo; - } - - public void setOutTradeNo(String outTradeNo) { - this.outTradeNo = outTradeNo; - } - - public Integer getTotalFee() { - return totalFee; - } - - public void setTotalFee(Integer totalFee) { - this.totalFee = totalFee; - } - - public Integer getSettlementTotalFee() { - return settlementTotalFee; - } - - public void setSettlementTotalFee(Integer settlementTotalFee) { - this.settlementTotalFee = settlementTotalFee; - } - - public String getFeeType() { - return feeType; - } - - public void setFeeType(String feeType) { - this.feeType = feeType; - } - - public Integer getCashFee() { - return cashFee; - } - - public void setCashFee(Integer cashFee) { - this.cashFee = cashFee; - } - - public Integer getRefundCount() { - return refundCount; - } - - public void setRefundCount(Integer refundCount) { - this.refundCount = refundCount; - } - - public List getRefundRecords() { - return refundRecords; - } - - public void setRefundRecords(List refundRecords) { - this.refundRecords = refundRecords; - } - /** * 组装生成退款记录属性的内容 */ @@ -203,7 +136,7 @@ public void composeRefundRecords() { refundRecord.setCouponRefundFee(this.getXmlValueAsInt("xml/coupon_refund_fee_" + i)); refundRecord.setCouponRefundCount(this.getXmlValueAsInt("xml/coupon_refund_count_" + i)); refundRecord.setRefundStatus(this.getXmlValue("xml/refund_status_" + i)); - refundRecord.setRefundRecvAccout(this.getXmlValue("xml/refund_recv_accout_" + i)); + refundRecord.setRefundRecvAccount(this.getXmlValue("xml/refund_recv_accout_" + i)); if (refundRecord.getCouponRefundCount() == null || refundRecord.getCouponRefundCount() == 0) { continue; @@ -223,6 +156,10 @@ public void composeRefundRecords() { } } + @Data + @Builder(builderMethodName = "newBuilder") + @NoArgsConstructor + @AllArgsConstructor public static class RefundRecord { /** *
    @@ -371,104 +308,10 @@ public static class RefundRecord {
          * 
    */ @XStreamAlias("refund_recv_accout") - private String refundRecvAccout; - - public String getOutRefundNo() { - return outRefundNo; - } - - public void setOutRefundNo(String outRefundNo) { - this.outRefundNo = outRefundNo; - } - - public String getRefundId() { - return refundId; - } - - public void setRefundId(String refundId) { - this.refundId = refundId; - } - - public String getRefundChannel() { - return refundChannel; - } - - public void setRefundChannel(String refundChannel) { - this.refundChannel = refundChannel; - } - - public Integer getRefundFee() { - return refundFee; - } - - public void setRefundFee(Integer refundFee) { - this.refundFee = refundFee; - } - - public Integer getSettlementRefundFee() { - return settlementRefundFee; - } - - public void setSettlementRefundFee(Integer settlementRefundFee) { - this.settlementRefundFee = settlementRefundFee; - } - - public String getRefundAccount() { - return refundAccount; - } - - public void setRefundAccount(String refundAccount) { - this.refundAccount = refundAccount; - } - - public String getCouponType() { - return couponType; - } - - public void setCouponType(String couponType) { - this.couponType = couponType; - } - - public Integer getCouponRefundFee() { - return couponRefundFee; - } - - public void setCouponRefundFee(Integer couponRefundFee) { - this.couponRefundFee = couponRefundFee; - } - - public Integer getCouponRefundCount() { - return couponRefundCount; - } - - public void setCouponRefundCount(Integer couponRefundCount) { - this.couponRefundCount = couponRefundCount; - } - - public List getRefundCoupons() { - return refundCoupons; - } - - public void setRefundCoupons(List refundCoupons) { - this.refundCoupons = refundCoupons; - } - - public String getRefundStatus() { - return refundStatus; - } - - public void setRefundStatus(String refundStatus) { - this.refundStatus = refundStatus; - } - - public String getRefundRecvAccout() { - return refundRecvAccout; - } - - public void setRefundRecvAccout(String refundRecvAccout) { - this.refundRecvAccout = refundRecvAccout; - } + private String refundRecvAccount; + @Data + @NoArgsConstructor public static class RefundCoupon { /** *
    @@ -516,12 +359,6 @@ public RefundCoupon(String couponRefundId, Integer couponRefundFee) {
             this.couponRefundFee = couponRefundFee;
           }
     
    -      @Deprecated
    -      public RefundCoupon(String couponRefundBatchId, String couponRefundId, Integer couponRefundFee) {
    -        this.couponRefundBatchId = couponRefundBatchId;
    -        this.couponRefundId = couponRefundId;
    -        this.couponRefundFee = couponRefundFee;
    -      }
         }
     
       }
    diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayRefundResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayRefundResult.java
    index 1e6126b210..2da31a3798 100644
    --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayRefundResult.java
    +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayRefundResult.java
    @@ -1,6 +1,9 @@
     package com.github.binarywang.wxpay.bean.result;
     
     import com.thoughtworks.xstream.annotations.XStreamAlias;
    +import lombok.Data;
    +import lombok.EqualsAndHashCode;
    +import lombok.NoArgsConstructor;
     
     import java.io.Serializable;
     
    @@ -12,6 +15,9 @@
      *
      * @author liukaitj
      */
    +@Data
    +@EqualsAndHashCode(callSuper = true)
    +@NoArgsConstructor
     @XStreamAlias("xml")
     public class WxPayRefundResult extends WxPayBaseResult implements Serializable {
       private static final long serialVersionUID = 1L;
    @@ -58,116 +64,4 @@ public class WxPayRefundResult extends WxPayBaseResult implements Serializable {
       @XStreamAlias("coupon_refund_id")
       private String couponRefundId;
     
    -  public String getDeviceInfo() {
    -    return this.deviceInfo;
    -  }
    -
    -  public void setDeviceInfo(String deviceInfo) {
    -    this.deviceInfo = deviceInfo;
    -  }
    -
    -  public String getTransactionId() {
    -    return this.transactionId;
    -  }
    -
    -  public void setTransactionId(String transactionId) {
    -    this.transactionId = transactionId;
    -  }
    -
    -  public String getOutTradeNo() {
    -    return this.outTradeNo;
    -  }
    -
    -  public void setOutTradeNo(String outTradeNo) {
    -    this.outTradeNo = outTradeNo;
    -  }
    -
    -  public String getOutRefundNo() {
    -    return this.outRefundNo;
    -  }
    -
    -  public void setOutRefundNo(String outRefundNo) {
    -    this.outRefundNo = outRefundNo;
    -  }
    -
    -  public String getRefundId() {
    -    return this.refundId;
    -  }
    -
    -  public void setRefundId(String refundId) {
    -    this.refundId = refundId;
    -  }
    -
    -  public String getRefundChannel() {
    -    return this.refundChannel;
    -  }
    -
    -  public void setRefundChannel(String refundChannel) {
    -    this.refundChannel = refundChannel;
    -  }
    -
    -  public String getRefundFee() {
    -    return this.refundFee;
    -  }
    -
    -  public void setRefundFee(String refundFee) {
    -    this.refundFee = refundFee;
    -  }
    -
    -  public String getTotalFee() {
    -    return this.totalFee;
    -  }
    -
    -  public void setTotalFee(String totalFee) {
    -    this.totalFee = totalFee;
    -  }
    -
    -  public String getFeeType() {
    -    return this.feeType;
    -  }
    -
    -  public void setFeeType(String feeType) {
    -    this.feeType = feeType;
    -  }
    -
    -  public String getCashFee() {
    -    return this.cashFee;
    -  }
    -
    -  public void setCashFee(String cashFee) {
    -    this.cashFee = cashFee;
    -  }
    -
    -  public String getCashRefundFee() {
    -    return this.cashRefundFee;
    -  }
    -
    -  public void setCashRefundFee(String cashRefundFee) {
    -    this.cashRefundFee = cashRefundFee;
    -  }
    -
    -  public String getCouponRefundFee() {
    -    return this.couponRefundFee;
    -  }
    -
    -  public void setCouponRefundFee(String couponRefundFee) {
    -    this.couponRefundFee = couponRefundFee;
    -  }
    -
    -  public String getCouponRefundCount() {
    -    return this.couponRefundCount;
    -  }
    -
    -  public void setCouponRefundCount(String couponRefundCount) {
    -    this.couponRefundCount = couponRefundCount;
    -  }
    -
    -  public String getCouponRefundId() {
    -    return this.couponRefundId;
    -  }
    -
    -  public void setCouponRefundId(String couponRefundId) {
    -    this.couponRefundId = couponRefundId;
    -  }
    -
     }
    diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPaySandboxSignKeyResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPaySandboxSignKeyResult.java
    index 6326f694d3..792e00fdeb 100644
    --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPaySandboxSignKeyResult.java
    +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPaySandboxSignKeyResult.java
    @@ -1,6 +1,9 @@
     package com.github.binarywang.wxpay.bean.result;
     
     import com.thoughtworks.xstream.annotations.XStreamAlias;
    +import lombok.Data;
    +import lombok.EqualsAndHashCode;
    +import lombok.NoArgsConstructor;
     
     /**
      * 
    @@ -9,6 +12,9 @@
      *
      * @author Binary Wang
      */
    +@Data
    +@EqualsAndHashCode(callSuper = true)
    +@NoArgsConstructor
     @XStreamAlias("xml")
     public class WxPaySandboxSignKeyResult extends WxPayBaseResult {
     
    @@ -25,11 +31,4 @@ public class WxPaySandboxSignKeyResult extends WxPayBaseResult {
       @XStreamAlias("sandbox_signkey")
       private String sandboxSignKey;
     
    -  public String getSandboxSignKey() {
    -    return sandboxSignKey;
    -  }
    -
    -  public void setSandboxSignKey(String sandboxSignKey) {
    -    this.sandboxSignKey = sandboxSignKey;
    -  }
     }
    diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPaySendRedpackResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPaySendRedpackResult.java
    index 868f089b74..560721f5a8 100644
    --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPaySendRedpackResult.java
    +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPaySendRedpackResult.java
    @@ -1,6 +1,9 @@
     package com.github.binarywang.wxpay.bean.result;
     
     import com.thoughtworks.xstream.annotations.XStreamAlias;
    +import lombok.Data;
    +import lombok.EqualsAndHashCode;
    +import lombok.NoArgsConstructor;
     
     import java.io.Serializable;
     
    @@ -10,6 +13,9 @@
      *
      * @author kane
      */
    +@Data
    +@EqualsAndHashCode(callSuper = true)
    +@NoArgsConstructor
     @XStreamAlias("xml")
     public class WxPaySendRedpackResult extends WxPayBaseResult implements Serializable {
       private static final long serialVersionUID = -4837415036337132073L;
    @@ -32,51 +38,4 @@ public class WxPaySendRedpackResult extends WxPayBaseResult implements Serializa
       @XStreamAlias("send_listid")
       private String sendListid;
     
    -  public String getMchBillno() {
    -    return this.mchBillno;
    -  }
    -
    -  public void setMchBillno(String mchBillno) {
    -    this.mchBillno = mchBillno;
    -  }
    -
    -  public String getWxappid() {
    -    return this.wxappid;
    -  }
    -
    -  public void setWxappid(String wxappid) {
    -    this.wxappid = wxappid;
    -  }
    -
    -  public String getReOpenid() {
    -    return this.reOpenid;
    -  }
    -
    -  public void setReOpenid(String reOpenid) {
    -    this.reOpenid = reOpenid;
    -  }
    -
    -  public int getTotalAmount() {
    -    return this.totalAmount;
    -  }
    -
    -  public void setTotalAmount(int totalAmount) {
    -    this.totalAmount = totalAmount;
    -  }
    -
    -  public String getSendTime() {
    -    return this.sendTime;
    -  }
    -
    -  public void setSendTime(String sendTime) {
    -    this.sendTime = sendTime;
    -  }
    -
    -  public String getSendListid() {
    -    return this.sendListid;
    -  }
    -
    -  public void setSendListid(String sendListid) {
    -    this.sendListid = sendListid;
    -  }
     }
    diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayShorturlResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayShorturlResult.java
    index 2f93cb81bf..93e74a0cce 100644
    --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayShorturlResult.java
    +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayShorturlResult.java
    @@ -1,14 +1,21 @@
     package com.github.binarywang.wxpay.bean.result;
     
     import com.thoughtworks.xstream.annotations.XStreamAlias;
    +import lombok.Data;
    +import lombok.EqualsAndHashCode;
    +import lombok.NoArgsConstructor;
     
     /**
      * 
      * 转换短链接结果对象类
      * Created by Binary Wang on 2017-3-27.
    - * @author binarywang(Binary Wang)
      * 
    + * + * @author Binary Wang */ +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor @XStreamAlias("xml") public class WxPayShorturlResult extends WxPayBaseResult { /** @@ -24,11 +31,4 @@ public class WxPayShorturlResult extends WxPayBaseResult { @XStreamAlias("short_url") private String shortUrl; - public String getShortUrl() { - return this.shortUrl; - } - - public void setShortUrl(String shortUrl) { - this.shortUrl = shortUrl; - } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderResult.java index d8ab2ab6df..4f25421fc2 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderResult.java @@ -1,6 +1,9 @@ package com.github.binarywang.wxpay.bean.result; import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; /** *
    @@ -10,6 +13,9 @@
      *
      * @author chanjarster
      */
    +@Data
    +@EqualsAndHashCode(callSuper = true)
    +@NoArgsConstructor
     @XStreamAlias("xml")
     public class WxPayUnifiedOrderResult extends WxPayBaseResult {
     
    @@ -37,35 +43,4 @@ public class WxPayUnifiedOrderResult extends WxPayBaseResult {
       @XStreamAlias("code_url")
       private String codeURL;
     
    -  public String getPrepayId() {
    -    return this.prepayId;
    -  }
    -
    -  public void setPrepayId(String prepayId) {
    -    this.prepayId = prepayId;
    -  }
    -
    -  public String getTradeType() {
    -    return this.tradeType;
    -  }
    -
    -  public void setTradeType(String tradeType) {
    -    this.tradeType = tradeType;
    -  }
    -
    -  public String getCodeURL() {
    -    return this.codeURL;
    -  }
    -
    -  public void setCodeURL(String codeURL) {
    -    this.codeURL = codeURL;
    -  }
    -
    -  public String getMwebUrl() {
    -    return mwebUrl;
    -  }
    -
    -  public void setMwebUrl(String mwebUrl) {
    -    this.mwebUrl = mwebUrl;
    -  }
     }
    diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java
    index 7d8cd5e1e3..684073d0af 100644
    --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java
    +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java
    @@ -36,6 +36,7 @@ public class WxPayConfig {
       private String subMchId;
       private String notifyUrl;
       private String tradeType;
    +  private String signType;
       private SSLContext sslContext;
       private String keyPath;
       private boolean useSandboxEnv = false;
    @@ -139,6 +140,19 @@ public void setTradeType(String tradeType) {
         this.tradeType = tradeType;
       }
     
    +  /**
    +   * 签名方式
    +   * 有两种HMAC_SHA256 和MD5
    +   * @see com.github.binarywang.wxpay.constant.WxPayConstants.SignType
    +   */
    +  public String getSignType() {
    +    return this.signType;
    +  }
    +
    +  public void setSignType(String signType) {
    +    this.signType = signType;
    +  }
    +
       public SSLContext getSslContext() {
         return this.sslContext;
       }
    diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/constant/WxPayConstants.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/constant/WxPayConstants.java
    index 47f636d0fc..8e9eea95fc 100644
    --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/constant/WxPayConstants.java
    +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/constant/WxPayConstants.java
    @@ -1,6 +1,9 @@
     package com.github.binarywang.wxpay.constant;
     
    +import com.google.common.collect.Lists;
    +
     import java.text.SimpleDateFormat;
    +import java.util.List;
     
     /**
      * 
    @@ -96,9 +99,9 @@ public static class TradeType {
       public static class SignType {
         public static final String HMAC_SHA256 = "HMAC-SHA256";
         public static final String MD5 = "MD5";
    +    public static final List ALL_SIGN_TYPES = Lists.newArrayList(HMAC_SHA256, MD5);
       }
     
    -
       /**
        * 限定支付方式
        */
    @@ -108,4 +111,170 @@ public static class LimitPay {
          */
         public static final String NO_CREDIT = "no_credit";
       }
    +
    +  /**
    +   * 业务结果代码
    +   */
    +  public static class ResultCode {
    +    /**
    +     * 成功
    +     */
    +    public static final String SUCCESS = "SUCCESS";
    +
    +    /**
    +     * 失败
    +     */
    +    public static final String FAIL = "FAIL";
    +  }
    +
    +  /**
    +   * 退款资金来源
    +   */
    +  public static class RefundAccountSource {
    +    /**
    +     * 可用余额退款/基本账户
    +     */
    +    public static final String RECHARGE_FUNDS = "REFUND_SOURCE_RECHARGE_FUNDS";
    +
    +    /**
    +     * 未结算资金退款
    +     */
    +    public static final String UNSETTLED_FUNDS = "REFUND_SOURCE_UNSETTLED_FUNDS";
    +
    +  }
    +
    +  /**
    +   * 退款渠道
    +   */
    +  public static class RefundChannel {
    +    /**
    +     * 原路退款
    +     */
    +    public static final String ORIGINAL = "ORIGINAL";
    +
    +    /**
    +     * 退回到余额
    +     */
    +    public static final String BALANCE = "BALANCE";
    +
    +    /**
    +     * 原账户异常退到其他余额账户
    +     */
    +    public static final String OTHER_BALANCE = "OTHER_BALANCE";
    +
    +    /**
    +     * 原银行卡异常退到其他银行卡
    +     */
    +    public static final String OTHER_BANKCARD = "OTHER_BANKCARD";
    +  }
    +
    +  /**
    +   * 交易状态
    +   */
    +  public static class WxpayTradeStatus {
    +    /**
    +     * 支付成功
    +     */
    +    public static final String SUCCESS = "SUCCESS";
    +
    +    /**
    +     * 支付失败(其他原因,如银行返回失败)
    +     */
    +    public static final String PAY_ERROR = "PAYERROR";
    +
    +    /**
    +     * 用户支付中
    +     */
    +    public static final String USER_PAYING = "USERPAYING";
    +
    +    /**
    +     * 已关闭
    +     */
    +    public static final String CLOSED = "CLOSED";
    +
    +    /**
    +     * 未支付
    +     */
    +    public static final String NOTPAY = "NOTPAY";
    +
    +    /**
    +     * 转入退款
    +     */
    +    public static final String REFUND = "REFUND";
    +
    +    /**
    +     * 已撤销(刷卡支付)
    +     */
    +    public static final String REVOKED = "REVOKED";
    +  }
    +
    +  /**
    +   * 退款状态
    +   */
    +  public static class RefundStatus {
    +    /**
    +     * 退款成功
    +     */
    +    public static final String SUCCESS = "SUCCESS";
    +
    +    /**
    +     * 退款关闭
    +     */
    +    public static final String REFUND_CLOSE = "REFUNDCLOSE";
    +
    +    /**
    +     * 退款处理中
    +     */
    +    public static final String PROCESSING = "PROCESSING";
    +
    +    /**
    +     * 退款异常,退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,可前往商户平台(pay.weixin.qq.com)-交易中心,手动处理此笔退款。
    +     */
    +    public static final String CHANGE = "CHANGE";
    +  }
    +
    +  /**
    +   * 关闭订单结果错误代码
    +   */
    +  public static class OrderCloseResultErrorCode {
    +    /**
    +     * 订单已支付
    +     */
    +    public static final String ORDER_PAID = "ORDERPAID";
    +
    +    /**
    +     * 系统错误
    +     */
    +    public static final String SYSTEM_ERROR = "SYSTEMERROR";
    +
    +    /**
    +     * 订单不存在
    +     */
    +    public static final String ORDER_NOT_EXIST = "ORDERNOTEXIST";
    +
    +    /**
    +     * 订单已关闭
    +     */
    +    public static final String ORDER_CLOSED = "ORDERCLOSED";
    +
    +    /**
    +     * 签名错误
    +     */
    +    public static final String SIGN_ERROR = "SIGNERROR";
    +
    +    /**
    +     * 未使用POST传递参数
    +     */
    +    public static final String REQUIRE_POST_METHOD = "REQUIRE_POST_METHOD";
    +
    +    /**
    +     * XML格式错误
    +     */
    +    public static final String XML_FORMAT_ERROR = "XML_FORMAT_ERROR";
    +
    +    /**
    +     * 订单状态错误
    +     */
    +    public static final String TRADE_STATE_ERROR = "TRADE_STATE_ERROR";
    +  }
     }
    diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java
    index ae058e1478..33cd56c6c9 100644
    --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java
    +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java
    @@ -19,7 +19,7 @@
      * Created by Binary Wang on 2016/7/28.
      * 
    * - * @author binarywang (https://github.com/binarywang) + * @author Binary Wang */ public interface WxPayService { @@ -56,6 +56,15 @@ public interface WxPayService { */ WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxPayException; + /** + * 调用统一下单接口,并组装生成支付所需参数对象 + * + * @param request 统一下单请求参数 + * @param 请使用{@link com.github.binarywang.wxpay.bean.order}包下的类 + * @return 返回 {@link com.github.binarywang.wxpay.bean.order}包下的类对象 + */ + T createOrder(WxPayUnifiedOrderRequest request) throws WxPayException; + /** * 统一下单(详见https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1) * 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识" @@ -70,7 +79,9 @@ public interface WxPayService { * 详见https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=8_5 * * @param request 请求对象,注意一些参数如appid、mchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置) + * @deprecated 建议使用 {@link com.github.binarywang.wxpay.service.WxPayService#createOrder(WxPayUnifiedOrderRequest)} */ + @Deprecated Map getPayInfo(WxPayUnifiedOrderRequest request) throws WxPayException; /** @@ -117,7 +128,7 @@ WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, Stri /** * @see WxPayService#parseOrderNotifyResult(String) - * @deprecated use WxPayService#parseOrderNotifyResult(String) instead + * @deprecated use {@link WxPayService#parseOrderNotifyResult(String)} instead */ @Deprecated WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxPayException; @@ -403,6 +414,7 @@ WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, Stri * 是否需要证书:需要 * 文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_17&index=10 *
    + * * @param beginDate 开始时间 * @param endDate 结束时间 * @param offset 位移 diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceAbstractImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceAbstractImpl.java index e77d3e1fc8..0eccb7272a 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceAbstractImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceAbstractImpl.java @@ -72,12 +72,12 @@ private String getPayBaseUrl() { @Override public WxPayRefundResult refund(WxPayRefundRequest request) throws WxPayException { - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = this.getPayBaseUrl() + "/secapi/pay/refund"; String responseContent = this.post(url, request.toXML(), true); WxPayRefundResult result = WxPayBaseResult.fromXML(responseContent, WxPayRefundResult.class); - result.checkResult(this); + result.checkResult(this, request.getSignType(), true); return result; } @@ -90,13 +90,13 @@ public WxPayRefundQueryResult refundQuery(String transactionId, String outTradeN request.setOutRefundNo(StringUtils.trimToNull(outRefundNo)); request.setRefundId(StringUtils.trimToNull(refundId)); - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = this.getPayBaseUrl() + "/pay/refundquery"; String responseContent = this.post(url, request.toXML(), false); WxPayRefundQueryResult result = WxPayBaseResult.fromXML(responseContent, WxPayRefundQueryResult.class); result.composeRefundRecords(); - result.checkResult(this); + result.checkResult(this, request.getSignType(), true); return result; } @@ -112,7 +112,7 @@ public WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData) throws WxPa log.debug("微信支付异步通知请求参数:{}", xmlData); WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlData); log.debug("微信支付异步通知请求解析后的对象:{}", result); - result.checkResult(this); + result.checkResult(this, null, false); return result; } catch (WxPayException e) { log.error(e.getMessage(), e); @@ -138,7 +138,7 @@ public WxPayRefundNotifyResult parseRefundNotifyResult(String xmlData) throws Wx @Override public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException { - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = this.getPayBaseUrl() + "/mmpaymkttransfers/sendredpack"; if (request.getAmtType() != null) { @@ -147,10 +147,8 @@ public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throw } String responseContent = this.post(url, request.toXML(), true); - WxPaySendRedpackResult result = WxPayBaseResult.fromXML(responseContent, WxPaySendRedpackResult.class); - //毋须校验,因为没有返回签名信息 - // this.checkResult(result); - return result; + //无需校验,因为没有返回签名信息 + return WxPayBaseResult.fromXML(responseContent, WxPaySendRedpackResult.class); } @Override @@ -158,12 +156,12 @@ public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayExcept WxPayRedpackQueryRequest request = new WxPayRedpackQueryRequest(); request.setMchBillNo(mchBillNo); request.setBillType(BillType.MCHT); - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = this.getPayBaseUrl() + "/mmpaymkttransfers/gethbinfo"; String responseContent = this.post(url, request.toXML(), true); WxPayRedpackQueryResult result = WxPayBaseResult.fromXML(responseContent, WxPayRedpackQueryResult.class); - result.checkResult(this); + result.checkResult(this, request.getSignType(), true); return result; } @@ -172,7 +170,7 @@ public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) WxPayOrderQueryRequest request = new WxPayOrderQueryRequest(); request.setOutTradeNo(StringUtils.trimToNull(outTradeNo)); request.setTransactionId(StringUtils.trimToNull(transactionId)); - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = this.getPayBaseUrl() + "/pay/orderquery"; String responseContent = this.post(url, request.toXML(), false); @@ -182,7 +180,7 @@ public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) WxPayOrderQueryResult result = WxPayBaseResult.fromXML(responseContent, WxPayOrderQueryResult.class); result.composeCoupons(); - result.checkResult(this); + result.checkResult(this, request.getSignType(), true); return result; } @@ -194,16 +192,17 @@ public WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxPayException WxPayOrderCloseRequest request = new WxPayOrderCloseRequest(); request.setOutTradeNo(StringUtils.trimToNull(outTradeNo)); - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = this.getPayBaseUrl() + "/pay/closeorder"; String responseContent = this.post(url, request.toXML(), false); WxPayOrderCloseResult result = WxPayBaseResult.fromXML(responseContent, WxPayOrderCloseResult.class); - result.checkResult(this); + result.checkResult(this, request.getSignType(), true); return result; } + @Override public T createOrder(WxPayUnifiedOrderRequest request) throws WxPayException { WxPayUnifiedOrderResult unifiedOrderResult = this.unifiedOrder(request); String prepayId = unifiedOrderResult.getPrepayId(); @@ -214,13 +213,13 @@ public T createOrder(WxPayUnifiedOrderRequest request) throws WxPayException String timestamp = String.valueOf(System.currentTimeMillis() / 1000); String nonceStr = String.valueOf(System.currentTimeMillis()); - Object payResult = null; switch (request.getTradeType()) { case TradeType.NATIVE: { - payResult = WxPayNativeOrderResult.newBuilder().codeUrl(unifiedOrderResult.getCodeURL()) + return (T) WxPayNativeOrderResult.builder() + .codeUrl(unifiedOrderResult.getCodeURL()) .build(); - break; } + case TradeType.APP: { // APP支付绑定的是微信开放平台上的账号,APPID为开放平台上绑定APP后发放的参数 String appId = this.getConfig().getAppId(); @@ -235,8 +234,8 @@ public T createOrder(WxPayUnifiedOrderRequest request) throws WxPayException configMap.put("noncestr", nonceStr); configMap.put("appid", appId); - payResult = WxPayAppOrderResult.newBuilder() - .sign(SignUtils.createSign(configMap, this.getConfig().getMchKey(), null)) + return (T) WxPayAppOrderResult.builder() + .sign(SignUtils.createSign(configMap, null, this.getConfig().getMchKey(), false)) .prepayId(prepayId) .partnerId(partnerId) .appId(appId) @@ -244,37 +243,48 @@ public T createOrder(WxPayUnifiedOrderRequest request) throws WxPayException .timeStamp(timestamp) .nonceStr(nonceStr) .build(); - break; } + case TradeType.JSAPI: { - payResult = WxPayMpOrderResult.newBuilder() + String signType = SignType.MD5; + WxPayMpOrderResult payResult = WxPayMpOrderResult.builder() .appId(unifiedOrderResult.getAppid()) .timeStamp(timestamp) .nonceStr(nonceStr) .packageValue("prepay_id=" + prepayId) - .signType(SignType.MD5) + .signType(signType) .build(); - ((WxPayMpOrderResult) payResult) - .setPaySign(SignUtils.createSign(payResult, this.getConfig().getMchKey(), null)); - break; + + payResult.setPaySign( + SignUtils.createSign( + payResult, + signType, + this.getConfig().getMchKey(), + false) + ); + return (T) payResult; + } + + default: { + throw new WxPayException("该交易类型暂不支持"); } } - return (T) payResult; } @Override public WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) throws WxPayException { - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = this.getPayBaseUrl() + "/pay/unifiedorder"; String responseContent = this.post(url, request.toXML(), false); WxPayUnifiedOrderResult result = WxPayBaseResult.fromXML(responseContent, WxPayUnifiedOrderResult.class); - result.checkResult(this); + result.checkResult(this, request.getSignType(), true); return result; } @Override + @Deprecated public Map getPayInfo(WxPayUnifiedOrderRequest request) throws WxPayException { WxPayUnifiedOrderResult unifiedOrderResult = this.unifiedOrder(request); String prepayId = unifiedOrderResult.getPrepayId(); @@ -302,7 +312,7 @@ public Map getPayInfo(WxPayUnifiedOrderRequest request) throws W configMap.put("noncestr", nonceStr); configMap.put("appid", appId); // 此map用于客户端与微信服务器交互 - payInfo.put("sign", SignUtils.createSign(configMap, this.getConfig().getMchKey(), null)); + payInfo.put("sign", SignUtils.createSign(configMap, null, this.getConfig().getMchKey(), false)); payInfo.put("prepayId", prepayId); payInfo.put("partnerId", partnerId); payInfo.put("appId", appId); @@ -316,7 +326,7 @@ public Map getPayInfo(WxPayUnifiedOrderRequest request) throws W payInfo.put("nonceStr", nonceStr); payInfo.put("package", "prepay_id=" + prepayId); payInfo.put("signType", SignType.MD5); - payInfo.put("paySign", SignUtils.createSign(payInfo, this.getConfig().getMchKey(), null)); + payInfo.put("paySign", SignUtils.createSign(payInfo, null, this.getConfig().getMchKey(), false)); } return payInfo; @@ -324,12 +334,12 @@ public Map getPayInfo(WxPayUnifiedOrderRequest request) throws W @Override public WxEntPayResult entPay(WxEntPayRequest request) throws WxPayException { - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = this.getPayBaseUrl() + "/mmpaymkttransfers/promotion/transfers"; String responseContent = this.post(url, request.toXML(), true); WxEntPayResult result = WxPayBaseResult.fromXML(responseContent, WxEntPayResult.class); - result.checkResult(this); + result.checkResult(this, request.getSignType(), true); return result; } @@ -337,12 +347,12 @@ public WxEntPayResult entPay(WxEntPayRequest request) throws WxPayException { public WxEntPayQueryResult queryEntPay(String partnerTradeNo) throws WxPayException { WxEntPayQueryRequest request = new WxEntPayQueryRequest(); request.setPartnerTradeNo(partnerTradeNo); - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = this.getPayBaseUrl() + "/mmpaymkttransfers/gettransferinfo"; String responseContent = this.post(url, request.toXML(), true); WxEntPayQueryResult result = WxPayBaseResult.fromXML(responseContent, WxEntPayQueryResult.class); - result.checkResult(this); + result.checkResult(this, request.getSignType(), true); return result; } @@ -363,7 +373,7 @@ public String createScanPayQrcodeMode1(String productId) { params.put("time_stamp", String.valueOf(System.currentTimeMillis() / 1000));//这里需要秒,10位数字 params.put("nonce_str", String.valueOf(System.currentTimeMillis())); - String sign = SignUtils.createSign(params, this.getConfig().getMchKey(), null); + String sign = SignUtils.createSign(params, null, this.getConfig().getMchKey(), false); params.put("sign", sign); for (String key : params.keySet()) { @@ -388,13 +398,14 @@ private byte[] createQrcode(String content, File logoFile, Integer sideLength) { return QrcodeUtils.createQrcode(content, sideLength, logoFile); } + @Override public void report(WxPayReportRequest request) throws WxPayException { - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = this.getPayBaseUrl() + "/payitil/report"; String responseContent = this.post(url, request.toXML(), false); WxPayCommonResult result = WxPayBaseResult.fromXML(responseContent, WxPayCommonResult.class); - result.checkResult(this); + result.checkResult(this, request.getSignType(), true); } @Override @@ -405,15 +416,15 @@ public WxPayBillResult downloadBill(String billDate, String billType, String tar request.setTarType(tarType); request.setDeviceInfo(deviceInfo); - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = this.getPayBaseUrl() + "/pay/downloadbill"; String responseContent = this.post(url, request.toXML(), false); if (responseContent.startsWith("<")) { throw WxPayException.from(WxPayBaseResult.fromXML(responseContent, WxPayCommonResult.class)); - } else { - return this.handleBillInformation(responseContent); } + + return this.handleBillInformation(responseContent); } private WxPayBillResult handleBillInformation(String responseContent) { @@ -446,7 +457,7 @@ private WxPayBillResult handleBillInformation(String responseContent) { wxPayBillBaseResult.setMchId(tempStr[k + 2].trim()); wxPayBillBaseResult.setSubMchId(tempStr[k + 3].trim()); wxPayBillBaseResult.setDeviceInfo(tempStr[k + 4].trim()); - wxPayBillBaseResult.setTransationId(tempStr[k + 5].trim()); + wxPayBillBaseResult.setTransactionId(tempStr[k + 5].trim()); wxPayBillBaseResult.setOutTradeNo(tempStr[k + 6].trim()); wxPayBillBaseResult.setOpenId(tempStr[k + 7].trim()); wxPayBillBaseResult.setTradeType(tempStr[k + 8].trim()); @@ -487,34 +498,34 @@ private WxPayBillResult handleBillInformation(String responseContent) { @Override public WxPayMicropayResult micropay(WxPayMicropayRequest request) throws WxPayException { - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = this.getPayBaseUrl() + "/pay/micropay"; String responseContent = this.post(url, request.toXML(), false); WxPayMicropayResult result = WxPayBaseResult.fromXML(responseContent, WxPayMicropayResult.class); - result.checkResult(this); + result.checkResult(this, request.getSignType(), true); return result; } @Override public WxPayOrderReverseResult reverseOrder(WxPayOrderReverseRequest request) throws WxPayException { - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = this.getPayBaseUrl() + "/secapi/pay/reverse"; String responseContent = this.post(url, request.toXML(), true); WxPayOrderReverseResult result = WxPayBaseResult.fromXML(responseContent, WxPayOrderReverseResult.class); - result.checkResult(this); + result.checkResult(this, request.getSignType(), true); return result; } @Override public String shorturl(WxPayShorturlRequest request) throws WxPayException { - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = this.getPayBaseUrl() + "/tools/shorturl"; String responseContent = this.post(url, request.toXML(), false); WxPayShorturlResult result = WxPayBaseResult.fromXML(responseContent, WxPayShorturlResult.class); - result.checkResult(this); + result.checkResult(this, request.getSignType(), true); return result.getShortUrl(); } @@ -525,12 +536,12 @@ public String shorturl(String longUrl) throws WxPayException { @Override public String authcode2Openid(WxPayAuthcode2OpenidRequest request) throws WxPayException { - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = this.getPayBaseUrl() + "/tools/authcodetoopenid"; String responseContent = this.post(url, request.toXML(), false); WxPayAuthcode2OpenidResult result = WxPayBaseResult.fromXML(responseContent, WxPayAuthcode2OpenidResult.class); - result.checkResult(this); + result.checkResult(this, request.getSignType(), true); return result.getOpenid(); } @@ -542,45 +553,45 @@ public String authcode2Openid(String authCode) throws WxPayException { @Override public String getSandboxSignKey() throws WxPayException { WxPayDefaultRequest request = new WxPayDefaultRequest(); - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = "https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey"; String responseContent = this.post(url, request.toXML(), false); WxPaySandboxSignKeyResult result = WxPayBaseResult.fromXML(responseContent, WxPaySandboxSignKeyResult.class); - result.checkResult(this); + result.checkResult(this, request.getSignType(), true); return result.getSandboxSignKey(); } @Override public WxPayCouponSendResult sendCoupon(WxPayCouponSendRequest request) throws WxPayException { - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = this.getPayBaseUrl() + "/mmpaymkttransfers/send_coupon"; String responseContent = this.post(url, request.toXML(), true); WxPayCouponSendResult result = WxPayBaseResult.fromXML(responseContent, WxPayCouponSendResult.class); - result.checkResult(this); + result.checkResult(this, request.getSignType(), true); return result; } @Override public WxPayCouponStockQueryResult queryCouponStock(WxPayCouponStockQueryRequest request) throws WxPayException { - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = this.getPayBaseUrl() + "/mmpaymkttransfers/query_coupon_stock"; String responseContent = this.post(url, request.toXML(), false); WxPayCouponStockQueryResult result = WxPayBaseResult.fromXML(responseContent, WxPayCouponStockQueryResult.class); - result.checkResult(this); + result.checkResult(this, request.getSignType(), true); return result; } @Override public WxPayCouponInfoQueryResult queryCouponInfo(WxPayCouponInfoQueryRequest request) throws WxPayException { - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), false); String url = this.getPayBaseUrl() + "/mmpaymkttransfers/querycouponsinfo"; String responseContent = this.post(url, request.toXML(), false); WxPayCouponInfoQueryResult result = WxPayBaseResult.fromXML(responseContent, WxPayCouponInfoQueryResult.class); - result.checkResult(this); + result.checkResult(this, request.getSignType(), true); return result; } @@ -604,7 +615,7 @@ public String queryComment(Date beginDate, Date endDate, Integer offset, Integer request.setLimit(limit); request.setSignType(SignType.HMAC_SHA256); - request.checkAndSign(this.getConfig()); + request.checkAndSign(this.getConfig(), true); String url = this.getPayBaseUrl() + "/billcommentsp/batchquerycomment"; diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java index 1b3284f95f..653c1a8d6e 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java @@ -27,7 +27,7 @@ * Created by Binary Wang on 2016/7/28. *
    * - * @author binarywang (https://github.com/binarywang) + * @author Binary Wang */ public class WxPayServiceApacheHttpImpl extends WxPayServiceAbstractImpl { diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java index bbe024a309..b342c5cda8 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java @@ -18,7 +18,7 @@ * 微信支付请求实现类,jodd-http实现 * Created by Binary Wang on 2016/7/28. * - * @author binarywang (https://github.com/binarywang) + * @author Binary Wang */ public class WxPayServiceJoddHttpImpl extends WxPayServiceAbstractImpl { diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/SignUtils.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/SignUtils.java index b13175a724..efb9d85604 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/SignUtils.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/SignUtils.java @@ -1,10 +1,13 @@ package com.github.binarywang.wxpay.util; import com.github.binarywang.wxpay.constant.WxPayConstants.SignType; +import com.google.common.collect.Lists; import me.chanjar.weixin.common.util.BeanUtils; import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; @@ -16,96 +19,116 @@ /** *
    - * 签名相关工具类
    + * 签名相关工具类.
      * Created by Binary Wang on 2017-3-23.
    - * @author binarywang(Binary Wang)
      * 
    + * + * @author binarywang(Binary Wang) */ public class SignUtils { + private static final Logger log = LoggerFactory.getLogger(SignUtils.class); + + /** + * 请参考并使用 {@link #createSign(Object, String, String, boolean)}. + */ + @Deprecated + public static String createSign(Object xmlBean, String signKey) { + return createSign(BeanUtils.xmlBean2Map(xmlBean), signKey); + } + + /** + * 请参考并使用 {@link #createSign(Map, String, String, boolean)}. + */ + @Deprecated + public static String createSign(Map params, String signKey) { + return createSign(params, null, signKey, false); + } /** - * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) + * 微信支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3). * - * @param xmlBean Bean需要标记有XML注解 - * @param signKey 签名Key - * @param signType 签名类型,如果为空,则默认为MD5 + * @param xmlBean Bean里的属性如果存在XML注解,则使用其作为key,否则使用变量名 + * @param signType 签名类型,如果为空,则默认为MD5 + * @param signKey 签名Key + * @param isIgnoreSignType 签名时,是否忽略signType * @return 签名字符串 */ - public static String createSign(Object xmlBean, String signKey, String signType) { - return createSign(BeanUtils.xmlBean2Map(xmlBean), signKey, signType); + public static String createSign(Object xmlBean, String signType, String signKey, boolean isIgnoreSignType) { + return createSign(BeanUtils.xmlBean2Map(xmlBean), signType, signKey, isIgnoreSignType); } /** - * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) + * 微信支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3). * - * @param params 参数信息 - * @param signKey 签名Key - * @param signType 签名类型,如果为空,则默认为md5 + * @param params 参数信息 + * @param signType 签名类型,如果为空,则默认为MD5 + * @param signKey 签名Key + * @param ignoreSignType 签名时,是否忽略signType * @return 签名字符串 */ - public static String createSign(Map params, String signKey, String signType) { -// if (this.getConfig().useSandbox()) { -// //使用仿真测试环境 -// //TODO 目前测试发现,以下两行代码都会出问题,所以暂不建议使用仿真测试环境 -// signKey = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456"; -// //return "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456"; -// } - + public static String createSign(Map params, String signType, String signKey, boolean ignoreSignType) { SortedMap sortedMap = new TreeMap<>(params); StringBuilder toSign = new StringBuilder(); for (String key : sortedMap.keySet()) { String value = params.get(key); - if (StringUtils.isNotEmpty(value) - && !StringUtils.equalsAny(key, "sign", "key", "sign_type")) { + boolean shouldSign = false; + if (ignoreSignType && "sign_type".equals(key)) { + shouldSign = false; + } else if (StringUtils.isNotEmpty(value) + && !Lists.newArrayList("sign", "key", "xmlString", "xmlDoc", "couponList").contains(key)) { + shouldSign = true; + } + + if (shouldSign) { toSign.append(key).append("=").append(value).append("&"); } } toSign.append("key=").append(signKey); if (SignType.HMAC_SHA256.equals(signType)) { - return createHMACSha256Sign(toSign.toString(), signKey); + return createHmacSha256Sign(toSign.toString(), signKey); } else { return DigestUtils.md5Hex(toSign.toString()).toUpperCase(); } } - private static String createHMACSha256Sign(String message, String key) { + private static String createHmacSha256Sign(String message, String key) { try { - Mac hmacSHA256 = Mac.getInstance("HmacSHA256"); + Mac sha256 = Mac.getInstance("HmacSHA256"); SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(), "HmacSHA256"); - hmacSHA256.init(secretKeySpec); - byte[] bytes = hmacSHA256.doFinal(message.getBytes()); + sha256.init(secretKeySpec); + byte[] bytes = sha256.doFinal(message.getBytes()); return Hex.encodeHexString(bytes).toUpperCase(); } catch (NoSuchAlgorithmException | InvalidKeyException e) { - e.printStackTrace(); + log.error(e.getMessage(), e); } return null; } /** - * 校验签名是否正确 + * 校验签名是否正确. * - * @param xmlBean Bean需要标记有XML注解 - * @param signKey 校验的签名Key + * @param xmlBean Bean需要标记有XML注解 + * @param signType 签名类型,如果为空,则默认为MD5 + * @param signKey 校验的签名Key * @return true - 签名校验成功,false - 签名校验失败 - * @see #checkSign(Map, String) */ - public static boolean checkSign(Object xmlBean, String signKey) { - return checkSign(BeanUtils.xmlBean2Map(xmlBean), signKey); + public static boolean checkSign(Object xmlBean, String signType, String signKey) { + return checkSign(BeanUtils.xmlBean2Map(xmlBean), signType, signKey); } /** - * 校验签名是否正确 + * 校验签名是否正确. * - * @param params 需要校验的参数Map - * @param signKey 校验的签名Key + * @param params 需要校验的参数Map + * @param signType 签名类型,如果为空,则默认为MD5 + * @param signKey 校验的签名Key * @return true - 签名校验成功,false - 签名校验失败 - * @see #checkSign(Map, String) */ - public static boolean checkSign(Map params, String signKey) { - String sign = createSign(params, signKey, null); + public static boolean checkSign(Map params, String signType, String signKey) { + String sign = createSign(params, signType, signKey, false); return sign.equals(params.get("sign")); } } diff --git a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/WxPayServiceAbstractImplTest.java b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/WxPayServiceAbstractImplTest.java index 2fc5354424..9c293103b6 100644 --- a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/WxPayServiceAbstractImplTest.java +++ b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/WxPayServiceAbstractImplTest.java @@ -2,6 +2,10 @@ import com.github.binarywang.utils.qrcode.QrcodeUtils; import com.github.binarywang.wxpay.bean.coupon.*; +import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; +import com.github.binarywang.wxpay.bean.order.WxPayAppOrderResult; +import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult; +import com.github.binarywang.wxpay.bean.order.WxPayNativeOrderResult; import com.github.binarywang.wxpay.bean.request.*; import com.github.binarywang.wxpay.bean.result.*; import com.github.binarywang.wxpay.constant.WxPayConstants; @@ -15,14 +19,12 @@ import com.google.inject.Inject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.annotations.*; import java.nio.file.Files; import java.nio.file.Path; import java.util.Calendar; import java.util.Date; -import java.util.Map; import static org.testng.Assert.*; @@ -30,7 +32,7 @@ * 测试支付相关接口 * Created by Binary Wang on 2016/7/28. * - * @author binarywang (https://github.com/binarywang) + * @author Binary Wang */ @Test @Guice(modules = ApiTestModule.class) @@ -45,8 +47,30 @@ public class WxPayServiceAbstractImplTest { */ @Test public void testUnifiedOrder() throws WxPayException { - WxPayUnifiedOrderResult result = this.payService - .unifiedOrder(WxPayUnifiedOrderRequest.newBuilder() + WxPayUnifiedOrderRequest request = WxPayUnifiedOrderRequest.newBuilder() + .body("我去") + .totalFee(1) + .spbillCreateIp("11.1.11.1") + .notifyURL("111111") + .tradeType(TradeType.JSAPI) + .openid(((XmlWxPayConfig) this.payService.getConfig()).getOpenid()) + .outTradeNo("1111112") + .build(); + request.setSignType(SignType.HMAC_SHA256); + WxPayUnifiedOrderResult result = this.payService.unifiedOrder(request); + this.logger.info(result.toString()); + this.logger.warn(this.payService.getWxApiData().toString()); + } + + @Test + public void testCreateOrder() throws Exception { + //see other tests with method name starting with 'testCreateOrder_' + } + + @Test + public void testCreateOrder_jsapi() throws Exception { + WxPayMpOrderResult result = this.payService + .createOrder(WxPayUnifiedOrderRequest.newBuilder() .body("我去") .totalFee(1) .spbillCreateIp("11.1.11.1") @@ -59,18 +83,40 @@ public void testUnifiedOrder() throws WxPayException { this.logger.warn(this.payService.getWxApiData().toString()); } + @Test + public void testCreateOrder_app() throws Exception { + WxPayAppOrderResult result = this.payService + .createOrder(WxPayUnifiedOrderRequest.newBuilder() + .body("我去") + .totalFee(1) + .spbillCreateIp("11.1.11.1") + .notifyURL("111111") + .tradeType(TradeType.APP) + .outTradeNo("1111112") + .build()); + this.logger.info(result.toString()); + this.logger.warn(this.payService.getWxApiData().toString()); + } + + @Test + public void testCreateOrder_native() throws Exception { + WxPayNativeOrderResult result = this.payService + .createOrder(WxPayUnifiedOrderRequest.newBuilder() + .body("我去") + .totalFee(1) + .productId("aaa") + .spbillCreateIp("11.1.11.1") + .notifyURL("111111") + .tradeType(TradeType.NATIVE) + .outTradeNo("111111290") + .build()); + this.logger.info(result.toString()); + this.logger.warn(this.payService.getWxApiData().toString()); + } + @Test public void testGetPayInfo() throws Exception { - Map payInfo = this.payService.getPayInfo(WxPayUnifiedOrderRequest.newBuilder() - .body("我去") - .totalFee(1) - .spbillCreateIp("1.11.1.11") - .notifyURL("111111") - .tradeType(TradeType.JSAPI) - .outTradeNo("1111113") - .openid(((XmlWxPayConfig) this.payService.getConfig()).getOpenid()) - .build()); - this.logger.info(payInfo.toString()); + //please use createOrder instead } /** @@ -90,11 +136,24 @@ public void testCloseOrder() throws WxPayException { this.logger.info(this.payService.closeOrder("11212121").toString()); } + @DataProvider + public Object[][] billingData() { + return new Object[][]{ +// {"20170831", BillType.ALL, null, "deviceInfo"}, + {"20170831", BillType.SUCCESS, null, "deviceInfo"} + }; + } + + @Test(dataProvider = "billingData") + public void testDownloadBill(String billDate, String billType, + String tarType, String deviceInfo) throws Exception { + WxPayBillResult billResult = this.payService.downloadBill(billDate, billType, tarType, deviceInfo); + assertNotNull(billResult); + this.logger.info(billResult.toString()); + } + @Test - public void testDownloadBill() throws Exception { - WxPayBillResult wxPayBillResult = this.payService.downloadBill("20170831", BillType.ALL, null, "1111111"); - //前一天没有账单记录返回null - assertNotNull(wxPayBillResult); + public void testDownloadBill_withNoParams() throws Exception { //必填字段为空时,抛出异常 this.payService.downloadBill("", "", "", null); } @@ -225,19 +284,17 @@ public void testCreateScanPayQrcodeMode2() throws Exception { assertEquals(QrcodeUtils.decodeQrcode(qrcodeFilePath.toFile()), qrcodeContent); } - @Test - public void testGetOrderNotifyResult() throws Exception { - } - @Test public void testMicropay() throws Exception { - WxPayMicropayResult result = this.payService.micropay(WxPayMicropayRequest.newBuilder() - .body("body") - .outTradeNo("aaaaa") - .totalFee(123) - .spbillCreateIp("127.0.0.1") - .authCode("aaa") - .build()); + WxPayMicropayResult result = this.payService.micropay( + WxPayMicropayRequest + .newBuilder() + .body("body") + .outTradeNo("aaaaa") + .totalFee(123) + .spbillCreateIp("127.0.0.1") + .authCode("aaa") + .build()); this.logger.info(result.toString()); } @@ -253,9 +310,11 @@ public void testSetConfig() throws Exception { @Test public void testReverseOrder() throws Exception { - WxPayOrderReverseResult result = this.payService.reverseOrder(WxPayOrderReverseRequest.newBuilder() - .outTradeNo("1111") - .build()); + WxPayOrderReverseResult result = this.payService.reverseOrder( + WxPayOrderReverseRequest + .newBuilder() + .outTradeNo("1111") + .build()); assertNotNull(result); this.logger.info(result.toString()); } @@ -306,33 +365,82 @@ public void testSendCoupon() throws Exception { @Test public void testQueryCouponStock() throws Exception { - WxPayCouponStockQueryResult result = this.payService.queryCouponStock(WxPayCouponStockQueryRequest.newBuilder() - .couponStockId("123") - .build()); + WxPayCouponStockQueryResult result = this.payService.queryCouponStock( + WxPayCouponStockQueryRequest + .newBuilder() + .couponStockId("123") + .build()); this.logger.info(result.toString()); } @Test public void testQueryCouponInfo() throws Exception { - WxPayCouponInfoQueryResult result = this.payService.queryCouponInfo(WxPayCouponInfoQueryRequest.newBuilder() - .openid("ojOQA0y9o-Eb6Aep7uVTdbkJqrP4") - .couponId("11") - .stockId("1121") - .build()); + WxPayCouponInfoQueryResult result = this.payService.queryCouponInfo( + WxPayCouponInfoQueryRequest + .newBuilder() + .openid("ojOQA0y9o-Eb6Aep7uVTdbkJqrP4") + .couponId("11") + .stockId("1121") + .build()); this.logger.info(result.toString()); } /** - * 目前调用接口总报“系统繁忙,清稍后再试”,怀疑根本没法使用 + * 只支持拉取90天内的评论数据 */ @Test public void testQueryComment() throws Exception { Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.DAY_OF_MONTH, -2); - Date beginDate = calendar.getTime(); - calendar.add(Calendar.MONTH, -1); + calendar.add(Calendar.DAY_OF_MONTH, -1); Date endDate = calendar.getTime(); - this.payService.queryComment(beginDate, endDate, 0, null); + calendar.add(Calendar.DAY_OF_MONTH, -88); + Date beginDate = calendar.getTime(); + String result = this.payService.queryComment(beginDate, endDate, 0, null); + this.logger.info(result); + } + + /** + * @see {@link com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResultTest} + * @throws Exception + */ + @Test + public void testParseOrderNotifyResult() throws Exception { + // 请参考com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResultTest 里的单元测试 + + String xmlString = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 1\n" + + " \n" + + " \n" + + " 2\n" + + " \n" + + " 10000\n" + + " 100\n" + + " \n" + + " 10001\n" + + " 200\n" + + ""; + + WxPayOrderNotifyResult result = this.payService.parseOrderNotifyResult(xmlString); + System.out.println(result); + } + + @Test + public void testGetWxApiData() throws Exception { + //see test in testUnifiedOrder() } } diff --git a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/util/SignUtilsTest.java b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/util/SignUtilsTest.java index 23d7088b7b..57c185b544 100644 --- a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/util/SignUtilsTest.java +++ b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/util/SignUtilsTest.java @@ -20,7 +20,7 @@ public class SignUtilsTest { public void testCreateSign() throws Exception { String signKey = "192006250b4c09247ec02edce69f6a2d"; String message = "appid=wxd930ea5d5a258f4f&body=test&device_info=1000&mch_id=10000100&nonce_str=ibuaiVcKdpRxkhJA"; - assertEquals(SignUtils.createSign((Splitter.on("&").withKeyValueSeparator("=").split(message)), signKey, null), + assertEquals(SignUtils.createSign((Splitter.on("&").withKeyValueSeparator("=").split(message)), null, signKey, false), "9A0A8659F005D6984697E2CA0A9CF3B7"); } @@ -29,7 +29,7 @@ public void testCreateSign_HMACSHA256() throws Exception { String signKey = "192006250b4c09247ec02edce69f6a2d"; final String message = "appid=wxd930ea5d5a258f4f&body=test&device_info=1000&mch_id=10000100&nonce_str=ibuaiVcKdpRxkhJA"; String sign = SignUtils.createSign(Splitter.on("&").withKeyValueSeparator("=").split(message), - signKey, HMAC_SHA256); + HMAC_SHA256, signKey, false); assertEquals(sign, "6A9AE1657590FD6257D693A078E1C3E4BB6BA4DC30B23E0EE2496E54170DACD6"); }