+ * 微信类型枚举. + * Created by BinaryWang on 2018/5/14. + *+ * + * @author Binary Wang + */ +public enum WxType { + /** + * 企业微信 + */ + CP, + /** + * 微信公众号 + */ + MP, + /** + * 微信小程序 + */ + MiniApp, + /** + * 微信开放平台 + */ + Open, + /** + * 微信支付 + */ + Pay; +} 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 6380749224..9704f037a7 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 @@ -78,6 +78,11 @@ public static class KefuMsgType { * 转发到客服的消息. */ public static final String TRANSFER_CUSTOMER_SERVICE = "transfer_customer_service"; + + /** + * 小程序卡片(要求小程序与公众号已关联) + */ + public static final String MINIPROGRAMPAGE="miniprogrampage"; } /** 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 5117c765f3..7a452df66f 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 @@ -1,6 +1,6 @@ package me.chanjar.weixin.common.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; /** * WxErrorException处理器. 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 deleted file mode 100644 index 25a06f4785..0000000000 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java +++ /dev/null @@ -1,38 +0,0 @@ -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; - - private int errorCode; - - private String errorMsg; - - private String json; - - public static WxError fromJson(String json) { - return WxGsonBuilder.create().fromJson(json, WxError.class); - } - - @Override - public String toString() { - if (this.json != null) { - return this.json; - } - return "错误: Code=" + this.errorCode + ", Msg=" + this.errorMsg; - } - -} diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxCpErrorMsgEnum.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxCpErrorMsgEnum.java new file mode 100644 index 0000000000..0ae580620a --- /dev/null +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxCpErrorMsgEnum.java @@ -0,0 +1,806 @@ +package me.chanjar.weixin.common.error; + +import lombok.Getter; + +/** + *
+ * 企业微信全局错误码. + * 参考文档:企业微信全局错误码 + * Created by Binary Wang on 2018/5/13. + *+ * + * @author Binary Wang + */ +@Getter +public enum WxCpErrorMsgEnum { + /** + * 系统繁忙;服务器暂不可用,建议稍候重试。建议重试次数不超过3次。 + */ + CODE_1(-1, "系统繁忙;服务器暂不可用,建议稍候重试。建议重试次数不超过3次。"), + /** + * 请求成功;接口调用成功 + */ + CODE_0(0, "请求成功;接口调用成功"), + /** + * 不合法的secret参数;secret在应用详情/通讯录管理助手可查看 + */ + CODE_40001(40001, "不合法的secret参数;secret在应用详情/通讯录管理助手可查看"), + /** + * 无效的UserID + */ + CODE_40003(40003, "无效的UserID"), + /** + * 不合法的媒体文件类型;不满足系统文件要求。参考:上传的媒体文件限制 + */ + CODE_40004(40004, "不合法的媒体文件类型;不满足系统文件要求。参考:上传的媒体文件限制"), + /** + * 不合法的type参数;合法的type取值,参考:上传临时素材 + */ + CODE_40005(40005, "不合法的type参数;合法的type取值,参考:上传临时素材"), + /** + * 不合法的文件大小;系统文件要求,参考:上传的媒体文件限制 + */ + CODE_40006(40006, "不合法的文件大小;系统文件要求,参考:上传的媒体文件限制"), + /** + * 不合法的media_id参数 + */ + CODE_40007(40007, "不合法的media_id参数"), + /** + * 不合法的msgtype参数;合法的msgtype取值,参考:消息类型 + */ + CODE_40008(40008, "不合法的msgtype参数;合法的msgtype取值,参考:消息类型"), + /** + * 上传图片大小不是有效值;图片大小的系统限制,参考上传的媒体文件限制 + */ + CODE_40009(40009, "上传图片大小不是有效值;图片大小的系统限制,参考上传的媒体文件限制"), + /** + * 上传视频大小不是有效值;视频大小的系统限制,参考上传的媒体文件限制 + */ + CODE_40011(40011, "上传视频大小不是有效值;视频大小的系统限制,参考上传的媒体文件限制"), + /** + * 不合法的CorpID;需确认CorpID是否填写正确,在 web管理端-设置 可查看 + */ + CODE_40013(40013, "不合法的CorpID;需确认CorpID是否填写正确,在 web管理端-设置 可查看"), + /** + * 不合法的access_token + */ + CODE_40014(40014, "不合法的access_token"), + /** + * 不合法的按钮个数;菜单按钮1-3个 + */ + CODE_40016(40016, "不合法的按钮个数;菜单按钮1-3个"), + /** + * 不合法的按钮类型;支持的类型,参考:按钮类型 + */ + CODE_40017(40017, "不合法的按钮类型;支持的类型,参考:按钮类型"), + /** + * 不合法的按钮名字长度;长度应不超过16个字节 + */ + CODE_40018(40018, "不合法的按钮名字长度;长度应不超过16个字节"), + /** + * 不合法的按钮KEY长度;长度应不超过128字节 + */ + CODE_40019(40019, "不合法的按钮KEY长度;长度应不超过128字节"), + /** + * 不合法的按钮URL长度;长度应不超过1024字节 + */ + CODE_40020(40020, "不合法的按钮URL长度;长度应不超过1024字节"), + /** + * 不合法的子菜单级数;只能包含一级菜单和二级菜单 + */ + CODE_40022(40022, "不合法的子菜单级数;只能包含一级菜单和二级菜单"), + /** + * 不合法的子菜单按钮个数;子菜单按钮1-5个 + */ + CODE_40023(40023, "不合法的子菜单按钮个数;子菜单按钮1-5个"), + /** + * 不合法的子菜单按钮类型;支持的类型,参考:按钮类型 + */ + CODE_40024(40024, "不合法的子菜单按钮类型;支持的类型,参考:按钮类型"), + /** + * 不合法的子菜单按钮名字长度;支持的类型,参考:按钮类型 + */ + CODE_40025(40025, "不合法的子菜单按钮名字长度;支持的类型,参考:按钮类型"), + /** + * 不合法的子菜单按钮KEY长度;长度应不超过60个字节 + */ + CODE_40026(40026, "不合法的子菜单按钮KEY长度;长度应不超过60个字节"), + /** + * 不合法的子菜单按钮URL长度;长度应不超过1024字节 + */ + CODE_40027(40027, "不合法的子菜单按钮URL长度;长度应不超过1024字节"), + /** + * 不合法的oauth_code + */ + CODE_40029(40029, "不合法的oauth_code"), + /** + * 不合法的UserID列表;指定的UserID列表,至少存在一个UserID不在通讯录中 + */ + CODE_40031(40031, "不合法的UserID列表;指定的UserID列表,至少存在一个UserID不在通讯录中"), + /** + * 不合法的UserID列表长度 + */ + CODE_40032(40032, "不合法的UserID列表长度"), + /** + * 不合法的请求字符;不能包含\\uxxxx格式的字符 + */ + CODE_40033(40033, "不合法的请求字符;不能包含\\uxxxx格式的字符"), + /** + * 不合法的参数 + */ + CODE_40035(40035, "不合法的参数"), + /** + * chatid不存在;会话需要先创建后,才可修改会话详情或者发起聊天 + */ + CODE_40050(40050, "chatid不存在;会话需要先创建后,才可修改会话详情或者发起聊天"), + /** + * 不合法的子菜单url域名 + */ + CODE_40054(40054, "不合法的子菜单url域名"), + /** + * 不合法的菜单url域名 + */ + CODE_40055(40055, "不合法的菜单url域名"), + /** + * 不合法的agentid + */ + CODE_40056(40056, "不合法的agentid"), + /** + * 不合法的callbackurl或者callbackurl验证失败;可自助到开发调试工具重现 + */ + CODE_40057(40057, "不合法的callbackurl或者callbackurl验证失败;可自助到开发调试工具重现"), + /** + * 不合法的参数;传递参数不符合系统要求,需要参照具体API接口说明 + */ + CODE_40058(40058, "不合法的参数;传递参数不符合系统要求,需要参照具体API接口说明"), + /** + * 不合法的上报地理位置标志位;开关标志位只能填 0 或者 1 + */ + CODE_40059(40059, "不合法的上报地理位置标志位;开关标志位只能填 0 或者 1"), + /** + * 参数为空 + */ + CODE_40063(40063, "参数为空"), + /** + * 不合法的部门列表;部门列表为空,或者至少存在一个部门ID不存在于通讯录中 + */ + CODE_40066(40066, "不合法的部门列表;部门列表为空,或者至少存在一个部门ID不存在于通讯录中"), + /** + * 不合法的标签ID;标签ID未指定,或者指定的标签ID不存在 + */ + CODE_40068(40068, "不合法的标签ID;标签ID未指定,或者指定的标签ID不存在"), + /** + * 指定的标签范围结点全部无效 + */ + CODE_40070(40070, "指定的标签范围结点全部无效"), + /** + * 不合法的标签名字;标签名字已经存在 + */ + CODE_40071(40071, "不合法的标签名字;标签名字已经存在"), + /** + * 不合法的标签名字长度;不允许为空,最大长度限制为32个字(汉字或英文字母) + */ + CODE_40072(40072, "不合法的标签名字长度;不允许为空,最大长度限制为32个字(汉字或英文字母)"), + /** + * 不合法的openid;openid不存在,需确认获取来源 + */ + CODE_40073(40073, "不合法的openid;openid不存在,需确认获取来源"), + /** + * news消息不支持保密消息类型;图文消息支持保密类型需改用mpnews + */ + CODE_40074(40074, "news消息不支持保密消息类型;图文消息支持保密类型需改用mpnews"), + /** + * 不合法的pre_auth_code参数;预授权码不存在,参考:获取预授权码 + */ + CODE_40077(40077, "不合法的pre_auth_code参数;预授权码不存在,参考:获取预授权码"), + /** + * 不合法的auth_code参数;需确认获取来源,并且只能消费一次 + */ + CODE_40078(40078, "不合法的auth_code参数;需确认获取来源,并且只能消费一次"), + /** + * 不合法的suite_secret;套件secret可在第三方管理端套件详情查看 + */ + CODE_40080(40080, "不合法的suite_secret;套件secret可在第三方管理端套件详情查看"), + /** + * 不合法的suite_token + */ + CODE_40082(40082, "不合法的suite_token"), + /** + * 不合法的suite_id;suite_id不存在 + */ + CODE_40083(40083, "不合法的suite_id;suite_id不存在"), + /** + * 不合法的permanent_code参数 + */ + CODE_40084(40084, "不合法的permanent_code参数"), + /** + * 不合法的的suite_ticket参数;suite_ticket不存在或者已失效 + */ + CODE_40085(40085, "不合法的的suite_ticket参数;suite_ticket不存在或者已失效"), + /** + * 不合法的第三方应用appid;至少有一个不存在应用id + */ + CODE_40086(40086, "不合法的第三方应用appid;至少有一个不存在应用id"), + /** + * jobid不存在;请检查 jobid 来源 + */ + CODE_40088(40088, "jobid不存在;请检查 jobid 来源"), + /** + * 批量任务的结果已清理;系统仅保存最近5次批量任务的结果。可在通讯录查看实际导入情况 + */ + CODE_40089(40089, "批量任务的结果已清理;系统仅保存最近5次批量任务的结果。可在通讯录查看实际导入情况"), + /** + * secret不合法;可能用了别的企业的secret + */ + CODE_40091(40091, "secret不合法;可能用了别的企业的secret"), + /** + * 导入文件存在不合法的内容 + */ + CODE_40092(40092, "导入文件存在不合法的内容"), + /** + * 不合法的jsapi_ticket参数;ticket已失效,或者拼写错误 + */ + CODE_40093(40093, "不合法的jsapi_ticket参数;ticket已失效,或者拼写错误"), + /** + * 不合法的URL;缺少主页URL参数,或者URL不合法(链接需要带上协议头,以 http:// 或者 https:// 开头) + */ + CODE_40094(40094, "不合法的URL;缺少主页URL参数,或者URL不合法(链接需要带上协议头,以 http:// 或者 https:// 开头)"), + /** + * 缺少access_token参数 + */ + CODE_41001(41001, "缺少access_token参数"), + /** + * 缺少corpid参数 + */ + CODE_41002(41002, "缺少corpid参数"), + /** + * 缺少secret参数 + */ + CODE_41004(41004, "缺少secret参数"), + /** + * 缺少media_id参数;media_id为调用接口必填参数,请确认是否有传递 + */ + CODE_41006(41006, "缺少media_id参数;media_id为调用接口必填参数,请确认是否有传递"), + /** + * 缺少auth code参数 + */ + CODE_41008(41008, "缺少auth code参数"), + /** + * 缺少userid参数 + */ + CODE_41009(41009, "缺少userid参数"), + /** + * 缺少url参数 + */ + CODE_41010(41010, "缺少url参数"), + /** + * 缺少agentid参数 + */ + CODE_41011(41011, "缺少agentid参数"), + /** + * 缺少 description 参数;发送文本卡片消息接口,description 是必填字段 + */ + CODE_41033(41033, "缺少 description 参数;发送文本卡片消息接口,description 是必填字段"), + /** + * 缺少title参数;发送图文消息,标题是必填参数。请确认参数是否有传递。 + */ + CODE_41016(41016, "缺少title参数;发送图文消息,标题是必填参数。请确认参数是否有传递。"), + /** + * 缺少 department 参数 + */ + CODE_41019(41019, "缺少 department 参数"), + /** + * 缺少tagid参数 + */ + CODE_41017(41017, "缺少tagid参数"), + /** + * 缺少suite_id参数 + */ + CODE_41021(41021, "缺少suite_id参数"), + /** + * 缺少suite_access_token参数 + */ + CODE_41022(41022, "缺少suite_access_token参数"), + /** + * 缺少suite_ticket参数 + */ + CODE_41023(41023, "缺少suite_ticket参数"), + /** + * 缺少secret参数 + */ + CODE_41024(41024, "缺少secret参数"), + /** + * 缺少permanent_code参数 + */ + CODE_41025(41025, "缺少permanent_code参数"), + /** + * access_token已过期;access_token有时效性,需要重新获取一次 + */ + CODE_42001(42001, "access_token已过期;access_token有时效性,需要重新获取一次"), + /** + * pre_auth_code已过期;pre_auth_code有时效性,需要重新获取一次 + */ + CODE_42007(42007, "pre_auth_code已过期;pre_auth_code有时效性,需要重新获取一次"), + /** + * suite_access_token已过期;suite_access_token有时效性,需要重新获取一次 + */ + CODE_42009(42009, "suite_access_token已过期;suite_access_token有时效性,需要重新获取一次"), + /** + * 指定的userid未绑定微信或未关注微信插件;需要成员使用微信登录企业微信或者关注微信插件才能获取openid + */ + CODE_43004(43004, "指定的userid未绑定微信或未关注微信插件;需要成员使用微信登录企业微信或者关注微信插件才能获取openid"), + /** + * 多媒体文件为空;上传格式参考:上传临时素材,确认header和body的内容正确。 + */ + CODE_44001(44001, "多媒体文件为空;上传格式参考:上传临时素材,确认header和body的内容正确。"), + /** + * 文本消息content参数为空;发文本消息content为必填参数,且不能为空 + */ + CODE_44004(44004, "文本消息content参数为空;发文本消息content为必填参数,且不能为空"), + /** + * 多媒体文件大小超过限制;图片不可超过5M;音频不可超过5M;文件不可超过20M + */ + CODE_45001(45001, "多媒体文件大小超过限制;图片不可超过5M;音频不可超过5M;文件不可超过20M"), + /** + * 消息内容大小超过限制 + */ + CODE_45002(45002, "消息内容大小超过限制"), + /** + * 应用description参数长度不符合系统限制;设置应用若带有description参数,则长度必须为4至120个字符 + */ + CODE_45004(45004, "应用description参数长度不符合系统限制;设置应用若带有description参数,则长度必须为4至120个字符"), + /** + * 语音播放时间超过限制;语音播放时长不能超过60秒 + */ + CODE_45007(45007, "语音播放时间超过限制;语音播放时长不能超过60秒"), + /** + * 图文消息的文章数量不符合系统限制;图文消息的文章数量不能超过8条 + */ + CODE_45008(45008, "图文消息的文章数量不符合系统限制;图文消息的文章数量不能超过8条"), + /** + * 接口调用超过限制 + */ + CODE_45009(45009, "接口调用超过限制"), + /** + * 应用name参数长度不符合系统限制;设置应用若带有name参数,则不允许为空,且不超过32个字符 + */ + CODE_45022(45022, "应用name参数长度不符合系统限制;设置应用若带有name参数,则不允许为空,且不超过32个字符"), + /** + * 帐号数量超过上限 + */ + CODE_45024(45024, "帐号数量超过上限"), + /** + * 触发删除用户数的保护;限制参考:全量覆盖成员 + */ + CODE_45026(45026, "触发删除用户数的保护;限制参考:全量覆盖成员"), + /** + * 图文消息author参数长度超过限制;最长64个字节 + */ + CODE_45032(45032, "图文消息author参数长度超过限制;最长64个字节"), + /** + * 接口并发调用超过限制 + */ + CODE_45033(45033, "接口并发调用超过限制"), + /** + * 菜单未设置;菜单需发布后才能获取到数据 + */ + CODE_46003(46003, "菜单未设置;菜单需发布后才能获取到数据"), + /** + * 指定的用户不存在;需要确认指定的用户存在于通讯录中 + */ + CODE_46004(46004, "指定的用户不存在;需要确认指定的用户存在于通讯录中"), + /** + * API接口无权限调用 + */ + CODE_48002(48002, "API接口无权限调用"), + /** + * 不合法的suite_id;确认suite_access_token由指定的suite_id生成 + */ + CODE_48003(48003, "不合法的suite_id;确认suite_access_token由指定的suite_id生成"), + /** + * 授权关系无效;可能是无授权或授权已被取消 + */ + CODE_48004(48004, "授权关系无效;可能是无授权或授权已被取消"), + /** + * API接口已废弃;接口已不再支持,建议改用新接口或者新方案 + */ + CODE_48005(48005, "API接口已废弃;接口已不再支持,建议改用新接口或者新方案"), + /** + * redirect_url未登记可信域名 + */ + CODE_50001(50001, "redirect_url未登记可信域名"), + /** + * 成员不在权限范围;请检查应用或管理组的权限范围 + */ + CODE_50002(50002, "成员不在权限范围;请检查应用或管理组的权限范围"), + /** + * 应用已禁用;禁用的应用无法使用API接口。可在”管理端-企业应用”启用应用 + */ + CODE_50003(50003, "应用已禁用;禁用的应用无法使用API接口。可在”管理端-企业应用”启用应用"), + /** + * 部门长度不符合限制;部门名称不能为空且长度不能超过32个字 + */ + CODE_60001(60001, "部门长度不符合限制;部门名称不能为空且长度不能超过32个字"), + /** + * 部门ID不存在;需要确认部门ID是否有带,并且存在通讯录中 + */ + CODE_60003(60003, "部门ID不存在;需要确认部门ID是否有带,并且存在通讯录中"), + /** + * 父部门不存在;需要确认父亲部门ID是否有带,并且存在通讯录中 + */ + CODE_60004(60004, "父部门不存在;需要确认父亲部门ID是否有带,并且存在通讯录中"), + /** + * 部门下存在成员;不允许删除有成员的部门 + */ + CODE_60005(60005, "部门下存在成员;不允许删除有成员的部门"), + /** + * 部门下存在子部门;不允许删除有子部门的部门 + */ + CODE_60006(60006, "部门下存在子部门;不允许删除有子部门的部门"), + /** + * 不允许删除根部门 + */ + CODE_60007(60007, "不允许删除根部门"), + /** + * 部门已存在;部门ID或者部门名称已存在 + */ + CODE_60008(60008, "部门已存在;部门ID或者部门名称已存在"), + /** + * 部门名称含有非法字符;不能含有 \\:?*“< >| 等字符 + */ + CODE_60009(60009, "部门名称含有非法字符;不能含有 \\ :?*“< >| 等字符"), + /** + * 部门存在循环关系 + */ + CODE_60010(60010, "部门存在循环关系"), + /** + * 指定的成员/部门/标签参数无权限 + */ + CODE_60011(60011, "指定的成员/部门/标签参数无权限"), + /** + * 不允许删除默认应用;默认应用的id为0 + */ + CODE_60012(60012, "不允许删除默认应用;默认应用的id为0"), + /** + * 访问ip不在白名单之中;请确认访问ip是否在服务商白名单IP列表 + */ + CODE_60020(60020, "访问ip不在白名单之中;请确认访问ip是否在服务商白名单IP列表"), + /** + * 不允许修改第三方应用的主页 URL;第三方应用类型,不允许通过接口修改该应用的主页 URL + */ + CODE_60028(60028, "不允许修改第三方应用的主页 URL;第三方应用类型,不允许通过接口修改该应用的主页 URL"), + /** + * UserID已存在 + */ + CODE_60102(60102, "UserID已存在"), + /** + * 手机号码不合法;长度不超过32位,字符仅支持数字,加号和减号 + */ + CODE_60103(60103, "手机号码不合法;长度不超过32位,字符仅支持数字,加号和减号"), + /** + * 手机号码已存在;同一个企业内,成员的手机号不能重复。建议更换手机号,或者更新已有的手机记录。 + */ + CODE_60104(60104, "手机号码已存在;同一个企业内,成员的手机号不能重复。建议更换手机号,或者更新已有的手机记录。"), + /** + * 邮箱不合法;长度不超过64位,且为有效的email格式 + */ + CODE_60105(60105, "邮箱不合法;长度不超过64位,且为有效的email格式"), + /** + * 邮箱已存在;同一个企业内,成员的邮箱不能重复。建议更换邮箱,或者更新已有的邮箱记录。 + */ + CODE_60106(60106, "邮箱已存在;同一个企业内,成员的邮箱不能重复。建议更换邮箱,或者更新已有的邮箱记录。"), + /** + * 微信号不合法;微信号格式由字母、数字、”-“、”_“组成,长度为 3-20 字节,首字符必须是字母或”-“或”_“ + */ + CODE_60107(60107, "微信号不合法;微信号格式由字母、数字、”-“、”_“组成,长度为 3-20 字节,首字符必须是字母或”-“或”_“"), + /** + * 用户所属部门数量超过限制;用户同时归属部门不超过20个 + */ + CODE_60110(60110, "用户所属部门数量超过限制;用户同时归属部门不超过20个"), + /** + * UserID不存在;UserID参数为空,或者不存在通讯录中 + */ + CODE_60111(60111, "UserID不存在;UserID参数为空,或者不存在通讯录中"), + /** + * 成员name参数不合法;不能为空,且不能超过64字符 + */ + CODE_60112(60112, "成员name参数不合法;不能为空,且不能超过64字符"), + /** + * 无效的部门id;部门不存在通讯录中 + */ + CODE_60123(60123, "无效的部门id;部门不存在通讯录中"), + /** + * 无效的父部门id;父部门不存在通讯录中 + */ + CODE_60124(60124, "无效的父部门id;父部门不存在通讯录中"), + /** + * 非法部门名字;不能为空,且不能超过64字节,且不能含有\\:*?”< >|等字符 + */ + CODE_60125(60125, "非法部门名字;不能为空,且不能超过64字节,且不能含有\\:*?”< >|等字符"), + /** + * 缺少department参数 + */ + CODE_60127(60127, "缺少department参数"), + /** + * 成员手机和邮箱都为空;成员手机和邮箱至少有个非空 + */ + CODE_60129(60129, "成员手机和邮箱都为空;成员手机和邮箱至少有个非空"), + /** + * 发票已被其他公众号锁定 + */ + CODE_72023(72023, "发票已被其他公众号锁定"), + /** + * 发票状态错误;reimburse_status状态错误,参考:更新发票状态 + */ + CODE_72024(72024, "发票状态错误;reimburse_status状态错误,参考:更新发票状态"), + /** + * 存在发票不属于该用户;只能批量更新该openid的发票,参考:批量更新发票状态 + */ + CODE_72037(72037, "存在发票不属于该用户;只能批量更新该openid的发票,参考:批量更新发票状态"), + /** + * 可信域名不正确,或者无ICP备案 + */ + CODE_80001(80001, "可信域名不正确,或者无ICP备案"), + /** + * 部门下的结点数超过限制(3W) + */ + CODE_81001(81001, "部门下的结点数超过限制(3W)"), + /** + * 部门最多15层 + */ + CODE_81002(81002, "部门最多15层"), + /** + * 无权限操作标签 + */ + CODE_81011(81011, "无权限操作标签"), + /** + * UserID、部门ID、标签ID全部非法或无权限 + */ + CODE_81013(81013, "UserID、部门ID、标签ID全部非法或无权限"), + /** + * 标签添加成员,单次添加user或party过多 + */ + CODE_81014(81014, "标签添加成员,单次添加user或party过多"), + /** + * 指定的成员/部门/标签全部无效 + */ + CODE_82001(82001, "指定的成员/部门/标签全部无效"), + /** + * 不合法的PartyID列表长度;发消息,单次不能超过100个部门 + */ + CODE_82002(82002, "不合法的PartyID列表长度;发消息,单次不能超过100个部门"), + /** + * 不合法的TagID列表长度;发消息,单次不能超过100个标签 + */ + CODE_82003(82003, "不合法的TagID列表长度;发消息,单次不能超过100个标签"), + /** + * 成员票据过期 + */ + CODE_84014(84014, "成员票据过期"), + /** + * 成员票据无效;确认user_ticket参数来源是否正确。参考接口:根据code获取成员信息 + */ + CODE_84015(84015, "成员票据无效;确认user_ticket参数来源是否正确。参考接口:根据code获取成员信息"), + /** + * 缺少templateid参数 + */ + CODE_84019(84019, "缺少templateid参数"), + /** + * templateid不存在;确认参数是否有带,并且已创建 + */ + CODE_84020(84020, "templateid不存在;确认参数是否有带,并且已创建"), + /** + * 缺少register_code参数 + */ + CODE_84021(84021, "缺少register_code参数"), + /** + * 无效的register_code参数 + */ + CODE_84022(84022, "无效的register_code参数"), + /** + * 不允许调用设置通讯录同步完成接口 + */ + CODE_84023(84023, "不允许调用设置通讯录同步完成接口"), + /** + * 无注册信息 + */ + CODE_84024(84024, "无注册信息"), + /** + * 不符合的state参数;必须是[a-zA-Z0-9]的参数值,长度不可超过128个字节 + */ + CODE_84025(84025, "不符合的state参数;必须是[a-zA-Z0-9]的参数值,长度不可超过128个字节"), + /** + * 包含不合法的词语 + */ + CODE_85002(85002, "包含不合法的词语"), + /** + * 每企业每个月设置的可信域名不可超过20个 + */ + CODE_85004(85004, "每企业每个月设置的可信域名不可超过20个"), + /** + * 可信域名未通过所有权校验 + */ + CODE_85005(85005, "可信域名未通过所有权校验"), + /** + * 参数 chatid 不合法 + */ + CODE_86001(86001, "参数 chatid 不合法"), + /** + * 参数 chatid 不存在 + */ + CODE_86003(86003, "参数 chatid 不存在"), + /** + * 参数 群名不合法 + */ + CODE_86004(86004, "参数 群名不合法"), + /** + * 参数 群主不合法 + */ + CODE_86005(86005, "参数 群主不合法"), + /** + * 群成员数过多或过少 + */ + CODE_86006(86006, "群成员数过多或过少"), + /** + * 不合法的群成员 + */ + CODE_86007(86007, "不合法的群成员"), + /** + * 非法操作非自己创建的群 + */ + CODE_86008(86008, "非法操作非自己创建的群"), + /** + * 存在非法会话成员ID + */ + CODE_86216(86216, "存在非法会话成员ID"), + /** + * 会话发送者不在会话成员列表中;会话的发送者,必须是会话的成员列表之一 + */ + CODE_86217(86217, "会话发送者不在会话成员列表中;会话的发送者,必须是会话的成员列表之一"), + /** + * 指定的会话参数不合法 + */ + CODE_86220(86220, "指定的会话参数不合法"), + /** + * 未认证摇一摇周边 + */ + CODE_90001(90001, "未认证摇一摇周边"), + /** + * 缺少摇一摇周边ticket参数 + */ + CODE_90002(90002, "缺少摇一摇周边ticket参数"), + /** + * 摇一摇周边ticket参数不合法 + */ + CODE_90003(90003, "摇一摇周边ticket参数不合法"), + /** + * 非法的对外属性类型 + */ + CODE_90100(90100, "非法的对外属性类型"), + /** + * 对外属性:文本类型长度不合法;文本长度不可超过12个UTF8字符 + */ + CODE_90101(90101, "对外属性:文本类型长度不合法;文本长度不可超过12个UTF8字符"), + /** + * 对外属性:网页类型标题长度不合法;标题长度不可超过12个UTF8字符 + */ + CODE_90102(90102, "对外属性:网页类型标题长度不合法;标题长度不可超过12个UTF8字符"), + /** + * 对外属性:网页url不合法 + */ + CODE_90103(90103, "对外属性:网页url不合法"), + /** + * 对外属性:小程序类型标题长度不合法;标题长度不可超过12个UTF8字符 + */ + CODE_90104(90104, "对外属性:小程序类型标题长度不合法;标题长度不可超过12个UTF8字符"), + /** + * 对外属性:小程序类型pagepath不合法 + */ + CODE_90105(90105, "对外属性:小程序类型pagepath不合法"), + /** + * 对外属性:请求参数不合法 + */ + CODE_90106(90106, "对外属性:请求参数不合法"), + /** + * 获取ticket的类型无效 + */ + CODE_91040(91040, "获取ticket的类型无效"), + /** + * 无权限操作指定的应用 + */ + CODE_301002(301002, "无权限操作指定的应用"), + /** + * 不允许删除创建者;创建者不允许从通讯录中删除。如果需要删除该成员,需要先在WEB管理端转移创建者身份。 + */ + CODE_301005(301005, "不允许删除创建者;创建者不允许从通讯录中删除。如果需要删除该成员,需要先在WEB管理端转移创建者身份。"), + /** + * 参数 position 不合法;长度不允许超过128个字符 + */ + CODE_301012(301012, "参数 position 不合法;长度不允许超过128个字符"), + /** + * 参数 telephone 不合法;telephone必须由1-32位的纯数字或’-‘号组成。 + */ + CODE_301013(301013, "参数 telephone 不合法;telephone必须由1-32位的纯数字或’-‘号组成。"), + /** + * 参数 english_name 不合法;参数如果有传递,不允许为空字符串,同时不能超过64字节,只能是由字母、数字、点(.)、减号(-)、空格或下划线(_)组成 + */ + CODE_301014(301014, "参数 english_name 不合法;参数如果有传递,不允许为空字符串,同时不能超过64字节,只能是由字母、数字、点(.)、减号(-)、空格或下划线(_)组成"), + /** + * 参数 mediaid 不合法;请检查 mediaid 来源,应该通过上传临时素材的图片类型获得mediaid + */ + CODE_301015(301015, "参数 mediaid 不合法;请检查 mediaid 来源,应该通过上传临时素材的图片类型获得mediaid"), + /** + * 上传语音文件不符合系统要求;语音文件的系统限制,参考上传的媒体文件限制 + */ + CODE_301016(301016, "上传语音文件不符合系统要求;语音文件的系统限制,参考上传的媒体文件限制"), + /** + * 上传语音文件仅支持AMR格式;语音文件的系统限制,参考上传的媒体文件限制 + */ + CODE_301017(301017, "上传语音文件仅支持AMR格式;语音文件的系统限制,参考上传的媒体文件限制"), + /** + * 参数 userid 无效;至少有一个userid不存在于通讯录中 + */ + CODE_301021(301021, "参数 userid 无效;至少有一个userid不存在于通讯录中"), + /** + * 获取打卡数据失败;系统失败,可重试处理 + */ + CODE_301022(301022, "获取打卡数据失败;系统失败,可重试处理"), + /** + * useridlist非法或超过限额;列表数量不能为0且不超过100 + */ + CODE_301023(301023, "useridlist非法或超过限额;列表数量不能为0且不超过100"), + /** + * 获取打卡记录时间间隔超限;保证开始时间大于0 且结束时间大于 0 且结束时间大于开始时间,且间隔少于93天 + */ + CODE_301024(301024, "获取打卡记录时间间隔超限;保证开始时间大于0 且结束时间大于 0 且结束时间大于开始时间,且间隔少于93天"), + /** + * 不允许更新该用户的userid + */ + CODE_301036(301036, "不允许更新该用户的userid"), + /** + * 批量导入任务的文件中userid有重复 + */ + CODE_302003(302003, "批量导入任务的文件中userid有重复"), + /** + * 组织架构不合法(1不是一棵树,2 多个一样的partyid,3 partyid空,4 partyid name 空,5 同一个父节点下有两个子节点 部门名字一样 可能是以上情况,请一一排查) + */ + CODE_302004(302004, "组织架构不合法(1不是一棵树,2 多个一样的partyid,3 partyid空,4 partyid name 空,5 同一个父节点下有两个子节点 部门名字一样 可能是以上情况,请一一排查)"), + /** + * 批量导入系统失败,请重新尝试导入 + */ + CODE_302005(302005, "批量导入系统失败,请重新尝试导入"), + /** + * 批量导入任务的文件中partyid有重复 + */ + CODE_302006(302006, "批量导入任务的文件中partyid有重复"), + /** + * 批量导入任务的文件中,同一个部门下有两个子部门名字一样 + */ + CODE_302007(302007, "批量导入任务的文件中,同一个部门下有两个子部门名字一样"), + /** + * CorpId参数无效;指定的CorpId不存在 + */ + CODE_2000002(2000002, "CorpId参数无效;指定的CorpId不存在"); + + private int code; + private String msg; + + WxCpErrorMsgEnum(int code, String msg) { + this.code = code; + this.msg = msg; + } + + /** + * 通过错误代码查找其中文含义. + */ + public static String findMsgByCode(int code) { + WxCpErrorMsgEnum[] values = WxCpErrorMsgEnum.values(); + for (WxCpErrorMsgEnum value : values) { + if (value.code == code) { + return value.msg; + } + } + + return null; + } +} diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxError.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxError.java new file mode 100644 index 0000000000..fc9b624fa3 --- /dev/null +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxError.java @@ -0,0 +1,80 @@ +package me.chanjar.weixin.common.error; + +import java.io.Serializable; + +import org.apache.commons.lang3.StringUtils; + +import lombok.Builder; +import lombok.Data; +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; + +/** + * 微信错误码. + * 请阅读: + * 公众平台:全局返回码说明 + * 企业微信:全局错误码 + * + * @author Daniel Qian & Binary Wang + */ +@Data +@Builder +public class WxError implements Serializable { + private static final long serialVersionUID = 7869786563361406291L; + + /** + * 微信错误代码. + */ + private int errorCode; + + /** + * 微信错误信息. + * (如果可以翻译为中文,就为中文) + */ + private String errorMsg; + + /** + * 微信接口返回的错误原始信息(英文). + */ + private String errorMsgEn; + + private String json; + + public static WxError fromJson(String json) { + return fromJson(json, null); + } + + public static WxError fromJson(String json, WxType type) { + final WxError wxError = WxGsonBuilder.create().fromJson(json, WxError.class); + if (StringUtils.isNotEmpty(wxError.getErrorMsg())) { + wxError.setErrorMsgEn(wxError.getErrorMsg()); + } + + if (type == null) { + return wxError; + } + + if (type == WxType.MP) { + final String msg = WxMpErrorMsgEnum.findMsgByCode(wxError.getErrorCode()); + if (msg != null) { + wxError.setErrorMsg(msg); + } + } else if (type == WxType.CP) { + final String msg = WxCpErrorMsgEnum.findMsgByCode(wxError.getErrorCode()); + if (msg != null) { + wxError.setErrorMsg(msg); + } + } + + return wxError; + } + + @Override + public String toString() { + if (this.json != null) { + return this.json; + } + return "错误: Code=" + this.errorCode + ", Msg=" + this.errorMsg; + } + +} diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/exception/WxErrorException.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxErrorException.java similarity index 81% rename from weixin-java-common/src/main/java/me/chanjar/weixin/common/exception/WxErrorException.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxErrorException.java index 4038e60185..6e9a2c538d 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/exception/WxErrorException.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxErrorException.java @@ -1,9 +1,9 @@ -package me.chanjar.weixin.common.exception; - -import me.chanjar.weixin.common.bean.result.WxError; +package me.chanjar.weixin.common.error; +/** + * @author Daniel Qian + */ public class WxErrorException extends Exception { - private static final long serialVersionUID = -6357149550353160810L; private WxError error; diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxMpErrorMsgEnum.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxMpErrorMsgEnum.java new file mode 100644 index 0000000000..3882252b72 --- /dev/null +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxMpErrorMsgEnum.java @@ -0,0 +1,654 @@ +package me.chanjar.weixin.common.error; + +import lombok.Getter; + +/** + *
+ * 微信公众平台全局返回码. + * 参考文档:公众平台全局返回码 + * Created by Binary Wang on 2018/5/13. + *+ * + * @author Binary Wang + */ +@Getter +public enum WxMpErrorMsgEnum { + /** + * 系统繁忙,此时请开发者稍候再试 + */ + CODE_1(-1, "系统繁忙,此时请开发者稍候再试"), + /** + * 请求成功 + */ + CODE_0(0, "请求成功"), + /** + * 获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口 + */ + CODE_40001(40001, "获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口"), + /** + * 不合法的凭证类型 + */ + CODE_40002(40002, "不合法的凭证类型"), + /** + * 不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID + */ + CODE_40003(40003, "不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID"), + /** + * 不合法的媒体文件类型 + */ + CODE_40004(40004, "不合法的媒体文件类型"), + /** + * 不合法的文件类型 + */ + CODE_40005(40005, "不合法的文件类型"), + /** + * 不合法的文件大小 + */ + CODE_40006(40006, "不合法的文件大小"), + /** + * 不合法的媒体文件 id + */ + CODE_40007(40007, "不合法的媒体文件 id"), + /** + * 不合法的消息类型 + */ + CODE_40008(40008, "不合法的消息类型"), + /** + * 不合法的图片文件大小 + */ + CODE_40009(40009, "不合法的图片文件大小"), + /** + * 不合法的语音文件大小 + */ + CODE_40010(40010, "不合法的语音文件大小"), + /** + * 不合法的视频文件大小 + */ + CODE_40011(40011, "不合法的视频文件大小"), + /** + * 不合法的缩略图文件大小 + */ + CODE_40012(40012, "不合法的缩略图文件大小"), + /** + * 不合法的 AppID ,请开发者检查 AppID 的正确性,避免异常字符,注意大小写 + */ + CODE_40013(40013, "不合法的 AppID ,请开发者检查 AppID 的正确性,避免异常字符,注意大小写"), + /** + * 不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口 + */ + CODE_40014(40014, "不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口"), + /** + * 不合法的菜单类型 + */ + CODE_40015(40015, "不合法的菜单类型"), + /** + * 不合法的按钮个数 + */ + CODE_40016(40016, "不合法的按钮个数"), + /** + * 不合法的按钮个数 + */ + CODE_40017(40017, "不合法的按钮个数"), + /** + * 不合法的按钮名字长度 + */ + CODE_40018(40018, "不合法的按钮名字长度"), + /** + * 不合法的按钮 KEY 长度 + */ + CODE_40019(40019, "不合法的按钮 KEY 长度"), + /** + * 不合法的按钮 URL 长度 + */ + CODE_40020(40020, "不合法的按钮 URL 长度"), + /** + * 不合法的菜单版本号 + */ + CODE_40021(40021, "不合法的菜单版本号"), + /** + * 不合法的子菜单级数 + */ + CODE_40022(40022, "不合法的子菜单级数"), + /** + * 不合法的子菜单按钮个数 + */ + CODE_40023(40023, "不合法的子菜单按钮个数"), + /** + * 不合法的子菜单按钮类型 + */ + CODE_40024(40024, "不合法的子菜单按钮类型"), + /** + * 不合法的子菜单按钮名字长度 + */ + CODE_40025(40025, "不合法的子菜单按钮名字长度"), + /** + * 不合法的子菜单按钮 KEY 长度 + */ + CODE_40026(40026, "不合法的子菜单按钮 KEY 长度"), + /** + * 不合法的子菜单按钮 URL 长度 + */ + CODE_40027(40027, "不合法的子菜单按钮 URL 长度"), + /** + * 不合法的自定义菜单使用用户 + */ + CODE_40028(40028, "不合法的自定义菜单使用用户"), + /** + * 不合法的 oauth_code + */ + CODE_40029(40029, "不合法的 oauth_code"), + /** + * 不合法的 refresh_token + */ + CODE_40030(40030, "不合法的 refresh_token"), + /** + * 不合法的 openid 列表 + */ + CODE_40031(40031, "不合法的 openid 列表"), + /** + * 不合法的 openid 列表长度 + */ + CODE_40032(40032, "不合法的 openid 列表长度"), + /** + * 不合法的请求字符,不能包含\\uxxxx 格式的字符 + */ + CODE_40033(40033, "不合法的请求字符,不能包含\\uxxxx 格式的字符"), + /** + * 不合法的参数 + */ + CODE_40035(40035, "不合法的参数"), + /** + * 不合法的请求格式 + */ + CODE_40038(40038, "不合法的请求格式"), + /** + * 不合法的 URL 长度 + */ + CODE_40039(40039, "不合法的 URL 长度"), + /** + * 不合法的分组 id + */ + CODE_40050(40050, "不合法的分组 id"), + /** + * 分组名字不合法 + */ + CODE_40051(40051, "分组名字不合法"), + /** + * 删除单篇图文时,指定的 article_idx 不合法 + */ + CODE_40060(40060, "删除单篇图文时,指定的 article_idx 不合法"), + /** + * 分组名字不合法 + */ + CODE_40117(40117, "分组名字不合法"), + /** + * media_id 大小不合法 + */ + CODE_40118(40118, "media_id 大小不合法"), + /** + * button 类型错误 + */ + CODE_40119(40119, "button 类型错误"), + /** + * button 类型错误 + */ + CODE_40120(40120, "button 类型错误"), + /** + * 不合法的 media_id 类型 + */ + CODE_40121(40121, "不合法的 media_id 类型"), + /** + * 微信号不合法 + */ + CODE_40132(40132, "微信号不合法"), + /** + * 不支持的图片格式 + */ + CODE_40137(40137, "不支持的图片格式"), + /** + * 请勿添加其他公众号的主页链接 + */ + CODE_40155(40155, "请勿添加其他公众号的主页链接"), + /** + * 缺少 access_token 参数 + */ + CODE_41001(41001, "缺少 access_token 参数"), + /** + * 缺少 appid 参数 + */ + CODE_41002(41002, "缺少 appid 参数"), + /** + * 缺少 refresh_token 参数 + */ + CODE_41003(41003, "缺少 refresh_token 参数"), + /** + * 缺少 secret 参数 + */ + CODE_41004(41004, "缺少 secret 参数"), + /** + * 缺少多媒体文件数据 + */ + CODE_41005(41005, "缺少多媒体文件数据"), + /** + * 缺少 media_id 参数 + */ + CODE_41006(41006, "缺少 media_id 参数"), + /** + * 缺少子菜单数据 + */ + CODE_41007(41007, "缺少子菜单数据"), + /** + * 缺少 oauth code + */ + CODE_41008(41008, "缺少 oauth code"), + /** + * 缺少 openid + */ + CODE_41009(41009, "缺少 openid"), + /** + * access_token 超时,请检查 access_token 的有效期,请参考基础支持 - 获取 access_token 中,对 access_token 的详细机制说明 + */ + CODE_42001(42001, "access_token 超时,请检查 access_token 的有效期,请参考基础支持 - 获取 access_token 中,对 access_token 的详细机制说明"), + /** + * refresh_token 超时 + */ + CODE_42002(42002, "refresh_token 超时"), + /** + * oauth_code 超时 + */ + CODE_42003(42003, "oauth_code 超时"), + /** + * 用户修改微信密码, accesstoken 和 refreshtoken 失效,需要重新授权 + */ + CODE_42007(42007, "用户修改微信密码, accesstoken 和 refreshtoken 失效,需要重新授权"), + /** + * 需要 GET 请求 + */ + CODE_43001(43001, "需要 GET 请求"), + /** + * 需要 POST 请求 + */ + CODE_43002(43002, "需要 POST 请求"), + /** + * 需要 HTTPS 请求 + */ + CODE_43003(43003, "需要 HTTPS 请求"), + /** + * 需要接收者关注 + */ + CODE_43004(43004, "需要接收者关注"), + /** + * 需要好友关系 + */ + CODE_43005(43005, "需要好友关系"), + /** + * 需要将接收者从黑名单中移除 + */ + CODE_43019(43019, "需要将接收者从黑名单中移除"), + /** + * 多媒体文件为空 + */ + CODE_44001(44001, "多媒体文件为空"), + /** + * POST 的数据包为空 + */ + CODE_44002(44002, "POST 的数据包为空"), + /** + * 图文消息内容为空 + */ + CODE_44003(44003, "图文消息内容为空"), + /** + * 文本消息内容为空 + */ + CODE_44004(44004, "文本消息内容为空"), + /** + * 多媒体文件大小超过限制 + */ + CODE_45001(45001, "多媒体文件大小超过限制"), + /** + * 消息内容超过限制 + */ + CODE_45002(45002, "消息内容超过限制"), + /** + * 标题字段超过限制 + */ + CODE_45003(45003, "标题字段超过限制"), + /** + * 描述字段超过限制 + */ + CODE_45004(45004, "描述字段超过限制"), + /** + * 链接字段超过限制 + */ + CODE_45005(45005, "链接字段超过限制"), + /** + * 图片链接字段超过限制 + */ + CODE_45006(45006, "图片链接字段超过限制"), + /** + * 语音播放时间超过限制 + */ + CODE_45007(45007, "语音播放时间超过限制"), + /** + * 图文消息超过限制 + */ + CODE_45008(45008, "图文消息超过限制"), + /** + * 接口调用超过限制 + */ + CODE_45009(45009, "接口调用超过限制"), + /** + * 创建菜单个数超过限制 + */ + CODE_45010(45010, "创建菜单个数超过限制"), + /** + * API 调用太频繁,请稍候再试 + */ + CODE_45011(45011, "API 调用太频繁,请稍候再试"), + /** + * 回复时间超过限制 + */ + CODE_45015(45015, "回复时间超过限制"), + /** + * 系统分组,不允许修改 + */ + CODE_45016(45016, "系统分组,不允许修改"), + /** + * 分组名字过长 + */ + CODE_45017(45017, "分组名字过长"), + /** + * 分组数量超过上限 + */ + CODE_45018(45018, "分组数量超过上限"), + /** + * 客服接口下行条数超过上限 + */ + CODE_45047(45047, "客服接口下行条数超过上限"), + /** + * 不存在媒体数据 + */ + CODE_46001(46001, "不存在媒体数据"), + /** + * 不存在的菜单版本 + */ + CODE_46002(46002, "不存在的菜单版本"), + /** + * 不存在的菜单数据 + */ + CODE_46003(46003, "不存在的菜单数据"), + /** + * 不存在的用户 + */ + CODE_46004(46004, "不存在的用户"), + /** + * 解析 JSON/XML 内容错误 + */ + CODE_47001(47001, "解析 JSON/XML 内容错误"), + /** + * api 功能未授权,请确认公众号已获得该接口,可以在公众平台官网 - 开发者中心页中查看接口权限 + */ + CODE_48001(48001, "api 功能未授权,请确认公众号已获得该接口,可以在公众平台官网 - 开发者中心页中查看接口权限"), + /** + * 粉丝拒收消息(粉丝在公众号选项中,关闭了 “ 接收消息 ” ) + */ + CODE_48002(48002, "粉丝拒收消息(粉丝在公众号选项中,关闭了 “ 接收消息 ” )"), + /** + * api 接口被封禁,请登录 mp.weixin.qq.com 查看详情 + */ + CODE_48004(48004, "api 接口被封禁,请登录 mp.weixin.qq.com 查看详情"), + /** + * api 禁止删除被自动回复和自定义菜单引用的素材 + */ + CODE_48005(48005, "api 禁止删除被自动回复和自定义菜单引用的素材"), + /** + * api 禁止清零调用次数,因为清零次数达到上限 + */ + CODE_48006(48006, "api 禁止清零调用次数,因为清零次数达到上限"), + /** + * 没有该类型消息的发送权限 + */ + CODE_48008(48008, "没有该类型消息的发送权限"), + /** + * 用户未授权该 api + */ + CODE_50001(50001, "用户未授权该 api"), + /** + * 用户受限,可能是违规后接口被封禁 + */ + CODE_50002(50002, "用户受限,可能是违规后接口被封禁"), + /** + * 用户未关注公众号 + */ + CODE_50005(50005, "用户未关注公众号"), + /** + * 参数错误 (invalid parameter) + */ + CODE_61451(61451, "参数错误 (invalid parameter)"), + /** + * 无效客服账号 (invalid kf_account) + */ + CODE_61452(61452, "无效客服账号 (invalid kf_account)"), + /** + * 客服帐号已存在 (kf_account exsited) + */ + CODE_61453(61453, "客服帐号已存在 (kf_account exsited)"), + /** + * 客服帐号名长度超过限制 ( 仅允许 10 个英文字符,不包括 @ 及 @ 后的公众号的微信号 )(invalid kf_acount length) + */ + CODE_61454(61454, "客服帐号名长度超过限制 ( 仅允许 10 个英文字符,不包括 @ 及 @ 后的公众号的微信号 )(invalid kf_acount length)"), + /** + * 客服帐号名包含非法字符 ( 仅允许英文 + 数字 )(illegal character in kf_account) + */ + CODE_61455(61455, "客服帐号名包含非法字符 ( 仅允许英文 + 数字 )(illegal character in kf_account)"), + /** + * 客服帐号个数超过限制 (10 个客服账号 )(kf_account count exceeded) + */ + CODE_61456(61456, "客服帐号个数超过限制 (10 个客服账号 )(kf_account count exceeded)"), + /** + * 无效头像文件类型 (invalid file type) + */ + CODE_61457(61457, "无效头像文件类型 (invalid file type)"), + /** + * 系统错误 (system error) + */ + CODE_61450(61450, "系统错误 (system error)"), + /** + * 日期格式错误 + */ + CODE_61500(61500, "日期格式错误"), + /** + * 不存在此 menuid 对应的个性化菜单 + */ + CODE_65301(65301, "不存在此 menuid 对应的个性化菜单"), + /** + * 没有相应的用户 + */ + CODE_65302(65302, "没有相应的用户"), + /** + * 没有默认菜单,不能创建个性化菜单 + */ + CODE_65303(65303, "没有默认菜单,不能创建个性化菜单"), + /** + * MatchRule 信息为空 + */ + CODE_65304(65304, "MatchRule 信息为空"), + /** + * 个性化菜单数量受限 + */ + CODE_65305(65305, "个性化菜单数量受限"), + /** + * 不支持个性化菜单的帐号 + */ + CODE_65306(65306, "不支持个性化菜单的帐号"), + /** + * 个性化菜单信息为空 + */ + CODE_65307(65307, "个性化菜单信息为空"), + /** + * 包含没有响应类型的 button + */ + CODE_65308(65308, "包含没有响应类型的 button"), + /** + * 个性化菜单开关处于关闭状态 + */ + CODE_65309(65309, "个性化菜单开关处于关闭状态"), + /** + * 填写了省份或城市信息,国家信息不能为空 + */ + CODE_65310(65310, "填写了省份或城市信息,国家信息不能为空"), + /** + * 填写了城市信息,省份信息不能为空 + */ + CODE_65311(65311, "填写了城市信息,省份信息不能为空"), + /** + * 不合法的国家信息 + */ + CODE_65312(65312, "不合法的国家信息"), + /** + * 不合法的省份信息 + */ + CODE_65313(65313, "不合法的省份信息"), + /** + * 不合法的城市信息 + */ + CODE_65314(65314, "不合法的城市信息"), + /** + * 该公众号的菜单设置了过多的域名外跳(最多跳转到 3 个域名的链接) + */ + CODE_65316(65316, "该公众号的菜单设置了过多的域名外跳(最多跳转到 3 个域名的链接)"), + /** + * 不合法的 URL + */ + CODE_65317(65317, "不合法的 URL"), + /** + * POST 数据参数不合法 + */ + CODE_9001001(9001001, "POST 数据参数不合法"), + /** + * 远端服务不可用 + */ + CODE_9001002(9001002, "远端服务不可用"), + /** + * Ticket 不合法 + */ + CODE_9001003(9001003, "Ticket 不合法"), + /** + * 获取摇周边用户信息失败 + */ + CODE_9001004(9001004, "获取摇周边用户信息失败"), + /** + * 获取商户信息失败 + */ + CODE_9001005(9001005, "获取商户信息失败"), + /** + * 获取 OpenID 失败 + */ + CODE_9001006(9001006, "获取 OpenID 失败"), + /** + * 上传文件缺失 + */ + CODE_9001007(9001007, "上传文件缺失"), + /** + * 上传素材的文件类型不合法 + */ + CODE_9001008(9001008, "上传素材的文件类型不合法"), + /** + * 上传素材的文件尺寸不合法 + */ + CODE_9001009(9001009, "上传素材的文件尺寸不合法"), + /** + * 上传失败 + */ + CODE_9001010(9001010, "上传失败"), + /** + * 帐号不合法 + */ + CODE_9001020(9001020, "帐号不合法"), + /** + * 已有设备激活率低于 50% ,不能新增设备 + */ + CODE_9001021(9001021, "已有设备激活率低于 50% ,不能新增设备"), + /** + * 设备申请数不合法,必须为大于 0 的数字 + */ + CODE_9001022(9001022, "设备申请数不合法,必须为大于 0 的数字"), + /** + * 已存在审核中的设备 ID 申请 + */ + CODE_9001023(9001023, "已存在审核中的设备 ID 申请"), + /** + * 一次查询设备 ID 数量不能超过 50 + */ + CODE_9001024(9001024, "一次查询设备 ID 数量不能超过 50"), + /** + * 设备 ID 不合法 + */ + CODE_9001025(9001025, "设备 ID 不合法"), + /** + * 页面 ID 不合法 + */ + CODE_9001026(9001026, "页面 ID 不合法"), + /** + * 页面参数不合法 + */ + CODE_9001027(9001027, "页面参数不合法"), + /** + * 一次删除页面 ID 数量不能超过 10 + */ + CODE_9001028(9001028, "一次删除页面 ID 数量不能超过 10"), + /** + * 页面已应用在设备中,请先解除应用关系再删除 + */ + CODE_9001029(9001029, "页面已应用在设备中,请先解除应用关系再删除"), + /** + * 一次查询页面 ID 数量不能超过 50 + */ + CODE_9001030(9001030, "一次查询页面 ID 数量不能超过 50"), + /** + * 时间区间不合法 + */ + CODE_9001031(9001031, "时间区间不合法"), + /** + * 保存设备与页面的绑定关系参数错误 + */ + CODE_9001032(9001032, "保存设备与页面的绑定关系参数错误"), + /** + * 门店 ID 不合法 + */ + CODE_9001033(9001033, "门店 ID 不合法"), + /** + * 设备备注信息过长 + */ + CODE_9001034(9001034, "设备备注信息过长"), + /** + * 设备申请参数不合法 + */ + CODE_9001035(9001035, "设备申请参数不合法"), + /** + * 查询起始值 begin 不合法 + */ + CODE_9001036(9001036, "查询起始值 begin 不合法"); + + private int code; + private String msg; + + WxMpErrorMsgEnum(int code, String msg) { + this.code = code; + this.msg = msg; + } + + /** + * 通过错误代码查找其中文含义. + */ + public static String findMsgByCode(int code) { + WxMpErrorMsgEnum[] values = WxMpErrorMsgEnum.values(); + for (WxMpErrorMsgEnum value : values) { + if (value.code == code) { + return value.msg; + } + } + + return null; + } +} 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 fb031e2357..4b7f9be6a7 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 @@ -1,21 +1,17 @@ package me.chanjar.weixin.common.util; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.thoughtworks.xstream.annotations.XStreamAlias; import me.chanjar.weixin.common.annotation.Required; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; 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; -import java.util.Map; /** *
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/DataUtils.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/DataUtils.java new file mode 100644 index 0000000000..983d9a668f --- /dev/null +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/DataUtils.java @@ -0,0 +1,24 @@ +package me.chanjar.weixin.common.util; + +import org.apache.commons.lang3.StringUtils; + +/** + *+ * 数据处理工具类 + * Created by BinaryWang on 2018/5/8. + *+ * + * @author Binary Wang + */ +public class DataUtils { + /** + * 将数据中包含的secret字符使用星号替换,防止日志打印时被输出 + */ + public staticE handleDataWithSecret(E data) { + E dataForLog = data; + if(data instanceof String && StringUtils.contains((String)data, "&secret=")){ + dataForLog = (E) StringUtils.replaceAll((String)data,"&secret=\\w+&","&secret=******&"); + } + return dataForLog; + } +} diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/LogExceptionHandler.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/LogExceptionHandler.java index 7ad976abd8..7487a0fe29 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/LogExceptionHandler.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/LogExceptionHandler.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.common.util; import me.chanjar.weixin.common.api.WxErrorExceptionHandler; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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 234422b04b..1b051a4718 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 @@ -19,7 +19,7 @@ public static File createTmpFile(InputStream inputStream, String name, String ex File resultFile = File.createTempFile(name, '.' + ext, tmpDirFile); resultFile.deleteOnExit(); - org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, resultFile); + org.apache.commons.io.FileUtils.copyToFile(inputStream, resultFile); return resultFile; } 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 37efdaaf38..ceaeffbd1e 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 @@ -1,8 +1,8 @@ package me.chanjar.weixin.common.util.http; import jodd.http.HttpResponse; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import okhttp3.Response; import org.apache.http.Header; import org.apache.http.client.methods.CloseableHttpResponse; diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/RequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/RequestExecutor.java index 583db4f5ae..a5a9423fd0 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/RequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/RequestExecutor.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.common.util.http; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import java.io.IOException; @@ -9,51 +9,13 @@ * * @param 返回值类型 * @param 请求参数类型 + * @author Daniel Qian */ public interface RequestExecutor { /** * @param uri uri * @param data 数据 - * @throws WxErrorException - * @throws IOException */ T execute(String uri, E data) throws WxErrorException, IOException; - - /** - * apache-http实现方式 - * @param httpclient - * @param httpProxy - * @param uri - * @param data - * @return - * @throws WxErrorException - * @throws IOException - *//* - T executeApache(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, E data) throws WxErrorException, IOException; - - *//** - * jodd-http实现方式 - * @param provider - * @param proxyInfo - * @param uri - * @param data - * @return - * @throws WxErrorException - * @throws IOException - *//* - T executeJodd(HttpConnectionProvider provider, ProxyInfo proxyInfo, String uri, E data) throws WxErrorException, IOException; - - - *//** okhttp实现方式 - * @param pool - * @param proxyInfo - * @param uri - * @param data - * @return - * @throws WxErrorException - * @throws IOException - *//* - T executeOkhttp(ConnectionPool pool, final OkHttpProxyInfo proxyInfo, String uri, E data) throws WxErrorException, IOException; -*/ } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheHttpClientSimpleGetRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheHttpClientSimpleGetRequestExecutor.java index e47216e6cd..658ea4afd0 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheHttpClientSimpleGetRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheHttpClientSimpleGetRequestExecutor.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.common.util.http.apache; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; import org.apache.http.HttpHost; 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 be2d91b84f..2ce8750822 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 @@ -1,11 +1,9 @@ package me.chanjar.weixin.common.util.http.apache; -import me.chanjar.weixin.common.bean.result.WxError; -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.BaseMediaDownloadRequestExecutor; -import me.chanjar.weixin.common.util.http.RequestHttp; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.apache.http.Header; @@ -16,9 +14,12 @@ import org.apache.http.entity.ContentType; import org.apache.http.impl.client.CloseableHttpClient; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.util.fs.FileUtils; +import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor; +import me.chanjar.weixin.common.util.http.HttpResponseProxy; +import me.chanjar.weixin.common.util.http.RequestHttp; /** * Created by ecoolper on 2017/5/5. @@ -45,8 +46,7 @@ public File execute(String uri, String queryParam) throws WxErrorException, IOEx } try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpGet); - InputStream inputStream = InputStreamResponseHandler.INSTANCE - .handleResponse(response)) { + InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response)) { Header[] contentTypeHeader = response.getHeaders("Content-Type"); if (contentTypeHeader != null && contentTypeHeader.length > 0) { if (contentTypeHeader[0].getValue().startsWith(ContentType.APPLICATION_JSON.getMimeType())) { diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheMediaUploadRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheMediaUploadRequestExecutor.java index bdddf0dfb9..6684bb9362 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheMediaUploadRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheMediaUploadRequestExecutor.java @@ -1,8 +1,8 @@ package me.chanjar.weixin.common.util.http.apache; -import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; import org.apache.http.HttpEntity; @@ -10,7 +10,6 @@ import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.HttpMultipartMode; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.impl.client.CloseableHttpClient; 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 1a8a292b9f..2517dbcd71 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 @@ -1,7 +1,7 @@ package me.chanjar.weixin.common.util.http.apache; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; import org.apache.http.Consts; 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 f3442aaa6d..a0918f5b35 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 @@ -1,23 +1,24 @@ package me.chanjar.weixin.common.util.http.jodd; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.StringUtils; + import jodd.http.HttpConnectionProvider; import jodd.http.HttpRequest; 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.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; -import me.chanjar.weixin.common.util.http.HttpResponseProxy; import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor; +import me.chanjar.weixin.common.util.http.HttpResponseProxy; import me.chanjar.weixin.common.util.http.RequestHttp; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.lang3.StringUtils; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; /** * Created by ecoolper on 2017/5/5. @@ -57,9 +58,12 @@ public File execute(String uri, String queryParam) throws WxErrorException, IOEx return null; } - InputStream inputStream = new ByteArrayInputStream(response.bodyBytes()); - return FileUtils.createTmpFile(inputStream, FilenameUtils.getBaseName(fileName), FilenameUtils.getExtension(fileName), - super.tmpDirFile); + try (InputStream inputStream = new ByteArrayInputStream(response.bodyBytes())) { + return FileUtils.createTmpFile(inputStream, + FilenameUtils.getBaseName(fileName), + FilenameUtils.getExtension(fileName), + super.tmpDirFile); + } } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMediaUploadRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMediaUploadRequestExecutor.java index b4eef26a79..8ef4ddec1e 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMediaUploadRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMediaUploadRequestExecutor.java @@ -6,9 +6,9 @@ import jodd.http.ProxyInfo; import jodd.util.StringPool; -import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpSimpleGetRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpSimpleGetRequestExecutor.java index 63386e77a8..bee1d174f7 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpSimpleGetRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpSimpleGetRequestExecutor.java @@ -3,8 +3,8 @@ import jodd.http.*; import jodd.util.StringPool; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; 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 57207f1b3e..b4ee996971 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,8 +5,8 @@ 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.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; 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 b3ddaf3c3c..6f0a535fdf 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 @@ -1,7 +1,7 @@ package me.chanjar.weixin.common.util.http.okhttp; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor; import me.chanjar.weixin.common.util.http.HttpResponseProxy; import me.chanjar.weixin.common.util.http.RequestHttp; diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpMediaUploadRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpMediaUploadRequestExecutor.java index 9edeee89be..02fffb1b1b 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpMediaUploadRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpMediaUploadRequestExecutor.java @@ -1,8 +1,8 @@ package me.chanjar.weixin.common.util.http.okhttp; -import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; import okhttp3.*; diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpSimpleGetRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpSimpleGetRequestExecutor.java index e468c609c8..380014d003 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpSimpleGetRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpSimpleGetRequestExecutor.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.common.util.http.okhttp; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; import okhttp3.*; diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpSimplePostRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpSimplePostRequestExecutor.java index bc54d7b4cd..8ba0906b38 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpSimplePostRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpSimplePostRequestExecutor.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.common.util.http.okhttp; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; import okhttp3.*; 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 6646ed8d9d..0ea52b9a86 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 @@ -1,7 +1,7 @@ package me.chanjar.weixin.common.util.json; import com.google.gson.*; -import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.error.WxError; import java.lang.reflect.Type; diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxGsonBuilder.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxGsonBuilder.java index 9847d16211..7c7d92f03c 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxGsonBuilder.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxGsonBuilder.java @@ -4,7 +4,7 @@ import com.google.gson.GsonBuilder; import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.bean.menu.WxMenu; -import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; public class WxGsonBuilder { diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/XStreamInitializer.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/XStreamInitializer.java index e1a00c3348..d97062ee61 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/XStreamInitializer.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/XStreamInitializer.java @@ -1,5 +1,7 @@ package me.chanjar.weixin.common.util.xml; +import java.io.Writer; + import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider; import com.thoughtworks.xstream.core.util.QuickWriter; @@ -9,8 +11,6 @@ import com.thoughtworks.xstream.security.NullPermission; import com.thoughtworks.xstream.security.PrimitiveTypePermission; -import java.io.Writer; - public class XStreamInitializer { public static XStream getInstance() { @@ -38,7 +38,8 @@ protected void writeText(QuickWriter writer, String text) { @Override public String encodeNode(String name) { - return name;//防止将_转换成__ + //防止将_转换成__ + return name; } }; } @@ -48,6 +49,7 @@ public String encodeNode(String name) { xstream.setMode(XStream.NO_REFERENCES); xstream.addPermission(NullPermission.NULL); xstream.addPermission(PrimitiveTypePermission.PRIMITIVES); + xstream.setClassLoader(Thread.currentThread().getContextClassLoader()); return xstream; } 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/error/WxErrorTest.java similarity index 53% rename from weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxErrorTest.java rename to weixin-java-common/src/test/java/me/chanjar/weixin/common/error/WxErrorTest.java index 1c05ea731e..bbefd4879b 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/error/WxErrorTest.java @@ -1,8 +1,9 @@ -package me.chanjar.weixin.common.bean; +package me.chanjar.weixin.common.error; -import me.chanjar.weixin.common.bean.result.WxError; -import org.testng.*; -import org.testng.annotations.*; +import org.testng.Assert; +import org.testng.annotations.Test; + +import static org.testng.Assert.*; @Test public class WxErrorTest { @@ -10,26 +11,24 @@ public class WxErrorTest { public void testFromJson() { String json = "{ \"errcode\": 40003, \"errmsg\": \"invalid openid\" }"; WxError wxError = WxError.fromJson(json); - Assert.assertTrue(wxError.getErrorCode() == 40003); - Assert.assertEquals(wxError.getErrorMsg(), "invalid openid"); + assertEquals(40003, wxError.getErrorCode()); + assertEquals(wxError.getErrorMsg(), "invalid openid"); } public void testFromBadJson1() { - String json = "{ \"errcode\": 40003, \"errmsg\": \"invalid openid\", \"media_id\": \"12323423dsfafsf232f\" }"; WxError wxError = WxError.fromJson(json); - Assert.assertTrue(wxError.getErrorCode() == 40003); - Assert.assertEquals(wxError.getErrorMsg(), "invalid openid"); + assertEquals(40003, wxError.getErrorCode()); + assertEquals(wxError.getErrorMsg(), "invalid openid"); } public void testFromBadJson2() { - String json = "{\"access_token\":\"ACCESS_TOKEN\",\"expires_in\":7200}"; WxError wxError = WxError.fromJson(json); - Assert.assertTrue(wxError.getErrorCode() == 0); - Assert.assertEquals(wxError.getErrorMsg(), null); + assertEquals(0, wxError.getErrorCode()); + assertEquals(wxError.getErrorMsg(), null); } diff --git a/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/DataUtilsTest.java b/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/DataUtilsTest.java new file mode 100644 index 0000000000..af34880901 --- /dev/null +++ b/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/DataUtilsTest.java @@ -0,0 +1,23 @@ +package me.chanjar.weixin.common.util; + +import org.testng.annotations.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.testng.Assert.*; + +/** + * + * Created by BinaryWang on 2018/5/8. + *+ * + * @author Binary Wang + */ +public class DataUtilsTest { + + @Test + public void testHandleDataWithSecret() { + String data = "js_code=001tZveq0SMoiq1AEXeq0ECJeq0tZveZ&secret=5681022fa1643845392367ea88888888&grant_type=authorization_code&appid=wxe156d4848d999999"; + final String s = DataUtils.handleDataWithSecret(data); + assertThat(s).contains("&secret=******&"); + } +} diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index ff4293b8dc..a0bf143fcd 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -7,7 +7,7 @@com.github.binarywang weixin-java-parent -3.0.0 +3.1.0 weixin-java-cp diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java new file mode 100644 index 0000000000..3fbc981b63 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java @@ -0,0 +1,28 @@ +package me.chanjar.weixin.cp.api; + +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.cp.bean.WxCpAgent; + +/** + *+ * 管理企业号应用 + * Created by huansinho on 2018/4/13. + *+ * + * @author huansinho + */ +public interface WxCpAgentService { + + /** + *+ * 获取企业号应用信息 + * 该API用于获取企业号某个应用的基本信息,包括头像、昵称、帐号类型、认证类型、可见范围等信息 + * 详情请见: http://qydev.weixin.qq.com/wiki/index.php?title=获取企业号应用 + *+ * + * @param agentId 企业应用的id + * @return 部门id + */ + WxCpAgent get(Integer agentId) throws WxErrorException; + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java index f981f03526..45da3c0d83 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.cp.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.bean.WxCpDepart; import java.util.List; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMediaService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMediaService.java index f813f1bf3f..bef0401e0a 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMediaService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMediaService.java @@ -1,12 +1,12 @@ package me.chanjar.weixin.cp.api; -import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; - import java.io.File; import java.io.IOException; import java.io.InputStream; +import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; +import me.chanjar.weixin.common.error.WxErrorException; + /** ** 媒体管理接口 @@ -30,7 +30,7 @@ public interface WxCpMediaService { * * @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts} * @param fileType 文件类型,请看{@link me.chanjar.weixin.common.api.WxConsts} - * @param inputStream 输入流 + * @param inputStream 输入流,需要调用方控制关闭该输入流 */ WxMediaUploadResult upload(String mediaType, String fileType, InputStream inputStream) throws WxErrorException, IOException; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMenuService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMenuService.java index 012efefb7f..068c037a48 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMenuService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMenuService.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.cp.api; import me.chanjar.weixin.common.bean.menu.WxMenu; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; /** *diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java index 3312489538..a9fa5f9455 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.cp.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.cp.bean.WxCpUserDetail; /** *@@ -64,4 +65,19 @@ public interface WxCpOAuth2Service { */ String[] getUserInfo(Integer agentId, String code) throws WxErrorException; + /** + *+ * 使用user_ticket获取成员详情. + * + * 文档地址:https://work.weixin.qq.com/api/doc#10028/%E4%BD%BF%E7%94%A8user_ticket%E8%8E%B7%E5%8F%96%E6%88%90%E5%91%98%E8%AF%A6%E6%83%85 + * 请求方式:POST(HTTPS) + * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/user/getuserdetail?access_token=ACCESS_TOKEN + * + * 权限说明: + * 需要有对应应用的使用权限,且成员必须在授权应用的可见范围内。 + *+ * + * @param userTicket 成员票据 + */ + WxCpUserDetail getUserDetail(String userTicket) throws WxErrorException; } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java index 3a63de9899..3e33c4eb55 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java @@ -1,9 +1,7 @@ package me.chanjar.weixin.cp.api; import me.chanjar.weixin.common.bean.WxJsapiSignature; -import me.chanjar.weixin.common.bean.menu.WxMenu; -import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.session.WxSession; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; @@ -12,11 +10,6 @@ import me.chanjar.weixin.cp.bean.*; import me.chanjar.weixin.cp.config.WxCpConfigStorage; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - /** * 微信API的Service * @author chanjaster @@ -249,6 +242,8 @@ public interface WxCpService { */ WxCpUserService getUserService(); + WxCpAgentService getAgentService(); + /** * http请求对象 */ diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java index c96318b80b..9624f9e409 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java @@ -1,15 +1,16 @@ package me.chanjar.weixin.cp.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.bean.WxCpTag; import me.chanjar.weixin.cp.bean.WxCpTagAddOrRemoveUsersResult; +import me.chanjar.weixin.cp.bean.WxCpTagGetResult; import me.chanjar.weixin.cp.bean.WxCpUser; import java.util.List; /** *- * 标签管理接口 + * 标签管理接口. * Created by BinaryWang on 2017/6/24. ** @@ -17,14 +18,14 @@ */ public interface WxCpTagService { /** - * 创建标签 + * 创建标签. * * @param tagName 标签名 */ String create(String tagName) throws WxErrorException; /** - * 更新标签 + * 更新标签. * * @param tagId 标签id * @param tagName 标签名 @@ -32,35 +33,49 @@ public interface WxCpTagService { void update(String tagId, String tagName) throws WxErrorException; /** - * 删除标签 + * 删除标签. * * @param tagId 标签id */ void delete(String tagId) throws WxErrorException; /** - * 获得标签列表 + * 获得标签列表. */ ListlistAll() throws WxErrorException; /** - * 获取标签成员 + * 获取标签成员. * * @param tagId 标签ID */ List listUsersByTagId(String tagId) throws WxErrorException; /** - * 增加标签成员 - * @param tagId 标签id - * @param userIds 用户ID 列表 + * 增加标签成员. + * + * @param tagId 标签id + * @param userIds 用户ID 列表 + * @param partyIds 企业部门ID列表 */ WxCpTagAddOrRemoveUsersResult addUsers2Tag(String tagId, List userIds, List partyIds) throws WxErrorException; /** - * 移除标签成员 - * @param tagId 标签id - * @param userIds 用户id列表 + * 移除标签成员. + * + * @param tagId 标签id + * @param userIds 用户id列表 + * @param partyIds 企业部门ID列表 */ - WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List userIds) throws WxErrorException; + WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List userIds, List partyIds) throws WxErrorException; + + + /** + * 获取标签成员. + * 对应: http://qydev.weixin.qq.com/wiki/index.php?title=管理标签 中的get接口 + * + * @param tagId 标签id + */ + WxCpTagGetResult get(String tagId) throws WxErrorException; + } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java index 93333fefe6..05211d71dd 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.cp.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.cp.bean.WxCpInviteResult; import me.chanjar.weixin.cp.bean.WxCpUser; import java.util.List; @@ -84,18 +85,18 @@ public interface WxCpUserService { /** * - * 邀请成员关注 - * http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E9.82.80.E8.AF.B7.E6.88.90.E5.91.98.E5.85.B3.E6.B3.A8 + * 邀请成员 + * 企业可通过接口批量邀请成员使用企业微信,邀请后将通过短信或邮件下发通知。 + * 请求方式:POST(HTTPS) + * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/batch/invite?access_token=ACCESS_TOKEN + * 文档地址:https://work.weixin.qq.com/api/doc#12543 ** - * @param userId 用户的userid - * @param inviteTips 推送到微信上的提示语(只有认证号可以使用)。当使用微信推送时,该字段默认为“请关注XXX企业号”,邮件邀请时,该字段无效。 - * @return 1:微信邀请 2.邮件邀请 - * @deprecated api obsoleted. 邀请关注的功能微信企业号已经下线了, - * 详细请参考该链接点击查看 https://qy.weixin.qq.com/cgi-bin/homepagenotify?action=get&id=46 + * @param userIds 成员ID列表, 最多支持1000个。 + * @param partyIds 部门ID列表,最多支持100个。 + * @param tagIds 标签ID列表,最多支持100个。 */ - @Deprecated - int invite(String userId, String inviteTips) throws WxErrorException; + WxCpInviteResult invite(ListuserIds, List partyIds, List tagIds) throws WxErrorException; /** * diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java new file mode 100644 index 0000000000..3a2733b807 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java @@ -0,0 +1,37 @@ +package me.chanjar.weixin.cp.api.impl; + +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.cp.api.WxCpAgentService; +import me.chanjar.weixin.cp.api.WxCpService; +import me.chanjar.weixin.cp.bean.WxCpAgent; + + +/** + *+ * 管理企业号应用 + * Created by huansinho on 2018/4/13. + *+ * + * @author huansinho + */ +public class WxCpAgentServiceImpl implements WxCpAgentService { + private WxCpService mainService; + + public WxCpAgentServiceImpl(WxCpService mainService) { + this.mainService = mainService; + } + + @Override + public WxCpAgent get(Integer agentId) throws WxErrorException { + + String url = "https://qyapi.weixin.qq.com/cgi-bin/agent/get"; + if (agentId != null) { + url += "?agentid=" + agentId; + } else { + throw new IllegalArgumentException("缺少agentid参数"); + } + String responseContent = this.mainService.get(url, null); + return WxCpAgent.fromJson(responseContent); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java index d836517fa0..6645219902 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java @@ -3,7 +3,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonParser; import com.google.gson.reflect.TypeToken; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.cp.api.WxCpDepartmentService; import me.chanjar.weixin.cp.api.WxCpService; 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 706ba2e01d..f1cf272fed 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 @@ -1,7 +1,7 @@ package me.chanjar.weixin.cp.api.impl; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor; import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImpl.java index 7c3937d83e..f58eff4763 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImpl.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.cp.api.impl; import me.chanjar.weixin.common.bean.menu.WxMenu; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.WxCpMenuService; import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java index 123d750726..f5950f5b7f 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java @@ -1,13 +1,15 @@ package me.chanjar.weixin.cp.api.impl; +import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.URIUtil; import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.cp.api.WxCpOAuth2Service; import me.chanjar.weixin.cp.api.WxCpService; +import me.chanjar.weixin.cp.bean.WxCpUserDetail; /** *@@ -52,9 +54,8 @@ public String[] getUserInfo(String code) throws WxErrorException { @Override public String[] getUserInfo(Integer agentId, String code) throws WxErrorException { - String url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?" - + "code=" + code - + "&agentid=" + agentId; + String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?code=%s&agentid=%d", + code, agentId); String responseText = this.mainService.get(url, null); JsonElement je = new JsonParser().parse(responseText); JsonObject jo = je.getAsJsonObject(); @@ -63,4 +64,12 @@ public String[] getUserInfo(Integer agentId, String code) throws WxErrorExceptio GsonHelper.getString(jo, "OpenId")}; } + @Override + public WxCpUserDetail getUserDetail(String userTicket) throws WxErrorException { + String url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserdetail"; + JsonObject param = new JsonObject(); + param.addProperty("user_ticket", userTicket); + String responseText = this.mainService.post(url, param.toString()); + return new GsonBuilder().create().fromJson(responseText, WxCpUserDetail.class); + } } 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 797e4a4c97..0c66e0ef77 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 @@ -5,13 +5,12 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import me.chanjar.weixin.common.bean.WxJsapiSignature; -import me.chanjar.weixin.common.bean.menu.WxMenu; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.session.StandardSessionManager; import me.chanjar.weixin.common.session.WxSession; import me.chanjar.weixin.common.session.WxSessionManager; +import me.chanjar.weixin.common.util.DataUtils; import me.chanjar.weixin.common.util.RandomUtils; import me.chanjar.weixin.common.util.crypto.SHA1; import me.chanjar.weixin.common.util.http.RequestExecutor; @@ -21,14 +20,11 @@ import me.chanjar.weixin.cp.api.*; import me.chanjar.weixin.cp.bean.*; import me.chanjar.weixin.cp.config.WxCpConfigStorage; -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; -import java.io.InputStream; -import java.util.List; public abstract class WxCpServiceAbstractImplimplements WxCpService, RequestHttp { protected final Logger log = LoggerFactory.getLogger(this.getClass()); @@ -39,6 +35,7 @@ public abstract class WxCpServiceAbstractImpl implements WxCpService, Requ private WxCpMenuService menuService = new WxCpMenuServiceImpl(this); private WxCpOAuth2Service oauth2Service = new WxCpOAuth2ServiceImpl(this); private WxCpTagService tagService = new WxCpTagServiceImpl(this); + private WxCpAgentService agentService = new WxCpAgentServiceImpl(this); /** * 全局的是否正在刷新access token的锁 @@ -200,6 +197,8 @@ public T execute(RequestExecutor executor, String uri, E data) thro } protected T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException { + E dataForLog = DataUtils.handleDataWithSecret(data); + if (uri.contains("access_token=")) { throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri); } @@ -209,7 +208,7 @@ protected T executeInternal(RequestExecutor executor, String uri, E try { T result = executor.execute(uriWithAccessToken, data); - this.log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, data, result); + this.log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, dataForLog, result); return result; } catch (WxErrorException e) { WxError error = e.getError(); @@ -226,12 +225,12 @@ protected T executeInternal(RequestExecutor executor, String uri, E } if (error.getErrorCode() != 0) { - this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, data, error); + this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, dataForLog, error); throw new WxErrorException(error, e); } return null; } catch (IOException e) { - this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, data, e.getMessage()); + this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage()); throw new RuntimeException(e); } } @@ -368,4 +367,13 @@ public void setOauth2Service(WxCpOAuth2Service oauth2Service) { public void setTagService(WxCpTagService tagService) { this.tagService = tagService; } + + @Override + public WxCpAgentService getAgentService() { + return agentService; + } + + public void setAgentService(WxCpAgentService agentService) { + this.agentService = agentService; + } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java index af32f5fb5d..7081272793 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java @@ -1,9 +1,10 @@ package me.chanjar.weixin.cp.api.impl; +import me.chanjar.weixin.common.WxType; import me.chanjar.weixin.common.bean.WxAccessToken; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.HttpType; import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder; import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder; @@ -58,7 +59,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException { } finally { httpGet.releaseConnection(); } - WxError error = WxError.fromJson(resultContent); + WxError error = WxError.fromJson(resultContent, WxType.CP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceJoddHttpImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceJoddHttpImpl.java index 3e7c4bc5b8..2d7e1b1c29 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceJoddHttpImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceJoddHttpImpl.java @@ -1,9 +1,10 @@ package me.chanjar.weixin.cp.api.impl; import jodd.http.*; +import me.chanjar.weixin.common.WxType; import me.chanjar.weixin.common.bean.WxAccessToken; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.HttpType; import me.chanjar.weixin.cp.config.WxCpConfigStorage; @@ -44,7 +45,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException { HttpResponse response = request.send(); String resultContent = response.bodyText(); - WxError error = WxError.fromJson(resultContent); + WxError error = WxError.fromJson(resultContent, WxType.CP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } 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 af9219cfe8..34c978cd4f 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 @@ -1,8 +1,9 @@ package me.chanjar.weixin.cp.api.impl; +import me.chanjar.weixin.common.WxType; import me.chanjar.weixin.common.bean.WxAccessToken; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.HttpType; import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo; import me.chanjar.weixin.cp.config.WxCpConfigStorage; @@ -51,7 +52,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException { this.log.error(e.getMessage(), e); } - WxError error = WxError.fromJson(resultContent); + WxError error = WxError.fromJson(resultContent, WxType.CP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImpl.java index ff995d9724..aa8260b14e 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImpl.java @@ -2,11 +2,12 @@ import com.google.gson.*; import com.google.gson.reflect.TypeToken; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.api.WxCpTagService; import me.chanjar.weixin.cp.bean.WxCpTag; import me.chanjar.weixin.cp.bean.WxCpTagAddOrRemoveUsersResult; +import me.chanjar.weixin.cp.bean.WxCpTagGetResult; import me.chanjar.weixin.cp.bean.WxCpUser; import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; @@ -82,6 +83,22 @@ public WxCpTagAddOrRemoveUsersResult addUsers2Tag(String tagId, List use String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers"; JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("tagid", tagId); + this.addUserIdsAndPartyIdsToJson(userIds, partyIds, jsonObject); + + return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString())); + } + + @Override + public WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List userIds, List partyIds) throws WxErrorException { + String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers"; + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("tagid", tagId); + this.addUserIdsAndPartyIdsToJson(userIds, partyIds, jsonObject); + + return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString())); + } + + private void addUserIdsAndPartyIdsToJson(List userIds, List partyIds, JsonObject jsonObject) { if (userIds != null) { JsonArray jsonArray = new JsonArray(); for (String userId : userIds) { @@ -89,6 +106,7 @@ public WxCpTagAddOrRemoveUsersResult addUsers2Tag(String tagId, List use } jsonObject.add("userlist", jsonArray); } + if (partyIds != null) { JsonArray jsonArray = new JsonArray(); for (String userId : partyIds) { @@ -96,21 +114,19 @@ public WxCpTagAddOrRemoveUsersResult addUsers2Tag(String tagId, List use } jsonObject.add("partylist", jsonArray); } - - return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString())); } @Override - public WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List userIds) throws WxErrorException { - String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers"; - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("tagid", tagId); - JsonArray jsonArray = new JsonArray(); - for (String userId : userIds) { - jsonArray.add(new JsonPrimitive(userId)); + public WxCpTagGetResult get(String tagId) throws WxErrorException { + String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/get"; + if (tagId != null) { + url += "?tagId=" + tagId; + } else { + throw new IllegalArgumentException("缺少tagId参数"); } - jsonObject.add("userlist", jsonArray); - return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString())); + String responseContent = this.mainService.get(url, null); + + return WxCpTagGetResult.fromJson(responseContent); } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java index f0249e8e11..e4baff52bc 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java @@ -3,12 +3,12 @@ import com.google.common.collect.Maps; import com.google.gson.*; import com.google.gson.reflect.TypeToken; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.api.WxCpUserService; +import me.chanjar.weixin.cp.bean.WxCpInviteResult; import me.chanjar.weixin.cp.bean.WxCpUser; import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; -import org.apache.commons.lang3.StringUtils; import java.util.List; import java.util.Map; @@ -116,17 +116,34 @@ public List listSimpleByDepartment(Integer departId, Boolean fetchChil } @Override - @Deprecated - public int invite(String userId, String inviteTips) throws WxErrorException { - String url = "https://qyapi.weixin.qq.com/cgi-bin/invite/send"; + public WxCpInviteResult invite(List userIds, List partyIds, List tagIds) throws WxErrorException { + String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/invite"; JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("userid", userId); - if (StringUtils.isNotEmpty(inviteTips)) { - jsonObject.addProperty("invite_tips", inviteTips); + if (userIds != null) { + JsonArray jsonArray = new JsonArray(); + for (String userId : userIds) { + jsonArray.add(new JsonPrimitive(userId)); + } + jsonObject.add("user", jsonArray); } - String responseContent = this.mainService.post(url, jsonObject.toString()); - JsonElement tmpJsonElement = new JsonParser().parse(responseContent); - return tmpJsonElement.getAsJsonObject().get("type").getAsInt(); + + if (partyIds != null) { + JsonArray jsonArray = new JsonArray(); + for (String userId : partyIds) { + jsonArray.add(new JsonPrimitive(userId)); + } + jsonObject.add("party", jsonArray); + } + + if (tagIds != null) { + JsonArray jsonArray = new JsonArray(); + for (String tagId : tagIds) { + jsonArray.add(new JsonPrimitive(tagId)); + } + jsonObject.add("tag", jsonArray); + } + + return WxCpInviteResult.fromJson(this.mainService.post(url, jsonObject.toString())); } @Override diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/Gender.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/Gender.java new file mode 100644 index 0000000000..2b6e26efde --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/Gender.java @@ -0,0 +1,47 @@ +package me.chanjar.weixin.cp.bean; + +/** + * + * 性别枚举 + * Created by BinaryWang on 2018/4/22. + *+ * + * @author Binary Wang + */ +public enum Gender { + /** + * 男 + */ + MALE("男", "1"), + /** + * 女 + */ + FEMALE("女", "2"); + + private String genderName; + private String code; + + Gender(String genderName, String code) { + this.genderName = genderName; + this.code = code; + } + + public String getGenderName() { + return this.genderName; + } + + public String getCode() { + return this.code; + } + + public static Gender fromCode(String code) { + if ("1".equals(code)) { + return Gender.MALE; + } + if ("2".equals(code)) { + return Gender.FEMALE; + } + + return null; + } +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpAgent.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpAgent.java new file mode 100644 index 0000000000..eb7069bdc8 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpAgent.java @@ -0,0 +1,96 @@ +package me.chanjar.weixin.cp.bean; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; +import java.util.List; + +/** + *+ * 企业号应用信息. + * Created by huansinho on 2018/4/13. + *+ * + * @author huansinho + */ +@Data +public class WxCpAgent implements Serializable { + + @SerializedName("errcode") + private Integer errcode; + + @SerializedName("errmsg") + private String errmsg; + + @SerializedName("agentid") + private Integer agentid; + + @SerializedName("name") + private String name; + + @SerializedName("square_logo_url") + private String squareLogoUrl; + + @SerializedName("description") + private String description; + + @SerializedName("allow_userinfos") + private Users allowUserinfos; + + @SerializedName("allow_partys") + private Partys allowPartys; + + @SerializedName("allow_tags") + private Tags allowTags; + + @SerializedName("close") + private Integer close; + + @SerializedName("redirect_domain") + private String redirectDomain; + + @SerializedName("report_location_flag") + private Integer reportLocationFlag; + + @SerializedName("isreportenter") + private Integer isreportenter; + + @SerializedName("home_url") + private String homeUrl; + + public static WxCpAgent fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpAgent.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + + @Data + public static class Users implements Serializable { + @SerializedName("user") + private Listuser; + } + + + @Data + public class User implements Serializable { + @SerializedName("userid") + private String userid; + } + + @Data + public class Partys { + @SerializedName("partyid") + private List partyids = null; + } + + @Data + public class Tags { + @SerializedName("tagid") + private List tagids = null; + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpInviteResult.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpInviteResult.java new file mode 100644 index 0000000000..35f61ba0f2 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpInviteResult.java @@ -0,0 +1,60 @@ +package me.chanjar.weixin.cp.bean; + +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 2018-5-13. + * + * @author Binary Wang + */ +@Data +public class WxCpInviteResult implements Serializable { + private static final long serialVersionUID = 1420065684270213578L; + + @Override + public String toString() { + return ToStringUtils.toSimpleString(this); + } + + public static WxCpInviteResult fromJson(String json) { + return WxCpGsonBuilder.INSTANCE.create().fromJson(json, WxCpInviteResult.class); + } + + @SerializedName("errcode") + private Integer errCode; + + @SerializedName("errmsg") + private String errMsg; + + @SerializedName("invaliduser") + private String invalidUsers; + + @SerializedName("invalidparty") + private String[] invalidParties; + + @SerializedName("invalidtag") + private String[] invalidTags; + + public List getInvalidUserList() { + return this.content2List(this.invalidUsers); + } + + private List content2List(String content) { + if (StringUtils.isBlank(content)) { + return Collections.emptyList(); + } + + return Splitter.on("|").splitToList(content); + } + +} 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 403e9dc365..58fc983063 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 @@ -34,6 +34,7 @@ public class WxCpMessage implements Serializable { private String hqMusicUrl; private String safe; private String url; + private String btnTxt; private List articles = new ArrayList<>(); private List mpnewsArticles = new ArrayList<>(); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTagGetResult.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTagGetResult.java new file mode 100644 index 0000000000..28cc4807a1 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTagGetResult.java @@ -0,0 +1,57 @@ +package me.chanjar.weixin.cp.bean; + +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; +import java.util.List; + +/** + * + * 管理企业号应用-测试 + * Created by huansinho on 2018/4/16. + *+ * + * @author huansinho + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class WxCpTagGetResult implements Serializable { + + @SerializedName("errcode") + private Integer errcode; + + @SerializedName("errmsg") + private String errmsg; + + /** + * 用户列表 + */ + @SerializedName("userlist") + private Listuserlist; + + /** + * 部门列表 + */ + @SerializedName("partylist") + private List partylist; + + /** + * 标签名称 + */ + @SerializedName("tagname") + private String tagname; + + public static WxCpTagGetResult fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpTagGetResult.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + +} 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 0acbb49b52..fd06ea23c5 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 @@ -15,44 +15,6 @@ */ @Data public class WxCpUser implements Serializable { - public enum Gender { - /** - * 男 - */ - MALE("男", "1"), - /** - * 女 - */ - FEMALE("女", "2"); - - private String genderName; - private String code; - - Gender(String genderName, String code) { - this.genderName = genderName; - this.code = code; - } - - public String getGenderName() { - return this.genderName; - } - - public String getCode() { - return this.code; - } - - public static Gender fromCode(String code) { - if ("1".equals(code)) { - return Gender.MALE; - } - if ("2".equals(code)) { - return Gender.FEMALE; - } - - return null; - } - } - private static final long serialVersionUID = -5696099236344075582L; private String userId; private String name; @@ -69,6 +31,8 @@ public static Gender fromCode(String code) { private Integer hideMobile; private String englishName; private String telephone; + private String qrCode; + private Boolean toInvite; public void addExtAttr(String name, String value) { this.extAttrs.add(new Attr(name, value)); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUserDetail.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUserDetail.java new file mode 100644 index 0000000000..d8df026d47 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUserDetail.java @@ -0,0 +1,24 @@ +package me.chanjar.weixin.cp.bean; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +/** + * + * 使用user_ticket获取成员详情接口返回类. + * Created by BinaryWang on 2018/4/22. + *+ * + * @author Binary Wang + */ +@Data +public class WxCpUserDetail { + @SerializedName("userid") + private String userId; + private String name; + private String mobile; + private String gender; + private String email; + @SerializedName("qrCode") + private String qrCode; +} 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 992397981f..c8149cabfa 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 @@ -3,6 +3,7 @@ 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; @@ -11,6 +12,7 @@ @XStreamAlias("xml") @Data +@EqualsAndHashCode(callSuper = true) public class WxCpXmlOutNewsMessage extends WxCpXmlOutMessage { private static final long serialVersionUID = -5796178637883178826L; 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 f453bddb9b..6cae763d19 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 @@ -16,6 +16,7 @@ public class TextCardBuilder extends BaseBuilder{ private String title; private String description; private String url; + private String btnTxt; public TextCardBuilder() { this.msgType = WxConsts.KefuMsgType.TEXTCARD; @@ -36,12 +37,18 @@ public TextCardBuilder url(String url) { return this; } + public TextCardBuilder btnTxt(String btnTxt) { + this.btnTxt = btnTxt; + return this; + } + @Override public WxCpMessage build() { WxCpMessage m = super.build(); m.setTitle(this.title); m.setDescription(this.description); m.setUrl(this.url); + m.setBtnTxt(this.btnTxt); return m; } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageHandler.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageHandler.java index 615fa8f220..22074d6e70 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageHandler.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageHandler.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.cp.message; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.bean.WxCpXmlMessage; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageInterceptor.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageInterceptor.java index 21abb5cdb4..ab4c658e4f 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageInterceptor.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageInterceptor.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.cp.message; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.bean.WxCpXmlMessage; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouterRule.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouterRule.java index b5912404ce..8f3766a160 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouterRule.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouterRule.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.cp.message; import me.chanjar.weixin.common.api.WxErrorExceptionHandler; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.bean.WxCpXmlMessage; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpGsonBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpGsonBuilder.java index 5efee45ce5..c9c5596466 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpGsonBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpGsonBuilder.java @@ -3,7 +3,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import me.chanjar.weixin.common.bean.menu.WxMenu; -import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.util.json.WxErrorAdapter; import me.chanjar.weixin.cp.bean.WxCpDepart; import me.chanjar.weixin.cp.bean.WxCpMessage; 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 5e19b50121..7bed435d30 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 @@ -48,6 +48,7 @@ public JsonElement serialize(WxCpMessage message, Type typeOfSrc, JsonSerializat text.addProperty("title", message.getTitle()); text.addProperty("description", message.getDescription()); text.addProperty("url", message.getUrl()); + text.addProperty("btntxt", message.getBtnTxt()); messageJson.add("textcard", text); } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java index 6531d07ba9..1eec481512 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java @@ -10,6 +10,7 @@ import com.google.gson.*; import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.cp.bean.Gender; import me.chanjar.weixin.cp.bean.WxCpUser; import java.lang.reflect.Type; @@ -39,7 +40,7 @@ public WxCpUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationC user.setName(GsonHelper.getString(o, "name")); user.setPosition(GsonHelper.getString(o, "position")); user.setMobile(GsonHelper.getString(o, "mobile")); - user.setGender(WxCpUser.Gender.fromCode(GsonHelper.getString(o, "gender"))); + user.setGender(Gender.fromCode(GsonHelper.getString(o, "gender"))); user.setEmail(GsonHelper.getString(o, "email")); user.setAvatar(GsonHelper.getString(o, "avatar")); user.setStatus(GsonHelper.getInteger(o, "status")); @@ -48,6 +49,8 @@ public WxCpUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationC user.setHideMobile(GsonHelper.getInteger(o, "hide_mobile")); user.setEnglishName(GsonHelper.getString(o, "english_name")); user.setTelephone(GsonHelper.getString(o, "telephone")); + user.setQrCode(GsonHelper.getString(o, "qr_code")); + user.setToInvite(GsonHelper.getBoolean(o, "to_invite")); if (GsonHelper.isNotNull(o.get("extattr"))) { JsonArray attrJsonElements = o.get("extattr").getAsJsonObject().get("attrs").getAsJsonArray(); @@ -111,6 +114,13 @@ public JsonElement serialize(WxCpUser user, Type typeOfSrc, JsonSerializationCon if (user.getTelephone() != null) { o.addProperty("telephone", user.getTelephone()); } + if (user.getQrCode() != null) { + o.addProperty("qr_code", user.getQrCode()); + } + if (user.getToInvite() != null) { + o.addProperty("to_invite", user.getToInvite()); + } + if (user.getExtAttrs().size() > 0) { JsonArray attrsJsonArray = new JsonArray(); for (WxCpUser.Attr attr : user.getExtAttrs()) { 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 fdc78ace8a..5ef1503df1 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 @@ -63,7 +63,6 @@ private static Map configXStreamInstance() { private static XStream configWxCpXmlMessage() { XStream xstream = XStreamInitializer.getInstance(); - xstream.setClassLoader(Thread.currentThread().getContextClassLoader()); xstream.processAnnotations(WxCpXmlMessage.class); xstream.processAnnotations(WxCpXmlMessage.ScanCodeInfo.class); @@ -75,7 +74,6 @@ private static XStream configWxCpXmlMessage() { private static XStream configWxCpXmlOutImageMessage() { XStream xstream = XStreamInitializer.getInstance(); - xstream.setClassLoader(Thread.currentThread().getContextClassLoader()); xstream.processAnnotations(WxCpXmlOutMessage.class); xstream.processAnnotations(WxCpXmlOutImageMessage.class); @@ -84,7 +82,6 @@ private static XStream configWxCpXmlOutImageMessage() { private static XStream configWxCpXmlOutNewsMessage() { XStream xstream = XStreamInitializer.getInstance(); - xstream.setClassLoader(Thread.currentThread().getContextClassLoader()); xstream.processAnnotations(WxCpXmlOutMessage.class); xstream.processAnnotations(WxCpXmlOutNewsMessage.class); @@ -94,7 +91,6 @@ private static XStream configWxCpXmlOutNewsMessage() { private static XStream configWxCpXmlOutTextMessage() { XStream xstream = XStreamInitializer.getInstance(); - xstream.setClassLoader(Thread.currentThread().getContextClassLoader()); xstream.processAnnotations(WxCpXmlOutMessage.class); xstream.processAnnotations(WxCpXmlOutTextMessage.class); @@ -103,7 +99,6 @@ private static XStream configWxCpXmlOutTextMessage() { private static XStream configWxCpXmlOutVideoMessage() { XStream xstream = XStreamInitializer.getInstance(); - xstream.setClassLoader(Thread.currentThread().getContextClassLoader()); xstream.processAnnotations(WxCpXmlOutMessage.class); xstream.processAnnotations(WxCpXmlOutVideoMessage.class); @@ -113,7 +108,6 @@ private static XStream configWxCpXmlOutVideoMessage() { private static XStream configWxCpXmlOutVoiceMessage() { XStream xstream = XStreamInitializer.getInstance(); - xstream.setClassLoader(Thread.currentThread().getContextClassLoader()); xstream.processAnnotations(WxCpXmlOutMessage.class); xstream.processAnnotations(WxCpXmlOutVoiceMessage.class); diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java index 179086f739..c87b6455ac 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java @@ -1,20 +1,24 @@ package me.chanjar.weixin.cp.api; +import java.io.IOException; +import java.io.InputStream; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.google.inject.Binder; import com.google.inject.Module; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.XStreamAlias; import me.chanjar.weixin.common.util.xml.XStreamInitializer; import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl; -import me.chanjar.weixin.cp.config.WxCpConfigStorage; import me.chanjar.weixin.cp.config.WxCpInMemoryConfigStorage; -import java.io.IOException; -import java.io.InputStream; - public class ApiTestModule implements Module { + private final Logger log = LoggerFactory.getLogger(this.getClass()); + private static final String TEST_CONFIG_XML = "test-config.xml"; - public static T fromXml(Class clazz, InputStream is) { + private static T fromXml(Class clazz, InputStream is) { XStream xstream = XStreamInitializer.getInstance(); xstream.alias("xml", clazz); xstream.processAnnotations(clazz); @@ -23,17 +27,19 @@ public static T fromXml(Class clazz, InputStream is) { @Override public void configure(Binder binder) { - try (InputStream is1 = ClassLoader - .getSystemResourceAsStream("test-config.xml")) { - WxXmlCpInMemoryConfigStorage config = fromXml( - WxXmlCpInMemoryConfigStorage.class, is1); + try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(TEST_CONFIG_XML)) { + if (inputStream == null) { + throw new RuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成"); + } + + WxXmlCpInMemoryConfigStorage config = fromXml(WxXmlCpInMemoryConfigStorage.class, inputStream); WxCpService wxService = new WxCpServiceImpl(); wxService.setWxCpConfigStorage(config); binder.bind(WxCpService.class).toInstance(wxService); binder.bind(WxXmlCpInMemoryConfigStorage.class).toInstance(config); } catch (IOException e) { - e.printStackTrace(); + this.log.error(e.getMessage(), e); } } diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java index b535634a45..58ba1a9791 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.cp.api; import com.google.inject.Inject; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl; import me.chanjar.weixin.cp.config.WxCpConfigStorage; import org.apache.commons.lang3.StringUtils; 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 6d4e8ce893..2e89e5e79d 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 @@ -1,7 +1,7 @@ package me.chanjar.weixin.cp.api; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl; import org.testng.annotations.DataProvider; 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 4194efc17a..640bbad17d 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 @@ -2,7 +2,7 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.bean.WxCpMessage; import me.chanjar.weixin.cp.bean.WxCpMessageSendResult; import org.testng.annotations.*; diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImplTest.java new file mode 100644 index 0000000000..f4b2aac052 --- /dev/null +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImplTest.java @@ -0,0 +1,52 @@ +package me.chanjar.weixin.cp.api.impl; + +import com.google.inject.Inject; +import me.chanjar.weixin.common.api.WxConsts; +import me.chanjar.weixin.common.bean.menu.WxMenu; +import me.chanjar.weixin.common.bean.menu.WxMenuButton; +import me.chanjar.weixin.cp.api.ApiTestModule; +import me.chanjar.weixin.cp.api.WxCpAgentService; +import me.chanjar.weixin.cp.api.WxCpService; +import me.chanjar.weixin.cp.bean.WxCpAgent; +import me.chanjar.weixin.cp.config.WxCpInMemoryConfigStorage; +import org.mockito.Mock; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.mockito.Mockito.*; + + +/** + * + * 管理企业号应用-测试 + * Created by huansinho on 2018/4/13. + *+ * + * @author huansinho + */ +public class WxCpAgentServiceImplTest { + + protected WxCpService wxService = mock(WxCpService.class); + + @Test + public void testGet() throws Exception { + String returnJson = "{\"errcode\": 0,\"errmsg\": \"ok\",\"agentid\": 9,\"name\": \"测试应用\",\"square_logo_url\": \"http://wx.qlogo.cn/mmhead/alksjf;lasdjf;lasjfuodiuj3rj2o34j/0\",\"description\": \"这是一个企业号应用\",\"allow_userinfos\": {\"user\": [{\"userid\": \"0009854\"}, {\"userid\": \"1723\"}, {\"userid\": \"5625\"}]},\"allow_partys\": {\"partyid\": [42762742]},\"allow_tags\": {\"tagid\": [23, 22, 35, 19, 32, 125, 133, 46, 150, 38, 183, 9, 7]},\"close\": 0,\"redirect_domain\": \"weixin.com.cn\",\"report_location_flag\": 0,\"isreportenter\": 0,\"home_url\": \"\"}"; + when(wxService.get("https://qyapi.weixin.qq.com/cgi-bin/agent/get?agentid=9", null)).thenReturn(returnJson); + when(wxService.getAgentService()).thenReturn(new WxCpAgentServiceImpl(wxService)); + + WxCpAgentService wxAgentService = this.wxService.getAgentService(); + WxCpAgent wxCpAgent = wxAgentService.get(9); + + Assert.assertEquals(9, wxCpAgent.getAgentid().intValue()); + + Assert.assertEquals(new Integer[]{42762742}, wxCpAgent.getAllowPartys().getPartyids().toArray()); + + Assert.assertEquals(new Integer[]{23, 22, 35, 19, 32, 125, 133, 46, 150, 38, 183, 9, 7}, wxCpAgent.getAllowTags().getTagids().toArray()); + + } + +} 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 522d169cfa..9a19564cd2 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 @@ -56,7 +56,7 @@ public void testList(Integer id) throws Exception { } } - @Test(dependsOnMethods = {"testListAll", "testCreate"}) + @Test(dependsOnMethods = {"testList", "testCreate"}) public void testUpdate() throws Exception { System.out.println("=================更新部门"); this.depart.setName("子部门改名" + System.currentTimeMillis()); 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 084f59f289..ad925690bc 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 @@ -3,7 +3,7 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.ApiTestModule; import me.chanjar.weixin.cp.api.TestConstants; import me.chanjar.weixin.cp.api.WxCpService; diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImplTest.java new file mode 100644 index 0000000000..21801e4b42 --- /dev/null +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImplTest.java @@ -0,0 +1,33 @@ +package me.chanjar.weixin.cp.api.impl; + +import com.google.inject.Inject; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.cp.api.ApiTestModule; +import me.chanjar.weixin.cp.api.WxCpService; +import me.chanjar.weixin.cp.bean.WxCpUserDetail; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +/** + *+ * Created by BinaryWang on 2018/4/22. + *+ * + * @author Binary Wang + */ +@Guice(modules = ApiTestModule.class) +public class WxCpOAuth2ServiceImplTest { + @Inject + private WxCpService wxService; + + @Test + public void testGetUserDetail() throws WxErrorException { + WxCpUserDetail userDetail = this.wxService.getOauth2Service().getUserDetail("b"); + System.out.println(userDetail); + } + + @Test + public void testGetUserInfo() throws WxErrorException { + this.wxService.getOauth2Service().getUserInfo("abc"); + } +} diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImplTest.java index 94ac3b09db..5a6e8ccabd 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImplTest.java @@ -2,16 +2,23 @@ import com.google.common.base.Splitter; import com.google.inject.Inject; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.ApiTestModule; import me.chanjar.weixin.cp.api.WxCpService; +import me.chanjar.weixin.cp.api.WxCpTagService; import me.chanjar.weixin.cp.bean.WxCpTag; import me.chanjar.weixin.cp.bean.WxCpTagAddOrRemoveUsersResult; +import me.chanjar.weixin.cp.bean.WxCpTagGetResult; import me.chanjar.weixin.cp.bean.WxCpUser; -import org.testng.annotations.*; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; import java.util.List; -import static org.testng.Assert.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; /** *@@ -63,7 +70,7 @@ public void testListUsersByTagId() throws Exception { @Test(dependsOnMethods = {"testListUsersByTagId", "testAddUsers2Tag", "testListAll", "testUpdate", "testCreate"}) public void testRemoveUsersFromTag() throws Exception { ListuserIds = Splitter.on("|").splitToList(this.configStorage.getUserId()); - WxCpTagAddOrRemoveUsersResult result = this.wxService.getTagService().removeUsersFromTag(this.tagId, userIds); + WxCpTagAddOrRemoveUsersResult result = this.wxService.getTagService().removeUsersFromTag(this.tagId, userIds, null); assertEquals(result.getErrCode(), Integer.valueOf(0)); } @@ -72,4 +79,24 @@ public void testDelete() throws Exception { this.wxService.getTagService().delete(this.tagId); } + @Test + public void testGet() throws WxErrorException { + String apiResultJson = "{\"errcode\": 0,\"errmsg\": \"ok\",\"userlist\": [{\"userid\": \"0124035\",\"name\": \"王五\"},{\"userid\": \"0114035\",\"name\": \"梦雪\"}],\"partylist\": [9576,9567,9566],\"tagname\": \"测试标签-001\"}"; + WxCpService wxService = mock(WxCpService.class); + when(wxService.get("https://qyapi.weixin.qq.com/cgi-bin/tag/get?tagId=150", null)).thenReturn(apiResultJson); + when(wxService.getTagService()).thenReturn(new WxCpTagServiceImpl(wxService)); + + WxCpTagService wxCpTagService = wxService.getTagService(); + + WxCpTagGetResult wxCpTagGetResult = wxCpTagService.get(String.valueOf(150)); + + assertEquals(0, wxCpTagGetResult.getErrcode().intValue()); + + assertEquals(2, wxCpTagGetResult.getUserlist().size()); + assertEquals(3, wxCpTagGetResult.getPartylist().size()); + assertEquals("测试标签-001", wxCpTagGetResult.getTagname()); + + + } + } diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImplTest.java index bbb5dcab2d..9babeb3f0b 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImplTest.java @@ -1,8 +1,11 @@ package me.chanjar.weixin.cp.api.impl; +import com.google.common.collect.Lists; import com.google.inject.Inject; import me.chanjar.weixin.cp.api.ApiTestModule; import me.chanjar.weixin.cp.api.WxCpService; +import me.chanjar.weixin.cp.bean.Gender; +import me.chanjar.weixin.cp.bean.WxCpInviteResult; import me.chanjar.weixin.cp.bean.WxCpUser; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -40,7 +43,7 @@ public void testCreate() throws Exception { user.setName("Some Woman"); user.setDepartIds(new Integer[]{2}); user.setEmail("none@none.com"); - user.setGender(WxCpUser.Gender.FEMALE); + user.setGender(Gender.FEMALE); user.setMobile("13560084979"); user.setPosition("woman"); user.setTelephone("3300393"); @@ -87,9 +90,9 @@ public void testListSimpleByDepartment() throws Exception { } @Test - @Deprecated public void testInvite() throws Exception { - int result = this.wxCpService.getUserService().invite(userId, ""); + WxCpInviteResult result = this.wxCpService.getUserService().invite( + Lists.newArrayList(userId), null,null); System.out.println(result); } diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpAgentTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpAgentTest.java new file mode 100644 index 0000000000..6a2b87c588 --- /dev/null +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpAgentTest.java @@ -0,0 +1,25 @@ +package me.chanjar.weixin.cp.bean; + +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * Created by huansinho on 2018/4/13. + */ +@Test +public class WxCpAgentTest { + + public void testDeserialize() { + String json = "{\"errcode\": 0,\"errmsg\": \"ok\",\"agentid\": 9,\"name\": \"测试应用\",\"square_logo_url\": \"http://wx.qlogo.cn/mmhead/alksjf;lasdjf;lasjfuodiuj3rj2o34j/0\",\"description\": \"这是一个企业号应用\",\"allow_userinfos\": {\"user\": [{\"userid\": \"0009854\"}, {\"userid\": \"1723\"}, {\"userid\": \"5625\"}]},\"allow_partys\": {\"partyid\": [42762742]},\"allow_tags\": {\"tagid\": [23, 22, 35, 19, 32, 125, 133, 46, 150, 38, 183, 9, 7]},\"close\": 0,\"redirect_domain\": \"weixin.com.cn\",\"report_location_flag\": 0,\"isreportenter\": 0,\"home_url\": \"\"}"; + + WxCpAgent wxCpAgent = WxCpAgent.fromJson(json); + + Assert.assertEquals(9, wxCpAgent.getAgentid().intValue()); + + Assert.assertEquals(new Integer[]{42762742}, wxCpAgent.getAllowPartys().getPartyids().toArray()); + + Assert.assertEquals(new Integer[]{23, 22, 35, 19, 32, 125, 133, 46, 150, 38, 183, 9, 7}, wxCpAgent.getAllowTags().getTagids().toArray()); + + } + +} diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpMessageTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpMessageTest.java index e02cc6672d..0af121a835 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpMessageTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpMessageTest.java @@ -2,39 +2,47 @@ import me.chanjar.weixin.cp.bean.article.MpnewsArticle; import me.chanjar.weixin.cp.bean.article.NewArticle; -import org.testng.annotations.*; +import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.testng.Assert.assertEquals; @Test public class WxCpMessageTest { public void testTextBuild() { WxCpMessage reply = WxCpMessage.TEXT().toUser("OPENID").content("sfsfdsdf").build(); - assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"},\"safe\":\"0\"}"); + assertThat(reply.toJson()) + .isEqualTo("{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"},\"safe\":\"0\"}"); } public void testTextCardBuild() { WxCpMessage reply = WxCpMessage.TEXTCARD().toUser("OPENID") .title("领奖通知") - .description( " 2016年9月26日恭喜你抽中iPhone 7一台,领奖码:xxxx请于2016年10月10日前联系行政同事领取") - .url("http://www.qq.com").build(); - assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"textcard\",\"textcard\":{\"title\":\"领奖通知\",\"description\":\"2016年9月26日恭喜你抽中iPhone 7一台,领奖码:xxxx请于2016年10月10日前联系行政同事领取\",\"url\":\"http://www.qq.com\"},\"safe\":\"0\"}"); + .description("2016年9月26日恭喜你抽中iPhone 7一台,领奖码:xxxx请于2016年10月10日前联系行政同事领取") + .url("http://www.qq.com") + .btnTxt("更多") + .build(); + assertThat(reply.toJson()) + .isEqualTo("{\"touser\":\"OPENID\",\"msgtype\":\"textcard\",\"textcard\":{\"title\":\"领奖通知\",\"description\":\"2016年9月26日恭喜你抽中iPhone 7一台,领奖码:xxxx请于2016年10月10日前联系行政同事领取\",\"url\":\"http://www.qq.com\",\"btntxt\":\"更多\"},\"safe\":\"0\"}"); } public void testImageBuild() { WxCpMessage reply = WxCpMessage.IMAGE().toUser("OPENID").mediaId("MEDIA_ID").build(); - assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"},\"safe\":\"0\"}"); + assertThat(reply.toJson()) + .isEqualTo("{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"},\"safe\":\"0\"}"); } public void testVoiceBuild() { WxCpMessage reply = WxCpMessage.VOICE().toUser("OPENID").mediaId("MEDIA_ID").build(); - assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"},\"safe\":\"0\"}"); + assertThat(reply.toJson()) + .isEqualTo("{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"},\"safe\":\"0\"}"); } public void testVideoBuild() { WxCpMessage reply = WxCpMessage.VIDEO().toUser("OPENID").title("TITLE").mediaId("MEDIA_ID").thumbMediaId("MEDIA_ID").description("DESCRIPTION").build(); - assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"safe\":\"0\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}"); + assertThat(reply.toJson()) + .isEqualTo("{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"safe\":\"0\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}"); } public void testNewsBuild() { @@ -52,7 +60,8 @@ public void testNewsBuild() { WxCpMessage reply = WxCpMessage.NEWS().toUser("OPENID").addArticle(article1).addArticle(article2).build(); - assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"safe\":\"0\",\"news\":{\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}}"); + assertThat(reply.toJson()) + .isEqualTo( "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"safe\":\"0\",\"news\":{\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}}"); } public void testMpnewsBuild_with_articles() { @@ -78,14 +87,15 @@ public void testMpnewsBuild_with_articles() { WxCpMessage reply = WxCpMessage.MPNEWS().toUser("OPENID").addArticle(article1, article2).build(); - assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"mpnews\",\"safe\":\"0\",\"mpnews\":{\"articles\":[{\"title\":\"Happy Day\",\"thumb_media_id\":\"thumb\",\"author\":\"aaaaaa\",\"content_source_url\":\"nice url\",\"content\":\"hahaha\",\"digest\":\"digest\",\"show_cover_pic\":\"heihei\"},{\"title\":\"Happy Day\",\"thumb_media_id\":\"thumb\",\"author\":\"aaaaaa\",\"content_source_url\":\"nice url\",\"content\":\"hahaha\",\"digest\":\"digest\",\"show_cover_pic\":\"heihei\"}]}}"); + assertThat(reply.toJson()) + .isEqualTo( "{\"touser\":\"OPENID\",\"msgtype\":\"mpnews\",\"safe\":\"0\",\"mpnews\":{\"articles\":[{\"title\":\"Happy Day\",\"thumb_media_id\":\"thumb\",\"author\":\"aaaaaa\",\"content_source_url\":\"nice url\",\"content\":\"hahaha\",\"digest\":\"digest\",\"show_cover_pic\":\"heihei\"},{\"title\":\"Happy Day\",\"thumb_media_id\":\"thumb\",\"author\":\"aaaaaa\",\"content_source_url\":\"nice url\",\"content\":\"hahaha\",\"digest\":\"digest\",\"show_cover_pic\":\"heihei\"}]}}"); } public void testMpnewsBuild_with_media_id() { WxCpMessage reply = WxCpMessage.MPNEWS().toUser("OPENID").mediaId("mmm").build(); - assertEquals(reply.toJson(), - "{\"touser\":\"OPENID\",\"msgtype\":\"mpnews\",\"safe\":\"0\",\"mpnews\":{\"media_id\":\"mmm\"}}"); + assertThat(reply.toJson()) + .isEqualTo("{\"touser\":\"OPENID\",\"msgtype\":\"mpnews\",\"safe\":\"0\",\"mpnews\":{\"media_id\":\"mmm\"}}"); } } diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpOAuth2Servlet.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpOAuth2Servlet.java index 37c2b7a12f..d652884b64 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpOAuth2Servlet.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpOAuth2Servlet.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.cp.demo; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.WxCpService; import javax.servlet.http.HttpServlet; diff --git a/weixin-java-miniapp/pom.xml b/weixin-java-miniapp/pom.xml index ff3f26fcc4..571a30a028 100644 --- a/weixin-java-miniapp/pom.xml +++ b/weixin-java-miniapp/pom.xml @@ -7,7 +7,7 @@com.github.binarywang weixin-java-parent -3.0.0 +3.1.0 weixin-java-miniapp Weixin Java Tools - MiniApp diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaAnalysisService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaAnalysisService.java new file mode 100644 index 0000000000..e8273bc402 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaAnalysisService.java @@ -0,0 +1,145 @@ +package cn.binarywang.wx.miniapp.api; + +import cn.binarywang.wx.miniapp.bean.analysis.WxMaRetainInfo; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaSummaryTrend; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaUserPortrait; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaVisitDistribution; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaVisitPage; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaVisitTrend; +import me.chanjar.weixin.common.error.WxErrorException; + +import java.util.Date; +import java.util.List; + +/** + * 小程序数据分析相关接口 + * 文档:https://mp.weixin.qq.com/debug/wxadoc/dev/api/analysis.html + * + * @author Charming + * @since 2018-04-28 + */ +public interface WxMaAnalysisService { + String GET_DAILY_SUMMARY_TREND_URL = "https://api.weixin.qq.com/datacube/getweanalysisappiddailysummarytrend"; + String GET_DAILY_VISIT_TREND_URL = "https://api.weixin.qq.com/datacube/getweanalysisappiddailyvisittrend"; + String GET_WEEKLY_VISIT_TREND_URL = "https://api.weixin.qq.com/datacube/getweanalysisappidweeklyvisittrend"; + String GET_MONTHLY_VISIT_TREND_URL = "https://api.weixin.qq.com/datacube/getweanalysisappidmonthlyvisittrend"; + String GET_VISIT_DISTRIBUTION_URL = "https://api.weixin.qq.com/datacube/getweanalysisappidvisitdistribution"; + String GET_DAILY_RETAIN_INFO_URL = "https://api.weixin.qq.com/datacube/getweanalysisappiddailyretaininfo"; + String GET_WEEKLY_RETAIN_INFO_URL = "https://api.weixin.qq.com/datacube/getweanalysisappidweeklyretaininfo"; + String GET_MONTHLY_RETAIN_INFO_URL = "https://api.weixin.qq.com/datacube/getweanalysisappidmonthlyretaininfo"; + String GET_VISIT_PAGE_URL = "https://api.weixin.qq.com/datacube/getweanalysisappidvisitpage"; + String GET_USER_PORTRAIT_URL = "https://api.weixin.qq.com/datacube/getweanalysisappiduserportrait"; + + /** + * 查询概况趋势 + * 温馨提示:小程序接口目前只能查询一天的数据,即 beginDate 和 endDate 一样 + * + * @param beginDate 开始日期 + * @param endDate 结束日期,限定查询1天数据,end_date允许设置的最大值为昨日 + * @return 概况趋势 + * @throws WxErrorException 获取失败时抛出,具体错误码请看文档 + */ + ListgetDailySummaryTrend(Date beginDate, Date endDate) throws WxErrorException; + + /** + * 获取日访问趋势 + * 温馨提示:小程序接口目前只能查询一天的数据,即 beginDate 和 endDate 一样 + * + * @param beginDate 开始日期 + * @param endDate 结束日期,限定查询1天数据,end_date允许设置的最大值为昨日 + * @return 日访问趋势 + * @throws WxErrorException 获取失败时抛出,具体错误码请看文档 + */ + List getDailyVisitTrend(Date beginDate, Date endDate) throws WxErrorException; + + /** + * 获取周访问趋势 + * 限定查询一个自然周的数据,时间必须按照自然周的方式输入: 如:20170306(周一), 20170312(周日) + * + * @param beginDate 开始日期,为周一日期 + * @param endDate 结束日期,为周日日期,限定查询一周数据 + * @return 周访问趋势(每项数据都是一个自然周汇总) + * @throws WxErrorException 获取失败时抛出,具体错误码请看文档 + */ + List getWeeklyVisitTrend(Date beginDate, Date endDate) throws WxErrorException; + + /** + * 获取月访问趋势 + * 限定查询一个自然月的数据,时间必须按照自然月的方式输入: 如:20170201(月初), 20170228(月末) + * + * @param beginDate 开始日期,为自然月第一天 + * @param endDate 结束日期,为自然月最后一天,限定查询一个月数据 + * @return 月访问趋势(每项数据都是一个自然月汇总) + * @throws WxErrorException 获取失败时抛出,具体错误码请看文档 + */ + List getMonthlyVisitTrend(Date beginDate, Date endDate) throws WxErrorException; + + /** + * 获取访问分布 + * (此接口目前只能查询一天的数据,即 beginDate 和 endDate 一样) + * + * @param beginDate 开始日期,为周一日期 + * @param endDate 结束日期,限定查询1天数据,end_date允许设置的最大值为昨日 + * @return 访问分布 + * @throws WxErrorException 获取失败时抛出,具体错误码请看文档 + */ + WxMaVisitDistribution getVisitDistribution(Date beginDate, Date endDate) throws WxErrorException; + + /** + * 日留存 + * (此接口目前只能查询一天的数据,即 beginDate 和 endDate 一样) + * + * @param beginDate 开始日期,为周一日期 + * @param endDate 结束日期,限定查询 1 天数据,endDate 允许设置的最大值为昨日 + * @return 日留存 + * @throws WxErrorException 获取失败时抛出,具体错误码请看文档 + */ + WxMaRetainInfo getDailyRetainInfo(Date beginDate, Date endDate) throws WxErrorException; + + /** + * 周留存 + * 限定查询一个自然周的数据,时间必须按照自然周的方式输入: 如:20170306(周一), 20170312(周日) + * + * @param beginDate 开始日期,为周一日期 + * @param endDate 结束日期,为周日日期,限定查询一周数据 + * @return 周留存 + * @throws WxErrorException 获取失败时抛出,具体错误码请看文档 + */ + WxMaRetainInfo getWeeklyRetainInfo(Date beginDate, Date endDate) throws WxErrorException; + + /** + * 月留存 + * 限定查询一个自然月的数据,时间必须按照自然月的方式输入: 如:20170201(月初), 20170228(月末) + * + * @param beginDate 开始日期,为自然月第一天 + * @param endDate 结束日期,为自然月最后一天,限定查询一个月数据 + * @return 月留存 + * @throws WxErrorException 获取失败时抛出,具体错误码请看文档 + */ + WxMaRetainInfo getMonthlyRetainInfo(Date beginDate, Date endDate) throws WxErrorException; + + /** + * 获取访问页面数据 + * 温馨提示:此接口目前只能查询一天的数据,即 beginDate 和 endDate 一样 + * + * @param beginDate 开始日期 + * @param endDate 结束日期,限定查询1天数据,end_date允许设置的最大值为昨日 + * @return 访问页面数据 + * @throws WxErrorException 获取失败时抛出,具体错误码请看文档 + */ + List getVisitPage(Date beginDate, Date endDate) throws WxErrorException; + + /** + * 获取小程序新增或活跃用户的画像分布数据 + * 时间范围支持昨天、最近7天、最近30天。 + * 其中,新增用户数为时间范围内首次访问小程序的去重用户数, + * 活跃用户数为时间范围内访问过小程序的去重用户数。 + * 画像属性包括用户年龄、性别、省份、城市、终端类型、机型。 + * + * @param beginDate 开始日期 + * @param endDate 结束日期,开始日期与结束日期相差的天数限定为0/6/29,分别表示查询最近1/7/30天数据,end_date允许设置的最大值为昨日 + * @return 小程序新增或活跃用户的画像分布数据 + * @throws WxErrorException 获取失败时抛出,具体错误码请看文档 + */ + WxMaUserPortrait getUserPortrait(Date beginDate, Date endDate) throws WxErrorException; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaCodeService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaCodeService.java new file mode 100644 index 0000000000..eb90c12555 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaCodeService.java @@ -0,0 +1,140 @@ +package cn.binarywang.wx.miniapp.api; + +import cn.binarywang.wx.miniapp.bean.code.WxMaCategory; +import cn.binarywang.wx.miniapp.bean.code.WxMaCodeAuditStatus; +import cn.binarywang.wx.miniapp.bean.code.WxMaCodeCommitRequest; +import cn.binarywang.wx.miniapp.bean.code.WxMaCodeSubmitAuditRequest; +import cn.binarywang.wx.miniapp.bean.code.WxMaCodeVersionDistribution; +import me.chanjar.weixin.common.error.WxErrorException; + +import java.util.List; + +/** + * 小程序代码管理相关 API(大部分只能是第三方平台调用) + * 文档:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1489140610_Uavc4&token=&lang=zh_CN + * + * @author Charming + * @since 2018-04-26 19:43 + */ +public interface WxMaCodeService { + /** + * 为授权的小程序帐号上传小程序代码 + */ + String COMMIT_URL = "https://api.weixin.qq.com/wxa/commit"; + String GET_QRCODE_URL = "https://api.weixin.qq.com/wxa/get_qrcode"; + String GET_CATEGORY_URL = "https://api.weixin.qq.com/wxa/get_category"; + String GET_PAGE_URL = "https://api.weixin.qq.com/wxa/get_page"; + String SUBMIT_AUDIT_URL = "https://api.weixin.qq.com/wxa/submit_audit"; + String GET_AUDIT_STATUS_URL = "https://api.weixin.qq.com/wxa/get_auditstatus"; + String GET_LATEST_AUDIT_STATUS_URL = "https://api.weixin.qq.com/wxa/get_latest_auditstatus"; + String RELEASE_URL = "https://api.weixin.qq.com/wxa/release"; + String CHANGE_VISIT_STATUS_URL = "https://api.weixin.qq.com/wxa/change_visitstatus"; + String REVERT_CODE_RELEASE_URL = "https://api.weixin.qq.com/wxa/revertcoderelease"; + String GET_SUPPORT_VERSION_URL = "https://api.weixin.qq.com/cgi-bin/wxopen/getweappsupportversion"; + String SET_SUPPORT_VERSION_URL = "https://api.weixin.qq.com/cgi-bin/wxopen/setweappsupportversion"; + String UNDO_CODE_AUDIT_URL = "https://api.weixin.qq.com/wxa/undocodeaudit"; + + /** + * 为授权的小程序帐号上传小程序代码(仅仅支持第三方开放平台) + * + * @param commitRequest 参数 + * @throws WxErrorException 上传失败时抛出,具体错误码请看类注释文档 + */ + void commit(WxMaCodeCommitRequest commitRequest) throws WxErrorException; + + /** + * 获取体验小程序的体验二维码 + * + * @return 二维码 bytes + * @throws WxErrorException 上传失败时抛出,具体错误码请看类注释文档 + */ + byte[] getQrCode() throws WxErrorException; + + /** + * 获取授权小程序帐号的可选类目 + * + * @return List + * @throws WxErrorException 获取失败时返回,具体错误码请看此接口的注释文档 + */ + List getCategory() throws WxErrorException; + + /** + * 获取小程序的第三方提交代码的页面配置(仅供第三方开发者代小程序调用) + * + * @return page_list 页面配置列表 + * @throws WxErrorException 获取失败时返回,具体错误码请看此接口的注释文档 + */ + List getPage() throws WxErrorException; + + /** + * 将第三方提交的代码包提交审核(仅供第三方开发者代小程序调用) + * + * @param auditRequest 提交审核参数 + * @return 审核编号 + * @throws WxErrorException 提交失败时返回,具体错误码请看此接口的注释文档 + */ + long submitAudit(WxMaCodeSubmitAuditRequest auditRequest) throws WxErrorException; + + /** + * 查询某个指定版本的审核状态(仅供第三方代小程序调用) + * + * @param auditId 提交审核时获得的审核id + * @return 审核状态 + * @throws WxErrorException 查询失败时返回,具体错误码请看此接口的注释文档 + */ + WxMaCodeAuditStatus getAuditStatus(long auditId) throws WxErrorException; + + /** + * 查询最新一次提交的审核状态(仅供第三方代小程序调用) + * + * @return 审核状态 + * @throws WxErrorException 查询失败时返回,具体错误码请看此接口的注释文档 + */ + WxMaCodeAuditStatus getLatestAuditStatus() throws WxErrorException; + + /** + * 发布已通过审核的小程序(仅供第三方代小程序调用) + * + * @throws WxErrorException 发布失败时抛出,具体错误码请看此接口的注释文档 + */ + void release() throws WxErrorException; + + /** + * 修改小程序线上代码的可见状态(仅供第三方代小程序调用) + * + * @param action 设置可访问状态,发布后默认可访问,close为不可见,open为可见 + * @throws WxErrorException 发布失败时抛出,具体错误码请看此接口的注释文档 + */ + void changeVisitStatus(String action) throws WxErrorException; + + /** + * 小程序版本回退(仅供第三方代小程序调用) + * + * @throws WxErrorException 失败时抛出,具体错误码请看此接口的注释文档 + */ + void revertCodeRelease() throws WxErrorException; + + /** + * 查询当前设置的最低基础库版本及各版本用户占比 (仅供第三方代小程序调用) + * + * @return 小程序版本分布信息 + * @throws WxErrorException 失败时抛出,具体错误码请看此接口的注释文档 + */ + WxMaCodeVersionDistribution getSupportVersion() throws WxErrorException; + + /** + * 设置最低基础库版本(仅供第三方代小程序调用) + * + * @param version 版本 + * @throws WxErrorException 失败时抛出,具体错误码请看此接口的注释文档 + */ + void setSupportVersion(String version) throws WxErrorException; + + /** + * 小程序审核撤回 + * 单个帐号每天审核撤回次数最多不超过1次,一个月不超过10次 + * + * @throws WxErrorException 失败时抛出,具体错误码请看此接口的注释文档 + */ + void undoCodeAudit() throws WxErrorException; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaMediaService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaMediaService.java index 09c8aa5b9d..d2c57ca5e4 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaMediaService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaMediaService.java @@ -1,7 +1,7 @@ package cn.binarywang.wx.miniapp.api; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import java.io.File; import java.io.InputStream; diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaMsgService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaMsgService.java index 65522f4b75..3adf883c34 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaMsgService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaMsgService.java @@ -2,7 +2,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaKefuMessage; import cn.binarywang.wx.miniapp.bean.WxMaTemplateMessage; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; /** * 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 6fbeb96d82..2903737486 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,7 +1,7 @@ package cn.binarywang.wx.miniapp.api; import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import java.io.File; @@ -9,7 +9,7 @@ *+ * * @param scene 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式) * @param page 必须是已经发布的小程序页面,例如 "pages/index/index" ,如果不填写这个字段,默认跳主页面 * @param width 默认false 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 * @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 * @param lineColor auth_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} + * @param isHyaline 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码 */ - File createWxCodeLimit(String scene, String page, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException; + File createWxaCodeUnlimit(String scene, String page, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException; - File createWxCodeLimit(String scene, String page) throws WxErrorException; + File createWxaCodeUnlimit(String scene, String page) throws WxErrorException; } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java index c437966ef8..e89929ca4a 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java @@ -2,7 +2,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import cn.binarywang.wx.miniapp.config.WxMaConfig; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; @@ -135,6 +135,27 @@ public interface WxMaService { */ WxMaTemplateService getTemplateService(); + /** + * 数据分析相关查询服务 + * + * @return WxMaAnalysisService + */ + WxMaAnalysisService getAnalysisService(); + + /** + * 返回代码操作相关的 API + * + * @return WxMaCodeService + */ + WxMaCodeService getCodeService(); + + /** + * 小程序修改服务器地址、成员管理 API + * + * @return WxMaSettingService + */ + WxMaSettingService getSettingService(); + /** * 初始化http请求对象. */ diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSettingService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSettingService.java new file mode 100644 index 0000000000..8cc7934988 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSettingService.java @@ -0,0 +1,65 @@ +package cn.binarywang.wx.miniapp.api; + +import cn.binarywang.wx.miniapp.bean.WxMaDomainAction; +import me.chanjar.weixin.common.error.WxErrorException; + +/** + * 小程序修改服务器地址、成员管理 API(大部分只能是第三方平台调用) + * + * @author Charming + * @since 2018-04-27 15:46 + */ +public interface WxMaSettingService { + /** + * 修改服务器地址:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1489138143_WPbOO&token=&lang=zh_CN + * access_token 为 authorizer_access_token + */ + String MODIFY_DOMAIN_URL = "https://api.weixin.qq.com/wxa/modify_domain"; + String SET_WEB_VIEW_DOMAIN_URL = "https://api.weixin.qq.com/wxa/setwebviewdomain"; + /** + * 小程序成员管理:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1489140588_nVUgx&token=&lang=zh_CN + * access_token 为 authorizer_access_token + */ + String BIND_TESTER_URL = "https://api.weixin.qq.com/wxa/bind_tester"; + String UNBIND_TESTER_URL = "https://api.weixin.qq.com/wxa/unbind_tester"; + + /** + * 操作服务器域名 + * + * @param domainAction 域名操作参数 + * 除了 webViewDomain,都是有效的 + * @return 以下字段仅在 get 时返回完整字段 + * @throws WxErrorException 操作失败时抛出,具体错误码请看文档 + */ + WxMaDomainAction modifyDomain(WxMaDomainAction domainAction) throws WxErrorException; + + /** + * 设置小程序业务域名(仅供第三方代小程序调用) + * 授权给第三方的小程序,其业务域名只可以为第三方的服务器, + * 当小程序通过第三方发布代码上线后,小程序原先自己配置的业务域名将被删除, + * 只保留第三方平台的域名,所以第三方平台在代替小程序发布代码之前,需要调用接口为小程序添加业务域名。 + * 提示:需要先将域名登记到第三方平台的小程序业务域名中,才可以调用接口进行配置。 + * + * @param domainAction 域名操作参数 + * 只有 action 和 webViewDomain 是有效的 + * @return 以下字段仅在 get 时返回完整字段 + * @throws WxErrorException 操作失败时抛出,具体错误码请看文档 + */ + WxMaDomainAction setWebViewDomain(WxMaDomainAction domainAction) throws WxErrorException; + + /** + * 绑定微信用户为小程序体验者 + * + * @param wechatId 微信号 + * @throws WxErrorException 失败时抛出,具体错误码请看文档 + */ + void bindTester(String wechatId) throws WxErrorException; + + /** + * 解除绑定小程序的体验者 + * + * @param wechatId 微信号 + * @throws WxErrorException 失败时抛出,具体错误码请看文档 + */ + void unbindTester(String wechatId) throws WxErrorException; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaTemplateService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaTemplateService.java index 62be40ed83..1dbf052695 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaTemplateService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaTemplateService.java @@ -4,7 +4,7 @@ import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateLibraryGetResult; import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateLibraryListResult; import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateListResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import java.util.List; diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaUserService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaUserService.java index 7cf449fbd1..8c56721841 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaUserService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaUserService.java @@ -3,7 +3,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; import cn.binarywang.wx.miniapp.bean.WxMaUserInfo; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; /** * 用户信息相关操作接口. diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaAnalysisServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaAnalysisServiceImpl.java new file mode 100644 index 0000000000..dc7fe42437 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaAnalysisServiceImpl.java @@ -0,0 +1,126 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaAnalysisService; +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaRetainInfo; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaSummaryTrend; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaUserPortrait; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaVisitDistribution; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaVisitPage; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaVisitTrend; +import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; +import me.chanjar.weixin.common.error.WxErrorException; +import org.apache.commons.lang3.time.DateFormatUtils; + +import java.lang.reflect.Type; +import java.util.Date; +import java.util.List; + +/** + * @author Charming + * @since 2018-04-28 + */ +public class WxMaAnalysisServiceImpl implements WxMaAnalysisService { + private static final JsonParser JSON_PARSER = new JsonParser(); + private WxMaService wxMaService; + + public WxMaAnalysisServiceImpl(WxMaService wxMaService) { + this.wxMaService = wxMaService; + } + + @Override + public List* 二维码相关操作接口. * - * 接口A(createWxCode)加上接口C(createQrcode),总共生成的码数量限制为100,000,请谨慎调用。 + * 接口A(createWxaCode)加上接口C(createQrcode),总共生成的码数量限制为100,000,请谨慎调用。 * * 文档地址:https://mp.weixin.qq.com/debug/wxadoc/dev/api/qrcode.html *@@ -40,16 +40,17 @@ public interface WxMaQrcodeService { /** * 接口A: 获取小程序码. * - * @param path 不能为空,最大长度 128 字节 - * @param width 默认430 二维码的宽度 - * @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 - * @param lineColor auth_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} + * @param path 不能为空,最大长度 128 字节 + * @param width 默认430 二维码的宽度 + * @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 + * @param lineColor auth_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} + * @param is_hyaline 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码 */ - File createWxCode(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException; + File createWxaCode(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean is_hyaline) throws WxErrorException; - File createWxCode(String path, int width) throws WxErrorException; + File createWxaCode(String path, int width) throws WxErrorException; - File createWxCode(String path) throws WxErrorException; + File createWxaCode(String path) throws WxErrorException; /** * 接口B: 获取小程序码(永久有效、数量暂无限制). @@ -59,14 +60,16 @@ public interface WxMaQrcodeService { * 使用如下代码可以获取到二维码中的 scene 字段的值。 * 调试阶段可以使用开发工具的条件编译自定义参数 scene=xxxx 进行模拟,开发工具模拟时的 scene 的参数值需要进行 urlencode *getDailySummaryTrend(Date beginDate, Date endDate) throws WxErrorException { + return getAnalysisResultAsList(GET_DAILY_SUMMARY_TREND_URL, beginDate, endDate, + new TypeToken >() { + }.getType()); + } + + @Override + public List
getDailyVisitTrend(Date beginDate, Date endDate) throws WxErrorException { + return getAnalysisResultAsList(GET_DAILY_VISIT_TREND_URL, beginDate, endDate, + new TypeToken >() { + }.getType()); + } + + @Override + public List
getWeeklyVisitTrend(Date beginDate, Date endDate) throws WxErrorException { + return getAnalysisResultAsList(GET_WEEKLY_VISIT_TREND_URL, beginDate, endDate, + new TypeToken >() { + }.getType()); + } + + @Override + public List
getMonthlyVisitTrend(Date beginDate, Date endDate) throws WxErrorException { + return getAnalysisResultAsList(GET_MONTHLY_VISIT_TREND_URL, beginDate, endDate, + new TypeToken >() { + }.getType()); + } + + @Override + public WxMaVisitDistribution getVisitDistribution(Date beginDate, Date endDate) throws WxErrorException { + String responseContent = this.wxMaService.post(GET_VISIT_DISTRIBUTION_URL, toJson(beginDate, endDate)); + return WxMaVisitDistribution.fromJson(responseContent); + } + + @Override + public WxMaRetainInfo getDailyRetainInfo(Date beginDate, Date endDate) throws WxErrorException { + return getRetainInfo(beginDate, endDate, GET_DAILY_RETAIN_INFO_URL); + } + + @Override + public WxMaRetainInfo getWeeklyRetainInfo(Date beginDate, Date endDate) throws WxErrorException { + return getRetainInfo(beginDate, endDate, GET_WEEKLY_RETAIN_INFO_URL); + } + + @Override + public WxMaRetainInfo getMonthlyRetainInfo(Date beginDate, Date endDate) throws WxErrorException { + return getRetainInfo(beginDate, endDate, GET_MONTHLY_RETAIN_INFO_URL); + } + + @Override + public List
getVisitPage(Date beginDate, Date endDate) throws WxErrorException { + return getAnalysisResultAsList(GET_VISIT_PAGE_URL, beginDate, endDate, + new TypeToken >() { + }.getType()); + } + + @Override + public WxMaUserPortrait getUserPortrait(Date beginDate, Date endDate) throws WxErrorException { + String responseContent = this.wxMaService.post(GET_USER_PORTRAIT_URL, toJson(beginDate, endDate)); + return WxMaUserPortrait.fromJson(responseContent); + } + + private WxMaRetainInfo getRetainInfo(Date beginDate, Date endDate, String url) throws WxErrorException { + String responseContent = this.wxMaService.post(url, toJson(beginDate, endDate)); + return WxMaRetainInfo.fromJson(responseContent); + } + + /** + * 获取数据分析结果并返回 List,returnType 类型 + * + * @param url 链接 + * @param returnType 返回的类型 + * @param
返回的类型 + * @return List 类型的数据 + */ + private List getAnalysisResultAsList(String url, Date beginDate, Date endDate, Type returnType) throws WxErrorException { + String responseContent = this.wxMaService.post(url, toJson(beginDate, endDate)); + JsonObject response = JSON_PARSER.parse(responseContent).getAsJsonObject(); + boolean hasList = response.has("list"); + if (hasList) { + return WxMaGsonBuilder.create().fromJson(response.getAsJsonArray("list"), returnType); + } else { + return null; + } + } + + private static String toJson(Date beginDate, Date endDate) { + JsonObject param = new JsonObject(); + param.addProperty("begin_date", DateFormatUtils.format(beginDate, "yyyyMMdd")); + param.addProperty("end_date", DateFormatUtils.format(endDate, "yyyyMMdd")); + return param.toString(); + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCodeServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCodeServiceImpl.java new file mode 100644 index 0000000000..199d140a40 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCodeServiceImpl.java @@ -0,0 +1,148 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaCodeService; +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.bean.code.WxMaCategory; +import cn.binarywang.wx.miniapp.bean.code.WxMaCodeAuditStatus; +import cn.binarywang.wx.miniapp.bean.code.WxMaCodeCommitRequest; +import cn.binarywang.wx.miniapp.bean.code.WxMaCodeSubmitAuditRequest; +import cn.binarywang.wx.miniapp.bean.code.WxMaCodeVersionDistribution; +import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor; +import me.chanjar.weixin.common.util.http.RequestExecutor; +import me.chanjar.weixin.common.util.json.GsonHelper; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +/** + * @author Charming + * @since 2018-04-26 20:00 + */ +public class WxMaCodeServiceImpl implements WxMaCodeService { + private static final JsonParser JSON_PARSER = new JsonParser(); + private WxMaService wxMaService; + + public WxMaCodeServiceImpl(WxMaService wxMaService) { + this.wxMaService = wxMaService; + } + + @Override + public void commit(WxMaCodeCommitRequest commitRequest) throws WxErrorException { + this.wxMaService.post(COMMIT_URL, commitRequest.toJson()); + } + + @Override + public byte[] getQrCode() throws WxErrorException { + String appId = this.wxMaService.getWxMaConfig().getAppid(); + Path qrCodeFilePath = null; + try { + RequestExecutor executor = BaseMediaDownloadRequestExecutor + .create(this.wxMaService.getRequestHttp(), Files.createTempDirectory("weixin-java-tools-ma-" + appId).toFile()); + qrCodeFilePath = this.wxMaService.execute(executor, GET_QRCODE_URL, null).toPath(); + return Files.readAllBytes(qrCodeFilePath); + } catch (IOException e) { + throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e); + } finally { + if (qrCodeFilePath != null) { + try { + // 及时删除二维码文件,避免积压过多缓存文件 + Files.delete(qrCodeFilePath); + } catch (Exception ignored) { + } + } + } + } + + @Override + public List getCategory() throws WxErrorException { + String responseContent = this.wxMaService.get(GET_CATEGORY_URL, null); + JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject(); + boolean hasCategoryList = jsonObject.has("category_list"); + if (hasCategoryList) { + return WxMaGsonBuilder.create().fromJson(jsonObject.getAsJsonArray("category_list"), + new TypeToken >() { + }.getType()); + } else { + return null; + } + } + + @Override + public List
getPage() throws WxErrorException { + String responseContent = this.wxMaService.get(GET_PAGE_URL, null); + JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject(); + boolean hasPageList = jsonObject.has("page_list"); + if (hasPageList) { + return WxMaGsonBuilder.create().fromJson(jsonObject.getAsJsonArray("page_list"), + new TypeToken >() { + }.getType()); + } else { + return null; + } + } + + @Override + public long submitAudit(WxMaCodeSubmitAuditRequest auditRequest) throws WxErrorException { + String responseContent = this.wxMaService.post(SUBMIT_AUDIT_URL, auditRequest.toJson()); + JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject(); + return GsonHelper.getLong(jsonObject, "auditid"); + } + + @Override + public WxMaCodeAuditStatus getAuditStatus(long auditId) throws WxErrorException { + JsonObject param = new JsonObject(); + param.addProperty("auditid", auditId); + String responseContent = this.wxMaService.post(GET_AUDIT_STATUS_URL, param.toString()); + return WxMaCodeAuditStatus.fromJson(responseContent); + } + + @Override + public WxMaCodeAuditStatus getLatestAuditStatus() throws WxErrorException { + String responseContent = this.wxMaService.get(GET_LATEST_AUDIT_STATUS_URL, null); + return WxMaCodeAuditStatus.fromJson(responseContent); + } + + @Override + public void release() throws WxErrorException { + this.wxMaService.post(RELEASE_URL, "{}"); + } + + @Override + public void changeVisitStatus(String action) throws WxErrorException { + JsonObject param = new JsonObject(); + param.addProperty("action", action); + this.wxMaService.post(CHANGE_VISIT_STATUS_URL, param.toString()); + } + + @Override + public void revertCodeRelease() throws WxErrorException { + this.wxMaService.get(REVERT_CODE_RELEASE_URL, null); + } + + @Override + public WxMaCodeVersionDistribution getSupportVersion() throws WxErrorException { + String responseContent = this.wxMaService.post(GET_SUPPORT_VERSION_URL, "{}"); + return WxMaCodeVersionDistribution.fromJson(responseContent); + } + + @Override + public void setSupportVersion(String version) throws WxErrorException { + JsonObject param = new JsonObject(); + param.addProperty("version", version); + this.wxMaService.post(SET_SUPPORT_VERSION_URL, param.toString()); + } + + @Override + public void undoCodeAudit() throws WxErrorException { + this.wxMaService.get(UNDO_CODE_AUDIT_URL, null); + } +} 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 b198fc7a07..695f9578d1 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 @@ -2,9 +2,9 @@ import cn.binarywang.wx.miniapp.api.WxMaMediaService; import cn.binarywang.wx.miniapp.api.WxMaService; -import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor; import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; 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 aadc04f8a0..0a39712502 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 @@ -7,8 +7,8 @@ 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; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; /** * @author Binary Wang 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 b2ddfae7b8..277418e752 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 @@ -5,9 +5,9 @@ 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; +import cn.binarywang.wx.miniapp.bean.WxaCodeUnlimit; import cn.binarywang.wx.miniapp.util.http.QrCodeRequestExecutor; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import java.io.File; @@ -33,42 +33,44 @@ public File createQrcode(String path) throws WxErrorException { } @Override - public File createWxCode(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException { + public File createWxaCode(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException { WxMaWxcode wxMaWxcode = new WxMaWxcode(); wxMaWxcode.setPath(path); wxMaWxcode.setWidth(width); wxMaWxcode.setAutoColor(autoColor); wxMaWxcode.setLineColor(lineColor); + wxMaWxcode.setHyaline(isHyaline); return this.wxMaService.execute(new QrCodeRequestExecutor(this.wxMaService.getRequestHttp()), GET_WXACODE_URL, wxMaWxcode); } @Override - public File createWxCode(String path, int width) throws WxErrorException { - return this.createWxCode(path, width, true, null); + public File createWxaCode(String path, int width) throws WxErrorException { + return this.createWxaCode(path, width, true, null, false); } @Override - public File createWxCode(String path) throws WxErrorException { - return this.createWxCode(path, 430, true, null); + public File createWxaCode(String path) throws WxErrorException { + return this.createWxaCode(path, 430, true, null, false); } @Override - public File createWxCodeLimit(String scene, String page, int width, boolean autoColor, WxMaCodeLineColor lineColor) + public File createWxaCodeUnlimit(String scene, String page, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException { - WxMaWxcodeLimit wxMaWxcodeLimit = new WxMaWxcodeLimit(); - wxMaWxcodeLimit.setScene(scene); - wxMaWxcodeLimit.setPage(page); - wxMaWxcodeLimit.setWidth(width); - wxMaWxcodeLimit.setAutoColor(autoColor); - wxMaWxcodeLimit.setLineColor(lineColor); + WxaCodeUnlimit wxaCodeUnlimit = new WxaCodeUnlimit(); + wxaCodeUnlimit.setScene(scene); + wxaCodeUnlimit.setPage(page); + wxaCodeUnlimit.setWidth(width); + wxaCodeUnlimit.setAutoColor(autoColor); + wxaCodeUnlimit.setLineColor(lineColor); + wxaCodeUnlimit.setHyaline(isHyaline); return this.wxMaService.execute(new QrCodeRequestExecutor(this.wxMaService.getRequestHttp()), - GET_WXACODE_UNLIMIT_URL, wxMaWxcodeLimit); + GET_WXACODE_UNLIMIT_URL, wxaCodeUnlimit); } @Override - public File createWxCodeLimit(String scene, String page) throws WxErrorException { - return this.createWxCodeLimit(scene, page, 430, true, null); + public File createWxaCodeUnlimit(String scene, String page) throws WxErrorException { + return this.createWxaCodeUnlimit(scene, page, 430, true, null, false); } } 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 1ec7801d16..be9dff6912 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 @@ -1,32 +1,21 @@ package cn.binarywang.wx.miniapp.api.impl; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.locks.Lock; - -import org.apache.http.HttpHost; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.BasicResponseHandler; -import org.apache.http.impl.client.CloseableHttpClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - +import cn.binarywang.wx.miniapp.api.WxMaAnalysisService; +import cn.binarywang.wx.miniapp.api.WxMaCodeService; import cn.binarywang.wx.miniapp.api.WxMaMediaService; import cn.binarywang.wx.miniapp.api.WxMaMsgService; import cn.binarywang.wx.miniapp.api.WxMaQrcodeService; import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.api.WxMaSettingService; import cn.binarywang.wx.miniapp.api.WxMaTemplateService; import cn.binarywang.wx.miniapp.api.WxMaUserService; import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import cn.binarywang.wx.miniapp.config.WxMaConfig; -import cn.binarywang.wx.miniapp.constant.WxMaConstants; import com.google.common.base.Joiner; import me.chanjar.weixin.common.bean.WxAccessToken; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.util.DataUtils; import me.chanjar.weixin.common.util.crypto.SHA1; import me.chanjar.weixin.common.util.http.HttpType; import me.chanjar.weixin.common.util.http.RequestExecutor; @@ -35,6 +24,21 @@ import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder; import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder; +import org.apache.http.HttpHost; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.BasicResponseHandler; +import org.apache.http.impl.client.CloseableHttpClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.locks.Lock; + +import static cn.binarywang.wx.miniapp.constant.WxMaConstants.ErrorCode.*; /** * @author Binary Wang @@ -51,6 +55,9 @@ public class WxMaServiceImpl implements WxMaService, RequestHttp
T execute(RequestExecutor executor, String uri, E data) thro throw new RuntimeException("微信服务端异常,超出重试次数"); } - public T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException { + private T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException { + E dataForLog = DataUtils.handleDataWithSecret(data); + if (uri.contains("access_token=")) { throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri); } @@ -217,16 +226,16 @@ public T executeInternal(RequestExecutor executor, String uri, E da try { T result = executor.execute(uriWithAccessToken, data); - this.log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, data, result); + this.log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, dataForLog, result); return result; } catch (WxErrorException e) { WxError error = e.getError(); /* * 发生以下情况时尝试刷新access_token */ - if (error.getErrorCode() == WxMaConstants.ErrorCode.ERR_40001 - || error.getErrorCode() == WxMaConstants.ErrorCode.ERR_42001 - || error.getErrorCode() == WxMaConstants.ErrorCode.ERR_40014) { + if (error.getErrorCode() == ERR_40001 + || error.getErrorCode() == ERR_42001 + || error.getErrorCode() == ERR_40014) { // 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token this.getWxMaConfig().expireAccessToken(); if (this.getWxMaConfig().autoRefreshToken()) { @@ -235,12 +244,12 @@ public T executeInternal(RequestExecutor executor, String uri, E da } if (error.getErrorCode() != 0) { - this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, data, error); + this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, dataForLog, error); throw new WxErrorException(error, e); } return null; } catch (IOException e) { - this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, data, e.getMessage()); + this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage()); throw new RuntimeException(e); } } @@ -290,4 +299,19 @@ public WxMaQrcodeService getQrcodeService() { public WxMaTemplateService getTemplateService() { return this.templateService; } + + @Override + public WxMaAnalysisService getAnalysisService() { + return this.analysisService; + } + + @Override + public WxMaCodeService getCodeService() { + return this.codeService; + } + + @Override + public WxMaSettingService getSettingService() { + return this.settingService; + } } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSettingServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSettingServiceImpl.java new file mode 100644 index 0000000000..ac45e6ce31 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSettingServiceImpl.java @@ -0,0 +1,48 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.api.WxMaSettingService; +import cn.binarywang.wx.miniapp.bean.WxMaDomainAction; +import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; +import me.chanjar.weixin.common.error.WxErrorException; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Charming + * @since 2018-04-27 15:46 + */ +public class WxMaSettingServiceImpl implements WxMaSettingService { + private WxMaService wxMaService; + + public WxMaSettingServiceImpl(WxMaService wxMaService) { + this.wxMaService = wxMaService; + } + + @Override + public WxMaDomainAction modifyDomain(WxMaDomainAction domainAction) throws WxErrorException { + String responseContent = this.wxMaService.post(MODIFY_DOMAIN_URL, domainAction.toJson()); + return WxMaDomainAction.fromJson(responseContent); + } + + @Override + public WxMaDomainAction setWebViewDomain(WxMaDomainAction domainAction) throws WxErrorException { + String responseContent = this.wxMaService.post(SET_WEB_VIEW_DOMAIN_URL, domainAction.toJson()); + return WxMaDomainAction.fromJson(responseContent); + } + + @Override + public void bindTester(String wechatId) throws WxErrorException { + Map param = new HashMap<>(1); + param.put("wechatid", wechatId); + this.wxMaService.post(BIND_TESTER_URL, WxMaGsonBuilder.create().toJson(param)); + } + + @Override + public void unbindTester(String wechatId) throws WxErrorException { + Map param = new HashMap<>(1); + param.put("wechatid", wechatId); + this.wxMaService.post(UNBIND_TESTER_URL, WxMaGsonBuilder.create().toJson(param)); + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaTemplateServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaTemplateServiceImpl.java index 44c160ea63..9570c07a91 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaTemplateServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaTemplateServiceImpl.java @@ -6,8 +6,8 @@ import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateLibraryGetResult; import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateLibraryListResult; import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateListResult; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.json.WxGsonBuilder; import java.util.HashMap; 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 2849101903..f1bac75e87 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 @@ -8,7 +8,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; import cn.binarywang.wx.miniapp.bean.WxMaUserInfo; import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; /** * @author Binary Wang diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaDomainAction.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaDomainAction.java new file mode 100644 index 0000000000..313f6cbed8 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaDomainAction.java @@ -0,0 +1,58 @@ +package cn.binarywang.wx.miniapp.bean; + +import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 域名相关操作 + * + * @author Charming + * @since 2018-04-27 15:45 + */ +@Data +@Builder +public class WxMaDomainAction implements Serializable { + private static final long serialVersionUID = -2898601966852935708L; + /** + * add添加, delete删除, set覆盖, get获取。当参数是get时不需要填四个域名字段 + */ + private String action; + /** + * request合法域名,当action参数是get时不需要此字段。 + */ + @SerializedName("requestdomain") + private List requestDomain; + /** + * socket合法域名,当action参数是get时不需要此字段。 + */ + @SerializedName("wsrequestdomain") + private List wsRequestDomain; + /** + * uploadFile合法域名,当action参数是get时不需要此字段。 + */ + @SerializedName("uploaddomain") + private List uploadDomain; + /** + * downloadFile合法域名,当action参数是get时不需要此字段。 + */ + @SerializedName("downloaddomain") + private List downloadDomain; + /** + * 小程序业务域名,当action参数是get时不需要此字段。 + */ + @SerializedName("webviewdomain") + private List webViewDomain; + + public String toJson() { + return WxMaGsonBuilder.create().toJson(this); + } + + public static WxMaDomainAction fromJson(String json) { + return WxMaGsonBuilder.create().fromJson(json, WxMaDomainAction.class); + } +} 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 85fece8b32..ee11476878 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 @@ -4,7 +4,7 @@ import cn.binarywang.wx.miniapp.builder.LinkMessageBuilder; import cn.binarywang.wx.miniapp.builder.MaPageMessageBuilder; import cn.binarywang.wx.miniapp.builder.TextMessageBuilder; -import com.google.gson.GsonBuilder; +import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; import com.google.gson.annotations.SerializedName; import lombok.AllArgsConstructor; import lombok.Builder; @@ -104,7 +104,7 @@ public static MaPageMessageBuilder newMaPageBuilder() { } public String toJson() { - return new GsonBuilder().create().toJson(this); + 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 60b19bf906..d04212d41b 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 @@ -42,7 +42,6 @@ public class WxMaMessage implements Serializable { @SerializedName("CreateTime") @XStreamAlias("CreateTime") - @XStreamConverter(value = XStreamCDataConverter.class) private Integer createTime; @SerializedName("MsgType") @@ -62,7 +61,6 @@ public class WxMaMessage implements Serializable { @SerializedName("MsgId") @XStreamAlias("MsgId") - @XStreamConverter(value = XStreamCDataConverter.class) private Long msgId; @SerializedName("PicUrl") @@ -80,6 +78,31 @@ public class WxMaMessage implements Serializable { @XStreamConverter(value = XStreamCDataConverter.class) private String event; + @SerializedName("Title") + @XStreamAlias("Title") + @XStreamConverter(value = XStreamCDataConverter.class) + private String title; + + @SerializedName("AppId") + @XStreamAlias("AppId") + @XStreamConverter(value = XStreamCDataConverter.class) + private String appId; + + @SerializedName("PagePath") + @XStreamAlias("PagePath") + @XStreamConverter(value = XStreamCDataConverter.class) + private String pagePath; + + @SerializedName("ThumbUrl") + @XStreamAlias("ThumbUrl") + @XStreamConverter(value = XStreamCDataConverter.class) + private String thumbUrl; + + @SerializedName("ThumbMediaId") + @XStreamAlias("ThumbMediaId") + @XStreamConverter(value = XStreamCDataConverter.class) + private String thumbMediaId; + @SerializedName("SessionFrom") @XStreamAlias("SessionFrom") @XStreamConverter(value = XStreamCDataConverter.class) 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 8e629096c6..e538a1bb83 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 @@ -23,6 +23,9 @@ public class WxMaWxcode extends AbstractWxMaQrcodeWrapper implements Serializabl @SerializedName("auto_color") private boolean autoColor = true; + @SerializedName("is_hyaline") + private boolean isHyaline = false; + @SerializedName("line_color") private WxMaCodeLineColor lineColor = new WxMaCodeLineColor("0", "0", "0"); 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/WxaCodeUnlimit.java similarity index 70% rename from weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaWxcodeLimit.java rename to weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxaCodeUnlimit.java index a251f05465..05bf134c6b 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/WxaCodeUnlimit.java @@ -15,7 +15,7 @@ */ @Data @EqualsAndHashCode(callSuper = false) -public class WxMaWxcodeLimit extends AbstractWxMaQrcodeWrapper implements Serializable { +public class WxaCodeUnlimit extends AbstractWxMaQrcodeWrapper implements Serializable { private static final long serialVersionUID = 4782193774524960401L; private String scene; private String page; @@ -25,11 +25,14 @@ public class WxMaWxcodeLimit extends AbstractWxMaQrcodeWrapper implements Serial @SerializedName("auto_color") private boolean autoColor = true; + @SerializedName("is_hyaline") + private boolean isHyaline = false; + @SerializedName("line_color") private WxMaCodeLineColor lineColor = new WxMaCodeLineColor("0", "0", "0"); - public static WxMaWxcodeLimit fromJson(String json) { - return WxMaGsonBuilder.create().fromJson(json, WxMaWxcodeLimit.class); + public static WxaCodeUnlimit fromJson(String json) { + return WxMaGsonBuilder.create().fromJson(json, WxaCodeUnlimit.class); } } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaRetainInfo.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaRetainInfo.java new file mode 100644 index 0000000000..7021a180e9 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaRetainInfo.java @@ -0,0 +1,43 @@ +package cn.binarywang.wx.miniapp.bean.analysis; + +import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +import java.io.Serializable; +import java.util.Map; + +/** + * 访问留存 + * + * @author Charming + * @since 2018-04-28 14:41 + */ +@Data +public class WxMaRetainInfo implements Serializable { + private static final long serialVersionUID = 8986403173656848413L; + /** + * 日留存:日期,yyyyMMdd 格式,如 20170313 + * 周留存:时间,如"20170306-20170312" + * 月留存:时间,如"201702" + */ + @SerializedName(value = "refDate", alternate = "ref_date") + private String refDate; + /** + * 新增用户留存 + * - key: + * - 日留存:标识,0开始,0表示当天,1表示1天后,依此类推,key取值分别是:0,1,2,3,4,5,6,7,14,30 + * - 周留存:标识,0开始,0表示当周,1表示1周后,依此类推,key 取值分别是:0,1,2,3,4 + * - 月留存:标识,0开始,0表示当月,1表示1月后,key取值分别是:0,1 + * - value: key对应日期的新增用户数/活跃用户数(key=0时)或留存用户数(k>0时) + */ + private Map visitUvNew; + /** + * 活跃用户留存 + */ + private Map visitUv; + + public static WxMaRetainInfo fromJson(String json) { + return WxMaGsonBuilder.create().fromJson(json, WxMaRetainInfo.class); + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaSummaryTrend.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaSummaryTrend.java new file mode 100644 index 0000000000..f4ceb0ad95 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaSummaryTrend.java @@ -0,0 +1,37 @@ +package cn.binarywang.wx.miniapp.bean.analysis; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +import java.io.Serializable; + +/** + * 小程序概况趋势 + * + * @author Charming + * @since 2018-04-28 + */ +@Data +public class WxMaSummaryTrend implements Serializable { + private static final long serialVersionUID = 1379688517709317935L; + /** + * 日期,yyyyMMdd 格式,如 20170313 + */ + @SerializedName(value = "refDate", alternate = "ref_date") + private String refDate; + /** + * 累计用户数 + */ + @SerializedName(value = "visitTotal", alternate = "visit_total") + private Long visitTotal; + /** + * 转发次数 + */ + @SerializedName(value = "sharePv", alternate = "share_pv") + private Long sharePv; + /** + * 转发人数 + */ + @SerializedName(value = "shareUv", alternate = "share_uv") + private Long shareUv; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaUserPortrait.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaUserPortrait.java new file mode 100644 index 0000000000..5e1164909e --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaUserPortrait.java @@ -0,0 +1,68 @@ +package cn.binarywang.wx.miniapp.bean.analysis; + +import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; +import lombok.Data; + +import java.io.Serializable; +import java.util.Map; + +/** + * 用户画像 + * + * @author Charming + * @since 2018-04-28 + */ +@Data +public class WxMaUserPortrait implements Serializable { + private static final long serialVersionUID = 5653571047669243178L; + /** + * 时间范围,如: "20170611-20170617" + */ + private String refDate; + /** + * 新用户 + */ + private Item visitUvNew; + /** + * 活跃用户 + */ + private Item visitUv; + + public static WxMaUserPortrait fromJson(String json) { + return WxMaGsonBuilder.create().fromJson(json, WxMaUserPortrait.class); + } + + @Data + public static class Item { + /** + * key: 省份,如北京、广东等 + * value: 活跃用户数或新用户数 + */ + private Map province; + /** + * key: 城市,如北京、广州等 + * value: 活跃用户数或新用户数 + */ + private Map city; + /** + * key: 性别,包括男、女、未知 + * value: 活跃用户数或新用户数 + */ + private Map genders; + /** + * key: 终端类型,包括iPhone, android,其他 + * value: 活跃用户数或新用户数 + */ + private Map platforms; + /** + * key: 机型,如苹果iPhone6, OPPO R9等 + * value: 活跃用户数或新用户数 + */ + private Map devices; + /** + * key: 年龄,包括17岁以下、18-24岁等区间 + * value: 活跃用户数或新用户数 + */ + private Map ages; + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaVisitDistribution.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaVisitDistribution.java new file mode 100644 index 0000000000..1655eec286 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaVisitDistribution.java @@ -0,0 +1,83 @@ +package cn.binarywang.wx.miniapp.bean.analysis; + +import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +import java.io.Serializable; +import java.util.Map; + +/** + * 访问分布 + * 访问来源:(index="access_source_session_cnt") + * 1:小程序历史列表 + * 2:搜索 + * 3:会话 + * 4:二维码 + * 5:公众号主页 + * 6:聊天顶部 + * 7:系统桌面 + * 8:小程序主页 + * 9:附近的小程序 + * 10:其他 + * 11:模板消息 + * 12:客服消息 + * 13: 公众号菜单 + * 14: APP分享 + * 15: 支付完成页 + * 16: 长按识别二维码 + * 17: 相册选取二维码 + * 18: 公众号文章 + * 19:钱包 + * 20:卡包 + * 21:小程序内卡券 + * 22:其他小程序 + * 23:其他小程序返回 + * 24:卡券适用门店列表 + * 25:搜索框快捷入口 + * 26:小程序客服消息 + * 27:公众号下发 + * 访问时长:(index="access_staytime_info") + * 1: 0-2s + * 2: 3-5s + * 3: 6-10s + * 4: 11-20s + * 5: 20-30s + * 6: 30-50s + * 7: 50-100s + * 8: > 100s + * 平均访问深度:(index="access_depth_info") + * 1: 1页 + * 2: 2页 + * 3: 3页 + * 4: 4页 + * 5: 5页 + * 6: 6-10页 + * 7: >10页 + * + * @author Charming + * @since 2018-04-28 + */ +@Data +public class WxMaVisitDistribution implements Serializable { + private static final long serialVersionUID = 5404250039495926632L; + /** + * 日期,yyyyMMdd 格式,如 20170313 + */ + @SerializedName(value = "refDate", alternate = "ref_date") + private String refDate; + /** + * key: 分布类型 + * - access_source_session_cnt 访问来源分布 + * - access_staytime_info 访问时长分布 + * - access_depth_info 访问深度的分布 + * value: 场景 ID 下的值 + * - key: 场景 ID + * - value: 场景下的值 + */ + private Map > list; + + public static WxMaVisitDistribution fromJson(String json) { + return WxMaGsonBuilder.create().fromJson(json, WxMaVisitDistribution.class); + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaVisitPage.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaVisitPage.java new file mode 100644 index 0000000000..705cf6b49e --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaVisitPage.java @@ -0,0 +1,55 @@ +package cn.binarywang.wx.miniapp.bean.analysis; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author Charming + * @since 2018-04-28 + */ +@Data +public class WxMaVisitPage implements Serializable { + private static final long serialVersionUID = -7006334774516877372L; + /** + * 页面路径 + */ + @SerializedName(value = "pagePath", alternate = "page_path") + private String pagePath; + /** + * 访问次数 + */ + @SerializedName(value = "pageVisitPv", alternate = "page_visit_pv") + private Long pageVisitPv; + /** + * 访问人数 + */ + @SerializedName(value = "pageVisitUv", alternate = "page_visit_uv") + private Long pageVisitUv; + /** + * 次均停留时长 + */ + @SerializedName(value = "pageStayTimePv", alternate = "page_staytime_pv") + private Float pageStayTimePv; + /** + * 进入页次数 + */ + @SerializedName(value = "entryPagePv", alternate = "entrypage_pv") + private Long entryPagePv; + /** + * 退出页次数 + */ + @SerializedName(value = "exitPagePv", alternate = "exitpage_pv") + private Long exitPagePv; + /** + * 转发次数 + */ + @SerializedName(value = "pageSharePv", alternate = "page_share_pv") + private Long pageSharePv; + /** + * 转发人数 + */ + @SerializedName(value = "pageShareUv", alternate = "page_share_uv") + private Long pageShareUv; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaVisitTrend.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaVisitTrend.java new file mode 100644 index 0000000000..72223ef618 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaVisitTrend.java @@ -0,0 +1,59 @@ +package cn.binarywang.wx.miniapp.bean.analysis; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +import java.io.Serializable; + +/** + * 访问趋势 + * + * @author Charming + * @since 2018-04-28 + */ +@Data +public class WxMaVisitTrend implements Serializable { + private static final long serialVersionUID = 1379688517709317935L; + /** + * 日留存:日期,yyyyMMdd 格式,如 20170313 + * 周留存:时间,如"20170306-20170312" + * 月留存:时间,如"201702" + */ + @SerializedName(value = "refDate", alternate = "ref_date") + private String refDate; + /** + * 打开次数 + */ + @SerializedName(value = "sessionCnt", alternate = "session_cnt") + private Long sessionCnt; + /** + * 访问次数 + */ + @SerializedName(value = "visitPv", alternate = "visit_pv") + private Long visitPv; + /** + * 访问人数 + */ + @SerializedName(value = "visitUv", alternate = "visit_uv") + private Long visitUv; + /** + * 新用户数 + */ + @SerializedName(value = "visitUvNew", alternate = "visit_uv_new") + private Long visitUvNew; + /** + * 人均停留时长 (浮点型,单位:秒) + */ + @SerializedName(value = "stayTimeUv", alternate = "stay_time_uv") + private Float stayTimeUv; + /** + * 人均停留时长 (浮点型,单位:秒) + */ + @SerializedName(value = "stayTimeSession", alternate = "stay_time_session") + private Float stayTimeSession; + /** + * 人均停留时长 (浮点型,单位:秒) + */ + @SerializedName(value = "visitDepth", alternate = "visit_depth") + private Float visitDepth; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/package-info.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/package-info.java new file mode 100644 index 0000000000..e4e68c7805 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/analysis/package-info.java @@ -0,0 +1,7 @@ +/** + * 数据分析 + * + * @author Charming + * @since 2018-04-28 + */ +package cn.binarywang.wx.miniapp.bean.analysis; diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCategory.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCategory.java new file mode 100644 index 0000000000..32195333eb --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCategory.java @@ -0,0 +1,62 @@ +package cn.binarywang.wx.miniapp.bean.code; + +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; + +/** + * 小程序帐号的可选类目,其中 address / tag / title 是提交审核会用到的 + * + * @author Charming + * @since 2018-04-26 19:44 + */ +@Data +@Builder +public class WxMaCategory implements Serializable { + private static final long serialVersionUID = -7663757440028175135L; + /** + * 一级类目名称 + */ + @SerializedName("first_class") + private String firstClass; + /** + * 二级类目名称 + */ + @SerializedName("second_class") + private String secondClass; + /** + * 三级类目名称 + */ + @SerializedName("third_class") + private String thirdClass; + /** + * 一级类目的ID编号 + */ + @SerializedName("first_id") + private Long firstId; + /** + * 二级类目的ID编号 + */ + @SerializedName("second_id") + private Long secondId; + /** + * 三级类目的ID编号 + */ + @SerializedName("third_id") + private Long thirdId; + + /** + * 小程序的页面,可通过“获取小程序的第三方提交代码的页面配置”接口获得 + */ + private String address; + /** + * 小程序的标签,多个标签用空格分隔,标签不能多于10个,标签长度不超过20 + */ + private String tag; + /** + * 小程序页面的标题,标题长度不超过32 + */ + private String title; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeAuditStatus.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeAuditStatus.java new file mode 100644 index 0000000000..36c33eaf1a --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeAuditStatus.java @@ -0,0 +1,37 @@ +package cn.binarywang.wx.miniapp.bean.code; + +import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; + +/** + * 小程序代码审核状态 + * + * @author Charming + * @since 2018-04-26 19:44:39 + */ +@Data +@Builder +public class WxMaCodeAuditStatus implements Serializable { + private static final long serialVersionUID = 4655119308692217268L; + /** + * 审核 ID + */ + @SerializedName(value = "auditId", alternate = {"auditid"}) + private Long auditId; + /** + * 审核状态,其中0为审核成功,1为审核失败,2为审核中 + */ + private Integer status; + /** + * 当status=1,审核被拒绝时,返回的拒绝原因 + */ + private String reason; + + public static WxMaCodeAuditStatus fromJson(String json) { + return WxMaGsonBuilder.create().fromJson(json, WxMaCodeAuditStatus.class); + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeCommitRequest.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeCommitRequest.java new file mode 100644 index 0000000000..ec64da59a3 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeCommitRequest.java @@ -0,0 +1,39 @@ +package cn.binarywang.wx.miniapp.bean.code; + +import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; + +/** + * 微信代码请求上传参数 + * + * @author Charming + * @since 2018-04-26 19:44:47 + */ +@Data +@Builder +public class WxMaCodeCommitRequest implements Serializable { + private static final long serialVersionUID = 7495157056049312108L; + /** + * 代码库中的代码模版ID + */ + private Long templateId; + /** + * 第三方自定义的配置 + */ + private WxMaCodeExtConfig extConfig; + /** + * 代码版本号,开发者可自定义 + */ + private String userVersion; + /** + * 代码描述,开发者可自定义 + */ + private String userDesc; + + public String toJson() { + return WxMaGsonBuilder.create().toJson(this); + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeExtConfig.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeExtConfig.java new file mode 100644 index 0000000000..5121112392 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeExtConfig.java @@ -0,0 +1,199 @@ +package cn.binarywang.wx.miniapp.bean.code; + +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +/** + * 上传代码需要用到的第三方自定义的配置 + * + * @author Charming + * @since 2018-04-26 19:44 + */ +@Data +@Builder +public class WxMaCodeExtConfig implements Serializable { + private static final long serialVersionUID = -7666911367458178753L; + /** + * 配置 ext.json 是否生效 + * 必填:是 + */ + private boolean extEnable; + /** + * 配置 extAppid + * 必填:是 + */ + private String extAppid; + /** + * 开发自定义的数据字段 + * 必填:否 + */ + private Object ext; + /** + * 单独设置每个页面的 json + * 必填:否 + * key: page 名称,如 pages/logs/logs + * value: page 配置 + */ + private Map extPages; + /** + * 是否直接提交到待审核列表 + * 必填:否 + */ + private Boolean directCommit; + /** + * 设置页面路径(同 app.json 相同的字段,填写会覆盖 app.json) + * 必填:否 + */ + private List pages; + /** + * 设置默认页面的窗口表现(同 app.json 相同的字段,填写会覆盖 app.json) + * 必填:否 + */ + private PageConfig window; + /** + * 设置各种网络请求的超时时间(同 app.json 相同的字段,填写会覆盖 app.json) + * 必填:否 + */ + private NetworkTimeout networkTimeout; + /** + * 设置是否开启 debug 模式(同 app.json 相同的字段,填写会覆盖 app.json) + * 必填:否 + */ + private Boolean debug; + + /** + * page.json 配置,页面配置 + * 文档:https://mp.weixin.qq.com/debug/wxadoc/dev/framework/config.html + */ + @Data + @Builder + public static class PageConfig { + /** + * 导航栏背景颜色,如"#000000" HexColor + * 默认:#000000 + */ + private String navigationBarBackgroundColor; + /** + * 导航栏标题颜色,仅支持 black/white + * 默认:white + */ + private String navigationBarTextStyle; + /** + * 导航栏标题文字内容 + */ + private String navigationBarTitleText; + /** + * 窗口的背景色 HexColor + * 默认:#ffffff + */ + private String backgroundColor; + /** + * 下拉背景字体、loading 图的样式,仅支持 dark/light + * 默认:dark + */ + private String backgroundTextStyle; + /** + * 是否开启下拉刷新,详见页面相关事件处理函数 + * 默认:false + */ + private String enablePullDownRefresh; + /** + * 设置为 true 则页面整体不能上下滚动;只在 page.json 中有效,无法在 app.json 中设置该项 + * 默认:false + */ + private Boolean disableScroll; + /** + * 页面上拉触底事件触发时距页面底部距离,单位为px + * 默认:50 + */ + private Integer onReachBottomDistance; + } + + /** + * tabBar 配置 + */ + @Data + @Builder + public static class TabBar { + /** + * HexColor, tab 上的文字默认颜色 + */ + private String color; + /** + * HexColor, tab 上的文字选中时的颜色 + */ + private String selectedColor; + /** + * HexColor, tab 的背景色 + */ + private String backgroundColor; + /** + * tabbar 上边框的颜色,仅支持 black/white + */ + private String borderStyle; + /** + * tab 的列表,最少2个、最多5个 tab + */ + private List - list; + /** + * 可选值 bottom、top + */ + private String position; + + /** + * list item + */ + @Data + @Builder + public static class Item { + /** + * 是 页面路径,必须在 pages 中先定义 + */ + private String pagePath; + /** + * tab 上按钮文字 + */ + private String text; + /** + * 图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片 + */ + private String iconPath; + /** + * 选中时的图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效 + */ + private String selectedIconPath; + } + } + + /** + * 各种网络请求的超时时间 + */ + @Data + @Builder + public static class NetworkTimeout { + /** + * wx.request的超时时间,单位毫秒,默认为:60000 + * 必填:否 + */ + private Integer request; + /** + * wx.connectSocket的超时时间,单位毫秒,默认为:60000 + * 必填:否 + */ + private Integer connectSocket; + /** + * wx.uploadFile的超时时间,单位毫秒,默认为:60000 + * 必填:否 + */ + private Integer uploadFile; + /** + * wx.downloadFile的超时时间,单位毫秒,默认为:60000 + * 必填:否 + */ + private Integer downloadFile; + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeSubmitAuditRequest.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeSubmitAuditRequest.java new file mode 100644 index 0000000000..5b784dbded --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeSubmitAuditRequest.java @@ -0,0 +1,30 @@ +package cn.binarywang.wx.miniapp.bean.code; + +import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 提交审核的请求 + * + * @author Charming + * @since 2018-04-26 19:45 + */ +@Data +@Builder +public class WxMaCodeSubmitAuditRequest implements Serializable { + private static final long serialVersionUID = 8854979405505241314L; + /** + * 提交审核项的一个列表(至少填写1项,至多填写5项) + */ + @SerializedName("item_list") + private List
itemList; + + public String toJson() { + return WxMaGsonBuilder.create().toJson(this); + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeVersionDistribution.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeVersionDistribution.java new file mode 100644 index 0000000000..4c0f09644f --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeVersionDistribution.java @@ -0,0 +1,30 @@ +package cn.binarywang.wx.miniapp.bean.code; + +import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; +import lombok.Data; + +import java.util.Map; + +/** + * 小程序代码版本号分布 + * + * @author Charming + * @since 2018-04-26 19:45 + */ +@Data +public class WxMaCodeVersionDistribution { + /** + * 当前版本 + */ + private String nowVersion; + /** + * 受影响用户占比 + * key: version, 版本号 + * value: percentage, 受影响比例 + */ + private Map uvInfo; + + public static WxMaCodeVersionDistribution fromJson(String json) { + return WxMaGsonBuilder.create().fromJson(json, WxMaCodeVersionDistribution.class); + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/package-info.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/package-info.java new file mode 100644 index 0000000000..01f6496b99 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/package-info.java @@ -0,0 +1,7 @@ +/** + * 微信小程序代码管理相关的 bean + * + * @author Charming + * @since 2018-04-26 19:44 + */ +package cn.binarywang.wx.miniapp.bean.code; diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageHandler.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageHandler.java index 794d60e98a..f60edc1d8a 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageHandler.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageHandler.java @@ -2,7 +2,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.bean.WxMaMessage; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.session.WxSessionManager; import java.util.Map; diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageInterceptor.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageInterceptor.java index 3443862fe1..ef0d500a19 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageInterceptor.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageInterceptor.java @@ -2,7 +2,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.bean.WxMaMessage; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.session.WxSessionManager; import java.util.Map; 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 5353652995..2e4906ebf1 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 @@ -3,7 +3,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.bean.WxMaMessage; import me.chanjar.weixin.common.api.WxErrorExceptionHandler; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.session.WxSessionManager; import java.util.ArrayList; 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 1b64ec6327..cb8097db53 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,8 +1,8 @@ package cn.binarywang.wx.miniapp.util.http; 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.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaCodeCommitRequestGsonAdapter.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaCodeCommitRequestGsonAdapter.java new file mode 100755 index 0000000000..410f86ca1f --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaCodeCommitRequestGsonAdapter.java @@ -0,0 +1,28 @@ +package cn.binarywang.wx.miniapp.util.json; + +import cn.binarywang.wx.miniapp.bean.code.WxMaCodeCommitRequest; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; + +/** + * @author Charming + * @since 2018-04-26 19:47 + */ +public class WxMaCodeCommitRequestGsonAdapter implements JsonSerializer { + + @Override + public JsonElement serialize(WxMaCodeCommitRequest request, Type typeOfSrc, JsonSerializationContext context) { + JsonObject requestJson = new JsonObject(); + requestJson.addProperty("template_id", request.getTemplateId()); + requestJson.addProperty("user_version", request.getUserVersion()); + requestJson.addProperty("user_desc", request.getUserDesc()); + if (request.getExtConfig() != null) { + requestJson.addProperty("ext_json", WxMaGsonBuilder.create().toJson(request.getExtConfig())); + } + return requestJson; + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaCodeVersionDistributionGsonAdapter.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaCodeVersionDistributionGsonAdapter.java new file mode 100644 index 0000000000..027ca6a959 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaCodeVersionDistributionGsonAdapter.java @@ -0,0 +1,50 @@ +package cn.binarywang.wx.miniapp.util.json; + +import cn.binarywang.wx.miniapp.bean.code.WxMaCodeVersionDistribution; +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import me.chanjar.weixin.common.util.json.GsonHelper; + +import java.lang.reflect.Type; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author Charming + * @since 2018-04-26 19:47 + */ +public class WxMaCodeVersionDistributionGsonAdapter implements JsonDeserializer { + @Override + public WxMaCodeVersionDistribution deserialize(JsonElement json, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + if (json == null) { + return null; + } + + WxMaCodeVersionDistribution distribution = new WxMaCodeVersionDistribution(); + JsonObject object = json.getAsJsonObject(); + distribution.setNowVersion(GsonHelper.getString(object, "now_version")); + distribution.setUvInfo(getAsMap(object.getAsJsonObject("uv_info"), "items")); + return distribution; + } + + private Map getAsMap(JsonObject object, String memberName) { + JsonArray array = object.getAsJsonArray(memberName); + if (array != null && array.size() > 0) { + Map map = new LinkedHashMap<>(array.size()); + for (JsonElement element : array) { + JsonObject elementObject = element.getAsJsonObject(); + String version = GsonHelper.getString(elementObject, "version"); + if (version != null) { + Float percentage = GsonHelper.getFloat(elementObject, "percentage"); + map.put(version, percentage); + } + } + return map; + } + return null; + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaGsonBuilder.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaGsonBuilder.java index 5a08a39a7e..21f48d3ffd 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaGsonBuilder.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaGsonBuilder.java @@ -1,6 +1,11 @@ package cn.binarywang.wx.miniapp.util.json; import cn.binarywang.wx.miniapp.bean.WxMaTemplateMessage; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaRetainInfo; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaUserPortrait; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaVisitDistribution; +import cn.binarywang.wx.miniapp.bean.code.WxMaCodeCommitRequest; +import cn.binarywang.wx.miniapp.bean.code.WxMaCodeVersionDistribution; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -13,6 +18,11 @@ public class WxMaGsonBuilder { static { INSTANCE.disableHtmlEscaping(); INSTANCE.registerTypeAdapter(WxMaTemplateMessage.class, new WxMaTemplateMessageGsonAdapter()); + INSTANCE.registerTypeAdapter(WxMaCodeCommitRequest.class, new WxMaCodeCommitRequestGsonAdapter()); + INSTANCE.registerTypeAdapter(WxMaCodeVersionDistribution.class, new WxMaCodeVersionDistributionGsonAdapter()); + INSTANCE.registerTypeAdapter(WxMaVisitDistribution.class, new WxMaVisitDistributionGsonAdapter()); + INSTANCE.registerTypeAdapter(WxMaRetainInfo.class, new WxMaRetainInfoGsonAdapter()); + INSTANCE.registerTypeAdapter(WxMaUserPortrait.class, new WxMaUserPortraitGsonAdapter()); } public static Gson create() { diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaRetainInfoGsonAdapter.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaRetainInfoGsonAdapter.java new file mode 100644 index 0000000000..a51972b4bd --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaRetainInfoGsonAdapter.java @@ -0,0 +1,52 @@ +package cn.binarywang.wx.miniapp.util.json; + +import cn.binarywang.wx.miniapp.bean.analysis.WxMaRetainInfo; +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import me.chanjar.weixin.common.util.json.GsonHelper; + +import java.lang.reflect.Type; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author Charming + * @since 2018-04-28 + */ +public class WxMaRetainInfoGsonAdapter implements JsonDeserializer { + @Override + public WxMaRetainInfo deserialize(JsonElement json, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + if (json == null) { + return null; + } + + WxMaRetainInfo retainInfo = new WxMaRetainInfo(); + JsonObject object = json.getAsJsonObject(); + String refDate = GsonHelper.getString(object, "ref_date"); + retainInfo.setRefDate(refDate); + retainInfo.setVisitUvNew(getAsMap(object, "visit_uv_new")); + retainInfo.setVisitUv(getAsMap(object, "visit_uv")); + return retainInfo; + } + + private Map getAsMap(JsonObject object, String memberName) { + JsonArray array = object.getAsJsonArray(memberName); + if (array != null && array.size() > 0) { + Map map = new LinkedHashMap<>(array.size()); + for (JsonElement element : array) { + JsonObject elementObject = element.getAsJsonObject(); + Integer key = GsonHelper.getInteger(elementObject, "key"); + if (key != null) { + Integer value = GsonHelper.getInteger(elementObject, "value"); + map.put(key, value); + } + } + return map; + } + return null; + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaUserPortraitGsonAdapter.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaUserPortraitGsonAdapter.java new file mode 100644 index 0000000000..b8a7c448ff --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaUserPortraitGsonAdapter.java @@ -0,0 +1,67 @@ +package cn.binarywang.wx.miniapp.util.json; + +import cn.binarywang.wx.miniapp.bean.analysis.WxMaUserPortrait; +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import me.chanjar.weixin.common.util.json.GsonHelper; +import org.apache.commons.lang3.StringUtils; + +import java.lang.reflect.Type; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author Charming + * @since 2018-04-28 + */ +public class WxMaUserPortraitGsonAdapter implements JsonDeserializer { + @Override + public WxMaUserPortrait deserialize(JsonElement json, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + if (json == null) { + return null; + } + + WxMaUserPortrait portrait = new WxMaUserPortrait(); + JsonObject object = json.getAsJsonObject(); + String refDate = GsonHelper.getString(object, "ref_date"); + portrait.setRefDate(refDate); + portrait.setVisitUvNew(getPortraitItem(object.getAsJsonObject("visit_uv_new"))); + portrait.setVisitUv(getPortraitItem(object.getAsJsonObject("visit_uv"))); + return portrait; + } + + private WxMaUserPortrait.Item getPortraitItem(JsonObject object) { + if (object == null) { + return null; + } + WxMaUserPortrait.Item item = new WxMaUserPortrait.Item(); + item.setProvince(getAsMap(object, "province")); + item.setCity(getAsMap(object, "city")); + item.setGenders(getAsMap(object, "genders")); + item.setPlatforms(getAsMap(object, "platforms")); + item.setDevices(getAsMap(object, "devices")); + item.setAges(getAsMap(object, "ages")); + return item; + } + + private Map getAsMap(JsonObject object, String memberName) { + JsonArray array = object.getAsJsonArray(memberName); + if (array != null && array.size() > 0) { + Map map = new LinkedHashMap<>(array.size()); + for (JsonElement element : array) { + JsonObject elementObject = element.getAsJsonObject(); + String name = GsonHelper.getString(elementObject, "name"); + if (StringUtils.isNotBlank(name)) { + Long value = GsonHelper.getLong(elementObject, "value"); + map.put(name, value); + } + } + return map; + } + return null; + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaVisitDistributionGsonAdapter.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaVisitDistributionGsonAdapter.java new file mode 100644 index 0000000000..45bdbac0ff --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/json/WxMaVisitDistributionGsonAdapter.java @@ -0,0 +1,67 @@ +package cn.binarywang.wx.miniapp.util.json; + +import cn.binarywang.wx.miniapp.bean.analysis.WxMaVisitDistribution; +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import me.chanjar.weixin.common.util.json.GsonHelper; + +import java.lang.reflect.Type; +import java.util.Hashtable; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author Charming + * @since 2018-04-28 + */ +public class WxMaVisitDistributionGsonAdapter implements JsonDeserializer { + @Override + public WxMaVisitDistribution deserialize(JsonElement json, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + if (json == null) { + return null; + } + + WxMaVisitDistribution distribution = new WxMaVisitDistribution(); + JsonObject object = json.getAsJsonObject(); + String refDate = GsonHelper.getString(object, "ref_date"); + distribution.setRefDate(refDate); + + boolean hasList = object.has("list"); + if (!hasList) { + return distribution; + } + + JsonArray listArray = object.getAsJsonArray("list"); + Map > list = new Hashtable<>(listArray.size()); + for (JsonElement indexElement : listArray) { + JsonObject indexObject = indexElement.getAsJsonObject(); + String index = GsonHelper.getString(indexObject, "index"); + if (index == null) { + continue; + } + + Map itemList = new LinkedHashMap<>(); + JsonArray itemArray = indexObject.getAsJsonArray("item_list"); + if (itemArray == null || itemArray.size() <= 0) { + list.put(index, itemList); + continue; + } + + for (JsonElement itemElement : itemArray) { + JsonObject itemObject = itemElement.getAsJsonObject(); + Integer key = GsonHelper.getInteger(itemObject, "key"); + Integer value = GsonHelper.getInteger(itemObject, "value"); + if (key != null) { + itemList.put(key, value); + } + } + list.put(index, itemList); + } + distribution.setList(list); + return distribution; + } +} 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 500b173a87..95b09713a3 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 @@ -60,7 +60,6 @@ public 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)); diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaAnalysisServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaAnalysisServiceImplTest.java new file mode 100644 index 0000000000..9c1c2f00e5 --- /dev/null +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaAnalysisServiceImplTest.java @@ -0,0 +1,155 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaAnalysisService; +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaRetainInfo; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaSummaryTrend; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaUserPortrait; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaVisitDistribution; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaVisitPage; +import cn.binarywang.wx.miniapp.bean.analysis.WxMaVisitTrend; +import cn.binarywang.wx.miniapp.test.ApiTestModule; +import com.google.inject.Inject; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.apache.commons.lang3.time.DateUtils; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import static org.testng.Assert.*; + +/** + * @author Charming + * @since 2018-04-28 + */ +@Guice(modules = ApiTestModule.class) +public class WxMaAnalysisServiceImplTest { + @Inject + private WxMaService wxMaService; + + @Test + public void testGetDailySummaryTrend() throws Exception { + final WxMaAnalysisService service = wxMaService.getAnalysisService(); + Date twoDaysAgo = DateUtils.addDays(new Date(), -2); + List trends = service.getDailySummaryTrend(twoDaysAgo, twoDaysAgo); + assertEquals(1, trends.size()); + System.out.println(trends); + } + + @Test + public void testGetDailyVisitTrend() throws Exception { + final WxMaAnalysisService service = wxMaService.getAnalysisService(); + Date twoDaysAgo = DateUtils.addDays(new Date(), -2); + List trends = service.getDailyVisitTrend(twoDaysAgo, twoDaysAgo); + assertEquals(1, trends.size()); + System.out.println(trends); + } + + @Test + public void testGetWeeklyVisitTrend() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); + Date now = new Date(); + Date lastSunday = calendar.getTime(); + if (DateUtils.isSameDay(lastSunday, now)) { + lastSunday = DateUtils.addDays(lastSunday, -7); + } + Date lastMonday = DateUtils.addDays(lastSunday, -6); + + final WxMaAnalysisService service = wxMaService.getAnalysisService(); + List trends = service.getWeeklyVisitTrend(lastMonday, lastSunday); + assertEquals(1, trends.size()); + System.out.println(trends); + } + + @Test + public void testGetMonthlyVisitTrend() throws Exception { + Date now = new Date(); + Date firstDayOfThisMonth = DateUtils.setDays(now, 1); + Date lastDayOfLastMonth = DateUtils.addDays(firstDayOfThisMonth, -1); + Date firstDayOfLastMonth = DateUtils.addMonths(firstDayOfThisMonth, -1); + + final WxMaAnalysisService service = wxMaService.getAnalysisService(); + List trends = service.getMonthlyVisitTrend(firstDayOfLastMonth, lastDayOfLastMonth); + assertEquals(1, trends.size()); + System.out.println(trends); + } + + @Test + public void testGetVisitDistribution() throws Exception { + final WxMaAnalysisService service = wxMaService.getAnalysisService(); + Date twoDaysAgo = DateUtils.addDays(new Date(), -2); + WxMaVisitDistribution distribution = service.getVisitDistribution(twoDaysAgo, twoDaysAgo); + assertNotNull(distribution); + String date = DateFormatUtils.format(twoDaysAgo, "yyyyMMdd"); + assertEquals(date, distribution.getRefDate()); + assertTrue(distribution.getList().containsKey("access_source_session_cnt")); + assertTrue(distribution.getList().containsKey("access_staytime_info")); + assertTrue(distribution.getList().containsKey("access_depth_info")); + System.out.println(distribution); + } + + @Test + public void testGetDailyRetainInfo() throws Exception { + final WxMaAnalysisService service = wxMaService.getAnalysisService(); + Date twoDaysAgo = DateUtils.addDays(new Date(), -2); + WxMaRetainInfo retainInfo = service.getDailyRetainInfo(twoDaysAgo, twoDaysAgo); + assertNotNull(retainInfo); + System.out.println(retainInfo); + } + + @Test + public void testGetWeeklyRetainInfo() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); + Date now = new Date(); + Date lastSunday = calendar.getTime(); + if (DateUtils.isSameDay(lastSunday, now)) { + lastSunday = DateUtils.addDays(lastSunday, -7); + } + Date lastMonday = DateUtils.addDays(lastSunday, -6); + + final WxMaAnalysisService service = wxMaService.getAnalysisService(); + WxMaRetainInfo retainInfo = service.getWeeklyRetainInfo(lastMonday, lastSunday); + assertNotNull(retainInfo); + System.out.println(retainInfo); + } + + @Test + public void testGetMonthlyRetainInfo() throws Exception { + Date now = new Date(); + Date firstDayOfThisMonth = DateUtils.setDays(now, 1); + Date lastDayOfLastMonth = DateUtils.addDays(firstDayOfThisMonth, -1); + Date firstDayOfLastMonth = DateUtils.addMonths(firstDayOfThisMonth, -1); + + final WxMaAnalysisService service = wxMaService.getAnalysisService(); + WxMaRetainInfo retainInfo = service.getMonthlyRetainInfo(firstDayOfLastMonth, lastDayOfLastMonth); + assertNotNull(retainInfo); + System.out.println(retainInfo); + } + + @Test + public void testGetVisitPage() throws Exception { + final WxMaAnalysisService service = wxMaService.getAnalysisService(); + Date twoDaysAgo = DateUtils.addDays(new Date(), -2); + List visitPages = service.getVisitPage(twoDaysAgo, twoDaysAgo); + assertNotNull(visitPages); + System.out.println(visitPages); + System.out.println(visitPages.get(0).getPagePath()); + System.out.println(visitPages.get(0).getPageVisitPv()); + } + + @Test + public void testGetUserPortrait() throws Exception { + Date twoDaysAgo = DateUtils.addDays(new Date(), -2); + Date eightDaysAgo = DateUtils.addDays(new Date(), -8); + + final WxMaAnalysisService service = wxMaService.getAnalysisService(); + WxMaUserPortrait portrait = service.getUserPortrait(eightDaysAgo, twoDaysAgo); + assertNotNull(portrait); + System.out.println(portrait); + } +} diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaCodeServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaCodeServiceImplTest.java new file mode 100644 index 0000000000..34c788993b --- /dev/null +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaCodeServiceImplTest.java @@ -0,0 +1,156 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaCodeService; +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.bean.code.WxMaCategory; +import cn.binarywang.wx.miniapp.bean.code.WxMaCodeAuditStatus; +import cn.binarywang.wx.miniapp.bean.code.WxMaCodeCommitRequest; +import cn.binarywang.wx.miniapp.bean.code.WxMaCodeExtConfig; +import cn.binarywang.wx.miniapp.bean.code.WxMaCodeSubmitAuditRequest; +import cn.binarywang.wx.miniapp.bean.code.WxMaCodeVersionDistribution; +import cn.binarywang.wx.miniapp.config.WxMaConfig; +import cn.binarywang.wx.miniapp.test.ApiTestModule; +import com.google.inject.Inject; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +/** + * @author Charming + * @since 2018-04-26 20:18 + */ +@Test +@Guice(modules = ApiTestModule.class) +public class WxMaCodeServiceImplTest { + @Inject + private WxMaService wxService; + @Inject + private WxMaConfig wxMaConfig; + + @Test + public void testGetCategory() throws Exception { + List categories = wxService.getCodeService().getCategory(); + System.out.println(String.valueOf(categories)); + } + + @Test + public void testCommit() throws Exception { + String themeColor = "#0074d9"; + String themeFontColor = "#ffffff"; + + Map ext = new HashMap<>(); + ext.put("appName", "xxx"); + ext.put("verified", true); + ext.put("navigationBarBackgroundColor", themeColor); + ext.put("navigationBarTextStyle", themeFontColor); + ext.put("companyId", 4128); + ext.put("companyFullName", "xxx有限公司"); + + WxMaCodeService wxMaCodeService = wxService.getCodeService(); + WxMaCodeCommitRequest commitRequest = WxMaCodeCommitRequest + .builder() + .templateId(6L) + .userVersion("v0.1.0") + .userDesc("init") + .extConfig(WxMaCodeExtConfig.builder() + .extAppid(wxMaConfig.getAppid()) + .extEnable(true) + .ext(ext) + .window( + WxMaCodeExtConfig.PageConfig + .builder() + .navigationBarBackgroundColor(themeColor) + .navigationBarTextStyle(themeFontColor) + .build() + ) + .build()) + .build(); + wxMaCodeService.commit(commitRequest); + } + + @Test + public void testGetQrCode() throws Exception { + byte[] qrCode = wxService.getCodeService().getQrCode(); + assertTrue(qrCode.length > 0); + } + + @Test + public void testGetPage() throws Exception { + List pageList = wxService.getCodeService().getPage(); + System.out.println(String.valueOf(pageList)); + } + + @Test + public void testSubmitAudit() throws Exception { + WxMaCodeSubmitAuditRequest auditRequest = WxMaCodeSubmitAuditRequest + .builder() + .itemList(Arrays.asList( + WxMaCategory + .builder() + .address("pages/logs/logs") + .tag("工具 效率") + .firstClass("工具") + .firstId(287L) + .secondClass("效率") + .secondId(616L) + .title("日志") + .build() + )).build(); + long auditId = wxService.getCodeService().submitAudit(auditRequest); + assertTrue(auditId > 0); + // 421937937 + System.out.println(auditId); + } + + @Test + public void testGetAuditStatus() throws Exception { + WxMaCodeAuditStatus auditStatus = wxService.getCodeService().getAuditStatus(421937937L); + System.out.println(auditStatus); + assertNotNull(auditStatus); + } + + @Test + public void testGetLatestAuditStatus() throws Exception { + WxMaCodeAuditStatus auditStatus = wxService.getCodeService().getLatestAuditStatus(); + System.out.println(auditStatus); + assertNotNull(auditStatus); + } + + @Test + public void testRelease() throws Exception { + wxService.getCodeService().release(); + } + + @Test + public void testChangeVisitStatus() throws Exception { + wxService.getCodeService().changeVisitStatus("open"); + } + + @Test + public void testRevertCodeRelease() throws Exception { + wxService.getCodeService().revertCodeRelease(); + } + + @Test + public void testGetSupportVersion() throws Exception { + WxMaCodeVersionDistribution distribution = wxService.getCodeService().getSupportVersion(); + System.out.println(distribution); + } + + @Test + public void testSetSupportVersion() throws Exception { + wxService.getCodeService().setSupportVersion("1.2.0"); + } + + @Test + public void testUndoCodeAudit() throws Exception { + + } +} diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaMediaServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaMediaServiceImplTest.java index 825ad05f76..6c9420be0e 100644 --- a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaMediaServiceImplTest.java +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaMediaServiceImplTest.java @@ -4,7 +4,7 @@ import cn.binarywang.wx.miniapp.test.ApiTestModule; import com.google.inject.Inject; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import org.testng.annotations.Guice; import org.testng.annotations.Test; 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 8ad7a72837..d05c031e83 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 @@ -7,7 +7,7 @@ import cn.binarywang.wx.miniapp.test.TestConfig; import com.google.common.collect.Lists; import com.google.inject.Inject; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import org.testng.annotations.*; import java.text.SimpleDateFormat; diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImplTest.java index eba65f7c34..ae2e8d8fed 100644 --- a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImplTest.java +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImplTest.java @@ -1,12 +1,12 @@ package cn.binarywang.wx.miniapp.api.impl; +import java.io.File; + +import org.testng.annotations.*; + import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.test.ApiTestModule; import com.google.inject.Inject; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; - -import java.io.File; /** * @author Binary Wang @@ -15,7 +15,7 @@ @Guice(modules = ApiTestModule.class) public class WxMaQrcodeServiceImplTest { @Inject - protected WxMaService wxService; + private WxMaService wxService; @Test public void testCreateQrCode() throws Exception { @@ -24,14 +24,14 @@ public void testCreateQrCode() throws Exception { } @Test - public void testCreateWxCode() throws Exception { - final File wxCode = this.wxService.getQrcodeService().createWxCode("111", 122); + public void testCreateWxaCode() throws Exception { + final File wxCode = this.wxService.getQrcodeService().createWxaCode("111", 122); System.out.println(wxCode); } @Test - public void testCreateWxCodeLimit() throws Exception { - final File wxCode = this.wxService.getQrcodeService().createWxCodeLimit("111", null); + public void testCreateWxaCodeUnlimit() throws Exception { + final File wxCode = this.wxService.getQrcodeService().createWxaCodeUnlimit("111", null); System.out.println(wxCode); } diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImplTest.java index 1c99530d36..1d7ec2f3ee 100644 --- a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImplTest.java +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImplTest.java @@ -4,7 +4,7 @@ import cn.binarywang.wx.miniapp.config.WxMaConfig; import cn.binarywang.wx.miniapp.test.ApiTestModule; import com.google.inject.Inject; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import org.apache.commons.lang3.StringUtils; import org.testng.annotations.Guice; import org.testng.annotations.Test; diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaSettingServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaSettingServiceImplTest.java new file mode 100644 index 0000000000..8da5f19208 --- /dev/null +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaSettingServiceImplTest.java @@ -0,0 +1,54 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.bean.WxMaDomainAction; +import cn.binarywang.wx.miniapp.test.ApiTestModule; +import com.google.inject.Inject; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertNotNull; + +/** + * @author Charming + * @since 2018-04-27 15:38 + */ +@Test +@Guice(modules = ApiTestModule.class) +public class WxMaSettingServiceImplTest { + @Inject + private WxMaService wxService; + + @Test + public void testModifyDomain() throws Exception { + WxMaDomainAction domainAction = wxService.getSettingService().modifyDomain(WxMaDomainAction + .builder() + .action("get") + .build()); + System.out.println(domainAction); + assertNotNull(domainAction); + + domainAction.setAction("set"); + WxMaDomainAction result = wxService.getSettingService().modifyDomain(domainAction); + System.out.println(result); + } + + @Test + public void testBindTester() throws Exception { + wxService.getSettingService().bindTester("WeChatId"); + } + + @Test + public void testUnbindTester() throws Exception { + wxService.getSettingService().unbindTester("WeChatId"); + } + + @Test + public void testSetWebViewDomain() throws Exception { + WxMaDomainAction domainAction = wxService.getSettingService().setWebViewDomain(WxMaDomainAction + .builder() + .action("get") + .build()); + System.out.println(domainAction); + } +} 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 d32dfca7fd..6486c3237f 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 @@ -53,5 +53,17 @@ public void testMaPageBuilder() { "\"miniprogrampage\":{\"title\":\"title\",\"pagepath\":\"pagePath\",\"thumb_media_id\":\"thumbMediaId\"}}"); } + public void testURLEscaped() { + WxMaKefuMessage reply = WxMaKefuMessage.newLinkBuilder() + .toUser("OPENID") + .url("https://mp.weixin.qq.com/s?__biz=MzI0MDA2OTY5NQ==") + .description("description") + .title("title") + .thumbUrl("thumbUrl") + .build(); + assertThat(reply.toJson()) + .isEqualTo( "{\"touser\":\"OPENID\",\"msgtype\":\"link\"," + + "\"link\":{\"title\":\"title\",\"description\":\"description\",\"url\":\"https://mp.weixin.qq.com/s?__biz=MzI0MDA2OTY5NQ==\",\"thumb_url\":\"thumbUrl\"}}"); + } } 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 fa7d3ebb92..26855b36ef 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 @@ -12,118 +12,39 @@ public class WxMaMessageTest { public void testFromXml() { - String xml = " " - + " "; + String xml = "" - + " " - + " 1348831860 " - + "" - + " " - + " 1234567890123456 " - + "" - + " " - + " " - + " " - + " 23.134521 " - + "113.358803 " - + "20 " - + "" - + "" - + " " - + " " - + " " - + " " - + " " - + " 23.137466 " - + "113.352425 " - + "119.385040 " - + "" - + " " - + "" - + " " - + " " - + " " - + "1 \n" - + "" - + " " - + "- " - + "
" - + "" - + " " - + " " - + "\n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" + + " "; WxMaMessage wxMessage = WxMaMessage.fromXml(xml); assertEquals(wxMessage.getToUser(), "toUser"); assertEquals(wxMessage.getFromUser(), "fromUser"); - assertEquals(wxMessage.getCreateTime(), new Long(1348831860L)); + assertEquals(wxMessage.getCreateTime(),new Integer(1482048670)); 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"); assertEquals(wxMessage.getMediaId(), "media_id"); - assertEquals(wxMessage.getEvent(), "subscribe"); - } - - public void testFromXml2() { - - String xml = "\n" + + " \n" + + " 1482048670 \n" + + "\n" + + " \n" + + " 1234567890123456 \n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " " - + " "; - WxMaMessage wxMessage = WxMaMessage.fromXml(xml); - assertEquals(wxMessage.getToUser(), "toUser"); - assertEquals(wxMessage.getFromUser(), "fromUser"); - assertEquals(wxMessage.getCreateTime(), new Integer(1348831860)); - 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"); - assertEquals(wxMessage.getMediaId(), "media_id"); - assertEquals(wxMessage.getEvent(), "subscribe"); + assertEquals(wxMessage.getTitle(), "Title"); + assertEquals(wxMessage.getPagePath(), "PagePath"); + assertEquals(wxMessage.getThumbUrl(), "ThumbUrl"); + assertEquals(wxMessage.getThumbMediaId(), "ThumbMediaId"); + assertEquals(wxMessage.getAppId(), "AppId"); + assertEquals(wxMessage.getEvent(), "user_enter_tempsession"); + assertEquals(wxMessage.getSessionFrom(), "sessionFrom"); } } diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaRetainInfoTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaRetainInfoTest.java new file mode 100644 index 0000000000..c2fd925e09 --- /dev/null +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaRetainInfoTest.java @@ -0,0 +1,22 @@ +package cn.binarywang.wx.miniapp.bean.analysis; + +import org.testng.annotations.Test; + +import static org.testng.Assert.*; + +/** + * @author Charming + * @since 2018-04-28 + */ +public class WxMaRetainInfoTest { + @Test + public void testFromJson() throws Exception { + String json = "{\"ref_date\":\"20170313\",\"visit_uv_new\":[{\"key\":0,\"value\":5464}],\"visit_uv\":[{\"key\":0,\"value\":55500}]}\n"; + WxMaRetainInfo retainInfo = WxMaRetainInfo.fromJson(json); + assertNotNull(retainInfo); + assertEquals("20170313", retainInfo.getRefDate()); + assertTrue(retainInfo.getVisitUv().containsKey(0)); + assertTrue(retainInfo.getVisitUvNew().containsKey(0)); + System.out.println(retainInfo); + } +} diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaUserPortraitTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaUserPortraitTest.java new file mode 100644 index 0000000000..87239bb599 --- /dev/null +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaUserPortraitTest.java @@ -0,0 +1,19 @@ +package cn.binarywang.wx.miniapp.bean.analysis; + +import org.testng.annotations.Test; + +import static org.testng.Assert.assertNotNull; + +/** + * @author Charming + * @since 2018-04-28 + */ +public class WxMaUserPortraitTest { + @Test + public void testFromJson() throws Exception { + String json = "{\"ref_date\":\"20170611\",\"visit_uv_new\":{\"province\":[{\"id\":31,\"name\":\"广东省\",\"value\":215}],\"city\":[{\"id\":3102,\"name\":\"广州\",\"value\":78}],\"genders\":[{\"id\":1,\"name\":\"男\",\"value\":2146}],\"platforms\":[{\"id\":1,\"name\":\"iPhone\",\"value\":27642}],\"devices\":[{\"name\":\"OPPO R9\",\"value\":61}],\"ages\":[{\"id\":1,\"name\":\"17岁以下\",\"value\":151}]},\"visit_uv\":{\"province\":[{\"id\":31,\"name\":\"广东省\",\"value\":1341}],\"city\":[{\"id\":3102,\"name\":\"广州\",\"value\":234}],\"genders\":[{\"id\":1,\"name\":\"男\",\"value\":14534}],\"platforms\":[{\"id\":1,\"name\":\"iPhone\",\"value\":21750}],\"devices\":[{\"name\":\"OPPO R9\",\"value\":617}],\"ages\":[{\"id\":1,\"name\":\"17岁以下\",\"value\":3156}]}}\n"; + WxMaUserPortrait portrait = WxMaUserPortrait.fromJson(json); + System.out.println(portrait); + assertNotNull(portrait); + } +} diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaVisitDistributionTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaVisitDistributionTest.java new file mode 100644 index 0000000000..2b01b3aad7 --- /dev/null +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/analysis/WxMaVisitDistributionTest.java @@ -0,0 +1,23 @@ +package cn.binarywang.wx.miniapp.bean.analysis; + +import org.testng.annotations.Test; + +import static org.testng.Assert.*; + +/** + * @author Charming + * @since 2018-04-28 + */ +public class WxMaVisitDistributionTest { + @Test + public void testFromJson() throws Exception { + String json = "{\"ref_date\":\"20170313\",\"list\":[{\"index\":\"access_source_session_cnt\",\"item_list\":[{\"key\":10,\"value\":5},{\"key\":8,\"value\":687},{\"key\":7,\"value\":10740},{\"key\":6,\"value\":1961},{\"key\":5,\"value\":677},{\"key\":4,\"value\":653},{\"key\":3,\"value\":1120},{\"key\":2,\"value\":10243},{\"key\":1,\"value\":116578}]},{\"index\":\"access_staytime_info\",\"item_list\":[{\"key\":8,\"value\":16329},{\"key\":7,\"value\":19322},{\"key\":6,\"value\":21832},{\"key\":5,\"value\":19539},{\"key\":4,\"value\":29670},{\"key\":3,\"value\":19667},{\"key\":2,\"value\":11794},{\"key\":1,\"value\":4511}]},{\"index\":\"access_depth_info\",\"item_list\":[{\"key\":5,\"value\":217},{\"key\":4,\"value\":3259},{\"key\":3,\"value\":32445},{\"key\":2,\"value\":63542},{\"key\":1,\"value\":43201}]}]}\n"; + WxMaVisitDistribution distribution = WxMaVisitDistribution.fromJson(json); + assertNotNull(distribution); + assertEquals("20170313", distribution.getRefDate()); + assertTrue(distribution.getList().containsKey("access_source_session_cnt")); + assertTrue(distribution.getList().containsKey("access_staytime_info")); + assertTrue(distribution.getList().containsKey("access_depth_info")); + System.out.println(distribution); + } +} diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeCommitRequestTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeCommitRequestTest.java new file mode 100644 index 0000000000..36cf1c4840 --- /dev/null +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeCommitRequestTest.java @@ -0,0 +1,25 @@ +package cn.binarywang.wx.miniapp.bean.code; + +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + +/** + * @author Charming + * @since 2018-04-26 19:54 + */ +public class WxMaCodeCommitRequestTest { + @Test + public void testToJson() { + WxMaCodeCommitRequest commitRequest = WxMaCodeCommitRequest.builder() + .templateId(1L) + .userVersion("v0.1.0") + .userDesc("init") + .extConfig(WxMaCodeExtConfig.builder() + .extAppid("app123") + .extEnable(true) + .build()) + .build(); + assertEquals(commitRequest.toJson(), "{\"template_id\":1,\"user_version\":\"v0.1.0\",\"user_desc\":\"init\",\"ext_json\":\"{\\\"extEnable\\\":true,\\\"extAppid\\\":\\\"app123\\\"}\"}"); + } +} diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeSubmitAuditRequestTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeSubmitAuditRequestTest.java new file mode 100644 index 0000000000..1f962087dc --- /dev/null +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeSubmitAuditRequestTest.java @@ -0,0 +1,30 @@ +package cn.binarywang.wx.miniapp.bean.code; + +import org.testng.annotations.Test; + +import java.util.Arrays; + +/** + * @author Charming + * @since 2018-04-26 19:55 + */ +public class WxMaCodeSubmitAuditRequestTest { + @Test + public void testToJson() { + WxMaCodeSubmitAuditRequest request = WxMaCodeSubmitAuditRequest + .builder() + .itemList(Arrays.asList( + WxMaCategory + .builder() + .address("pages/logs/logs") + .tag("工具 效率") + .firstClass("工具") + .firstId(287L) + .secondClass("效率") + .secondId(616L) + .title("日志") + .build() + )).build(); + System.out.println(request.toJson()); + } +} diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeVersionDistributionTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeVersionDistributionTest.java new file mode 100644 index 0000000000..da02972e04 --- /dev/null +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeVersionDistributionTest.java @@ -0,0 +1,15 @@ +package cn.binarywang.wx.miniapp.bean.code; + +import org.testng.annotations.Test; + +/** + * @author Charming + * @since 2018-04-26 19:58 + */ +public class WxMaCodeVersionDistributionTest { + @Test + public void testFromJson() { + String json = "{\"errcode\":0,\"errmsg\":\"ok\",\"now_version\":\"1.2.0\",\"uv_info\":{\"items\":[{\"version\":\"0.0.0\",\"percentage\":0},{\"version\":\"1.0.0\",\"percentage\":0},{\"version\":\"1.0.1\",\"percentage\":0},{\"version\":\"1.1.0\",\"percentage\":0},{\"version\":\"1.1.1\",\"percentage\":0},{\"version\":\"1.2.0\",\"percentage\":0},{\"version\":\"1.2.1\",\"percentage\":0},{\"version\":\"1.2.2\",\"percentage\":0},{\"version\":\"1.2.3\",\"percentage\":0},{\"version\":\"1.2.4\",\"percentage\":0},{\"version\":\"1.2.5\",\"percentage\":0},{\"version\":\"1.2.6\",\"percentage\":0},{\"version\":\"1.3.0\",\"percentage\":0},{\"version\":\"1.4.0\",\"percentage\":0},{\"version\":\"1.4.1\",\"percentage\":0},{\"version\":\"1.4.2\",\"percentage\":0},{\"version\":\"1.4.3\",\"percentage\":0},{\"version\":\"1.4.4\",\"percentage\":0},{\"version\":\"1.5.0\",\"percentage\":0},{\"version\":\"1.5.1\",\"percentage\":0},{\"version\":\"1.5.2\",\"percentage\":0},{\"version\":\"1.5.3\",\"percentage\":0},{\"version\":\"1.5.4\",\"percentage\":0},{\"version\":\"1.5.5\",\"percentage\":0},{\"version\":\"1.5.6\",\"percentage\":0},{\"version\":\"1.5.7\",\"percentage\":0},{\"version\":\"1.5.8\",\"percentage\":0},{\"version\":\"1.6.0\",\"percentage\":0.0132},{\"version\":\"1.6.1\",\"percentage\":0.0132},{\"version\":\"1.6.2\",\"percentage\":0.0132},{\"version\":\"1.6.3\",\"percentage\":0.0132},{\"version\":\"1.6.4\",\"percentage\":0.0132},{\"version\":\"1.6.5\",\"percentage\":0.0132},{\"version\":\"1.6.6\",\"percentage\":0.0132},{\"version\":\"1.6.7\",\"percentage\":0.1711},{\"version\":\"1.6.8\",\"percentage\":0.1711},{\"version\":\"1.7.0\",\"percentage\":0.1842},{\"version\":\"1.7.1\",\"percentage\":0.25},{\"version\":\"1.7.2\",\"percentage\":0.5263},{\"version\":\"1.7.3\",\"percentage\":0.5263},{\"version\":\"1.7.4\",\"percentage\":0.6711}]}}\n"; + System.out.println(WxMaCodeVersionDistribution.fromJson(json)); + } +} 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 8d14b261ff..bc4b13a109 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 @@ -12,7 +12,7 @@ import cn.binarywang.wx.miniapp.test.TestConfig; import com.google.common.collect.Lists; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.session.WxSessionManager; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/test/ApiTestModule.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/test/ApiTestModule.java index 3b569e1b89..267eb70ca3 100644 --- a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/test/ApiTestModule.java +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/test/ApiTestModule.java @@ -1,22 +1,30 @@ package cn.binarywang.wx.miniapp.test; +import java.io.IOException; +import java.io.InputStream; +import java.util.concurrent.locks.ReentrantLock; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.config.WxMaConfig; import com.google.inject.Binder; import com.google.inject.Module; -import java.io.IOException; -import java.io.InputStream; -import java.util.concurrent.locks.ReentrantLock; - /** * @author Binary Wang */ public class ApiTestModule implements Module { + private final Logger log = LoggerFactory.getLogger(this.getClass()); + private static final String TEST_CONFIG_XML = "test-config.xml"; @Override public void configure(Binder binder) { - try (InputStream inputStream = ClassLoader.getSystemResourceAsStream("test-config.xml")) { + try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(TEST_CONFIG_XML)) { + if (inputStream == null) { + throw new RuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成"); + } TestConfig config = TestConfig.fromXml(inputStream); config.setAccessTokenLock(new ReentrantLock()); @@ -26,7 +34,7 @@ public void configure(Binder binder) { binder.bind(WxMaService.class).toInstance(wxService); binder.bind(WxMaConfig.class).toInstance(config); } catch (IOException e) { - e.printStackTrace(); + this.log.error(e.getMessage(), e); } } diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index fc141836f4..fbffe94d37 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -7,7 +7,7 @@" - + " " - + " 1348831860 " - + "" - + " " - + " 1234567890123456 " - + "" - + " " - + " " - + " " - + " 23.134521 " - + "113.358803 " - + "20 " - + "" - + "" - + " " - + " " - + " " - + " " - + " " - + " 23.137466 " - + "113.352425 " - + "119.385040 " - + "" - + " " - + "" - + " " - + " " - + " " - + "1 \n" - + "" - + " " - + "- " - + "
" - + "" - + " " - + " " - + "\n" - + " \n" - + " \n" - + " \n" - + " \n" - + " com.github.binarywang weixin-java-parent -3.0.0 +3.1.0 weixin-java-mp Weixin Java Tools - MP diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/AiLangType.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/AiLangType.java new file mode 100644 index 0000000000..54b61b1e51 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/AiLangType.java @@ -0,0 +1,29 @@ +package me.chanjar.weixin.mp; + +import lombok.Getter; + +/** + *+ * AI开放接口里的语言类型,目前只支持两种:中文和英文 + * Created by BinaryWang on 2018/6/10. + *+ * + * @author Binary Wang + */ +@Getter +public enum AiLangType { + /** + * 中文 汉语 + */ + zh_CN("zh_CN"), + /** + * 英文 英语 + */ + en_US("en_US"); + + private String code; + + AiLangType(String code) { + this.code = code; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpAiOpenService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpAiOpenService.java new file mode 100644 index 0000000000..1e9c8e02f8 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpAiOpenService.java @@ -0,0 +1,97 @@ +package me.chanjar.weixin.mp.api; + +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.mp.AiLangType; + +import java.io.File; + +/** + *+ * 微信AI开放接口(语音识别,微信翻译). + * https://mp.weixin.qq.com/wiki?t=resource/res_main&id=21516712282KzWVE + * Created by BinaryWang on 2018/6/9. + *+ * + * @author Binary Wang + */ +public interface WxMpAiOpenService { + String VOICE_UPLOAD_URL = "http://api.weixin.qq.com/cgi-bin/media/voice/addvoicetorecofortext?format=%s&voice_id=%s&lang=%s"; + String VOICE_QUERY_RESULT_URL = "http://api.weixin.qq.com/cgi-bin/media/voice/queryrecoresultfortext"; + + /** + *+ * 提交语音. + * 接口调用请求说明 + * + * http请求方式: POST + * http://api.weixin.qq.com/cgi-bin/media/voice/addvoicetorecofortext?access_token=ACCESS_TOKEN&format=&voice_id=xxxxxx&lang=zh_CN + * 参数说明 + * + * 参数 是否必须 说明 + * access_token 是 接口调用凭证 + * format 是 文件格式 (只支持mp3,16k,单声道,最大1M) + * voice_id 是 语音唯一标识 + * lang 否 语言,zh_CN 或 en_US,默认中文 + * 语音内容放body里或者上传文件的形式 + *+ * + * @param lang 语言,zh_CN 或 en_US,默认中文 + * @param voiceFile 语音文件 + * @param voiceId 语音唯一标识 + */ + void uploadVoice(String voiceId, AiLangType lang, File voiceFile) throws WxErrorException; + + /** + *+ * 获取语音识别结果. + * 接口调用请求说明 + * + * http请求方式: POST + * http://api.weixin.qq.com/cgi-bin/media/voice/queryrecoresultfortext?access_token=ACCESS_TOKEN&voice_id=xxxxxx&lang=zh_CN + * 请注意,添加完文件之后10s内调用这个接口 + * + * 参数说明 + * + * 参数 是否必须 说明 + * access_token 是 接口调用凭证 + * voice_id 是 语音唯一标识 + * lang 否 语言,zh_CN 或 en_US,默认中文 + *+ * + * @param lang 语言,zh_CN 或 en_US,默认中文 + * @param voiceId 语音唯一标识 + */ + String queryRecognitionResult(String voiceId, AiLangType lang) throws WxErrorException; + + /** + * 识别指定语音文件内容. + * 此方法揉合了前两两个方法:uploadVoice 和 queryRecognitionResult + * + * @param lang 语言,zh_CN 或 en_US,默认中文 + * @param voiceFile 语音文件 + * @param voiceId 语音唯一标识 + */ + String recogniseVoice(String voiceId, AiLangType lang, File voiceFile) throws WxErrorException; + + /** + *+ * 微信翻译. + * 接口调用请求说明 + * + * http请求方式: POST + * http://api.weixin.qq.com/cgi-bin/media/voice/translatecontent?access_token=ACCESS_TOKEN&lfrom=xxx<o=xxx + * 参数说明 + * + * 参数 是否必须 说明 + * access_token 是 接口调用凭证 + * lfrom 是 源语言,zh_CN 或 en_US + * lto 是 目标语言,zh_CN 或 en_US + * 源内容放body里或者上传文件的形式(utf8格式,最大600Byte) + *+ * + * @param langFrom 源语言,zh_CN 或 en_US + * @param langTo 目标语言,zh_CN 或 en_US + * @param content 要翻译的文本内容 + */ + String translate(AiLangType langFrom, AiLangType langTo, String content) throws WxErrorException; +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCardService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCardService.java index 08ea9a7007..9545709a7d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCardService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCardService.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.api; import me.chanjar.weixin.common.bean.WxCardApiSignature; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.bean.result.WxMpCardResult; /** diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpDataCubeService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpDataCubeService.java index 7610b03d3a..fecceea444 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpDataCubeService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpDataCubeService.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.bean.datacube.*; import java.util.Date; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpDeviceService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpDeviceService.java index 6b3fcd9e39..8a0fb6a58e 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpDeviceService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpDeviceService.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.bean.device.*; /** 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 9e0de39c4b..e5c2735037 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 @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; import me.chanjar.weixin.mp.bean.kefu.result.*; 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 669dfd7db1..f3e8db9d10 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 @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.bean.*; import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMaterialService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMaterialService.java index 05ca87eab7..50490dbbf4 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMaterialService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMaterialService.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.api; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.bean.material.*; import java.io.File; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMemberCardService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMemberCardService.java index 7cebb8c858..9c022034f5 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMemberCardService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMemberCardService.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardActivatedMessage; import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUpdateMessage; import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUpdateResult; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java index bfd606175c..f0fe549575 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.api; import me.chanjar.weixin.common.bean.menu.WxMenu; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult; import me.chanjar.weixin.mp.bean.menu.WxMpMenu; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageHandler.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageHandler.java index 5a336bc8d9..474e3e6950 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageHandler.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageHandler.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageInterceptor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageInterceptor.java index 15223895b9..f377b036d1 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageInterceptor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageInterceptor.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; 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 9cf43b770c..8350593aa2 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 @@ -75,6 +75,29 @@ public WxMpMessageRouter(WxMpService wxMpService) { this.exceptionHandler = new LogExceptionHandler(); } + /** + *+ * 使用自定义的 {@link ExecutorService} + *+ */ + public WxMpMessageRouter(WxMpService wxMpService, ExecutorService executorService) { + this.wxMpService = wxMpService; + this.executorService = executorService; + this.messageDuplicateChecker = new WxMessageInMemoryDuplicateChecker(); + this.sessionManager = new StandardSessionManager(); + this.exceptionHandler = new LogExceptionHandler(); + } + + /** + *+ * 如果使用默认的 {@link ExecutorService},则系统退出前,应该调用该方法。 + *+ */ + public void shutDownExecutorService() { + this.executorService.shutdown(); + } + + /** ** 设置自定义的 {@link ExecutorService} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouterRule.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouterRule.java index 50e30af6b7..ad11e81b41 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouterRule.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouterRule.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.api; import me.chanjar.weixin.common.api.WxErrorExceptionHandler; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java index 37ed7dcd12..131ebf6341 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; import java.io.File; 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 5cbce57083..c4212affc2 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 @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.api; import me.chanjar.weixin.common.bean.WxJsapiSignature; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; @@ -58,7 +58,7 @@ public interface WxMpService { /** * oauth2授权的url连接 */ - 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#wechat_redirect"; + 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&connect_redirect=1#wechat_redirect"; /** * 获取公众号的自动回复规则 @@ -408,6 +408,20 @@ public interface WxMpService { */ WxMpMassMessageService getMassMessageService(); + /** + * 返回AI开放接口方法的实现类对象,以方便调用其各个接口 + * + * @return WxMpAiOpenService + */ + WxMpAiOpenService getAiOpenService(); + + /** + * 返回WIFI接口方法的实现类对象,以方便调用其各个接口 + * + * @return WxMpWifiService + */ + WxMpWifiService getWifiService(); + void setKefuService(WxMpKefuService kefuService); void setMaterialService(WxMpMaterialService materialService); @@ -437,4 +451,6 @@ public interface WxMpService { void setMemberCardService(WxMpMemberCardService memberCardService); void setMassMessageService(WxMpMassMessageService massMessageService); + + void setAiOpenService(WxMpAiOpenService aiOpenService); } 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 697bfe899d..1f6c3052e7 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,7 +1,7 @@ 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.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult; import me.chanjar.weixin.mp.bean.WxMpShakeQuery; import me.chanjar.weixin.mp.bean.shake.*; 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 fa349c93b2..7b0913e688 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 @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo; import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo; import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpSubscribeMsgService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpSubscribeMsgService.java index 9e3b45e062..1e91d9a2d6 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpSubscribeMsgService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpSubscribeMsgService.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.bean.subscribe.WxMpSubscribeMessage; /** 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 494813ecae..f57c469c01 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 @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.bean.template.WxMpTemplate; import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry; import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserBlacklistService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserBlacklistService.java index d93384f005..e7e2fd84fc 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserBlacklistService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserBlacklistService.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; import java.util.List; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserService.java index e207e5efc3..7523a9f39e 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserService.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.bean.WxMpUserQuery; import me.chanjar.weixin.mp.bean.result.WxMpUser; import me.chanjar.weixin.mp.bean.result.WxMpUserList; 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 ce218922c3..031585053e 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 @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.bean.tag.WxTagListUser; import me.chanjar.weixin.mp.bean.tag.WxUserTag; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpWifiService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpWifiService.java new file mode 100644 index 0000000000..9cda53bbb5 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpWifiService.java @@ -0,0 +1,28 @@ +package me.chanjar.weixin.mp.api; + +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopListResult; + +/** + *+ * 微信连接WI-FI接口. + * Created by BinaryWang on 2018/6/10. + *+ * + * @author Binary Wang + */ +public interface WxMpWifiService { + /** + *+ * 获取Wi-Fi门店列表. + * 通过此接口获取WiFi的门店列表,该列表包括公众平台的门店信息、以及添加设备后的WiFi相关信息。创建门店方法请参考“微信门店接口”。 + * 注:微信连Wi-Fi下的所有接口中的shop_id,必需先通过此接口获取。 + * + * http请求方式: POST + * 请求URL:https://api.weixin.qq.com/bizwifi/shop/list?access_token=ACCESS_TOKEN + *+ * @param pageIndex 分页下标,默认从1开始 + * @param pageSize 每页的个数,默认10个,最大20个 + */ + WxMpWifiShopListResult listShop(int pageIndex, int pageSize) throws WxErrorException; +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceBaseImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java similarity index 94% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceBaseImpl.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java index 0800f0a9b5..09d21bacff 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceBaseImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java @@ -5,10 +5,11 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import me.chanjar.weixin.common.bean.WxJsapiSignature; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.session.StandardSessionManager; import me.chanjar.weixin.common.session.WxSessionManager; +import me.chanjar.weixin.common.util.DataUtils; import me.chanjar.weixin.common.util.RandomUtils; import me.chanjar.weixin.common.util.crypto.SHA1; import me.chanjar.weixin.common.util.http.*; @@ -25,11 +26,14 @@ import java.io.IOException; import java.util.concurrent.locks.Lock; -public abstract class WxMpServiceBaseImplimplements WxMpService, RequestHttp { - +/** + * @author someone + */ +public abstract class BaseWxMpServiceImpl implements WxMpService, RequestHttp { private static final JsonParser JSON_PARSER = new JsonParser(); protected final Logger log = LoggerFactory.getLogger(this.getClass()); + protected WxSessionManager sessionManager = new StandardSessionManager(); protected WxMpConfigStorage wxMpConfigStorage; private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this); @@ -48,6 +52,8 @@ public abstract class WxMpServiceBaseImpl implements WxMpService, RequestH private WxMpShakeService shakeService = new WxMpShakeServiceImpl(this); private WxMpMemberCardService memberCardService = new WxMpMemberCardServiceImpl(this); private WxMpMassMessageService massMessageService = new WxMpMassMessageServiceImpl(this); + private WxMpAiOpenService aiOpenService = new WxMpAiOpenServiceImpl(this); + private WxMpWifiService wifiService = new WxMpWifiServiceImpl(this); private int retrySleepMillis = 1000; private int maxRetryTimes = 5; @@ -265,6 +271,8 @@ public T execute(RequestExecutor executor, String uri, E data) thro } public T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException { + E dataForLog = DataUtils.handleDataWithSecret(data); + if (uri.contains("access_token=")) { throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri); } @@ -275,7 +283,7 @@ public T executeInternal(RequestExecutor executor, String uri, E da try { T result = executor.execute(uriWithAccessToken, data); - this.log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, data, result); + this.log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, dataForLog, result); return result; } catch (WxErrorException e) { WxError error = e.getError(); @@ -294,12 +302,12 @@ public T executeInternal(RequestExecutor executor, String uri, E da } if (error.getErrorCode() != 0) { - this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, data, error); + this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, dataForLog, error); throw new WxErrorException(error, e); } return null; } catch (IOException e) { - this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, data, e.getMessage()); + this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage()); throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e); } } @@ -484,4 +492,19 @@ public void setMemberCardService(WxMpMemberCardService memberCardService) { public void setMassMessageService(WxMpMassMessageService massMessageService) { this.massMessageService = massMessageService; } + + @Override + public WxMpAiOpenService getAiOpenService() { + return this.aiOpenService; + } + + @Override + public void setAiOpenService(WxMpAiOpenService aiOpenService) { + this.aiOpenService = aiOpenService; + } + + @Override + public WxMpWifiService getWifiService() { + return this.wifiService; + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpAiOpenServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpAiOpenServiceImpl.java new file mode 100644 index 0000000000..f492e4670d --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpAiOpenServiceImpl.java @@ -0,0 +1,76 @@ +package me.chanjar.weixin.mp.api.impl; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.mp.AiLangType; +import me.chanjar.weixin.mp.api.WxMpAiOpenService; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.util.requestexecuter.voice.VoiceUploadRequestExecutor; + +import java.io.File; + +/** + * + * Created by BinaryWang on 2018/6/9. + *+ * + * @author Binary Wang + */ +public class WxMpAiOpenServiceImpl implements WxMpAiOpenService { + + private static final JsonParser JSON_PARSER = new JsonParser(); + public static final String TRANSLATE_URL = "http://api.weixin.qq.com/cgi-bin/media/voice/translatecontent?lfrom=%s<o=%s"; + private WxMpService wxMpService; + + public WxMpAiOpenServiceImpl(WxMpService wxMpService) { + this.wxMpService = wxMpService; + } + + @Override + public void uploadVoice(String voiceId, AiLangType lang, File voiceFile) throws WxErrorException { + if (lang == null) { + lang = AiLangType.zh_CN; + } + + this.wxMpService.execute(VoiceUploadRequestExecutor.create(this.wxMpService.getRequestHttp()), + String.format(VOICE_UPLOAD_URL, "mp3", voiceId, lang.getCode()), + voiceFile); + } + + @Override + public String recogniseVoice(String voiceId, AiLangType lang, File voiceFile) throws WxErrorException { + this.uploadVoice(voiceId, lang, voiceFile); + return this.queryRecognitionResult(voiceId, lang); + } + + @Override + public String translate(AiLangType langFrom, AiLangType langTo, String content) throws WxErrorException { + final String responseContent = this.wxMpService.post(String.format(TRANSLATE_URL, langFrom.getCode(), langTo.getCode()), + content); + final JsonObject jsonObject = new JsonParser().parse(responseContent).getAsJsonObject(); + if (jsonObject.get("errcode") == null || jsonObject.get("errcode").getAsInt() == 0) { + return jsonObject.get("to_content").getAsString(); + } + + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP)); + } + + @Override + public String queryRecognitionResult(String voiceId, AiLangType lang) throws WxErrorException { + if (lang == null) { + lang = AiLangType.zh_CN; + } + + final String responseContent = this.wxMpService.get(VOICE_QUERY_RESULT_URL, + String.format("voice_id=%s&lang=%s", voiceId, lang.getCode())); + final JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject(); + if (jsonObject.get("errcode") == null || jsonObject.get("errcode").getAsInt() == 0) { + return jsonObject.get("result").getAsString(); + } + + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP)); + } +} 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 9a1d470b9a..c3a75f6401 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 @@ -6,8 +6,8 @@ import com.google.gson.JsonPrimitive; import com.google.gson.reflect.TypeToken; import me.chanjar.weixin.common.bean.WxCardApiSignature; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.RandomUtils; import me.chanjar.weixin.common.util.crypto.SHA1; import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java index 25bd3cfaab..bf60892a1b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.api.impl; import com.google.gson.JsonObject; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpDataCubeService; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.datacube.*; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImpl.java index 284c0a2966..3fe464a89e 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImpl.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.api.impl; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpDeviceService; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.device.*; 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 6bda9e5caf..604ce8327e 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 @@ -1,9 +1,9 @@ package me.chanjar.weixin.mp.api.impl; import com.google.gson.JsonObject; -import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; import me.chanjar.weixin.mp.api.WxMpKefuService; import me.chanjar.weixin.mp.api.WxMpService; 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 266f79edcb..31aa043e93 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 @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.api.impl; import com.google.gson.JsonObject; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpMassMessageService; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.*; 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 67e9c37a04..5c539b5b6d 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 @@ -1,9 +1,10 @@ package me.chanjar.weixin.mp.api.impl; +import me.chanjar.weixin.common.WxType; import me.chanjar.weixin.common.api.WxConsts; -import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor; import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; @@ -11,7 +12,8 @@ import me.chanjar.weixin.mp.api.WxMpMaterialService; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.material.*; -import me.chanjar.weixin.mp.util.http.*; +import me.chanjar.weixin.mp.util.requestexecuter.material.*; +import me.chanjar.weixin.mp.util.requestexecuter.media.MediaImgUploadRequestExecutor; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.File; @@ -100,7 +102,7 @@ public WxMpMaterialNews materialNewsInfo(String mediaId) throws WxErrorException @Override public boolean materialNewsUpdate(WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate) throws WxErrorException { String responseText = this.wxMpService.post(NEWS_UPDATE_URL, wxMpMaterialArticleUpdate.toJson()); - WxError wxError = WxError.fromJson(responseText); + WxError wxError = WxError.fromJson(responseText, WxType.MP); if (wxError.getErrorCode() == 0) { return true; } else { @@ -116,7 +118,7 @@ public boolean materialDelete(String mediaId) throws WxErrorException { @Override public WxMpMaterialCountResult materialCount() throws WxErrorException { String responseText = this.wxMpService.get(MATERIAL_GET_COUNT_URL, null); - WxError wxError = WxError.fromJson(responseText); + WxError wxError = WxError.fromJson(responseText, WxType.MP); if (wxError.getErrorCode() == 0) { return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialCountResult.class); } else { @@ -131,7 +133,7 @@ public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(int offset, int count params.put("offset", offset); params.put("count", count); String responseText = this.wxMpService.post(MATERIAL_BATCHGET_URL, WxGsonBuilder.create().toJson(params)); - WxError wxError = WxError.fromJson(responseText); + WxError wxError = WxError.fromJson(responseText, WxType.MP); if (wxError.getErrorCode() == 0) { return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialNewsBatchGetResult.class); } else { @@ -146,7 +148,7 @@ public WxMpMaterialFileBatchGetResult materialFileBatchGet(String type, int offs params.put("offset", offset); params.put("count", count); String responseText = this.wxMpService.post(MATERIAL_BATCHGET_URL, WxGsonBuilder.create().toJson(params)); - WxError wxError = WxError.fromJson(responseText); + WxError wxError = WxError.fromJson(responseText, WxType.MP); if (wxError.getErrorCode() == 0) { return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialFileBatchGetResult.class); } else { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMemberCardServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMemberCardServiceImpl.java index b3a43a765a..8eb09cc1ee 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMemberCardServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMemberCardServiceImpl.java @@ -5,7 +5,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.reflect.TypeToken; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpMemberCardService; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardActivatedMessage; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java index d22f4c82e2..e8dc84766b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java @@ -3,7 +3,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import me.chanjar.weixin.common.bean.menu.WxMenu; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpMenuService; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult; 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 f6af96e5f8..5783ce7991 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 @@ -1,12 +1,12 @@ package me.chanjar.weixin.mp.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.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpQrcodeService; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; -import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor; +import me.chanjar.weixin.mp.util.requestexecuter.qrcode.QrCodeRequestExecutor; import org.apache.commons.lang3.StringUtils; import java.io.File; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceHttpClientImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceHttpClientImpl.java index 9a357ba509..3db9e9b149 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceHttpClientImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceHttpClientImpl.java @@ -1,8 +1,9 @@ package me.chanjar.weixin.mp.api.impl; +import me.chanjar.weixin.common.WxType; import me.chanjar.weixin.common.bean.WxAccessToken; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.HttpType; import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder; import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder; @@ -21,7 +22,7 @@ /** * apache http client方式实现. */ -public class WxMpServiceHttpClientImpl extends WxMpServiceBaseImpl{ +public class WxMpServiceHttpClientImpl extends BaseWxMpServiceImpl { private CloseableHttpClient httpClient; private HttpHost httpProxy; @@ -76,7 +77,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException { } try (CloseableHttpResponse response = getRequestHttpClient().execute(httpGet)) { String resultContent = new BasicResponseHandler().handleResponse(response); - WxError error = WxError.fromJson(resultContent); + WxError error = WxError.fromJson(resultContent, WxType.MP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceJoddHttpImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceJoddHttpImpl.java index fc4976bee5..ee8411ab73 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceJoddHttpImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceJoddHttpImpl.java @@ -2,9 +2,10 @@ import jodd.http.*; import jodd.http.net.SocketHttpConnectionProvider; +import me.chanjar.weixin.common.WxType; import me.chanjar.weixin.common.bean.WxAccessToken; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.HttpType; import me.chanjar.weixin.mp.api.WxMpConfigStorage; import me.chanjar.weixin.mp.api.WxMpService; @@ -14,7 +15,7 @@ /** * jodd-http方式实现 */ -public class WxMpServiceJoddHttpImpl extends WxMpServiceBaseImpl { +public class WxMpServiceJoddHttpImpl extends BaseWxMpServiceImpl { private HttpConnectionProvider httpClient; private ProxyInfo httpProxy; @@ -65,7 +66,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException { } HttpResponse response = request.send(); String resultContent = response.bodyText(); - WxError error = WxError.fromJson(resultContent); + WxError error = WxError.fromJson(resultContent, WxType.MP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } 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 e099924163..6d3f5bf29a 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 @@ -1,8 +1,9 @@ package me.chanjar.weixin.mp.api.impl; +import me.chanjar.weixin.common.WxType; import me.chanjar.weixin.common.bean.WxAccessToken; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.HttpType; import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo; import me.chanjar.weixin.mp.api.WxMpService; @@ -14,7 +15,7 @@ /** * okhttp实现 */ -public class WxMpServiceOkHttpImpl extends WxMpServiceBaseImpl { +public class WxMpServiceOkHttpImpl extends BaseWxMpServiceImpl { private OkHttpClient httpClient; private OkHttpProxyInfo httpProxy; @@ -47,7 +48,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException { Request request = new Request.Builder().url(url).get().build(); Response response = getRequestHttpClient().newCall(request).execute(); String resultContent = response.body().string(); - WxError error = WxError.fromJson(resultContent); + WxError error = WxError.fromJson(resultContent, WxType.MP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } 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 2c90f70e2b..6f6beda5ab 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,7 +1,8 @@ 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.common.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpShakeService; import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult; @@ -53,7 +54,7 @@ public WxError deviceBindPageQuery(WxMpShakeAroundDeviceBindPageQuery shakeAroun 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); + return WxError.fromJson(responseContent, WxType.MP); } @Override 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 00c0c1097c..402102064c 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 @@ -3,8 +3,9 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.reflect.TypeToken; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.BeanUtils; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpStoreService; @@ -32,7 +33,7 @@ public void add(WxMpStoreBaseInfo request) throws WxErrorException { BeanUtils.checkRequiredFields(request); String response = this.wxMpService.post(POI_ADD_URL, request.toJson()); - WxError wxError = WxError.fromJson(response); + WxError wxError = WxError.fromJson(response, WxType.MP); if (wxError.getErrorCode() != 0) { throw new WxErrorException(wxError); } @@ -43,7 +44,7 @@ public WxMpStoreBaseInfo get(String poiId) throws WxErrorException { JsonObject paramObject = new JsonObject(); paramObject.addProperty("poi_id", poiId); String response = this.wxMpService.post(POI_GET_URL, paramObject.toString()); - WxError wxError = WxError.fromJson(response); + WxError wxError = WxError.fromJson(response, WxType.MP); if (wxError.getErrorCode() != 0) { throw new WxErrorException(wxError); } @@ -56,7 +57,7 @@ public void delete(String poiId) throws WxErrorException { JsonObject paramObject = new JsonObject(); paramObject.addProperty("poi_id", poiId); String response = this.wxMpService.post(POI_DEL_URL, paramObject.toString()); - WxError wxError = WxError.fromJson(response); + WxError wxError = WxError.fromJson(response, WxType.MP); if (wxError.getErrorCode() != 0) { throw new WxErrorException(wxError); } @@ -70,7 +71,7 @@ public WxMpStoreListResult list(int begin, int limit) params.addProperty("limit", limit); String response = this.wxMpService.post(POI_LIST_URL, params.toString()); - WxError wxError = WxError.fromJson(response); + WxError wxError = WxError.fromJson(response, WxType.MP); if (wxError.getErrorCode() != 0) { throw new WxErrorException(wxError); } @@ -102,7 +103,7 @@ public List listAll() throws WxErrorException { @Override public void update(WxMpStoreBaseInfo request) throws WxErrorException { String response = this.wxMpService.post(POI_UPDATE_URL, request.toJson()); - WxError wxError = WxError.fromJson(response); + WxError wxError = WxError.fromJson(response, WxType.MP); if (wxError.getErrorCode() != 0) { throw new WxErrorException(wxError); } @@ -111,7 +112,7 @@ public void update(WxMpStoreBaseInfo request) throws WxErrorException { @Override public List listCategories() throws WxErrorException { String response = this.wxMpService.get(POI_GET_WX_CATEGORY_URL, null); - WxError wxError = WxError.fromJson(response); + WxError wxError = WxError.fromJson(response, WxType.MP); if (wxError.getErrorCode() != 0) { throw new WxErrorException(wxError); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpSubscribeMsgServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpSubscribeMsgServiceImpl.java index 4cf17bd2c9..fe1cfb306c 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpSubscribeMsgServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpSubscribeMsgServiceImpl.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.api.impl; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.URIUtil; import me.chanjar.weixin.mp.api.WxMpConfigStorage; import me.chanjar.weixin.mp.api.WxMpService; 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 7b73f102d6..472cd0fe8c 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 @@ -2,8 +2,9 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpTemplateMsgService; import me.chanjar.weixin.mp.bean.template.WxMpTemplate; @@ -37,7 +38,7 @@ public String sendTemplateMsg(WxMpTemplateMessage templateMessage) throws WxErro if (jsonObject.get("errcode").getAsInt() == 0) { return jsonObject.get("msgid").getAsString(); } - throw new WxErrorException(WxError.fromJson(responseContent)); + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP)); } @Override @@ -70,7 +71,7 @@ public String addTemplate(String shortTemplateId) throws WxErrorException { return result.get("template_id").getAsString(); } - throw new WxErrorException(WxError.fromJson(responseContent)); + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP)); } @Override @@ -85,7 +86,7 @@ public boolean delPrivateTemplate(String templateId) throws WxErrorException { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("template_id", templateId); String responseContent = this.wxMpService.post(url, jsonObject.toString()); - WxError error = WxError.fromJson(responseContent); + WxError error = WxError.fromJson(responseContent, WxType.MP); if (error.getErrorCode() == 0) { return true; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImpl.java index 4e3f78140a..561d7c04f1 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImpl.java @@ -2,7 +2,7 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpUserBlacklistService; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java index ba74f0e4a7..def801e4e9 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.api.impl; import com.google.gson.JsonObject; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpUserService; import me.chanjar.weixin.mp.bean.WxMpUserQuery; 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 e5357b1ed7..6a37741b84 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 @@ -4,8 +4,9 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.reflect.TypeToken; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpUserTagService; import me.chanjar.weixin.mp.bean.tag.WxTagListUser; @@ -60,7 +61,7 @@ public Boolean tagUpdate(Long id, String name) throws WxErrorException { json.add("tag", tagJson); String responseContent = this.wxMpService.post(url, json.toString()); - WxError wxError = WxError.fromJson(responseContent); + WxError wxError = WxError.fromJson(responseContent, WxType.MP); if (wxError.getErrorCode() == 0) { return true; } @@ -78,7 +79,7 @@ public Boolean tagDelete(Long id) throws WxErrorException { json.add("tag", tagJson); String responseContent = this.wxMpService.post(url, json.toString()); - WxError wxError = WxError.fromJson(responseContent); + WxError wxError = WxError.fromJson(responseContent, WxType.MP); if (wxError.getErrorCode() == 0) { return true; } @@ -113,7 +114,7 @@ public boolean batchTagging(Long tagId, String[] openids) json.add("openid_list", openidArrayJson); String responseContent = this.wxMpService.post(url, json.toString()); - WxError wxError = WxError.fromJson(responseContent); + WxError wxError = WxError.fromJson(responseContent, WxType.MP); if (wxError.getErrorCode() == 0) { return true; } @@ -135,7 +136,7 @@ public boolean batchUntagging(Long tagId, String[] openids) json.add("openid_list", openidArrayJson); String responseContent = this.wxMpService.post(url, json.toString()); - WxError wxError = WxError.fromJson(responseContent); + WxError wxError = WxError.fromJson(responseContent, WxType.MP); if (wxError.getErrorCode() == 0) { return true; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpWifiServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpWifiServiceImpl.java new file mode 100644 index 0000000000..f87c784b89 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpWifiServiceImpl.java @@ -0,0 +1,31 @@ +package me.chanjar.weixin.mp.api.impl; + +import com.google.gson.JsonObject; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.WxMpWifiService; +import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopListResult; + +/** + * + * Created by BinaryWang on 2018/6/10. + *+ * + * @author Binary Wang + */ +public class WxMpWifiServiceImpl implements WxMpWifiService { + private WxMpService wxMpService; + + public WxMpWifiServiceImpl(WxMpService wxMpService) { + this.wxMpService = wxMpService; + } + + @Override + public WxMpWifiShopListResult listShop(int pageIndex, int pageSize) throws WxErrorException { + JsonObject json = new JsonObject(); + json.addProperty("pageindex", pageIndex); + json.addProperty("pagesize", pageSize); + final String result = this.wxMpService.post("https://api.weixin.qq.com/bizwifi/shop/list", json.toString()); + return WxMpWifiShopListResult.fromJson(result); + } +} 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 7f480e3fa4..742b016590 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 @@ -41,6 +41,11 @@ public class WxMpMassOpenIdsMessage implements Serializable { */ private boolean sendIgnoreReprint = false; + /** + * 开发者侧群发msgid,长度限制64字节,如不填,则后台默认以群发范围和群发内容的摘要值做为clientmsgid + */ + private String clientMsgId; + public WxMpMassOpenIdsMessage() { super(); } 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 5bcd408441..9487124c86 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 @@ -38,11 +38,17 @@ public class WxMpMassTagMessage implements Serializable { * 是否群发给所有用户 */ private boolean isSendAll = false; + /** * 文章被判定为转载时,是否继续进行群发操作。 */ private boolean sendIgnoreReprint = false; + /** + * 开发者侧群发msgid,长度限制64字节,如不填,则后台默认以群发范围和群发内容的摘要值做为clientmsgid + */ + private String clientMsgId; + public WxMpMassTagMessage() { super(); } 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 97b40920ea..2b24325211 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 @@ -30,6 +30,8 @@ public class WxMpKefuMessage implements Serializable { private String kfAccount; private String cardId; private String mpNewsMediaId; + private String miniProgramAppId; + private String miniProgramPagePath; private Listarticles = new ArrayList<>(); /** @@ -88,6 +90,13 @@ public static WxCardBuilder WXCARD() { return new WxCardBuilder(); } + /** + * 小程序卡片 + */ + public static MiniProgramPageBuilder MINIPROGRAMPAGE() { + return new MiniProgramPageBuilder(); + } + /** * * 请使用 @@ -99,6 +108,7 @@ public static WxCardBuilder WXCARD() { * {@link WxConsts.KefuMsgType#NEWS} * {@link WxConsts.KefuMsgType#MPNEWS} * {@link WxConsts.KefuMsgType#WXCARD} + * {@link WxConsts.KefuMsgType#MINIPROGRAMPAGE} ** */ 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 6cd9ca0630..5d9c6bce28 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 @@ -1,5 +1,9 @@ package me.chanjar.weixin.mp.bean.result; +import java.io.Serializable; +import java.lang.reflect.Type; +import java.util.List; + import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; @@ -7,10 +11,6 @@ import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; -import java.io.Serializable; -import java.lang.reflect.Type; -import java.util.List; - /** * 微信用户信息. * @@ -56,6 +56,23 @@ public class WxMpUser implements Serializable { */ private String[] privileges; + /** + * subscribe_scene 返回用户关注的渠道来源. + * ADD_SCENE_SEARCH 公众号搜索,ADD_SCENE_ACCOUNT_MIGRATION 公众号迁移,ADD_SCENE_PROFILE_CARD 名片分享,ADD_SCENE_QR_CODE 扫描二维码,ADD_SCENEPROFILE LINK 图文页内名称点击,ADD_SCENE_PROFILE_ITEM 图文页右上角菜单,ADD_SCENE_PAID 支付后关注,ADD_SCENE_OTHERS 其他 + */ + private String subscribeScene; + + /** + * qr_scene 二维码扫码场景(开发者自定义). + */ + private String qrScene; + + /** + * qr_scene_str 二维码扫码场景描述(开发者自定义). + */ + private String qrSceneStr; + + public static WxMpUser fromJson(String json) { return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpUser.class); } 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 a7ef1802de..a66dbc07a8 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 @@ -55,7 +55,7 @@ public class WxMpTemplateMessage implements Serializable { /** * 模板数据. */ - private Listdata; + private List data = new ArrayList<>(); public WxMpTemplateMessage addData(WxMpTemplateData datum) { if (this.data == null) { @@ -76,7 +76,7 @@ public static class MiniProgram implements Serializable { private static final long serialVersionUID = -7945254706501974849L; private String appid; - private String path; + private String pagePath; } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/wifi/WxMpWifiShopListResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/wifi/WxMpWifiShopListResult.java new file mode 100644 index 0000000000..69947aefcd --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/wifi/WxMpWifiShopListResult.java @@ -0,0 +1,90 @@ +package me.chanjar.weixin.mp.bean.wifi; + +import com.google.gson.JsonParser; +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; + +import java.util.List; + +/** + * + * Created by BinaryWang on 2018/6/10. + *+ * + * @author Binary Wang + */ +@Data +public class WxMpWifiShopListResult { + public static WxMpWifiShopListResult fromJson(String json) { + return WxMpGsonBuilder.create().fromJson( + new JsonParser().parse(json).getAsJsonObject().get("data"), + WxMpWifiShopListResult.class); + } + + /** + * 总数 + */ + @SerializedName("totalcount") + private int totalCount; + + /** + * 分页下标 + */ + @SerializedName("pageindex") + private int pageIndex; + + /** + * 分页页数 + */ + @SerializedName("pagecount") + private int pageCount; + + private Listrecords; + + @Data + public static class Record { + + /** + * 门店ID(适用于微信连Wi-Fi业务) + */ + @SerializedName("shop_id") + private Integer shopId; + + /** + * 门店名称 + */ + @SerializedName("shop_name") + private String shopName; + + /** + * 无线网络设备的ssid,未添加设备为空,多个ssid时显示第一个 + */ + @SerializedName("ssid") + private String ssid; + + /** + * 无线网络设备的ssid列表,返回数组格式 + */ + @SerializedName("ssid_list") + private List ssidList; + + /** + * 门店内设备的设备类型,0-未添加设备,1-专业型设备,4-密码型设备,5-portal自助型设备,31-portal改造型设备 + */ + @SerializedName("protocol_type") + private Integer protocolType; + + /** + * 商户自己的id,与门店poi_id对应关系,建议在添加门店时候建立关联关系,具体请参考“微信门店接口” + */ + @SerializedName("sid") + private String sid; + + /** + * 门店ID(适用于微信卡券、微信门店业务),具体定义参考微信门店,与shop_id一一对应 + */ + @SerializedName("poi_id") + private String poiId; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/MiniProgramPageBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/MiniProgramPageBuilder.java new file mode 100644 index 0000000000..0aedbae9c6 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/MiniProgramPageBuilder.java @@ -0,0 +1,61 @@ +package me.chanjar.weixin.mp.builder.kefu; + +import me.chanjar.weixin.common.api.WxConsts.KefuMsgType; +import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; + +/** + * 小程序卡片 builder + * + * 用法: + * WxMpKefuMessage m = WxMpKefuMessage.MINIPROGRAMPAGE().title("xxxx").thumbMediaId("xxxxx").appId("xxxx").pagePath("****").toUser(...).build(); + *+ * + * @author boris.bao + */ +public final class MiniProgramPageBuilder extends BaseBuilder{ + + private String title; + private String appId; + private String pagePath; + private String thumbMediaId; + + public MiniProgramPageBuilder() { + this.msgType = KefuMsgType.MINIPROGRAMPAGE; + } + + + public MiniProgramPageBuilder title(String title) { + this.title = title; + return this; + } + + public MiniProgramPageBuilder appId(String appId) { + this.appId = appId; + return this; + } + + + public MiniProgramPageBuilder pagePath(String pagePath) { + this.pagePath = pagePath; + return this; + } + + + public MiniProgramPageBuilder thumbMediaId(String thumbMediaId) { + this.thumbMediaId = thumbMediaId; + return this; + } + + + @Override + public WxMpKefuMessage build() { + WxMpKefuMessage m = super.build(); + m.setTitle(this.title); + m.setMiniProgramAppId(this.appId); + m.setMiniProgramPagePath(this.pagePath); + m.setThumbMediaId(this.thumbMediaId); + return m; + } + + +} 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 fc44ee4df3..63389866f3 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 @@ -2,6 +2,7 @@ import com.google.gson.*; import me.chanjar.weixin.common.api.WxConsts; +import me.chanjar.weixin.common.api.WxConsts.KefuMsgType; import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; import org.apache.commons.lang3.StringUtils; @@ -79,6 +80,15 @@ public JsonElement serialize(WxMpKefuMessage message, Type typeOfSrc, JsonSerial messageJson.add("wxcard", wxcard); } + if (KefuMsgType.MINIPROGRAMPAGE.equals(message.getMsgType())) { + JsonObject miniProgramPage = new JsonObject(); + miniProgramPage.addProperty("title", message.getTitle()); + miniProgramPage.addProperty("appid", message.getMiniProgramAppId()); + miniProgramPage.addProperty("pagepath", message.getMiniProgramPagePath()); + miniProgramPage.addProperty("thumb_media_id", message.getThumbMediaId()); + messageJson.add("miniprogrampage", miniProgramPage); + } + if (StringUtils.isNotBlank(message.getKfAccount())) { JsonObject newsJsonObject = new JsonObject(); newsJsonObject.addProperty("kf_account", message.getKfAccount()); 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 3a7d3b2a00..562222fc67 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 @@ -3,9 +3,13 @@ import com.google.gson.*; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; +import org.apache.commons.lang3.StringUtils; import java.lang.reflect.Type; +/** + * @author someone + */ public class WxMpMassOpenIdsMessageGsonAdapter implements JsonSerializer { @Override @@ -45,6 +49,11 @@ public JsonElement serialize(WxMpMassOpenIdsMessage message, Type typeOfSrc, Jso } messageJson.addProperty("msgtype", message.getMsgType()); messageJson.addProperty("send_ignore_reprint", message.isSendIgnoreReprint() ? 0 : 1); + + if(StringUtils.isNotEmpty(message.getClientMsgId())){ + messageJson.addProperty("clientmsgid", message.getClientMsgId()); + } + return messageJson; } 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 f432c91919..3d8f58ffa9 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 @@ -6,9 +6,13 @@ import com.google.gson.JsonSerializer; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; +import org.apache.commons.lang3.StringUtils; import java.lang.reflect.Type; +/** + * @author someone + */ public class WxMpMassTagMessageGsonAdapter implements JsonSerializer { @Override @@ -51,6 +55,11 @@ public JsonElement serialize(WxMpMassTagMessage message, Type typeOfSrc, JsonSer } messageJson.addProperty("msgtype", message.getMsgType()); messageJson.addProperty("send_ignore_reprint", message.isSendIgnoreReprint() ? 0 : 1); + + if (StringUtils.isNotEmpty(message.getClientMsgId())) { + messageJson.addProperty("clientmsgid", message.getClientMsgId()); + } + return messageJson; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpTemplateMessageGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpTemplateMessageGsonAdapter.java index f79cd4ca87..6bb5d2c5fc 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpTemplateMessageGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpTemplateMessageGsonAdapter.java @@ -23,7 +23,7 @@ public JsonElement serialize(WxMpTemplateMessage message, Type typeOfSrc, JsonSe if (message.getMiniProgram() != null) { JsonObject miniProgramJson = new JsonObject(); miniProgramJson.addProperty("appid", message.getMiniProgram().getAppid()); - miniProgramJson.addProperty("path", message.getMiniProgram().getPath()); + miniProgramJson.addProperty("pagepath", message.getMiniProgram().getPagePath()); messageJson.add("miniprogram", miniProgramJson); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserGsonAdapter.java index 956fda8bff..910ae8c89f 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserGsonAdapter.java @@ -33,6 +33,9 @@ public WxMpUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationC user.setGroupId(GsonHelper.getInteger(o, "groupid")); user.setTagIds(GsonHelper.getLongArray(o, "tagid_list")); user.setPrivileges(GsonHelper.getStringArray(o, "privilege")); + user.setSubscribeScene(GsonHelper.getString(o, "subscribe_scene")); + user.setQrScene(GsonHelper.getString(o, "qr_scene")); + user.setQrSceneStr(GsonHelper.getString(o, "qr_scene_str")); Integer sex = GsonHelper.getInteger(o, "sex"); if (sex != null) { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialDeleteRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialDeleteApacheHttpRequestExecutor.java similarity index 76% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialDeleteRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialDeleteApacheHttpRequestExecutor.java index be0991d3a2..b64093252d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialDeleteRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialDeleteApacheHttpRequestExecutor.java @@ -1,11 +1,11 @@ -package me.chanjar.weixin.mp.util.http.apache; +package me.chanjar.weixin.mp.util.requestexecuter.material; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; import me.chanjar.weixin.common.util.json.WxGsonBuilder; -import me.chanjar.weixin.mp.util.http.MaterialDeleteRequestExecutor; import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; @@ -20,8 +20,8 @@ /** * Created by ecoolper on 2017/5/5. */ -public class ApacheMaterialDeleteRequestExecutor extends MaterialDeleteRequestExecutor { - public ApacheMaterialDeleteRequestExecutor(RequestHttp requestHttp) { +public class MaterialDeleteApacheHttpRequestExecutor extends MaterialDeleteRequestExecutor { + public MaterialDeleteApacheHttpRequestExecutor(RequestHttp requestHttp) { super(requestHttp); } @@ -38,7 +38,7 @@ public Boolean execute(String uri, String materialId) throws WxErrorException, I httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params))); try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) { String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); - WxError error = WxError.fromJson(responseContent); + WxError error = WxError.fromJson(responseContent, WxType.MP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } else { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialDeleteRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialDeleteJoddHttpRequestExecutor.java similarity index 67% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialDeleteRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialDeleteJoddHttpRequestExecutor.java index 0344e1cddc..f1ffdd6bf5 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialDeleteRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialDeleteJoddHttpRequestExecutor.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.mp.util.http.jodd; +package me.chanjar.weixin.mp.util.requestexecuter.material; import jodd.http.HttpConnectionProvider; import jodd.http.HttpRequest; @@ -6,18 +6,18 @@ 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.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; -import me.chanjar.weixin.mp.util.http.MaterialDeleteRequestExecutor; import java.io.IOException; /** * Created by ecoolper on 2017/5/5. */ -public class JoddMaterialDeleteRequestExecutor extends MaterialDeleteRequestExecutor { - public JoddMaterialDeleteRequestExecutor(RequestHttp requestHttp) { +public class MaterialDeleteJoddHttpRequestExecutor extends MaterialDeleteRequestExecutor { + public MaterialDeleteJoddHttpRequestExecutor(RequestHttp requestHttp) { super(requestHttp); } @@ -33,7 +33,7 @@ public Boolean execute(String uri, String materialId) throws WxErrorException, I HttpResponse response = request.send(); response.charset(StringPool.UTF_8); String responseContent = response.bodyText(); - WxError error = WxError.fromJson(responseContent); + WxError error = WxError.fromJson(responseContent, WxType.MP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } else { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialDeleteRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialDeleteOkhttpRequestExecutor.java similarity index 68% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialDeleteRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialDeleteOkhttpRequestExecutor.java index 40ac27465e..1635793e95 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialDeleteRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialDeleteOkhttpRequestExecutor.java @@ -1,10 +1,10 @@ -package me.chanjar.weixin.mp.util.http.okhttp; +package me.chanjar.weixin.mp.util.requestexecuter.material; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo; -import me.chanjar.weixin.mp.util.http.MaterialDeleteRequestExecutor; import okhttp3.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,17 +14,17 @@ /** * Created by ecoolper on 2017/5/5. */ -public class OkhttpMaterialDeleteRequestExecutor extends MaterialDeleteRequestExecutor { +public class MaterialDeleteOkhttpRequestExecutor extends MaterialDeleteRequestExecutor { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - public OkhttpMaterialDeleteRequestExecutor(RequestHttp requestHttp) { + public MaterialDeleteOkhttpRequestExecutor(RequestHttp requestHttp) { super(requestHttp); } @Override public Boolean execute(String uri, String materialId) throws WxErrorException, IOException { - logger.debug("OkhttpMaterialDeleteRequestExecutor is running"); + logger.debug("MaterialDeleteOkhttpRequestExecutor is running"); //得到httpClient OkHttpClient client = requestHttp.getRequestHttpClient(); @@ -32,7 +32,7 @@ public Boolean execute(String uri, String materialId) throws WxErrorException, I Request request = new Request.Builder().url(uri).post(requestBody).build(); Response response = client.newCall(request).execute(); String responseContent = response.body().string(); - WxError error = WxError.fromJson(responseContent); + WxError error = WxError.fromJson(responseContent, WxType.MP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } else { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialDeleteRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialDeleteRequestExecutor.java similarity index 56% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialDeleteRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialDeleteRequestExecutor.java index 51b7a67764..a185b54d75 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialDeleteRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialDeleteRequestExecutor.java @@ -1,10 +1,7 @@ -package me.chanjar.weixin.mp.util.http; +package me.chanjar.weixin.mp.util.requestexecuter.material; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; -import me.chanjar.weixin.mp.util.http.apache.ApacheMaterialDeleteRequestExecutor; -import me.chanjar.weixin.mp.util.http.jodd.JoddMaterialDeleteRequestExecutor; -import me.chanjar.weixin.mp.util.http.okhttp.OkhttpMaterialDeleteRequestExecutor; public abstract class MaterialDeleteRequestExecutor implements RequestExecutor { protected RequestHttp requestHttp; @@ -16,11 +13,11 @@ public MaterialDeleteRequestExecutor(RequestHttp requestHttp) { public static RequestExecutor create(RequestHttp requestHttp) { switch (requestHttp.getRequestType()) { case APACHE_HTTP: - return new ApacheMaterialDeleteRequestExecutor(requestHttp); + return new MaterialDeleteApacheHttpRequestExecutor(requestHttp); case JODD_HTTP: - return new JoddMaterialDeleteRequestExecutor(requestHttp); + return new MaterialDeleteJoddHttpRequestExecutor(requestHttp); case OK_HTTP: - return new OkhttpMaterialDeleteRequestExecutor(requestHttp); + return new MaterialDeleteOkhttpRequestExecutor(requestHttp); default: return null; } 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/requestexecuter/material/MaterialNewsInfoApacheHttpRequestExecutor.java similarity index 81% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialNewsInfoRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialNewsInfoApacheHttpRequestExecutor.java index baab51b591..aa717c0acc 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/requestexecuter/material/MaterialNewsInfoApacheHttpRequestExecutor.java @@ -1,13 +1,13 @@ -package me.chanjar.weixin.mp.util.http.apache; +package me.chanjar.weixin.mp.util.requestexecuter.material; 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.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; 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; import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; @@ -19,8 +19,6 @@ import org.slf4j.LoggerFactory; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; /** * httpclient 实现的素材请求执行器. @@ -28,11 +26,11 @@ * @author ecoolper * @date 2017/5/5 */ -public class ApacheMaterialNewsInfoRequestExecutor +public class MaterialNewsInfoApacheHttpRequestExecutor extends MaterialNewsInfoRequestExecutor { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - public ApacheMaterialNewsInfoRequestExecutor(RequestHttp requestHttp) { + public MaterialNewsInfoApacheHttpRequestExecutor(RequestHttp requestHttp) { super(requestHttp); } @@ -48,7 +46,7 @@ public WxMpMaterialNews execute(String uri, String materialId) throws WxErrorExc try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) { String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); this.logger.debug("响应原始数据:{}", responseContent); - WxError error = WxError.fromJson(responseContent); + WxError error = WxError.fromJson(responseContent, WxType.MP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } else { 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/requestexecuter/material/MaterialNewsInfoJoddHttpRequestExecutor.java similarity index 75% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialNewsInfoRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialNewsInfoJoddHttpRequestExecutor.java index 2bce6ee4f6..d91e2afc15 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/requestexecuter/material/MaterialNewsInfoJoddHttpRequestExecutor.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.mp.util.http.jodd; +package me.chanjar.weixin.mp.util.requestexecuter.material; import com.google.common.collect.ImmutableMap; import jodd.http.HttpConnectionProvider; @@ -7,12 +7,12 @@ 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.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.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; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,9 +22,9 @@ /** * Created by ecoolper on 2017/5/5. */ -public class JoddMaterialNewsInfoRequestExecutor extends MaterialNewsInfoRequestExecutor { +public class MaterialNewsInfoJoddHttpRequestExecutor extends MaterialNewsInfoRequestExecutor { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - public JoddMaterialNewsInfoRequestExecutor(RequestHttp requestHttp) { + public MaterialNewsInfoJoddHttpRequestExecutor(RequestHttp requestHttp) { super(requestHttp); } @@ -42,7 +42,7 @@ public WxMpMaterialNews execute(String uri, String materialId) throws WxErrorExc String responseContent = response.bodyText(); this.logger.debug("响应原始数据:{}", responseContent); - WxError error = WxError.fromJson(responseContent); + WxError error = WxError.fromJson(responseContent, WxType.MP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } else { 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/requestexecuter/material/MaterialNewsInfoOkhttpRequestExecutor.java similarity index 78% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialNewsInfoRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialNewsInfoOkhttpRequestExecutor.java index e8bd9beea6..5883a05842 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/requestexecuter/material/MaterialNewsInfoOkhttpRequestExecutor.java @@ -1,13 +1,13 @@ -package me.chanjar.weixin.mp.util.http.okhttp; +package me.chanjar.weixin.mp.util.requestexecuter.material; 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.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.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; import okhttp3.*; import org.slf4j.Logger; @@ -18,9 +18,9 @@ /** * Created by ecoolper on 2017/5/5. */ -public class OkhttpMaterialNewsInfoRequestExecutor extends MaterialNewsInfoRequestExecutor { +public class MaterialNewsInfoOkhttpRequestExecutor extends MaterialNewsInfoRequestExecutor { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - public OkhttpMaterialNewsInfoRequestExecutor(RequestHttp requestHttp) { + public MaterialNewsInfoOkhttpRequestExecutor(RequestHttp requestHttp) { super(requestHttp); } @@ -38,7 +38,7 @@ public WxMpMaterialNews execute(String uri, String materialId) throws WxErrorExc String responseContent = response.body().string(); this.logger.debug("响应原始数据:{}", responseContent); - WxError error = WxError.fromJson(responseContent); + WxError error = WxError.fromJson(responseContent, WxType.MP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } else { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialNewsInfoRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialNewsInfoRequestExecutor.java similarity index 60% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialNewsInfoRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialNewsInfoRequestExecutor.java index 24c00fe75a..62ef709aca 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialNewsInfoRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialNewsInfoRequestExecutor.java @@ -1,11 +1,8 @@ -package me.chanjar.weixin.mp.util.http; +package me.chanjar.weixin.mp.util.requestexecuter.material; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; -import me.chanjar.weixin.mp.util.http.apache.ApacheMaterialNewsInfoRequestExecutor; -import me.chanjar.weixin.mp.util.http.jodd.JoddMaterialNewsInfoRequestExecutor; -import me.chanjar.weixin.mp.util.http.okhttp.OkhttpMaterialNewsInfoRequestExecutor; public abstract class MaterialNewsInfoRequestExecutor implements RequestExecutor { protected RequestHttp requestHttp; @@ -17,11 +14,11 @@ public MaterialNewsInfoRequestExecutor(RequestHttp requestHttp) { public static RequestExecutor create(RequestHttp requestHttp) { switch (requestHttp.getRequestType()) { case APACHE_HTTP: - return new ApacheMaterialNewsInfoRequestExecutor(requestHttp); + return new MaterialNewsInfoApacheHttpRequestExecutor(requestHttp); case JODD_HTTP: - return new JoddMaterialNewsInfoRequestExecutor(requestHttp); + return new MaterialNewsInfoJoddHttpRequestExecutor(requestHttp); case OK_HTTP: - return new OkhttpMaterialNewsInfoRequestExecutor(requestHttp); + return new MaterialNewsInfoOkhttpRequestExecutor(requestHttp); default: //TODO 需要优化抛出异常 return null; 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/requestexecuter/material/MaterialUploadApacheHttpRequestExecutor.java similarity index 84% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialUploadRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadApacheHttpRequestExecutor.java index 9ddd61f9a9..d2e1029f9c 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/requestexecuter/material/MaterialUploadApacheHttpRequestExecutor.java @@ -1,13 +1,13 @@ -package me.chanjar.weixin.mp.util.http.apache; +package me.chanjar.weixin.mp.util.requestexecuter.material; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; import me.chanjar.weixin.common.util.json.WxGsonBuilder; import me.chanjar.weixin.mp.bean.material.WxMpMaterial; import me.chanjar.weixin.mp.bean.material.WxMpMaterialUploadResult; -import me.chanjar.weixin.mp.util.http.MaterialUploadRequestExecutor; import org.apache.http.Consts; import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; @@ -27,8 +27,8 @@ /** * Created by ecoolper on 2017/5/5. */ -public class ApacheMaterialUploadRequestExecutor extends MaterialUploadRequestExecutor { - public ApacheMaterialUploadRequestExecutor(RequestHttp requestHttp) { +public class MaterialUploadApacheHttpRequestExecutor extends MaterialUploadRequestExecutor { + public MaterialUploadApacheHttpRequestExecutor(RequestHttp requestHttp) { super(requestHttp); } @@ -64,7 +64,7 @@ public WxMpMaterialUploadResult execute(String uri, WxMpMaterial material) throw try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) { String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); - WxError error = WxError.fromJson(responseContent); + WxError error = WxError.fromJson(responseContent, WxType.MP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } else { 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/requestexecuter/material/MaterialUploadJoddHttpRequestExecutor.java similarity index 78% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialUploadRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadJoddHttpRequestExecutor.java index a7a5509c08..a09788a8de 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/requestexecuter/material/MaterialUploadJoddHttpRequestExecutor.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.mp.util.http.jodd; +package me.chanjar.weixin.mp.util.requestexecuter.material; import jodd.http.HttpConnectionProvider; import jodd.http.HttpRequest; @@ -6,13 +6,13 @@ 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.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.json.WxGsonBuilder; import me.chanjar.weixin.mp.bean.material.WxMpMaterial; import me.chanjar.weixin.mp.bean.material.WxMpMaterialUploadResult; -import me.chanjar.weixin.mp.util.http.MaterialUploadRequestExecutor; import java.io.File; import java.io.FileNotFoundException; @@ -22,8 +22,8 @@ /** * Created by ecoolper on 2017/5/5. */ -public class JoddMaterialUploadRequestExecutor extends MaterialUploadRequestExecutor { - public JoddMaterialUploadRequestExecutor(RequestHttp requestHttp) { +public class MaterialUploadJoddHttpRequestExecutor extends MaterialUploadRequestExecutor { + public MaterialUploadJoddHttpRequestExecutor(RequestHttp requestHttp) { super(requestHttp); } @@ -52,7 +52,7 @@ public WxMpMaterialUploadResult execute(String uri, WxMpMaterial material) throw HttpResponse response = request.send(); response.charset(StringPool.UTF_8); String responseContent = response.bodyText(); - WxError error = WxError.fromJson(responseContent); + WxError error = WxError.fromJson(responseContent, WxType.MP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } else { 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/requestexecuter/material/MaterialUploadOkhttpRequestExecutor.java similarity index 80% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialUploadRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadOkhttpRequestExecutor.java index 766d239565..879df49675 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/requestexecuter/material/MaterialUploadOkhttpRequestExecutor.java @@ -1,13 +1,13 @@ -package me.chanjar.weixin.mp.util.http.okhttp; +package me.chanjar.weixin.mp.util.requestexecuter.material; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.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.WxMpMaterial; import me.chanjar.weixin.mp.bean.material.WxMpMaterialUploadResult; -import me.chanjar.weixin.mp.util.http.MaterialUploadRequestExecutor; import okhttp3.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,16 +20,16 @@ /** * Created by ecoolper on 2017/5/5. */ -public class OkhttpMaterialUploadRequestExecutor extends MaterialUploadRequestExecutor { +public class MaterialUploadOkhttpRequestExecutor extends MaterialUploadRequestExecutor { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - public OkhttpMaterialUploadRequestExecutor(RequestHttp requestHttp) { + public MaterialUploadOkhttpRequestExecutor(RequestHttp requestHttp) { super(requestHttp); } @Override public WxMpMaterialUploadResult execute(String uri, WxMpMaterial material) throws WxErrorException, IOException { - logger.debug("OkhttpMaterialUploadRequestExecutor is running"); + logger.debug("MaterialUploadOkhttpRequestExecutor is running"); if (material == null) { throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("非法请求,material参数为空").build()); } @@ -55,7 +55,7 @@ public WxMpMaterialUploadResult execute(String uri, WxMpMaterial material) throw Request request = new Request.Builder().url(uri).post(bodyBuilder.build()).build(); Response response = client.newCall(request).execute(); String responseContent = response.body().string(); - WxError error = WxError.fromJson(responseContent); + WxError error = WxError.fromJson(responseContent, WxType.MP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } else { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialUploadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadRequestExecutor.java similarity index 62% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialUploadRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadRequestExecutor.java index c850d28cf9..c279be3213 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialUploadRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadRequestExecutor.java @@ -1,13 +1,13 @@ -package me.chanjar.weixin.mp.util.http; +package me.chanjar.weixin.mp.util.requestexecuter.material; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.mp.bean.material.WxMpMaterial; import me.chanjar.weixin.mp.bean.material.WxMpMaterialUploadResult; -import me.chanjar.weixin.mp.util.http.apache.ApacheMaterialUploadRequestExecutor; -import me.chanjar.weixin.mp.util.http.jodd.JoddMaterialUploadRequestExecutor; -import me.chanjar.weixin.mp.util.http.okhttp.OkhttpMaterialUploadRequestExecutor; +/** + * @author codepiano + */ public abstract class MaterialUploadRequestExecutor implements RequestExecutor { protected RequestHttp requestHttp; @@ -18,11 +18,11 @@ public MaterialUploadRequestExecutor(RequestHttp requestHttp) { public static RequestExecutor create(RequestHttp requestHttp) { switch (requestHttp.getRequestType()) { case APACHE_HTTP: - return new ApacheMaterialUploadRequestExecutor(requestHttp); + return new MaterialUploadApacheHttpRequestExecutor(requestHttp); case JODD_HTTP: - return new JoddMaterialUploadRequestExecutor(requestHttp); + return new MaterialUploadJoddHttpRequestExecutor(requestHttp); case OK_HTTP: - return new OkhttpMaterialUploadRequestExecutor(requestHttp); + return new MaterialUploadOkhttpRequestExecutor(requestHttp); default: return null; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialVideoInfoRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVideoInfoApacheHttpRequestExecutor.java similarity index 77% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialVideoInfoRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVideoInfoApacheHttpRequestExecutor.java index 7b81ea863f..65af9cf71c 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialVideoInfoRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVideoInfoApacheHttpRequestExecutor.java @@ -1,12 +1,12 @@ -package me.chanjar.weixin.mp.util.http.apache; +package me.chanjar.weixin.mp.util.requestexecuter.material; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; import me.chanjar.weixin.common.util.json.WxGsonBuilder; import me.chanjar.weixin.mp.bean.material.WxMpMaterialVideoInfoResult; -import me.chanjar.weixin.mp.util.http.MaterialVideoInfoRequestExecutor; import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; @@ -21,8 +21,8 @@ /** * Created by ecoolper on 2017/5/5. */ -public class ApacheMaterialVideoInfoRequestExecutor extends MaterialVideoInfoRequestExecutor { - public ApacheMaterialVideoInfoRequestExecutor(RequestHttp requestHttp) { +public class MaterialVideoInfoApacheHttpRequestExecutor extends MaterialVideoInfoRequestExecutor { + public MaterialVideoInfoApacheHttpRequestExecutor(RequestHttp requestHttp) { super(requestHttp); } @@ -39,7 +39,7 @@ public WxMpMaterialVideoInfoResult execute(String uri, String materialId) throws httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params))); try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) { String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); - WxError error = WxError.fromJson(responseContent); + WxError error = WxError.fromJson(responseContent, WxType.MP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } else { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialVideoInfoRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVideoInfoJoddHttpRequestExecutor.java similarity index 69% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialVideoInfoRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVideoInfoJoddHttpRequestExecutor.java index ab4ce6682c..852bea5da4 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialVideoInfoRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVideoInfoJoddHttpRequestExecutor.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.mp.util.http.jodd; +package me.chanjar.weixin.mp.util.requestexecuter.material; import jodd.http.HttpConnectionProvider; import jodd.http.HttpRequest; @@ -6,19 +6,19 @@ 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.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.mp.bean.material.WxMpMaterialVideoInfoResult; -import me.chanjar.weixin.mp.util.http.MaterialVideoInfoRequestExecutor; import java.io.IOException; /** * Created by ecoolper on 2017/5/5. */ -public class JoddMaterialVideoInfoRequestExecutor extends MaterialVideoInfoRequestExecutor { - public JoddMaterialVideoInfoRequestExecutor(RequestHttp requestHttp) { +public class MaterialVideoInfoJoddHttpRequestExecutor extends MaterialVideoInfoRequestExecutor { + public MaterialVideoInfoJoddHttpRequestExecutor(RequestHttp requestHttp) { super(requestHttp); } @@ -34,7 +34,7 @@ public WxMpMaterialVideoInfoResult execute(String uri, String materialId) throws HttpResponse response = request.send(); response.charset(StringPool.UTF_8); String responseContent = response.bodyText(); - WxError error = WxError.fromJson(responseContent); + WxError error = WxError.fromJson(responseContent, WxType.MP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } else { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialVideoInfoRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVideoInfoOkhttpRequestExecutor.java similarity index 71% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialVideoInfoRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVideoInfoOkhttpRequestExecutor.java index 79dd12be53..118c9673af 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialVideoInfoRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVideoInfoOkhttpRequestExecutor.java @@ -1,11 +1,11 @@ -package me.chanjar.weixin.mp.util.http.okhttp; +package me.chanjar.weixin.mp.util.requestexecuter.material; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo; import me.chanjar.weixin.mp.bean.material.WxMpMaterialVideoInfoResult; -import me.chanjar.weixin.mp.util.http.MaterialVideoInfoRequestExecutor; import okhttp3.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,16 +15,16 @@ /** * Created by ecoolper on 2017/5/5. */ -public class OkhttpMaterialVideoInfoRequestExecutor extends MaterialVideoInfoRequestExecutor { +public class MaterialVideoInfoOkhttpRequestExecutor extends MaterialVideoInfoRequestExecutor { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - public OkhttpMaterialVideoInfoRequestExecutor(RequestHttp requestHttp) { + public MaterialVideoInfoOkhttpRequestExecutor(RequestHttp requestHttp) { super(requestHttp); } @Override public WxMpMaterialVideoInfoResult execute(String uri, String materialId) throws WxErrorException, IOException { - logger.debug("OkhttpMaterialVideoInfoRequestExecutor is running"); + logger.debug("MaterialVideoInfoOkhttpRequestExecutor is running"); //得到httpClient OkHttpClient client = requestHttp.getRequestHttpClient(); @@ -32,7 +32,7 @@ public WxMpMaterialVideoInfoResult execute(String uri, String materialId) throws Request request = new Request.Builder().url(uri).post(requestBody).build(); Response response = client.newCall(request).execute(); String responseContent = response.body().string(); - WxError error = WxError.fromJson(responseContent); + WxError error = WxError.fromJson(responseContent, WxType.MP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } else { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVideoInfoRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVideoInfoRequestExecutor.java similarity index 61% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVideoInfoRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVideoInfoRequestExecutor.java index 73948052ff..b09fd75ae2 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVideoInfoRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVideoInfoRequestExecutor.java @@ -1,13 +1,10 @@ -package me.chanjar.weixin.mp.util.http; +package me.chanjar.weixin.mp.util.requestexecuter.material; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.mp.bean.material.WxMpMaterialVideoInfoResult; - import me.chanjar.weixin.mp.util.http.apache.ApacheMaterialVideoInfoRequestExecutor; - import me.chanjar.weixin.mp.util.http.jodd.JoddMaterialVideoInfoRequestExecutor; - import me.chanjar.weixin.mp.util.http.okhttp.OkhttpMaterialVideoInfoRequestExecutor; public abstract class MaterialVideoInfoRequestExecutor implements RequestExecutor { @@ -20,11 +17,11 @@ public MaterialVideoInfoRequestExecutor(RequestHttp requestHttp) { public static RequestExecutor create(RequestHttp requestHttp) { switch (requestHttp.getRequestType()) { case APACHE_HTTP: - return new ApacheMaterialVideoInfoRequestExecutor(requestHttp); + return new MaterialVideoInfoApacheHttpRequestExecutor(requestHttp); case JODD_HTTP: - return new JoddMaterialVideoInfoRequestExecutor(requestHttp); + return new MaterialVideoInfoJoddHttpRequestExecutor(requestHttp); case OK_HTTP: - return new OkhttpMaterialVideoInfoRequestExecutor(requestHttp); + return new MaterialVideoInfoOkhttpRequestExecutor(requestHttp); default: return null; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialVoiceAndImageDownloadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVoiceAndImageDownloadApacheHttpRequestExecutor.java similarity index 81% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialVoiceAndImageDownloadRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVoiceAndImageDownloadApacheHttpRequestExecutor.java index b1011a5282..cb295d0670 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialVoiceAndImageDownloadRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVoiceAndImageDownloadApacheHttpRequestExecutor.java @@ -1,11 +1,10 @@ -package me.chanjar.weixin.mp.util.http.apache; +package me.chanjar.weixin.mp.util.requestexecuter.material; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.apache.InputStreamResponseHandler; import me.chanjar.weixin.common.util.json.WxGsonBuilder; -import me.chanjar.weixin.mp.util.http.MaterialVoiceAndImageDownloadRequestExecutor; import org.apache.commons.io.IOUtils; import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; @@ -25,8 +24,8 @@ /** * Created by ecoolper on 2017/5/5. */ -public class ApacheMaterialVoiceAndImageDownloadRequestExecutor extends MaterialVoiceAndImageDownloadRequestExecutor { - public ApacheMaterialVoiceAndImageDownloadRequestExecutor(RequestHttp requestHttp, File tmpDirFile) { +public class MaterialVoiceAndImageDownloadApacheHttpRequestExecutor extends MaterialVoiceAndImageDownloadRequestExecutor { + public MaterialVoiceAndImageDownloadApacheHttpRequestExecutor(RequestHttp requestHttp, File tmpDirFile) { super(requestHttp, tmpDirFile); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialVoiceAndImageDownloadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVoiceAndImageDownloadJoddHttpRequestExecutor.java similarity index 78% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialVoiceAndImageDownloadRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVoiceAndImageDownloadJoddHttpRequestExecutor.java index ca43a1455d..391befbbe3 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialVoiceAndImageDownloadRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVoiceAndImageDownloadJoddHttpRequestExecutor.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.mp.util.http.jodd; +package me.chanjar.weixin.mp.util.requestexecuter.material; import jodd.http.HttpConnectionProvider; import jodd.http.HttpRequest; @@ -6,11 +6,10 @@ 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.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.json.WxGsonBuilder; -import me.chanjar.weixin.mp.util.http.MaterialVoiceAndImageDownloadRequestExecutor; import org.apache.commons.io.IOUtils; import java.io.ByteArrayInputStream; @@ -22,8 +21,8 @@ /** * Created by ecoolper on 2017/5/5. */ -public class JoddMaterialVoiceAndImageDownloadRequestExecutor extends MaterialVoiceAndImageDownloadRequestExecutor { - public JoddMaterialVoiceAndImageDownloadRequestExecutor(RequestHttp requestHttp, File tmpDirFile) { +public class MaterialVoiceAndImageDownloadJoddHttpRequestExecutor extends MaterialVoiceAndImageDownloadRequestExecutor { + public MaterialVoiceAndImageDownloadJoddHttpRequestExecutor(RequestHttp requestHttp, File tmpDirFile) { super(requestHttp, tmpDirFile); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialVoiceAndImageDownloadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVoiceAndImageDownloadOkhttpRequestExecutor.java similarity index 73% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialVoiceAndImageDownloadRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVoiceAndImageDownloadOkhttpRequestExecutor.java index 8c48139183..8952d173f0 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialVoiceAndImageDownloadRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVoiceAndImageDownloadOkhttpRequestExecutor.java @@ -1,15 +1,13 @@ -package me.chanjar.weixin.mp.util.http.okhttp; +package me.chanjar.weixin.mp.util.requestexecuter.material; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.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.util.http.MaterialVoiceAndImageDownloadRequestExecutor; import okhttp3.*; import okio.BufferedSink; import okio.Okio; -import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,16 +16,16 @@ /** * Created by ecoolper on 2017/5/5. */ -public class OkhttpMaterialVoiceAndImageDownloadRequestExecutor extends MaterialVoiceAndImageDownloadRequestExecutor { +public class MaterialVoiceAndImageDownloadOkhttpRequestExecutor extends MaterialVoiceAndImageDownloadRequestExecutor { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - public OkhttpMaterialVoiceAndImageDownloadRequestExecutor(RequestHttp requestHttp, File tmpDirFile) { + public MaterialVoiceAndImageDownloadOkhttpRequestExecutor(RequestHttp requestHttp, File tmpDirFile) { super(requestHttp, tmpDirFile); } @Override public InputStream execute(String uri, String materialId) throws WxErrorException, IOException { - logger.debug("OkhttpMaterialVoiceAndImageDownloadRequestExecutor is running"); + logger.debug("MaterialVoiceAndImageDownloadOkhttpRequestExecutor is running"); OkHttpClient client = requestHttp.getRequestHttpClient(); RequestBody requestBody = new FormBody.Builder().add("media_id", materialId).build(); Request request = new Request.Builder().url(uri).get().post(requestBody).build(); @@ -35,7 +33,7 @@ public InputStream execute(String uri, String materialId) throws WxErrorExceptio String contentTypeHeader = response.header("Content-Type"); if ("text/plain".equals(contentTypeHeader)) { String responseContent = response.body().string(); - throw new WxErrorException(WxError.fromJson(responseContent)); + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP)); } try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BufferedSink sink = Okio.buffer(Okio.sink(outputStream))) { sink.writeAll(response.body().source()); 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/requestexecuter/material/MaterialVoiceAndImageDownloadRequestExecutor.java similarity index 58% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVoiceAndImageDownloadRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVoiceAndImageDownloadRequestExecutor.java index 8a4f7462f7..c11c41cce0 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/requestexecuter/material/MaterialVoiceAndImageDownloadRequestExecutor.java @@ -1,10 +1,7 @@ -package me.chanjar.weixin.mp.util.http; +package me.chanjar.weixin.mp.util.requestexecuter.material; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; -import me.chanjar.weixin.mp.util.http.apache.ApacheMaterialVoiceAndImageDownloadRequestExecutor; -import me.chanjar.weixin.mp.util.http.jodd.JoddMaterialVoiceAndImageDownloadRequestExecutor; -import me.chanjar.weixin.mp.util.http.okhttp.OkhttpMaterialVoiceAndImageDownloadRequestExecutor; import java.io.File; import java.io.InputStream; @@ -22,11 +19,11 @@ public MaterialVoiceAndImageDownloadRequestExecutor(RequestHttp requestHttp, Fil public static RequestExecutor create(RequestHttp requestHttp, File tmpDirFile) { switch (requestHttp.getRequestType()) { case APACHE_HTTP: - return new ApacheMaterialVoiceAndImageDownloadRequestExecutor(requestHttp, tmpDirFile); + return new MaterialVoiceAndImageDownloadApacheHttpRequestExecutor(requestHttp, tmpDirFile); case JODD_HTTP: - return new JoddMaterialVoiceAndImageDownloadRequestExecutor(requestHttp, tmpDirFile); + return new MaterialVoiceAndImageDownloadJoddHttpRequestExecutor(requestHttp, tmpDirFile); case OK_HTTP: - return new OkhttpMaterialVoiceAndImageDownloadRequestExecutor(requestHttp, tmpDirFile); + return new MaterialVoiceAndImageDownloadOkhttpRequestExecutor(requestHttp, tmpDirFile); default: return null; } 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/requestexecuter/media/MediaImgUploadApacheHttpRequestExecutor.java similarity index 79% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMediaImgUploadRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/media/MediaImgUploadApacheHttpRequestExecutor.java index c27165bf77..dc6d979222 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/requestexecuter/media/MediaImgUploadApacheHttpRequestExecutor.java @@ -1,11 +1,11 @@ -package me.chanjar.weixin.mp.util.http.apache; +package me.chanjar.weixin.mp.util.requestexecuter.media; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult; -import me.chanjar.weixin.mp.util.http.MediaImgUploadRequestExecutor; import org.apache.http.HttpEntity; import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; @@ -21,9 +21,11 @@ /** * Created by ecoolper on 2017/5/5. + * + * @author ecoolper */ -public class ApacheMediaImgUploadRequestExecutor extends MediaImgUploadRequestExecutor { - public ApacheMediaImgUploadRequestExecutor(RequestHttp requestHttp) { +public class MediaImgUploadApacheHttpRequestExecutor extends MediaImgUploadRequestExecutor { + public MediaImgUploadApacheHttpRequestExecutor(RequestHttp requestHttp) { super(requestHttp); } @@ -49,7 +51,7 @@ public WxMediaImgUploadResult execute(String uri, File data) throws WxErrorExcep try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) { String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); - WxError error = WxError.fromJson(responseContent); + WxError error = WxError.fromJson(responseContent, WxType.MP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } 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/requestexecuter/media/MediaImgUploadHttpRequestExecutor.java similarity index 75% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMediaImgUploadRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/media/MediaImgUploadHttpRequestExecutor.java index b66a793365..c7ff37ba88 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/requestexecuter/media/MediaImgUploadHttpRequestExecutor.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.mp.util.http.jodd; +package me.chanjar.weixin.mp.util.requestexecuter.media; import jodd.http.HttpConnectionProvider; import jodd.http.HttpRequest; @@ -6,20 +6,22 @@ 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.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult; -import me.chanjar.weixin.mp.util.http.MediaImgUploadRequestExecutor; import java.io.File; import java.io.IOException; /** * Created by ecoolper on 2017/5/5. + * + * @author ecoolper */ -public class JoddMediaImgUploadRequestExecutor extends MediaImgUploadRequestExecutor { - public JoddMediaImgUploadRequestExecutor(RequestHttp requestHttp) { +public class MediaImgUploadHttpRequestExecutor extends MediaImgUploadRequestExecutor { + public MediaImgUploadHttpRequestExecutor(RequestHttp requestHttp) { super(requestHttp); } @@ -39,7 +41,7 @@ public WxMediaImgUploadResult execute(String uri, File data) throws WxErrorExcep HttpResponse response = request.send(); response.charset(StringPool.UTF_8); String responseContent = response.bodyText(); - WxError error = WxError.fromJson(responseContent); + WxError error = WxError.fromJson(responseContent, WxType.MP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMediaImgUploadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/media/MediaImgUploadOkhttpRequestExecutor.java similarity index 73% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMediaImgUploadRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/media/MediaImgUploadOkhttpRequestExecutor.java index f8e5859287..c787126e30 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMediaImgUploadRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/media/MediaImgUploadOkhttpRequestExecutor.java @@ -1,11 +1,11 @@ -package me.chanjar.weixin.mp.util.http.okhttp; +package me.chanjar.weixin.mp.util.requestexecuter.media; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo; import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult; -import me.chanjar.weixin.mp.util.http.MediaImgUploadRequestExecutor; import okhttp3.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,17 +15,19 @@ /** * Created by ecoolper on 2017/5/5. + * + * @author ecoolper */ -public class OkhttpMediaImgUploadRequestExecutor extends MediaImgUploadRequestExecutor { +public class MediaImgUploadOkhttpRequestExecutor extends MediaImgUploadRequestExecutor { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - public OkhttpMediaImgUploadRequestExecutor(RequestHttp requestHttp) { + public MediaImgUploadOkhttpRequestExecutor(RequestHttp requestHttp) { super(requestHttp); } @Override public WxMediaImgUploadResult execute(String uri, File file) throws WxErrorException, IOException { - logger.debug("OkhttpMediaImgUploadRequestExecutor is running"); + logger.debug("MediaImgUploadOkhttpRequestExecutor is running"); //得到httpClient OkHttpClient client = requestHttp.getRequestHttpClient(); @@ -39,7 +41,7 @@ public WxMediaImgUploadResult execute(String uri, File file) throws WxErrorExcep Request request = new Request.Builder().url(uri).post(body).build(); Response response = client.newCall(request).execute(); String responseContent = response.body().string(); - WxError error = WxError.fromJson(responseContent); + WxError error = WxError.fromJson(responseContent, WxType.MP); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MediaImgUploadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/media/MediaImgUploadRequestExecutor.java similarity index 61% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MediaImgUploadRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/media/MediaImgUploadRequestExecutor.java index e187561fc8..c937fbe51a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MediaImgUploadRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/media/MediaImgUploadRequestExecutor.java @@ -1,11 +1,8 @@ -package me.chanjar.weixin.mp.util.http; +package me.chanjar.weixin.mp.util.requestexecuter.media; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult; -import me.chanjar.weixin.mp.util.http.apache.ApacheMediaImgUploadRequestExecutor; -import me.chanjar.weixin.mp.util.http.jodd.JoddMediaImgUploadRequestExecutor; -import me.chanjar.weixin.mp.util.http.okhttp.OkhttpMediaImgUploadRequestExecutor; import java.io.File; @@ -22,11 +19,11 @@ public MediaImgUploadRequestExecutor(RequestHttp requestHttp) { public static RequestExecutor create(RequestHttp requestHttp) { switch (requestHttp.getRequestType()) { case APACHE_HTTP: - return new ApacheMediaImgUploadRequestExecutor(requestHttp); + return new MediaImgUploadApacheHttpRequestExecutor(requestHttp); case JODD_HTTP: - return new JoddMediaImgUploadRequestExecutor(requestHttp); + return new MediaImgUploadHttpRequestExecutor(requestHttp); case OK_HTTP: - return new OkhttpMediaImgUploadRequestExecutor(requestHttp); + return new MediaImgUploadOkhttpRequestExecutor(requestHttp); default: return null; } 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/requestexecuter/qrcode/QrCodeApacheHttpRequestExecutor.java similarity index 85% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheQrCodeRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/qrcode/QrCodeApacheHttpRequestExecutor.java index 59874ee2bd..6280be7a0b 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/requestexecuter/qrcode/QrCodeApacheHttpRequestExecutor.java @@ -1,13 +1,13 @@ -package me.chanjar.weixin.mp.util.http.apache; +package me.chanjar.weixin.mp.util.requestexecuter.qrcode; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.apache.InputStreamResponseHandler; import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; -import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor; import org.apache.http.Header; import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; @@ -25,8 +25,8 @@ /** * Created by ecoolper on 2017/5/5. */ -public class ApacheQrCodeRequestExecutor extends QrCodeRequestExecutor { - public ApacheQrCodeRequestExecutor(RequestHttp requestHttp) { +public class QrCodeApacheHttpRequestExecutor extends QrCodeRequestExecutor { + public QrCodeApacheHttpRequestExecutor(RequestHttp requestHttp) { super(requestHttp); } @@ -55,7 +55,7 @@ public File execute(String uri, WxMpQrCodeTicket ticket) throws WxErrorException if (ContentType.TEXT_PLAIN.getMimeType() .equals(ContentType.parse(contentTypeHeader[0].getValue()).getMimeType())) { String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); - throw new WxErrorException(WxError.fromJson(responseContent)); + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP)); } } return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg"); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddQrCodeRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/qrcode/QrCodeJoddHttpRequestExecutor.java similarity index 81% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddQrCodeRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/qrcode/QrCodeJoddHttpRequestExecutor.java index 8b15dccf00..1798065f3e 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddQrCodeRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/qrcode/QrCodeJoddHttpRequestExecutor.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.mp.util.http.jodd; +package me.chanjar.weixin.mp.util.requestexecuter.qrcode; import jodd.http.HttpConnectionProvider; import jodd.http.HttpRequest; @@ -7,12 +7,12 @@ import jodd.util.MimeTypes; import jodd.util.StringPool; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; -import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor; import java.io.ByteArrayInputStream; import java.io.File; @@ -24,8 +24,8 @@ /** * Created by ecoolper on 2017/5/5. */ -public class JoddQrCodeRequestExecutor extends QrCodeRequestExecutor { - public JoddQrCodeRequestExecutor(RequestHttp requestHttp) { +public class QrCodeJoddHttpRequestExecutor extends QrCodeRequestExecutor { + public QrCodeJoddHttpRequestExecutor(RequestHttp requestHttp) { super(requestHttp); } @@ -51,7 +51,7 @@ public File execute(String uri, WxMpQrCodeTicket ticket) throws WxErrorException String contentTypeHeader = response.header("Content-Type"); if (MimeTypes.MIME_TEXT_PLAIN.equals(contentTypeHeader)) { String responseContent = response.bodyText(); - throw new WxErrorException(WxError.fromJson(responseContent)); + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP)); } try (InputStream inputStream = new ByteArrayInputStream(response.bodyBytes())) { return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg"); 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/requestexecuter/qrcode/QrCodeOkhttpRequestExecutor.java similarity index 80% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpQrCodeRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/qrcode/QrCodeOkhttpRequestExecutor.java index 79fd294e24..825af37725 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/requestexecuter/qrcode/QrCodeOkhttpRequestExecutor.java @@ -1,12 +1,12 @@ -package me.chanjar.weixin.mp.util.http.okhttp; +package me.chanjar.weixin.mp.util.requestexecuter.qrcode; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; import me.chanjar.weixin.common.util.http.RequestHttp; 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.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -24,16 +24,16 @@ * @author ecoolper * @date 2017/5/5 */ -public class OkhttpQrCodeRequestExecutor extends QrCodeRequestExecutor { +public class QrCodeOkhttpRequestExecutor extends QrCodeRequestExecutor { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - public OkhttpQrCodeRequestExecutor(RequestHttp requestHttp) { + public QrCodeOkhttpRequestExecutor(RequestHttp requestHttp) { super(requestHttp); } @Override public File execute(String uri, WxMpQrCodeTicket ticket) throws WxErrorException, IOException { - logger.debug("OkhttpQrCodeRequestExecutor is running"); + logger.debug("QrCodeOkhttpRequestExecutor is running"); if (ticket != null) { if (uri.indexOf('?') == -1) { @@ -50,7 +50,7 @@ public File execute(String uri, WxMpQrCodeTicket ticket) throws WxErrorException String contentTypeHeader = response.header("Content-Type"); if ("text/plain".equals(contentTypeHeader)) { String responseContent = response.body().string(); - throw new WxErrorException(WxError.fromJson(responseContent)); + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP)); } try (InputStream inputStream = response.body().byteStream()) { 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/requestexecuter/qrcode/QrCodeRequestExecutor.java similarity index 61% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/QrCodeRequestExecutor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/qrcode/QrCodeRequestExecutor.java index af2e025796..7c666cd0d5 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/requestexecuter/qrcode/QrCodeRequestExecutor.java @@ -1,13 +1,10 @@ -package me.chanjar.weixin.mp.util.http; +package me.chanjar.weixin.mp.util.requestexecuter.qrcode; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.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; -import me.chanjar.weixin.mp.util.http.apache.ApacheQrCodeRequestExecutor; -import me.chanjar.weixin.mp.util.http.jodd.JoddQrCodeRequestExecutor; -import me.chanjar.weixin.mp.util.http.okhttp.OkhttpQrCodeRequestExecutor; import java.io.File; @@ -26,11 +23,11 @@ public QrCodeRequestExecutor(RequestHttp requestHttp) { public static RequestExecutor create(RequestHttp requestHttp) throws WxErrorException { switch (requestHttp.getRequestType()) { case APACHE_HTTP: - return new ApacheQrCodeRequestExecutor(requestHttp); + return new QrCodeApacheHttpRequestExecutor(requestHttp); case JODD_HTTP: - return new JoddQrCodeRequestExecutor(requestHttp); + return new QrCodeJoddHttpRequestExecutor(requestHttp); case OK_HTTP: - return new OkhttpQrCodeRequestExecutor(requestHttp); + return new QrCodeOkhttpRequestExecutor(requestHttp); default: throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("不支持的http框架").build()); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/voice/VoiceUploadApacheHttpRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/voice/VoiceUploadApacheHttpRequestExecutor.java new file mode 100644 index 0000000000..c23b3a3219 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/voice/VoiceUploadApacheHttpRequestExecutor.java @@ -0,0 +1,65 @@ +package me.chanjar.weixin.mp.util.requestexecuter.voice; + +import me.chanjar.weixin.common.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.util.http.RequestHttp; +import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; +import org.apache.http.HttpEntity; +import org.apache.http.HttpHost; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.mime.HttpMultipartMode; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.impl.client.CloseableHttpClient; + +import java.io.File; +import java.io.IOException; + +/** + * + * Created by BinaryWang on 2018/6/9. + *+ * + * @author Binary Wang + */ +public class VoiceUploadApacheHttpRequestExecutor extends VoiceUploadRequestExecutor{ + public VoiceUploadApacheHttpRequestExecutor(RequestHttp requestHttp) { + super(requestHttp); + } + + @Override + public Boolean execute(String uri, File data) throws WxErrorException, IOException { + if (data == null) { + throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("文件对象为空").build()); + } + + HttpPost httpPost = new HttpPost(uri); + if (requestHttp.getRequestHttpProxy() != null) { + RequestConfig config = RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build(); + httpPost.setConfig(config); + } + + HttpEntity entity = MultipartEntityBuilder + .create() + .addBinaryBody("media", data) + .setMode(HttpMultipartMode.RFC6532) + .build(); + httpPost.setEntity(entity); + httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString()); + + try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) { + String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); + WxError error = WxError.fromJson(responseContent, WxType.MP); + if (error.getErrorCode() != 0) { + throw new WxErrorException(error); + } + + return true; + } finally { + httpPost.releaseConnection(); + } + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/voice/VoiceUploadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/voice/VoiceUploadRequestExecutor.java new file mode 100644 index 0000000000..34c7ae2108 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/voice/VoiceUploadRequestExecutor.java @@ -0,0 +1,33 @@ +package me.chanjar.weixin.mp.util.requestexecuter.voice; + +import me.chanjar.weixin.common.util.http.RequestExecutor; +import me.chanjar.weixin.common.util.http.RequestHttp; + +import java.io.File; + +/** + * + * Created by BinaryWang on 2018/6/9. + *+ * + * @author Binary Wang + */ +public abstract class VoiceUploadRequestExecutorimplements RequestExecutor { + protected RequestHttp requestHttp; + + public VoiceUploadRequestExecutor(RequestHttp requestHttp) { + this.requestHttp = requestHttp; + } + + public static RequestExecutor create(RequestHttp requestHttp) { + switch (requestHttp.getRequestType()) { + case APACHE_HTTP: + return new VoiceUploadApacheHttpRequestExecutor(requestHttp); + case JODD_HTTP: + case OK_HTTP: + default: + return null; + } + } + +} 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 6588cac3fb..ace711a236 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 @@ -71,7 +71,6 @@ public 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)); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java index 7fb10716f0..ffcd232cf4 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.api; import com.google.inject.Inject; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.test.ApiTestModule; import org.apache.commons.lang3.StringUtils; import org.testng.*; 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 2a07e3b9b2..507ab31b6b 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 @@ -1,7 +1,7 @@ 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.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl; import org.testng.annotations.*; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java index 8e1c58d783..0b14d9564b 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java @@ -1,7 +1,6 @@ package me.chanjar.weixin.mp.api; import com.google.inject.Inject; -import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.crypto.SHA1; import me.chanjar.weixin.mp.api.test.ApiTestModule; import org.testng.*; 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 4b919a2293..b9424eb023 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 @@ -8,6 +8,8 @@ import org.testng.*; import org.testng.annotations.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.Map; /** @@ -67,9 +69,23 @@ public void testAsync(WxMpXmlMessage message, String expected) throws Interrupte prepare(true, sb, router); router.route(message); Thread.sleep(500); + router.shutDownExecutorService(); Assert.assertEquals(sb.toString(), expected); } + @Test(dataProvider = "messages-1") + public void testExternalExcutorService(WxMpXmlMessage message, String expected) throws InterruptedException { + StringBuffer sb = new StringBuffer(); + ExecutorService executorService = Executors.newFixedThreadPool(100); + WxMpMessageRouter router = new WxMpMessageRouter(null, executorService); + prepare(true, sb, router); + router.route(message); + Thread.sleep(500); + executorService.shutdown(); + Assert.assertEquals(sb.toString(), expected); + } + + public void testConcurrency() throws InterruptedException { final WxMpMessageRouter router = new WxMpMessageRouter(null); router.rule().handler(new WxMpMessageHandler() { diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMiscAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMiscAPITest.java index 8c61a56059..d8ed016b37 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMiscAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMiscAPITest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.api; import com.google.inject.Inject; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.test.ApiTestModule; import org.testng.*; import org.testng.annotations.*; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java index 3e8a45c361..ec6e75d7c5 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.api; import com.google.inject.Inject; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.test.ApiTestModule; import org.testng.*; import org.testng.annotations.*; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpAiOpenServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpAiOpenServiceImplTest.java new file mode 100644 index 0000000000..f10f988866 --- /dev/null +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpAiOpenServiceImplTest.java @@ -0,0 +1,47 @@ +package me.chanjar.weixin.mp.api.impl; + +import com.google.inject.Inject; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.mp.AiLangType; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import java.io.File; + +/** + * + * Created by BinaryWang on 2018/6/10. + *+ * + * @author Binary Wang + */ +@Test +@Guice(modules = ApiTestModule.class) +public class WxMpAiOpenServiceImplTest { + @Inject + protected WxMpService wxService; + + @Test + public void testUploadVoice() throws WxErrorException { + String voiceId = System.currentTimeMillis() + "a"; + AiLangType lang = AiLangType.zh_CN; + this.wxService.getAiOpenService().uploadVoice(voiceId, lang, new File("d:\\t.mp3")); + } + + @Test + public void testRecogniseVoice() throws WxErrorException { + String voiceId = System.currentTimeMillis() + "a"; + AiLangType lang = AiLangType.zh_CN; + final String result = this.wxService.getAiOpenService().recogniseVoice(voiceId, lang, new File("d:\\t.mp3")); + System.out.println(result); + } + + @Test + public void testTranslate() throws WxErrorException { + final String responseContent = this.wxService.getAiOpenService() + .translate(AiLangType.zh_CN, AiLangType.en_US, "微信文档很坑爹"); + System.out.println(responseContent); + } +} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java index 0f465d4a47..e5e0e22586 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.datacube.*; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java index d48161e354..2039a5f32b 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java @@ -2,7 +2,7 @@ import com.google.inject.Inject; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.device.WxDeviceQrCodeResult; 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 d0c3aac835..13a161a189 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 @@ -2,7 +2,7 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; 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 da025374a8..f2d7683021 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 @@ -3,7 +3,7 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; 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 919b4cb43b..afca1a2acf 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 @@ -3,7 +3,7 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; 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 ff00d474a7..c25c946df4 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 @@ -4,7 +4,7 @@ import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.menu.WxMenu; import me.chanjar.weixin.common.bean.menu.WxMenuButton; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult; 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 75eb291a04..833671e4b0 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 @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; 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 89060a6ef1..e9999f577d 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 @@ -2,7 +2,7 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; 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 e6f4c15570..564259c664 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 @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpSubscribeMsgServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpSubscribeMsgServiceImplTest.java index 3db67ef6de..77a661ee58 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpSubscribeMsgServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpSubscribeMsgServiceImplTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; 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 4457aeb339..94d759fc75 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 @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java index 27f117916e..0a4cd21a17 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpWifiServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpWifiServiceImplTest.java new file mode 100644 index 0000000000..e129474e39 --- /dev/null +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpWifiServiceImplTest.java @@ -0,0 +1,31 @@ +package me.chanjar.weixin.mp.api.impl; + +import com.google.inject.Inject; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; +import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopListResult; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import static org.testng.Assert.*; + +/** + *+ * Created by BinaryWang on 2018/6/10. + *+ * + * @author Binary Wang + */ +@Test +@Guice(modules = ApiTestModule.class) +public class WxMpWifiServiceImplTest { + @Inject + private WxMpService wxService; + + @Test + public void testListShop() throws WxErrorException { + final WxMpWifiShopListResult result = this.wxService.getWifiService().listShop(1, 2); + System.out.println(result); + } +} 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 030da968e9..98173f7d35 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 @@ -1,5 +1,13 @@ package me.chanjar.weixin.mp.api.test; +import java.io.IOException; +import java.io.InputStream; +import java.util.concurrent.locks.ReentrantLock; + +import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.google.inject.Binder; import com.google.inject.Module; import com.thoughtworks.xstream.XStream; @@ -8,24 +16,26 @@ import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.impl.WxMpServiceOkHttpImpl; -import java.io.IOException; -import java.io.InputStream; -import java.util.concurrent.locks.ReentrantLock; - public class ApiTestModule implements Module { + private final Logger log = LoggerFactory.getLogger(this.getClass()); + private static final String TEST_CONFIG_XML = "test-config.xml"; @Override public void configure(Binder binder) { - try (InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml")) { - TestConfigStorage config = this.fromXml(TestConfigStorage.class, is1); + try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(TEST_CONFIG_XML)) { + if (inputStream == null) { + throw new RuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成"); + } + + TestConfigStorage config = this.fromXml(TestConfigStorage.class, inputStream); config.setAccessTokenLock(new ReentrantLock()); - WxMpService wxService = new WxMpServiceOkHttpImpl(); + WxMpService wxService = new WxMpServiceHttpClientImpl(); wxService.setWxMpConfigStorage(config); binder.bind(WxMpService.class).toInstance(wxService); binder.bind(WxMpConfigStorage.class).toInstance(config); } catch (IOException e) { - e.printStackTrace(); + this.log.error(e.getMessage(), e); } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/TestConfigStorage.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/TestConfigStorage.java index 6400f81dee..ed6c5cb168 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/TestConfigStorage.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/TestConfigStorage.java @@ -52,10 +52,12 @@ public void setQrconnectRedirectUrl(String qrconnectRedirectUrl) { this.qrconnectRedirectUrl = qrconnectRedirectUrl; } + @Override public String getTemplateId() { return this.templateId; } + @Override public void setTemplateId(String templateId) { this.templateId = templateId; } 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 bfeb84c119..4f983dde13 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 @@ -2,8 +2,8 @@ import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage.WxArticle; -import org.testng.*; -import org.testng.annotations.*; +import org.testng.Assert; +import org.testng.annotations.Test; @Test public class WxMpKefuMessageTest { @@ -13,12 +13,14 @@ public void testTextReply() { reply.setToUser("OPENID"); reply.setMsgType(WxConsts.KefuMsgType.TEXT); reply.setContent("sfsfdsdf"); - Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}"); + Assert + .assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}"); } public void testTextBuild() { WxMpKefuMessage reply = WxMpKefuMessage.TEXT().toUser("OPENID").content("sfsfdsdf").build(); - Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}"); + Assert + .assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}"); } public void testImageReply() { @@ -26,12 +28,14 @@ public void testImageReply() { reply.setToUser("OPENID"); reply.setMsgType(WxConsts.KefuMsgType.IMAGE); reply.setMediaId("MEDIA_ID"); - Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}"); + Assert.assertEquals(reply.toJson(), + "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}"); } public void testImageBuild() { WxMpKefuMessage reply = WxMpKefuMessage.IMAGE().toUser("OPENID").mediaId("MEDIA_ID").build(); - Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}"); + Assert.assertEquals(reply.toJson(), + "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}"); } public void testVoiceReply() { @@ -39,12 +43,14 @@ public void testVoiceReply() { reply.setToUser("OPENID"); reply.setMsgType(WxConsts.KefuMsgType.VOICE); reply.setMediaId("MEDIA_ID"); - Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}"); + Assert.assertEquals(reply.toJson(), + "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}"); } public void testVoiceBuild() { WxMpKefuMessage reply = WxMpKefuMessage.VOICE().toUser("OPENID").mediaId("MEDIA_ID").build(); - Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}"); + Assert.assertEquals(reply.toJson(), + "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}"); } public void testVideoReply() { @@ -55,12 +61,15 @@ public void testVideoReply() { reply.setThumbMediaId("MEDIA_ID"); reply.setTitle("TITLE"); reply.setDescription("DESCRIPTION"); - Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}"); + Assert.assertEquals(reply.toJson(), + "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}"); } public void testVideoBuild() { - WxMpKefuMessage reply = WxMpKefuMessage.VIDEO().toUser("OPENID").title("TITLE").mediaId("MEDIA_ID").thumbMediaId("MEDIA_ID").description("DESCRIPTION").build(); - Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}"); + WxMpKefuMessage reply = WxMpKefuMessage.VIDEO().toUser("OPENID").title("TITLE").mediaId("MEDIA_ID") + .thumbMediaId("MEDIA_ID").description("DESCRIPTION").build(); + Assert.assertEquals(reply.toJson(), + "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}"); } public void testMusicReply() { @@ -72,7 +81,8 @@ public void testMusicReply() { reply.setTitle("TITLE"); reply.setMusicUrl("MUSIC_URL"); reply.setHqMusicUrl("HQ_MUSIC_URL"); - Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}"); + Assert.assertEquals(reply.toJson(), + "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}"); } public void testMusicBuild() { @@ -84,7 +94,8 @@ public void testMusicBuild() { .musicUrl("MUSIC_URL") .hqMusicUrl("HQ_MUSIC_URL") .build(); - Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}"); + Assert.assertEquals(reply.toJson(), + "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}"); } public void testNewsReply() { @@ -106,8 +117,8 @@ public void testNewsReply() { article2.setTitle("Happy Day"); reply.getArticles().add(article2); - - Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"news\":{\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}}"); + Assert.assertEquals(reply.toJson(), + "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"news\":{\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}}"); } public void testNewsBuild() { @@ -125,7 +136,22 @@ public void testNewsBuild() { WxMpKefuMessage reply = WxMpKefuMessage.NEWS().toUser("OPENID").addArticle(article1).addArticle(article2).build(); - Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"news\":{\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}}"); + Assert.assertEquals(reply.toJson(), + "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"news\":{\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}}"); + } + + public void testMiniProgramPageBuild() { + + WxMpKefuMessage reply = WxMpKefuMessage.MINIPROGRAMPAGE() + .toUser("OPENID") + .title("title") + .appId("appid") + .pagePath("pagepath") + .thumbMediaId("thumb_media_id") + .build(); + + Assert.assertEquals(reply.toJson(), + "{\"touser\":\"OPENID\",\"msgtype\":\"miniprogrampage\",\"miniprogrampage\":{\"title\":\"title\",\"appid\":\"appid\",\"pagepath\":\"pagepath\",\"thumb_media_id\":\"thumb_media_id\"}}"); } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoGuessNumberHandler.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoGuessNumberHandler.java index 1743b1f955..0e04972350 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoGuessNumberHandler.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoGuessNumberHandler.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.demo; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.session.WxSession; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.mp.api.WxMpMessageHandler; 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 5578f637be..22b58ccf16 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 @@ -2,7 +2,7 @@ import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.mp.api.WxMpMessageHandler; import me.chanjar.weixin.mp.api.WxMpService; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpOAuth2Servlet.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpOAuth2Servlet.java index e739a93689..4712fb322f 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpOAuth2Servlet.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpOAuth2Servlet.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.demo; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; import me.chanjar.weixin.mp.bean.result.WxMpUser; diff --git a/weixin-java-open/pom.xml b/weixin-java-open/pom.xml index fb6d88832b..c644f3f732 100644 --- a/weixin-java-open/pom.xml +++ b/weixin-java-open/pom.xml @@ -8,7 +8,7 @@com.github.binarywang weixin-java-parent -3.0.0 +3.1.0 weixin-java-open Weixin Java Tools - Open 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 index 9b07759051..c2e19943ca 100644 --- 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 @@ -2,19 +2,21 @@ import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; +import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate; 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 java.util.List; + /** * @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"; @@ -23,7 +25,6 @@ public interface WxOpenComponentService { 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"; @@ -87,4 +88,48 @@ public interface WxOpenComponentService { WxMaJscode2SessionResult miniappJscode2Session(String appId, String jsCode) throws WxErrorException; + /** + * 代小程序实现业务 + *+ * 小程序代码模版库管理:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1506504150_nMMh6&token=&lang=zh_CN + * access_token 为 component_access_token + */ + String GET_TEMPLATE_DRAFT_LIST_URL = "https://api.weixin.qq.com/wxa/gettemplatedraftlist"; + String GET_TEMPLATE_LIST_URL = "https://api.weixin.qq.com/wxa/gettemplatelist"; + String ADD_TO_TEMPLATE_URL = "https://api.weixin.qq.com/wxa/addtotemplate"; + String DELETE_TEMPLATE_URL = "https://api.weixin.qq.com/wxa/deletetemplate"; + + /** + * 获取草稿箱内的所有临时代码草稿 + * + * @return 草稿箱代码模板列表(draftId) + * @throws WxErrorException 获取失败时返回,具体错误码请看此接口的注释文档 + */ + List
getTemplateDraftList() throws WxErrorException; + + /** + * 获取代码模版库中的所有小程序代码模版 + * + * @return 小程序代码模版列表(templateId) + * @throws WxErrorException 获取失败时返回,具体错误码请看此接口的注释文档 + */ + List getTemplateList() throws WxErrorException; + + /** + * 将草稿箱的草稿选为小程序代码模版 + * + * @param draftId 草稿ID,本字段可通过“获取草稿箱内的所有临时代码草稿”接口获得 + * @throws WxErrorException 操作失败时抛出,具体错误码请看此接口的注释文档 + * @see #getTemplateDraftList + */ + void addToTemplate(long draftId) throws WxErrorException; + + /** + * 删除指定小程序代码模版 + * + * @param templateId 要删除的模版ID + * @throws WxErrorException 操作失败时抛出,具体错误码请看此接口的注释文档 + * @see #getTemplateList + */ + void deleteTemplate(long templateId) throws WxErrorException; } 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 index 07366475db..b0d833b29d 100644 --- 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 @@ -34,8 +34,18 @@ public interface WxOpenConfigStorage { boolean isComponentAccessTokenExpired(); + void expireComponentAccessToken(); + void updateComponentAccessTokent(WxOpenComponentAccessToken componentAccessToken); + String getHttpProxyHost(); + + int getHttpProxyPort(); + + String getHttpProxyUsername(); + + String getHttpProxyPassword(); + WxMpConfigStorage getWxMpConfigStorage(String appId); WxMaConfig getWxMaConfig(String appId); @@ -115,5 +125,4 @@ public interface WxOpenConfigStorage { * @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 index e11296e6c8..a157581b36 100644 --- 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 @@ -1,6 +1,6 @@ package me.chanjar.weixin.open.api; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; /** * @author 007 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 index 1467091659..05f3df1123 100644 --- 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 @@ -3,7 +3,10 @@ import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import com.google.gson.JsonObject; -import me.chanjar.weixin.common.exception.WxErrorException; +import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.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; @@ -14,6 +17,7 @@ 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.WxOpenMaCodeTemplate; import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo; import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult; @@ -25,13 +29,14 @@ import org.slf4j.LoggerFactory; import java.util.Hashtable; +import java.util.List; import java.util.Map; /** * @author 007 */ public class WxOpenComponentServiceImpl implements WxOpenComponentService { - + private static final JsonParser JSON_PARSER = new JsonParser(); private static final Map WX_OPEN_MA_SERVICE_MAP = new Hashtable<>(); private static final Map WX_OPEN_MP_SERVICE_MAP = new Hashtable<>(); @@ -110,15 +115,64 @@ public String getComponentAccessToken(boolean forceRefresh) throws WxErrorExcept } private String post(String uri, String postData) throws WxErrorException { + return post(uri, postData, "component_access_token"); + } + + private String post(String uri, String postData, String accessTokenKey) throws WxErrorException { String componentAccessToken = getComponentAccessToken(false); - String uriWithComponentAccessToken = uri + (uri.contains("?") ? "&" : "?") + "component_access_token=" + componentAccessToken; - return getWxOpenService().post(uriWithComponentAccessToken, postData); + String uriWithComponentAccessToken = uri + (uri.contains("?") ? "&" : "?") + accessTokenKey + "=" + componentAccessToken; + try { + return getWxOpenService().post(uriWithComponentAccessToken, postData); + } 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) { + // 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token + this.getWxOpenConfigStorage().expireComponentAccessToken(); + if (this.getWxOpenConfigStorage().autoRefreshToken()) { + return this.post(uri, postData, accessTokenKey); + } + } + if (error.getErrorCode() != 0) { + throw new WxErrorException(error, e); + } + return null; + } } private String get(String uri) throws WxErrorException { + return get(uri, "component_access_token"); + } + private String get(String uri, String accessTokenKey) throws WxErrorException { String componentAccessToken = getComponentAccessToken(false); - String uriWithComponentAccessToken = uri + (uri.contains("?") ? "&" : "?") + "component_access_token=" + componentAccessToken; - return getWxOpenService().get(uriWithComponentAccessToken, null); + String uriWithComponentAccessToken = uri + (uri.contains("?") ? "&" : "?") + accessTokenKey + "=" + componentAccessToken; + try { + return getWxOpenService().get(uriWithComponentAccessToken, null); + } 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) { + // 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token + this.getWxOpenConfigStorage().expireComponentAccessToken(); + if (this.getWxOpenConfigStorage().autoRefreshToken()) { + return this.get(uri, accessTokenKey); + } + } + if (error.getErrorCode() != 0) { + throw new WxErrorException(error, e); + } + return null; + } } @Override @@ -146,14 +200,6 @@ public String route(final WxOpenXmlMessage wxMessage) throws WxErrorException { 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 ""; @@ -165,7 +211,19 @@ public WxOpenQueryAuthResult getQueryAuth(String authorizationCode) throws WxErr 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); + WxOpenQueryAuthResult queryAuth = WxOpenGsonBuilder.create().fromJson(responseContent, WxOpenQueryAuthResult.class); + if (queryAuth == null || queryAuth.getAuthorizationInfo() == null) { + return queryAuth; + } + 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 queryAuth; } @Override @@ -245,4 +303,45 @@ public WxMaJscode2SessionResult miniappJscode2Session(String appId, String jsCod return WxMaJscode2SessionResult.fromJson(responseContent); } + @Override + public List getTemplateDraftList() throws WxErrorException { + String responseContent = get(GET_TEMPLATE_DRAFT_LIST_URL, "access_token"); + JsonObject response = JSON_PARSER.parse(StringUtils.defaultString(responseContent, "{}")).getAsJsonObject(); + boolean hasDraftList = response.has("draft_list"); + if (hasDraftList) { + return WxOpenGsonBuilder.create().fromJson(response.getAsJsonArray("draft_list"), + new TypeToken >() { + }.getType()); + } else { + return null; + } + } + + @Override + public List
getTemplateList() throws WxErrorException { + String responseContent = get(GET_TEMPLATE_LIST_URL, "access_token"); + JsonObject response = JSON_PARSER.parse(StringUtils.defaultString(responseContent, "{}")).getAsJsonObject(); + boolean hasDraftList = response.has("template_list"); + if (hasDraftList) { + return WxOpenGsonBuilder.create().fromJson(response.getAsJsonArray("template_list"), + new TypeToken >() { + }.getType()); + } else { + return null; + } + } + + @Override + public void addToTemplate(long draftId) throws WxErrorException { + JsonObject param = new JsonObject(); + param.addProperty("draft_id", draftId); + post(ADD_TO_TEMPLATE_URL, param.toString(), "access_token"); + } + + @Override + public void deleteTemplate(long templateId) throws WxErrorException { + JsonObject param = new JsonObject(); + param.addProperty("template_id", templateId); + post(DELETE_TEMPLATE_URL, param.toString(), "access_token"); + } } 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 index 9950482c1e..56e1d9a1c1 100644 --- 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 @@ -30,6 +30,11 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage { private String componentAccessToken; private long componentExpiresTime; + private String httpProxyHost; + private int httpProxyPort; + private String httpProxyUsername; + private String httpProxyPassword; + private Map
authorizerRefreshTokens = new Hashtable<>(); private Map authorizerAccessTokens = new Hashtable<>(); private Map jsapiTickets = new Hashtable<>(); @@ -95,11 +100,52 @@ public boolean isComponentAccessTokenExpired() { return System.currentTimeMillis() > componentExpiresTime; } + @Override + public void expireComponentAccessToken() { + this.componentExpiresTime = 0L; + } + @Override public void updateComponentAccessTokent(WxOpenComponentAccessToken componentAccessToken) { updateComponentAccessTokent(componentAccessToken.getComponentAccessToken(), componentAccessToken.getExpiresIn()); } + @Override + public String getHttpProxyHost() { + return httpProxyHost; + } + + public void setHttpProxyHost(String httpProxyHost) { + this.httpProxyHost = httpProxyHost; + } + + @Override + public int getHttpProxyPort() { + return httpProxyPort; + } + + public void setHttpProxyPort(int httpProxyPort) { + this.httpProxyPort = httpProxyPort; + } + + @Override + public String getHttpProxyUsername() { + return httpProxyUsername; + } + + public void setHttpProxyUsername(String httpProxyUsername) { + this.httpProxyUsername = httpProxyUsername; + } + + @Override + public String getHttpProxyPassword() { + return httpProxyPassword; + } + + public void setHttpProxyPassword(String httpProxyPassword) { + this.httpProxyPassword = httpProxyPassword; + } + @Override public WxMpConfigStorage getWxMpConfigStorage(String appId) { return new WxOpenInnerConfigStorage(this, appId); @@ -372,22 +418,22 @@ public String getOauth2redirectUri() { @Override public String getHttpProxyHost() { - return null; + return this.wxOpenConfigStorage.getHttpProxyHost(); } @Override public int getHttpProxyPort() { - return 0; + return this.wxOpenConfigStorage.getHttpProxyPort(); } @Override public String getHttpProxyUsername() { - return null; + return this.wxOpenConfigStorage.getHttpProxyUsername(); } @Override public String getHttpProxyPassword() { - return null; + return this.wxOpenConfigStorage.getHttpProxyPassword(); } @Override 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 index 86404dfb6d..3745a15034 100644 --- 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 @@ -1,7 +1,9 @@ package me.chanjar.weixin.open.api.impl; +import org.apache.commons.lang3.StringUtils; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; +import redis.clients.util.Pool; /** * @author 007 @@ -15,7 +17,11 @@ public class WxOpenInRedisConfigStorage extends WxOpenInMemoryConfigStorage { 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; + protected final Pool jedisPool; + /** + * redis 存储的 key 的前缀,可为空 + */ + private String keyPrefix; private String componentVerifyTicketKey; private String componentAccessTokenKey; private String authorizerRefreshTokenKey; @@ -23,6 +29,15 @@ public class WxOpenInRedisConfigStorage extends WxOpenInMemoryConfigStorage { private String jsapiTicketKey; private String cardApiTicket; + public WxOpenInRedisConfigStorage(Pool jedisPool) { + this.jedisPool = jedisPool; + } + + public WxOpenInRedisConfigStorage(Pool jedisPool, String keyPrefix) { + this.jedisPool = jedisPool; + this.keyPrefix = keyPrefix; + } + public WxOpenInRedisConfigStorage(JedisPool jedisPool) { this.jedisPool = jedisPool; } @@ -30,10 +45,12 @@ public WxOpenInRedisConfigStorage(JedisPool jedisPool) { @Override public void setComponentAppId(String componentAppId) { super.setComponentAppId(componentAppId); - this.componentVerifyTicketKey = COMPONENT_VERIFY_TICKET_KEY.concat(componentAppId); - this.componentAccessTokenKey = COMPONENT_ACCESS_TOKEN_KEY.concat(componentAppId); - this.authorizerRefreshTokenKey = AUTHORIZER_REFRESH_TOKEN_KEY.concat(componentAppId); - this.authorizerAccessTokenKey = AUTHORIZER_ACCESS_TOKEN_KEY.concat(componentAppId); + String prefix = StringUtils.isBlank(keyPrefix) ? "" : + (StringUtils.endsWith(keyPrefix, ":") ? keyPrefix : (keyPrefix + ":")); + componentVerifyTicketKey = prefix + COMPONENT_VERIFY_TICKET_KEY.concat(componentAppId); + componentAccessTokenKey = prefix + COMPONENT_ACCESS_TOKEN_KEY.concat(componentAppId); + authorizerRefreshTokenKey = prefix + AUTHORIZER_REFRESH_TOKEN_KEY.concat(componentAppId); + authorizerAccessTokenKey = prefix + AUTHORIZER_ACCESS_TOKEN_KEY.concat(componentAppId); this.jsapiTicketKey = JSAPI_TICKET_KEY.concat(componentAppId); this.cardApiTicket = CARD_API_TICKET_KEY.concat(componentAppId); } @@ -66,6 +83,13 @@ public boolean isComponentAccessTokenExpired() { } } + @Override + public void expireComponentAccessToken(){ + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.expire(this.componentAccessTokenKey, 0); + } + } + @Override public void updateComponentAccessTokent(String componentAccessToken, int expiresInSeconds) { try (Jedis jedis = this.jedisPool.getResource()) { diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMaServiceImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMaServiceImpl.java index c0645d760a..acadd7e61d 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMaServiceImpl.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMaServiceImpl.java @@ -1,15 +1,12 @@ package me.chanjar.weixin.open.api.impl; +import cn.binarywang.wx.miniapp.api.WxMaUserService; import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import cn.binarywang.wx.miniapp.config.WxMaConfig; -import com.google.common.base.Joiner; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.open.api.WxOpenComponentService; -import java.util.HashMap; -import java.util.Map; - /** * @author 007 */ @@ -38,5 +35,4 @@ public WxMaConfig getWxMaConfig() { public String getAccessToken(boolean forceRefresh) throws WxErrorException { return wxOpenComponentService.getAuthorizerAccessToken(appId, forceRefresh); } - } 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 index 6c61b1fc2b..a946fb7014 100644 --- 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 @@ -1,6 +1,6 @@ package me.chanjar.weixin.open.api.impl; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpConfigStorage; import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; 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 index 5ace633f3c..4949726402 100644 --- 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 @@ -1,7 +1,7 @@ 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.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.open.api.WxOpenComponentService; @@ -33,8 +33,14 @@ public WxOpenConfigStorage getWxOpenConfigStorage() { @Override public void setWxOpenConfigStorage(WxOpenConfigStorage wxOpenConfigStorage) { this.wxOpenConfigStorage = wxOpenConfigStorage; + this.initHttp(); } + /** + * 初始化 RequestHttp + */ + public abstract void initHttp(); + protected synchronized T execute(RequestExecutor executor, String uri, E data) throws WxErrorException { try { T result = executor.execute(uri, data); 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 index 58921e6957..e428af5657 100644 --- 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 @@ -1,10 +1,11 @@ package me.chanjar.weixin.open.api.impl; -import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.error.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 me.chanjar.weixin.open.api.WxOpenConfigStorage; import org.apache.http.HttpHost; import org.apache.http.impl.client.CloseableHttpClient; @@ -14,8 +15,21 @@ * @author 007 */ public class WxOpenServiceApacheHttpClientImpl extends WxOpenServiceAbstractImpl { - private CloseableHttpClient httpClient = DefaultApacheHttpClientBuilder.get().build(); - private HttpHost httpProxy = null; + private CloseableHttpClient httpClient; + private HttpHost httpProxy; + + @Override + public void initHttp() { + WxOpenConfigStorage configStorage = this.getWxOpenConfigStorage(); + if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) { + this.httpProxy = new HttpHost(configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort()); + } + this.httpClient = DefaultApacheHttpClientBuilder.get() + .httpProxyHost(configStorage.getHttpProxyHost()) + .httpProxyPort(configStorage.getHttpProxyPort()) + .httpProxyUsername(configStorage.getHttpProxyUsername()) + .httpProxyPassword(configStorage.getHttpProxyPassword()).build(); + } @Override public CloseableHttpClient getRequestHttpClient() { @@ -41,5 +55,4 @@ public String get(String url, String queryParam) throws WxErrorException { 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/bean/WxOpenMaCodeTemplate.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/WxOpenMaCodeTemplate.java new file mode 100644 index 0000000000..be1bb9b138 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/WxOpenMaCodeTemplate.java @@ -0,0 +1,40 @@ +package me.chanjar.weixin.open.bean; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author Charming + * @since 2018-04-26 17:10 + */ +@Data +public class WxOpenMaCodeTemplate implements Serializable { + private static final long serialVersionUID = -3278116984473619010L; + /** + * 草稿id + */ + @SerializedName(value = "draftId", alternate = "draft_id") + private Long draftId; + /** + * 模版id + */ + @SerializedName(value = "templateId", alternate = "template_id") + private Long templateId; + /** + * 模版版本号,开发者自定义字段 + */ + @SerializedName(value = "userVersion", alternate = "user_version") + private String userVersion; + /** + * 模版描述 开发者自定义字段 + */ + @SerializedName(value = "userDesc", alternate = "user_desc") + private String userDesc; + /** + * 开发者上传草稿时间 / 被添加为模版的时间 + */ + @SerializedName(value = "createTime", alternate = "create_time") + private Long createTime; +} 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 index 95c70f10e5..0065748ab9 100644 --- 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 @@ -60,7 +60,6 @@ public 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)); diff --git a/weixin-java-pay/pom.xml b/weixin-java-pay/pom.xml index f38851917a..3410569769 100644 --- a/weixin-java-pay/pom.xml +++ b/weixin-java-pay/pom.xml @@ -5,7 +5,7 @@