| @@ -15,9 +15,6 @@ import me.chanjar.weixin.mp.enums.AiLangType; | |||||
| * @author <a href="https://github.com/binarywang">Binary Wang</a> | * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||
| */ | */ | ||||
| public interface WxMpAiOpenService { | public interface WxMpAiOpenService { | ||||
| String TRANSLATE_URL = "http://api.weixin.qq.com/cgi-bin/media/voice/translatecontent?lfrom=%s<o=%s"; | |||||
| 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"; | |||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| @@ -11,27 +11,6 @@ import me.chanjar.weixin.mp.bean.card.*; | |||||
| * @author yuanqixun 2018-08-29 | * @author yuanqixun 2018-08-29 | ||||
| */ | */ | ||||
| public interface WxMpCardService { | public interface WxMpCardService { | ||||
| String CARD_CREATE = "https://api.weixin.qq.com/card/create"; | |||||
| String CARD_GET = "https://api.weixin.qq.com/card/get"; | |||||
| String CARD_GET_TICKET = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=wx_card"; | |||||
| String CARD_CODE_DECRYPT = "https://api.weixin.qq.com/card/code/decrypt"; | |||||
| String CARD_CODE_GET = "https://api.weixin.qq.com/card/code/get"; | |||||
| String CARD_CODE_CONSUME = "https://api.weixin.qq.com/card/code/consume"; | |||||
| String CARD_CODE_MARK = "https://api.weixin.qq.com/card/code/mark"; | |||||
| String CARD_TEST_WHITELIST = "https://api.weixin.qq.com/card/testwhitelist/set"; | |||||
| String CARD_QRCODE_CREATE = "https://api.weixin.qq.com/card/qrcode/create"; | |||||
| String CARD_LANDING_PAGE_CREATE = "https://api.weixin.qq.com/card/landingpage/create"; | |||||
| /** | |||||
| * 将用户的卡券设置为失效状态. | |||||
| */ | |||||
| String CARD_CODE_UNAVAILABLE = "https://api.weixin.qq.com/card/code/unavailable"; | |||||
| /** | |||||
| * 卡券删除. | |||||
| */ | |||||
| String CARD_DELETE = "https://api.weixin.qq.com/card/delete"; | |||||
| /** | /** | ||||
| * 得到WxMpService. | * 得到WxMpService. | ||||
| */ | */ | ||||
| @@ -13,7 +13,6 @@ import me.chanjar.weixin.mp.enums.TicketType; | |||||
| * @author chanjarster | * @author chanjarster | ||||
| */ | */ | ||||
| public interface WxMpConfigStorage { | public interface WxMpConfigStorage { | ||||
| String getAccessToken(); | String getAccessToken(); | ||||
| Lock getAccessTokenLock(); | Lock getAccessTokenLock(); | ||||
| @@ -13,24 +13,6 @@ import java.util.List; | |||||
| * @author binarywang (https://github.com/binarywang) | * @author binarywang (https://github.com/binarywang) | ||||
| */ | */ | ||||
| public interface WxMpDataCubeService { | public interface WxMpDataCubeService { | ||||
| String GET_USER_SUMMARY = "https://api.weixin.qq.com/datacube/getusersummary"; | |||||
| String GET_USER_CUMULATE = "https://api.weixin.qq.com/datacube/getusercumulate"; | |||||
| String GET_ARTICLE_SUMMARY = "https://api.weixin.qq.com/datacube/getarticlesummary"; | |||||
| String GET_ARTICLE_TOTAL = "https://api.weixin.qq.com/datacube/getarticletotal"; | |||||
| String GET_USER_READ = "https://api.weixin.qq.com/datacube/getuserread"; | |||||
| String GET_USER_READ_HOUR = "https://api.weixin.qq.com/datacube/getuserreadhour"; | |||||
| String GET_USER_SHARE = "https://api.weixin.qq.com/datacube/getusershare"; | |||||
| String GET_USER_SHARE_HOUR = "https://api.weixin.qq.com/datacube/getusersharehour"; | |||||
| String GET_UPSTREAM_MSG = "https://api.weixin.qq.com/datacube/getupstreammsg"; | |||||
| String GET_UPSTREAM_MSG_HOUR = "https://api.weixin.qq.com/datacube/getupstreammsghour"; | |||||
| String GET_UPSTREAM_MSG_WEEK = "https://api.weixin.qq.com/datacube/getupstreammsgweek"; | |||||
| String GET_UPSTREAM_MSG_MONTH = "https://api.weixin.qq.com/datacube/getupstreammsgmonth"; | |||||
| String GET_UPSTREAM_MSG_DIST = "https://api.weixin.qq.com/datacube/getupstreammsgdist"; | |||||
| String GET_UPSTREAM_MSG_DIST_WEEK = "https://api.weixin.qq.com/datacube/getupstreammsgdistweek"; | |||||
| String GET_UPSTREAM_MSG_DIST_MONTH = "https://api.weixin.qq.com/datacube/getupstreammsgdistmonth"; | |||||
| String GET_INTERFACE_SUMMARY = "https://api.weixin.qq.com/datacube/getinterfacesummary"; | |||||
| String GET_INTERFACE_SUMMARY_HOUR = "https://api.weixin.qq.com/datacube/getinterfacesummaryhour"; | |||||
| //*******************用户分析数据接口***********************// | //*******************用户分析数据接口***********************// | ||||
| /** | /** | ||||
| @@ -5,6 +5,8 @@ import me.chanjar.weixin.mp.bean.device.*; | |||||
| /** | /** | ||||
| * Created by keungtung on 10/12/2016. | * Created by keungtung on 10/12/2016. | ||||
| * | |||||
| * @author keungtung | |||||
| */ | */ | ||||
| public interface WxMpDeviceService { | public interface WxMpDeviceService { | ||||
| /** | /** | ||||
| @@ -22,22 +22,6 @@ import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionWaitCaseList; | |||||
| * @author Binary Wang | * @author Binary Wang | ||||
| */ | */ | ||||
| public interface WxMpKefuService { | public interface WxMpKefuService { | ||||
| String MESSAGE_CUSTOM_SEND = "https://api.weixin.qq.com/cgi-bin/message/custom/send"; | |||||
| String GET_KF_LIST = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist"; | |||||
| String GET_ONLINE_KF_LIST = "https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist"; | |||||
| String KFACCOUNT_ADD = "https://api.weixin.qq.com/customservice/kfaccount/add"; | |||||
| String KFACCOUNT_UPDATE = "https://api.weixin.qq.com/customservice/kfaccount/update"; | |||||
| String KFACCOUNT_INVITE_WORKER = "https://api.weixin.qq.com/customservice/kfaccount/inviteworker"; | |||||
| String KFACCOUNT_UPLOAD_HEAD_IMG = "https://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?kf_account=%s"; | |||||
| String KFACCOUNT_DEL = "https://api.weixin.qq.com/customservice/kfaccount/del?kf_account=%s"; | |||||
| String KFSESSION_CREATE = "https://api.weixin.qq.com/customservice/kfsession/create"; | |||||
| String KFSESSION_CLOSE = "https://api.weixin.qq.com/customservice/kfsession/close"; | |||||
| String KFSESSION_GET_SESSION = "https://api.weixin.qq.com/customservice/kfsession/getsession?openid=%s"; | |||||
| String KFSESSION_GET_SESSION_LIST = "https://api.weixin.qq.com/customservice/kfsession/getsessionlist?kf_account=%s"; | |||||
| String KFSESSION_GET_WAIT_CASE = "https://api.weixin.qq.com/customservice/kfsession/getwaitcase"; | |||||
| String MSG_RECORD_LIST = "https://api.weixin.qq.com/customservice/msgrecord/getmsglist"; | |||||
| String CUSTOM_TYPING = "https://api.weixin.qq.com/cgi-bin/message/custom/typing"; | |||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| * 发送客服消息 | * 发送客服消息 | ||||
| @@ -18,8 +18,6 @@ import java.util.List; | |||||
| * @author <a href="https://github.com/007gzs">007</a> | * @author <a href="https://github.com/007gzs">007</a> | ||||
| */ | */ | ||||
| public interface WxMpMarketingService { | public interface WxMpMarketingService { | ||||
| String API_URL_PREFIX = "https://api.weixin.qq.com/marketing/"; | |||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| * 创建数据源 | * 创建数据源 | ||||
| @@ -14,31 +14,6 @@ import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; | |||||
| * @author <a href="https://github.com/binarywang">Binary Wang</a> | * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||
| */ | */ | ||||
| public interface WxMpMassMessageService { | public interface WxMpMassMessageService { | ||||
| /** | |||||
| * 上传群发用的图文消息. | |||||
| */ | |||||
| String MEDIA_UPLOAD_NEWS_URL = "https://api.weixin.qq.com/cgi-bin/media/uploadnews"; | |||||
| /** | |||||
| * 上传群发用的视频. | |||||
| */ | |||||
| String MEDIA_UPLOAD_VIDEO_URL = "https://api.weixin.qq.com/cgi-bin/media/uploadvideo"; | |||||
| /** | |||||
| * 分组群发消息. | |||||
| */ | |||||
| String MESSAGE_MASS_SENDALL_URL = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall"; | |||||
| /** | |||||
| * 按openId列表群发消息. | |||||
| */ | |||||
| String MESSAGE_MASS_SEND_URL = "https://api.weixin.qq.com/cgi-bin/message/mass/send"; | |||||
| /** | |||||
| * 群发消息预览接口. | |||||
| */ | |||||
| String MESSAGE_MASS_PREVIEW_URL = "https://api.weixin.qq.com/cgi-bin/message/mass/preview"; | |||||
| /** | |||||
| * 删除群发接口. | |||||
| */ | |||||
| String MESSAGE_MASS_DELETE_URL = "https://api.weixin.qq.com/cgi-bin/message/mass/delete"; | |||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| * 上传群发用的图文消息,上传后才能群发图文消息. | * 上传群发用的图文消息,上传后才能群发图文消息. | ||||
| @@ -85,7 +60,8 @@ public interface WxMpMassMessageService { | |||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| * 群发消息预览接口. | * 群发消息预览接口. | ||||
| * 开发者可通过该接口发送消息给指定用户,在手机端查看消息的样式和排版。为了满足第三方平台开发者的需求,在保留对openID预览能力的同时,增加了对指定微信号发送预览的能力,但该能力每日调用次数有限制(100次),请勿滥用。 | |||||
| * 开发者可通过该接口发送消息给指定用户,在手机端查看消息的样式和排版。为了满足第三方平台开发者的需求, | |||||
| * 在保留对openID预览能力的同时,增加了对指定微信号发送预览的能力,但该能力每日调用次数有限制(100次),请勿滥用。 | |||||
| * 接口调用请求说明 | * 接口调用请求说明 | ||||
| * http请求方式: POST | * http请求方式: POST | ||||
| * https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token=ACCESS_TOKEN | * https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token=ACCESS_TOKEN | ||||
| @@ -22,19 +22,10 @@ import me.chanjar.weixin.mp.bean.material.WxMpMaterialVideoInfoResult; | |||||
| * 即以https://api.weixin.qq.com/cgi-bin/material | * 即以https://api.weixin.qq.com/cgi-bin/material | ||||
| * 和 https://api.weixin.qq.com/cgi-bin/media开头的接口 | * 和 https://api.weixin.qq.com/cgi-bin/media开头的接口 | ||||
| * </pre> | * </pre> | ||||
| * | |||||
| * @author Binary Wang | |||||
| */ | */ | ||||
| public interface WxMpMaterialService { | public interface WxMpMaterialService { | ||||
| String MEDIA_GET_URL = "https://api.weixin.qq.com/cgi-bin/media/get"; | |||||
| String MEDIA_UPLOAD_URL = "https://api.weixin.qq.com/cgi-bin/media/upload?type=%s"; | |||||
| String IMG_UPLOAD_URL = "https://api.weixin.qq.com/cgi-bin/media/uploadimg"; | |||||
| String MATERIAL_ADD_URL = "https://api.weixin.qq.com/cgi-bin/material/add_material?type=%s"; | |||||
| String NEWS_ADD_URL = "https://api.weixin.qq.com/cgi-bin/material/add_news"; | |||||
| String MATERIAL_GET_URL = "https://api.weixin.qq.com/cgi-bin/material/get_material"; | |||||
| String NEWS_UPDATE_URL = "https://api.weixin.qq.com/cgi-bin/material/update_news"; | |||||
| String MATERIAL_DEL_URL = "https://api.weixin.qq.com/cgi-bin/material/del_material"; | |||||
| String MATERIAL_GET_COUNT_URL = "https://api.weixin.qq.com/cgi-bin/material/get_materialcount"; | |||||
| String MATERIAL_BATCHGET_URL = "https://api.weixin.qq.com/cgi-bin/material/batchget_material"; | |||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| * 新增临时素材 | * 新增临时素材 | ||||
| @@ -17,31 +17,6 @@ import me.chanjar.weixin.mp.bean.membercard.*; | |||||
| * @date 2018-08-30 | * @date 2018-08-30 | ||||
| */ | */ | ||||
| public interface WxMpMemberCardService { | public interface WxMpMemberCardService { | ||||
| String MEMBER_CARD_CREATE = "https://api.weixin.qq.com/card/create"; | |||||
| String MEMBER_CARD_ACTIVATE = "https://api.weixin.qq.com/card/membercard/activate"; | |||||
| String MEMBER_CARD_USER_INFO_GET = "https://api.weixin.qq.com/card/membercard/userinfo/get"; | |||||
| String MEMBER_CARD_UPDATE_USER = "https://api.weixin.qq.com/card/membercard/updateuser"; | |||||
| /** | |||||
| * 会员卡激活之微信开卡接口(wx_activate=true情况调用). | |||||
| */ | |||||
| String MEMBER_CARD_ACTIVATE_USER_FORM = "https://api.weixin.qq.com/card/membercard/activateuserform/set"; | |||||
| /** | |||||
| * 获取会员卡开卡插件参数. | |||||
| */ | |||||
| String MEMBER_CARD_ACTIVATE_URL = "https://api.weixin.qq.com/card/membercard/activate/geturl"; | |||||
| /** | |||||
| * 会员卡信息更新. | |||||
| */ | |||||
| String MEMBER_CARD_UPDATE = "https://api.weixin.qq.com/card/update"; | |||||
| /** | |||||
| * 跳转型会员卡开卡字段. | |||||
| * 获取用户提交资料(wx_activate=true情况调用),开发者根据activate_ticket获取到用户填写的信息 | |||||
| */ | |||||
| String MEMBER_CARD_ACTIVATE_TEMP_INFO = "https://api.weixin.qq.com/card/membercard/activatetempinfo/get"; | |||||
| /** | /** | ||||
| * 得到WxMpService. | * 得到WxMpService. | ||||
| * | * | ||||
| @@ -6,12 +6,11 @@ import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult; | |||||
| import me.chanjar.weixin.mp.bean.menu.WxMpMenu; | import me.chanjar.weixin.mp.bean.menu.WxMpMenu; | ||||
| /** | /** | ||||
| * 菜单相关操作接口 | |||||
| * 菜单相关操作接口. | |||||
| * | * | ||||
| * @author Binary Wang | * @author Binary Wang | ||||
| */ | */ | ||||
| public interface WxMpMenuService { | public interface WxMpMenuService { | ||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| * 自定义菜单创建接口 | * 自定义菜单创建接口 | ||||
| @@ -14,7 +14,6 @@ import java.io.File; | |||||
| * @author Binary Wang | * @author Binary Wang | ||||
| */ | */ | ||||
| public interface WxMpQrcodeService { | public interface WxMpQrcodeService { | ||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| * 换取临时二维码ticket | * 换取临时二维码ticket | ||||
| @@ -5,13 +5,13 @@ import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; | import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; | ||||
| import me.chanjar.weixin.common.util.http.RequestExecutor; | import me.chanjar.weixin.common.util.http.RequestExecutor; | ||||
| import me.chanjar.weixin.common.util.http.RequestHttp; | import me.chanjar.weixin.common.util.http.RequestHttp; | ||||
| import me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl; | |||||
| import me.chanjar.weixin.mp.bean.WxMpSemanticQuery; | import me.chanjar.weixin.mp.bean.WxMpSemanticQuery; | ||||
| import me.chanjar.weixin.mp.bean.result.WxMpCurrentAutoReplyInfo; | import me.chanjar.weixin.mp.bean.result.WxMpCurrentAutoReplyInfo; | ||||
| import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | ||||
| import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; | import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; | ||||
| import me.chanjar.weixin.mp.bean.result.WxMpUser; | import me.chanjar.weixin.mp.bean.result.WxMpUser; | ||||
| import me.chanjar.weixin.mp.enums.TicketType; | import me.chanjar.weixin.mp.enums.TicketType; | ||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| @@ -21,61 +21,6 @@ import java.util.Map; | |||||
| * @author chanjarster | * @author chanjarster | ||||
| */ | */ | ||||
| public interface WxMpService { | public interface WxMpService { | ||||
| /** | |||||
| * 获取access_token. | |||||
| */ | |||||
| String GET_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s"; | |||||
| /** | |||||
| * 获得各种类型的ticket. | |||||
| */ | |||||
| String GET_TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type="; | |||||
| /** | |||||
| * 长链接转短链接接口. | |||||
| */ | |||||
| String SHORTURL_API_URL = "https://api.weixin.qq.com/cgi-bin/shorturl"; | |||||
| /** | |||||
| * 语义查询接口. | |||||
| */ | |||||
| String SEMANTIC_SEMPROXY_SEARCH_URL = "https://api.weixin.qq.com/semantic/semproxy/search"; | |||||
| /** | |||||
| * 用code换取oauth2的access token. | |||||
| */ | |||||
| String OAUTH2_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code"; | |||||
| /** | |||||
| * 刷新oauth2的access token. | |||||
| */ | |||||
| String OAUTH2_REFRESH_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=%s&grant_type=refresh_token&refresh_token=%s"; | |||||
| /** | |||||
| * 用oauth2获取用户信息. | |||||
| */ | |||||
| String OAUTH2_USERINFO_URL = "https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=%s"; | |||||
| /** | |||||
| * 验证oauth2的access token是否有效. | |||||
| */ | |||||
| String OAUTH2_VALIDATE_TOKEN_URL = "https://api.weixin.qq.com/sns/auth?access_token=%s&openid=%s"; | |||||
| /** | |||||
| * 获取微信服务器IP地址. | |||||
| */ | |||||
| String GET_CALLBACK_IP_URL = "https://api.weixin.qq.com/cgi-bin/getcallbackip"; | |||||
| /** | |||||
| * 第三方使用网站应用授权登录的url. | |||||
| */ | |||||
| String QRCONNECT_URL = "https://open.weixin.qq.com/connect/qrconnect?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect"; | |||||
| /** | |||||
| * 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&connect_redirect=1#wechat_redirect"; | |||||
| /** | |||||
| * 获取公众号的自动回复规则. | |||||
| */ | |||||
| String GET_CURRENT_AUTOREPLY_INFO_URL = "https://api.weixin.qq.com/cgi-bin/get_current_autoreply_info"; | |||||
| /** | |||||
| * 公众号调用或第三方平台帮公众号调用对公众号的所有api调用(包括第三方帮其调用)次数进行清零. | |||||
| */ | |||||
| String CLEAR_QUOTA_URL = "https://api.weixin.qq.com/cgi-bin/clear_quota"; | |||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| * 验证消息的确来自微信服务器. | * 验证消息的确来自微信服务器. | ||||
| @@ -158,7 +103,7 @@ public interface WxMpService { | |||||
| * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=长链接转短链接接口 | * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=长链接转短链接接口 | ||||
| * </pre> | * </pre> | ||||
| */ | */ | ||||
| String shortUrl(String long_url) throws WxErrorException; | |||||
| String shortUrl(String longUrl) throws WxErrorException; | |||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| @@ -264,11 +209,21 @@ public interface WxMpService { | |||||
| /** | /** | ||||
| * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求. | * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求. | ||||
| * | |||||
| * @param queryParam 参数 | |||||
| * @param url 请求接口地址 | |||||
| * @return 接口响应字符串 | |||||
| * @throws WxErrorException 异常 | |||||
| */ | */ | ||||
| String get(String url, String queryParam) throws WxErrorException; | String get(String url, String queryParam) throws WxErrorException; | ||||
| /** | /** | ||||
| * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的POST请求. | * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的POST请求. | ||||
| * | |||||
| * @param postData 请求参数json值 | |||||
| * @param url 请求接口地址 | |||||
| * @return 接口响应字符串 | |||||
| * @throws WxErrorException 异常 | |||||
| */ | */ | ||||
| String post(String url, String postData) throws WxErrorException; | String post(String url, String postData) throws WxErrorException; | ||||
| @@ -278,14 +233,54 @@ public interface WxMpService { | |||||
| * 比{@link #get}和{@link #post}方法更灵活,可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。 | * 比{@link #get}和{@link #post}方法更灵活,可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。 | ||||
| * 可以参考,{@link MediaUploadRequestExecutor}的实现方法 | * 可以参考,{@link MediaUploadRequestExecutor}的实现方法 | ||||
| * </pre> | * </pre> | ||||
| * | |||||
| * @param data 参数数据 | |||||
| * @param executor 执行器 | |||||
| * @param url 接口地址 | |||||
| * @return 结果 | |||||
| * @throws WxErrorException 异常 | |||||
| */ | |||||
| <T, E> T execute(RequestExecutor<T, E> executor, String url, E data) throws WxErrorException; | |||||
| /** | |||||
| * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求. | |||||
| * | |||||
| * @param queryParam 参数 | |||||
| * @param url 请求接口地址 | |||||
| * @return 接口响应字符串 | |||||
| * @throws WxErrorException 异常 | |||||
| */ | |||||
| String get(WxMpApiUrl url, String queryParam) throws WxErrorException; | |||||
| /** | |||||
| * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的POST请求. | |||||
| * | |||||
| * @param postData 请求参数json值 | |||||
| * @param url 请求接口地址 | |||||
| * @return 接口响应字符串 | |||||
| * @throws WxErrorException 异常 | |||||
| */ | */ | ||||
| <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException; | |||||
| String post(WxMpApiUrl url, String postData) throws WxErrorException; | |||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| * Service没有实现某个API的时候,可以用这个, | |||||
| * 比{@link #get}和{@link #post}方法更灵活,可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。 | |||||
| * 可以参考,{@link MediaUploadRequestExecutor}的实现方法 | |||||
| * </pre> | |||||
| * | |||||
| * @param data 参数数据 | |||||
| * @param executor 执行器 | |||||
| * @param url 接口地址 | |||||
| * @return 结果 | |||||
| * @throws WxErrorException 异常 | |||||
| */ | |||||
| <T, E> T execute(RequestExecutor<T, E> executor, WxMpApiUrl url, E data) throws WxErrorException; | |||||
| /** | |||||
| * 设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试. | * 设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试. | ||||
| * | |||||
| * @param retrySleepMillis 默认:1000ms | * @param retrySleepMillis 默认:1000ms | ||||
| * </pre> | |||||
| */ | */ | ||||
| void setRetrySleepMillis(int retrySleepMillis); | void setRetrySleepMillis(int retrySleepMillis); | ||||
| @@ -311,12 +306,14 @@ public interface WxMpService { | |||||
| /** | /** | ||||
| * {@link Map<String, WxMpConfigStorage>} 加入新的 {@link WxMpConfigStorage},适用于动态添加新的微信公众号配置 | * {@link Map<String, WxMpConfigStorage>} 加入新的 {@link WxMpConfigStorage},适用于动态添加新的微信公众号配置 | ||||
| * | |||||
| * @param configStorage 新的微信配置 | * @param configStorage 新的微信配置 | ||||
| */ | */ | ||||
| void addConfigStorage(String mpId, WxMpConfigStorage configStorage); | void addConfigStorage(String mpId, WxMpConfigStorage configStorage); | ||||
| /** | /** | ||||
| * 从{@link Map<String, WxMpConfigStorage>} 移除 {@link String mpId} 所对应的 {@link WxMpConfigStorage},适用于动态移除微信公众号配置 | * 从{@link Map<String, WxMpConfigStorage>} 移除 {@link String mpId} 所对应的 {@link WxMpConfigStorage},适用于动态移除微信公众号配置 | ||||
| * | |||||
| * @param mpId 对应公众号的标识 | * @param mpId 对应公众号的标识 | ||||
| */ | */ | ||||
| void removeConfigStorage(String mpId); | void removeConfigStorage(String mpId); | ||||
| @@ -324,19 +321,22 @@ public interface WxMpService { | |||||
| /** | /** | ||||
| * 注入多个 {@link WxMpConfigStorage} 的实现. 并为每个 {@link WxMpConfigStorage} 赋予不同的 {@link String mpId} 值 | * 注入多个 {@link WxMpConfigStorage} 的实现. 并为每个 {@link WxMpConfigStorage} 赋予不同的 {@link String mpId} 值 | ||||
| * 随机采用一个{@link String mpId}进行Http初始化操作 | * 随机采用一个{@link String mpId}进行Http初始化操作 | ||||
| * | |||||
| * @param configStorages WxMpConfigStorage map | * @param configStorages WxMpConfigStorage map | ||||
| */ | */ | ||||
| void setMultiConfigStorages(Map<String, WxMpConfigStorage> configStorages); | void setMultiConfigStorages(Map<String, WxMpConfigStorage> configStorages); | ||||
| /** | /** | ||||
| * 注入多个 {@link WxMpConfigStorage} 的实现. 并为每个 {@link WxMpConfigStorage} 赋予不同的 {@link String label} 值 | * 注入多个 {@link WxMpConfigStorage} 的实现. 并为每个 {@link WxMpConfigStorage} 赋予不同的 {@link String label} 值 | ||||
| * | |||||
| * @param configStorages WxMpConfigStorage map | * @param configStorages WxMpConfigStorage map | ||||
| * @param defaultMpId 设置一个{@link WxMpConfigStorage} 所对应的{@link String mpId}进行Http初始化 | |||||
| * @param defaultMpId 设置一个{@link WxMpConfigStorage} 所对应的{@link String mpId}进行Http初始化 | |||||
| */ | */ | ||||
| void setMultiConfigStorages(Map<String, WxMpConfigStorage> configStorages, String defaultMpId); | void setMultiConfigStorages(Map<String, WxMpConfigStorage> configStorages, String defaultMpId); | ||||
| /** | /** | ||||
| * 进行相应的公众号切换 | * 进行相应的公众号切换 | ||||
| * | |||||
| * @param mpId 公众号标识 | * @param mpId 公众号标识 | ||||
| * @return 切换是否成功 | * @return 切换是否成功 | ||||
| */ | */ | ||||
| @@ -344,6 +344,7 @@ public interface WxMpService { | |||||
| /** | /** | ||||
| * 进行相应的公众号切换 | * 进行相应的公众号切换 | ||||
| * | |||||
| * @param mpId 公众号标识 | * @param mpId 公众号标识 | ||||
| * @return 切换成功,则返回当前对象,方便链式调用,否则抛出异常 | * @return 切换成功,则返回当前对象,方便链式调用,否则抛出异常 | ||||
| */ | */ | ||||
| @@ -7,12 +7,11 @@ import me.chanjar.weixin.mp.bean.WxMpShakeQuery; | |||||
| import me.chanjar.weixin.mp.bean.shake.*; | import me.chanjar.weixin.mp.bean.shake.*; | ||||
| /** | /** | ||||
| * 摇一摇周边的相关接口 | |||||
| * 摇一摇周边的相关接口. | |||||
| * | * | ||||
| * @author rememberber | * @author rememberber | ||||
| */ | */ | ||||
| public interface WxMpShakeService { | public interface WxMpShakeService { | ||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| * 获取设备及用户信息<br/> | * 获取设备及用户信息<br/> | ||||
| @@ -8,20 +8,12 @@ import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult; | |||||
| import java.util.List; | import java.util.List; | ||||
| /** | /** | ||||
| * 门店管理的相关接口代码 | |||||
| * <p> | |||||
| * 门店管理的相关接口代码. | |||||
| * Created by Binary Wang on 2016-09-23. | * Created by Binary Wang on 2016-09-23. | ||||
| * | * | ||||
| * @author <a href="https://github.com/binarywang">Binary Wang</a> | * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||
| */ | */ | ||||
| public interface WxMpStoreService<H, P> { | public interface WxMpStoreService<H, P> { | ||||
| String POI_GET_WX_CATEGORY_URL = "https://api.weixin.qq.com/cgi-bin/poi/getwxcategory"; | |||||
| String POI_UPDATE_URL = "https://api.weixin.qq.com/cgi-bin/poi/updatepoi"; | |||||
| String POI_LIST_URL = "https://api.weixin.qq.com/cgi-bin/poi/getpoilist"; | |||||
| String POI_DEL_URL = "https://api.weixin.qq.com/cgi-bin/poi/delpoi"; | |||||
| String POI_GET_URL = "https://api.weixin.qq.com/cgi-bin/poi/getpoi"; | |||||
| String POI_ADD_URL = "https://api.weixin.qq.com/cgi-bin/poi/addpoi"; | |||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| * 创建门店 | * 创建门店 | ||||
| @@ -13,7 +13,6 @@ import me.chanjar.weixin.mp.bean.subscribe.WxMpSubscribeMessage; | |||||
| * @date 2018-01-22 上午11:07 | * @date 2018-01-22 上午11:07 | ||||
| */ | */ | ||||
| public interface WxMpSubscribeMsgService { | public interface WxMpSubscribeMsgService { | ||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| * 构造用户订阅一条模板消息授权的url连接 | * 构造用户订阅一条模板消息授权的url连接 | ||||
| @@ -17,7 +17,6 @@ import java.util.List; | |||||
| * </pre> | * </pre> | ||||
| */ | */ | ||||
| public interface WxMpTemplateMsgService { | public interface WxMpTemplateMsgService { | ||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| * 设置所属行业 | * 设置所属行业 | ||||
| @@ -1,25 +1,19 @@ | |||||
| package me.chanjar.weixin.mp.api; | package me.chanjar.weixin.mp.api; | ||||
| import java.util.List; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.mp.bean.WxMpUserQuery; | import me.chanjar.weixin.mp.bean.WxMpUserQuery; | ||||
| import me.chanjar.weixin.mp.bean.result.WxMpChangeOpenid; | import me.chanjar.weixin.mp.bean.result.WxMpChangeOpenid; | ||||
| import me.chanjar.weixin.mp.bean.result.WxMpUser; | import me.chanjar.weixin.mp.bean.result.WxMpUser; | ||||
| import me.chanjar.weixin.mp.bean.result.WxMpUserList; | import me.chanjar.weixin.mp.bean.result.WxMpUserList; | ||||
| import java.util.List; | |||||
| /** | /** | ||||
| * 用户管理相关操作接口. | * 用户管理相关操作接口. | ||||
| * | * | ||||
| * @author Binary Wang | * @author Binary Wang | ||||
| */ | */ | ||||
| public interface WxMpUserService { | public interface WxMpUserService { | ||||
| String USER_INFO_BATCH_GET_URL = "https://api.weixin.qq.com/cgi-bin/user/info/batchget"; | |||||
| String USER_GET_URL = "https://api.weixin.qq.com/cgi-bin/user/get"; | |||||
| String USER_INFO_URL = "https://api.weixin.qq.com/cgi-bin/user/info"; | |||||
| String USER_INFO_UPDATE_REMARK_URL = "https://api.weixin.qq.com/cgi-bin/user/info/updateremark"; | |||||
| String USER_CHANGE_OPENID_URL = "http://api.weixin.qq.com/cgi-bin/changeopenid"; | |||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| * 设置用户备注名 | * 设置用户备注名 | ||||
| @@ -87,7 +81,9 @@ public interface WxMpUserService { | |||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| * 获取用户列表 | * 获取用户列表 | ||||
| * 公众号可通过本接口来获取帐号的关注者列表,关注者列表由一串OpenID(加密后的微信号,每个用户对每个公众号的OpenID是唯一的)组成。一次拉取调用最多拉取10000个关注者的OpenID,可以通过多次拉取的方式来满足需求。 | |||||
| * 公众号可通过本接口来获取帐号的关注者列表, | |||||
| * 关注者列表由一串OpenID(加密后的微信号,每个用户对每个公众号的OpenID是唯一的)组成。 | |||||
| * 一次拉取调用最多拉取10000个关注者的OpenID,可以通过多次拉取的方式来满足需求。 | |||||
| * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140840&token=&lang=zh_CN | * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140840&token=&lang=zh_CN | ||||
| * http请求方式: GET(请使用https协议) | * http请求方式: GET(请使用https协议) | ||||
| * 接口地址:https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENID | * 接口地址:https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENID | ||||
| @@ -101,11 +97,12 @@ public interface WxMpUserService { | |||||
| * <pre> | * <pre> | ||||
| * 微信公众号主体变更迁移用户 openid | * 微信公众号主体变更迁移用户 openid | ||||
| * 详情请见: http://kf.qq.com/faq/170221aUnmmU170221eUZJNf.html | * 详情请见: http://kf.qq.com/faq/170221aUnmmU170221eUZJNf.html | ||||
| * http://kf.qq.com/faq/1901177NrqMr190117nqYJze.html | |||||
| * http请求方式: POST | * http请求方式: POST | ||||
| * 接口地址:https://api.weixin.qq.com/cgi-bin/changeopenid?access_token=ACCESS_TOKEN | * 接口地址:https://api.weixin.qq.com/cgi-bin/changeopenid?access_token=ACCESS_TOKEN | ||||
| * </pre> | * </pre> | ||||
| * | * | ||||
| * @param fromAppid 原公众号的 appid | |||||
| * @param fromAppid 原公众号的 appid | |||||
| * @param openidList 需要转换的openid,这些必须是旧账号目前关注的才行,否则会出错;一次最多100个 | * @param openidList 需要转换的openid,这些必须是旧账号目前关注的才行,否则会出错;一次最多100个 | ||||
| */ | */ | ||||
| List<WxMpChangeOpenid> changeOpenid(String fromAppid, List<String> openidList) throws WxErrorException; | List<WxMpChangeOpenid> changeOpenid(String fromAppid, List<String> openidList) throws WxErrorException; | ||||
| @@ -13,7 +13,6 @@ import java.util.List; | |||||
| * @author <a href="https://github.com/binarywang">Binary Wang</a> | * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||
| */ | */ | ||||
| public interface WxMpUserTagService { | public interface WxMpUserTagService { | ||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| * 创建标签 | * 创建标签 | ||||
| @@ -6,6 +6,7 @@ import com.google.gson.JsonArray; | |||||
| import com.google.gson.JsonElement; | import com.google.gson.JsonElement; | ||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||
| import com.google.gson.JsonParser; | import com.google.gson.JsonParser; | ||||
| import lombok.extern.slf4j.Slf4j; | |||||
| import me.chanjar.weixin.common.bean.WxJsapiSignature; | import me.chanjar.weixin.common.bean.WxJsapiSignature; | ||||
| import me.chanjar.weixin.common.error.WxError; | import me.chanjar.weixin.common.error.WxError; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| @@ -22,25 +23,25 @@ import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | |||||
| import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; | import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; | ||||
| import me.chanjar.weixin.mp.bean.result.WxMpUser; | import me.chanjar.weixin.mp.bean.result.WxMpUser; | ||||
| import me.chanjar.weixin.mp.enums.TicketType; | import me.chanjar.weixin.mp.enums.TicketType; | ||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import me.chanjar.weixin.mp.util.WxMpConfigStorageHolder; | import me.chanjar.weixin.mp.util.WxMpConfigStorageHolder; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.util.Map; | import java.util.Map; | ||||
| import java.util.concurrent.locks.Lock; | import java.util.concurrent.locks.Lock; | ||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Other.*; | |||||
| /** | /** | ||||
| * 基础实现类. | * 基础实现类. | ||||
| * | * | ||||
| * @author someone | * @author someone | ||||
| */ | */ | ||||
| @Slf4j | |||||
| public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestHttp<H, P> { | public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestHttp<H, P> { | ||||
| private static final JsonParser JSON_PARSER = new JsonParser(); | private static final JsonParser JSON_PARSER = new JsonParser(); | ||||
| protected final Logger log = LoggerFactory.getLogger(this.getClass()); | |||||
| protected WxSessionManager sessionManager = new StandardSessionManager(); | protected WxSessionManager sessionManager = new StandardSessionManager(); | ||||
| private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this); | private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this); | ||||
| private WxMpMaterialService materialService = new WxMpMaterialServiceImpl(this); | private WxMpMaterialService materialService = new WxMpMaterialServiceImpl(this); | ||||
| @@ -73,7 +74,7 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | |||||
| return SHA1.gen(this.getWxMpConfigStorage().getToken(), timestamp, nonce) | return SHA1.gen(this.getWxMpConfigStorage().getToken(), timestamp, nonce) | ||||
| .equals(signature); | .equals(signature); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| this.log.error("Checking signature failed, and the reason is :" + e.getMessage()); | |||||
| log.error("Checking signature failed, and the reason is :" + e.getMessage()); | |||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| @@ -94,7 +95,7 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | |||||
| if (this.getWxMpConfigStorage().isTicketExpired(type)) { | if (this.getWxMpConfigStorage().isTicketExpired(type)) { | ||||
| String responseContent = execute(SimpleGetRequestExecutor.create(this), | String responseContent = execute(SimpleGetRequestExecutor.create(this), | ||||
| WxMpService.GET_TICKET_URL + type.getCode(), null); | |||||
| GET_TICKET_URL + type.getCode(), null); | |||||
| JsonObject tmpJsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject(); | JsonObject tmpJsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject(); | ||||
| String jsapiTicket = tmpJsonObject.get("ticket").getAsString(); | String jsapiTicket = tmpJsonObject.get("ticket").getAsString(); | ||||
| int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt(); | int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt(); | ||||
| @@ -143,27 +144,27 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | |||||
| JsonObject o = new JsonObject(); | JsonObject o = new JsonObject(); | ||||
| o.addProperty("action", "long2short"); | o.addProperty("action", "long2short"); | ||||
| o.addProperty("long_url", longUrl); | o.addProperty("long_url", longUrl); | ||||
| String responseContent = this.post(WxMpService.SHORTURL_API_URL, o.toString()); | |||||
| String responseContent = this.post(SHORTURL_API_URL, o.toString()); | |||||
| JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent); | JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent); | ||||
| return tmpJsonElement.getAsJsonObject().get("short_url").getAsString(); | return tmpJsonElement.getAsJsonObject().get("short_url").getAsString(); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpSemanticQueryResult semanticQuery(WxMpSemanticQuery semanticQuery) throws WxErrorException { | public WxMpSemanticQueryResult semanticQuery(WxMpSemanticQuery semanticQuery) throws WxErrorException { | ||||
| String responseContent = this.post(WxMpService.SEMANTIC_SEMPROXY_SEARCH_URL, semanticQuery.toJson()); | |||||
| String responseContent = this.post(SEMANTIC_SEMPROXY_SEARCH_URL, semanticQuery.toJson()); | |||||
| return WxMpSemanticQueryResult.fromJson(responseContent); | return WxMpSemanticQueryResult.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state) { | public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state) { | ||||
| return String.format(WxMpService.CONNECT_OAUTH2_AUTHORIZE_URL, | |||||
| return String.format(CONNECT_OAUTH2_AUTHORIZE_URL.getUrl(), | |||||
| this.getWxMpConfigStorage().getAppId(), URIUtil.encodeURIComponent(redirectURI), scope, StringUtils.trimToEmpty(state)); | this.getWxMpConfigStorage().getAppId(), URIUtil.encodeURIComponent(redirectURI), scope, StringUtils.trimToEmpty(state)); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public String buildQrConnectUrl(String redirectURI, String scope, String state) { | public String buildQrConnectUrl(String redirectURI, String scope, String state) { | ||||
| return String.format(WxMpService.QRCONNECT_URL, | |||||
| this.getWxMpConfigStorage().getAppId(), URIUtil.encodeURIComponent(redirectURI), scope, StringUtils.trimToEmpty(state)); | |||||
| return String.format(QRCONNECT_URL.getUrl(), this.getWxMpConfigStorage().getAppId(), | |||||
| URIUtil.encodeURIComponent(redirectURI), scope, StringUtils.trimToEmpty(state)); | |||||
| } | } | ||||
| private WxMpOAuth2AccessToken getOAuth2AccessToken(String url) throws WxErrorException { | private WxMpOAuth2AccessToken getOAuth2AccessToken(String url) throws WxErrorException { | ||||
| @@ -178,13 +179,14 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | |||||
| @Override | @Override | ||||
| public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException { | public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException { | ||||
| String url = String.format(WxMpService.OAUTH2_ACCESS_TOKEN_URL, this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret(), code); | |||||
| String url = String.format(OAUTH2_ACCESS_TOKEN_URL.getUrl(), this.getWxMpConfigStorage().getAppId(), | |||||
| this.getWxMpConfigStorage().getSecret(), code); | |||||
| return this.getOAuth2AccessToken(url); | return this.getOAuth2AccessToken(url); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpOAuth2AccessToken oauth2refreshAccessToken(String refreshToken) throws WxErrorException { | public WxMpOAuth2AccessToken oauth2refreshAccessToken(String refreshToken) throws WxErrorException { | ||||
| String url = String.format(WxMpService.OAUTH2_REFRESH_TOKEN_URL, this.getWxMpConfigStorage().getAppId(), refreshToken); | |||||
| String url = String.format(OAUTH2_REFRESH_TOKEN_URL.getUrl(), this.getWxMpConfigStorage().getAppId(), refreshToken); | |||||
| return this.getOAuth2AccessToken(url); | return this.getOAuth2AccessToken(url); | ||||
| } | } | ||||
| @@ -194,7 +196,7 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | |||||
| lang = "zh_CN"; | lang = "zh_CN"; | ||||
| } | } | ||||
| String url = String.format(WxMpService.OAUTH2_USERINFO_URL, token.getAccessToken(), token.getOpenId(), lang); | |||||
| String url = String.format(OAUTH2_USERINFO_URL.getUrl(), token.getAccessToken(), token.getOpenId(), lang); | |||||
| try { | try { | ||||
| RequestExecutor<String, String> executor = SimpleGetRequestExecutor.create(this); | RequestExecutor<String, String> executor = SimpleGetRequestExecutor.create(this); | ||||
| @@ -207,7 +209,7 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | |||||
| @Override | @Override | ||||
| public boolean oauth2validateAccessToken(WxMpOAuth2AccessToken token) { | public boolean oauth2validateAccessToken(WxMpOAuth2AccessToken token) { | ||||
| String url = String.format(WxMpService.OAUTH2_VALIDATE_TOKEN_URL, token.getAccessToken(), token.getOpenId()); | |||||
| String url = String.format(OAUTH2_VALIDATE_TOKEN_URL.getUrl(), token.getAccessToken(), token.getOpenId()); | |||||
| try { | try { | ||||
| SimpleGetRequestExecutor.create(this).execute(url, null); | SimpleGetRequestExecutor.create(this).execute(url, null); | ||||
| @@ -221,7 +223,7 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | |||||
| @Override | @Override | ||||
| public String[] getCallbackIP() throws WxErrorException { | public String[] getCallbackIP() throws WxErrorException { | ||||
| String responseContent = this.get(WxMpService.GET_CALLBACK_IP_URL, null); | |||||
| String responseContent = this.get(GET_CALLBACK_IP_URL, null); | |||||
| JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent); | JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent); | ||||
| JsonArray ipList = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray(); | JsonArray ipList = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray(); | ||||
| String[] ipArray = new String[ipList.size()]; | String[] ipArray = new String[ipList.size()]; | ||||
| @@ -248,11 +250,26 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | |||||
| return execute(SimpleGetRequestExecutor.create(this), url, queryParam); | return execute(SimpleGetRequestExecutor.create(this), url, queryParam); | ||||
| } | } | ||||
| @Override | |||||
| public String get(WxMpApiUrl url, String queryParam) throws WxErrorException { | |||||
| return this.get(url.getUrl(), queryParam); | |||||
| } | |||||
| @Override | @Override | ||||
| public String post(String url, String postData) throws WxErrorException { | public String post(String url, String postData) throws WxErrorException { | ||||
| return execute(SimplePostRequestExecutor.create(this), url, postData); | return execute(SimplePostRequestExecutor.create(this), url, postData); | ||||
| } | } | ||||
| @Override | |||||
| public String post(WxMpApiUrl url, String postData) throws WxErrorException { | |||||
| return this.post(url.getUrl(), postData); | |||||
| } | |||||
| @Override | |||||
| public <T, E> T execute(RequestExecutor<T, E> executor, WxMpApiUrl url, E data) throws WxErrorException { | |||||
| return this.execute(executor, url.getUrl(), data); | |||||
| } | |||||
| /** | /** | ||||
| * 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求. | * 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求. | ||||
| */ | */ | ||||
| @@ -264,7 +281,7 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | |||||
| return this.executeInternal(executor, uri, data); | return this.executeInternal(executor, uri, data); | ||||
| } catch (WxErrorException e) { | } catch (WxErrorException e) { | ||||
| if (retryTimes + 1 > this.maxRetryTimes) { | if (retryTimes + 1 > this.maxRetryTimes) { | ||||
| this.log.warn("重试达到最大次数【{}】", maxRetryTimes); | |||||
| log.warn("重试达到最大次数【{}】", maxRetryTimes); | |||||
| //最后一次重试失败后,直接抛出异常,不再等待 | //最后一次重试失败后,直接抛出异常,不再等待 | ||||
| throw new RuntimeException("微信服务端异常,超出重试次数"); | throw new RuntimeException("微信服务端异常,超出重试次数"); | ||||
| } | } | ||||
| @@ -274,7 +291,7 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | |||||
| if (error.getErrorCode() == -1) { | if (error.getErrorCode() == -1) { | ||||
| int sleepMillis = this.retrySleepMillis * (1 << retryTimes); | int sleepMillis = this.retrySleepMillis * (1 << retryTimes); | ||||
| try { | try { | ||||
| this.log.warn("微信系统繁忙,{} ms 后重试(第{}次)", sleepMillis, retryTimes + 1); | |||||
| log.warn("微信系统繁忙,{} ms 后重试(第{}次)", sleepMillis, retryTimes + 1); | |||||
| Thread.sleep(sleepMillis); | Thread.sleep(sleepMillis); | ||||
| } catch (InterruptedException e1) { | } catch (InterruptedException e1) { | ||||
| throw new RuntimeException(e1); | throw new RuntimeException(e1); | ||||
| @@ -285,11 +302,11 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | |||||
| } | } | ||||
| } while (retryTimes++ < this.maxRetryTimes); | } while (retryTimes++ < this.maxRetryTimes); | ||||
| this.log.warn("重试达到最大次数【{}】", this.maxRetryTimes); | |||||
| log.warn("重试达到最大次数【{}】", this.maxRetryTimes); | |||||
| throw new RuntimeException("微信服务端异常,超出重试次数"); | throw new RuntimeException("微信服务端异常,超出重试次数"); | ||||
| } | } | ||||
| public <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException { | |||||
| protected <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException { | |||||
| E dataForLog = DataUtils.handleDataWithSecret(data); | E dataForLog = DataUtils.handleDataWithSecret(data); | ||||
| if (uri.contains("access_token=")) { | if (uri.contains("access_token=")) { | ||||
| @@ -302,7 +319,7 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | |||||
| try { | try { | ||||
| T result = executor.execute(uriWithAccessToken, data); | T result = executor.execute(uriWithAccessToken, data); | ||||
| this.log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, dataForLog, result); | |||||
| log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, dataForLog, result); | |||||
| return result; | return result; | ||||
| } catch (WxErrorException e) { | } catch (WxErrorException e) { | ||||
| WxError error = e.getError(); | WxError error = e.getError(); | ||||
| @@ -321,12 +338,12 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | |||||
| } | } | ||||
| if (error.getErrorCode() != 0) { | if (error.getErrorCode() != 0) { | ||||
| this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, dataForLog, error); | |||||
| log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, dataForLog, error); | |||||
| throw new WxErrorException(error, e); | throw new WxErrorException(error, e); | ||||
| } | } | ||||
| return null; | return null; | ||||
| } catch (IOException e) { | } catch (IOException e) { | ||||
| this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage()); | |||||
| log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage()); | |||||
| throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e); | throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e); | ||||
| } | } | ||||
| } | } | ||||
| @@ -1,16 +1,20 @@ | |||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
| import java.io.File; | |||||
| import com.google.gson.JsonParser; | import com.google.gson.JsonParser; | ||||
| import lombok.RequiredArgsConstructor; | |||||
| import me.chanjar.weixin.common.WxType; | import me.chanjar.weixin.common.WxType; | ||||
| import me.chanjar.weixin.common.error.WxError; | import me.chanjar.weixin.common.error.WxError; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.mp.api.WxMpAiOpenService; | import me.chanjar.weixin.mp.api.WxMpAiOpenService; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
| import me.chanjar.weixin.mp.enums.AiLangType; | import me.chanjar.weixin.mp.enums.AiLangType; | ||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import me.chanjar.weixin.mp.util.requestexecuter.voice.VoiceUploadRequestExecutor; | import me.chanjar.weixin.mp.util.requestexecuter.voice.VoiceUploadRequestExecutor; | ||||
| import java.io.File; | |||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.AiOpen.*; | |||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| * Created by BinaryWang on 2018/6/9. | * Created by BinaryWang on 2018/6/9. | ||||
| @@ -18,13 +22,10 @@ import me.chanjar.weixin.mp.util.requestexecuter.voice.VoiceUploadRequestExecuto | |||||
| * | * | ||||
| * @author <a href="https://github.com/binarywang">Binary Wang</a> | * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||
| */ | */ | ||||
| @RequiredArgsConstructor | |||||
| public class WxMpAiOpenServiceImpl implements WxMpAiOpenService { | public class WxMpAiOpenServiceImpl implements WxMpAiOpenService { | ||||
| private static final JsonParser JSON_PARSER = new JsonParser(); | private static final JsonParser JSON_PARSER = new JsonParser(); | ||||
| private WxMpService wxMpService; | |||||
| public WxMpAiOpenServiceImpl(WxMpService wxMpService) { | |||||
| this.wxMpService = wxMpService; | |||||
| } | |||||
| private final WxMpService wxMpService; | |||||
| @Override | @Override | ||||
| public void uploadVoice(String voiceId, AiLangType lang, File voiceFile) throws WxErrorException { | public void uploadVoice(String voiceId, AiLangType lang, File voiceFile) throws WxErrorException { | ||||
| @@ -33,7 +34,7 @@ public class WxMpAiOpenServiceImpl implements WxMpAiOpenService { | |||||
| } | } | ||||
| this.wxMpService.execute(VoiceUploadRequestExecutor.create(this.wxMpService.getRequestHttp()), | this.wxMpService.execute(VoiceUploadRequestExecutor.create(this.wxMpService.getRequestHttp()), | ||||
| String.format(VOICE_UPLOAD_URL, "mp3", voiceId, lang.getCode()), | |||||
| String.format(VOICE_UPLOAD_URL.getUrl(), "mp3", voiceId, lang.getCode()), | |||||
| voiceFile); | voiceFile); | ||||
| } | } | ||||
| @@ -45,7 +46,7 @@ public class WxMpAiOpenServiceImpl implements WxMpAiOpenService { | |||||
| @Override | @Override | ||||
| public String translate(AiLangType langFrom, AiLangType langTo, String content) throws WxErrorException { | public String translate(AiLangType langFrom, AiLangType langTo, String content) throws WxErrorException { | ||||
| String response = this.wxMpService.post(String.format(TRANSLATE_URL, langFrom.getCode(), langTo.getCode()), content); | |||||
| String response = this.wxMpService.post(String.format(TRANSLATE_URL.getUrl(), langFrom.getCode(), langTo.getCode()), content); | |||||
| WxError error = WxError.fromJson(response, WxType.MP); | WxError error = WxError.fromJson(response, WxType.MP); | ||||
| if (error.getErrorCode() != 0) { | if (error.getErrorCode() != 0) { | ||||
| @@ -13,6 +13,7 @@ import me.chanjar.weixin.mp.api.WxMpCardService; | |||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
| import me.chanjar.weixin.mp.bean.card.*; | import me.chanjar.weixin.mp.bean.card.*; | ||||
| import me.chanjar.weixin.mp.enums.TicketType; | import me.chanjar.weixin.mp.enums.TicketType; | ||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | ||||
| import org.apache.commons.codec.digest.DigestUtils; | import org.apache.commons.codec.digest.DigestUtils; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| @@ -54,7 +55,7 @@ public class WxMpCardServiceImpl implements WxMpCardService { | |||||
| if (this.getWxMpService().getWxMpConfigStorage().isTicketExpired(type)) { | if (this.getWxMpService().getWxMpConfigStorage().isTicketExpired(type)) { | ||||
| String responseContent = this.wxMpService.execute(SimpleGetRequestExecutor | String responseContent = this.wxMpService.execute(SimpleGetRequestExecutor | ||||
| .create(this.getWxMpService().getRequestHttp()), CARD_GET_TICKET, null); | |||||
| .create(this.getWxMpService().getRequestHttp()), WxMpApiUrl.Card.CARD_GET_TICKET, null); | |||||
| JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | ||||
| JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject(); | JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject(); | ||||
| String cardApiTicket = tmpJsonObject.get("ticket").getAsString(); | String cardApiTicket = tmpJsonObject.get("ticket").getAsString(); | ||||
| @@ -94,7 +95,7 @@ public class WxMpCardServiceImpl implements WxMpCardService { | |||||
| public String decryptCardCode(String encryptCode) throws WxErrorException { | public String decryptCardCode(String encryptCode) throws WxErrorException { | ||||
| JsonObject param = new JsonObject(); | JsonObject param = new JsonObject(); | ||||
| param.addProperty("encrypt_code", encryptCode); | param.addProperty("encrypt_code", encryptCode); | ||||
| String responseContent = this.wxMpService.post(CARD_CODE_DECRYPT, param.toString()); | |||||
| String responseContent = this.wxMpService.post(WxMpApiUrl.Card.CARD_CODE_DECRYPT, param.toString()); | |||||
| JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | ||||
| JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject(); | JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject(); | ||||
| JsonPrimitive jsonPrimitive = tmpJsonObject.getAsJsonPrimitive("code"); | JsonPrimitive jsonPrimitive = tmpJsonObject.getAsJsonPrimitive("code"); | ||||
| @@ -107,7 +108,7 @@ public class WxMpCardServiceImpl implements WxMpCardService { | |||||
| param.addProperty("card_id", cardId); | param.addProperty("card_id", cardId); | ||||
| param.addProperty("code", code); | param.addProperty("code", code); | ||||
| param.addProperty("check_consume", checkConsume); | param.addProperty("check_consume", checkConsume); | ||||
| String responseContent = this.wxMpService.post(CARD_CODE_GET, param.toString()); | |||||
| String responseContent = this.wxMpService.post(WxMpApiUrl.Card.CARD_CODE_GET, param.toString()); | |||||
| JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | ||||
| return WxMpGsonBuilder.create().fromJson(tmpJsonElement, | return WxMpGsonBuilder.create().fromJson(tmpJsonElement, | ||||
| new TypeToken<WxMpCardResult>() { | new TypeToken<WxMpCardResult>() { | ||||
| @@ -128,7 +129,7 @@ public class WxMpCardServiceImpl implements WxMpCardService { | |||||
| param.addProperty("card_id", cardId); | param.addProperty("card_id", cardId); | ||||
| } | } | ||||
| return this.wxMpService.post(CARD_CODE_CONSUME, param.toString()); | |||||
| return this.wxMpService.post(WxMpApiUrl.Card.CARD_CODE_CONSUME, param.toString()); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -138,7 +139,7 @@ public class WxMpCardServiceImpl implements WxMpCardService { | |||||
| param.addProperty("card_id", cardId); | param.addProperty("card_id", cardId); | ||||
| param.addProperty("openid", openId); | param.addProperty("openid", openId); | ||||
| param.addProperty("is_mark", isMark); | param.addProperty("is_mark", isMark); | ||||
| String responseContent = this.getWxMpService().post(CARD_CODE_MARK, param.toString()); | |||||
| String responseContent = this.getWxMpService().post(WxMpApiUrl.Card.CARD_CODE_MARK, param.toString()); | |||||
| JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | ||||
| WxMpCardResult cardResult = WxMpGsonBuilder.create().fromJson(tmpJsonElement, | WxMpCardResult cardResult = WxMpGsonBuilder.create().fromJson(tmpJsonElement, | ||||
| new TypeToken<WxMpCardResult>() { | new TypeToken<WxMpCardResult>() { | ||||
| @@ -152,7 +153,7 @@ public class WxMpCardServiceImpl implements WxMpCardService { | |||||
| public String getCardDetail(String cardId) throws WxErrorException { | public String getCardDetail(String cardId) throws WxErrorException { | ||||
| JsonObject param = new JsonObject(); | JsonObject param = new JsonObject(); | ||||
| param.addProperty("card_id", cardId); | param.addProperty("card_id", cardId); | ||||
| String responseContent = this.wxMpService.post(CARD_GET, param.toString()); | |||||
| String responseContent = this.wxMpService.post(WxMpApiUrl.Card.CARD_GET, param.toString()); | |||||
| // 判断返回值 | // 判断返回值 | ||||
| JsonObject json = (new JsonParser()).parse(responseContent).getAsJsonObject(); | JsonObject json = (new JsonParser()).parse(responseContent).getAsJsonObject(); | ||||
| @@ -173,12 +174,12 @@ public class WxMpCardServiceImpl implements WxMpCardService { | |||||
| array.add(openid); | array.add(openid); | ||||
| JsonObject jsonObject = new JsonObject(); | JsonObject jsonObject = new JsonObject(); | ||||
| jsonObject.add("openid", array); | jsonObject.add("openid", array); | ||||
| return this.wxMpService.post(CARD_TEST_WHITELIST, GSON.toJson(jsonObject)); | |||||
| return this.wxMpService.post(WxMpApiUrl.Card.CARD_TEST_WHITELIST, GSON.toJson(jsonObject)); | |||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpCardCreateResult createCard(WxMpCardCreateMessage cardCreateMessage) throws WxErrorException { | public WxMpCardCreateResult createCard(WxMpCardCreateMessage cardCreateMessage) throws WxErrorException { | ||||
| String response = this.wxMpService.post(CARD_CREATE, GSON.toJson(cardCreateMessage)); | |||||
| String response = this.wxMpService.post(WxMpApiUrl.Card.CARD_CREATE, GSON.toJson(cardCreateMessage)); | |||||
| return WxMpCardCreateResult.fromJson(response); | return WxMpCardCreateResult.fromJson(response); | ||||
| } | } | ||||
| @@ -200,12 +201,12 @@ public class WxMpCardServiceImpl implements WxMpCardService { | |||||
| cardJson.addProperty("outer_str", outerStr); | cardJson.addProperty("outer_str", outerStr); | ||||
| actionInfoJson.add("card", cardJson); | actionInfoJson.add("card", cardJson); | ||||
| jsonObject.add("action_info", actionInfoJson); | jsonObject.add("action_info", actionInfoJson); | ||||
| return WxMpCardQrcodeCreateResult.fromJson(this.wxMpService.post(CARD_QRCODE_CREATE, GSON.toJson(jsonObject))); | |||||
| return WxMpCardQrcodeCreateResult.fromJson(this.wxMpService.post(WxMpApiUrl.Card.CARD_QRCODE_CREATE, GSON.toJson(jsonObject))); | |||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpCardLandingPageCreateResult createLandingPage(WxMpCardLandingPageCreateRequest request) throws WxErrorException { | public WxMpCardLandingPageCreateResult createLandingPage(WxMpCardLandingPageCreateRequest request) throws WxErrorException { | ||||
| String response = this.wxMpService.post(CARD_LANDING_PAGE_CREATE, GSON.toJson(request)); | |||||
| String response = this.wxMpService.post(WxMpApiUrl.Card.CARD_LANDING_PAGE_CREATE, GSON.toJson(request)); | |||||
| return WxMpCardLandingPageCreateResult.fromJson(response); | return WxMpCardLandingPageCreateResult.fromJson(response); | ||||
| } | } | ||||
| @@ -218,7 +219,7 @@ public class WxMpCardServiceImpl implements WxMpCardService { | |||||
| jsonRequest.addProperty("card_id", cardId); | jsonRequest.addProperty("card_id", cardId); | ||||
| jsonRequest.addProperty("code", code); | jsonRequest.addProperty("code", code); | ||||
| jsonRequest.addProperty("reason", reason); | jsonRequest.addProperty("reason", reason); | ||||
| return this.wxMpService.post(CARD_CODE_UNAVAILABLE, GSON.toJson(jsonRequest)); | |||||
| return this.wxMpService.post(WxMpApiUrl.Card.CARD_CODE_UNAVAILABLE, GSON.toJson(jsonRequest)); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -228,7 +229,7 @@ public class WxMpCardServiceImpl implements WxMpCardService { | |||||
| } | } | ||||
| JsonObject param = new JsonObject(); | JsonObject param = new JsonObject(); | ||||
| param.addProperty("card_id", cardId); | param.addProperty("card_id", cardId); | ||||
| String response = this.wxMpService.post(CARD_DELETE, param.toString()); | |||||
| String response = this.wxMpService.post(WxMpApiUrl.Card.CARD_DELETE, param.toString()); | |||||
| return WxMpCardDeleteResult.fromJson(response); | return WxMpCardDeleteResult.fromJson(response); | ||||
| } | } | ||||
| } | } | ||||
| @@ -1,30 +1,30 @@ | |||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||
| import lombok.RequiredArgsConstructor; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.mp.api.WxMpDataCubeService; | import me.chanjar.weixin.mp.api.WxMpDataCubeService; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
| import me.chanjar.weixin.mp.bean.datacube.*; | import me.chanjar.weixin.mp.bean.datacube.*; | ||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import org.apache.commons.lang3.time.FastDateFormat; | import org.apache.commons.lang3.time.FastDateFormat; | ||||
| import java.text.Format; | import java.text.Format; | ||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.List; | import java.util.List; | ||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.DataCube.*; | |||||
| /** | /** | ||||
| * Created by Binary Wang on 2016/8/23. | * Created by Binary Wang on 2016/8/23. | ||||
| * | * | ||||
| * @author binarywang (https://github.com/binarywang) | * @author binarywang (https://github.com/binarywang) | ||||
| */ | */ | ||||
| @RequiredArgsConstructor | |||||
| public class WxMpDataCubeServiceImpl implements WxMpDataCubeService { | public class WxMpDataCubeServiceImpl implements WxMpDataCubeService { | ||||
| private final Format dateFormat = FastDateFormat.getInstance("yyyy-MM-dd"); | private final Format dateFormat = FastDateFormat.getInstance("yyyy-MM-dd"); | ||||
| private WxMpService wxMpService; | |||||
| public WxMpDataCubeServiceImpl(WxMpService wxMpService) { | |||||
| this.wxMpService = wxMpService; | |||||
| } | |||||
| private final WxMpService wxMpService; | |||||
| @Override | @Override | ||||
| public List<WxDataCubeUserSummary> getUserSummary(Date beginDate, Date endDate) throws WxErrorException { | public List<WxDataCubeUserSummary> getUserSummary(Date beginDate, Date endDate) throws WxErrorException { | ||||
| @@ -69,7 +69,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService { | |||||
| return this.getArticleResults(GET_USER_SHARE_HOUR, beginDate, endDate); | return this.getArticleResults(GET_USER_SHARE_HOUR, beginDate, endDate); | ||||
| } | } | ||||
| private List<WxDataCubeArticleResult> getArticleResults(String url, Date beginDate, Date endDate) throws WxErrorException { | |||||
| private List<WxDataCubeArticleResult> getArticleResults(WxMpApiUrl url, Date beginDate, Date endDate) throws WxErrorException { | |||||
| String responseContent = this.wxMpService.post(url, buildParams(beginDate, endDate)); | String responseContent = this.wxMpService.post(url, buildParams(beginDate, endDate)); | ||||
| return WxDataCubeArticleResult.fromJson(responseContent); | return WxDataCubeArticleResult.fromJson(responseContent); | ||||
| } | } | ||||
| @@ -109,13 +109,13 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService { | |||||
| return this.getUpstreamMsg(GET_UPSTREAM_MSG_DIST_MONTH, beginDate, endDate); | return this.getUpstreamMsg(GET_UPSTREAM_MSG_DIST_MONTH, beginDate, endDate); | ||||
| } | } | ||||
| private List<WxDataCubeMsgResult> getUpstreamMsg(String url, Date beginDate, Date endDate) throws WxErrorException { | |||||
| private List<WxDataCubeMsgResult> getUpstreamMsg(WxMpApiUrl url, Date beginDate, Date endDate) throws WxErrorException { | |||||
| String responseContent = this.wxMpService.post(url, buildParams(beginDate, endDate)); | String responseContent = this.wxMpService.post(url, buildParams(beginDate, endDate)); | ||||
| return WxDataCubeMsgResult.fromJson(responseContent); | return WxDataCubeMsgResult.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public List<WxDataCubeInterfaceResult> getInterfaceSummary(Date beginDate, Date endDate) throws WxErrorException { | |||||
| public List<WxDataCubeInterfaceResult> getInterfaceSummary(Date beginDate, Date endDate) throws WxErrorException { | |||||
| String responseContent = this.wxMpService.post(GET_INTERFACE_SUMMARY, buildParams(beginDate, endDate)); | String responseContent = this.wxMpService.post(GET_INTERFACE_SUMMARY, buildParams(beginDate, endDate)); | ||||
| return WxDataCubeInterfaceResult.fromJson(responseContent); | return WxDataCubeInterfaceResult.fromJson(responseContent); | ||||
| } | } | ||||
| @@ -128,7 +128,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public List<WxDataCubeInterfaceResult> getInterfaceSummaryHour(Date beginDate, Date endDate) throws WxErrorException { | |||||
| public List<WxDataCubeInterfaceResult> getInterfaceSummaryHour(Date beginDate, Date endDate) throws WxErrorException { | |||||
| String responseContent = this.wxMpService.post(GET_INTERFACE_SUMMARY_HOUR, buildParams(beginDate, endDate)); | String responseContent = this.wxMpService.post(GET_INTERFACE_SUMMARY_HOUR, buildParams(beginDate, endDate)); | ||||
| return WxDataCubeInterfaceResult.fromJson(responseContent); | return WxDataCubeInterfaceResult.fromJson(responseContent); | ||||
| } | } | ||||
| @@ -1,86 +1,76 @@ | |||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
| import lombok.RequiredArgsConstructor; | |||||
| import lombok.extern.slf4j.Slf4j; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.mp.api.WxMpDeviceService; | import me.chanjar.weixin.mp.api.WxMpDeviceService; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
| import me.chanjar.weixin.mp.bean.device.*; | import me.chanjar.weixin.mp.bean.device.*; | ||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Device.*; | |||||
| /** | /** | ||||
| * Created by keungtung on 10/12/2016. | * Created by keungtung on 10/12/2016. | ||||
| * | |||||
| * @author keungtung | |||||
| */ | */ | ||||
| @Slf4j | |||||
| @RequiredArgsConstructor | |||||
| public class WxMpDeviceServiceImpl implements WxMpDeviceService { | public class WxMpDeviceServiceImpl implements WxMpDeviceService { | ||||
| private static final String API_URL_PREFIX = "https://api.weixin.qq.com/device"; | |||||
| private static Logger log = LoggerFactory.getLogger(WxMpMenuServiceImpl.class); | |||||
| private WxMpService wxMpService; | |||||
| public WxMpDeviceServiceImpl(WxMpService wxMpService) { | |||||
| this.wxMpService = wxMpService; | |||||
| } | |||||
| private final WxMpService wxMpService; | |||||
| @Override | @Override | ||||
| public TransMsgResp transMsg(WxDeviceMsg msg) throws WxErrorException { | public TransMsgResp transMsg(WxDeviceMsg msg) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/transmsg"; | |||||
| String response = this.wxMpService.post(url, msg.toJson()); | |||||
| String response = this.wxMpService.post(DEVICE_TRANSMSG, msg.toJson()); | |||||
| return TransMsgResp.fromJson(response); | return TransMsgResp.fromJson(response); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxDeviceQrCodeResult getQrCode(String productId) throws WxErrorException { | public WxDeviceQrCodeResult getQrCode(String productId) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/getqrcode"; | |||||
| String response = this.wxMpService.get(url, "product_id=" + productId); | |||||
| String response = this.wxMpService.get(DEVICE_GETQRCODE, "product_id=" + productId); | |||||
| return WxDeviceQrCodeResult.fromJson(response); | return WxDeviceQrCodeResult.fromJson(response); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxDeviceAuthorizeResult authorize(WxDeviceAuthorize wxDeviceAuthorize) throws WxErrorException { | public WxDeviceAuthorizeResult authorize(WxDeviceAuthorize wxDeviceAuthorize) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/authorize_device"; | |||||
| String response = this.wxMpService.post(url, wxDeviceAuthorize.toJson()); | |||||
| String response = this.wxMpService.post(DEVICE_AUTHORIZE_DEVICE, wxDeviceAuthorize.toJson()); | |||||
| return WxDeviceAuthorizeResult.fromJson(response); | return WxDeviceAuthorizeResult.fromJson(response); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxDeviceBindResult bind(WxDeviceBind wxDeviceBind) throws WxErrorException { | public WxDeviceBindResult bind(WxDeviceBind wxDeviceBind) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/bind"; | |||||
| String response = this.wxMpService.post(url, wxDeviceBind.toJson()); | |||||
| String response = this.wxMpService.post(DEVICE_BIND, wxDeviceBind.toJson()); | |||||
| return WxDeviceBindResult.fromJson(response); | return WxDeviceBindResult.fromJson(response); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxDeviceBindResult compelBind(WxDeviceBind wxDeviceBind) throws WxErrorException { | public WxDeviceBindResult compelBind(WxDeviceBind wxDeviceBind) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/compel_bind"; | |||||
| String response = this.wxMpService.post(url, wxDeviceBind.toJson()); | |||||
| String response = this.wxMpService.post(DEVICE_COMPEL_BIND, wxDeviceBind.toJson()); | |||||
| return WxDeviceBindResult.fromJson(response); | return WxDeviceBindResult.fromJson(response); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxDeviceBindResult unbind(WxDeviceBind wxDeviceBind) throws WxErrorException { | public WxDeviceBindResult unbind(WxDeviceBind wxDeviceBind) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/unbind?"; | |||||
| String response = this.wxMpService.post(url, wxDeviceBind.toJson()); | |||||
| String response = this.wxMpService.post(DEVICE_UNBIND, wxDeviceBind.toJson()); | |||||
| return WxDeviceBindResult.fromJson(response); | return WxDeviceBindResult.fromJson(response); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxDeviceBindResult compelUnbind(WxDeviceBind wxDeviceBind) throws WxErrorException { | public WxDeviceBindResult compelUnbind(WxDeviceBind wxDeviceBind) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/compel_unbind?"; | |||||
| String response = this.wxMpService.post(url, wxDeviceBind.toJson()); | |||||
| String response = this.wxMpService.post(DEVICE_COMPEL_UNBIND, wxDeviceBind.toJson()); | |||||
| return WxDeviceBindResult.fromJson(response); | return WxDeviceBindResult.fromJson(response); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxDeviceOpenIdResult getOpenId(String deviceType, String deviceId) throws WxErrorException { | public WxDeviceOpenIdResult getOpenId(String deviceType, String deviceId) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/get_openid"; | |||||
| String response = this.wxMpService.get(url, "device_type=" + deviceType + "&device_id=" + deviceId); | |||||
| String response = this.wxMpService.get(DEVICE_GET_OPENID, "device_type=" + deviceType + "&device_id=" + deviceId); | |||||
| return WxDeviceOpenIdResult.fromJson(response); | return WxDeviceOpenIdResult.fromJson(response); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxDeviceBindDeviceResult getBindDevice(String openId) throws WxErrorException { | public WxDeviceBindDeviceResult getBindDevice(String openId) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/get_bind_device"; | |||||
| String response = this.wxMpService.get(url, "openid=" + openId); | |||||
| String response = this.wxMpService.get(DEVICE_GET_BIND_DEVICE, "openid=" + openId); | |||||
| return WxDeviceBindDeviceResult.fromJson(response); | return WxDeviceBindDeviceResult.fromJson(response); | ||||
| } | } | ||||
| } | } | ||||
| @@ -1,12 +1,8 @@ | |||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
| import java.io.File; | |||||
| import java.util.Date; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||
| import lombok.RequiredArgsConstructor; | |||||
| import lombok.extern.slf4j.Slf4j; | |||||
| import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; | import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; | ||||
| import me.chanjar.weixin.common.error.WxError; | import me.chanjar.weixin.common.error.WxError; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| @@ -16,23 +12,21 @@ import me.chanjar.weixin.mp.api.WxMpService; | |||||
| import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | ||||
| import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; | import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; | ||||
| import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfSessionRequest; | import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfSessionRequest; | ||||
| import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfList; | |||||
| import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfMsgList; | |||||
| import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfOnlineList; | |||||
| import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionGetResult; | |||||
| import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionList; | |||||
| import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionWaitCaseList; | |||||
| import me.chanjar.weixin.mp.bean.kefu.result.*; | |||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import java.io.File; | |||||
| import java.util.Date; | |||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Kefu.*; | |||||
| /** | /** | ||||
| * @author Binary Wang | * @author Binary Wang | ||||
| */ | */ | ||||
| @Slf4j | |||||
| @RequiredArgsConstructor | |||||
| public class WxMpKefuServiceImpl implements WxMpKefuService { | public class WxMpKefuServiceImpl implements WxMpKefuService { | ||||
| protected final Logger log = LoggerFactory.getLogger(this.getClass()); | |||||
| private WxMpService wxMpService; | |||||
| public WxMpKefuServiceImpl(WxMpService wxMpService) { | |||||
| this.wxMpService = wxMpService; | |||||
| } | |||||
| private final WxMpService wxMpService; | |||||
| @Override | @Override | ||||
| public boolean sendKefuMessage(WxMpKefuMessage message) throws WxErrorException { | public boolean sendKefuMessage(WxMpKefuMessage message) throws WxErrorException { | ||||
| @@ -73,13 +67,14 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { | |||||
| @Override | @Override | ||||
| public boolean kfAccountUploadHeadImg(String kfAccount, File imgFile) throws WxErrorException { | public boolean kfAccountUploadHeadImg(String kfAccount, File imgFile) throws WxErrorException { | ||||
| WxMediaUploadResult responseContent = this.wxMpService | WxMediaUploadResult responseContent = this.wxMpService | ||||
| .execute(MediaUploadRequestExecutor.create(this.wxMpService.getRequestHttp()), String.format(KFACCOUNT_UPLOAD_HEAD_IMG, kfAccount), imgFile); | |||||
| .execute(MediaUploadRequestExecutor.create(this.wxMpService.getRequestHttp()), | |||||
| String.format(KFACCOUNT_UPLOAD_HEAD_IMG.getUrl(), kfAccount), imgFile); | |||||
| return responseContent != null; | return responseContent != null; | ||||
| } | } | ||||
| @Override | @Override | ||||
| public boolean kfAccountDel(String kfAccount) throws WxErrorException { | public boolean kfAccountDel(String kfAccount) throws WxErrorException { | ||||
| String responseContent = this.wxMpService.get(String.format(KFACCOUNT_DEL, kfAccount), null); | |||||
| String responseContent = this.wxMpService.get(String.format(KFACCOUNT_DEL.getUrl(), kfAccount), null); | |||||
| return responseContent != null; | return responseContent != null; | ||||
| } | } | ||||
| @@ -99,13 +94,13 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { | |||||
| @Override | @Override | ||||
| public WxMpKfSessionGetResult kfSessionGet(String openid) throws WxErrorException { | public WxMpKfSessionGetResult kfSessionGet(String openid) throws WxErrorException { | ||||
| String responseContent = this.wxMpService.get(String.format(KFSESSION_GET_SESSION, openid), null); | |||||
| String responseContent = this.wxMpService.get(String.format(KFSESSION_GET_SESSION.getUrl(), openid), null); | |||||
| return WxMpKfSessionGetResult.fromJson(responseContent); | return WxMpKfSessionGetResult.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpKfSessionList kfSessionList(String kfAccount) throws WxErrorException { | public WxMpKfSessionList kfSessionList(String kfAccount) throws WxErrorException { | ||||
| String responseContent = this.wxMpService.get(String.format(KFSESSION_GET_SESSION_LIST, kfAccount), null); | |||||
| String responseContent = this.wxMpService.get(String.format(KFSESSION_GET_SESSION_LIST.getUrl(), kfAccount), null); | |||||
| return WxMpKfSessionList.fromJson(responseContent); | return WxMpKfSessionList.fromJson(responseContent); | ||||
| } | } | ||||
| @@ -4,6 +4,8 @@ import com.google.gson.JsonArray; | |||||
| import com.google.gson.JsonElement; | import com.google.gson.JsonElement; | ||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||
| import com.google.gson.JsonParser; | import com.google.gson.JsonParser; | ||||
| import lombok.RequiredArgsConstructor; | |||||
| import lombok.extern.slf4j.Slf4j; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.mp.api.WxMpMarketingService; | import me.chanjar.weixin.mp.api.WxMpMarketingService; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
| @@ -12,8 +14,6 @@ import me.chanjar.weixin.mp.bean.marketing.WxMpAdLeadResult; | |||||
| import me.chanjar.weixin.mp.bean.marketing.WxMpUserAction; | import me.chanjar.weixin.mp.bean.marketing.WxMpUserAction; | ||||
| import me.chanjar.weixin.mp.bean.marketing.WxMpUserActionSet; | import me.chanjar.weixin.mp.bean.marketing.WxMpUserActionSet; | ||||
| import org.apache.commons.lang3.time.DateFormatUtils; | import org.apache.commons.lang3.time.DateFormatUtils; | ||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.net.URLEncoder; | import java.net.URLEncoder; | ||||
| @@ -21,44 +21,40 @@ import java.nio.charset.StandardCharsets; | |||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.List; | import java.util.List; | ||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Marketing.*; | |||||
| /** | /** | ||||
| * @author <a href="https://github.com/007gzs">007</a> | * @author <a href="https://github.com/007gzs">007</a> | ||||
| */ | */ | ||||
| @Slf4j | |||||
| @RequiredArgsConstructor | |||||
| public class WxMpMarketingServiceImpl implements WxMpMarketingService { | public class WxMpMarketingServiceImpl implements WxMpMarketingService { | ||||
| protected final Logger log = LoggerFactory.getLogger(this.getClass()); | |||||
| private WxMpService wxMpService; | |||||
| public WxMpMarketingServiceImpl(WxMpService wxMpService) { | |||||
| this.wxMpService = wxMpService; | |||||
| } | |||||
| private final WxMpService wxMpService; | |||||
| @Override | @Override | ||||
| public long addUserActionSets(String type, String name, String description) throws WxErrorException { | public long addUserActionSets(String type, String name, String description) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "user_action_sets/add?version=v1.0"; | |||||
| JsonObject json = new JsonObject(); | JsonObject json = new JsonObject(); | ||||
| json.addProperty("type", type); | json.addProperty("type", type); | ||||
| json.addProperty("name", name); | json.addProperty("name", name); | ||||
| json.addProperty("description", description); | json.addProperty("description", description); | ||||
| String responseContent = wxMpService.post(url, json.toString()); | |||||
| String responseContent = wxMpService.post(USER_ACTION_SETS_ADD, json.toString()); | |||||
| JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | ||||
| return tmpJsonElement.getAsJsonObject().get("data").getAsJsonObject().get("user_action_set_id").getAsLong(); | return tmpJsonElement.getAsJsonObject().get("data").getAsJsonObject().get("user_action_set_id").getAsLong(); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public List<WxMpUserActionSet> getUserActionSets(Long userActionSetId) throws WxErrorException { | public List<WxMpUserActionSet> getUserActionSets(Long userActionSetId) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "user_action_sets/get"; | |||||
| String responseContent = wxMpService.get(url, "version=v1.0&user_action_set_id=" + userActionSetId); | |||||
| String responseContent = wxMpService.get(USER_ACTION_SETS_GET, "version=v1.0&user_action_set_id=" + userActionSetId); | |||||
| return WxMpUserActionSet.fromJson(responseContent); | return WxMpUserActionSet.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public void addUserAction(List<WxMpUserAction> actions) throws WxErrorException { | public void addUserAction(List<WxMpUserAction> actions) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "user_actions/add?version=v1.0"; | |||||
| JsonArray json = new JsonArray(); | JsonArray json = new JsonArray(); | ||||
| for (WxMpUserAction action : actions) { | for (WxMpUserAction action : actions) { | ||||
| json.add(action.toJsonObject()); | json.add(action.toJsonObject()); | ||||
| } | } | ||||
| wxMpService.post(url, json.toString()); | |||||
| wxMpService.post(USER_ACTIONS_ADD, json.toString()); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -70,7 +66,6 @@ public class WxMpMarketingServiceImpl implements WxMpMarketingService { | |||||
| if (endDate == null) { | if (endDate == null) { | ||||
| endDate = today; | endDate = today; | ||||
| } | } | ||||
| String url = API_URL_PREFIX + "wechat_ad_leads/get"; | |||||
| String params = "version=v1.0"; | String params = "version=v1.0"; | ||||
| JsonObject dateRange = new JsonObject(); | JsonObject dateRange = new JsonObject(); | ||||
| dateRange.addProperty("begin_date", DateFormatUtils.format(beginDate, "yyyy-MM-dd")); | dateRange.addProperty("begin_date", DateFormatUtils.format(beginDate, "yyyy-MM-dd")); | ||||
| @@ -84,9 +79,8 @@ public class WxMpMarketingServiceImpl implements WxMpMarketingService { | |||||
| filterJson.add(filter.toJsonObject()); | filterJson.add(filter.toJsonObject()); | ||||
| } | } | ||||
| params += "&filtering=" + URLEncoder.encode(filterJson.toString(), StandardCharsets.UTF_8.name()); | params += "&filtering=" + URLEncoder.encode(filterJson.toString(), StandardCharsets.UTF_8.name()); | ||||
| ; | |||||
| } | } | ||||
| String responseContent = wxMpService.get(url, params); | |||||
| String responseContent = wxMpService.get(WECHAT_AD_LEADS_GET, params); | |||||
| return WxMpAdLeadResult.fromJson(responseContent); | return WxMpAdLeadResult.fromJson(responseContent); | ||||
| } | } | ||||
| } | } | ||||
| @@ -1,14 +1,15 @@ | |||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||
| import lombok.RequiredArgsConstructor; | |||||
| import lombok.extern.slf4j.Slf4j; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.mp.api.WxMpMassMessageService; | import me.chanjar.weixin.mp.api.WxMpMassMessageService; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
| import me.chanjar.weixin.mp.bean.*; | import me.chanjar.weixin.mp.bean.*; | ||||
| import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; | import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; | ||||
| import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; | import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; | ||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| @@ -18,41 +19,38 @@ import org.slf4j.LoggerFactory; | |||||
| * | * | ||||
| * @author <a href="https://github.com/binarywang">Binary Wang</a> | * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||
| */ | */ | ||||
| @Slf4j | |||||
| @RequiredArgsConstructor | |||||
| public class WxMpMassMessageServiceImpl implements WxMpMassMessageService { | public class WxMpMassMessageServiceImpl implements WxMpMassMessageService { | ||||
| protected final Logger log = LoggerFactory.getLogger(this.getClass()); | |||||
| private WxMpService wxMpService; | |||||
| public WxMpMassMessageServiceImpl(WxMpService wxMpService) { | |||||
| this.wxMpService = wxMpService; | |||||
| } | |||||
| private final WxMpService wxMpService; | |||||
| @Override | @Override | ||||
| public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException { | public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException { | ||||
| String responseContent = this.wxMpService.post(MEDIA_UPLOAD_NEWS_URL, news.toJson()); | |||||
| String responseContent = this.wxMpService.post(WxMpApiUrl.MassMessage.MEDIA_UPLOAD_NEWS_URL, news.toJson()); | |||||
| return WxMpMassUploadResult.fromJson(responseContent); | return WxMpMassUploadResult.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpMassUploadResult massVideoUpload(WxMpMassVideo video) throws WxErrorException { | public WxMpMassUploadResult massVideoUpload(WxMpMassVideo video) throws WxErrorException { | ||||
| String responseContent = this.wxMpService.post(MEDIA_UPLOAD_VIDEO_URL, video.toJson()); | |||||
| String responseContent = this.wxMpService.post(WxMpApiUrl.MassMessage.MEDIA_UPLOAD_VIDEO_URL, video.toJson()); | |||||
| return WxMpMassUploadResult.fromJson(responseContent); | return WxMpMassUploadResult.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpMassSendResult massGroupMessageSend(WxMpMassTagMessage message) throws WxErrorException { | public WxMpMassSendResult massGroupMessageSend(WxMpMassTagMessage message) throws WxErrorException { | ||||
| String responseContent = this.wxMpService.post(WxMpMassMessageService.MESSAGE_MASS_SENDALL_URL, message.toJson()); | |||||
| String responseContent = this.wxMpService.post(WxMpApiUrl.MassMessage.MESSAGE_MASS_SENDALL_URL, message.toJson()); | |||||
| return WxMpMassSendResult.fromJson(responseContent); | return WxMpMassSendResult.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpMassSendResult massOpenIdsMessageSend(WxMpMassOpenIdsMessage message) throws WxErrorException { | public WxMpMassSendResult massOpenIdsMessageSend(WxMpMassOpenIdsMessage message) throws WxErrorException { | ||||
| String responseContent = this.wxMpService.post(MESSAGE_MASS_SEND_URL, message.toJson()); | |||||
| String responseContent = this.wxMpService.post(WxMpApiUrl.MassMessage.MESSAGE_MASS_SEND_URL, message.toJson()); | |||||
| return WxMpMassSendResult.fromJson(responseContent); | return WxMpMassSendResult.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage) throws WxErrorException { | public WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage) throws WxErrorException { | ||||
| String responseContent = this.wxMpService.post(MESSAGE_MASS_PREVIEW_URL, wxMpMassPreviewMessage.toJson()); | |||||
| String responseContent = this.wxMpService.post(WxMpApiUrl.MassMessage.MESSAGE_MASS_PREVIEW_URL, wxMpMassPreviewMessage.toJson()); | |||||
| return WxMpMassSendResult.fromJson(responseContent); | return WxMpMassSendResult.fromJson(responseContent); | ||||
| } | } | ||||
| @@ -61,7 +59,7 @@ public class WxMpMassMessageServiceImpl implements WxMpMassMessageService { | |||||
| JsonObject jsonObject = new JsonObject(); | JsonObject jsonObject = new JsonObject(); | ||||
| jsonObject.addProperty("msg_id", msgId); | jsonObject.addProperty("msg_id", msgId); | ||||
| jsonObject.addProperty("article_idx", articleIndex); | jsonObject.addProperty("article_idx", articleIndex); | ||||
| this.wxMpService.post(MESSAGE_MASS_DELETE_URL, jsonObject.toString()); | |||||
| this.wxMpService.post(WxMpApiUrl.MassMessage.MESSAGE_MASS_DELETE_URL, jsonObject.toString()); | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,12 +1,6 @@ | |||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
| import java.io.File; | |||||
| import java.io.IOException; | |||||
| import java.io.InputStream; | |||||
| import java.util.HashMap; | |||||
| import java.util.Map; | |||||
| import java.util.UUID; | |||||
| import lombok.RequiredArgsConstructor; | |||||
| import me.chanjar.weixin.common.WxType; | import me.chanjar.weixin.common.WxType; | ||||
| import me.chanjar.weixin.common.api.WxConsts; | import me.chanjar.weixin.common.api.WxConsts; | ||||
| import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; | import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; | ||||
| @@ -18,33 +12,29 @@ import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; | |||||
| import me.chanjar.weixin.common.util.json.WxGsonBuilder; | import me.chanjar.weixin.common.util.json.WxGsonBuilder; | ||||
| import me.chanjar.weixin.mp.api.WxMpMaterialService; | import me.chanjar.weixin.mp.api.WxMpMaterialService; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
| import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult; | |||||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterial; | |||||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialArticleUpdate; | |||||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialCountResult; | |||||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialFileBatchGetResult; | |||||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; | |||||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialNewsBatchGetResult; | |||||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialUploadResult; | |||||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialVideoInfoResult; | |||||
| import me.chanjar.weixin.mp.bean.material.*; | |||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | ||||
| import me.chanjar.weixin.mp.util.requestexecuter.material.MaterialDeleteRequestExecutor; | |||||
| import me.chanjar.weixin.mp.util.requestexecuter.material.MaterialNewsInfoRequestExecutor; | |||||
| import me.chanjar.weixin.mp.util.requestexecuter.material.MaterialUploadRequestExecutor; | |||||
| import me.chanjar.weixin.mp.util.requestexecuter.material.MaterialVideoInfoRequestExecutor; | |||||
| import me.chanjar.weixin.mp.util.requestexecuter.material.MaterialVoiceAndImageDownloadRequestExecutor; | |||||
| import me.chanjar.weixin.mp.util.requestexecuter.material.*; | |||||
| import me.chanjar.weixin.mp.util.requestexecuter.media.MediaImgUploadRequestExecutor; | import me.chanjar.weixin.mp.util.requestexecuter.media.MediaImgUploadRequestExecutor; | ||||
| import java.io.File; | |||||
| import java.io.IOException; | |||||
| import java.io.InputStream; | |||||
| import java.util.HashMap; | |||||
| import java.util.Map; | |||||
| import java.util.UUID; | |||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Material.*; | |||||
| /** | /** | ||||
| * Created by Binary Wang on 2016/7/21. | * Created by Binary Wang on 2016/7/21. | ||||
| * | |||||
| * @author Binary Wang | |||||
| */ | */ | ||||
| @RequiredArgsConstructor | |||||
| public class WxMpMaterialServiceImpl implements WxMpMaterialService { | public class WxMpMaterialServiceImpl implements WxMpMaterialService { | ||||
| private WxMpService wxMpService; | |||||
| public WxMpMaterialServiceImpl(WxMpService wxMpService) { | |||||
| this.wxMpService = wxMpService; | |||||
| } | |||||
| private final WxMpService wxMpService; | |||||
| @Override | @Override | ||||
| public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream) throws WxErrorException { | public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream) throws WxErrorException { | ||||
| @@ -63,7 +53,7 @@ public class WxMpMaterialServiceImpl implements WxMpMaterialService { | |||||
| @Override | @Override | ||||
| public WxMediaUploadResult mediaUpload(String mediaType, File file) throws WxErrorException { | public WxMediaUploadResult mediaUpload(String mediaType, File file) throws WxErrorException { | ||||
| String url = String.format(MEDIA_UPLOAD_URL, mediaType); | |||||
| String url = String.format(MEDIA_UPLOAD_URL.getUrl(), mediaType); | |||||
| return this.wxMpService.execute(MediaUploadRequestExecutor.create(this.wxMpService.getRequestHttp()), url, file); | return this.wxMpService.execute(MediaUploadRequestExecutor.create(this.wxMpService.getRequestHttp()), url, file); | ||||
| } | } | ||||
| @@ -82,7 +72,7 @@ public class WxMpMaterialServiceImpl implements WxMpMaterialService { | |||||
| @Override | @Override | ||||
| public WxMpMaterialUploadResult materialFileUpload(String mediaType, WxMpMaterial material) throws WxErrorException { | public WxMpMaterialUploadResult materialFileUpload(String mediaType, WxMpMaterial material) throws WxErrorException { | ||||
| String url = String.format(MATERIAL_ADD_URL, mediaType); | |||||
| String url = String.format(MATERIAL_ADD_URL.getUrl(), mediaType); | |||||
| return this.wxMpService.execute(MaterialUploadRequestExecutor.create(this.wxMpService.getRequestHttp()), url, material); | return this.wxMpService.execute(MaterialUploadRequestExecutor.create(this.wxMpService.getRequestHttp()), url, material); | ||||
| } | } | ||||
| @@ -98,17 +88,20 @@ public class WxMpMaterialServiceImpl implements WxMpMaterialService { | |||||
| @Override | @Override | ||||
| public InputStream materialImageOrVoiceDownload(String mediaId) throws WxErrorException { | public InputStream materialImageOrVoiceDownload(String mediaId) throws WxErrorException { | ||||
| return this.wxMpService.execute(MaterialVoiceAndImageDownloadRequestExecutor | return this.wxMpService.execute(MaterialVoiceAndImageDownloadRequestExecutor | ||||
| .create(this.wxMpService.getRequestHttp(), this.wxMpService.getWxMpConfigStorage().getTmpDirFile()), MATERIAL_GET_URL, mediaId); | |||||
| .create(this.wxMpService.getRequestHttp(), this.wxMpService.getWxMpConfigStorage().getTmpDirFile()), | |||||
| MATERIAL_GET_URL, mediaId); | |||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpMaterialVideoInfoResult materialVideoInfo(String mediaId) throws WxErrorException { | public WxMpMaterialVideoInfoResult materialVideoInfo(String mediaId) throws WxErrorException { | ||||
| return this.wxMpService.execute(MaterialVideoInfoRequestExecutor.create(this.wxMpService.getRequestHttp()), MATERIAL_GET_URL, mediaId); | |||||
| return this.wxMpService.execute(MaterialVideoInfoRequestExecutor.create(this.wxMpService.getRequestHttp()), | |||||
| MATERIAL_GET_URL, mediaId); | |||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpMaterialNews materialNewsInfo(String mediaId) throws WxErrorException { | public WxMpMaterialNews materialNewsInfo(String mediaId) throws WxErrorException { | ||||
| return this.wxMpService.execute(MaterialNewsInfoRequestExecutor.create(this.wxMpService.getRequestHttp()), MATERIAL_GET_URL, mediaId); | |||||
| return this.wxMpService.execute(MaterialNewsInfoRequestExecutor.create(this.wxMpService.getRequestHttp()), | |||||
| MATERIAL_GET_URL, mediaId); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -124,7 +117,8 @@ public class WxMpMaterialServiceImpl implements WxMpMaterialService { | |||||
| @Override | @Override | ||||
| public boolean materialDelete(String mediaId) throws WxErrorException { | public boolean materialDelete(String mediaId) throws WxErrorException { | ||||
| return this.wxMpService.execute(MaterialDeleteRequestExecutor.create(this.wxMpService.getRequestHttp()), MATERIAL_DEL_URL, mediaId); | |||||
| return this.wxMpService.execute(MaterialDeleteRequestExecutor.create(this.wxMpService.getRequestHttp()), | |||||
| MATERIAL_DEL_URL, mediaId); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -140,7 +134,7 @@ public class WxMpMaterialServiceImpl implements WxMpMaterialService { | |||||
| @Override | @Override | ||||
| public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(int offset, int count) throws WxErrorException { | public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(int offset, int count) throws WxErrorException { | ||||
| Map<String, Object> params = new HashMap<>(); | |||||
| Map<String, Object> params = new HashMap<>(4); | |||||
| params.put("type", WxConsts.MaterialType.NEWS); | params.put("type", WxConsts.MaterialType.NEWS); | ||||
| params.put("offset", offset); | params.put("offset", offset); | ||||
| params.put("count", count); | params.put("count", count); | ||||
| @@ -155,7 +149,7 @@ public class WxMpMaterialServiceImpl implements WxMpMaterialService { | |||||
| @Override | @Override | ||||
| public WxMpMaterialFileBatchGetResult materialFileBatchGet(String type, int offset, int count) throws WxErrorException { | public WxMpMaterialFileBatchGetResult materialFileBatchGet(String type, int offset, int count) throws WxErrorException { | ||||
| Map<String, Object> params = new HashMap<>(); | |||||
| Map<String, Object> params = new HashMap<>(4); | |||||
| params.put("type", type); | params.put("type", type); | ||||
| params.put("offset", offset); | params.put("offset", offset); | ||||
| params.put("count", count); | params.put("count", count); | ||||
| @@ -5,7 +5,9 @@ import java.net.URLDecoder; | |||||
| import java.util.HashMap; | import java.util.HashMap; | ||||
| import java.util.Map; | import java.util.Map; | ||||
| import lombok.RequiredArgsConstructor; | |||||
| import me.chanjar.weixin.mp.bean.membercard.*; | import me.chanjar.weixin.mp.bean.membercard.*; | ||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import com.google.gson.Gson; | import com.google.gson.Gson; | ||||
| @@ -40,15 +42,12 @@ import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
| * @version 2017/7/8 | * @version 2017/7/8 | ||||
| */ | */ | ||||
| @Slf4j | @Slf4j | ||||
| @RequiredArgsConstructor | |||||
| public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | ||||
| private WxMpService wxMpService; | |||||
| private final WxMpService wxMpService; | |||||
| private static final Gson GSON = WxMpGsonBuilder.create(); | private static final Gson GSON = WxMpGsonBuilder.create(); | ||||
| public WxMpMemberCardServiceImpl(WxMpService wxMpService) { | |||||
| this.wxMpService = wxMpService; | |||||
| } | |||||
| @Override | @Override | ||||
| public WxMpService getWxMpService() { | public WxMpService getWxMpService() { | ||||
| return this.wxMpService; | return this.wxMpService; | ||||
| @@ -70,7 +69,7 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | |||||
| return validResult; | return validResult; | ||||
| } | } | ||||
| String response = this.wxMpService.post(MEMBER_CARD_CREATE, GSON.toJson(createMessageMessage)); | |||||
| String response = this.wxMpService.post(WxMpApiUrl.MemberCard.MEMBER_CARD_CREATE, GSON.toJson(createMessageMessage)); | |||||
| return WxMpCardCreateResult.fromJson(response); | return WxMpCardCreateResult.fromJson(response); | ||||
| } | } | ||||
| @@ -212,7 +211,7 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | |||||
| @Override | @Override | ||||
| public String activateMemberCard(WxMpMemberCardActivatedMessage activatedMessage) throws WxErrorException { | public String activateMemberCard(WxMpMemberCardActivatedMessage activatedMessage) throws WxErrorException { | ||||
| return this.wxMpService.post(MEMBER_CARD_ACTIVATE, GSON.toJson(activatedMessage)); | |||||
| return this.wxMpService.post(WxMpApiUrl.MemberCard.MEMBER_CARD_ACTIVATE, GSON.toJson(activatedMessage)); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -221,7 +220,7 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | |||||
| jsonObject.addProperty("card_id", cardId); | jsonObject.addProperty("card_id", cardId); | ||||
| jsonObject.addProperty("code", code); | jsonObject.addProperty("code", code); | ||||
| String responseContent = this.getWxMpService().post(MEMBER_CARD_USER_INFO_GET, jsonObject.toString()); | |||||
| String responseContent = this.getWxMpService().post(WxMpApiUrl.MemberCard.MEMBER_CARD_USER_INFO_GET, jsonObject.toString()); | |||||
| log.debug("{}", responseContent); | log.debug("{}", responseContent); | ||||
| JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | ||||
| return WxMpGsonBuilder.create().fromJson(tmpJsonElement, | return WxMpGsonBuilder.create().fromJson(tmpJsonElement, | ||||
| @@ -233,7 +232,7 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | |||||
| public WxMpMemberCardUpdateResult updateUserMemberCard(WxMpMemberCardUpdateMessage updateUserMessage) | public WxMpMemberCardUpdateResult updateUserMemberCard(WxMpMemberCardUpdateMessage updateUserMessage) | ||||
| throws WxErrorException { | throws WxErrorException { | ||||
| String responseContent = this.getWxMpService().post(MEMBER_CARD_UPDATE_USER, GSON.toJson(updateUserMessage)); | |||||
| String responseContent = this.getWxMpService().post(WxMpApiUrl.MemberCard.MEMBER_CARD_UPDATE_USER, GSON.toJson(updateUserMessage)); | |||||
| JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | ||||
| return WxMpGsonBuilder.create().fromJson(tmpJsonElement, | return WxMpGsonBuilder.create().fromJson(tmpJsonElement, | ||||
| @@ -243,7 +242,7 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | |||||
| @Override | @Override | ||||
| public MemberCardActivateUserFormResult setActivateUserForm(MemberCardActivateUserFormRequest userFormRequest) throws WxErrorException { | public MemberCardActivateUserFormResult setActivateUserForm(MemberCardActivateUserFormRequest userFormRequest) throws WxErrorException { | ||||
| String responseContent = this.getWxMpService().post(MEMBER_CARD_ACTIVATE_USER_FORM, GSON.toJson(userFormRequest)); | |||||
| String responseContent = this.getWxMpService().post(WxMpApiUrl.MemberCard.MEMBER_CARD_ACTIVATE_USER_FORM, GSON.toJson(userFormRequest)); | |||||
| return MemberCardActivateUserFormResult.fromJson(responseContent); | return MemberCardActivateUserFormResult.fromJson(responseContent); | ||||
| } | } | ||||
| @@ -252,7 +251,7 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | |||||
| JsonObject params = new JsonObject(); | JsonObject params = new JsonObject(); | ||||
| params.addProperty("card_id", cardId); | params.addProperty("card_id", cardId); | ||||
| params.addProperty("outer_str", outStr); | params.addProperty("outer_str", outStr); | ||||
| String response = this.wxMpService.post(MEMBER_CARD_ACTIVATE_URL, GSON.toJson(params)); | |||||
| String response = this.wxMpService.post(WxMpApiUrl.MemberCard.MEMBER_CARD_ACTIVATE_URL, GSON.toJson(params)); | |||||
| ActivatePluginParamResult result = GSON.fromJson(response, ActivatePluginParamResult.class); | ActivatePluginParamResult result = GSON.fromJson(response, ActivatePluginParamResult.class); | ||||
| if (0 == result.getErrcode()) { | if (0 == result.getErrcode()) { | ||||
| String url = result.getUrl(); | String url = result.getUrl(); | ||||
| @@ -273,18 +272,16 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | |||||
| @Override | @Override | ||||
| public CardUpdateResult updateCardInfo(MemberCardUpdateRequest memberCardUpdateRequest) throws WxErrorException { | public CardUpdateResult updateCardInfo(MemberCardUpdateRequest memberCardUpdateRequest) throws WxErrorException { | ||||
| String response = this.wxMpService.post(MEMBER_CARD_UPDATE, GSON.toJson(memberCardUpdateRequest)); | |||||
| CardUpdateResult result = GSON.fromJson(response, CardUpdateResult.class); | |||||
| return result; | |||||
| String response = this.wxMpService.post(WxMpApiUrl.MemberCard.MEMBER_CARD_UPDATE, GSON.toJson(memberCardUpdateRequest)); | |||||
| return GSON.fromJson(response, CardUpdateResult.class); | |||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpMemberCardActivateTempInfoResult getActivateTempInfo(String activateTicket) throws WxErrorException { | public WxMpMemberCardActivateTempInfoResult getActivateTempInfo(String activateTicket) throws WxErrorException { | ||||
| JsonObject params = new JsonObject(); | JsonObject params = new JsonObject(); | ||||
| params.addProperty("activate_ticket", activateTicket); | params.addProperty("activate_ticket", activateTicket); | ||||
| String response = this.wxMpService.post(MEMBER_CARD_ACTIVATE_TEMP_INFO, GSON.toJson(params)); | |||||
| WxMpMemberCardActivateTempInfoResult result = GSON.fromJson(response, WxMpMemberCardActivateTempInfoResult.class); | |||||
| return result; | |||||
| String response = this.wxMpService.post(WxMpApiUrl.MemberCard.MEMBER_CARD_ACTIVATE_TEMP_INFO, GSON.toJson(params)); | |||||
| return GSON.fromJson(response, WxMpMemberCardActivateTempInfoResult.class); | |||||
| } | } | ||||
| private static String truncateUrlPage(String strURL) { | private static String truncateUrlPage(String strURL) { | ||||
| @@ -302,7 +299,7 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | |||||
| return strAllParam; | return strAllParam; | ||||
| } | } | ||||
| public static Map<String, String> parseRequestUrl(String url) { | |||||
| private static Map<String, String> parseRequestUrl(String url) { | |||||
| Map<String, String> mapRequest = new HashMap<>(16); | Map<String, String> mapRequest = new HashMap<>(16); | ||||
| String[] arrSplit; | String[] arrSplit; | ||||
| @@ -2,34 +2,34 @@ package me.chanjar.weixin.mp.api.impl; | |||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||
| import com.google.gson.JsonParser; | import com.google.gson.JsonParser; | ||||
| import lombok.RequiredArgsConstructor; | |||||
| import lombok.extern.slf4j.Slf4j; | |||||
| import me.chanjar.weixin.common.bean.menu.WxMenu; | import me.chanjar.weixin.common.bean.menu.WxMenu; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.mp.api.WxMpMenuService; | import me.chanjar.weixin.mp.api.WxMpMenuService; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
| import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult; | import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult; | ||||
| import me.chanjar.weixin.mp.bean.menu.WxMpMenu; | import me.chanjar.weixin.mp.bean.menu.WxMpMenu; | ||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Menu.*; | |||||
| /** | /** | ||||
| * Created by Binary Wang on 2016/7/21. | * Created by Binary Wang on 2016/7/21. | ||||
| * | |||||
| * @author Binary Wang | |||||
| */ | */ | ||||
| @Slf4j | |||||
| @RequiredArgsConstructor | |||||
| public class WxMpMenuServiceImpl implements WxMpMenuService { | public class WxMpMenuServiceImpl implements WxMpMenuService { | ||||
| private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/menu"; | |||||
| private static Logger log = LoggerFactory.getLogger(WxMpMenuServiceImpl.class); | |||||
| private WxMpService wxMpService; | |||||
| public WxMpMenuServiceImpl(WxMpService wxMpService) { | |||||
| this.wxMpService = wxMpService; | |||||
| } | |||||
| private final WxMpService wxMpService; | |||||
| @Override | @Override | ||||
| public String menuCreate(WxMenu menu) throws WxErrorException { | public String menuCreate(WxMenu menu) throws WxErrorException { | ||||
| String menuJson = menu.toJson(); | String menuJson = menu.toJson(); | ||||
| String url = API_URL_PREFIX + "/create"; | |||||
| WxMpApiUrl.Menu url = MENU_CREATE; | |||||
| if (menu.getMatchRule() != null) { | if (menu.getMatchRule() != null) { | ||||
| url = API_URL_PREFIX + "/addconditional"; | |||||
| url = MENU_ADDCONDITIONAL; | |||||
| } | } | ||||
| log.debug("开始创建菜单:{}", menuJson); | log.debug("开始创建菜单:{}", menuJson); | ||||
| @@ -48,9 +48,9 @@ public class WxMpMenuServiceImpl implements WxMpMenuService { | |||||
| public String menuCreate(String json) throws WxErrorException { | public String menuCreate(String json) throws WxErrorException { | ||||
| JsonParser jsonParser = new JsonParser(); | JsonParser jsonParser = new JsonParser(); | ||||
| JsonObject jsonObject = jsonParser.parse(json).getAsJsonObject(); | JsonObject jsonObject = jsonParser.parse(json).getAsJsonObject(); | ||||
| String url = API_URL_PREFIX + "/create"; | |||||
| WxMpApiUrl.Menu url = MENU_CREATE; | |||||
| if (jsonObject.get("matchrule") != null) { | if (jsonObject.get("matchrule") != null) { | ||||
| url = API_URL_PREFIX + "/addconditional"; | |||||
| url = MENU_ADDCONDITIONAL; | |||||
| } | } | ||||
| String result = this.wxMpService.post(url, json); | String result = this.wxMpService.post(url, json); | ||||
| @@ -63,25 +63,22 @@ public class WxMpMenuServiceImpl implements WxMpMenuService { | |||||
| @Override | @Override | ||||
| public void menuDelete() throws WxErrorException { | public void menuDelete() throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/delete"; | |||||
| String result = this.wxMpService.get(url, null); | |||||
| String result = this.wxMpService.get(MENU_DELETE, null); | |||||
| log.debug("删除菜单结果:{}", result); | log.debug("删除菜单结果:{}", result); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public void menuDelete(String menuId) throws WxErrorException { | public void menuDelete(String menuId) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/delconditional"; | |||||
| JsonObject jsonObject = new JsonObject(); | JsonObject jsonObject = new JsonObject(); | ||||
| jsonObject.addProperty("menuid", menuId); | jsonObject.addProperty("menuid", menuId); | ||||
| String result = this.wxMpService.post(url, jsonObject.toString()); | |||||
| String result = this.wxMpService.post(MENU_DELCONDITIONAL, jsonObject.toString()); | |||||
| log.debug("根据MeunId({})删除个性化菜单结果:{}", menuId, result); | log.debug("根据MeunId({})删除个性化菜单结果:{}", menuId, result); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpMenu menuGet() throws WxErrorException { | public WxMpMenu menuGet() throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/get"; | |||||
| try { | try { | ||||
| String resultContent = this.wxMpService.get(url, null); | |||||
| String resultContent = this.wxMpService.get(MENU_GET, null); | |||||
| return WxMpMenu.fromJson(resultContent); | return WxMpMenu.fromJson(resultContent); | ||||
| } catch (WxErrorException e) { | } catch (WxErrorException e) { | ||||
| // 46003 不存在的菜单数据 | // 46003 不存在的菜单数据 | ||||
| @@ -94,11 +91,10 @@ public class WxMpMenuServiceImpl implements WxMpMenuService { | |||||
| @Override | @Override | ||||
| public WxMenu menuTryMatch(String userid) throws WxErrorException { | public WxMenu menuTryMatch(String userid) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/trymatch"; | |||||
| JsonObject jsonObject = new JsonObject(); | JsonObject jsonObject = new JsonObject(); | ||||
| jsonObject.addProperty("user_id", userid); | jsonObject.addProperty("user_id", userid); | ||||
| try { | try { | ||||
| String resultContent = this.wxMpService.post(url, jsonObject.toString()); | |||||
| String resultContent = this.wxMpService.post(MENU_TRYMATCH, jsonObject.toString()); | |||||
| return WxMenu.fromJson(resultContent); | return WxMenu.fromJson(resultContent); | ||||
| } catch (WxErrorException e) { | } catch (WxErrorException e) { | ||||
| // 46003 不存在的菜单数据;46002 不存在的菜单版本 | // 46003 不存在的菜单数据;46002 不存在的菜单版本 | ||||
| @@ -112,8 +108,7 @@ public class WxMpMenuServiceImpl implements WxMpMenuService { | |||||
| @Override | @Override | ||||
| public WxMpGetSelfMenuInfoResult getSelfMenuInfo() throws WxErrorException { | public WxMpGetSelfMenuInfoResult getSelfMenuInfo() throws WxErrorException { | ||||
| String url = "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info"; | |||||
| String resultContent = this.wxMpService.get(url, null); | |||||
| String resultContent = this.wxMpService.get(GET_CURRENT_SELFMENU_INFO, null); | |||||
| return WxMpGetSelfMenuInfoResult.fromJson(resultContent); | return WxMpGetSelfMenuInfoResult.fromJson(resultContent); | ||||
| } | } | ||||
| } | } | ||||
| @@ -1,6 +1,7 @@ | |||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||
| import lombok.RequiredArgsConstructor; | |||||
| import me.chanjar.weixin.common.error.WxError; | import me.chanjar.weixin.common.error.WxError; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.mp.api.WxMpQrcodeService; | import me.chanjar.weixin.mp.api.WxMpQrcodeService; | ||||
| @@ -14,16 +15,16 @@ import java.io.UnsupportedEncodingException; | |||||
| import java.net.URLEncoder; | import java.net.URLEncoder; | ||||
| import java.nio.charset.StandardCharsets; | import java.nio.charset.StandardCharsets; | ||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Qrcode.*; | |||||
| /** | /** | ||||
| * Created by Binary Wang on 2016/7/21. | * Created by Binary Wang on 2016/7/21. | ||||
| * | |||||
| * @author Binary Wang | |||||
| */ | */ | ||||
| @RequiredArgsConstructor | |||||
| public class WxMpQrcodeServiceImpl implements WxMpQrcodeService { | public class WxMpQrcodeServiceImpl implements WxMpQrcodeService { | ||||
| private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/qrcode"; | |||||
| private WxMpService wxMpService; | |||||
| public WxMpQrcodeServiceImpl(WxMpService wxMpService) { | |||||
| this.wxMpService = wxMpService; | |||||
| } | |||||
| private final WxMpService wxMpService; | |||||
| @Override | @Override | ||||
| public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException { | public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException { | ||||
| @@ -31,37 +32,20 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService { | |||||
| throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("临时二维码场景值不能为0!").build()); | throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("临时二维码场景值不能为0!").build()); | ||||
| } | } | ||||
| //expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。 | |||||
| if (expireSeconds != null && expireSeconds > 2592000) { | |||||
| throw new WxErrorException(WxError.builder().errorCode(-1) | |||||
| .errorMsg("临时二维码有效时间最大不能超过2592000(即30天)!").build()); | |||||
| } | |||||
| if (expireSeconds == null) { | |||||
| expireSeconds = 30; | |||||
| } | |||||
| String url = API_URL_PREFIX + "/create"; | |||||
| JsonObject json = new JsonObject(); | |||||
| json.addProperty("action_name", "QR_SCENE"); | |||||
| json.addProperty("expire_seconds", expireSeconds); | |||||
| JsonObject actionInfo = new JsonObject(); | |||||
| JsonObject scene = new JsonObject(); | |||||
| scene.addProperty("scene_id", sceneId); | |||||
| actionInfo.add("scene", scene); | |||||
| json.add("action_info", actionInfo); | |||||
| String responseContent = this.wxMpService.post(url, json.toString()); | |||||
| return WxMpQrCodeTicket.fromJson(responseContent); | |||||
| return this.createQrCode("QR_SCENE", null, sceneId, expireSeconds); | |||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpQrCodeTicket qrCodeCreateTmpTicket(String sceneStr, Integer expireSeconds) throws WxErrorException { | public WxMpQrCodeTicket qrCodeCreateTmpTicket(String sceneStr, Integer expireSeconds) throws WxErrorException { | ||||
| if (StringUtils.isBlank(sceneStr)) { | if (StringUtils.isBlank(sceneStr)) { | ||||
| throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("临时二维码场景值不能为空!").build()); | throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("临时二维码场景值不能为空!").build()); | ||||
| } | } | ||||
| return this.createQrCode("QR_STR_SCENE", sceneStr, null, expireSeconds); | |||||
| } | |||||
| private WxMpQrCodeTicket createQrCode(String actionName, String sceneStr, Integer sceneId, Integer expireSeconds) | |||||
| throws WxErrorException { | |||||
| //expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。 | //expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。 | ||||
| if (expireSeconds != null && expireSeconds > 2592000) { | if (expireSeconds != null && expireSeconds > 2592000) { | ||||
| throw new WxErrorException(WxError.builder().errorCode(-1) | throw new WxErrorException(WxError.builder().errorCode(-1) | ||||
| @@ -72,21 +56,31 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService { | |||||
| expireSeconds = 30; | expireSeconds = 30; | ||||
| } | } | ||||
| String url = API_URL_PREFIX + "/create"; | |||||
| return this.getQrCodeTicket(actionName, sceneStr, sceneId, expireSeconds); | |||||
| } | |||||
| private WxMpQrCodeTicket getQrCodeTicket(String actionName, String sceneStr, Integer sceneId, Integer expireSeconds) | |||||
| throws WxErrorException { | |||||
| JsonObject json = new JsonObject(); | JsonObject json = new JsonObject(); | ||||
| json.addProperty("action_name", "QR_STR_SCENE"); | |||||
| json.addProperty("expire_seconds", expireSeconds); | |||||
| json.addProperty("action_name", actionName); | |||||
| if (expireSeconds != null) { | |||||
| json.addProperty("expire_seconds", expireSeconds); | |||||
| } | |||||
| JsonObject actionInfo = new JsonObject(); | JsonObject actionInfo = new JsonObject(); | ||||
| JsonObject scene = new JsonObject(); | JsonObject scene = new JsonObject(); | ||||
| scene.addProperty("scene_str", sceneStr); | |||||
| if (sceneStr != null) { | |||||
| scene.addProperty("scene_str", sceneStr); | |||||
| } else if (sceneId != null) { | |||||
| scene.addProperty("scene_id", sceneId); | |||||
| } | |||||
| actionInfo.add("scene", scene); | actionInfo.add("scene", scene); | ||||
| json.add("action_info", actionInfo); | json.add("action_info", actionInfo); | ||||
| String responseContent = this.wxMpService.post(url, json.toString()); | |||||
| String responseContent = this.wxMpService.post(QRCODE_CREATE, json.toString()); | |||||
| return WxMpQrCodeTicket.fromJson(responseContent); | return WxMpQrCodeTicket.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId) throws WxErrorException { | public WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId) throws WxErrorException { | ||||
| if (sceneId < 1 || sceneId > 100000) { | if (sceneId < 1 || sceneId > 100000) { | ||||
| @@ -95,44 +89,23 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService { | |||||
| .build()); | .build()); | ||||
| } | } | ||||
| String url = API_URL_PREFIX + "/create"; | |||||
| JsonObject json = new JsonObject(); | |||||
| json.addProperty("action_name", "QR_LIMIT_SCENE"); | |||||
| JsonObject actionInfo = new JsonObject(); | |||||
| JsonObject scene = new JsonObject(); | |||||
| scene.addProperty("scene_id", sceneId); | |||||
| actionInfo.add("scene", scene); | |||||
| json.add("action_info", actionInfo); | |||||
| String responseContent = this.wxMpService.post(url, json.toString()); | |||||
| return WxMpQrCodeTicket.fromJson(responseContent); | |||||
| return this.getQrCodeTicket("QR_LIMIT_SCENE", null, sceneId, null); | |||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpQrCodeTicket qrCodeCreateLastTicket(String sceneStr) throws WxErrorException { | public WxMpQrCodeTicket qrCodeCreateLastTicket(String sceneStr) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/create"; | |||||
| JsonObject json = new JsonObject(); | |||||
| json.addProperty("action_name", "QR_LIMIT_STR_SCENE"); | |||||
| JsonObject actionInfo = new JsonObject(); | |||||
| JsonObject scene = new JsonObject(); | |||||
| scene.addProperty("scene_str", sceneStr); | |||||
| actionInfo.add("scene", scene); | |||||
| json.add("action_info", actionInfo); | |||||
| String responseContent = this.wxMpService.post(url, json.toString()); | |||||
| return WxMpQrCodeTicket.fromJson(responseContent); | |||||
| return this.getQrCodeTicket("QR_LIMIT_STR_SCENE", sceneStr, null, null); | |||||
| } | } | ||||
| @Override | @Override | ||||
| public File qrCodePicture(WxMpQrCodeTicket ticket) throws WxErrorException { | public File qrCodePicture(WxMpQrCodeTicket ticket) throws WxErrorException { | ||||
| String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode"; | |||||
| return this.wxMpService.execute(QrCodeRequestExecutor.create(this.wxMpService.getRequestHttp()), url, ticket); | |||||
| return this.wxMpService.execute(QrCodeRequestExecutor.create(this.wxMpService.getRequestHttp()), SHOW_QRCODE, ticket); | |||||
| } | } | ||||
| @Override | @Override | ||||
| public String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErrorException { | public String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErrorException { | ||||
| String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s"; | |||||
| try { | try { | ||||
| String resultUrl = String.format(url, | |||||
| URLEncoder.encode(ticket, StandardCharsets.UTF_8.name())); | |||||
| String resultUrl = String.format(SHOW_QRCODE_WITH_TICKET.getUrl(), URLEncoder.encode(ticket, StandardCharsets.UTF_8.name())); | |||||
| if (needShortUrl) { | if (needShortUrl) { | ||||
| return this.wxMpService.shortUrl(resultUrl); | return this.wxMpService.shortUrl(resultUrl); | ||||
| } | } | ||||
| @@ -145,7 +118,7 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService { | |||||
| @Override | @Override | ||||
| public String qrCodePictureUrl(String ticket) throws WxErrorException { | public String qrCodePictureUrl(String ticket) throws WxErrorException { | ||||
| return qrCodePictureUrl(ticket, false); | |||||
| return this.qrCodePictureUrl(ticket, false); | |||||
| } | } | ||||
| } | } | ||||
| @@ -8,7 +8,7 @@ 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.ApacheHttpClientBuilder; | ||||
| import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder; | import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder; | ||||
| import me.chanjar.weixin.mp.api.WxMpConfigStorage; | import me.chanjar.weixin.mp.api.WxMpConfigStorage; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | |||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import org.apache.http.HttpHost; | import org.apache.http.HttpHost; | ||||
| import org.apache.http.client.config.RequestConfig; | import org.apache.http.client.config.RequestConfig; | ||||
| import org.apache.http.client.methods.CloseableHttpResponse; | import org.apache.http.client.methods.CloseableHttpResponse; | ||||
| @@ -19,8 +19,12 @@ import org.apache.http.impl.client.CloseableHttpClient; | |||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.util.concurrent.locks.Lock; | import java.util.concurrent.locks.Lock; | ||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Other.*; | |||||
| /** | /** | ||||
| * apache http client方式实现. | * apache http client方式实现. | ||||
| * | |||||
| * @author someone | |||||
| */ | */ | ||||
| public class WxMpServiceHttpClientImpl extends BaseWxMpServiceImpl<CloseableHttpClient, HttpHost> { | public class WxMpServiceHttpClientImpl extends BaseWxMpServiceImpl<CloseableHttpClient, HttpHost> { | ||||
| private CloseableHttpClient httpClient; | private CloseableHttpClient httpClient; | ||||
| @@ -70,7 +74,7 @@ public class WxMpServiceHttpClientImpl extends BaseWxMpServiceImpl<CloseableHttp | |||||
| Lock lock = this.getWxMpConfigStorage().getAccessTokenLock(); | Lock lock = this.getWxMpConfigStorage().getAccessTokenLock(); | ||||
| lock.lock(); | lock.lock(); | ||||
| try { | try { | ||||
| String url = String.format(WxMpService.GET_ACCESS_TOKEN_URL, | |||||
| String url = String.format(GET_ACCESS_TOKEN_URL.getUrl(), | |||||
| this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret()); | this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret()); | ||||
| try { | try { | ||||
| HttpGet httpGet = new HttpGet(url); | HttpGet httpGet = new HttpGet(url); | ||||
| @@ -8,12 +8,15 @@ import me.chanjar.weixin.common.error.WxError; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.common.util.http.HttpType; | import me.chanjar.weixin.common.util.http.HttpType; | ||||
| import me.chanjar.weixin.mp.api.WxMpConfigStorage; | import me.chanjar.weixin.mp.api.WxMpConfigStorage; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | |||||
| import java.util.concurrent.locks.Lock; | import java.util.concurrent.locks.Lock; | ||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Other.GET_ACCESS_TOKEN_URL; | |||||
| /** | /** | ||||
| * jodd-http方式实现 | |||||
| * jodd-http方式实现. | |||||
| * | |||||
| * @author someone | |||||
| */ | */ | ||||
| public class WxMpServiceJoddHttpImpl extends BaseWxMpServiceImpl<HttpConnectionProvider, ProxyInfo> { | public class WxMpServiceJoddHttpImpl extends BaseWxMpServiceImpl<HttpConnectionProvider, ProxyInfo> { | ||||
| private HttpConnectionProvider httpClient; | private HttpConnectionProvider httpClient; | ||||
| @@ -55,7 +58,7 @@ public class WxMpServiceJoddHttpImpl extends BaseWxMpServiceImpl<HttpConnectionP | |||||
| Lock lock = this.getWxMpConfigStorage().getAccessTokenLock(); | Lock lock = this.getWxMpConfigStorage().getAccessTokenLock(); | ||||
| lock.lock(); | lock.lock(); | ||||
| try { | try { | ||||
| String url = String.format(WxMpService.GET_ACCESS_TOKEN_URL, | |||||
| String url = String.format(GET_ACCESS_TOKEN_URL.getUrl(), | |||||
| this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret()); | this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret()); | ||||
| HttpRequest request = HttpRequest.get(url); | HttpRequest request = HttpRequest.get(url); | ||||
| @@ -7,14 +7,18 @@ import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import me.chanjar.weixin.common.util.http.HttpType; | import me.chanjar.weixin.common.util.http.HttpType; | ||||
| import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo; | import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo; | ||||
| import me.chanjar.weixin.mp.api.WxMpConfigStorage; | import me.chanjar.weixin.mp.api.WxMpConfigStorage; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | |||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import okhttp3.*; | import okhttp3.*; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.util.concurrent.locks.Lock; | import java.util.concurrent.locks.Lock; | ||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Other.*; | |||||
| /** | /** | ||||
| * okhttp实现 | |||||
| * okhttp实现. | |||||
| * | |||||
| * @author someone | |||||
| */ | */ | ||||
| public class WxMpServiceOkHttpImpl extends BaseWxMpServiceImpl<OkHttpClient, OkHttpProxyInfo> { | public class WxMpServiceOkHttpImpl extends BaseWxMpServiceImpl<OkHttpClient, OkHttpProxyInfo> { | ||||
| private OkHttpClient httpClient; | private OkHttpClient httpClient; | ||||
| @@ -44,7 +48,7 @@ public class WxMpServiceOkHttpImpl extends BaseWxMpServiceImpl<OkHttpClient, OkH | |||||
| Lock lock = this.getWxMpConfigStorage().getAccessTokenLock(); | Lock lock = this.getWxMpConfigStorage().getAccessTokenLock(); | ||||
| lock.lock(); | lock.lock(); | ||||
| try { | try { | ||||
| String url = String.format(WxMpService.GET_ACCESS_TOKEN_URL, | |||||
| String url = String.format(GET_ACCESS_TOKEN_URL.getUrl(), | |||||
| this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret()); | this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret()); | ||||
| Request request = new Request.Builder().url(url).get().build(); | Request request = new Request.Builder().url(url).get().build(); | ||||
| @@ -1,5 +1,6 @@ | |||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
| import lombok.RequiredArgsConstructor; | |||||
| import me.chanjar.weixin.common.WxType; | import me.chanjar.weixin.common.WxType; | ||||
| import me.chanjar.weixin.common.error.WxError; | import me.chanjar.weixin.common.error.WxError; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| @@ -9,59 +10,45 @@ import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult; | |||||
| import me.chanjar.weixin.mp.bean.WxMpShakeQuery; | import me.chanjar.weixin.mp.bean.WxMpShakeQuery; | ||||
| import me.chanjar.weixin.mp.bean.shake.*; | import me.chanjar.weixin.mp.bean.shake.*; | ||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.ShakeAround.*; | |||||
| /** | /** | ||||
| * Created by rememberber on 2017/6/5. | * Created by rememberber on 2017/6/5. | ||||
| * | * | ||||
| * @author rememberber | * @author rememberber | ||||
| */ | */ | ||||
| @RequiredArgsConstructor | |||||
| public class WxMpShakeServiceImpl implements WxMpShakeService { | public class WxMpShakeServiceImpl implements WxMpShakeService { | ||||
| private final WxMpService wxMpService; | |||||
| private WxMpService wxMpService; | |||||
| public WxMpShakeServiceImpl(WxMpService wxMpService) { | |||||
| this.wxMpService = wxMpService; | |||||
| } | |||||
| /** | |||||
| * <pre> | |||||
| * 获取设备及用户信息<br/> | |||||
| * 获取设备信息,包括UUID、major、minor,以及距离、openID等信息。 | |||||
| * 详情请见: https://mp.weixin.qq.com/wiki?action=doc&id=mp1443447963 | |||||
| * http请求方式: POST(请使用https协议) | |||||
| * 接口地址:https://api.weixin.qq.com/shakearound/user/getshakeinfo?access_token=ACCESS_TOKE | |||||
| * </pre> | |||||
| * | |||||
| * @param wxMpShakeQuery 查询参数 | |||||
| */ | |||||
| @Override | @Override | ||||
| public WxMpShakeInfoResult getShakeInfo(WxMpShakeQuery wxMpShakeQuery) throws WxErrorException { | public WxMpShakeInfoResult getShakeInfo(WxMpShakeQuery wxMpShakeQuery) throws WxErrorException { | ||||
| String url = "https://api.weixin.qq.com/shakearound/user/getshakeinfo"; | |||||
| String postData = wxMpShakeQuery.toJsonString(); | String postData = wxMpShakeQuery.toJsonString(); | ||||
| String responseContent = this.wxMpService.post(url, postData); | |||||
| String responseContent = this.wxMpService.post(SHAKEAROUND_USER_GETSHAKEINFO, postData); | |||||
| return WxMpShakeInfoResult.fromJson(responseContent); | return WxMpShakeInfoResult.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpShakeAroundPageAddResult pageAdd(WxMpShakeAroundPageAddQuery shakeAroundPageAddQuery) throws WxErrorException { | |||||
| String url = "https://api.weixin.qq.com/shakearound/page/add"; | |||||
| public WxMpShakeAroundPageAddResult pageAdd(WxMpShakeAroundPageAddQuery shakeAroundPageAddQuery) | |||||
| throws WxErrorException { | |||||
| String postData = shakeAroundPageAddQuery.toJsonString(); | String postData = shakeAroundPageAddQuery.toJsonString(); | ||||
| String responseContent = this.wxMpService.post(url, postData); | |||||
| String responseContent = this.wxMpService.post(SHAKEAROUND_PAGE_ADD, postData); | |||||
| return WxMpShakeAroundPageAddResult.fromJson(responseContent); | return WxMpShakeAroundPageAddResult.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxError deviceBindPageQuery(WxMpShakeAroundDeviceBindPageQuery shakeAroundDeviceBindPageQuery) throws WxErrorException { | |||||
| String url = "https://api.weixin.qq.com/shakearound/device/bindpage"; | |||||
| public WxError deviceBindPageQuery(WxMpShakeAroundDeviceBindPageQuery shakeAroundDeviceBindPageQuery) | |||||
| throws WxErrorException { | |||||
| String postData = shakeAroundDeviceBindPageQuery.toJsonString(); | String postData = shakeAroundDeviceBindPageQuery.toJsonString(); | ||||
| String responseContent = this.wxMpService.post(url, postData); | |||||
| String responseContent = this.wxMpService.post(SHAKEAROUND_DEVICE_BINDPAGE, postData); | |||||
| return WxError.fromJson(responseContent, WxType.MP); | return WxError.fromJson(responseContent, WxType.MP); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpShakeAroundRelationSearchResult relationSearch(WxMpShakeAroundRelationSearchQuery shakeAroundRelationSearchQuery) throws WxErrorException { | |||||
| String url = "https://api.weixin.qq.com/shakearound/relation/search"; | |||||
| String postData = shakeAroundRelationSearchQuery.toJsonString(); | |||||
| String responseContent = this.wxMpService.post(url, postData); | |||||
| public WxMpShakeAroundRelationSearchResult relationSearch(WxMpShakeAroundRelationSearchQuery searchQuery) | |||||
| throws WxErrorException { | |||||
| String postData = searchQuery.toJsonString(); | |||||
| String responseContent = this.wxMpService.post(SHAKEAROUND_RELATION_SEARCH, postData); | |||||
| return WxMpShakeAroundRelationSearchResult.fromJson(responseContent); | return WxMpShakeAroundRelationSearchResult.fromJson(responseContent); | ||||
| } | } | ||||
| } | } | ||||
| @@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api.impl; | |||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||
| import com.google.gson.JsonParser; | import com.google.gson.JsonParser; | ||||
| import com.google.gson.reflect.TypeToken; | import com.google.gson.reflect.TypeToken; | ||||
| import lombok.RequiredArgsConstructor; | |||||
| import me.chanjar.weixin.common.WxType; | import me.chanjar.weixin.common.WxType; | ||||
| import me.chanjar.weixin.common.error.WxError; | import me.chanjar.weixin.common.error.WxError; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| @@ -12,6 +13,7 @@ import me.chanjar.weixin.mp.api.WxMpStoreService; | |||||
| import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo; | import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo; | ||||
| import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo; | import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo; | ||||
| import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult; | import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult; | ||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | ||||
| import java.util.List; | import java.util.List; | ||||
| @@ -21,18 +23,15 @@ import java.util.List; | |||||
| * | * | ||||
| * @author binarywang (https://github.com/binarywang) | * @author binarywang (https://github.com/binarywang) | ||||
| */ | */ | ||||
| @RequiredArgsConstructor | |||||
| public class WxMpStoreServiceImpl implements WxMpStoreService { | public class WxMpStoreServiceImpl implements WxMpStoreService { | ||||
| private WxMpService wxMpService; | |||||
| public WxMpStoreServiceImpl(WxMpService wxMpService) { | |||||
| this.wxMpService = wxMpService; | |||||
| } | |||||
| private final WxMpService wxMpService; | |||||
| @Override | @Override | ||||
| public void add(WxMpStoreBaseInfo request) throws WxErrorException { | public void add(WxMpStoreBaseInfo request) throws WxErrorException { | ||||
| BeanUtils.checkRequiredFields(request); | BeanUtils.checkRequiredFields(request); | ||||
| String response = this.wxMpService.post(POI_ADD_URL, request.toJson()); | |||||
| String response = this.wxMpService.post(WxMpApiUrl.Store.POI_ADD_URL, request.toJson()); | |||||
| WxError wxError = WxError.fromJson(response, WxType.MP); | WxError wxError = WxError.fromJson(response, WxType.MP); | ||||
| if (wxError.getErrorCode() != 0) { | if (wxError.getErrorCode() != 0) { | ||||
| throw new WxErrorException(wxError); | throw new WxErrorException(wxError); | ||||
| @@ -43,7 +42,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService { | |||||
| public WxMpStoreBaseInfo get(String poiId) throws WxErrorException { | public WxMpStoreBaseInfo get(String poiId) throws WxErrorException { | ||||
| JsonObject paramObject = new JsonObject(); | JsonObject paramObject = new JsonObject(); | ||||
| paramObject.addProperty("poi_id", poiId); | paramObject.addProperty("poi_id", poiId); | ||||
| String response = this.wxMpService.post(POI_GET_URL, paramObject.toString()); | |||||
| String response = this.wxMpService.post(WxMpApiUrl.Store.POI_GET_URL, paramObject.toString()); | |||||
| WxError wxError = WxError.fromJson(response, WxType.MP); | WxError wxError = WxError.fromJson(response, WxType.MP); | ||||
| if (wxError.getErrorCode() != 0) { | if (wxError.getErrorCode() != 0) { | ||||
| throw new WxErrorException(wxError); | throw new WxErrorException(wxError); | ||||
| @@ -56,7 +55,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService { | |||||
| public void delete(String poiId) throws WxErrorException { | public void delete(String poiId) throws WxErrorException { | ||||
| JsonObject paramObject = new JsonObject(); | JsonObject paramObject = new JsonObject(); | ||||
| paramObject.addProperty("poi_id", poiId); | paramObject.addProperty("poi_id", poiId); | ||||
| String response = this.wxMpService.post(POI_DEL_URL, paramObject.toString()); | |||||
| String response = this.wxMpService.post(WxMpApiUrl.Store.POI_DEL_URL, paramObject.toString()); | |||||
| WxError wxError = WxError.fromJson(response, WxType.MP); | WxError wxError = WxError.fromJson(response, WxType.MP); | ||||
| if (wxError.getErrorCode() != 0) { | if (wxError.getErrorCode() != 0) { | ||||
| throw new WxErrorException(wxError); | throw new WxErrorException(wxError); | ||||
| @@ -69,7 +68,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService { | |||||
| JsonObject params = new JsonObject(); | JsonObject params = new JsonObject(); | ||||
| params.addProperty("begin", begin); | params.addProperty("begin", begin); | ||||
| params.addProperty("limit", limit); | params.addProperty("limit", limit); | ||||
| String response = this.wxMpService.post(POI_LIST_URL, params.toString()); | |||||
| String response = this.wxMpService.post(WxMpApiUrl.Store.POI_LIST_URL, params.toString()); | |||||
| WxError wxError = WxError.fromJson(response, WxType.MP); | WxError wxError = WxError.fromJson(response, WxType.MP); | ||||
| if (wxError.getErrorCode() != 0) { | if (wxError.getErrorCode() != 0) { | ||||
| @@ -102,7 +101,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService { | |||||
| @Override | @Override | ||||
| public void update(WxMpStoreBaseInfo request) throws WxErrorException { | public void update(WxMpStoreBaseInfo request) throws WxErrorException { | ||||
| String response = this.wxMpService.post(POI_UPDATE_URL, request.toJson()); | |||||
| String response = this.wxMpService.post(WxMpApiUrl.Store.POI_UPDATE_URL, request.toJson()); | |||||
| WxError wxError = WxError.fromJson(response, WxType.MP); | WxError wxError = WxError.fromJson(response, WxType.MP); | ||||
| if (wxError.getErrorCode() != 0) { | if (wxError.getErrorCode() != 0) { | ||||
| throw new WxErrorException(wxError); | throw new WxErrorException(wxError); | ||||
| @@ -111,7 +110,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService { | |||||
| @Override | @Override | ||||
| public List<String> listCategories() throws WxErrorException { | public List<String> listCategories() throws WxErrorException { | ||||
| String response = this.wxMpService.get(POI_GET_WX_CATEGORY_URL, null); | |||||
| String response = this.wxMpService.get(WxMpApiUrl.Store.POI_GET_WX_CATEGORY_URL, null); | |||||
| WxError wxError = WxError.fromJson(response, WxType.MP); | WxError wxError = WxError.fromJson(response, WxType.MP); | ||||
| if (wxError.getErrorCode() != 0) { | if (wxError.getErrorCode() != 0) { | ||||
| throw new WxErrorException(wxError); | throw new WxErrorException(wxError); | ||||
| @@ -1,32 +1,30 @@ | |||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
| import lombok.RequiredArgsConstructor; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.common.util.http.URIUtil; | import me.chanjar.weixin.common.util.http.URIUtil; | ||||
| import me.chanjar.weixin.mp.api.WxMpConfigStorage; | import me.chanjar.weixin.mp.api.WxMpConfigStorage; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
| import me.chanjar.weixin.mp.api.WxMpSubscribeMsgService; | import me.chanjar.weixin.mp.api.WxMpSubscribeMsgService; | ||||
| import me.chanjar.weixin.mp.bean.subscribe.WxMpSubscribeMessage; | import me.chanjar.weixin.mp.bean.subscribe.WxMpSubscribeMessage; | ||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.SubscribeMsg.*; | |||||
| /** | /** | ||||
| * 一次性订阅消息接口. | |||||
| * | |||||
| * @author Mklaus | * @author Mklaus | ||||
| * @date 2018-01-22 上午11:19 | * @date 2018-01-22 上午11:19 | ||||
| */ | */ | ||||
| @RequiredArgsConstructor | |||||
| public class WxMpSubscribeMsgServiceImpl implements WxMpSubscribeMsgService { | public class WxMpSubscribeMsgServiceImpl implements WxMpSubscribeMsgService { | ||||
| private static final String SUBSCRIBE_MESSAGE_AUTHORIZE_URL = | |||||
| "https://mp.weixin.qq.com/mp/subscribemsg?action=get_confirm&appid=%s&scene=%d&template_id=%s&redirect_url=%s&reserved=%s#wechat_redirect"; | |||||
| private static final String SEND_MESSAGE_URL = "https://api.weixin.qq.com/cgi-bin/message/template/subscribe"; | |||||
| private WxMpService wxMpService; | |||||
| public WxMpSubscribeMsgServiceImpl(WxMpService wxMpService) { | |||||
| this.wxMpService = wxMpService; | |||||
| } | |||||
| private final WxMpService wxMpService; | |||||
| @Override | @Override | ||||
| public String subscribeMsgAuthorizationUrl(String redirectURI, int scene, String reserved) { | public String subscribeMsgAuthorizationUrl(String redirectURI, int scene, String reserved) { | ||||
| WxMpConfigStorage storage = this.wxMpService.getWxMpConfigStorage(); | WxMpConfigStorage storage = this.wxMpService.getWxMpConfigStorage(); | ||||
| return String.format(SUBSCRIBE_MESSAGE_AUTHORIZE_URL, | |||||
| return String.format(SUBSCRIBE_MESSAGE_AUTHORIZE_URL.getUrl(), | |||||
| storage.getAppId(), scene, storage.getTemplateId(), URIUtil.encodeURIComponent(redirectURI), reserved); | storage.getAppId(), scene, storage.getTemplateId(), URIUtil.encodeURIComponent(redirectURI), reserved); | ||||
| } | } | ||||
| @@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.api.impl; | |||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||
| import com.google.gson.JsonParser; | import com.google.gson.JsonParser; | ||||
| import lombok.RequiredArgsConstructor; | |||||
| import me.chanjar.weixin.common.WxType; | import me.chanjar.weixin.common.WxType; | ||||
| import me.chanjar.weixin.common.error.WxError; | import me.chanjar.weixin.common.error.WxError; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| @@ -10,9 +11,12 @@ import me.chanjar.weixin.mp.api.WxMpTemplateMsgService; | |||||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplate; | import me.chanjar.weixin.mp.bean.template.WxMpTemplate; | ||||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry; | import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry; | ||||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; | import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; | ||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import java.util.List; | import java.util.List; | ||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.TemplateMsg.*; | |||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| * Created by Binary Wang on 2016-10-14. | * Created by Binary Wang on 2016-10-14. | ||||
| @@ -20,20 +24,15 @@ import java.util.List; | |||||
| * | * | ||||
| * @author <a href="https://github.com/binarywang">Binary Wang</a> | * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||
| */ | */ | ||||
| @RequiredArgsConstructor | |||||
| public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService { | public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService { | ||||
| public static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/template"; | |||||
| private static final JsonParser JSON_PARSER = new JsonParser(); | private static final JsonParser JSON_PARSER = new JsonParser(); | ||||
| private WxMpService wxMpService; | |||||
| public WxMpTemplateMsgServiceImpl(WxMpService wxMpService) { | |||||
| this.wxMpService = wxMpService; | |||||
| } | |||||
| private final WxMpService wxMpService; | |||||
| @Override | @Override | ||||
| public String sendTemplateMsg(WxMpTemplateMessage templateMessage) throws WxErrorException { | public String sendTemplateMsg(WxMpTemplateMessage templateMessage) throws WxErrorException { | ||||
| String url = "https://api.weixin.qq.com/cgi-bin/message/template/send"; | |||||
| String responseContent = this.wxMpService.post(url, templateMessage.toJson()); | |||||
| String responseContent = this.wxMpService.post(MESSAGE_TEMPLATE_SEND, templateMessage.toJson()); | |||||
| final JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject(); | final JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject(); | ||||
| if (jsonObject.get("errcode").getAsInt() == 0) { | if (jsonObject.get("errcode").getAsInt() == 0) { | ||||
| return jsonObject.get("msgid").getAsString(); | return jsonObject.get("msgid").getAsString(); | ||||
| @@ -48,24 +47,21 @@ public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService { | |||||
| throw new IllegalArgumentException("行业Id不能为空,请核实"); | throw new IllegalArgumentException("行业Id不能为空,请核实"); | ||||
| } | } | ||||
| String url = API_URL_PREFIX + "/api_set_industry"; | |||||
| this.wxMpService.post(url, wxMpIndustry.toJson()); | |||||
| this.wxMpService.post(TEMPLATE_API_SET_INDUSTRY, wxMpIndustry.toJson()); | |||||
| return true; | return true; | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpTemplateIndustry getIndustry() throws WxErrorException { | public WxMpTemplateIndustry getIndustry() throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/get_industry"; | |||||
| String responseContent = this.wxMpService.get(url, null); | |||||
| String responseContent = this.wxMpService.get(TEMPLATE_GET_INDUSTRY, null); | |||||
| return WxMpTemplateIndustry.fromJson(responseContent); | return WxMpTemplateIndustry.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public String addTemplate(String shortTemplateId) throws WxErrorException { | public String addTemplate(String shortTemplateId) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/api_add_template"; | |||||
| JsonObject jsonObject = new JsonObject(); | JsonObject jsonObject = new JsonObject(); | ||||
| jsonObject.addProperty("template_id_short", shortTemplateId); | jsonObject.addProperty("template_id_short", shortTemplateId); | ||||
| String responseContent = this.wxMpService.post(url, jsonObject.toString()); | |||||
| String responseContent = this.wxMpService.post(TEMPLATE_API_ADD_TEMPLATE, jsonObject.toString()); | |||||
| final JsonObject result = JSON_PARSER.parse(responseContent).getAsJsonObject(); | final JsonObject result = JSON_PARSER.parse(responseContent).getAsJsonObject(); | ||||
| if (result.get("errcode").getAsInt() == 0) { | if (result.get("errcode").getAsInt() == 0) { | ||||
| return result.get("template_id").getAsString(); | return result.get("template_id").getAsString(); | ||||
| @@ -76,16 +72,14 @@ public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService { | |||||
| @Override | @Override | ||||
| public List<WxMpTemplate> getAllPrivateTemplate() throws WxErrorException { | public List<WxMpTemplate> getAllPrivateTemplate() throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/get_all_private_template"; | |||||
| return WxMpTemplate.fromJson(this.wxMpService.get(url, null)); | |||||
| return WxMpTemplate.fromJson(this.wxMpService.get(TEMPLATE_GET_ALL_PRIVATE_TEMPLATE, null)); | |||||
| } | } | ||||
| @Override | @Override | ||||
| public boolean delPrivateTemplate(String templateId) throws WxErrorException { | public boolean delPrivateTemplate(String templateId) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/del_private_template"; | |||||
| JsonObject jsonObject = new JsonObject(); | JsonObject jsonObject = new JsonObject(); | ||||
| jsonObject.addProperty("template_id", templateId); | jsonObject.addProperty("template_id", templateId); | ||||
| String responseContent = this.wxMpService.post(url, jsonObject.toString()); | |||||
| String responseContent = this.wxMpService.post(TEMPLATE_DEL_PRIVATE_TEMPLATE, jsonObject.toString()); | |||||
| WxError error = WxError.fromJson(responseContent, WxType.MP); | WxError error = WxError.fromJson(responseContent, WxType.MP); | ||||
| if (error.getErrorCode() == 0) { | if (error.getErrorCode() == 0) { | ||||
| return true; | return true; | ||||
| @@ -1,43 +1,42 @@ | |||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
| import java.util.HashMap; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||
| import lombok.RequiredArgsConstructor; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; | import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
| import me.chanjar.weixin.mp.api.WxMpUserBlacklistService; | import me.chanjar.weixin.mp.api.WxMpUserBlacklistService; | ||||
| import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; | import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; | ||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | ||||
| import java.util.HashMap; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.UserBlacklist.*; | |||||
| /** | /** | ||||
| * @author miller | * @author miller | ||||
| */ | */ | ||||
| @RequiredArgsConstructor | |||||
| public class WxMpUserBlacklistServiceImpl implements WxMpUserBlacklistService { | public class WxMpUserBlacklistServiceImpl implements WxMpUserBlacklistService { | ||||
| private static final String API_BLACKLIST_PREFIX = "https://api.weixin.qq.com/cgi-bin/tags/members"; | |||||
| private WxMpService wxMpService; | |||||
| public WxMpUserBlacklistServiceImpl(WxMpService wxMpService) { | |||||
| this.wxMpService = wxMpService; | |||||
| } | |||||
| private final WxMpService wxMpService; | |||||
| @Override | @Override | ||||
| public WxMpUserBlacklistGetResult getBlacklist(String nextOpenid) throws WxErrorException { | public WxMpUserBlacklistGetResult getBlacklist(String nextOpenid) throws WxErrorException { | ||||
| JsonObject jsonObject = new JsonObject(); | JsonObject jsonObject = new JsonObject(); | ||||
| jsonObject.addProperty("begin_openid", nextOpenid); | jsonObject.addProperty("begin_openid", nextOpenid); | ||||
| String url = API_BLACKLIST_PREFIX + "/getblacklist"; | |||||
| String responseContent = this.wxMpService.execute(SimplePostRequestExecutor.create(this.wxMpService.getRequestHttp()), url, jsonObject.toString()); | |||||
| String responseContent = this.wxMpService.execute(SimplePostRequestExecutor.create(this.wxMpService.getRequestHttp()), | |||||
| GETBLACKLIST, jsonObject.toString()); | |||||
| return WxMpUserBlacklistGetResult.fromJson(responseContent); | return WxMpUserBlacklistGetResult.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public void pushToBlacklist(List<String> openidList) throws WxErrorException { | public void pushToBlacklist(List<String> openidList) throws WxErrorException { | ||||
| Map<String, Object> map = new HashMap<>(); | |||||
| Map<String, Object> map = new HashMap<>(2); | |||||
| map.put("openid_list", openidList); | map.put("openid_list", openidList); | ||||
| String url = API_BLACKLIST_PREFIX + "/batchblacklist"; | |||||
| this.wxMpService.execute(SimplePostRequestExecutor.create(this.wxMpService.getRequestHttp()), url, | |||||
| this.wxMpService.execute(SimplePostRequestExecutor.create(this.wxMpService.getRequestHttp()), BATCHBLACKLIST, | |||||
| WxMpGsonBuilder.create().toJson(map)); | WxMpGsonBuilder.create().toJson(map)); | ||||
| } | } | ||||
| @@ -45,7 +44,7 @@ public class WxMpUserBlacklistServiceImpl implements WxMpUserBlacklistService { | |||||
| public void pullFromBlacklist(List<String> openidList) throws WxErrorException { | public void pullFromBlacklist(List<String> openidList) throws WxErrorException { | ||||
| Map<String, Object> map = new HashMap<>(2); | Map<String, Object> map = new HashMap<>(2); | ||||
| map.put("openid_list", openidList); | map.put("openid_list", openidList); | ||||
| String url = API_BLACKLIST_PREFIX + "/batchunblacklist"; | |||||
| this.wxMpService.execute(SimplePostRequestExecutor.create(this.wxMpService.getRequestHttp()), url, WxMpGsonBuilder.create().toJson(map)); | |||||
| this.wxMpService.execute(SimplePostRequestExecutor.create(this.wxMpService.getRequestHttp()), BATCHUNBLACKLIST, | |||||
| WxMpGsonBuilder.create().toJson(map)); | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,11 +1,7 @@ | |||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
| import java.util.HashMap; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| import com.google.gson.JsonArray; | |||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||
| import lombok.RequiredArgsConstructor; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
| import me.chanjar.weixin.mp.api.WxMpUserService; | import me.chanjar.weixin.mp.api.WxMpUserService; | ||||
| @@ -13,19 +9,23 @@ import me.chanjar.weixin.mp.bean.WxMpUserQuery; | |||||
| import me.chanjar.weixin.mp.bean.result.WxMpChangeOpenid; | import me.chanjar.weixin.mp.bean.result.WxMpChangeOpenid; | ||||
| import me.chanjar.weixin.mp.bean.result.WxMpUser; | import me.chanjar.weixin.mp.bean.result.WxMpUser; | ||||
| import me.chanjar.weixin.mp.bean.result.WxMpUserList; | import me.chanjar.weixin.mp.bean.result.WxMpUserList; | ||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | ||||
| import java.util.HashMap; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.User.*; | |||||
| /** | /** | ||||
| * Created by Binary Wang on 2016/7/21. | * Created by Binary Wang on 2016/7/21. | ||||
| * | * | ||||
| * @author BinaryWang | * @author BinaryWang | ||||
| */ | */ | ||||
| @RequiredArgsConstructor | |||||
| public class WxMpUserServiceImpl implements WxMpUserService { | public class WxMpUserServiceImpl implements WxMpUserService { | ||||
| private WxMpService wxMpService; | |||||
| public WxMpUserServiceImpl(WxMpService wxMpService) { | |||||
| this.wxMpService = wxMpService; | |||||
| } | |||||
| private final WxMpService wxMpService; | |||||
| @Override | @Override | ||||
| public void userUpdateRemark(String openid, String remark) throws WxErrorException { | public void userUpdateRemark(String openid, String remark) throws WxErrorException { | ||||
| @@ -43,21 +43,19 @@ public class WxMpUserServiceImpl implements WxMpUserService { | |||||
| @Override | @Override | ||||
| public WxMpUser userInfo(String openid, String lang) throws WxErrorException { | public WxMpUser userInfo(String openid, String lang) throws WxErrorException { | ||||
| lang = lang == null ? "zh_CN" : lang; | lang = lang == null ? "zh_CN" : lang; | ||||
| String responseContent = this.wxMpService.get(USER_INFO_URL, | |||||
| "openid=" + openid + "&lang=" + lang); | |||||
| String responseContent = this.wxMpService.get(USER_INFO_URL, "openid=" + openid + "&lang=" + lang); | |||||
| return WxMpUser.fromJson(responseContent); | return WxMpUser.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpUserList userList(String nextOpenid) throws WxErrorException { | public WxMpUserList userList(String nextOpenid) throws WxErrorException { | ||||
| String responseContent = this.wxMpService.get(USER_GET_URL, | |||||
| nextOpenid == null ? null : "next_openid=" + nextOpenid); | |||||
| String responseContent = this.wxMpService.get(USER_GET_URL, nextOpenid == null ? null : "next_openid=" + nextOpenid); | |||||
| return WxMpUserList.fromJson(responseContent); | return WxMpUserList.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public List<WxMpChangeOpenid> changeOpenid(String fromAppid, List<String> openidList) throws WxErrorException { | public List<WxMpChangeOpenid> changeOpenid(String fromAppid, List<String> openidList) throws WxErrorException { | ||||
| Map<String, Object> map = new HashMap<>(); | |||||
| Map<String, Object> map = new HashMap<>(2); | |||||
| map.put("from_appid", fromAppid); | map.put("from_appid", fromAppid); | ||||
| map.put("openid_list", openidList); | map.put("openid_list", openidList); | ||||
| String responseContent = this.wxMpService.post(USER_CHANGE_OPENID_URL, WxMpGsonBuilder.create().toJson(map)); | String responseContent = this.wxMpService.post(USER_CHANGE_OPENID_URL, WxMpGsonBuilder.create().toJson(map)); | ||||
| @@ -4,6 +4,7 @@ import com.google.gson.JsonArray; | |||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||
| import com.google.gson.JsonParser; | import com.google.gson.JsonParser; | ||||
| import com.google.gson.reflect.TypeToken; | import com.google.gson.reflect.TypeToken; | ||||
| import lombok.RequiredArgsConstructor; | |||||
| import me.chanjar.weixin.common.WxType; | import me.chanjar.weixin.common.WxType; | ||||
| import me.chanjar.weixin.common.error.WxError; | import me.chanjar.weixin.common.error.WxError; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| @@ -16,51 +17,43 @@ import org.apache.commons.lang3.StringUtils; | |||||
| import java.util.List; | import java.util.List; | ||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.UserTag.*; | |||||
| /** | /** | ||||
| * Created by Binary Wang on 2016/9/2. | * Created by Binary Wang on 2016/9/2. | ||||
| * | * | ||||
| * @author <a href="https://github.com/binarywang">Binary Wang</a> | * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||
| */ | */ | ||||
| @RequiredArgsConstructor | |||||
| public class WxMpUserTagServiceImpl implements WxMpUserTagService { | public class WxMpUserTagServiceImpl implements WxMpUserTagService { | ||||
| private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/tags"; | |||||
| private WxMpService wxMpService; | |||||
| public WxMpUserTagServiceImpl(WxMpService wxMpService) { | |||||
| this.wxMpService = wxMpService; | |||||
| } | |||||
| private final WxMpService wxMpService; | |||||
| @Override | @Override | ||||
| public WxUserTag tagCreate(String name) throws WxErrorException { | public WxUserTag tagCreate(String name) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/create"; | |||||
| JsonObject json = new JsonObject(); | JsonObject json = new JsonObject(); | ||||
| JsonObject tagJson = new JsonObject(); | JsonObject tagJson = new JsonObject(); | ||||
| tagJson.addProperty("name", name); | tagJson.addProperty("name", name); | ||||
| json.add("tag", tagJson); | json.add("tag", tagJson); | ||||
| String responseContent = this.wxMpService.post(url, json.toString()); | |||||
| String responseContent = this.wxMpService.post(TAGS_CREATE, json.toString()); | |||||
| return WxUserTag.fromJson(responseContent); | return WxUserTag.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public List<WxUserTag> tagGet() throws WxErrorException { | public List<WxUserTag> tagGet() throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/get"; | |||||
| String responseContent = this.wxMpService.get(url, null); | |||||
| String responseContent = this.wxMpService.get(TAGS_GET, null); | |||||
| return WxUserTag.listFromJson(responseContent); | return WxUserTag.listFromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public Boolean tagUpdate(Long id, String name) throws WxErrorException { | public Boolean tagUpdate(Long id, String name) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/update"; | |||||
| JsonObject json = new JsonObject(); | JsonObject json = new JsonObject(); | ||||
| JsonObject tagJson = new JsonObject(); | JsonObject tagJson = new JsonObject(); | ||||
| tagJson.addProperty("id", id); | tagJson.addProperty("id", id); | ||||
| tagJson.addProperty("name", name); | tagJson.addProperty("name", name); | ||||
| json.add("tag", tagJson); | json.add("tag", tagJson); | ||||
| String responseContent = this.wxMpService.post(url, json.toString()); | |||||
| String responseContent = this.wxMpService.post(TAGS_UPDATE, json.toString()); | |||||
| WxError wxError = WxError.fromJson(responseContent, WxType.MP); | WxError wxError = WxError.fromJson(responseContent, WxType.MP); | ||||
| if (wxError.getErrorCode() == 0) { | if (wxError.getErrorCode() == 0) { | ||||
| return true; | return true; | ||||
| @@ -71,14 +64,12 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService { | |||||
| @Override | @Override | ||||
| public Boolean tagDelete(Long id) throws WxErrorException { | public Boolean tagDelete(Long id) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/delete"; | |||||
| JsonObject json = new JsonObject(); | JsonObject json = new JsonObject(); | ||||
| JsonObject tagJson = new JsonObject(); | JsonObject tagJson = new JsonObject(); | ||||
| tagJson.addProperty("id", id); | tagJson.addProperty("id", id); | ||||
| json.add("tag", tagJson); | json.add("tag", tagJson); | ||||
| String responseContent = this.wxMpService.post(url, json.toString()); | |||||
| String responseContent = this.wxMpService.post(TAGS_DELETE, json.toString()); | |||||
| WxError wxError = WxError.fromJson(responseContent, WxType.MP); | WxError wxError = WxError.fromJson(responseContent, WxType.MP); | ||||
| if (wxError.getErrorCode() == 0) { | if (wxError.getErrorCode() == 0) { | ||||
| return true; | return true; | ||||
| @@ -88,23 +79,17 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public WxTagListUser tagListUser(Long tagId, String nextOpenid) | |||||
| throws WxErrorException { | |||||
| String url = "https://api.weixin.qq.com/cgi-bin/user/tag/get"; | |||||
| public WxTagListUser tagListUser(Long tagId, String nextOpenid) throws WxErrorException { | |||||
| JsonObject json = new JsonObject(); | JsonObject json = new JsonObject(); | ||||
| json.addProperty("tagid", tagId); | json.addProperty("tagid", tagId); | ||||
| json.addProperty("next_openid", StringUtils.trimToEmpty(nextOpenid)); | json.addProperty("next_openid", StringUtils.trimToEmpty(nextOpenid)); | ||||
| String responseContent = this.wxMpService.post(url, json.toString()); | |||||
| String responseContent = this.wxMpService.post(TAG_GET, json.toString()); | |||||
| return WxTagListUser.fromJson(responseContent); | return WxTagListUser.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public boolean batchTagging(Long tagId, String[] openids) | |||||
| throws WxErrorException { | |||||
| String url = API_URL_PREFIX + "/members/batchtagging"; | |||||
| public boolean batchTagging(Long tagId, String[] openids) throws WxErrorException { | |||||
| JsonObject json = new JsonObject(); | JsonObject json = new JsonObject(); | ||||
| json.addProperty("tagid", tagId); | json.addProperty("tagid", tagId); | ||||
| JsonArray openidArrayJson = new JsonArray(); | JsonArray openidArrayJson = new JsonArray(); | ||||
| @@ -113,7 +98,7 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService { | |||||
| } | } | ||||
| json.add("openid_list", openidArrayJson); | json.add("openid_list", openidArrayJson); | ||||
| String responseContent = this.wxMpService.post(url, json.toString()); | |||||
| String responseContent = this.wxMpService.post(TAGS_MEMBERS_BATCHTAGGING, json.toString()); | |||||
| WxError wxError = WxError.fromJson(responseContent, WxType.MP); | WxError wxError = WxError.fromJson(responseContent, WxType.MP); | ||||
| if (wxError.getErrorCode() == 0) { | if (wxError.getErrorCode() == 0) { | ||||
| return true; | return true; | ||||
| @@ -123,10 +108,7 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public boolean batchUntagging(Long tagId, String[] openids) | |||||
| throws WxErrorException { | |||||
| String url = API_URL_PREFIX + "/members/batchuntagging"; | |||||
| public boolean batchUntagging(Long tagId, String[] openids) throws WxErrorException { | |||||
| JsonObject json = new JsonObject(); | JsonObject json = new JsonObject(); | ||||
| json.addProperty("tagid", tagId); | json.addProperty("tagid", tagId); | ||||
| JsonArray openidArrayJson = new JsonArray(); | JsonArray openidArrayJson = new JsonArray(); | ||||
| @@ -135,7 +117,7 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService { | |||||
| } | } | ||||
| json.add("openid_list", openidArrayJson); | json.add("openid_list", openidArrayJson); | ||||
| String responseContent = this.wxMpService.post(url, json.toString()); | |||||
| String responseContent = this.wxMpService.post(TAGS_MEMBERS_BATCHUNTAGGING, json.toString()); | |||||
| WxError wxError = WxError.fromJson(responseContent, WxType.MP); | WxError wxError = WxError.fromJson(responseContent, WxType.MP); | ||||
| if (wxError.getErrorCode() == 0) { | if (wxError.getErrorCode() == 0) { | ||||
| return true; | return true; | ||||
| @@ -146,12 +128,10 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService { | |||||
| @Override | @Override | ||||
| public List<Long> userTagList(String openid) throws WxErrorException { | public List<Long> userTagList(String openid) throws WxErrorException { | ||||
| String url = API_URL_PREFIX + "/getidlist"; | |||||
| JsonObject json = new JsonObject(); | JsonObject json = new JsonObject(); | ||||
| json.addProperty("openid", openid); | json.addProperty("openid", openid); | ||||
| String responseContent = this.wxMpService.post(url, json.toString()); | |||||
| String responseContent = this.wxMpService.post(TAGS_GETIDLIST, json.toString()); | |||||
| return WxMpGsonBuilder.create().fromJson( | return WxMpGsonBuilder.create().fromJson( | ||||
| new JsonParser().parse(responseContent).getAsJsonObject().get("tagid_list"), | new JsonParser().parse(responseContent).getAsJsonObject().get("tagid_list"), | ||||
| @@ -1,10 +1,14 @@ | |||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||
| import lombok.RequiredArgsConstructor; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
| import me.chanjar.weixin.mp.api.WxMpWifiService; | import me.chanjar.weixin.mp.api.WxMpWifiService; | ||||
| import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopListResult; | import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopListResult; | ||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Wifi.*; | |||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| @@ -13,19 +17,16 @@ import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopListResult; | |||||
| * | * | ||||
| * @author <a href="https://github.com/binarywang">Binary Wang</a> | * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||
| */ | */ | ||||
| @RequiredArgsConstructor | |||||
| public class WxMpWifiServiceImpl implements WxMpWifiService { | public class WxMpWifiServiceImpl implements WxMpWifiService { | ||||
| private WxMpService wxMpService; | |||||
| public WxMpWifiServiceImpl(WxMpService wxMpService) { | |||||
| this.wxMpService = wxMpService; | |||||
| } | |||||
| private final WxMpService wxMpService; | |||||
| @Override | @Override | ||||
| public WxMpWifiShopListResult listShop(int pageIndex, int pageSize) throws WxErrorException { | public WxMpWifiShopListResult listShop(int pageIndex, int pageSize) throws WxErrorException { | ||||
| JsonObject json = new JsonObject(); | JsonObject json = new JsonObject(); | ||||
| json.addProperty("pageindex", pageIndex); | json.addProperty("pageindex", pageIndex); | ||||
| json.addProperty("pagesize", pageSize); | json.addProperty("pagesize", pageSize); | ||||
| final String result = this.wxMpService.post("https://api.weixin.qq.com/bizwifi/shop/list", json.toString()); | |||||
| final String result = this.wxMpService.post(BIZWIFI_SHOP_LIST, json.toString()); | |||||
| return WxMpWifiShopListResult.fromJson(result); | return WxMpWifiShopListResult.fromJson(result); | ||||
| } | } | ||||
| } | } | ||||
| @@ -9,11 +9,10 @@ import java.io.Serializable; | |||||
| /** | /** | ||||
| * . | * . | ||||
| * @author leeis | * @author leeis | ||||
| * @Date 2018/12/29 | |||||
| * @date 2018/12/29 | |||||
| */ | */ | ||||
| @Data | @Data | ||||
| public class Card implements Serializable { | public class Card implements Serializable { | ||||
| private static final long serialVersionUID = -3697110761983756780L; | private static final long serialVersionUID = -3697110761983756780L; | ||||
| /** | /** | ||||
| @@ -0,0 +1,837 @@ | |||||
| package me.chanjar.weixin.mp.enums; | |||||
| import lombok.AllArgsConstructor; | |||||
| /** | |||||
| * <pre> | |||||
| * 公众号接口api地址 | |||||
| * Created by BinaryWang on 2019-06-03. | |||||
| * </pre> | |||||
| * | |||||
| * @author <a href="https://github.com/binarywang">Binary Wang</a> | |||||
| */ | |||||
| public interface WxMpApiUrl { | |||||
| String WX_API_BASE_URL = "https://api.weixin.qq.com"; | |||||
| String WX_MP_BASE_URL = "https://mp.weixin.qq.com"; | |||||
| String WX_OPEN_BASE_URL = "https://open.weixin.qq.com"; | |||||
| /** | |||||
| * 得到api完整地址. | |||||
| * | |||||
| * @return api地址 | |||||
| */ | |||||
| String getUrl(); | |||||
| @AllArgsConstructor | |||||
| enum Device implements WxMpApiUrl { | |||||
| /** | |||||
| * get_bind_device. | |||||
| */ | |||||
| DEVICE_GET_BIND_DEVICE(WX_API_BASE_URL, "/device/get_bind_device"), | |||||
| /** | |||||
| * get_openid. | |||||
| */ | |||||
| DEVICE_GET_OPENID(WX_API_BASE_URL, "/device/get_openid"), | |||||
| /** | |||||
| * compel_unbind. | |||||
| */ | |||||
| DEVICE_COMPEL_UNBIND(WX_API_BASE_URL, "/device/compel_unbind?"), | |||||
| /** | |||||
| * unbind. | |||||
| */ | |||||
| DEVICE_UNBIND(WX_API_BASE_URL, "/device/unbind?"), | |||||
| /** | |||||
| * compel_bind. | |||||
| */ | |||||
| DEVICE_COMPEL_BIND(WX_API_BASE_URL, "/device/compel_bind"), | |||||
| /** | |||||
| * bind. | |||||
| */ | |||||
| DEVICE_BIND(WX_API_BASE_URL, "/device/bind"), | |||||
| /** | |||||
| * authorize_device. | |||||
| */ | |||||
| DEVICE_AUTHORIZE_DEVICE(WX_API_BASE_URL, "/device/authorize_device"), | |||||
| /** | |||||
| * getqrcode. | |||||
| */ | |||||
| DEVICE_GETQRCODE(WX_API_BASE_URL, "/device/getqrcode"), | |||||
| /** | |||||
| * transmsg. | |||||
| */ | |||||
| DEVICE_TRANSMSG(WX_API_BASE_URL, "/device/transmsg"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum Other implements WxMpApiUrl { | |||||
| /** | |||||
| * 获取access_token. | |||||
| */ | |||||
| GET_ACCESS_TOKEN_URL(WX_API_BASE_URL, "/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s"), | |||||
| /** | |||||
| * 获得各种类型的ticket. | |||||
| */ | |||||
| GET_TICKET_URL(WX_API_BASE_URL, "/cgi-bin/ticket/getticket?type="), | |||||
| /** | |||||
| * 长链接转短链接接口. | |||||
| */ | |||||
| SHORTURL_API_URL(WX_API_BASE_URL, "/cgi-bin/shorturl"), | |||||
| /** | |||||
| * 语义查询接口. | |||||
| */ | |||||
| SEMANTIC_SEMPROXY_SEARCH_URL(WX_API_BASE_URL, "/semantic/semproxy/search"), | |||||
| /** | |||||
| * 用code换取oauth2的access token. | |||||
| */ | |||||
| OAUTH2_ACCESS_TOKEN_URL(WX_API_BASE_URL, "/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code"), | |||||
| /** | |||||
| * 刷新oauth2的access token. | |||||
| */ | |||||
| OAUTH2_REFRESH_TOKEN_URL(WX_API_BASE_URL, "/sns/oauth2/refresh_token?appid=%s&grant_type=refresh_token&refresh_token=%s"), | |||||
| /** | |||||
| * 用oauth2获取用户信息. | |||||
| */ | |||||
| OAUTH2_USERINFO_URL(WX_API_BASE_URL, "/sns/userinfo?access_token=%s&openid=%s&lang=%s"), | |||||
| /** | |||||
| * 验证oauth2的access token是否有效. | |||||
| */ | |||||
| OAUTH2_VALIDATE_TOKEN_URL(WX_API_BASE_URL, "/sns/auth?access_token=%s&openid=%s"), | |||||
| /** | |||||
| * 获取微信服务器IP地址. | |||||
| */ | |||||
| GET_CALLBACK_IP_URL(WX_API_BASE_URL, "/cgi-bin/getcallbackip"), | |||||
| /** | |||||
| * 第三方使用网站应用授权登录的url. | |||||
| */ | |||||
| QRCONNECT_URL(WX_OPEN_BASE_URL, "/connect/qrconnect?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect"), | |||||
| /** | |||||
| * oauth2授权的url连接. | |||||
| */ | |||||
| CONNECT_OAUTH2_AUTHORIZE_URL(WX_OPEN_BASE_URL, "/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s&connect_redirect=1#wechat_redirect"), | |||||
| /** | |||||
| * 获取公众号的自动回复规则. | |||||
| */ | |||||
| GET_CURRENT_AUTOREPLY_INFO_URL(WX_API_BASE_URL, "/cgi-bin/get_current_autoreply_info"), | |||||
| /** | |||||
| * 公众号调用或第三方平台帮公众号调用对公众号的所有api调用(包括第三方帮其调用)次数进行清零. | |||||
| */ | |||||
| CLEAR_QUOTA_URL(WX_API_BASE_URL, "/cgi-bin/clear_quota"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum Marketing implements WxMpApiUrl { | |||||
| /** | |||||
| * sets add. | |||||
| */ | |||||
| USER_ACTION_SETS_ADD(WX_API_BASE_URL, "/marketing/user_action_sets/add?version=v1.0"), | |||||
| /** | |||||
| * get. | |||||
| */ | |||||
| USER_ACTION_SETS_GET(WX_API_BASE_URL, "/marketing/user_action_sets/get"), | |||||
| /** | |||||
| * add. | |||||
| */ | |||||
| USER_ACTIONS_ADD(WX_API_BASE_URL, "/marketing/user_actions/add?version=v1.0"), | |||||
| /** | |||||
| * get. | |||||
| */ | |||||
| WECHAT_AD_LEADS_GET(WX_API_BASE_URL, "/marketing/wechat_ad_leads/get"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum Menu implements WxMpApiUrl { | |||||
| /** | |||||
| * get_current_selfmenu_info. | |||||
| */ | |||||
| GET_CURRENT_SELFMENU_INFO(WX_API_BASE_URL, "/cgi-bin/get_current_selfmenu_info"), | |||||
| /** | |||||
| * trymatch. | |||||
| */ | |||||
| MENU_TRYMATCH(WX_API_BASE_URL, "/cgi-bin/menu/trymatch"), | |||||
| /** | |||||
| * get. | |||||
| */ | |||||
| MENU_GET(WX_API_BASE_URL, "/cgi-bin/menu/get"), | |||||
| /** | |||||
| * delconditional. | |||||
| */ | |||||
| MENU_DELCONDITIONAL(WX_API_BASE_URL, "/cgi-bin/menu/delconditional"), | |||||
| /** | |||||
| * delete. | |||||
| */ | |||||
| MENU_DELETE(WX_API_BASE_URL, "/cgi-bin/menu/delete"), | |||||
| /** | |||||
| * create. | |||||
| */ | |||||
| MENU_CREATE(WX_API_BASE_URL, "/cgi-bin/menu/create"), | |||||
| /** | |||||
| * addconditional. | |||||
| */ | |||||
| MENU_ADDCONDITIONAL(WX_API_BASE_URL, "/cgi-bin/menu/addconditional"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum Qrcode implements WxMpApiUrl { | |||||
| /** | |||||
| * create. | |||||
| */ | |||||
| QRCODE_CREATE(WX_API_BASE_URL, "/cgi-bin/qrcode/create"), | |||||
| /** | |||||
| * showqrcode. | |||||
| */ | |||||
| SHOW_QRCODE(WX_MP_BASE_URL, "/cgi-bin/showqrcode"), | |||||
| /** | |||||
| * showqrcode. | |||||
| */ | |||||
| SHOW_QRCODE_WITH_TICKET(WX_MP_BASE_URL, "/cgi-bin/showqrcode?ticket=%s"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum ShakeAround implements WxMpApiUrl { | |||||
| /** | |||||
| * getshakeinfo. | |||||
| */ | |||||
| SHAKEAROUND_USER_GETSHAKEINFO(WX_API_BASE_URL, "/shakearound/user/getshakeinfo"), | |||||
| /** | |||||
| * add. | |||||
| */ | |||||
| SHAKEAROUND_PAGE_ADD(WX_API_BASE_URL, "/shakearound/page/add"), | |||||
| /** | |||||
| * bindpage. | |||||
| */ | |||||
| SHAKEAROUND_DEVICE_BINDPAGE(WX_API_BASE_URL, "/shakearound/device/bindpage"), | |||||
| /** | |||||
| * search. | |||||
| */ | |||||
| SHAKEAROUND_RELATION_SEARCH(WX_API_BASE_URL, "/shakearound/relation/search"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum SubscribeMsg implements WxMpApiUrl { | |||||
| /** | |||||
| * subscribemsg. | |||||
| */ | |||||
| SUBSCRIBE_MESSAGE_AUTHORIZE_URL(WX_MP_BASE_URL, "/mp/subscribemsg?action=get_confirm&appid=%s&scene=%d&template_id=%s&redirect_url=%s&reserved=%s#wechat_redirect"), | |||||
| /** | |||||
| * subscribe. | |||||
| */ | |||||
| SEND_MESSAGE_URL(WX_API_BASE_URL, "/cgi-bin/message/template/subscribe"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum TemplateMsg implements WxMpApiUrl { | |||||
| /** | |||||
| * send. | |||||
| */ | |||||
| MESSAGE_TEMPLATE_SEND(WX_API_BASE_URL, "/cgi-bin/message/template/send"), | |||||
| /** | |||||
| * api_set_industry. | |||||
| */ | |||||
| TEMPLATE_API_SET_INDUSTRY(WX_API_BASE_URL, "/cgi-bin/template/api_set_industry"), | |||||
| /** | |||||
| * get_industry. | |||||
| */ | |||||
| TEMPLATE_GET_INDUSTRY(WX_API_BASE_URL, "/cgi-bin/template/get_industry"), | |||||
| /** | |||||
| * api_add_template. | |||||
| */ | |||||
| TEMPLATE_API_ADD_TEMPLATE(WX_API_BASE_URL, "/cgi-bin/template/api_add_template"), | |||||
| /** | |||||
| * get_all_private_template. | |||||
| */ | |||||
| TEMPLATE_GET_ALL_PRIVATE_TEMPLATE(WX_API_BASE_URL, "/cgi-bin/template/get_all_private_template"), | |||||
| /** | |||||
| * del_private_template. | |||||
| */ | |||||
| TEMPLATE_DEL_PRIVATE_TEMPLATE(WX_API_BASE_URL, "/cgi-bin/template/del_private_template"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum UserBlacklist implements WxMpApiUrl { | |||||
| /** | |||||
| * getblacklist. | |||||
| */ | |||||
| GETBLACKLIST(WX_API_BASE_URL, "/cgi-bin/tags/members/getblacklist"), | |||||
| /** | |||||
| * batchblacklist. | |||||
| */ | |||||
| BATCHBLACKLIST(WX_API_BASE_URL, "/cgi-bin/tags/members/batchblacklist"), | |||||
| /** | |||||
| * batchunblacklist. | |||||
| */ | |||||
| BATCHUNBLACKLIST(WX_API_BASE_URL, "/cgi-bin/tags/members/batchunblacklist"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum UserTag implements WxMpApiUrl { | |||||
| /** | |||||
| * create. | |||||
| */ | |||||
| TAGS_CREATE(WX_API_BASE_URL, "/cgi-bin/tags/create"), | |||||
| /** | |||||
| * get. | |||||
| */ | |||||
| TAGS_GET(WX_API_BASE_URL, "/cgi-bin/tags/get"), | |||||
| /** | |||||
| * update. | |||||
| */ | |||||
| TAGS_UPDATE(WX_API_BASE_URL, "/cgi-bin/tags/update"), | |||||
| /** | |||||
| * delete. | |||||
| */ | |||||
| TAGS_DELETE(WX_API_BASE_URL, "/cgi-bin/tags/delete"), | |||||
| /** | |||||
| * get. | |||||
| */ | |||||
| TAG_GET(WX_API_BASE_URL, "/cgi-bin/user/tag/get"), | |||||
| /** | |||||
| * batchtagging. | |||||
| */ | |||||
| TAGS_MEMBERS_BATCHTAGGING(WX_API_BASE_URL, "/cgi-bin/tags/members/batchtagging"), | |||||
| /** | |||||
| * batchuntagging. | |||||
| */ | |||||
| TAGS_MEMBERS_BATCHUNTAGGING(WX_API_BASE_URL, "/cgi-bin/tags/members/batchuntagging"), | |||||
| /** | |||||
| * getidlist. | |||||
| */ | |||||
| TAGS_GETIDLIST(WX_API_BASE_URL, "/cgi-bin/tags/getidlist"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum Wifi implements WxMpApiUrl { | |||||
| /** | |||||
| * list. | |||||
| */ | |||||
| BIZWIFI_SHOP_LIST(WX_API_BASE_URL, "/bizwifi/shop/list"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum AiOpen implements WxMpApiUrl { | |||||
| /** | |||||
| * translatecontent. | |||||
| */ | |||||
| TRANSLATE_URL(WX_API_BASE_URL, "/cgi-bin/media/voice/translatecontent?lfrom=%s<o=%s"), | |||||
| /** | |||||
| * addvoicetorecofortext. | |||||
| */ | |||||
| VOICE_UPLOAD_URL(WX_API_BASE_URL, "/cgi-bin/media/voice/addvoicetorecofortext?format=%s&voice_id=%s&lang=%s"), | |||||
| /** | |||||
| * queryrecoresultfortext. | |||||
| */ | |||||
| VOICE_QUERY_RESULT_URL(WX_API_BASE_URL, "/cgi-bin/media/voice/queryrecoresultfortext"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum Card implements WxMpApiUrl { | |||||
| /** | |||||
| * create. | |||||
| */ | |||||
| CARD_CREATE(WX_API_BASE_URL, "/card/create"), | |||||
| /** | |||||
| * get. | |||||
| */ | |||||
| CARD_GET(WX_API_BASE_URL, "/card/get"), | |||||
| /** | |||||
| * wx_card. | |||||
| */ | |||||
| CARD_GET_TICKET(WX_API_BASE_URL, "/cgi-bin/ticket/getticket?type=wx_card"), | |||||
| /** | |||||
| * decrypt. | |||||
| */ | |||||
| CARD_CODE_DECRYPT(WX_API_BASE_URL, "/card/code/decrypt"), | |||||
| /** | |||||
| * get. | |||||
| */ | |||||
| CARD_CODE_GET(WX_API_BASE_URL, "/card/code/get"), | |||||
| /** | |||||
| * consume. | |||||
| */ | |||||
| CARD_CODE_CONSUME(WX_API_BASE_URL, "/card/code/consume"), | |||||
| /** | |||||
| * mark. | |||||
| */ | |||||
| CARD_CODE_MARK(WX_API_BASE_URL, "/card/code/mark"), | |||||
| /** | |||||
| * set. | |||||
| */ | |||||
| CARD_TEST_WHITELIST(WX_API_BASE_URL, "/card/testwhitelist/set"), | |||||
| /** | |||||
| * create. | |||||
| */ | |||||
| CARD_QRCODE_CREATE(WX_API_BASE_URL, "/card/qrcode/create"), | |||||
| /** | |||||
| * create. | |||||
| */ | |||||
| CARD_LANDING_PAGE_CREATE(WX_API_BASE_URL, "/card/landingpage/create"), | |||||
| /** | |||||
| * 将用户的卡券设置为失效状态. | |||||
| */ | |||||
| CARD_CODE_UNAVAILABLE(WX_API_BASE_URL, "/card/code/unavailable"), | |||||
| /** | |||||
| * 卡券删除. | |||||
| */ | |||||
| CARD_DELETE(WX_API_BASE_URL, "/card/delete"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum DataCube implements WxMpApiUrl { | |||||
| /** | |||||
| * getusersummary. | |||||
| */ | |||||
| GET_USER_SUMMARY(WX_API_BASE_URL, "/datacube/getusersummary"), | |||||
| /** | |||||
| * getusercumulate. | |||||
| */ | |||||
| GET_USER_CUMULATE(WX_API_BASE_URL, "/datacube/getusercumulate"), | |||||
| /** | |||||
| * getarticlesummary. | |||||
| */ | |||||
| GET_ARTICLE_SUMMARY(WX_API_BASE_URL, "/datacube/getarticlesummary"), | |||||
| /** | |||||
| * getarticletotal. | |||||
| */ | |||||
| GET_ARTICLE_TOTAL(WX_API_BASE_URL, "/datacube/getarticletotal"), | |||||
| /** | |||||
| * getuserread. | |||||
| */ | |||||
| GET_USER_READ(WX_API_BASE_URL, "/datacube/getuserread"), | |||||
| /** | |||||
| * getuserreadhour. | |||||
| */ | |||||
| GET_USER_READ_HOUR(WX_API_BASE_URL, "/datacube/getuserreadhour"), | |||||
| /** | |||||
| * getusershare. | |||||
| */ | |||||
| GET_USER_SHARE(WX_API_BASE_URL, "/datacube/getusershare"), | |||||
| /** | |||||
| * getusersharehour. | |||||
| */ | |||||
| GET_USER_SHARE_HOUR(WX_API_BASE_URL, "/datacube/getusersharehour"), | |||||
| /** | |||||
| * getupstreammsg. | |||||
| */ | |||||
| GET_UPSTREAM_MSG(WX_API_BASE_URL, "/datacube/getupstreammsg"), | |||||
| /** | |||||
| * getupstreammsghour. | |||||
| */ | |||||
| GET_UPSTREAM_MSG_HOUR(WX_API_BASE_URL, "/datacube/getupstreammsghour"), | |||||
| /** | |||||
| * getupstreammsgweek. | |||||
| */ | |||||
| GET_UPSTREAM_MSG_WEEK(WX_API_BASE_URL, "/datacube/getupstreammsgweek"), | |||||
| /** | |||||
| * getupstreammsgmonth. | |||||
| */ | |||||
| GET_UPSTREAM_MSG_MONTH(WX_API_BASE_URL, "/datacube/getupstreammsgmonth"), | |||||
| /** | |||||
| * getupstreammsgdist. | |||||
| */ | |||||
| GET_UPSTREAM_MSG_DIST(WX_API_BASE_URL, "/datacube/getupstreammsgdist"), | |||||
| /** | |||||
| * getupstreammsgdistweek. | |||||
| */ | |||||
| GET_UPSTREAM_MSG_DIST_WEEK(WX_API_BASE_URL, "/datacube/getupstreammsgdistweek"), | |||||
| /** | |||||
| * getupstreammsgdistmonth. | |||||
| */ | |||||
| GET_UPSTREAM_MSG_DIST_MONTH(WX_API_BASE_URL, "/datacube/getupstreammsgdistmonth"), | |||||
| /** | |||||
| * getinterfacesummary. | |||||
| */ | |||||
| GET_INTERFACE_SUMMARY(WX_API_BASE_URL, "/datacube/getinterfacesummary"), | |||||
| /** | |||||
| * getinterfacesummaryhour. | |||||
| */ | |||||
| GET_INTERFACE_SUMMARY_HOUR(WX_API_BASE_URL, "/datacube/getinterfacesummaryhour"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum Kefu implements WxMpApiUrl { | |||||
| /** | |||||
| * send. | |||||
| */ | |||||
| MESSAGE_CUSTOM_SEND(WX_API_BASE_URL, "/cgi-bin/message/custom/send"), | |||||
| /** | |||||
| * getkflist. | |||||
| */ | |||||
| GET_KF_LIST(WX_API_BASE_URL, "/cgi-bin/customservice/getkflist"), | |||||
| /** | |||||
| * getonlinekflist. | |||||
| */ | |||||
| GET_ONLINE_KF_LIST(WX_API_BASE_URL, "/cgi-bin/customservice/getonlinekflist"), | |||||
| /** | |||||
| * add. | |||||
| */ | |||||
| KFACCOUNT_ADD(WX_API_BASE_URL, "/customservice/kfaccount/add"), | |||||
| /** | |||||
| * update. | |||||
| */ | |||||
| KFACCOUNT_UPDATE(WX_API_BASE_URL, "/customservice/kfaccount/update"), | |||||
| /** | |||||
| * inviteworker. | |||||
| */ | |||||
| KFACCOUNT_INVITE_WORKER(WX_API_BASE_URL, "/customservice/kfaccount/inviteworker"), | |||||
| /** | |||||
| * uploadheadimg. | |||||
| */ | |||||
| KFACCOUNT_UPLOAD_HEAD_IMG(WX_API_BASE_URL, "/customservice/kfaccount/uploadheadimg?kf_account=%s"), | |||||
| /** | |||||
| * del kfaccount. | |||||
| */ | |||||
| KFACCOUNT_DEL(WX_API_BASE_URL, "/customservice/kfaccount/del?kf_account=%s"), | |||||
| /** | |||||
| * create. | |||||
| */ | |||||
| KFSESSION_CREATE(WX_API_BASE_URL, "/customservice/kfsession/create"), | |||||
| /** | |||||
| * close. | |||||
| */ | |||||
| KFSESSION_CLOSE(WX_API_BASE_URL, "/customservice/kfsession/close"), | |||||
| /** | |||||
| * getsession. | |||||
| */ | |||||
| KFSESSION_GET_SESSION(WX_API_BASE_URL, "/customservice/kfsession/getsession?openid=%s"), | |||||
| /** | |||||
| * getsessionlist. | |||||
| */ | |||||
| KFSESSION_GET_SESSION_LIST(WX_API_BASE_URL, "/customservice/kfsession/getsessionlist?kf_account=%s"), | |||||
| /** | |||||
| * getwaitcase. | |||||
| */ | |||||
| KFSESSION_GET_WAIT_CASE(WX_API_BASE_URL, "/customservice/kfsession/getwaitcase"), | |||||
| /** | |||||
| * getmsglist. | |||||
| */ | |||||
| MSG_RECORD_LIST(WX_API_BASE_URL, "/customservice/msgrecord/getmsglist"), | |||||
| /** | |||||
| * typing. | |||||
| */ | |||||
| CUSTOM_TYPING(WX_API_BASE_URL, "/cgi-bin/message/custom/typing"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum MassMessage implements WxMpApiUrl { | |||||
| /** | |||||
| * 上传群发用的图文消息. | |||||
| */ | |||||
| MEDIA_UPLOAD_NEWS_URL(WX_API_BASE_URL, "/cgi-bin/media/uploadnews"), | |||||
| /** | |||||
| * 上传群发用的视频. | |||||
| */ | |||||
| MEDIA_UPLOAD_VIDEO_URL(WX_API_BASE_URL, "/cgi-bin/media/uploadvideo"), | |||||
| /** | |||||
| * 分组群发消息. | |||||
| */ | |||||
| MESSAGE_MASS_SENDALL_URL(WX_API_BASE_URL, "/cgi-bin/message/mass/sendall"), | |||||
| /** | |||||
| * 按openId列表群发消息. | |||||
| */ | |||||
| MESSAGE_MASS_SEND_URL(WX_API_BASE_URL, "/cgi-bin/message/mass/send"), | |||||
| /** | |||||
| * 群发消息预览接口. | |||||
| */ | |||||
| MESSAGE_MASS_PREVIEW_URL(WX_API_BASE_URL, "/cgi-bin/message/mass/preview"), | |||||
| /** | |||||
| * 删除群发接口. | |||||
| */ | |||||
| MESSAGE_MASS_DELETE_URL(WX_API_BASE_URL, "/cgi-bin/message/mass/delete"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum Material implements WxMpApiUrl { | |||||
| /** | |||||
| * get. | |||||
| */ | |||||
| MEDIA_GET_URL(WX_API_BASE_URL, "/cgi-bin/media/get"), | |||||
| /** | |||||
| * upload. | |||||
| */ | |||||
| MEDIA_UPLOAD_URL(WX_API_BASE_URL, "/cgi-bin/media/upload?type=%s"), | |||||
| /** | |||||
| * uploadimg. | |||||
| */ | |||||
| IMG_UPLOAD_URL(WX_API_BASE_URL, "/cgi-bin/media/uploadimg"), | |||||
| /** | |||||
| * add_material. | |||||
| */ | |||||
| MATERIAL_ADD_URL(WX_API_BASE_URL, "/cgi-bin/material/add_material?type=%s"), | |||||
| /** | |||||
| * add_news. | |||||
| */ | |||||
| NEWS_ADD_URL(WX_API_BASE_URL, "/cgi-bin/material/add_news"), | |||||
| /** | |||||
| * get_material. | |||||
| */ | |||||
| MATERIAL_GET_URL(WX_API_BASE_URL, "/cgi-bin/material/get_material"), | |||||
| /** | |||||
| * update_news. | |||||
| */ | |||||
| NEWS_UPDATE_URL(WX_API_BASE_URL, "/cgi-bin/material/update_news"), | |||||
| /** | |||||
| * del_material. | |||||
| */ | |||||
| MATERIAL_DEL_URL(WX_API_BASE_URL, "/cgi-bin/material/del_material"), | |||||
| /** | |||||
| * get_materialcount. | |||||
| */ | |||||
| MATERIAL_GET_COUNT_URL(WX_API_BASE_URL, "/cgi-bin/material/get_materialcount"), | |||||
| /** | |||||
| * batchget_material. | |||||
| */ | |||||
| MATERIAL_BATCHGET_URL(WX_API_BASE_URL, "/cgi-bin/material/batchget_material"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum MemberCard implements WxMpApiUrl { | |||||
| /** | |||||
| * create. | |||||
| */ | |||||
| MEMBER_CARD_CREATE(WX_API_BASE_URL, "/card/create"), | |||||
| /** | |||||
| * activate. | |||||
| */ | |||||
| MEMBER_CARD_ACTIVATE(WX_API_BASE_URL, "/card/membercard/activate"), | |||||
| /** | |||||
| * get userinfo. | |||||
| */ | |||||
| MEMBER_CARD_USER_INFO_GET(WX_API_BASE_URL, "/card/membercard/userinfo/get"), | |||||
| /** | |||||
| * updateuser. | |||||
| */ | |||||
| MEMBER_CARD_UPDATE_USER(WX_API_BASE_URL, "/card/membercard/updateuser"), | |||||
| /** | |||||
| * 会员卡激活之微信开卡接口(wx_activate=true情况调用). | |||||
| */ | |||||
| MEMBER_CARD_ACTIVATE_USER_FORM(WX_API_BASE_URL, "/card/membercard/activateuserform/set"), | |||||
| /** | |||||
| * 获取会员卡开卡插件参数. | |||||
| */ | |||||
| MEMBER_CARD_ACTIVATE_URL(WX_API_BASE_URL, "/card/membercard/activate/geturl"), | |||||
| /** | |||||
| * 会员卡信息更新. | |||||
| */ | |||||
| MEMBER_CARD_UPDATE(WX_API_BASE_URL, "/card/update"), | |||||
| /** | |||||
| * 跳转型会员卡开卡字段. | |||||
| * 获取用户提交资料(wx_activate=true情况调用),开发者根据activate_ticket获取到用户填写的信息 | |||||
| */ | |||||
| MEMBER_CARD_ACTIVATE_TEMP_INFO(WX_API_BASE_URL, "/card/membercard/activatetempinfo/get"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum Store implements WxMpApiUrl { | |||||
| /** | |||||
| * getwxcategory. | |||||
| */ | |||||
| POI_GET_WX_CATEGORY_URL(WX_API_BASE_URL, "/cgi-bin/poi/getwxcategory"), | |||||
| /** | |||||
| * updatepoi. | |||||
| */ | |||||
| POI_UPDATE_URL(WX_API_BASE_URL, "/cgi-bin/poi/updatepoi"), | |||||
| /** | |||||
| * getpoilist. | |||||
| */ | |||||
| POI_LIST_URL(WX_API_BASE_URL, "/cgi-bin/poi/getpoilist"), | |||||
| /** | |||||
| * delpoi. | |||||
| */ | |||||
| POI_DEL_URL(WX_API_BASE_URL, "/cgi-bin/poi/delpoi"), | |||||
| /** | |||||
| * getpoi. | |||||
| */ | |||||
| POI_GET_URL(WX_API_BASE_URL, "/cgi-bin/poi/getpoi"), | |||||
| /** | |||||
| * addpoi. | |||||
| */ | |||||
| POI_ADD_URL(WX_API_BASE_URL, "/cgi-bin/poi/addpoi"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| @AllArgsConstructor | |||||
| enum User implements WxMpApiUrl { | |||||
| /** | |||||
| * batchget. | |||||
| */ | |||||
| USER_INFO_BATCH_GET_URL(WX_API_BASE_URL, "/cgi-bin/user/info/batchget"), | |||||
| /** | |||||
| * get. | |||||
| */ | |||||
| USER_GET_URL(WX_API_BASE_URL, "/cgi-bin/user/get"), | |||||
| /** | |||||
| * info. | |||||
| */ | |||||
| USER_INFO_URL(WX_API_BASE_URL, "/cgi-bin/user/info"), | |||||
| /** | |||||
| * updateremark. | |||||
| */ | |||||
| USER_INFO_UPDATE_REMARK_URL(WX_API_BASE_URL, "/cgi-bin/user/info/updateremark"), | |||||
| /** | |||||
| * changeopenid. | |||||
| */ | |||||
| USER_CHANGE_OPENID_URL(WX_API_BASE_URL, "/cgi-bin/changeopenid"); | |||||
| private String prefix; | |||||
| private String path; | |||||
| @Override | |||||
| public String getUrl() { | |||||
| return this.prefix + this.path; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,5 +1,6 @@ | |||||
| package me.chanjar.weixin.mp.api; | package me.chanjar.weixin.mp.api; | ||||
| import lombok.extern.slf4j.Slf4j; | |||||
| import me.chanjar.weixin.common.error.WxError; | import me.chanjar.weixin.common.error.WxError; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.common.util.http.RequestExecutor; | import me.chanjar.weixin.common.util.http.RequestExecutor; | ||||
| @@ -12,6 +13,7 @@ import java.util.concurrent.Executors; | |||||
| import java.util.concurrent.Future; | import java.util.concurrent.Future; | ||||
| @Test | @Test | ||||
| @Slf4j | |||||
| public class WxMpBusyRetryTest { | public class WxMpBusyRetryTest { | ||||
| @DataProvider(name = "getService") | @DataProvider(name = "getService") | ||||
| @@ -22,7 +24,7 @@ public class WxMpBusyRetryTest { | |||||
| public synchronized <T, E> T executeInternal( | public synchronized <T, E> T executeInternal( | ||||
| RequestExecutor<T, E> executor, String uri, E data) | RequestExecutor<T, E> executor, String uri, E data) | ||||
| throws WxErrorException { | throws WxErrorException { | ||||
| this.log.info("Executed"); | |||||
| log.info("Executed"); | |||||
| throw new WxErrorException(WxError.builder().errorCode(-1).build()); | throw new WxErrorException(WxError.builder().errorCode(-1).build()); | ||||
| } | } | ||||
| }; | }; | ||||
| @@ -34,7 +36,7 @@ public class WxMpBusyRetryTest { | |||||
| @Test(dataProvider = "getService", expectedExceptions = RuntimeException.class) | @Test(dataProvider = "getService", expectedExceptions = RuntimeException.class) | ||||
| public void testRetry(WxMpService service) throws WxErrorException { | public void testRetry(WxMpService service) throws WxErrorException { | ||||
| service.execute(null, null, null); | |||||
| service.execute(null, (String)null, null); | |||||
| } | } | ||||
| @Test(dataProvider = "getService") | @Test(dataProvider = "getService") | ||||
| @@ -47,7 +49,7 @@ public class WxMpBusyRetryTest { | |||||
| try { | try { | ||||
| System.out.println("====================="); | System.out.println("====================="); | ||||
| System.out.println(Thread.currentThread().getName() + ": testRetry"); | System.out.println(Thread.currentThread().getName() + ": testRetry"); | ||||
| service.execute(null, null, null); | |||||
| service.execute(null, (String)null, null); | |||||
| } catch (WxErrorException e) { | } catch (WxErrorException e) { | ||||
| throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
| } catch (RuntimeException e) { | } catch (RuntimeException e) { | ||||
| @@ -3,24 +3,22 @@ package me.chanjar.weixin.mp.api; | |||||
| import com.google.inject.Inject; | import com.google.inject.Inject; | ||||
| import me.chanjar.weixin.common.util.crypto.SHA1; | import me.chanjar.weixin.common.util.crypto.SHA1; | ||||
| import me.chanjar.weixin.mp.api.test.ApiTestModule; | import me.chanjar.weixin.mp.api.test.ApiTestModule; | ||||
| import org.testng.*; | |||||
| import org.testng.annotations.*; | |||||
| import org.testng.Assert; | |||||
| import org.testng.annotations.Guice; | |||||
| import org.testng.annotations.Test; | |||||
| /** | /** | ||||
| * 测试jsapi ticket接口 | * 测试jsapi ticket接口 | ||||
| * | * | ||||
| * @author chanjarster | * @author chanjarster | ||||
| */ | */ | ||||
| @Test(groups = "jsAPI", dependsOnGroups = "baseAPI") | |||||
| @Test | |||||
| @Guice(modules = ApiTestModule.class) | @Guice(modules = ApiTestModule.class) | ||||
| public class WxMpJsAPITest { | public class WxMpJsAPITest { | ||||
| @Inject | @Inject | ||||
| protected WxMpService wxService; | protected WxMpService wxService; | ||||
| public void test() { | public void test() { | ||||
| long timestamp = 1419835025L; | long timestamp = 1419835025L; | ||||
| String url = "http://omstest.vmall.com:23568/thirdparty/wechat/vcode/gotoshare?quantity=1&batchName=MATE7"; | String url = "http://omstest.vmall.com:23568/thirdparty/wechat/vcode/gotoshare?quantity=1&batchName=MATE7"; | ||||
| @@ -1,25 +1,27 @@ | |||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
| import java.util.ArrayList; | |||||
| import java.util.HashMap; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| import me.chanjar.weixin.mp.api.WxMpUserService; | |||||
| import me.chanjar.weixin.mp.bean.result.WxMpChangeOpenid; | |||||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
| import org.testng.*; | |||||
| import org.testng.annotations.*; | |||||
| import com.google.inject.Inject; | import com.google.inject.Inject; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
| import me.chanjar.weixin.mp.api.test.ApiTestModule; | import me.chanjar.weixin.mp.api.test.ApiTestModule; | ||||
| import me.chanjar.weixin.mp.api.test.TestConfigStorage; | import me.chanjar.weixin.mp.api.test.TestConfigStorage; | ||||
| import me.chanjar.weixin.mp.bean.WxMpUserQuery; | import me.chanjar.weixin.mp.bean.WxMpUserQuery; | ||||
| import me.chanjar.weixin.mp.bean.result.WxMpChangeOpenid; | |||||
| import me.chanjar.weixin.mp.bean.result.WxMpUser; | import me.chanjar.weixin.mp.bean.result.WxMpUser; | ||||
| import me.chanjar.weixin.mp.bean.result.WxMpUserList; | import me.chanjar.weixin.mp.bean.result.WxMpUserList; | ||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
| import org.testng.Assert; | |||||
| import org.testng.annotations.BeforeTest; | |||||
| import org.testng.annotations.Guice; | |||||
| import org.testng.annotations.Test; | |||||
| import java.util.ArrayList; | |||||
| import java.util.HashMap; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.User.*; | |||||
| import static org.mockito.Mockito.mock; | import static org.mockito.Mockito.mock; | ||||
| import static org.mockito.Mockito.when; | import static org.mockito.Mockito.when; | ||||
| @@ -86,8 +88,7 @@ public class WxMpUserServiceImplTest { | |||||
| public void testChangeOpenid() throws WxErrorException { | public void testChangeOpenid() throws WxErrorException { | ||||
| List<String> openids = new ArrayList<>(); | List<String> openids = new ArrayList<>(); | ||||
| openids.add(this.configProvider.getOpenid()); | openids.add(this.configProvider.getOpenid()); | ||||
| List<WxMpChangeOpenid> wxMpChangeOpenidList = this.wxService.getUserService() | |||||
| .changeOpenid("原公众号appid", openids); | |||||
| List<WxMpChangeOpenid> wxMpChangeOpenidList = this.wxService.getUserService().changeOpenid("原公众号appid", openids); | |||||
| Assert.assertNotNull(wxMpChangeOpenidList); | Assert.assertNotNull(wxMpChangeOpenidList); | ||||
| Assert.assertEquals(1, wxMpChangeOpenidList.size()); | Assert.assertEquals(1, wxMpChangeOpenidList.size()); | ||||
| WxMpChangeOpenid wxMpChangeOpenid = wxMpChangeOpenidList.get(0); | WxMpChangeOpenid wxMpChangeOpenid = wxMpChangeOpenidList.get(0); | ||||
| @@ -98,6 +99,7 @@ public class WxMpUserServiceImplTest { | |||||
| public static class MockTest { | public static class MockTest { | ||||
| private WxMpService wxService = mock(WxMpService.class); | private WxMpService wxService = mock(WxMpService.class); | ||||
| @Test | @Test | ||||
| public void testMockChangeOpenid() throws WxErrorException { | public void testMockChangeOpenid() throws WxErrorException { | ||||
| List<String> openids = new ArrayList<>(); | List<String> openids = new ArrayList<>(); | ||||
| @@ -109,9 +111,8 @@ public class WxMpUserServiceImplTest { | |||||
| map.put("openid_list", openids); | map.put("openid_list", openids); | ||||
| String returnJson = "{\"errcode\": 0,\"errmsg\": \"ok\",\"result_list\": [{\"ori_openid\": \"oEmYbwN-n24jxvk4Sox81qedINkQ\",\"new_openid\": \"o2FwqwI9xCsVadFah_HtpPfaR-X4\",\"err_msg\": \"ok\"},{\"ori_openid\": \"oEmYbwH9uVd4RKJk7ZZg6SzL6tTo\",\"err_msg\": \"ori_openid error\"}]}"; | String returnJson = "{\"errcode\": 0,\"errmsg\": \"ok\",\"result_list\": [{\"ori_openid\": \"oEmYbwN-n24jxvk4Sox81qedINkQ\",\"new_openid\": \"o2FwqwI9xCsVadFah_HtpPfaR-X4\",\"err_msg\": \"ok\"},{\"ori_openid\": \"oEmYbwH9uVd4RKJk7ZZg6SzL6tTo\",\"err_msg\": \"ori_openid error\"}]}"; | ||||
| when(wxService.post(WxMpUserService.USER_CHANGE_OPENID_URL, WxMpGsonBuilder.create().toJson(map))).thenReturn(returnJson); | |||||
| List<WxMpChangeOpenid> wxMpChangeOpenidList = this.wxService.getUserService() | |||||
| .changeOpenid(fromAppid, openids); | |||||
| when(wxService.post(USER_CHANGE_OPENID_URL, WxMpGsonBuilder.create().toJson(map))).thenReturn(returnJson); | |||||
| List<WxMpChangeOpenid> wxMpChangeOpenidList = this.wxService.getUserService().changeOpenid(fromAppid, openids); | |||||
| Assert.assertNotNull(wxMpChangeOpenidList); | Assert.assertNotNull(wxMpChangeOpenidList); | ||||
| Assert.assertEquals(2, wxMpChangeOpenidList.size()); | Assert.assertEquals(2, wxMpChangeOpenidList.size()); | ||||
| WxMpChangeOpenid wxMpChangeOpenid = wxMpChangeOpenidList.get(0); | WxMpChangeOpenid wxMpChangeOpenid = wxMpChangeOpenidList.get(0); | ||||