- * 分组管理接口 - 创建分组 - * 最多支持创建500个分组 - * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口 - *- * - * @param name 分组名字(30个字符以内) - */ - WxMpGroup groupCreate(String name) throws WxErrorException; - - /** - *
- * 分组管理接口 - 查询所有分组 - * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口 - *- */ - List
- * 分组管理接口 - 查询用户所在分组 - * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口 - *- * - * @param openid 微信用户的openid - */ - long userGetGroup(String openid) throws WxErrorException; - - /** - *
- * 分组管理接口 - 修改分组名 - * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口 - * - * 如果id为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误 - *- * - * @param group 要更新的group,group的id,name必须设置 - */ - void groupUpdate(WxMpGroup group) throws WxErrorException; - - /** - *
- * 分组管理接口 - 移动用户分组 - * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口 - * - * 如果to_groupid为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误 - *- * - * @param openid 用户openid - * @param to_groupid 移动到的分组id - */ - void userUpdateGroup(String openid, long to_groupid) throws WxErrorException; -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpKefuService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpKefuService.java index c4731cb5..fc678b42 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpKefuService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpKefuService.java @@ -1,12 +1,18 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; -import me.chanjar.weixin.mp.bean.kefu.result.*; - import java.io.File; import java.util.Date; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.bean.WxMpCustomMessage; +import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; +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; + /** * 客服接口 , * 命名采用kefu拼音的原因是: @@ -17,6 +23,14 @@ import java.util.Date; */ public interface WxMpKefuService { + /** + *
+ * 发送客服消息 + * 详情请见: 发送客服消息 + *+ */ + boolean customMessageSend(WxMpCustomMessage message) throws WxErrorException; + //*******************客服管理接口***********************// /** diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMaterialService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMaterialService.java index 2325ccac..48a6f610 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMaterialService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMaterialService.java @@ -10,10 +10,12 @@ import java.io.IOException; import java.io.InputStream; /** + *
* Created by Binary Wang on 2016/7/21. * 素材管理的相关接口,包括媒体管理的接口, * 即以https://api.weixin.qq.com/cgi-bin/material * 和 https://api.weixin.qq.com/cgi-bin/media开头的接口 + **/ public interface WxMpMaterialService { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java index b72cc45a..7db50e79 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java @@ -1,24 +1,25 @@ package me.chanjar.weixin.mp.api; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import me.chanjar.weixin.common.api.WxErrorExceptionHandler; +import me.chanjar.weixin.common.api.WxMessageDuplicateChecker; +import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker; import me.chanjar.weixin.common.session.InternalSession; import me.chanjar.weixin.common.session.InternalSessionManager; import me.chanjar.weixin.common.session.StandardSessionManager; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.common.util.LogExceptionHandler; -import me.chanjar.weixin.common.api.WxErrorExceptionHandler; -import me.chanjar.weixin.common.api.WxMessageDuplicateChecker; -import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker; import me.chanjar.weixin.mp.bean.WxMpXmlMessage; import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; /** *
@@ -155,7 +156,7 @@ public class WxMpMessageRouter { } WxMpXmlOutMessage res = null; - final List*/ - WxMpMassSendResult massGroupMessageSend(WxMpMassGroupMessage message) throws WxErrorException; + WxMpMassSendResult massGroupMessageSend(WxMpMassTagMessage message) throws WxErrorException; /** *futures = new ArrayList<>(); + final List > futures = new ArrayList<>(); for (final WxMpMessageRouterRule rule : matchRules) { // 返回最后一个非异步的rule的执行结果 if(rule.isAsync()) { @@ -170,7 +171,7 @@ public class WxMpMessageRouter { } else { res = rule.service(wxMessage, this.wxMpService, this.sessionManager, this.exceptionHandler); // 在同步操作结束,session访问结束 - this.log.debug("End session access: async=false, sessionId={}", wxMessage.getFromUserName()); + this.log.debug("End session access: async=false, sessionId={}", wxMessage.getFromUser()); sessionEndAccess(wxMessage); } } @@ -179,10 +180,10 @@ public class WxMpMessageRouter { this.executorService.submit(new Runnable() { @Override public void run() { - for (Future future : futures) { + for (Future> future : futures) { try { future.get(); - WxMpMessageRouter.this.log.debug("End session access: async=true, sessionId={}", wxMessage.getFromUserName()); + WxMpMessageRouter.this.log.debug("End session access: async=true, sessionId={}", wxMessage.getFromUser()); // 异步操作结束,session访问结束 sessionEndAccess(wxMessage); } catch (InterruptedException e) { @@ -202,7 +203,7 @@ public class WxMpMessageRouter { StringBuffer messageId = new StringBuffer(); if (wxMessage.getMsgId() == null) { messageId.append(wxMessage.getCreateTime()) - .append("-").append(wxMessage.getFromUserName()) + .append("-").append(wxMessage.getFromUser()) .append("-").append(wxMessage.getEventKey() == null ? "" : wxMessage.getEventKey()) .append("-").append(wxMessage.getEvent() == null ? "" : wxMessage.getEvent()) ; @@ -220,7 +221,7 @@ public class WxMpMessageRouter { */ protected void sessionEndAccess(WxMpXmlMessage wxMessage) { - InternalSession session = ((InternalSessionManager)this.sessionManager).findSession(wxMessage.getFromUserName()); + InternalSession session = ((InternalSessionManager)this.sessionManager).findSession(wxMessage.getFromUser()); if (session != null) { session.endAccess(); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouterRule.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouterRule.java index eb02c641..317303b8 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouterRule.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouterRule.java @@ -168,7 +168,7 @@ public class WxMpMessageRouterRule { */ protected boolean test(WxMpXmlMessage wxMessage) { return - (this.fromUser == null || this.fromUser.equals(wxMessage.getFromUserName())) + (this.fromUser == null || this.fromUser.equals(wxMessage.getFromUser())) && (this.msgType == null || this.msgType.toLowerCase().equals((wxMessage.getMsgType()==null?null:wxMessage.getMsgType().toLowerCase()))) && diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java index 0db67cb7..72eabd08 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java @@ -1,10 +1,17 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.bean.result.*; - import java.util.Map; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.bean.pay.WxMpPayCallback; +import me.chanjar.weixin.mp.bean.pay.WxMpPayRefundResult; +import me.chanjar.weixin.mp.bean.pay.WxMpPayResult; +import me.chanjar.weixin.mp.bean.pay.WxMpPrepayIdResult; +import me.chanjar.weixin.mp.bean.pay.WxRedpackResult; +import me.chanjar.weixin.mp.bean.pay.WxSendRedpackRequest; +import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderRequest; +import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderResult; + /** * 微信支付相关接口 * Created by Binary Wang on 2016/7/28. @@ -12,77 +19,32 @@ import java.util.Map; */ public interface WxMpPayService { - - /** - * 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1) - * 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识" - * - * @param openId 支付人openId - * @param outTradeNo 商户端对应订单号 - * @param amt 金额(单位元) - * @param body 商品描述 - * @param tradeType 交易类型 JSAPI,NATIVE,APP,WAP - * @param ip 发起支付的客户端IP - * @param notifyUrl 通知地址 - * @deprecated Use me.chanjar.weixin.mp.api.WxMpService.getPrepayId(Map ) instead - */ - @Deprecated - WxMpPrepayIdResult getPrepayId(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String notifyUrl); - /** * 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1) * 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识" + * 接口地址:https://api.mch.weixin.qq.com/pay/unifiedorder + * @throws WxErrorException * - * @param parameters All required/optional parameters for weixin payment */ - WxMpPrepayIdResult getPrepayId(Map parameters); + WxUnifiedOrderResult unifiedOrder(WxUnifiedOrderRequest request) + throws WxErrorException; /** * 该接口调用“统一下单”接口,并拼装发起支付请求需要的参数 - * 详见http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E5.8F.91.E8.B5.B7.E4.B8.80.E4.B8.AA.E5.BE.AE.E4.BF.A1.E6.94.AF.E4.BB.98.E8.AF.B7.E6.B1.82 + * 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN * - * @param parameters the required or optional parameters */ - Map getPayInfo(Map parameters) throws WxErrorException; + Map getPayInfo(WxUnifiedOrderRequest request) throws WxErrorException; - /** - * 该接口调用“统一下单”接口,并拼装NATIVE发起支付请求需要的参数 - * 详见http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E5.8F.91.E8.B5.B7.E4.B8.80.E4.B8.AA.E5.BE.AE.E4.BF.A1.E6.94.AF.E4.BB.98.E8.AF.B7.E6.B1.82 - * tradeType 交易类型 NATIVE (其他交易类型JSAPI,APP,WAP) - * - * @param productId 商户商品ID - * @param outTradeNo 商户端对应订单号 - * @param amt 金额(单位元) - * @param body 商品描述 - * @param ip 发起支付的客户端IP - * @param notifyUrl 通知地址 - * @deprecated Use me.chanjar.weixin.mp.api.WxMpService.getPayInfo(Map ) instead - */ - @Deprecated - Map getNativePayInfo(String productId, String outTradeNo, double amt, String body, String ip, String notifyUrl) throws WxErrorException; - - /** - * 该接口调用“统一下单”接口,并拼装JSAPI发起支付请求需要的参数 - * 详见http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E5.8F.91.E8.B5.B7.E4.B8.80.E4.B8.AA.E5.BE.AE.E4.BF.A1.E6.94.AF.E4.BB.98.E8.AF.B7.E6.B1.82 - * tradeType 交易类型 JSAPI(其他交易类型NATIVE,APP,WAP) - * - * @param openId 支付人openId - * @param outTradeNo 商户端对应订单号 - * @param amt 金额(单位元) - * @param body 商品描述 - * @param ip 发起支付的客户端IP - * @param notifyUrl 通知地址 - * @deprecated Use me.chanjar.weixin.mp.api.WxMpService.getPayInfo(Map ) instead - */ - @Deprecated - Map getJsapiPayInfo(String openId, String outTradeNo, double amt, String body, String ip, String notifyUrl) throws WxErrorException; /** * 该接口提供所有微信支付订单的查询,当支付通知处理异常戒丢失的情冴,商户可以通过该接口查询订单支付状态。 * 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2 + * @throws WxErrorException * */ - WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo); + WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo) + throws WxErrorException; /** * 读取支付结果通知 @@ -116,23 +78,12 @@ public interface WxMpPayService { /** * 发送微信红包给个人用户 - * - * 需要传入的必填参数如下: - * mch_billno//商户订单号 - * send_name//商户名称 - * re_openid//用户openid - * total_amount//红包总额 - * total_num//红包发放总人数 - * wishing//红包祝福语 - * client_ip//服务器Ip地址 - * act_name//活动名称 - * remark //备注 - * 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5 - *
- * 使用现金红包功能需要在xml配置文件中额外设置: - *
微信商户平台ID - * 商户平台设置的API密钥 - * + * + * 文档详见: + * 发送普通红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3 + * 发送裂变红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4 + **/ - WxRedpackResult sendRedpack(Mapparameters) throws WxErrorException; + WxRedpackResult sendRedpack(WxSendRedpackRequest request) throws WxErrorException; + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java index ab205a03..292c5645 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java @@ -3,18 +3,25 @@ package me.chanjar.weixin.mp.api; import me.chanjar.weixin.common.bean.WxJsapiSignature; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.RequestExecutor; -import me.chanjar.weixin.mp.bean.*; -import me.chanjar.weixin.mp.bean.result.*; - -import java.text.SimpleDateFormat; +import me.chanjar.weixin.mp.bean.WxMpIndustry; +import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; +import me.chanjar.weixin.mp.bean.WxMpMassNews; +import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; +import me.chanjar.weixin.mp.bean.WxMpMassPreviewMessage; +import me.chanjar.weixin.mp.bean.WxMpMassVideo; +import me.chanjar.weixin.mp.bean.WxMpSemanticQuery; +import me.chanjar.weixin.mp.bean.WxMpTemplateMessage; +import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; +import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; +import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; +import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; +import me.chanjar.weixin.mp.bean.result.WxMpUser; /** * 微信API的Service */ public interface WxMpService { - SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); - /** * * 验证推送过来的消息的正确性 @@ -74,14 +81,6 @@ public interface WxMpService { */ WxJsapiSignature createJsapiSignature(String url) throws WxErrorException; - /** - ** - * @see #massGroupMessageSend(me.chanjar.weixin.mp.bean.WxMpMassGroupMessage) + * @see #massGroupMessageSend(me.chanjar.weixin.mp.bean.WxMpMassTagMessage) * @see #massOpenIdsMessageSend(me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage) */ WxMpMassUploadResult massVideoUpload(WxMpMassVideo video) throws WxErrorException; @@ -113,7 +112,7 @@ public interface WxMpService { * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口 *- * 发送客服消息 - * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=发送客服消息 - *- */ - void customMessageSend(WxMpCustomMessage message) throws WxErrorException; - /** ** 上传群发用的图文消息,上传后才能群发图文消息 @@ -89,7 +88,7 @@ public interface WxMpService { * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口 ** - * @see #massGroupMessageSend(me.chanjar.weixin.mp.bean.WxMpMassGroupMessage) + * @see #massGroupMessageSend(me.chanjar.weixin.mp.bean.WxMpMassTagMessage) * @see #massOpenIdsMessageSend(me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage) */ WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException; @@ -100,7 +99,7 @@ public interface WxMpService { * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口 *
@@ -303,58 +302,72 @@ public interface WxMpService { WxMpKefuService getKefuService(); /** - * 返回素材相关接口的方法实现类,以方便调用个其各种接口 + * 返回素材相关接口方法的实现类对象,以方便调用个其各种接口 * * @return WxMpMaterialService */ WxMpMaterialService getMaterialService(); /** - * 返回菜单相关接口的方法实现类,以方便调用个其各种接口 + * 返回菜单相关接口方法的实现类对象,以方便调用个其各种接口 * * @return WxMpMenuService */ WxMpMenuService getMenuService(); /** - * 返回用户相关接口的方法实现类,以方便调用个其各种接口 + * 返回用户相关接口方法的实现类对象,以方便调用个其各种接口 * * @return WxMpUserService */ WxMpUserService getUserService(); /** - * 返回用户分组相关接口的方法实现类,以方便调用个其各种接口 + * 返回用户标签相关接口方法的实现类对象,以方便调用个其各种接口 * - * @return WxMpGroupService + * @return WxMpUserTagService */ - WxMpGroupService getGroupService(); + WxMpUserTagService getUserTagService(); /** - * 返回二维码相关接口的方法实现类,以方便调用个其各种接口 + * 返回二维码相关接口方法的实现类对象,以方便调用个其各种接口 * * @return WxMpQrcodeService */ WxMpQrcodeService getQrcodeService(); /** - * 返回卡券相关接口的方法实现类,以方便调用个其各种接口 + * 返回卡券相关接口方法的实现类对象,以方便调用个其各种接口 * * @return WxMpCardService */ WxMpCardService getCardService(); /** - * 返回微信支付相关接口的方法实现类,以方便调用个其各种接口 + * 返回微信支付相关接口方法的实现类对象,以方便调用个其各种接口 * * @return WxMpPayService */ WxMpPayService getPayService(); /** - * 返回数据分析统计相关接口的方法实现类,以方便调用个其各种接口 + * 返回数据分析统计相关接口方法的实现类对象,以方便调用个其各种接口 * * @return WxMpDataCubeService */ WxMpDataCubeService getDataCubeService(); + + /** + * 返回用户黑名单管理相关接口方法的实现类对象,以方便调用其各种接口 + * + * @return WxMpUserBlacklistService + */ + WxMpUserBlacklistService getBlackListService(); + + /** + * 返回门店管理相关接口方法的实现类对象,以方便调用其各种接口 + * + * @return WxMpStoreService + */ + WxMpStoreService getStoreService(); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java new file mode 100644 index 00000000..0ce7cc03 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java @@ -0,0 +1,103 @@ +package me.chanjar.weixin.mp.api; + +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo; +import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo; +import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult; + +import java.util.List; + +/** + * 门店管理的相关接口代码 + * @author binarywang(https://github.com/binarywang) + * Created by Binary Wang on 2016-09-23. + */ +public interface WxMpStoreService { + /** + ** - * @param openidList 用户openid列表 + * @param openids 用户openid列表 */ - List+ * 创建门店 + * 接口说明 + * 创建门店接口是为商户提供创建自己门店数据的接口,门店数据字段越完整,商户页面展示越丰富,越能够吸引更多用户,并提高曝光度。 + * 创建门店接口调用成功后会返回errcode 0、errmsg ok,但不会实时返回poi_id。 + * 成功创建后,会生成poi_id,但该id不一定为最终id。门店信息会经过审核,审核通过后方可获取最终poi_id,该id为门店的唯一id,强烈建议自行存储审核通过后的最终poi_id,并为后续调用使用。 + * 详情请见: 微信门店接口 + * 接口格式: http://api.weixin.qq.com/cgi-bin/poi/addpoi?access_token=TOKEN + *+ * + */ + void add(WxMpStoreBaseInfo request) throws WxErrorException; + + /** + *+ * 查询门店信息 + * 创建门店后获取poi_id 后,商户可以利用poi_id,查询具体某条门店的信息。 + * 若在查询时,update_status 字段为1,表明在5 个工作日内曾用update 接口修改过门店扩展字段,该扩展字段为最新的修改字段,尚未经过审核采纳,因此不是最终结果。 + * 最终结果会在5 个工作日内,最终确认是否采纳,并前端生效(但该扩展字段的采纳过程不影响门店的可用性,即available_state仍为审核通过状态) + * 注:扩展字段为公共编辑信息(大家都可修改),修改将会审核,并决定是否对修改建议进行采纳,但不会影响该门店的生效可用状态。 + * 详情请见: 微信门店接口 + * 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getpoi?access_token=TOKEN + *+ * @param poiId 门店Id + * @throws WxErrorException + */ + WxMpStoreBaseInfo get(String poiId) throws WxErrorException; + + /** + *+ * 删除门店 + * 商户可以通过该接口,删除已经成功创建的门店。请商户慎重调用该接口。 + * 详情请见: 微信门店接口 + * 接口格式:http://api.weixin.qq.com/cgi-bin/poi/delpoi?access_token=TOKEN + *+ * @param poiId 门店Id + * @throws WxErrorException + */ + void delete(String poiId) throws WxErrorException; + + /** + *+ * 查询门店列表(指定查询起始位置和个数) + * 商户可以通过该接口,批量查询自己名下的门店list,并获取已审核通过的poi_id(所有状态均会返回poi_id,但该poi_id不一定为最终id)、商户自身sid 用于对应、商户名、分店名、地址字段。 + * 详情请见: 微信门店接口 + * 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=TOKEN + *+ * @param begin 开始位置,0 即为从第一条开始查询 + * @param limit 返回数据条数,最大允许50,默认为20 + * @throws WxErrorException + */ + WxMpStoreListResult list(int begin, int limit) throws WxErrorException; + + /** + *+ * 查询门店列表(所有) + * 商户可以通过该接口,批量查询自己名下的门店list,并获取已审核通过的poi_id(所有状态均会返回poi_id,但该poi_id不一定为最终id)、商户自身sid 用于对应、商户名、分店名、地址字段。 + * 详情请见: 微信门店接口 + * 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=TOKEN + *+ * @throws WxErrorException + */ + ListlistAll() throws WxErrorException; + + /** + * + * 修改门店服务信息 + * 商户可以通过该接口,修改门店的服务信息,包括:sid、图片列表、营业时间、推荐、特色服务、简介、人均价格、电话8个字段(名称、坐标、地址等不可修改)修改后需要人工审核。 + * 详情请见: 微信门店接口 + * 接口格式:http://api.weixin.qq.com/cgi-bin/poi/updatepoi?access_token=TOKEN + *+ * @throws WxErrorException + */ + void update(WxMpStoreBaseInfo info) throws WxErrorException; + + /** + *+ * 门店类目表 + * 类目名称接口是为商户提供自己门店类型信息的接口。门店类目定位的越规范,能够精准的吸引更多用户,提高曝光率。 + * 详情请见: 微信门店接口 + * 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getwxcategory?access_token=TOKEN + *+ * @throws WxErrorException + */ + ListlistCategories() throws WxErrorException; + +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserBlacklistService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserBlacklistService.java new file mode 100644 index 00000000..d93384f0 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserBlacklistService.java @@ -0,0 +1,35 @@ +package me.chanjar.weixin.mp.api; + +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; + +import java.util.List; + +/** + * @author miller + */ +public interface WxMpUserBlacklistService { + /** + * + * 获取公众号的黑名单列表 + * 详情请见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1471422259_pJMWA&token=&lang=zh_CN + *+ */ + WxMpUserBlacklistGetResult getBlacklist(String nextOpenid) throws WxErrorException; + + /** + *+ * 拉黑用户 + * 详情请见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1471422259_pJMWA&token=&lang=zh_CN + *+ */ + void pushToBlacklist(ListopenidList) throws WxErrorException; + + /** + * + * 取消拉黑用户 + * 详情请见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1471422259_pJMWA&token=&lang=zh_CN + *+ */ + void pullFromBlacklist(ListopenidList) throws WxErrorException; +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserService.java index deaf85ab..f46ca634 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserService.java @@ -1,14 +1,14 @@ package me.chanjar.weixin.mp.api; +import java.util.List; + import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.bean.WxMpUserQuery; import me.chanjar.weixin.mp.bean.result.WxMpUser; import me.chanjar.weixin.mp.bean.result.WxMpUserList; -import java.util.List; - /** - * 用户管理和统计相关操作接口 + * 用户管理相关操作接口 * * @author Binary Wang */ @@ -42,9 +42,9 @@ public interface WxMpUserService { * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=批量获取用户基本信息 *
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java new file mode 100644 index 00000000..0fcfb40f --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java @@ -0,0 +1,101 @@ +package me.chanjar.weixin.mp.api; + +import java.util.List; + +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.bean.tag.WxTagListUser; +import me.chanjar.weixin.mp.bean.tag.WxUserTag; + +/** + * 用户标签管理相关接口 + * Created by Binary Wang on 2016/9/2. + * @author binarywang(https://github.com/binarywang) + * + */ +public interface WxMpUserTagService { + + /** + ** - * @param openId + * @param openid * @return {@link WxMpUserQuery} */ - public WxMpUserQuery add(String openId) { - this.queryParamList.add(new WxMpUserQueryParam(openId)); + public WxMpUserQuery add(String openid) { + this.queryParamList.add(new WxMpUserQueryParam(openid)); return this; } /** * 删除指定的OpenId,语言使用默认(zh_CN) * - * @param openId + * @param openid * @return {@link WxMpUserQuery} */ - public WxMpUserQuery remove(String openId) { - this.queryParamList.remove(new WxMpUserQueryParam(openId)); + public WxMpUserQuery remove(String openid) { + this.queryParamList.remove(new WxMpUserQueryParam(openid)); return this; } /** * 删除指定的OpenId * - * @param openId + * @param openid * @param lang 国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语 * @return {@link WxMpUserQuery} */ - public WxMpUserQuery remove(String openId, String lang) { - this.queryParamList.remove(new WxMpUserQueryParam(openId, lang)); + public WxMpUserQuery remove(String openid, String lang) { + this.queryParamList.remove(new WxMpUserQueryParam(openid, lang)); return this; } @@ -110,9 +110,6 @@ public class WxMpUserQuery { // 查询参数封装 public class WxMpUserQueryParam implements Serializable { - /** - * @fields serialVersionUID - */ private static final long serialVersionUID = -6863571795702385319L; private String openid; private String lang; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlMessage.java index 823558fe..9adcb54d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlMessage.java @@ -6,8 +6,6 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import me.chanjar.weixin.mp.util.json.WxLongTimeJsonSerializer; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -22,11 +20,10 @@ import me.chanjar.weixin.mp.util.xml.XStreamTransformer; /** *+ * 创建标签 + * 一个公众号,最多可以创建100个标签。 + * 详情请见:用户标签管理 + * 接口url格式: https://api.weixin.qq.com/cgi-bin/tags/create?access_token=ACCESS_TOKEN + *+ * + * @param name 标签名字(30个字符以内) + */ + WxUserTag tagCreate(String name) throws WxErrorException; + + /** + *+ * 获取公众号已创建的标签 + * 详情请见:用户标签管理 + * 接口url格式: https://api.weixin.qq.com/cgi-bin/tags/get?access_token=ACCESS_TOKEN + *+ * + */ + ListtagGet() throws WxErrorException; + + /** + * + * 编辑标签 + * 详情请见:用户标签管理 + * 接口url格式: https://api.weixin.qq.com/cgi-bin/tags/update?access_token=ACCESS_TOKEN + *+ * + */ + Boolean tagUpdate(Long tagId, String name) throws WxErrorException; + + /** + *+ * 删除标签 + * 详情请见:用户标签管理 + * 接口url格式: https://api.weixin.qq.com/cgi-bin/tags/delete?access_token=ACCESS_TOKEN + *+ * + */ + Boolean tagDelete(Long tagId) throws WxErrorException; + + /** + *+ * 获取标签下粉丝列表 + * 详情请见:用户标签管理 + * 接口url格式: https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=ACCESS_TOKEN + *+ * + */ + WxTagListUser tagListUser(Long tagId, String nextOpenid) + throws WxErrorException; + + /** + *+ * 批量为用户打标签 + * 详情请见:用户标签管理 + * 接口url格式: https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=ACCESS_TOKEN + *+ * + */ + boolean batchTagging(Long tagId, String[] openids) throws WxErrorException; + + /** + *+ * 批量为用户取消标签 + * 详情请见:用户标签管理 + * 接口url格式: https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=ACCESS_TOKEN + *+ * + */ + boolean batchUntagging(Long tagId, String[] openids) throws WxErrorException; + + + /** + *+ * 获取用户身上的标签列表 + * 详情请见:用户标签管理 + * 接口url格式: https://api.weixin.qq.com/cgi-bin/tags/getidlist?access_token=ACCESS_TOKEN + *+ * + */ + ListuserTagList(String openid) throws WxErrorException; + +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImpl.java index b65d1ff4..63e13809 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImpl.java @@ -1,6 +1,5 @@ package me.chanjar.weixin.mp.api.impl; -import java.security.NoSuchAlgorithmException; import java.util.Arrays; import org.slf4j.Logger; @@ -111,16 +110,12 @@ public class WxMpCardServiceImpl implements WxMpCardService { signParam[optionalSignParam.length] = String.valueOf(timestamp); signParam[optionalSignParam.length + 1] = nonceStr; signParam[optionalSignParam.length + 2] = cardApiTicket; - try { - String signature = SHA1.gen(signParam); - WxCardApiSignature cardApiSignature = new WxCardApiSignature(); - cardApiSignature.setTimestamp(timestamp); - cardApiSignature.setNonceStr(nonceStr); - cardApiSignature.setSignature(signature); - return cardApiSignature; - } catch (NoSuchAlgorithmException e) { - throw new WxErrorException(WxError.newBuilder().setErrorMsg(e.getMessage()).build()); - } + String signature = SHA1.gen(signParam); + WxCardApiSignature cardApiSignature = new WxCardApiSignature(); + cardApiSignature.setTimestamp(timestamp); + cardApiSignature.setNonceStr(nonceStr); + cardApiSignature.setSignature(signature); + return cardApiSignature; } /** diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java index 092d6af1..2dbee076 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java @@ -1,21 +1,13 @@ package me.chanjar.weixin.mp.api.impl; import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.reflect.TypeToken; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.WxMpDataCubeService; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult; -import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleTotal; -import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult; -import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult; -import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate; -import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary; -import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import me.chanjar.weixin.mp.bean.datacube.*; +import org.apache.commons.lang3.time.FastDateFormat; +import java.text.Format; import java.util.Date; import java.util.List; @@ -24,9 +16,10 @@ import java.util.List; * @author binarywang (https://github.com/binarywang) */ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService { - protected final Logger log = LoggerFactory.getLogger(WxMpDataCubeServiceImpl.class); - private static final String API_URL_PREFIX = "https://api.weixin.qq.com/datacube"; + + private final Format dateFormat = FastDateFormat.getInstance("yyyy-MM-dd"); + private WxMpService wxMpService; public WxMpDataCubeServiceImpl(WxMpService wxMpService) { @@ -37,104 +30,80 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService { public List getUserSummary(Date beginDate, Date endDate) throws WxErrorException { String url = API_URL_PREFIX + "/getusersummary"; JsonObject param = new JsonObject(); - param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate)); - param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate)); + param.addProperty("begin_date", this.dateFormat.format(beginDate)); + param.addProperty("end_date", this.dateFormat.format(endDate)); String responseContent = this.wxMpService.post(url, param.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), - new TypeToken >() { - }.getType()); + return WxDataCubeUserSummary.fromJson(responseContent); } @Override public List
getUserCumulate(Date beginDate, Date endDate) throws WxErrorException { String url = API_URL_PREFIX + "/getusercumulate"; JsonObject param = new JsonObject(); - param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate)); - param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate)); + param.addProperty("begin_date", this.dateFormat.format(beginDate)); + param.addProperty("end_date", this.dateFormat.format(endDate)); String responseContent = this.wxMpService.post(url, param.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), - new TypeToken >() { - }.getType()); + return WxDataCubeUserCumulate.fromJson(responseContent); } @Override public List
getArticleSummary(Date beginDate, Date endDate) throws WxErrorException { String url = API_URL_PREFIX + "/getarticlesummary"; JsonObject param = new JsonObject(); - param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate)); - param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate)); + param.addProperty("begin_date", this.dateFormat.format(beginDate)); + param.addProperty("end_date", this.dateFormat.format(endDate)); String responseContent = this.wxMpService.post(url, param.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), - new TypeToken >() { - }.getType()); + return WxDataCubeArticleResult.fromJson(responseContent); } @Override public List
getArticleTotal(Date beginDate, Date endDate) throws WxErrorException { String url = API_URL_PREFIX + "/getarticletotal"; JsonObject param = new JsonObject(); - param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate)); - param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate)); + param.addProperty("begin_date", this.dateFormat.format(beginDate)); + param.addProperty("end_date", this.dateFormat.format(endDate)); String responseContent = this.wxMpService.post(url, param.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), - new TypeToken >() { - }.getType()); + return WxDataCubeArticleTotal.fromJson(responseContent); } @Override public List
getUserRead(Date beginDate, Date endDate) throws WxErrorException { String url = API_URL_PREFIX + "/getuserread"; JsonObject param = new JsonObject(); - param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate)); - param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate)); + param.addProperty("begin_date", this.dateFormat.format(beginDate)); + param.addProperty("end_date", this.dateFormat.format(endDate)); String responseContent = this.wxMpService.post(url, param.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), - new TypeToken >() { - }.getType()); + return WxDataCubeArticleResult.fromJson(responseContent); } @Override public List
getUserReadHour(Date beginDate, Date endDate) throws WxErrorException { String url = API_URL_PREFIX + "/getuserreadhour"; JsonObject param = new JsonObject(); - param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate)); - param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate)); + param.addProperty("begin_date", this.dateFormat.format(beginDate)); + param.addProperty("end_date", this.dateFormat.format(endDate)); String responseContent = this.wxMpService.post(url, param.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), - new TypeToken >() { - }.getType()); + return WxDataCubeArticleResult.fromJson(responseContent); } @Override public List
getUserShare(Date beginDate, Date endDate) throws WxErrorException { String url = API_URL_PREFIX + "/getusershare"; JsonObject param = new JsonObject(); - param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate)); - param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate)); + param.addProperty("begin_date", this.dateFormat.format(beginDate)); + param.addProperty("end_date", this.dateFormat.format(endDate)); String responseContent = this.wxMpService.post(url, param.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), - new TypeToken >() { - }.getType()); + return WxDataCubeArticleResult.fromJson(responseContent); } @Override public List
getUserShareHour(Date beginDate, Date endDate) throws WxErrorException { String url = API_URL_PREFIX + "/getusersharehour"; JsonObject param = new JsonObject(); - param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate)); - param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate)); + param.addProperty("begin_date", this.dateFormat.format(beginDate)); + param.addProperty("end_date", this.dateFormat.format(endDate)); String responseContent = this.wxMpService.post(url, param.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), - new TypeToken >() { - }.getType()); + return WxDataCubeArticleResult.fromJson(responseContent); } @Override @@ -142,13 +111,10 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService { throws WxErrorException { String url = API_URL_PREFIX + "/getupstreammsg"; JsonObject param = new JsonObject(); - param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate)); - param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate)); + param.addProperty("begin_date", this.dateFormat.format(beginDate)); + param.addProperty("end_date", this.dateFormat.format(endDate)); String responseContent = this.wxMpService.post(url, param.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), - new TypeToken
>() { - }.getType()); + return WxDataCubeMsgResult.fromJson(responseContent); } @Override @@ -156,13 +122,10 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService { Date endDate) throws WxErrorException { String url = API_URL_PREFIX + "/getupstreammsghour"; JsonObject param = new JsonObject(); - param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate)); - param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate)); + param.addProperty("begin_date", this.dateFormat.format(beginDate)); + param.addProperty("end_date", this.dateFormat.format(endDate)); String responseContent = this.wxMpService.post(url, param.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), - new TypeToken
>() { - }.getType()); + return WxDataCubeMsgResult.fromJson(responseContent); } @Override @@ -170,13 +133,10 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService { Date endDate) throws WxErrorException { String url = API_URL_PREFIX + "/getupstreammsgweek"; JsonObject param = new JsonObject(); - param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate)); - param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate)); + param.addProperty("begin_date", this.dateFormat.format(beginDate)); + param.addProperty("end_date", this.dateFormat.format(endDate)); String responseContent = this.wxMpService.post(url, param.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), - new TypeToken
>() { - }.getType()); + return WxDataCubeMsgResult.fromJson(responseContent); } @Override @@ -184,13 +144,10 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService { Date endDate) throws WxErrorException { String url = API_URL_PREFIX + "/getupstreammsgmonth"; JsonObject param = new JsonObject(); - param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate)); - param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate)); + param.addProperty("begin_date", this.dateFormat.format(beginDate)); + param.addProperty("end_date", this.dateFormat.format(endDate)); String responseContent = this.wxMpService.post(url, param.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), - new TypeToken
>() { - }.getType()); + return WxDataCubeMsgResult.fromJson(responseContent); } @Override @@ -198,13 +155,10 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService { Date endDate) throws WxErrorException { String url = API_URL_PREFIX + "/getupstreammsgdist"; JsonObject param = new JsonObject(); - param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate)); - param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate)); + param.addProperty("begin_date", this.dateFormat.format(beginDate)); + param.addProperty("end_date", this.dateFormat.format(endDate)); String responseContent = this.wxMpService.post(url, param.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), - new TypeToken
>() { - }.getType()); + return WxDataCubeMsgResult.fromJson(responseContent); } @Override @@ -212,13 +166,10 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService { Date endDate) throws WxErrorException { String url = API_URL_PREFIX + "/getupstreammsgdistweek"; JsonObject param = new JsonObject(); - param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate)); - param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate)); + param.addProperty("begin_date", this.dateFormat.format(beginDate)); + param.addProperty("end_date", this.dateFormat.format(endDate)); String responseContent = this.wxMpService.post(url, param.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), - new TypeToken
>() { - }.getType()); + return WxDataCubeMsgResult.fromJson(responseContent); } @Override @@ -226,13 +177,10 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService { Date endDate) throws WxErrorException { String url = API_URL_PREFIX + "/getupstreammsgdistmonth"; JsonObject param = new JsonObject(); - param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate)); - param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate)); + param.addProperty("begin_date", this.dateFormat.format(beginDate)); + param.addProperty("end_date", this.dateFormat.format(endDate)); String responseContent = this.wxMpService.post(url, param.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), - new TypeToken
>() { - }.getType()); + return WxDataCubeMsgResult.fromJson(responseContent); } @Override @@ -240,13 +188,10 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService { Date endDate) throws WxErrorException { String url = API_URL_PREFIX + "/getinterfacesummary"; JsonObject param = new JsonObject(); - param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate)); - param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate)); + param.addProperty("begin_date", this.dateFormat.format(beginDate)); + param.addProperty("end_date", this.dateFormat.format(endDate)); String responseContent = this.wxMpService.post(url, param.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), - new TypeToken
>() { - }.getType()); + return WxDataCubeInterfaceResult.fromJson(responseContent); } @Override @@ -254,12 +199,9 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService { Date endDate) throws WxErrorException { String url = API_URL_PREFIX + "/getinterfacesummaryhour"; JsonObject param = new JsonObject(); - param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate)); - param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate)); + param.addProperty("begin_date", this.dateFormat.format(beginDate)); + param.addProperty("end_date", this.dateFormat.format(endDate)); String responseContent = this.wxMpService.post(url, param.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), - new TypeToken
>() { - }.getType()); + return WxDataCubeInterfaceResult.fromJson(responseContent); } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImpl.java deleted file mode 100644 index 5f97a83a..00000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImpl.java +++ /dev/null @@ -1,84 +0,0 @@ -package me.chanjar.weixin.mp.api.impl; - -import java.util.List; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.reflect.TypeToken; - -import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; -import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; -import me.chanjar.weixin.common.util.json.GsonHelper; -import me.chanjar.weixin.mp.api.WxMpGroupService; -import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.bean.WxMpGroup; -import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; - -/** - * Created by Binary Wang on 2016/7/21. - */ -public class WxMpGroupServiceImpl implements WxMpGroupService { - private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/groups"; - private WxMpService wxMpService; - - public WxMpGroupServiceImpl(WxMpService wxMpService) { - this.wxMpService = wxMpService; - } - - @Override - public WxMpGroup groupCreate(String name) throws WxErrorException { - String url = API_URL_PREFIX + "/create"; - JsonObject json = new JsonObject(); - JsonObject groupJson = new JsonObject(); - json.add("group", groupJson); - groupJson.addProperty("name", name); - - String responseContent = this.wxMpService.execute( - new SimplePostRequestExecutor(), - url, - json.toString()); - return WxMpGroup.fromJson(responseContent); - } - - @Override - public List
groupGet() throws WxErrorException { - String url = API_URL_PREFIX + "/get"; - String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, null); - /* - * 操蛋的微信API,创建时返回的是 { group : { id : ..., name : ...} } - * 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] } - */ - JsonElement tmpJsonElement = new JsonParser().parse(responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"), - new TypeToken >() { - }.getType()); - } - - @Override - public long userGetGroup(String openid) throws WxErrorException { - String url = API_URL_PREFIX + "/getid"; - JsonObject o = new JsonObject(); - o.addProperty("openid", openid); - String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, o.toString()); - JsonElement tmpJsonElement = new JsonParser().parse(responseContent); - return GsonHelper.getAsLong(tmpJsonElement.getAsJsonObject().get("groupid")); - } - - @Override - public void groupUpdate(WxMpGroup group) throws WxErrorException { - String url = API_URL_PREFIX + "/update"; - this.wxMpService.execute(new SimplePostRequestExecutor(), url, group.toJson()); - } - - @Override - public void userUpdateGroup(String openid, long to_groupid) throws WxErrorException { - String url = API_URL_PREFIX + "/members/update"; - JsonObject json = new JsonObject(); - json.addProperty("openid", openid); - json.addProperty("to_groupid", to_groupid); - this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString()); - } - -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java index 6d6cf14c..99428348 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java @@ -1,52 +1,57 @@ package me.chanjar.weixin.mp.api.impl; -import java.io.File; -import java.util.Date; - import com.google.gson.JsonObject; - import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; -import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; -import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; import me.chanjar.weixin.mp.api.WxMpKefuService; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.WxMpCustomMessage; 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.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 org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.util.Date; /** - * + * * @author Binary Wang * */ public class WxMpKefuServiceImpl implements WxMpKefuService { + protected final Logger log = LoggerFactory + .getLogger(WxMpKefuServiceImpl.class); private static final String API_URL_PREFIX = "https://api.weixin.qq.com/customservice"; + private static final String API_URL_PREFIX_WITH_CGI_BIN = "https://api.weixin.qq.com/cgi-bin/customservice"; private WxMpService wxMpService; public WxMpKefuServiceImpl(WxMpService wxMpService) { this.wxMpService = wxMpService; } + @Override + public boolean customMessageSend(WxMpCustomMessage message) + throws WxErrorException { + String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send"; + String responseContent = this.wxMpService.post(url, message.toJson()); + return true; + } + @Override public WxMpKfList kfList() throws WxErrorException { - String url = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist"; - String responseContent = this.wxMpService - .execute(new SimpleGetRequestExecutor(), url, null); + String url = API_URL_PREFIX_WITH_CGI_BIN + "/getkflist"; + String responseContent = this.wxMpService.get(url, null); return WxMpKfList.fromJson(responseContent); } @Override public WxMpKfOnlineList kfOnlineList() throws WxErrorException { - String url = "https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist"; - String responseContent = this.wxMpService - .execute(new SimpleGetRequestExecutor(), url, null); + String url = API_URL_PREFIX_WITH_CGI_BIN + "/getonlinekflist"; + String responseContent = this.wxMpService.get(url, null); return WxMpKfOnlineList.fromJson(responseContent); } @@ -54,8 +59,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { public boolean kfAccountAdd(WxMpKfAccountRequest request) throws WxErrorException { String url = API_URL_PREFIX + "/kfaccount/add"; - this.wxMpService.execute(new SimplePostRequestExecutor(), url, - request.toJson()); + String responseContent = this.wxMpService.post(url, request.toJson()); return true; } @@ -63,16 +67,14 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { public boolean kfAccountUpdate(WxMpKfAccountRequest request) throws WxErrorException { String url = API_URL_PREFIX + "/kfaccount/update"; - this.wxMpService.execute(new SimplePostRequestExecutor(), url, - request.toJson()); + String responseContent = this.wxMpService.post(url, request.toJson()); return true; } @Override public boolean kfAccountInviteWorker(WxMpKfAccountRequest request) throws WxErrorException { String url = API_URL_PREFIX + "/kfaccount/inviteworker"; - this.wxMpService.execute(new SimplePostRequestExecutor(), url, - request.toJson()); + String responseContent = this.wxMpService.post(url, request.toJson()); return true; } @@ -80,14 +82,15 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { public boolean kfAccountUploadHeadImg(String kfAccount, File imgFile) throws WxErrorException { String url = API_URL_PREFIX + "/kfaccount/uploadheadimg?kf_account=" + kfAccount; - this.wxMpService.execute(new MediaUploadRequestExecutor(), url, imgFile); + WxMediaUploadResult responseContent = this.wxMpService + .execute(new MediaUploadRequestExecutor(), url, imgFile); return true; } @Override public boolean kfAccountDel(String kfAccount) throws WxErrorException { String url = API_URL_PREFIX + "/kfaccount/del?kf_account=" + kfAccount; - this.wxMpService.execute(new SimpleGetRequestExecutor(), url, null); + String responseContent = this.wxMpService.get(url, null); return true; } @@ -96,8 +99,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { throws WxErrorException { WxMpKfSessionRequest request = new WxMpKfSessionRequest(kfAccount, openid); String url = API_URL_PREFIX + "/kfsession/create"; - this.wxMpService.execute(new SimplePostRequestExecutor(), url, - request.toJson()); + String responseContent = this.wxMpService.post(url, request.toJson()); return true; } @@ -106,8 +108,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { throws WxErrorException { WxMpKfSessionRequest request = new WxMpKfSessionRequest(kfAccount, openid); String url = API_URL_PREFIX + "/kfsession/close"; - this.wxMpService.execute(new SimplePostRequestExecutor(), url, - request.toJson()); + String responseContent = this.wxMpService.post(url, request.toJson()); return true; } @@ -115,8 +116,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { public WxMpKfSessionGetResult kfSessionGet(String openid) throws WxErrorException { String url = API_URL_PREFIX + "/kfsession/getsession?openid=" + openid; - String responseContent = this.wxMpService - .execute(new SimpleGetRequestExecutor(), url, null); + String responseContent = this.wxMpService.get(url, null); return WxMpKfSessionGetResult.fromJson(responseContent); } @@ -124,8 +124,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { public WxMpKfSessionList kfSessionList(String kfAccount) throws WxErrorException { String url = API_URL_PREFIX + "/kfsession/getsessionlist?kf_account=" + kfAccount; - String responseContent = this.wxMpService - .execute(new SimpleGetRequestExecutor(), url, null); + String responseContent = this.wxMpService.get(url, null); return WxMpKfSessionList.fromJson(responseContent); } @@ -133,8 +132,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { public WxMpKfSessionWaitCaseList kfSessionGetWaitCase() throws WxErrorException { String url = API_URL_PREFIX + "/kfsession/getwaitcase"; - String responseContent = this.wxMpService - .execute(new SimpleGetRequestExecutor(), url, null); + String responseContent = this.wxMpService.get(url, null); return WxMpKfSessionWaitCaseList.fromJson(responseContent); } @@ -156,7 +154,8 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { param.addProperty("msgid", msgId); //msgid 消息id顺序从小到大,从1开始 param.addProperty("number", number); //number 每次获取条数,最多10000条 - String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, param.toString()); + String responseContent = this.wxMpService.post(url, param.toString()); + return WxMpKfMsgList.fromJson(responseContent); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImpl.java index c6825815..310bbe78 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImpl.java @@ -50,7 +50,10 @@ public class WxMpMaterialServiceImpl implements WxMpMaterialService { @Override public File mediaDownload(String media_id) throws WxErrorException { String url = MEDIA_API_URL_PREFIX + "/get"; - return this.wxMpService.execute(new MediaDownloadRequestExecutor(this.wxMpService.getWxMpConfigStorage().getTmpDirFile()), url, "media_id=" + media_id); + return this.wxMpService.execute( + new MediaDownloadRequestExecutor(this.wxMpService.getWxMpConfigStorage().getTmpDirFile()), + url, + "media_id=" + media_id); } @Override diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java index 28dbff91..2f40f709 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java @@ -1,9 +1,10 @@ package me.chanjar.weixin.mp.api.impl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import me.chanjar.weixin.common.bean.menu.WxMenu; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; -import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; import me.chanjar.weixin.mp.api.WxMpMenuService; import me.chanjar.weixin.mp.api.WxMpService; @@ -12,6 +13,8 @@ import me.chanjar.weixin.mp.api.WxMpService; */ 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; @@ -21,32 +24,37 @@ public class WxMpMenuServiceImpl implements WxMpMenuService { @Override public void menuCreate(WxMenu menu) throws WxErrorException { + String menuJson = menu.toJson(); + String url = API_URL_PREFIX + "/create"; if (menu.getMatchRule() != null) { - String url = API_URL_PREFIX + "/addconditional"; - this.wxMpService.execute(new SimplePostRequestExecutor(), url, menu.toJson()); - } else { - String url = API_URL_PREFIX + "/create"; - this.wxMpService.execute(new SimplePostRequestExecutor(), url, menu.toJson()); + url = API_URL_PREFIX + "/addconditional"; } + + log.debug("开始创建菜单:{}", menuJson); + + String result = this.wxMpService.post(url, menuJson); + log.debug("创建菜单:{},结果:{}", menuJson, result); } @Override public void menuDelete() throws WxErrorException { String url = API_URL_PREFIX + "/delete"; - this.wxMpService.execute(new SimpleGetRequestExecutor(), url, null); + String result = this.wxMpService.get(url, null); + log.debug("删除菜单结果:{}", result); } @Override public void menuDelete(String menuid) throws WxErrorException { String url = API_URL_PREFIX + "/delconditional"; - this.wxMpService.execute(new SimpleGetRequestExecutor(), url, "menuid=" + menuid); + String result = this.wxMpService.get(url, "menuid=" + menuid); + log.debug("根据MeunId({})删除菜单结果:{}", menuid, result); } @Override public WxMenu menuGet() throws WxErrorException { String url = API_URL_PREFIX + "/get"; try { - String resultContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, null); + String resultContent = this.wxMpService.get(url, null); return WxMenu.fromJson(resultContent); } catch (WxErrorException e) { // 46003 不存在的菜单数据 @@ -61,11 +69,12 @@ public class WxMpMenuServiceImpl implements WxMpMenuService { public WxMenu menuTryMatch(String userid) throws WxErrorException { String url = API_URL_PREFIX + "/trymatch"; try { - String resultContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, "user_id=" + userid); + String resultContent = this.wxMpService.get(url, "user_id=" + userid); return WxMenu.fromJson(resultContent); } catch (WxErrorException e) { // 46003 不存在的菜单数据 46002 不存在的菜单版本 - if (e.getError().getErrorCode() == 46003 || e.getError().getErrorCode() == 46002) { + if (e.getError().getErrorCode() == 46003 + || e.getError().getErrorCode() == 46002) { return null; } throw e; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java index ce7f9517..dcb1e89f 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java @@ -1,28 +1,37 @@ package me.chanjar.weixin.mp.api.impl; +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.SortedMap; +import java.util.TreeMap; + +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.lang3.StringUtils; +import org.joor.Reflect; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.annotations.XStreamAlias; + +import me.chanjar.weixin.common.annotation.Required; import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.common.util.crypto.WxCryptUtil; -import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; import me.chanjar.weixin.common.util.xml.XStreamInitializer; import me.chanjar.weixin.mp.api.WxMpPayService; -import me.chanjar.weixin.mp.bean.result.*; -import org.apache.http.Consts; -import org.apache.http.HttpHost; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.helpers.MessageFormatter; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.pay.WxMpPayCallback; +import me.chanjar.weixin.mp.bean.pay.WxMpPayRefundResult; +import me.chanjar.weixin.mp.bean.pay.WxMpPayResult; +import me.chanjar.weixin.mp.bean.pay.WxRedpackResult; +import me.chanjar.weixin.mp.bean.pay.WxSendRedpackRequest; +import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderRequest; +import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderResult; /** * Created by Binary Wang on 2016/7/28. @@ -31,198 +40,25 @@ import java.util.TreeMap; */ public class WxMpPayServiceImpl implements WxMpPayService { + private static final List
TRADE_TYPES = Lists.newArrayList("JSAPI", + "NATIVE", "APP"); private final Logger log = LoggerFactory.getLogger(WxMpPayServiceImpl.class); - private final String[] REQUIRED_ORDER_PARAMETERS = new String[]{"appid", - "mch_id", "body", "out_trade_no", "total_fee", "spbill_create_ip", - "notify_url", "trade_type"}; - private HttpHost httpProxy; - private WxMpServiceImpl wxMpService; + private WxMpService wxMpService; - public WxMpPayServiceImpl(WxMpServiceImpl wxMpService) { + public WxMpPayServiceImpl(WxMpService wxMpService) { this.wxMpService = wxMpService; - this.httpProxy = wxMpService.getHttpProxy(); - } - - @Override - public WxMpPrepayIdResult getPrepayId(String openId, String outTradeNo, - double amt, String body, String tradeType, String ip, - String callbackUrl) { - Map packageParams = new HashMap<>(); - packageParams.put("appid", - this.wxMpService.getWxMpConfigStorage().getAppId()); - packageParams.put("mch_id", - this.wxMpService.getWxMpConfigStorage().getPartnerId()); - packageParams.put("body", body); - packageParams.put("out_trade_no", outTradeNo); - packageParams.put("total_fee", (int) (amt * 100) + ""); - packageParams.put("spbill_create_ip", ip); - packageParams.put("notify_url", callbackUrl); - packageParams.put("trade_type", tradeType); - packageParams.put("openid", openId); - - return getPrepayId(packageParams); - } - - @Override - public WxMpPrepayIdResult getPrepayId(final Map parameters) { - final SortedMap packageParams = new TreeMap<>(parameters); - packageParams.put("appid", - this.wxMpService.getWxMpConfigStorage().getAppId()); - packageParams.put("mch_id", - this.wxMpService.getWxMpConfigStorage().getPartnerId()); - packageParams.put("nonce_str", System.currentTimeMillis() + ""); - checkParameters(packageParams); - - String sign = WxCryptUtil.createSign(packageParams, - this.wxMpService.getWxMpConfigStorage().getPartnerKey()); - packageParams.put("sign", sign); - - StringBuilder request = new StringBuilder(" "); - for (Map.Entry "); - - HttpPost httpPost = new HttpPost( - "https://api.mch.weixin.qq.com/pay/unifiedorder"); - if (this.httpProxy != null) { - RequestConfig config = RequestConfig.custom().setProxy(this.httpProxy) - .build(); - httpPost.setConfig(config); - } - - StringEntity entity = new StringEntity(request.toString(), Consts.UTF_8); - httpPost.setEntity(entity); - try (CloseableHttpResponse response = this.wxMpService.getHttpclient() - .execute(httpPost)) { - String responseContent = Utf8ResponseHandler.INSTANCE - .handleResponse(response); - XStream xstream = XStreamInitializer.getInstance(); - xstream.alias("xml", WxMpPrepayIdResult.class); - return (WxMpPrepayIdResult) xstream.fromXML(responseContent); - } catch (IOException e) { - throw new RuntimeException("Failed to get prepay id due to IO exception.", - e); - } finally { - httpPost.releaseConnection(); - } - } - - private void checkParameters(Mappara : packageParams.entrySet()) { - request.append(String.format("<%s>%s%s>", para.getKey(), - para.getValue(), para.getKey())); - } - - request.append(" parameters) { - for (String para : this.REQUIRED_ORDER_PARAMETERS) { - if (!parameters.containsKey(para)) { - throw new IllegalArgumentException( - "Reqiured argument '" + para + "' is missing."); - } - } - - if ("JSAPI".equals(parameters.get("trade_type")) - && !parameters.containsKey("openid")) { - throw new IllegalArgumentException( - "Reqiured argument 'openid' is missing when trade_type is 'JSAPI'."); - } - - if ("NATIVE".equals(parameters.get("trade_type")) - && !parameters.containsKey("product_id")) { - throw new IllegalArgumentException( - "Reqiured argument 'product_id' is missing when trade_type is 'NATIVE'."); - } - } - - @Override - public Map getJsapiPayInfo(String openId, String outTradeNo, - double amt, String body, String ip, String callbackUrl) - throws WxErrorException { - Map packageParams = new HashMap<>(); - packageParams.put("appid", - this.wxMpService.getWxMpConfigStorage().getAppId()); - packageParams.put("mch_id", - this.wxMpService.getWxMpConfigStorage().getPartnerId()); - packageParams.put("body", body); - packageParams.put("out_trade_no", outTradeNo); - packageParams.put("total_fee", (int) (amt * 100) + ""); - packageParams.put("spbill_create_ip", ip); - packageParams.put("notify_url", callbackUrl); - packageParams.put("trade_type", "JSAPI"); - packageParams.put("openid", openId); - - return getPayInfo(packageParams); - } - - @Override - public Map getNativePayInfo(String productId, - String outTradeNo, double amt, String body, String ip, String callbackUrl) - throws WxErrorException { - Map packageParams = new HashMap<>(); - packageParams.put("appid", - this.wxMpService.getWxMpConfigStorage().getAppId()); - packageParams.put("mch_id", - this.wxMpService.getWxMpConfigStorage().getPartnerId()); - packageParams.put("body", body); - packageParams.put("out_trade_no", outTradeNo); - packageParams.put("total_fee", (int) (amt * 100) + ""); - packageParams.put("spbill_create_ip", ip); - packageParams.put("notify_url", callbackUrl); - packageParams.put("trade_type", "NATIVE"); - packageParams.put("product_id", productId); - - return getPayInfo(packageParams); - } - - @Override - public Map getPayInfo(Map parameters) - throws WxErrorException { - WxMpPrepayIdResult wxMpPrepayIdResult = getPrepayId(parameters); - - if (!"SUCCESS".equalsIgnoreCase(wxMpPrepayIdResult.getReturn_code()) - || !"SUCCESS".equalsIgnoreCase(wxMpPrepayIdResult.getResult_code())) { - WxError error = new WxError(); - error.setErrorCode(-1); - error.setErrorMsg("return_code:" + wxMpPrepayIdResult.getReturn_code() - + ";return_msg:" + wxMpPrepayIdResult.getReturn_msg() - + ";result_code:" + wxMpPrepayIdResult.getResult_code() + ";err_code" - + wxMpPrepayIdResult.getErr_code() + ";err_code_des" - + wxMpPrepayIdResult.getErr_code_des()); - throw new WxErrorException(error); - } - - String prepayId = wxMpPrepayIdResult.getPrepay_id(); - if (prepayId == null || prepayId.equals("")) { - throw new RuntimeException( - String.format("Failed to get prepay id due to error code '%s'(%s).", - wxMpPrepayIdResult.getErr_code(), - wxMpPrepayIdResult.getErr_code_des())); - } - - Map payInfo = new HashMap<>(); - payInfo.put("appId", this.wxMpService.getWxMpConfigStorage().getAppId()); - // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符 - payInfo.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000)); - payInfo.put("nonceStr", System.currentTimeMillis() + ""); - payInfo.put("package", "prepay_id=" + prepayId); - payInfo.put("signType", "MD5"); - if ("NATIVE".equals(parameters.get("trade_type"))) { - payInfo.put("codeUrl", wxMpPrepayIdResult.getCode_url()); - } - - String finalSign = WxCryptUtil.createSign(payInfo, - this.wxMpService.getWxMpConfigStorage().getPartnerKey()); - payInfo.put("paySign", finalSign); - return payInfo; } @Override public WxMpPayResult getJSSDKPayResult(String transactionId, - String outTradeNo) { + String outTradeNo) throws WxErrorException { String nonce_str = System.currentTimeMillis() + ""; SortedMap packageParams = new TreeMap<>(); packageParams.put("appid", - this.wxMpService.getWxMpConfigStorage().getAppId()); + this.wxMpService.getWxMpConfigStorage().getAppId()); packageParams.put("mch_id", - this.wxMpService.getWxMpConfigStorage().getPartnerId()); + this.wxMpService.getWxMpConfigStorage().getPartnerId()); if (transactionId != null && !"".equals(transactionId.trim())) { packageParams.put("transaction_id", transactionId); @@ -230,41 +66,25 @@ public class WxMpPayServiceImpl implements WxMpPayService { packageParams.put("out_trade_no", outTradeNo); } else { throw new IllegalArgumentException( - "Either 'transactionId' or 'outTradeNo' must be given."); + "Either 'transactionId' or 'outTradeNo' must be given."); } packageParams.put("nonce_str", nonce_str); - packageParams.put("sign", WxCryptUtil.createSign(packageParams, - this.wxMpService.getWxMpConfigStorage().getPartnerKey())); + packageParams.put("sign", this.createSign(packageParams, + this.wxMpService.getWxMpConfigStorage().getPartnerKey())); StringBuilder request = new StringBuilder(" "); for (Map.Entry "); - HttpPost httpPost = new HttpPost( - "https://api.mch.weixin.qq.com/pay/orderquery"); - if (this.httpProxy != null) { - RequestConfig config = RequestConfig.custom().setProxy(this.httpProxy) - .build(); - httpPost.setConfig(config); - } - - StringEntity entity = new StringEntity(request.toString(), Consts.UTF_8); - httpPost.setEntity(entity); - try (CloseableHttpResponse response = this.wxMpService.getHttpclient() - .execute(httpPost)) { - String responseContent = Utf8ResponseHandler.INSTANCE - .handleResponse(response); - XStream xstream = XStreamInitializer.getInstance(); - xstream.alias("xml", WxMpPayResult.class); - return (WxMpPayResult) xstream.fromXML(responseContent); - } catch (IOException e) { - throw new RuntimeException("Failed to query order due to IO exception.", - e); - } + String url = "https://api.mch.weixin.qq.com/pay/orderquery"; + String responseContent = this.wxMpService.post(url, request.toString()); + XStream xstream = XStreamInitializer.getInstance(); + xstream.alias("xml", WxMpPayResult.class); + return (WxMpPayResult) xstream.fromXML(responseContent); } @Override @@ -282,127 +102,237 @@ public class WxMpPayServiceImpl implements WxMpPayService { @Override public WxMpPayRefundResult refundPay(Mappara : packageParams.entrySet()) { request.append(String.format("<%s>%s%s>", para.getKey(), - para.getValue(), para.getKey())); + para.getValue(), para.getKey())); } request.append(" parameters) - throws WxErrorException { + throws WxErrorException { SortedMap refundParams = new TreeMap<>(parameters); refundParams.put("appid", - this.wxMpService.getWxMpConfigStorage().getAppId()); + this.wxMpService.getWxMpConfigStorage().getAppId()); refundParams.put("mch_id", - this.wxMpService.getWxMpConfigStorage().getPartnerId()); + this.wxMpService.getWxMpConfigStorage().getPartnerId()); refundParams.put("nonce_str", System.currentTimeMillis() + ""); refundParams.put("op_user_id", - this.wxMpService.getWxMpConfigStorage().getPartnerId()); - String sign = WxCryptUtil.createSign(refundParams, - this.wxMpService.getWxMpConfigStorage().getPartnerKey()); + this.wxMpService.getWxMpConfigStorage().getPartnerId()); + String sign = this.createSign(refundParams, + this.wxMpService.getWxMpConfigStorage().getPartnerKey()); refundParams.put("sign", sign); StringBuilder request = new StringBuilder(" "); for (Map.Entry "); - HttpPost httpPost = new HttpPost( - "https://api.mch.weixin.qq.com/secapi/pay/refund"); - if (this.httpProxy != null) { - RequestConfig config = RequestConfig.custom().setProxy(this.httpProxy) - .build(); - httpPost.setConfig(config); + String url = "https://api.mch.weixin.qq.com/secapi/pay/refund"; + String responseContent = this.wxMpService.post(url, request.toString()); + XStream xstream = XStreamInitializer.getInstance(); + xstream.processAnnotations(WxMpPayRefundResult.class); + WxMpPayRefundResult wxMpPayRefundResult = (WxMpPayRefundResult) xstream + .fromXML(responseContent); + + if (!"SUCCESS".equalsIgnoreCase(wxMpPayRefundResult.getResultCode()) + || !"SUCCESS".equalsIgnoreCase(wxMpPayRefundResult.getReturnCode())) { + WxError error = new WxError(); + error.setErrorCode(-1); + error.setErrorMsg("return_code:" + wxMpPayRefundResult.getReturnCode() + + ";return_msg:" + wxMpPayRefundResult.getReturnMsg() + + ";result_code:" + wxMpPayRefundResult.getResultCode() + ";err_code" + + wxMpPayRefundResult.getErrCode() + ";err_code_des" + + wxMpPayRefundResult.getErrCodeDes()); + throw new WxErrorException(error); } - StringEntity entity = new StringEntity(request.toString(), Consts.UTF_8); - httpPost.setEntity(entity); - try (CloseableHttpResponse response = this.wxMpService.getHttpclient() - .execute(httpPost)) { - String responseContent = Utf8ResponseHandler.INSTANCE - .handleResponse(response); - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxMpPayRefundResult.class); - WxMpPayRefundResult wxMpPayRefundResult = (WxMpPayRefundResult) xstream - .fromXML(responseContent); - - if (!"SUCCESS".equalsIgnoreCase(wxMpPayRefundResult.getResultCode()) - || !"SUCCESS".equalsIgnoreCase(wxMpPayRefundResult.getReturnCode())) { - WxError error = new WxError(); - error.setErrorCode(-1); - error.setErrorMsg("return_code:" + wxMpPayRefundResult.getReturnCode() - + ";return_msg:" + wxMpPayRefundResult.getReturnMsg() - + ";result_code:" + wxMpPayRefundResult.getResultCode() - + ";err_code" + wxMpPayRefundResult.getErrCode() + ";err_code_des" - + wxMpPayRefundResult.getErrCodeDes()); - throw new WxErrorException(error); + return wxMpPayRefundResult; + } + + @Override + public boolean checkJSSDKCallbackDataSignature(Mappara : refundParams.entrySet()) { request.append(String.format("<%s>%s%s>", para.getKey(), - para.getValue(), para.getKey())); + para.getValue(), para.getKey())); } request.append(" kvm, + String signature) { + return signature.equals(this.createSign(kvm, + this.wxMpService.getWxMpConfigStorage().getPartnerKey())); + } + + @Override + public WxRedpackResult sendRedpack(WxSendRedpackRequest request) + throws WxErrorException { + XStream xstream = XStreamInitializer.getInstance(); + xstream.processAnnotations(WxSendRedpackRequest.class); + xstream.processAnnotations(WxRedpackResult.class); + + request.setWxAppid(this.wxMpService.getWxMpConfigStorage().getAppId()); + request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId()); + request.setNonceStr(System.currentTimeMillis() + ""); + + String sign = this.createSign(xmlBean2Map(request), + this.wxMpService.getWxMpConfigStorage().getPartnerKey()); + request.setSign(sign); + + String url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack"; + if (request.getAmtType() != null) { + //裂变红包 + url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack"; + } + + String responseContent = this.wxMpService.post(url, xstream.toXML(request)); + WxRedpackResult redpackResult = (WxRedpackResult) xstream + .fromXML(responseContent); + if ("FAIL".equals(redpackResult.getResultCode())) { + throw new WxErrorException(WxError.newBuilder() + .setErrorMsg( + redpackResult.getErrCode() + ":" + redpackResult.getErrCodeDes()) + .build()); + } + + return redpackResult; + } + + private Map xmlBean2Map(Object bean) { + Map result = Maps.newHashMap(); + for (Entry entry : Reflect.on(bean).fields().entrySet()) { + Reflect reflect = entry.getValue(); + if (reflect.get() == null) { + continue; + } + + try { + Field field = bean.getClass().getDeclaredField(entry.getKey()); + if (field.isAnnotationPresent(XStreamAlias.class)) { + result.put(field.getAnnotation(XStreamAlias.class).value(), + reflect.get().toString()); + } + } catch (NoSuchFieldException | SecurityException e) { + e.printStackTrace(); } - return wxMpPayRefundResult; - } catch (IOException e) { - String message = MessageFormatter - .format("Exception happened when sending refund '{}'.", - request.toString()) - .getMessage(); - this.log.error(message, e); - throw new WxErrorException( - WxError.newBuilder().setErrorMsg(message).build()); - } finally { - httpPost.releaseConnection(); } + + return result; } - @Override - public boolean checkJSSDKCallbackDataSignature(Map kvm, - String signature) { - return signature.equals(WxCryptUtil.createSign(kvm, - this.wxMpService.getWxMpConfigStorage().getPartnerKey())); + /** + * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) + * @param packageParams 原始参数 + * @param signKey 加密Key(即 商户Key) + * @return 签名字符串 + */ + private String createSign(Map packageParams, String signKey) { + SortedMap sortedMap = new TreeMap<>(packageParams); + + StringBuffer toSign = new StringBuffer(); + for (String key : sortedMap.keySet()) { + String value = packageParams.get(key); + if (null != value && !"".equals(value) && !"sign".equals(key) + && !"key".equals(key)) { + toSign.append(key + "=" + value + "&"); + } + } + + toSign.append("key=" + signKey); + + return DigestUtils.md5Hex(toSign.toString()).toUpperCase(); } @Override - public WxRedpackResult sendRedpack(Map parameters) - throws WxErrorException { - SortedMap packageParams = new TreeMap<>(parameters); - packageParams.put("wxappid", - this.wxMpService.getWxMpConfigStorage().getAppId()); - packageParams.put("mch_id", - this.wxMpService.getWxMpConfigStorage().getPartnerId()); - packageParams.put("nonce_str", System.currentTimeMillis() + ""); + public WxUnifiedOrderResult unifiedOrder(WxUnifiedOrderRequest request) + throws WxErrorException { + checkParameters(request); + + XStream xstream = XStreamInitializer.getInstance(); + xstream.processAnnotations(WxUnifiedOrderRequest.class); + xstream.processAnnotations(WxUnifiedOrderResult.class); + + request.setAppid(this.wxMpService.getWxMpConfigStorage().getAppId()); + request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId()); + request.setNonceStr(System.currentTimeMillis() + ""); + + String sign = this.createSign(xmlBean2Map(request), + this.wxMpService.getWxMpConfigStorage().getPartnerKey()); + request.setSign(sign); + + String url = "https://api.mch.weixin.qq.com/pay/unifiedorder"; + + String responseContent = this.wxMpService.post(url, xstream.toXML(request)); + WxUnifiedOrderResult result = (WxUnifiedOrderResult) xstream + .fromXML(responseContent); + if ("FAIL".equals(result.getResultCode())) { + throw new WxErrorException(WxError.newBuilder() + .setErrorMsg(result.getErrCode() + ":" + result.getErrCodeDes()) + .build()); + } - String sign = WxCryptUtil.createSign(packageParams, - this.wxMpService.getWxMpConfigStorage().getPartnerKey()); - packageParams.put("sign", sign); + return result; - StringBuilder request = new StringBuilder(" "); - for (Map.Entry "); + if (!nullFields.isEmpty()) { + throw new IllegalArgumentException("必填字段[" + nullFields + "]必须提供值"); + } + + if (!TRADE_TYPES.contains(request.getTradeType())) { + throw new IllegalArgumentException( + "trade_type目前必须为" + TRADE_TYPES + "其中之一"); - HttpPost httpPost = new HttpPost( - "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack"); - if (this.httpProxy != null) { - RequestConfig config = RequestConfig.custom().setProxy(this.httpProxy) - .build(); - httpPost.setConfig(config); } - StringEntity entity = new StringEntity(request.toString(), Consts.UTF_8); - httpPost.setEntity(entity); - try (CloseableHttpResponse response = this.wxMpService.getHttpclient() - .execute(httpPost)) { - String responseContent = Utf8ResponseHandler.INSTANCE - .handleResponse(response); - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxRedpackResult.class); - return (WxRedpackResult) xstream.fromXML(responseContent); - } catch (IOException e) { - String message = MessageFormatter - .format("Exception occured when sending redpack '{}'.", - request.toString()) - .getMessage(); - this.log.error(message, e); - throw new WxErrorException(WxError.newBuilder().setErrorMsg(message).build()); - } finally { - httpPost.releaseConnection(); + if ("JSAPI".equals(request.getTradeType()) && request.getOpenid() == null) { + throw new IllegalArgumentException("当 trade_type是'JSAPI'时未指定openid"); + } + + if ("NATIVE".equals(request.getTradeType()) + && request.getProductId() == null) { + throw new IllegalArgumentException("当 trade_type是'NATIVE'时未指定product_id"); } } + @Override + public Mappara : packageParams.entrySet()) { - request.append(String.format("<%s>%s%s>", para.getKey(), - para.getValue(), para.getKey())); + } + + private void checkParameters(WxUnifiedOrderRequest request) { + + List nullFields = Lists.newArrayList(); + for (Entry entry : Reflect.on(request).fields() + .entrySet()) { + Reflect reflect = entry.getValue(); + try { + Field field = request.getClass().getDeclaredField(entry.getKey()); + if (field.isAnnotationPresent(Required.class) + && reflect.get() == null) { + nullFields.add(entry.getKey()); + } + } catch (NoSuchFieldException | SecurityException e) { + e.printStackTrace(); + } } - request.append(" getPayInfo(WxUnifiedOrderRequest request) throws WxErrorException { + WxUnifiedOrderResult unifiedOrderResult = this.unifiedOrder(request); + + if (!"SUCCESS".equalsIgnoreCase(unifiedOrderResult.getReturnCode()) + || !"SUCCESS".equalsIgnoreCase(unifiedOrderResult.getResultCode())) { + throw new WxErrorException(WxError.newBuilder().setErrorCode(-1) + .setErrorMsg("return_code:" + unifiedOrderResult.getReturnCode() + ";return_msg:" + + unifiedOrderResult.getReturnMsg() + ";result_code:" + unifiedOrderResult.getResultCode() + ";err_code" + + unifiedOrderResult.getErrCode() + ";err_code_des" + unifiedOrderResult.getErrCodeDes()) + .build()); + } + + String prepayId = unifiedOrderResult.getPrepayId(); + if (StringUtils.isBlank(prepayId)) { + throw new RuntimeException(String.format("Failed to get prepay id due to error code '%s'(%s).", + unifiedOrderResult.getErrCode(), unifiedOrderResult.getErrCodeDes())); + } + + Map payInfo = new HashMap<>(); + payInfo.put("appId", this.wxMpService.getWxMpConfigStorage().getAppId()); + // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符 + payInfo.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000)); + payInfo.put("nonceStr", System.currentTimeMillis() + ""); + payInfo.put("package", "prepay_id=" + prepayId); + payInfo.put("signType", "MD5"); + if ("NATIVE".equals(request.getTradeType())) { + payInfo.put("codeUrl", unifiedOrderResult.getCodeURL()); + } + + String finalSign = this.createSign(payInfo, this.wxMpService.getWxMpConfigStorage().getPartnerKey()); + payInfo.put("paySign", finalSign); + return payInfo; + } + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java index b3f52ed8..1a7ffe84 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java @@ -1,9 +1,23 @@ package me.chanjar.weixin.mp.api.impl; +import java.io.IOException; + +import org.apache.http.HttpHost; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.conn.ssl.DefaultHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.BasicResponseHandler; +import org.apache.http.impl.client.CloseableHttpClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; + import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.bean.WxJsapiSignature; import me.chanjar.weixin.common.bean.result.WxError; @@ -12,23 +26,38 @@ import me.chanjar.weixin.common.session.StandardSessionManager; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.common.util.RandomUtils; import me.chanjar.weixin.common.util.crypto.SHA1; -import me.chanjar.weixin.common.util.http.*; -import me.chanjar.weixin.mp.api.*; -import me.chanjar.weixin.mp.bean.*; -import me.chanjar.weixin.mp.bean.result.*; -import org.apache.http.HttpHost; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.conn.ssl.DefaultHostnameVerifier; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.impl.client.BasicResponseHandler; -import org.apache.http.impl.client.CloseableHttpClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.security.NoSuchAlgorithmException; +import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder; +import me.chanjar.weixin.common.util.http.DefaultApacheHttpClientBuilder; +import me.chanjar.weixin.common.util.http.RequestExecutor; +import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; +import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; +import me.chanjar.weixin.common.util.http.URIUtil; +import me.chanjar.weixin.mp.api.WxMpCardService; +import me.chanjar.weixin.mp.api.WxMpConfigStorage; +import me.chanjar.weixin.mp.api.WxMpDataCubeService; +import me.chanjar.weixin.mp.api.WxMpKefuService; +import me.chanjar.weixin.mp.api.WxMpMaterialService; +import me.chanjar.weixin.mp.api.WxMpMenuService; +import me.chanjar.weixin.mp.api.WxMpPayService; +import me.chanjar.weixin.mp.api.WxMpQrcodeService; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.WxMpStoreService; +import me.chanjar.weixin.mp.api.WxMpUserBlacklistService; +import me.chanjar.weixin.mp.api.WxMpUserService; +import me.chanjar.weixin.mp.api.WxMpUserTagService; +import me.chanjar.weixin.mp.bean.WxMpIndustry; +import me.chanjar.weixin.mp.bean.WxMpMassNews; +import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; +import me.chanjar.weixin.mp.bean.WxMpMassPreviewMessage; +import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; +import me.chanjar.weixin.mp.bean.WxMpMassVideo; +import me.chanjar.weixin.mp.bean.WxMpSemanticQuery; +import me.chanjar.weixin.mp.bean.WxMpTemplateMessage; +import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; +import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; +import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; +import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; +import me.chanjar.weixin.mp.bean.result.WxMpUser; public class WxMpServiceImpl implements WxMpService { @@ -46,8 +75,8 @@ public class WxMpServiceImpl implements WxMpService { */ private final Object globalJsapiTicketRefreshLock = new Object(); - private WxMpConfigStorage wxMpConfigStorage; - + private WxMpConfigStorage configStorage; + private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this); private WxMpMaterialService materialService = new WxMpMaterialServiceImpl(this); @@ -56,7 +85,7 @@ public class WxMpServiceImpl implements WxMpService { private WxMpUserService userService = new WxMpUserServiceImpl(this); - private WxMpGroupService groupService = new WxMpGroupServiceImpl(this); + private WxMpUserTagService tagService = new WxMpUserTagServiceImpl(this); private WxMpQrcodeService qrCodeService = new WxMpQrcodeServiceImpl(this); @@ -64,8 +93,12 @@ public class WxMpServiceImpl implements WxMpService { private WxMpPayService payService = new WxMpPayServiceImpl(this); + private WxMpStoreService storeService = new WxMpStoreServiceImpl(this); + private WxMpDataCubeService dataCubeService = new WxMpDataCubeServiceImpl(this); + private WxMpUserBlacklistService blackListService = new WxMpUserBlacklistServiceImpl(this); + private CloseableHttpClient httpClient; private HttpHost httpProxy; @@ -79,7 +112,8 @@ public class WxMpServiceImpl implements WxMpService { @Override public boolean checkSignature(String timestamp, String nonce, String signature) { try { - return SHA1.gen(this.wxMpConfigStorage.getToken(), timestamp, nonce).equals(signature); + return SHA1.gen(this.configStorage.getToken(), timestamp, nonce) + .equals(signature); } catch (Exception e) { return false; } @@ -93,14 +127,14 @@ public class WxMpServiceImpl implements WxMpService { @Override public String getAccessToken(boolean forceRefresh) throws WxErrorException { if (forceRefresh) { - this.wxMpConfigStorage.expireAccessToken(); + this.configStorage.expireAccessToken(); } - if (this.wxMpConfigStorage.isAccessTokenExpired()) { + if (this.configStorage.isAccessTokenExpired()) { synchronized (this.globalAccessTokenRefreshLock) { - if (this.wxMpConfigStorage.isAccessTokenExpired()) { + if (this.configStorage.isAccessTokenExpired()) { String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential" + - "&appid=" + this.wxMpConfigStorage.getAppId() + - "&secret=" + this.wxMpConfigStorage.getSecret(); + "&appid=" + this.configStorage.getAppId() + "&secret=" + + this.configStorage.getSecret(); try { HttpGet httpGet = new HttpGet(url); if (this.httpProxy != null) { @@ -114,7 +148,8 @@ public class WxMpServiceImpl implements WxMpService { throw new WxErrorException(error); } WxAccessToken accessToken = WxAccessToken.fromJson(resultContent); - this.wxMpConfigStorage.updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn()); + this.configStorage.updateAccessToken(accessToken.getAccessToken(), + accessToken.getExpiresIn()); }finally { httpGet.releaseConnection(); } @@ -124,7 +159,7 @@ public class WxMpServiceImpl implements WxMpService { } } } - return this.wxMpConfigStorage.getAccessToken(); + return this.configStorage.getAccessToken(); } @Override @@ -135,23 +170,23 @@ public class WxMpServiceImpl implements WxMpService { @Override public String getJsapiTicket(boolean forceRefresh) throws WxErrorException { if (forceRefresh) { - this.wxMpConfigStorage.expireJsapiTicket(); + this.configStorage.expireJsapiTicket(); } - if (this.wxMpConfigStorage.isJsapiTicketExpired()) { + if (this.configStorage.isJsapiTicketExpired()) { synchronized (this.globalJsapiTicketRefreshLock) { - if (this.wxMpConfigStorage.isJsapiTicketExpired()) { + if (this.configStorage.isJsapiTicketExpired()) { String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi"; String responseContent = execute(new SimpleGetRequestExecutor(), url, null); JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent); JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject(); String jsapiTicket = tmpJsonObject.get("ticket").getAsString(); int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt(); - this.wxMpConfigStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds); + this.configStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds); } } } - return this.wxMpConfigStorage.getJsapiTicket(); + return this.configStorage.getJsapiTicket(); } @Override @@ -159,63 +194,49 @@ public class WxMpServiceImpl implements WxMpService { long timestamp = System.currentTimeMillis() / 1000; String noncestr = RandomUtils.getRandomStr(); String jsapiTicket = getJsapiTicket(false); - try { - String signature = SHA1.genWithAmple( - "jsapi_ticket=" + jsapiTicket, - "noncestr=" + noncestr, - "timestamp=" + timestamp, - "url=" + url - ); - WxJsapiSignature jsapiSignature = new WxJsapiSignature(); - jsapiSignature.setAppid(this.wxMpConfigStorage.getAppId()); - jsapiSignature.setTimestamp(timestamp); - jsapiSignature.setNoncestr(noncestr); - jsapiSignature.setUrl(url); - jsapiSignature.setSignature(signature); - return jsapiSignature; - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } - } - - @Override - public void customMessageSend(WxMpCustomMessage message) throws WxErrorException { - String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send"; - execute(new SimplePostRequestExecutor(), url, message.toJson()); + String signature = SHA1.genWithAmple("jsapi_ticket=" + jsapiTicket, + "noncestr=" + noncestr, "timestamp=" + timestamp, "url=" + url); + WxJsapiSignature jsapiSignature = new WxJsapiSignature(); + jsapiSignature.setAppid(this.configStorage.getAppId()); + jsapiSignature.setTimestamp(timestamp); + jsapiSignature.setNoncestr(noncestr); + jsapiSignature.setUrl(url); + jsapiSignature.setSignature(signature); + return jsapiSignature; } @Override public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException { String url = "https://api.weixin.qq.com/cgi-bin/media/uploadnews"; - String responseContent = execute(new SimplePostRequestExecutor(), url, news.toJson()); + String responseContent = this.post(url, news.toJson()); return WxMpMassUploadResult.fromJson(responseContent); } @Override public WxMpMassUploadResult massVideoUpload(WxMpMassVideo video) throws WxErrorException { String url = "https://api.weixin.qq.com/cgi-bin/media/uploadvideo"; - String responseContent = execute(new SimplePostRequestExecutor(), url, video.toJson()); + String responseContent = this.post(url, video.toJson()); return WxMpMassUploadResult.fromJson(responseContent); } @Override - public WxMpMassSendResult massGroupMessageSend(WxMpMassGroupMessage message) throws WxErrorException { + public WxMpMassSendResult massGroupMessageSend(WxMpMassTagMessage message) throws WxErrorException { String url = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall"; - String responseContent = execute(new SimplePostRequestExecutor(), url, message.toJson()); + String responseContent = this.post(url, message.toJson()); return WxMpMassSendResult.fromJson(responseContent); } @Override public WxMpMassSendResult massOpenIdsMessageSend(WxMpMassOpenIdsMessage message) throws WxErrorException { String url = "https://api.weixin.qq.com/cgi-bin/message/mass/send"; - String responseContent = execute(new SimplePostRequestExecutor(), url, message.toJson()); + String responseContent = this.post(url, message.toJson()); return WxMpMassSendResult.fromJson(responseContent); } @Override public WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage) throws Exception { String url = "https://api.weixin.qq.com/cgi-bin/message/mass/preview"; - String responseContent = execute(new SimplePostRequestExecutor(), url, wxMpMassPreviewMessage.toJson()); + String responseContent = this.post(url, wxMpMassPreviewMessage.toJson()); return WxMpMassSendResult.fromJson(responseContent); } @@ -225,7 +246,7 @@ public class WxMpServiceImpl implements WxMpService { JsonObject o = new JsonObject(); o.addProperty("action", "long2short"); o.addProperty("long_url", long_url); - String responseContent = execute(new SimplePostRequestExecutor(), url, o.toString()); + String responseContent = this.post(url, o.toString()); JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent); return tmpJsonElement.getAsJsonObject().get("short_url").getAsString(); } @@ -233,9 +254,8 @@ public class WxMpServiceImpl implements WxMpService { @Override public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException { String url = "https://api.weixin.qq.com/cgi-bin/message/template/send"; - String responseContent = execute(new SimplePostRequestExecutor(), url, templateMessage.toJson()); - JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent); - final JsonObject jsonObject = tmpJsonElement.getAsJsonObject(); + String responseContent = this.post(url, templateMessage.toJson()); + final JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject(); if (jsonObject.get("errcode").getAsInt() == 0){ return jsonObject.get("msgid").getAsString(); } @@ -250,20 +270,20 @@ public class WxMpServiceImpl implements WxMpService { throw new IllegalArgumentException("industry id is empty"); } String url = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry"; - return execute(new SimplePostRequestExecutor(), url, wxMpIndustry.toJson()); + return this.post(url, wxMpIndustry.toJson()); } @Override public WxMpIndustry getIndustry() throws WxErrorException { String url = "https://api.weixin.qq.com/cgi-bin/template/get_industry"; - String responseContent = execute(new SimpleGetRequestExecutor(), url, null); + String responseContent = this.get(url, null); return WxMpIndustry.fromJson(responseContent); } @Override public WxMpSemanticQueryResult semanticQuery(WxMpSemanticQuery semanticQuery) throws WxErrorException { String url = "https://api.weixin.qq.com/semantic/semproxy/search"; - String responseContent = execute(new SimplePostRequestExecutor(), url, semanticQuery.toJson()); + String responseContent = this.post(url, semanticQuery.toJson()); return WxMpSemanticQueryResult.fromJson(responseContent); } @@ -271,7 +291,7 @@ public class WxMpServiceImpl implements WxMpService { public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state) { StringBuilder url = new StringBuilder(); url.append("https://open.weixin.qq.com/connect/oauth2/authorize?"); - url.append("appid=").append(this.wxMpConfigStorage.getAppId()); + url.append("appid=").append(this.configStorage.getAppId()); url.append("&redirect_uri=").append(URIUtil.encodeURIComponent(redirectURI)); url.append("&response_type=code"); url.append("&scope=").append(scope); @@ -287,14 +307,14 @@ public class WxMpServiceImpl implements WxMpService { String state) { StringBuilder url = new StringBuilder(); url.append("https://open.weixin.qq.com/connect/qrconnect?"); - url.append("appid=").append(this.wxMpConfigStorage.getAppId()); + url.append("appid=").append(this.configStorage.getAppId()); url.append("&redirect_uri=").append(URIUtil.encodeURIComponent(redirectURI)); url.append("&response_type=code"); url.append("&scope=").append(scope); if (state != null) { url.append("&state=").append(state); } - + url.append("#wechat_redirect"); return url.toString(); } @@ -313,8 +333,8 @@ public class WxMpServiceImpl implements WxMpService { public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException { StringBuilder url = new StringBuilder(); url.append("https://api.weixin.qq.com/sns/oauth2/access_token?"); - url.append("appid=").append(this.wxMpConfigStorage.getAppId()); - url.append("&secret=").append(this.wxMpConfigStorage.getSecret()); + url.append("appid=").append(this.configStorage.getAppId()); + url.append("&secret=").append(this.configStorage.getSecret()); url.append("&code=").append(code); url.append("&grant_type=authorization_code"); @@ -325,7 +345,7 @@ public class WxMpServiceImpl implements WxMpService { public WxMpOAuth2AccessToken oauth2refreshAccessToken(String refreshToken) throws WxErrorException { StringBuilder url = new StringBuilder(); url.append("https://api.weixin.qq.com/sns/oauth2/refresh_token?"); - url.append("appid=").append(this.wxMpConfigStorage.getAppId()); + url.append("appid=").append(this.configStorage.getAppId()); url.append("&grant_type=refresh_token"); url.append("&refresh_token=").append(refreshToken); @@ -402,7 +422,9 @@ public class WxMpServiceImpl implements WxMpService { int retryTimes = 0; do { try { - return executeInternal(executor, uri, data); + T result = executeInternal(executor, uri, data); + this.log.debug("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}",uri, data, result); + return result; } catch (WxErrorException e) { WxError error = e.getError(); /** @@ -445,10 +467,12 @@ public class WxMpServiceImpl implements WxMpService { */ if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001) { // 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token - this.wxMpConfigStorage.expireAccessToken(); - return execute(executor, uri, data); + this.configStorage.expireAccessToken(); + return this.execute(executor, uri, data); } if (error.getErrorCode() != 0) { + this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", uri, data, + error); throw new WxErrorException(error); } return null; @@ -456,7 +480,7 @@ public class WxMpServiceImpl implements WxMpService { throw new RuntimeException(e); } } - + public HttpHost getHttpProxy() { return this.httpProxy; } @@ -467,33 +491,39 @@ public class WxMpServiceImpl implements WxMpService { @Override public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider) { - this.wxMpConfigStorage = wxConfigProvider; + this.configStorage = wxConfigProvider; this.initHttpClient(); } private void initHttpClient() { - ApacheHttpClientBuilder apacheHttpClientBuilder = this.wxMpConfigStorage.getApacheHttpClientBuilder(); + ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage + .getApacheHttpClientBuilder(); if (null == apacheHttpClientBuilder) { apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get(); } - - apacheHttpClientBuilder.httpProxyHost(this.wxMpConfigStorage.getHttpProxyHost()) - .httpProxyPort(this.wxMpConfigStorage.getHttpProxyPort()) - .httpProxyUsername(this.wxMpConfigStorage.getHttpProxyUsername()) - .httpProxyPassword(this.wxMpConfigStorage.getHttpProxyPassword()); - if (this.wxMpConfigStorage.getSSLContext() != null){ + apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost()) + .httpProxyPort(this.configStorage.getHttpProxyPort()) + .httpProxyUsername(this.configStorage.getHttpProxyUsername()) + .httpProxyPassword(this.configStorage.getHttpProxyPassword()); + + if (this.configStorage.getSSLContext() != null) { SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( - this.wxMpConfigStorage.getSSLContext(), new String[] { "TLSv1" }, null, new DefaultHostnameVerifier()); + this.configStorage.getSSLContext(), new String[] { "TLSv1" }, null, + new DefaultHostnameVerifier()); apacheHttpClientBuilder.sslConnectionSocketFactory(sslsf); } + if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) { + this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), this.configStorage.getHttpProxyPort()); + } + this.httpClient = apacheHttpClientBuilder.build(); } @Override public WxMpConfigStorage getWxMpConfigStorage() { - return this.wxMpConfigStorage; + return this.configStorage; } @Override @@ -527,8 +557,8 @@ public class WxMpServiceImpl implements WxMpService { } @Override - public WxMpGroupService getGroupService() { - return this.groupService; + public WxMpUserTagService getUserTagService() { + return this.tagService; } @Override @@ -551,4 +581,14 @@ public class WxMpServiceImpl implements WxMpService { return this.dataCubeService; } + @Override + public WxMpUserBlacklistService getBlackListService() { + return this.blackListService; + } + + @Override + public WxMpStoreService getStoreService() { + return this.storeService; + } + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java new file mode 100644 index 00000000..39c7f729 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java @@ -0,0 +1,158 @@ +package me.chanjar.weixin.mp.api.impl; + +import com.google.common.collect.Lists; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; +import me.chanjar.weixin.common.annotation.Required; +import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.WxMpStoreService; +import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo; +import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo; +import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult; +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; +import org.joor.Reflect; + +import java.lang.reflect.Field; +import java.util.List; +import java.util.Map.Entry; + +/** + * Created by Binary Wang on 2016/9/26. + * @author binarywang (https://github.com/binarywang) + * + */ +public class WxMpStoreServiceImpl implements WxMpStoreService { + private static final String API_BASE_URL = "http://api.weixin.qq.com/cgi-bin/poi"; + + private WxMpService wxMpService; + + public WxMpStoreServiceImpl(WxMpService wxMpService) { + this.wxMpService = wxMpService; + } + + @Override + public void add(WxMpStoreBaseInfo request) throws WxErrorException { + checkParameters(request); + + String url = API_BASE_URL + "/addpoi"; + String response = this.wxMpService.post(url, request.toJson()); + WxError wxError = WxError.fromJson(response); + if (wxError.getErrorCode() != 0) { + throw new WxErrorException(wxError); + } + } + + @Override + public WxMpStoreBaseInfo get(String poiId) throws WxErrorException { + String url = API_BASE_URL + "/getpoi"; + JsonObject paramObject = new JsonObject(); + paramObject.addProperty("poi_id",poiId); + String response = this.wxMpService.post(url, paramObject.toString()); + WxError wxError = WxError.fromJson(response); + if (wxError.getErrorCode() != 0) { + throw new WxErrorException(wxError); + } + return WxMpStoreBaseInfo.fromJson(new JsonParser().parse(response).getAsJsonObject() + .get("business").getAsJsonObject().get("base_info").toString()); + } + + @Override + public void delete(String poiId) throws WxErrorException { + String url = API_BASE_URL + "/delpoi"; + JsonObject paramObject = new JsonObject(); + paramObject.addProperty("poi_id",poiId); + String response = this.wxMpService.post(url, paramObject.toString()); + WxError wxError = WxError.fromJson(response); + if (wxError.getErrorCode() != 0) { + throw new WxErrorException(wxError); + } + } + + private void checkParameters(WxMpStoreBaseInfo request) { + List nullFields = Lists.newArrayList(); + for (Entry entry : Reflect.on(request).fields() + .entrySet()) { + Reflect reflect = entry.getValue(); + try { + Field field = request.getClass().getDeclaredField(entry.getKey()); + if (field.isAnnotationPresent(Required.class) + && reflect.get() == null) { + nullFields.add(entry.getKey()); + } + } catch (NoSuchFieldException | SecurityException e) { + e.printStackTrace(); + } + } + + if (!nullFields.isEmpty()) { + throw new IllegalArgumentException("必填字段[" + nullFields + "]必须提供值"); + } + + } + + @Override + public WxMpStoreListResult list(int begin, int limit) + throws WxErrorException { + String url = API_BASE_URL + "/getpoilist"; + JsonObject params = new JsonObject(); + params.addProperty("begin", begin); + params.addProperty("limit", limit); + String response = this.wxMpService.post(url, params.toString()); + + WxError wxError = WxError.fromJson(response); + if (wxError.getErrorCode() != 0) { + throw new WxErrorException(wxError); + } + + return WxMpStoreListResult.fromJson(response); + } + + @Override + public List listAll() throws WxErrorException { + int limit = 50; + WxMpStoreListResult list = this.list(0, limit); + List stores = list.getBusinessList(); + if (list.getTotalCount() > limit) { + int begin = limit; + WxMpStoreListResult followingList = this.list(begin, limit); + while (followingList.getBusinessList().size() > 0) { + stores.addAll(followingList.getBusinessList()); + begin += limit; + if (begin >= list.getTotalCount()) { + break; + } + followingList = this.list(begin, limit); + } + } + + return stores; + } + + @Override + public void update(WxMpStoreBaseInfo request) throws WxErrorException { + String url = API_BASE_URL + "/updatepoi"; + String response = this.wxMpService.post(url, request.toJson()); + WxError wxError = WxError.fromJson(response); + if (wxError.getErrorCode() != 0) { + throw new WxErrorException(wxError); + } + } + + @Override + public List listCategories() throws WxErrorException { + String url = API_BASE_URL + "/getwxcategory"; + String response = this.wxMpService.get(url, null); + WxError wxError = WxError.fromJson(response); + if (wxError.getErrorCode() != 0) { + throw new WxErrorException(wxError); + } + + return WxMpGsonBuilder.create().fromJson( + new JsonParser().parse(response).getAsJsonObject().get("category_list"), + new TypeToken >(){}.getType()); + } + +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImpl.java new file mode 100644 index 00000000..b0b35343 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImpl.java @@ -0,0 +1,50 @@ +package me.chanjar.weixin.mp.api.impl; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.WxMpUserBlacklistService; +import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author miller + */ +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; + } + + @Override + public WxMpUserBlacklistGetResult getBlacklist(String nextOpenid) throws WxErrorException { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("begin_openid", nextOpenid); + String url = API_BLACKLIST_PREFIX + "/getblacklist"; + String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, jsonObject.toString()); + return WxMpUserBlacklistGetResult.fromJson(responseContent); + } + + @Override + public void pushToBlacklist(List
openidList) throws WxErrorException { + Map map = new HashMap<>(); + map.put("openid_list", openidList); + String url = API_BLACKLIST_PREFIX + "/batchblacklist"; + this.wxMpService.execute(new SimplePostRequestExecutor(), url, new Gson().toJson(map)); + } + + @Override + public void pullFromBlacklist(List openidList) throws WxErrorException { + Map map = new HashMap<>(); + map.put("openid_list", openidList); + String url = API_BLACKLIST_PREFIX + "/batchunblacklist"; + this.wxMpService.execute(new SimplePostRequestExecutor(), url, new Gson().toJson(map)); + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java index 995eb58a..9267407c 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java @@ -5,8 +5,6 @@ import java.util.List; import com.google.gson.JsonObject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; -import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpUserService; import me.chanjar.weixin.mp.bean.WxMpUserQuery; @@ -30,33 +28,37 @@ public class WxMpUserServiceImpl implements WxMpUserService { JsonObject json = new JsonObject(); json.addProperty("openid", openid); json.addProperty("remark", remark); - this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString()); + this.wxMpService.post(url, json.toString()); } @Override public WxMpUser userInfo(String openid, String lang) throws WxErrorException { String url = API_URL_PREFIX + "/info"; lang = lang == null ? "zh_CN" : lang; - String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, "openid=" + openid + "&lang=" + lang); + String responseContent = this.wxMpService.get(url, + "openid=" + openid + "&lang=" + lang); return WxMpUser.fromJson(responseContent); } @Override public WxMpUserList userList(String next_openid) throws WxErrorException { String url = API_URL_PREFIX + "/get"; - String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, next_openid == null ? null : "next_openid=" + next_openid); + String responseContent = this.wxMpService.get(url, + next_openid == null ? null : "next_openid=" + next_openid); return WxMpUserList.fromJson(responseContent); } @Override - public List userInfoList(List openidList) throws WxErrorException { - return userInfoList(new WxMpUserQuery(openidList)); + public List userInfoList(List openids) + throws WxErrorException { + return this.userInfoList(new WxMpUserQuery(openids)); } @Override public List userInfoList(WxMpUserQuery userQuery) throws WxErrorException { String url = API_URL_PREFIX + "/info/batchget"; - String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, userQuery.toJsonString()); + String responseContent = this.wxMpService.post(url, + userQuery.toJsonString()); return WxMpUser.fromJsonList(responseContent); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java new file mode 100644 index 00000000..4d3639c8 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java @@ -0,0 +1,160 @@ +package me.chanjar.weixin.mp.api.impl; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; +import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.WxMpUserTagService; +import me.chanjar.weixin.mp.bean.tag.WxTagListUser; +import me.chanjar.weixin.mp.bean.tag.WxUserTag; +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; +import org.apache.commons.lang3.StringUtils; + +import java.util.List; + +/** + * + * @author binarywang(https://github.com/binarywang) + * Created by Binary Wang on 2016/9/2. + */ +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; + } + + @Override + public WxUserTag tagCreate(String name) throws WxErrorException { + String url = API_URL_PREFIX + "/create"; + JsonObject json = new JsonObject(); + JsonObject tagJson = new JsonObject(); + tagJson.addProperty("name", name); + json.add("tag", tagJson); + + String responseContent = this.wxMpService.post(url, json.toString()); + return WxUserTag.fromJson(responseContent); + } + + @Override + public List tagGet() throws WxErrorException { + String url = API_URL_PREFIX + "/get"; + + String responseContent = this.wxMpService.get(url, null); + return WxUserTag.listFromJson(responseContent); + } + + @Override + public Boolean tagUpdate(Long id, String name) throws WxErrorException { + String url = API_URL_PREFIX + "/update"; + + JsonObject json = new JsonObject(); + JsonObject tagJson = new JsonObject(); + tagJson.addProperty("id", id); + tagJson.addProperty("name", name); + json.add("tag", tagJson); + + String responseContent = this.wxMpService.post(url, json.toString()); + WxError wxError = WxError.fromJson(responseContent); + if (wxError.getErrorCode() == 0) { + return true; + } + + throw new WxErrorException(wxError); + } + + @Override + public Boolean tagDelete(Long id) throws WxErrorException { + String url = API_URL_PREFIX + "/delete"; + + JsonObject json = new JsonObject(); + JsonObject tagJson = new JsonObject(); + tagJson.addProperty("id", id); + json.add("tag", tagJson); + + String responseContent = this.wxMpService.post(url, json.toString()); + WxError wxError = WxError.fromJson(responseContent); + if (wxError.getErrorCode() == 0) { + return true; + } + + throw new WxErrorException(wxError); + } + + @Override + public WxTagListUser tagListUser(Long tagId, String nextOpenid) + throws WxErrorException { + String url = "https://api.weixin.qq.com/cgi-bin/user/tag/get"; + + JsonObject json = new JsonObject(); + json.addProperty("tagid", tagId); + json.addProperty("next_openid", StringUtils.trimToEmpty(nextOpenid)); + + String responseContent = this.wxMpService.post(url, json.toString()); + return WxTagListUser.fromJson(responseContent); + } + + @Override + public boolean batchTagging(Long tagId, String[] openids) + throws WxErrorException { + String url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging"; + + JsonObject json = new JsonObject(); + json.addProperty("tagid", tagId); + JsonArray openidArrayJson = new JsonArray(); + for (String openid : openids) { + openidArrayJson.add(openid); + } + json.add("openid_list", openidArrayJson); + + String responseContent = this.wxMpService.post(url, json.toString()); + WxError wxError = WxError.fromJson(responseContent); + if (wxError.getErrorCode() == 0) { + return true; + } + + throw new WxErrorException(wxError); + } + + @Override + public boolean batchUntagging(Long tagId, String[] openids) + throws WxErrorException { + String url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging"; + + JsonObject json = new JsonObject(); + json.addProperty("tagid", tagId); + JsonArray openidArrayJson = new JsonArray(); + for (String openid : openids) { + openidArrayJson.add(openid); + } + json.add("openid_list", openidArrayJson); + + String responseContent = this.wxMpService.post(url, json.toString()); + WxError wxError = WxError.fromJson(responseContent); + if (wxError.getErrorCode() == 0) { + return true; + } + + throw new WxErrorException(wxError); + } + + @Override + public List userTagList(String openid) throws WxErrorException { + String url = "https://api.weixin.qq.com/cgi-bin/tags/getidlist"; + + JsonObject json = new JsonObject(); + json.addProperty("openid", openid); + + String responseContent = this.wxMpService.post(url, json.toString()); + + return WxMpGsonBuilder.create().fromJson( + new JsonParser().parse(responseContent).getAsJsonObject().get("tagid_list"), + new TypeToken >() { + }.getType()); + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCustomMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCustomMessage.java index 04eee332..a7f1670f 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCustomMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCustomMessage.java @@ -1,12 +1,18 @@ package me.chanjar.weixin.mp.bean; -import me.chanjar.weixin.mp.bean.custombuilder.*; -import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; - import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import me.chanjar.weixin.mp.bean.custombuilder.ImageBuilder; +import me.chanjar.weixin.mp.bean.custombuilder.MusicBuilder; +import me.chanjar.weixin.mp.bean.custombuilder.NewsBuilder; +import me.chanjar.weixin.mp.bean.custombuilder.TextBuilder; +import me.chanjar.weixin.mp.bean.custombuilder.VideoBuilder; +import me.chanjar.weixin.mp.bean.custombuilder.VoiceBuilder; +import me.chanjar.weixin.mp.bean.custombuilder.WxCardBuilder; +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; + /** * 客服消息 * @author chanjarster @@ -14,7 +20,7 @@ import java.util.List; */ public class WxMpCustomMessage implements Serializable { private static final long serialVersionUID = -9196732086954365246L; - + private String toUser; private String msgType; private String content; @@ -25,8 +31,9 @@ public class WxMpCustomMessage implements Serializable { private String musicUrl; private String hqMusicUrl; private String kfAccount; + private String cardId; private List
articles = new ArrayList<>(); - + public String getToUser() { return this.toUser; } @@ -36,7 +43,7 @@ public class WxMpCustomMessage implements Serializable { public String getMsgType() { return this.msgType; } - + /** * * 请使用 @@ -46,6 +53,7 @@ public class WxMpCustomMessage implements Serializable { * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_MUSIC} * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_VIDEO} * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_NEWS} + * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_WXCARD} ** @param msgType */ @@ -94,24 +102,33 @@ public class WxMpCustomMessage implements Serializable { public void setHqMusicUrl(String hqMusicUrl) { this.hqMusicUrl = hqMusicUrl; } + + public String getCardId() { + return this.cardId; + } + + public void setCardId(String cardId) { + this.cardId = cardId; + } + public ListgetArticles() { return this.articles; } public void setArticles(List articles) { this.articles = articles; } - + public String toJson() { return WxMpGsonBuilder.INSTANCE.create().toJson(this); } - + public static class WxArticle { - + private String title; private String description; private String url; private String picUrl; - + public String getTitle() { return this.title; } @@ -136,9 +153,9 @@ public class WxMpCustomMessage implements Serializable { public void setPicUrl(String picUrl) { this.picUrl = picUrl; } - + } - + /** * 获得文本消息builder */ @@ -159,34 +176,41 @@ public class WxMpCustomMessage implements Serializable { public static VoiceBuilder VOICE() { return new VoiceBuilder(); } - + /** * 获得视频消息builder */ public static VideoBuilder VIDEO() { return new VideoBuilder(); } - + /** * 获得音乐消息builder */ public static MusicBuilder MUSIC() { return new MusicBuilder(); } - + /** * 获得图文消息builder */ public static NewsBuilder NEWS() { return new NewsBuilder(); } - + + + /** + * 获得卡券消息builder + */ + public static WxCardBuilder WXCARD() { + return new WxCardBuilder(); + } + public String getKfAccount() { return this.kfAccount; } - + public void setKfAccount(String kfAccount) { this.kfAccount = kfAccount; } - } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpGroup.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpGroup.java deleted file mode 100644 index 7dfd4ccc..00000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpGroup.java +++ /dev/null @@ -1,52 +0,0 @@ -package me.chanjar.weixin.mp.bean; - -import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; - -import java.io.Serializable; - -/** - * 微信用户分组 - * @author chanjarster - * - */ -public class WxMpGroup implements Serializable { - - /** - * - */ - private static final long serialVersionUID = 1554709708638735270L; - private long id = -1; - private String name; - private long count; - public long getId() { - return this.id; - } - public void setId(long id) { - this.id = id; - } - public String getName() { - return this.name; - } - public void setName(String name) { - this.name = name; - } - public long getCount() { - return this.count; - } - public void setCount(long count) { - this.count = count; - } - - public static WxMpGroup fromJson(String json) { - return WxMpGsonBuilder.create().fromJson(json, WxMpGroup.class); - } - - public String toJson() { - return WxMpGsonBuilder.create().toJson(this); - } - @Override - public String toString() { - return "WxMpGroup [id=" + this.id + ", name=" + this.name + ", count=" + this.count + "]"; - } - -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassGroupMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java similarity index 82% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassGroupMessage.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java index d77605a6..300b4f90 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassGroupMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java @@ -1,26 +1,23 @@ package me.chanjar.weixin.mp.bean; -import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; - import java.io.Serializable; +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; + /** - * 分组群发的消息 + * 按标签群发的消息 * * @author chanjarster */ -public class WxMpMassGroupMessage implements Serializable { +public class WxMpMassTagMessage implements Serializable { - /** - * - */ private static final long serialVersionUID = -6625914040986749286L; - private Long groupId; + private Long tagId; private String msgtype; private String content; private String mediaId; - public WxMpMassGroupMessage() { + public WxMpMassTagMessage() { super(); } @@ -64,16 +61,16 @@ public class WxMpMassGroupMessage implements Serializable { return WxMpGsonBuilder.INSTANCE.create().toJson(this); } - public Long getGroupId() { - return this.groupId; + public Long getTagId() { + return this.tagId; } /** * 如果不设置则就意味着发给所有用户 - * @param groupId + * @param tagId */ - public void setGroupId(Long groupId) { - this.groupId = groupId; + public void setTagId(Long tagId) { + this.tagId = tagId; } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateData.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateData.java index ff83baa9..d46ae24b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateData.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateData.java @@ -7,9 +7,6 @@ import java.io.Serializable; */ public class WxMpTemplateData implements Serializable { - /** - * - */ private static final long serialVersionUID = 6301835292940277870L; private String name; private String value; @@ -48,6 +45,7 @@ public class WxMpTemplateData implements Serializable { public String getColor() { return this.color; } + public void setColor(String color) { this.color = color; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateMessage.java index eec25eda..408abb50 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateMessage.java @@ -1,17 +1,14 @@ package me.chanjar.weixin.mp.bean; -import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; - import java.io.Serializable; import java.util.ArrayList; import java.util.List; -public class WxMpTemplateMessage implements Serializable { +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; - /** - * - */ +public class WxMpTemplateMessage implements Serializable { private static final long serialVersionUID = 5063374783759519418L; + private String toUser; private String templateId; private String url; @@ -65,4 +62,61 @@ public class WxMpTemplateMessage implements Serializable { public String toJson() { return WxMpGsonBuilder.INSTANCE.create().toJson(this); } + + public static WxMpTemplateMessageBuilder builder() { + return new WxMpTemplateMessageBuilder(); + } + + public static class WxMpTemplateMessageBuilder { + private String toUser; + private String templateId; + private String url; + private String topColor; + private List data = new ArrayList<>(); + + public WxMpTemplateMessageBuilder toUser(String toUser) { + this.toUser = toUser; + return this; + } + + public WxMpTemplateMessageBuilder templateId(String templateId) { + this.templateId = templateId; + return this; + } + + public WxMpTemplateMessageBuilder url(String url) { + this.url = url; + return this; + } + + public WxMpTemplateMessageBuilder topColor(String topColor) { + this.topColor = topColor; + return this; + } + + public WxMpTemplateMessageBuilder data(List data) { + this.data = data; + return this; + } + + public WxMpTemplateMessageBuilder from(WxMpTemplateMessage origin) { + this.toUser(origin.toUser); + this.templateId(origin.templateId); + this.url(origin.url); + this.topColor(origin.topColor); + this.data(origin.data); + return this; + } + + public WxMpTemplateMessage build() { + WxMpTemplateMessage m = new WxMpTemplateMessage(); + m.toUser = this.toUser; + m.templateId = this.templateId; + m.url = this.url; + m.topColor = this.topColor; + m.data = this.data; + return m; + } + } + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpUserQuery.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpUserQuery.java index f16c004c..e97389b8 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpUserQuery.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpUserQuery.java @@ -24,22 +24,22 @@ public class WxMpUserQuery { /** * 语言使用默认(zh_CN) * - * @param openIdList + * @param openids */ - public WxMpUserQuery(List openIdList) { + public WxMpUserQuery(List openids) { super(); - add(openIdList); + add(openids); } /** * 添加OpenId列表,语言使用默认(zh_CN) * - * @param openIdList + * @param openids * @return {@link WxMpUserQuery} */ - public WxMpUserQuery add(List openIdList) { - for (String openId : openIdList) { - this.add(openId); + public WxMpUserQuery add(List openids) { + for (String openid : openids) { + this.add(openid); } return this; } @@ -47,12 +47,12 @@ public class WxMpUserQuery { /** * 添加一个OpenId * - * @param openId + * @param openid * @param lang 国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语 * @return {@link WxMpUserQuery} */ - public WxMpUserQuery add(String openId, String lang) { - this.queryParamList.add(new WxMpUserQueryParam(openId, lang)); + public WxMpUserQuery add(String openid, String lang) { + this.queryParamList.add(new WxMpUserQueryParam(openid, lang)); return this; } @@ -63,34 +63,34 @@ public class WxMpUserQuery { * 该方法默认lang = zh_CN *
- * 微信推送过来的消息,也是同步回复给用户的消息,xml格式 - * 相关字段的解释看微信开发者文档: - * http://mp.weixin.qq.com/wiki/index.php?title=接收普通消息 - * http://mp.weixin.qq.com/wiki/index.php?title=接收事件推送 - * http://mp.weixin.qq.com/wiki/index.php?title=接收语音识别结果 + * 微信推送过来的消息,xml格式 + * 部分未注释的字段的解释请查阅相关微信开发文档: + * 接收普通消息 + * 接收事件推送 ** * @author chanjarster @@ -42,14 +39,13 @@ public class WxMpXmlMessage implements Serializable { @XStreamAlias("ToUserName") @XStreamConverter(value = XStreamCDataConverter.class) - private String toUserName; + private String toUser; @XStreamAlias("FromUserName") @XStreamConverter(value = XStreamCDataConverter.class) - private String fromUserName; + private String fromUser; @XStreamAlias("CreateTime") - @JsonSerialize(using = WxLongTimeJsonSerializer.class) private Long createTime; @XStreamAlias("MsgType") @@ -212,12 +208,75 @@ public class WxMpXmlMessage implements Serializable { @XStreamAlias("SendLocationInfo") private SendLocationInfo sendLocationInfo = new SendLocationInfo(); - public String getToUserName() { - return this.toUserName; + /////////////////////////////////////// + // 门店审核事件推送 + /////////////////////////////////////// + /** + * UniqId + * 商户自己内部ID,即字段中的sid + */ + @XStreamAlias("UniqId") + private String storeUniqId; + + /** + * PoiId + * 微信的门店ID,微信内门店唯一标示ID + */ + @XStreamAlias("PoiId") + private String poiId; + + /** + * Result + * 审核结果,成功succ 或失败fail + */ + @XStreamAlias("Result") + private String result; + + /** + * msg + * 成功的通知信息,或审核失败的驳回理由 + */ + @XStreamAlias("msg") + private String msg; + + public String getStoreUniqId() { + return this.storeUniqId; + } + + public void setStoreUniqId(String storeUniqId) { + this.storeUniqId = storeUniqId; + } + + public String getPoiId() { + return this.poiId; + } + + public void setPoiId(String poiId) { + this.poiId = poiId; + } + + public String getResult() { + return this.result; + } + + public void setResult(String result) { + this.result = result; + } + + public String getMsg() { + return this.msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public String getToUser() { + return this.toUser; } - public void setToUserName(String toUserName) { - this.toUserName = toUserName; + public void setToUser(String toUser) { + this.toUser = toUser; } public Long getCreateTime() { @@ -422,12 +481,12 @@ public class WxMpXmlMessage implements Serializable { this.recognition = recognition; } - public String getFromUserName() { - return this.fromUserName; + public String getFromUser() { + return this.fromUser; } - public void setFromUserName(String fromUserName) { - this.fromUserName = fromUserName; + public void setFromUser(String fromUser) { + this.fromUser = fromUser; } public static WxMpXmlMessage fromXml(String xml) { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/WxCardBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/WxCardBuilder.java new file mode 100644 index 00000000..8620cd84 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/WxCardBuilder.java @@ -0,0 +1,32 @@ +package me.chanjar.weixin.mp.bean.custombuilder; + +import me.chanjar.weixin.common.api.WxConsts; +import me.chanjar.weixin.mp.bean.WxMpCustomMessage; + +/** + * 卡券消息builder + *
+ * 用法: WxMpCustomMessage m = WxMpCustomMessage.WXCARD().cardId(...).toUser(...).build(); + *+ * @author mgcnrx11 + * + */ +public final class WxCardBuilder extends BaseBuilder
* 累计用户数据接口的返回JSON数据包 - * http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html + * 详情查看文档:用户分析数据接口 **/ public class WxDataCubeUserCumulate implements Serializable { + private static final JsonParser JSON_PARSER = new JsonParser(); + private static final long serialVersionUID = -3570981300225093657L; private Date refDate; @@ -40,4 +48,11 @@ public class WxDataCubeUserCumulate implements Serializable { public String toString() { return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); } + + public static List
* 用户增减数据接口的返回JSON数据包 - * http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html + * 详情查看文档:用户分析数据接口 **/ public class WxDataCubeUserSummary implements Serializable { private static final long serialVersionUID = -2336654489906694173L; + private static final JsonParser JSON_PARSER = new JsonParser(); + private Date refDate; private Integer userSource; @@ -59,4 +67,11 @@ public class WxDataCubeUserSummary implements Serializable { public String toString() { return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); } + + public static List
* 查询订单支付状态返回的结果 @@ -13,9 +16,11 @@ import java.io.Serializable; * @author ukid */ public class WxMpPayResult implements Serializable { - /** - * - */ + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); + } + private static final long serialVersionUID = -570934170727777190L; private String return_code; @@ -41,6 +46,16 @@ public class WxMpPayResult implements Serializable { private String out_trade_no; private String attach; private String time_end; + /** + * 现金支付金额 cash_fee 是 Int 100 现金支付金额订单现金支付金额,详见支付金额 + */ + private String cash_fee; + + /** + * 现金支付货币类型 cash_fee_type 否 + * + */ + private String cash_fee_type; public String getReturn_code() { return this.return_code; @@ -226,32 +241,19 @@ public class WxMpPayResult implements Serializable { this.trade_state_desc = trade_state_desc; } - @Override - public String toString() { - return "WxMpPayResult{" + - "return_code=" + this.return_code + - ", return_msg='" + this.return_msg + '\'' + - ", appid='" + this.appid + '\'' + - ", mch_id='" + this.mch_id + '\'' + - ", nonce_str='" + this.nonce_str + '\'' + - ", sign='" + this.sign + '\'' + - ", result_code='" + this.result_code + '\'' + - ", err_code='" + this.err_code + '\'' + - ", err_code_des='" + this.err_code_des + '\'' + - ", trade_state=" + this.trade_state + - ", trade_state_desc=" + this.trade_state_desc + - ", device_info='" + this.device_info + '\'' + - ", openid='" + this.openid + '\'' + - ", is_subscribe='" + this.is_subscribe + '\'' + - ", trade_type='" + this.trade_type + '\'' + - ", bank_type='" + this.bank_type + '\'' + - ", total_fee='" + this.total_fee + '\'' + - ", coupon_fee='" + this.coupon_fee + '\'' + - ", fee_type='" + this.fee_type + '\'' + - ", transaction_id='" + this.transaction_id + '\'' + - ", out_trade_no='" + this.out_trade_no + '\'' + - ", attach='" + this.attach + '\'' + - ", time_end='" + this.time_end + '\'' + - '}'; + public String getCash_fee() { + return this.cash_fee; + } + + public void setCash_fee(String cash_fee) { + this.cash_fee = cash_fee; + } + + public String getCash_fee_type() { + return this.cash_fee_type; + } + + public void setCash_fee_type(String cash_fee_type) { + this.cash_fee_type = cash_fee_type; } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxMpPrepayIdResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxMpPrepayIdResult.java new file mode 100644 index 00000000..cff9d787 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxMpPrepayIdResult.java @@ -0,0 +1,124 @@ +package me.chanjar.weixin.mp.bean.pay; + +import java.io.Serializable; + +/** + *+ * 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"返回的结果 + * 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1) + *+ * + * @author chanjarster + */ +@Deprecated +public class WxMpPrepayIdResult implements Serializable { + private static final long serialVersionUID = -8970574397788396143L; + private String return_code; + private String return_msg; + private String appid; + private String mch_id; + private String nonce_str; + private String sign; + private String result_code; + private String prepay_id; + private String trade_type; + private String err_code; + private String err_code_des; + private String code_url; + + public String getReturn_code() { + return this.return_code; + } + + public void setReturn_code(String return_code) { + this.return_code = return_code; + } + + public String getReturn_msg() { + return this.return_msg; + } + + public void setReturn_msg(String return_msg) { + this.return_msg = return_msg; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getMch_id() { + return this.mch_id; + } + + public void setMch_id(String mch_id) { + this.mch_id = mch_id; + } + + public String getNonce_str() { + return this.nonce_str; + } + + public void setNonce_str(String nonce_str) { + this.nonce_str = nonce_str; + } + + public String getSign() { + return this.sign; + } + + public void setSign(String sign) { + this.sign = sign; + } + + public String getResult_code() { + return this.result_code; + } + + public void setResult_code(String result_code) { + this.result_code = result_code; + } + + public String getPrepay_id() { + return this.prepay_id; + } + + public void setPrepay_id(String prepay_id) { + this.prepay_id = prepay_id; + } + + public String getTrade_type() { + return this.trade_type; + } + + public void setTrade_type(String trade_type) { + this.trade_type = trade_type; + } + + public String getErr_code() { + return this.err_code; + } + + public void setErr_code(String err_code) { + this.err_code = err_code; + } + + public String getErr_code_des() { + return this.err_code_des; + } + + public void setErr_code_des(String err_code_des) { + this.err_code_des = err_code_des; + } + + public String getCode_url() { + return this.code_url; + } + + public void setCode_url(String code_url) { + this.code_url = code_url; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxRedpackResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxRedpackResult.java similarity index 66% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxRedpackResult.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxRedpackResult.java index be328668..297e07d7 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxRedpackResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxRedpackResult.java @@ -1,7 +1,10 @@ -package me.chanjar.weixin.mp.bean.result; +package me.chanjar.weixin.mp.bean.pay; import java.io.Serializable; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + import com.thoughtworks.xstream.annotations.XStreamAlias; /** @@ -13,38 +16,35 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; @XStreamAlias("xml") public class WxRedpackResult implements Serializable { - /** - * - */ private static final long serialVersionUID = -4837415036337132073L; @XStreamAlias("return_code") - String returnCode; + private String returnCode; @XStreamAlias("return_msg") - String returnMsg; + private String returnMsg; @XStreamAlias("sign") - String sign; + private String sign; @XStreamAlias("result_code") - String resultCode; + private String resultCode; @XStreamAlias("err_code") - String errCode; + private String errCode; @XStreamAlias("err_code_des") - String errCodeDes; + private String errCodeDes; @XStreamAlias("mch_billno") - String mchBillno; + private String mchBillno; @XStreamAlias("mch_id") - String mchId; + private String mchId; @XStreamAlias("wxappid") - String wxappid; + private String wxappid; @XStreamAlias("re_openid") - String reOpenid; + private String reOpenid; @XStreamAlias("total_amount") - int totalAmount; + private int totalAmount; @XStreamAlias("send_time") - String sendTime; + private String sendTime; @XStreamAlias("send_listid") - String sendListid; + private String sendListid; public String getErrCode() { return this.errCode; @@ -100,19 +100,6 @@ public class WxRedpackResult implements Serializable { @Override public String toString() { - return "WxRedpackResult{" + - "returnCode=" + this.returnCode + - ", returnMsg=" + this.returnMsg + - ", sign=" + this.sign + - ", errCode=" + this.errCode + - ", errCodeDes=" + this.errCodeDes + - ", mchBillno=" + this.mchBillno + - ", mchId=" + this.mchId + - ", wxappid=" + this.wxappid + - ", reOpenid=" + this.reOpenid + - ", totalAmount=" + this.totalAmount + - ", sendTime=" + this.sendTime + - ", sendListid=" + this.sendListid + - '}'; + return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxSendRedpackRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxSendRedpackRequest.java new file mode 100644 index 00000000..abe0d68f --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxSendRedpackRequest.java @@ -0,0 +1,296 @@ +package me.chanjar.weixin.mp.bean.pay; + +import com.thoughtworks.xstream.annotations.XStreamAlias; + +/** + * 发送红包请求参数对象 + * Created by Binary Wang on 2016/9/24. + * @author binarywang (https://github.com/binarywang) + */ +@XStreamAlias("xml") +public class WxSendRedpackRequest { + /** + * mch_billno + * 商户订单号(每个订单号必须唯一) 组成:mch_id+yyyymmdd+10位一天内不能重复的数字。 接口根据商户订单号支持重入,如出现超时可再调用。 + */ + @XStreamAlias("mch_billno") + private String mchBillno; + + /** + * send_name + * 商户名称 + * 红包发送者名称 + */ + @XStreamAlias("send_name") + private String sendName; + + /** + * re_openid + * 接受红包的用户 用户在wxappid下的openid + */ + @XStreamAlias("re_openid") + private String reOpenid; + + /** + * total_amount + * 红包总额 + */ + @XStreamAlias("total_amount") + private Integer totalAmount; + + /** + * total_num + * 红包发放总人数 + */ + @XStreamAlias("total_num") + private Integer totalNum; + + /** + * amt_type + * 红包金额设置方式 + * ALL_RAND—全部随机,商户指定总金额和红包发放总人数,由微信支付随机计算出各红包金额 + * 裂变红包必填 + */ + @XStreamAlias("amt_type") + private String amtType; + + /** + * wishing + * 红包祝福语 + */ + @XStreamAlias("wishing") + private String wishing; + + /** + * client_ip + * 服务器Ip地址 + * 调用接口的机器Ip地址 + */ + @XStreamAlias("client_ip") + private String clientIp; + + /** + * act_name + * 活动名称 + */ + @XStreamAlias("act_name") + private String actName; + + /** + * remark + * 备注 + */ + @XStreamAlias("remark") + private String remark; + + /** + * wxappid + * 微信分配的公众账号ID(企业号corpid即为此appId)。接口传入的所有appid应该为公众号的appid(在mp.weixin.qq.com申请的),不能为APP的appid(在open.weixin.qq.com申请的) + */ + @XStreamAlias("wxappid") + private String wxAppid; + + /** + * mch_id + * 微信支付分配的商户号 + */ + @XStreamAlias("mch_id") + private String mchId; + + /** + * nonce_str + * 随机字符串,不长于32位 + */ + @XStreamAlias("nonce_str") + private String nonceStr; + + /** + * sign + * 详见签名生成算法 + */ + @XStreamAlias("sign") + private String sign; + + /** + *+ * scene_id + * 场景id + * PRODUCT_1:商品促销 + * PRODUCT_2:抽奖 + * PRODUCT_3:虚拟物品兑奖 + * PRODUCT_4:企业内部福利 + * PRODUCT_5:渠道分润 + * PRODUCT_6:保险回馈 + * PRODUCT_7:彩票派奖 + * PRODUCT_8:税务刮奖 + * 非必填字段 + *+ */ + @XStreamAlias("scene_id") + private String sceneId; + + /** + *+ * risk_info + * 活动信息 + * posttime:用户操作的时间戳 + * mobile:业务系统账号的手机号,国家代码-手机号。不需要+号 + * deviceid :mac 地址或者设备唯一标识 + * clientversion :用户操作的客户端版本 + * 把值为非空的信息用key=value进行拼接,再进行urlencode + * urlencode(posttime=xx&mobile=xx&deviceid=xx) + * 非必填字段 + *+ */ + @XStreamAlias("risk_info") + private String riskInfo; + + /** + *+ * consume_mch_id + * 资金授权商户号 + * 资金授权商户号 + * 服务商替特约商户发放时使用 + * 非必填字段 + *+ */ + @XStreamAlias("consume_mch_id") + private String consumeMchId; + + public String getMchBillno() { + return this.mchBillno; + } + + public void setMchBillno(String mchBillno) { + this.mchBillno = mchBillno; + } + + public String getSendName() { + return this.sendName; + } + + public void setSendName(String sendName) { + this.sendName = sendName; + } + + public String getReOpenid() { + return this.reOpenid; + } + + public void setReOpenid(String reOpenid) { + this.reOpenid = reOpenid; + } + + public Integer getTotalAmount() { + return this.totalAmount; + } + + public void setTotalAmount(Integer totalAmount) { + this.totalAmount = totalAmount; + } + + public Integer getTotalNum() { + return this.totalNum; + } + + public void setTotalNum(Integer totalNum) { + this.totalNum = totalNum; + } + + public String getAmtType() { + return this.amtType; + } + + public void setAmtType(String amtType) { + this.amtType = amtType; + } + + public String getWishing() { + return this.wishing; + } + + public void setWishing(String wishing) { + this.wishing = wishing; + } + + public String getClientIp() { + return this.clientIp; + } + + public void setClientIp(String clientIp) { + this.clientIp = clientIp; + } + + public String getActName() { + return this.actName; + } + + public void setActName(String actName) { + this.actName = actName; + } + + public String getRemark() { + return this.remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public String getWxAppid() { + return this.wxAppid; + } + + public void setWxAppid(String wxAppid) { + this.wxAppid = wxAppid; + } + + public String getMchId() { + return this.mchId; + } + + public void setMchId(String mchId) { + this.mchId = mchId; + } + + public String getNonceStr() { + return this.nonceStr; + } + + public void setNonceStr(String nonceStr) { + this.nonceStr = nonceStr; + } + + public String getSign() { + return this.sign; + } + + public void setSign(String sign) { + this.sign = sign; + } + + public String getSceneId() { + return this.sceneId; + } + + public void setSceneId(String sceneId) { + this.sceneId = sceneId; + } + + public String getRiskInfo() { + return this.riskInfo; + } + + public void setRiskInfo(String riskInfo) { + this.riskInfo = riskInfo; + } + + public String getConsumeMchId() { + return this.consumeMchId; + } + + public void setConsumeMchId(String consumeMchId) { + this.consumeMchId = consumeMchId; + } + +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxUnifiedOrderRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxUnifiedOrderRequest.java new file mode 100644 index 00000000..ccdfff90 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxUnifiedOrderRequest.java @@ -0,0 +1,666 @@ +package me.chanjar.weixin.mp.bean.pay; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import com.thoughtworks.xstream.annotations.XStreamAlias; + +import me.chanjar.weixin.common.annotation.Required; + +/** + *+ * 统一下单请求参数对象 + * 参考文档:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1 + * 每个字段描述对应如下: + *
+ * 公众账号ID + * appid + * 是 + * String(32) + * wxd678efh567hg6787 + * 微信分配的公众账号ID(企业号corpid即为此appId) + *+ */ + @XStreamAlias("appid") + private String appid; + + /** + *
+ * 商户号 + * mch_id + * 是 + * String(32) + * 1230000109 + * 微信支付分配的商户号 + *+ */ + @XStreamAlias("mch_id") + private String mchId; + + /** + *
+ * 设备号 + * device_info + * 否 + * String(32) + * 013467007045764 + * 终端设备号(门店号或收银设备Id),注意:PC网页或公众号内支付请传"WEB" + *+ */ + @XStreamAlias("device_info") + private String deviceInfo; + + /** + *
+ * 随机字符串 + * nonce_str + * 是 + * String(32) + * 5K8264ILTKCH16CQ2502SI8ZNMTM67VS + * 随机字符串,不长于32位。推荐随机数生成算法 + *+ */ + @XStreamAlias("nonce_str") + private String nonceStr; + + /** + *
+ * 签名 + * sign + * 是 + * String(32) + * C380BEC2BFD727A4B6845133519F3AD6 + * 签名,详见签名生成算法 + *+ */ + @XStreamAlias("sign") + private String sign; + + /** + *
+ * 商品描述 + * body + * 是 + * String(128) + * 腾讯充值中心-QQ会员充值 + * 商品简单描述,该字段须严格按照规范传递,具体请见参数规定 + *+ */ + @Required + @XStreamAlias("body") + private String body; + + /** + *
+ * 商品详情 + * detail + * 否 + * String(6000) + * { "goods_detail":[ + { + "goods_id":"iphone6s_16G", + "wxpay_goods_id":"1001", + "goods_name":"iPhone6s 16G", + "goods_num":1, + "price":528800, + "goods_category":"123456", + "body":"苹果手机" + }, + { + "goods_id":"iphone6s_32G", + "wxpay_goods_id":"1002", + "goods_name":"iPhone6s 32G", + "quantity":1, + "price":608800, + "goods_category":"123789", + "body":"苹果手机" + } + ] + } + 商品详细列表,使用Json格式,传输签名前请务必使用CDATA标签将JSON文本串保护起来。 + goods_detail []: + └ goods_id String 必填 32 商品的编号 + └ wxpay_goods_id String 可选 32 微信支付定义的统一商品编号 + └ goods_name String 必填 256 商品名称 + └ goods_num Int 必填 商品数量 + └ price Int 必填 商品单价,单位为分 + └ goods_category String 可选 32 商品类目Id + └ body String 可选 1000 商品描述信息 + *+ */ + @XStreamAlias("detail") + private String detail; + + /** + *
+ * 附加数据 + * attach + * 否 + * String(127) + * 深圳分店 + * 附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据 + *+ */ + @XStreamAlias("attach") + private String attach; + + /** + *
+ * 商户订单号 + * out_trade_no + * 是 + * String(32) + * 20150806125346 + * 商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号 + *+ */ + @Required + @XStreamAlias("out_trade_no") + private String outTradeNo; + + /** + *
+ * 货币类型 + * fee_type + * 否 + * String(16) + * CNY + * 符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型 + *+ */ + @XStreamAlias("fee_type") + private String feeType; + + /** + *
+ * 总金额 + * total_fee + * 是 + * Int + * 888 + * 订单总金额,单位为分,详见支付金额 + *+ */ + @Required + @XStreamAlias("total_fee") + private Integer totalFee; + + /** + *
+ * 终端IP + * spbill_create_ip + * 是 + * String(16) + * 123.12.12.123 + * APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。 + *+ */ + @Required + @XStreamAlias("spbill_create_ip") + private String spbillCreateIp; + + /** + *
+ * 交易起始时间 + * time_start + * 否 + * String(14) + * 20091225091010 + * 订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则 + *+ */ + @XStreamAlias("time_start") + private String timeStart; + + /** + *
+ * 交易结束时间 + * time_expire + * 否 + * String(14) + * 20091227091010 + * 订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则 + * 注意:最短失效时间间隔必须大于5分钟 + *+ */ + @XStreamAlias("time_expire") + private String timeExpire; + + /** + *
+ * 商品标记 + * goods_tag + * 否 + * String(32) + * WXG + * 商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠 + *+ */ + @XStreamAlias("goods_tag") + private String goodsTag; + + /** + *
+ * 通知地址 + * notify_url + * 是 + * String(256) + * http://www.weixin.qq.com/wxpay/pay.php + * 接收微信支付异步通知回调地址,通知url必须为直接可访问的url,不能携带参数。 + *+ */ + @Required + @XStreamAlias("notify_url") + private String notifyURL; + + /** + *
+ * 交易类型 + * trade_type + * 是 + * String(16) + * JSAPI + * 取值如下:JSAPI,NATIVE,APP,详细说明见参数规定: + * JSAPI--公众号支付、NATIVE--原生扫码支付、APP--app支付,统一下单接口trade_type的传参可参考这里 + *+ */ + @Required + @XStreamAlias("trade_type") + private String tradeType; + + /** + *
+ * 商品Id + * product_id + * 否 + * String(32) + * 12235413214070356458058 + * trade_type=NATIVE,此参数必传。此id为二维码中包含的商品Id,商户自行定义。 + *+ */ + @XStreamAlias("product_id") + private String productId; + + /** + *
+ * 指定支付方式 + * limit_pay + * 否 + * String(32) + * no_credit no_credit--指定不能使用信用卡支付 + *+ */ + @XStreamAlias("limit_pay") + private String limitPay; + + /** + *
+ * 用户标识 + * openid + * 否 + * String(128) + * oUpF8uMuAJO_M2pxb1Q9zNjWeS6o + * trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。 + * openid如何获取,可参考【获取openid】。 + * 企业号请使用【企业号OAuth2.0接口】获取企业号内成员userid,再调用【企业号userid转openid接口】进行转换 + *+ */ + @XStreamAlias("openid") + private String openid; + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getMchId() { + return this.mchId; + } + + public void setMchId(String mchId) { + this.mchId = mchId; + } + + public String getDeviceInfo() { + return this.deviceInfo; + } + + public void setDeviceInfo(String deviceInfo) { + this.deviceInfo = deviceInfo; + } + + public String getNonceStr() { + return this.nonceStr; + } + + public void setNonceStr(String nonceStr) { + this.nonceStr = nonceStr; + } + + public String getSign() { + return this.sign; + } + + public void setSign(String sign) { + this.sign = sign; + } + + public String getBody() { + return this.body; + } + + public void setBody(String body) { + this.body = body; + } + + public String getDetail() { + return this.detail; + } + + public void setDetail(String detail) { + this.detail = detail; + } + + public String getAttach() { + return this.attach; + } + + public void setAttach(String attach) { + this.attach = attach; + } + + public String getOutTradeNo() { + return this.outTradeNo; + } + + public void setOutTradeNo(String outTradeNo) { + this.outTradeNo = outTradeNo; + } + + public String getFeeType() { + return this.feeType; + } + + public void setFeeType(String feeType) { + this.feeType = feeType; + } + + public Integer getTotalFee() { + return this.totalFee; + } + + public void setTotalFee(Integer totalFee) { + this.totalFee = totalFee; + } + + public String getSpbillCreateIp() { + return this.spbillCreateIp; + } + + public void setSpbillCreateIp(String spbillCreateIp) { + this.spbillCreateIp = spbillCreateIp; + } + + public String getTimeStart() { + return this.timeStart; + } + + public void setTimeStart(String timeStart) { + this.timeStart = timeStart; + } + + public String getTimeExpire() { + return this.timeExpire; + } + + public void setTimeExpire(String timeExpire) { + this.timeExpire = timeExpire; + } + + public String getGoodsTag() { + return this.goodsTag; + } + + public void setGoodsTag(String goodsTag) { + this.goodsTag = goodsTag; + } + + public String getNotifyURL() { + return this.notifyURL; + } + + public void setNotifyURL(String notifyURL) { + this.notifyURL = notifyURL; + } + + public String getTradeType() { + return this.tradeType; + } + + public void setTradeType(String tradeType) { + this.tradeType = tradeType; + } + + public String getProductId() { + return this.productId; + } + + public void setProductId(String productId) { + this.productId = productId; + } + + public String getLimitPay() { + return this.limitPay; + } + + public void setLimitPay(String limitPay) { + this.limitPay = limitPay; + } + + public String getOpenid() { + return this.openid; + } + + public void setOpenid(String openid) { + this.openid = openid; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); + } + + public static WxUnifiedOrderRequestBuilder builder() { + return new WxUnifiedOrderRequestBuilder(); + } + + public static class WxUnifiedOrderRequestBuilder { + private String appid; + private String mchId; + private String deviceInfo; + private String nonceStr; + private String sign; + private String body; + private String detail; + private String attach; + private String outTradeNo; + private String feeType; + private Integer totalFee; + private String spbillCreateIp; + private String timeStart; + private String timeExpire; + private String goodsTag; + private String notifyURL; + private String tradeType; + private String productId; + private String limitPay; + private String openid; + + public WxUnifiedOrderRequestBuilder appid(String appid) { + this.appid = appid; + return this; + } + + public WxUnifiedOrderRequestBuilder mchId(String mchId) { + this.mchId = mchId; + return this; + } + + public WxUnifiedOrderRequestBuilder deviceInfo(String deviceInfo) { + this.deviceInfo = deviceInfo; + return this; + } + + public WxUnifiedOrderRequestBuilder nonceStr(String nonceStr) { + this.nonceStr = nonceStr; + return this; + } + + public WxUnifiedOrderRequestBuilder sign(String sign) { + this.sign = sign; + return this; + } + + public WxUnifiedOrderRequestBuilder body(String body) { + this.body = body; + return this; + } + + public WxUnifiedOrderRequestBuilder detail(String detail) { + this.detail = detail; + return this; + } + + public WxUnifiedOrderRequestBuilder attach(String attach) { + this.attach = attach; + return this; + } + + public WxUnifiedOrderRequestBuilder outTradeNo(String outTradeNo) { + this.outTradeNo = outTradeNo; + return this; + } + + public WxUnifiedOrderRequestBuilder feeType(String feeType) { + this.feeType = feeType; + return this; + } + + public WxUnifiedOrderRequestBuilder totalFee(Integer totalFee) { + this.totalFee = totalFee; + return this; + } + + public WxUnifiedOrderRequestBuilder spbillCreateIp(String spbillCreateIp) { + this.spbillCreateIp = spbillCreateIp; + return this; + } + + public WxUnifiedOrderRequestBuilder timeStart(String timeStart) { + this.timeStart = timeStart; + return this; + } + + public WxUnifiedOrderRequestBuilder timeExpire(String timeExpire) { + this.timeExpire = timeExpire; + return this; + } + + public WxUnifiedOrderRequestBuilder goodsTag(String goodsTag) { + this.goodsTag = goodsTag; + return this; + } + + public WxUnifiedOrderRequestBuilder notifyURL(String notifyURL) { + this.notifyURL = notifyURL; + return this; + } + + public WxUnifiedOrderRequestBuilder tradeType(String tradeType) { + this.tradeType = tradeType; + return this; + } + + public WxUnifiedOrderRequestBuilder productId(String productId) { + this.productId = productId; + return this; + } + + public WxUnifiedOrderRequestBuilder limitPay(String limitPay) { + this.limitPay = limitPay; + return this; + } + + public WxUnifiedOrderRequestBuilder openid(String openid) { + this.openid = openid; + return this; + } + + public WxUnifiedOrderRequestBuilder from(WxUnifiedOrderRequest origin) { + this.appid(origin.appid); + this.mchId(origin.mchId); + this.deviceInfo(origin.deviceInfo); + this.nonceStr(origin.nonceStr); + this.sign(origin.sign); + this.body(origin.body); + this.detail(origin.detail); + this.attach(origin.attach); + this.outTradeNo(origin.outTradeNo); + this.feeType(origin.feeType); + this.totalFee(origin.totalFee); + this.spbillCreateIp(origin.spbillCreateIp); + this.timeStart(origin.timeStart); + this.timeExpire(origin.timeExpire); + this.goodsTag(origin.goodsTag); + this.notifyURL(origin.notifyURL); + this.tradeType(origin.tradeType); + this.productId(origin.productId); + this.limitPay(origin.limitPay); + this.openid(origin.openid); + return this; + } + + public WxUnifiedOrderRequest build() { + WxUnifiedOrderRequest m = new WxUnifiedOrderRequest(); + m.appid = this.appid; + m.mchId = this.mchId; + m.deviceInfo = this.deviceInfo; + m.nonceStr = this.nonceStr; + m.sign = this.sign; + m.body = this.body; + m.detail = this.detail; + m.attach = this.attach; + m.outTradeNo = this.outTradeNo; + m.feeType = this.feeType; + m.totalFee = this.totalFee; + m.spbillCreateIp = this.spbillCreateIp; + m.timeStart = this.timeStart; + m.timeExpire = this.timeExpire; + m.goodsTag = this.goodsTag; + m.notifyURL = this.notifyURL; + m.tradeType = this.tradeType; + m.productId = this.productId; + m.limitPay = this.limitPay; + m.openid = this.openid; + return m; + } + } + +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxUnifiedOrderResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxUnifiedOrderResult.java new file mode 100644 index 00000000..18817461 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxUnifiedOrderResult.java @@ -0,0 +1,155 @@ +package me.chanjar.weixin.mp.bean.pay; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import com.thoughtworks.xstream.annotations.XStreamAlias; + +/** + *
+ * 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"返回的结果 + * 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1) + *+ * + * @author chanjarster + */ +@XStreamAlias("xml") +public class WxUnifiedOrderResult { + + @XStreamAlias("return_code") + private String returnCode; + + @XStreamAlias("return_msg") + private String returnMsg; + + @XStreamAlias("appid") + private String appid; + + @XStreamAlias("mch_id") + private String mchId; + + @XStreamAlias("nonce_str") + private String nonceStr; + + @XStreamAlias("sign") + private String sign; + + @XStreamAlias("result_code") + private String resultCode; + + @XStreamAlias("prepay_id") + private String prepayId; + + @XStreamAlias("trade_type") + private String tradeType; + + @XStreamAlias("err_code") + private String errCode; + + @XStreamAlias("err_code_des") + private String errCodeDes; + + @XStreamAlias("code_url") + private String codeURL; + + public String getReturnCode() { + return this.returnCode; + } + + public void setReturnCode(String returnCode) { + this.returnCode = returnCode; + } + + public String getReturnMsg() { + return this.returnMsg; + } + + public void setReturnMsg(String returnMsg) { + this.returnMsg = returnMsg; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getMchId() { + return this.mchId; + } + + public void setMchId(String mchId) { + this.mchId = mchId; + } + + public String getNonceStr() { + return this.nonceStr; + } + + public void setNonceStr(String nonceStr) { + this.nonceStr = nonceStr; + } + + public String getSign() { + return this.sign; + } + + public void setSign(String sign) { + this.sign = sign; + } + + public String getResultCode() { + return this.resultCode; + } + + public void setResultCode(String resultCode) { + this.resultCode = resultCode; + } + + public String getPrepayId() { + return this.prepayId; + } + + public void setPrepayId(String prepayId) { + this.prepayId = prepayId; + } + + public String getTradeType() { + return this.tradeType; + } + + public void setTradeType(String tradeType) { + this.tradeType = tradeType; + } + + public String getErrCode() { + return this.errCode; + } + + public void setErrCode(String errCode) { + this.errCode = errCode; + } + + public String getErrCodeDes() { + return this.errCodeDes; + } + + public void setErrCodeDes(String errCodeDes) { + this.errCodeDes = errCodeDes; + } + + public String getCodeURL() { + return this.codeURL; + } + + public void setCodeURL(String codeURL) { + this.codeURL = codeURL; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPrepayIdResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPrepayIdResult.java deleted file mode 100644 index e930fc13..00000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPrepayIdResult.java +++ /dev/null @@ -1,128 +0,0 @@ -package me.chanjar.weixin.mp.bean.result; - -import java.io.Serializable; - -/** - *
- * 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"返回的结果 - * - * 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1) - * - *- * - * @author chanjarster - */ -public class WxMpPrepayIdResult implements Serializable { - /** - * - */ - private static final long serialVersionUID = -8970574397788396143L; - private String return_code; - private String return_msg; - private String appid; - private String mch_id; - private String nonce_str; - private String sign; - private String result_code; - private String prepay_id; - private String trade_type; - private String err_code; - private String err_code_des; - private String code_url; - - public String getReturn_code() { - return this.return_code; - } - - public void setReturn_code(String return_code) { - this.return_code = return_code; - } - - public String getReturn_msg() { - return this.return_msg; - } - - public void setReturn_msg(String return_msg) { - this.return_msg = return_msg; - } - - public String getAppid() { - return this.appid; - } - - public void setAppid(String appid) { - this.appid = appid; - } - - public String getMch_id() { - return this.mch_id; - } - - public void setMch_id(String mch_id) { - this.mch_id = mch_id; - } - - public String getNonce_str() { - return this.nonce_str; - } - - public void setNonce_str(String nonce_str) { - this.nonce_str = nonce_str; - } - - public String getSign() { - return this.sign; - } - - public void setSign(String sign) { - this.sign = sign; - } - - public String getResult_code() { - return this.result_code; - } - - public void setResult_code(String result_code) { - this.result_code = result_code; - } - - public String getPrepay_id() { - return this.prepay_id; - } - - public void setPrepay_id(String prepay_id) { - this.prepay_id = prepay_id; - } - - public String getTrade_type() { - return this.trade_type; - } - - public void setTrade_type(String trade_type) { - this.trade_type = trade_type; - } - - public String getErr_code() { - return this.err_code; - } - - public void setErr_code(String err_code) { - this.err_code = err_code; - } - - public String getErr_code_des() { - return this.err_code_des; - } - - public void setErr_code_des(String err_code_des) { - this.err_code_des = err_code_des; - } - - public String getCode_url() { - return this.code_url; - } - - public void setCode_url(String code_url) { - this.code_url = code_url; - } -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUser.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUser.java index 76670f02..19d03abf 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUser.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUser.java @@ -4,6 +4,9 @@ import java.io.Serializable; import java.lang.reflect.Type; import java.util.List; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; @@ -17,91 +20,111 @@ import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; */ public class WxMpUser implements Serializable { - /** - * @fields serialVersionUID - */ private static final long serialVersionUID = 5788154322646488738L; - protected Boolean subscribe; - protected String openId; - protected String nickname; - protected String sex; - protected String language; - protected String city; - protected String province; - protected String country; - protected String headImgUrl; - protected Long subscribeTime; - protected String unionId; - protected Integer sexId; - protected String remark; - protected Integer groupId; + private Boolean subscribe; + private String openId; + private String nickname; + private String sex; + private String language; + private String city; + private String province; + private String country; + private String headImgUrl; + private Long subscribeTime; + private String unionId; + private Integer sexId; + private String remark; + private Integer groupId; + private Integer[] tagIds; public Boolean getSubscribe() { return this.subscribe; } + public Boolean isSubscribe() { return this.subscribe; } + public void setSubscribe(Boolean subscribe) { this.subscribe = subscribe; } + public String getOpenId() { return this.openId; } + public void setOpenId(String openId) { this.openId = openId; } + public String getNickname() { return this.nickname; } + public void setNickname(String nickname) { this.nickname = nickname; } + public String getSex() { return this.sex; } + public void setSex(String sex) { this.sex = sex; } + public String getLanguage() { return this.language; } + public void setLanguage(String language) { this.language = language; } + public String getCity() { return this.city; } + public void setCity(String city) { this.city = city; } + public String getProvince() { return this.province; } + public void setProvince(String province) { this.province = province; } + public String getCountry() { return this.country; } + public void setCountry(String country) { this.country = country; } + public String getHeadImgUrl() { return this.headImgUrl; } + public void setHeadImgUrl(String headImgUrl) { this.headImgUrl = headImgUrl; } + public Long getSubscribeTime() { return this.subscribeTime; } + public void setSubscribeTime(Long subscribeTime) { this.subscribeTime = subscribeTime; } + public String getUnionId() { return this.unionId; } + public void setUnionId(String unionId) { this.unionId = unionId; } @@ -118,22 +141,34 @@ public class WxMpUser implements Serializable { public String getRemark() { return this.remark; } + public void setRemark(String remark) { this.remark = remark; } + public Integer getGroupId() { return this.groupId; } + public void setGroupId(Integer groupId) { this.groupId = groupId; } + public Integer[] getTagIds() { + return this.tagIds; + } + + public void setTagIds(Integer[] tagIds) { + this.tagIds = tagIds; + } + public static WxMpUser fromJson(String json) { return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpUser.class); } public static List