From f7d0a5d4c155cd6c1699527dfa597d59c6c0fcfa Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 1 Dec 2016 10:19:11 +0800 Subject: [PATCH 01/80] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=E4=B8=BAsnapshot=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- pom.xml | 2 +- weixin-java-common/pom.xml | 2 +- weixin-java-cp/pom.xml | 2 +- weixin-java-mp/pom.xml | 2 +- weixin-java-osgi/pom.xml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 64785fceb0..49d71c348f 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ allprojects { apply plugin: 'maven' group = 'com.github.binarywang' - version = '2.4.0' + version = '2.5.0-SNAPSHOT' } subprojects { diff --git a/pom.xml b/pom.xml index e168d12070..ef459ec1b4 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.github.binarywang weixin-java-parent - 2.4.0 + 2.5.0-SNAPSHOT pom WeiXin Java Tools - Parent 微信公众号、企业号上级POM diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml index 329da5a297..11d31bdd27 100644 --- a/weixin-java-common/pom.xml +++ b/weixin-java-common/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.0 + 2.5.0-SNAPSHOT weixin-java-common diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index 6b7c166535..2398a12cf5 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.0 + 2.5.0-SNAPSHOT weixin-java-cp diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index ba79d0ca82..7f3a8b39f6 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.0 + 2.5.0-SNAPSHOT weixin-java-mp WeiXin Java Tools - MP diff --git a/weixin-java-osgi/pom.xml b/weixin-java-osgi/pom.xml index ca14e47640..ec9d1b7d09 100644 --- a/weixin-java-osgi/pom.xml +++ b/weixin-java-osgi/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.0 + 2.5.0-SNAPSHOT weixin-java-osgi From 64619c21926473547075f2253fcc5c743ec97bae Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 5 Dec 2016 17:47:25 +0800 Subject: [PATCH 02/80] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=EF=BC=8C=E6=98=8E=E7=A1=AE=E8=AF=81=E4=B9=A6=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E7=9A=84=E5=90=AB=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/me/chanjar/weixin/mp/api/WxMpPayService.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 e1396afbb3..5f1f373bd7 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 @@ -81,7 +81,7 @@ public interface WxMpPayService { * * * @param request 请求对象 - * @param keyFile 证书文件对象 + * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) * @return 退款操作结果 */ WxPayRefundResult refund(WxPayRefundRequest request, File keyFile) throws WxErrorException; @@ -128,7 +128,7 @@ public interface WxMpPayService { * * * @param request 请求对象 - * @param keyFile 证书文件对象 + * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) */ WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File keyFile) throws WxErrorException; @@ -141,7 +141,7 @@ public interface WxMpPayService { * 请求方式 POST * * @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890 - * @param keyFile 证书文件对象 + * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) */ WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) throws WxErrorException; @@ -156,7 +156,7 @@ public interface WxMpPayService { * * * @param request 请求对象 - * @param keyFile 证书文件对象 + * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) */ WxEntPayResult entPay(WxEntPayRequest request, File keyFile) throws WxErrorException; @@ -169,7 +169,7 @@ public interface WxMpPayService { * * * @param partnerTradeNo 商户订单号 - * @param keyFile 证书文件对象 + * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) */ WxEntPayQueryResult queryEntPay(String partnerTradeNo, File keyFile) throws WxErrorException; From 41da9e15a648996af3d9e0272f83c69b5485f9a1 Mon Sep 17 00:00:00 2001 From: aimilin Date: Thu, 8 Dec 2016 20:44:03 +0800 Subject: [PATCH 03/80] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=9B=9E=E6=8E=89=E5=8A=9F=E8=83=BD=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpConfigStorage.java | 19 + .../mp/api/WxMpInMemoryConfigStorage.java | 21 +- .../chanjar/weixin/mp/api/WxMpPayService.java | 80 +++- .../mp/api/impl/WxMpMenuServiceImpl.java | 1 - .../mp/api/impl/WxMpPayServiceImpl.java | 246 +++++++---- .../mp/bean/message/WxMpXmlOutMessage.java | 3 +- .../mp/bean/pay/WxPayJsSDKCallback.java | 267 ----------- .../mp/bean/pay/WxPayOrderNotifyCoupon.java | 59 +++ .../mp/bean/pay/WxPayOrderNotifyResponse.java | 61 +++ .../pay/WxPayOrderNotifyResultConverter.java | 130 ++++++ .../pay/request/WxEntPayQueryRequest.java | 1 - .../mp/bean/pay/request/WxPayBaseRequest.java | 12 + .../pay/request/WxPayUnifiedOrderRequest.java | 8 + .../mp/bean/pay/result/WxPayBaseResult.java | 8 + .../pay/result/WxPayOrderNotifyResult.java | 414 ++++++++++++++++++ .../weixin/mp/builder/kefu/BaseBuilder.java | 3 +- .../weixin/mp/builder/outxml/BaseBuilder.java | 6 +- ...lVoiceAndImageDownloadRequestExecutor.java | 2 - 18 files changed, 962 insertions(+), 379 deletions(-) delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayJsSDKCallback.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyCoupon.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyResponse.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyResultConverter.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java index 78b1a587d6..d93c30804a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java @@ -4,6 +4,7 @@ import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder; import javax.net.ssl.SSLContext; + import java.io.File; import java.util.concurrent.locks.Lock; @@ -81,6 +82,23 @@ public interface WxMpConfigStorage { String getPartnerId(); String getPartnerKey(); + + /** + * 微信支付异步回掉地址,通知url必须为直接可访问的url,不能携带参数。 + * @since 2.5.0 + * @return + */ + String getNotifyURL(); + + /** + * 交易类型 + *
+   * JSAPI--公众号支付、NATIVE--原生扫码支付、APP--app支付
+   * 
+ * @since 2.5.0 + * @return + */ + String getTradeType(); String getToken(); @@ -112,4 +130,5 @@ public interface WxMpConfigStorage { * 是否自动刷新token */ boolean autoRefreshToken(); + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java index e874e793b8..61b75fbbaa 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java @@ -20,6 +20,8 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage { protected volatile String secret; protected volatile String partnerId; protected volatile String partnerKey; + protected volatile String notifyURL; + protected volatile String tradeType; protected volatile String token; protected volatile String accessToken; protected volatile String aesKey; @@ -267,8 +269,25 @@ public String getPartnerKey() { public void setPartnerKey(String partnerKey) { this.partnerKey = partnerKey; } + + + public String getNotifyURL() { + return notifyURL; + } - @Override + public void setNotifyURL(String notifyURL) { + this.notifyURL = notifyURL; + } + + public String getTradeType() { + return tradeType; + } + + public void setTradeType(String tradeType) { + this.tradeType = tradeType; + } + + @Override public File getTmpDirFile() { return this.tmpDirFile; } 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 5f1f373bd7..024ce4a801 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,7 +1,6 @@ package me.chanjar.weixin.mp.api; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.bean.pay.WxPayJsSDKCallback; import me.chanjar.weixin.mp.bean.pay.request.WxEntPayRequest; import me.chanjar.weixin.mp.bean.pay.request.WxPayRefundRequest; import me.chanjar.weixin.mp.bean.pay.request.WxPaySendRedpackRequest; @@ -107,15 +106,82 @@ public interface WxMpPayService { * 读取支付结果通知 * 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7 */ - WxPayJsSDKCallback getJSSDKCallbackData(String xmlData) throws WxErrorException; + WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxErrorException; + + /** + * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) + * + * @param xmlbean Bean需要标记有XML注解,默认使用配置中的PartnerKey进行签名 + * @since 2.5.0 + * @return 签名字符串 + * @see #createSign(Map, String) + */ + String createSign(Object xmlbean); + + /** + * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) + * @param xmlbean Bean需要标记有XML注解 + * @param signKey 签名Key + * @return 签名字符串 + * @see #createSign(Map, String) + */ + String createSign(Object xmlbean, String signKey); + + /** + * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) + * @param prams 参数信息,默认使用配置中的PartnerKey进行签名 + * @param signKey 签名Key + * @return 签名字符串 + * @see #createSign(Map, String) + */ + String createSign(Map prams); + + + /** + * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) + * @param prams 参数信息 + * @param signKey 签名Key + * @return 签名字符串 + */ + String createSign(Map prams, String signKey); + + /** - *
-   * 计算Map键值对是否和签名相符,
-   * 按照字段名的 ASCII 码从小到大排序(字典序)后,使用 URL 键值对的 格式(即 key1=value1&key2=value2...)拼接成字符串
-   * 
+ * 校验签名是否正确,默认使用配置中的PartnerKey进行签名 + * @param xmlbean Bean需要标记有XML注解 + * @return true - 签名校验成功,false - 签名校验失败 + * @see #checkSign(Map, String) + */ + boolean checkSign(Object xmlbean); + + /** + * 校验签名是否正确 + * @param xmlbean Bean需要标记有XML注解 + * @param signKey 校验的签名Key + * @return true - 签名校验成功,false - 签名校验失败 + * @see #checkSign(Map, String) + */ + boolean checkSign(Object xmlbean, String signKey); + + /** + * 校验签名是否正确,默认使用配置中的PartnerKey进行签名 + * @param prams 需要校验的参数Map + * @return true - 签名校验成功,false - 签名校验失败 + * @see #checkSign(Map, String) + */ + boolean checkSign(Map prams); + + /** + * 校验签名是否正确 + * @param prams 需要校验的参数Map + * @param signKey 校验的签名Key + * @return true - 签名校验成功,false - 签名校验失败 + * @see #checkSign(Map, String) */ - boolean checkJSSDKCallbackDataSignature(Map kvm, String signature); + boolean checkSign(Map prams, String signKey); + + /** * 发送微信红包给个人用户 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 1373c83d19..579d5c72dd 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 @@ -5,7 +5,6 @@ import me.chanjar.weixin.mp.api.WxMpMenuService; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult; -import me.chanjar.weixin.mp.bean.menu.WxMpSelfMenuInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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 78e76e0f7c..df4c5a5efd 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,15 +1,17 @@ package me.chanjar.weixin.mp.api.impl; -import com.thoughtworks.xstream.XStream; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.common.util.BeanUtils; -import me.chanjar.weixin.common.util.xml.XStreamInitializer; -import me.chanjar.weixin.mp.api.WxMpPayService; -import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.bean.pay.WxPayJsSDKCallback; -import me.chanjar.weixin.mp.bean.pay.request.*; -import me.chanjar.weixin.mp.bean.pay.result.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.security.KeyStore; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +import javax.net.ssl.SSLContext; + import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; @@ -27,12 +29,36 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.net.ssl.SSLContext; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.security.KeyStore; -import java.util.*; +import com.thoughtworks.xstream.XStream; + +import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.util.BeanUtils; +import me.chanjar.weixin.common.util.xml.XStreamInitializer; +import me.chanjar.weixin.mp.api.WxMpConfigStorage; +import me.chanjar.weixin.mp.api.WxMpPayService; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.pay.WxPayOrderNotifyResultConverter; +import me.chanjar.weixin.mp.bean.pay.request.WxEntPayQueryRequest; +import me.chanjar.weixin.mp.bean.pay.request.WxEntPayRequest; +import me.chanjar.weixin.mp.bean.pay.request.WxPayOrderCloseRequest; +import me.chanjar.weixin.mp.bean.pay.request.WxPayOrderQueryRequest; +import me.chanjar.weixin.mp.bean.pay.request.WxPayRedpackQueryRequest; +import me.chanjar.weixin.mp.bean.pay.request.WxPayRefundQueryRequest; +import me.chanjar.weixin.mp.bean.pay.request.WxPayRefundRequest; +import me.chanjar.weixin.mp.bean.pay.request.WxPaySendRedpackRequest; +import me.chanjar.weixin.mp.bean.pay.request.WxPayUnifiedOrderRequest; +import me.chanjar.weixin.mp.bean.pay.result.WxEntPayQueryResult; +import me.chanjar.weixin.mp.bean.pay.result.WxEntPayResult; +import me.chanjar.weixin.mp.bean.pay.result.WxPayBaseResult; +import me.chanjar.weixin.mp.bean.pay.result.WxPayOrderCloseResult; +import me.chanjar.weixin.mp.bean.pay.result.WxPayOrderNotifyResult; +import me.chanjar.weixin.mp.bean.pay.result.WxPayOrderQueryResult; +import me.chanjar.weixin.mp.bean.pay.result.WxPayRedpackQueryResult; +import me.chanjar.weixin.mp.bean.pay.result.WxPayRefundQueryResult; +import me.chanjar.weixin.mp.bean.pay.result.WxPayRefundResult; +import me.chanjar.weixin.mp.bean.pay.result.WxPaySendRedpackResult; +import me.chanjar.weixin.mp.bean.pay.result.WxPayUnifiedOrderResult; /** * Created by Binary Wang on 2016/7/28. @@ -47,9 +73,11 @@ public class WxMpPayServiceImpl implements WxMpPayService { "REFUND_SOURCE_UNSETTLED_FUNDS"}; protected final Logger log = LoggerFactory.getLogger(this.getClass()); private WxMpService wxMpService; + private WxMpConfigStorage config; public WxMpPayServiceImpl(WxMpService wxMpService) { this.wxMpService = wxMpService; + this.config = wxMpService.getWxMpConfigStorage(); } @Override @@ -61,13 +89,12 @@ public WxPayRefundResult refund(WxPayRefundRequest request, File keyFile) xstream.processAnnotations(WxPayRefundRequest.class); xstream.processAnnotations(WxPayRefundResult.class); - request.setAppid(this.wxMpService.getWxMpConfigStorage().getAppId()); - String partnerId = this.wxMpService.getWxMpConfigStorage().getPartnerId(); + request.setAppid(this.config.getAppId()); + String partnerId = this.config.getPartnerId(); request.setMchId(partnerId); request.setNonceStr(System.currentTimeMillis() + ""); request.setOpUserId(partnerId); - String sign = this.createSign(BeanUtils.xmlBean2Map(request), this.wxMpService.getWxMpConfigStorage().getPartnerKey()); - request.setSign(sign); + request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/secapi/pay/refund"; String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), partnerId); @@ -93,13 +120,10 @@ public WxPayRefundQueryResult refundQuery(String transactionId, String outTradeN request.setOutRefundNo(StringUtils.trimToNull(outRefundNo)); request.setRefundId(StringUtils.trimToNull(refundId)); - request.setAppid(this.wxMpService.getWxMpConfigStorage().getAppId()); - request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId()); + request.setAppid(this.config.getAppId()); + request.setMchId(this.config.getPartnerId()); request.setNonceStr(System.currentTimeMillis() + ""); - - String sign = this.createSign(BeanUtils.xmlBean2Map(request), - this.wxMpService.getWxMpConfigStorage().getPartnerKey()); - request.setSign(sign); + request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/pay/refundquery"; @@ -109,8 +133,15 @@ public WxPayRefundQueryResult refundQuery(String transactionId, String outTradeN this.checkResult(result); return result; } + private void checkResult(WxPayBaseResult result) throws WxErrorException { + //校验返回结果签名 + if(!checkSign(result.toMap())){ + throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("参数格式校验错误!").build()); + } + + //校验结果是否成功 if (!"SUCCESS".equalsIgnoreCase(result.getReturnCode()) || !"SUCCESS".equalsIgnoreCase(result.getResultCode())) { throw new WxErrorException(WxError.newBuilder().setErrorCode(-1) @@ -136,23 +167,23 @@ private void checkParameters(WxPayRefundRequest request) throws WxErrorException } @Override - public WxPayJsSDKCallback getJSSDKCallbackData(String xmlData) throws WxErrorException { + public WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxErrorException { try { XStream xstream = XStreamInitializer.getInstance(); - xstream.alias("xml", WxPayJsSDKCallback.class); - return (WxPayJsSDKCallback) xstream.fromXML(xmlData); - } catch (Exception e) { - e.printStackTrace(); + xstream.autodetectAnnotations(true); + xstream.registerConverter(new WxPayOrderNotifyResultConverter(xstream.getMapper(),xstream.getReflectionProvider())); + WxPayOrderNotifyResult result = (WxPayOrderNotifyResult) xstream.fromXML(xmlData); + this.checkResult(result); + return result; + }catch (WxErrorException e) { + log.error(e.getMessage(),e); + throw e; + }catch (Exception e) { + log.error(e.getMessage(),e); throw new WxErrorException(WxError.newBuilder().setErrorMsg("发生异常" + e.getMessage()).build()); } } - @Override - public boolean checkJSSDKCallbackDataSignature(Map kvm, - String signature) { - return signature.equals(this.createSign(kvm, - this.wxMpService.getWxMpConfigStorage().getPartnerKey())); - } @Override public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File keyFile) @@ -161,14 +192,11 @@ public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File xstream.processAnnotations(WxPaySendRedpackRequest.class); xstream.processAnnotations(WxPaySendRedpackResult.class); - request.setWxAppid(this.wxMpService.getWxMpConfigStorage().getAppId()); - String mchId = this.wxMpService.getWxMpConfigStorage().getPartnerId(); + request.setWxAppid(this.config.getAppId()); + String mchId = this.config.getPartnerId(); request.setMchId(mchId); request.setNonceStr(System.currentTimeMillis() + ""); - - String sign = this.createSign(BeanUtils.xmlBean2Map(request), - this.wxMpService.getWxMpConfigStorage().getPartnerKey()); - request.setSign(sign); + request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/sendredpack"; if (request.getAmtType() != null) { @@ -177,8 +205,7 @@ public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File } String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), mchId); - WxPaySendRedpackResult result = (WxPaySendRedpackResult) xstream - .fromXML(responseContent); + WxPaySendRedpackResult result = (WxPaySendRedpackResult) xstream.fromXML(responseContent); this.checkResult(result); return result; } @@ -193,13 +220,12 @@ public WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) thro request.setMchBillNo(mchBillNo); request.setBillType("MCHT"); - request.setAppid(this.wxMpService.getWxMpConfigStorage().getAppId()); - String mchId = this.wxMpService.getWxMpConfigStorage().getPartnerId(); + request.setAppid(this.config.getAppId()); + String mchId = this.config.getPartnerId(); request.setMchId(mchId); request.setNonceStr(System.currentTimeMillis() + ""); - String sign = this.createSign(BeanUtils.xmlBean2Map(request), - this.wxMpService.getWxMpConfigStorage().getPartnerKey()); + String sign = this.createSign(request); request.setSign(sign); String url = PAY_BASE_URL + "/mmpaymkttransfers/gethbinfo"; @@ -208,30 +234,59 @@ public WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) thro this.checkResult(result); return result; } + + @Override + public String createSign(Object xmlBean) { + return createSign(BeanUtils.xmlBean2Map(xmlBean),this.config.getPartnerKey()); + } + + @Override + public String createSign(Object xmlBean, String signKey) { + return createSign(BeanUtils.xmlBean2Map(xmlBean), signKey); + } + + @Override + public String createSign(Map params) { + return createSign(params,this.config.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); + @Override + public String createSign(Map params, String signKey) { + SortedMap sortedMap = new TreeMap<>(params); StringBuilder toSign = new StringBuilder(); for (String key : sortedMap.keySet()) { - String value = packageParams.get(key); - if (null != value && !"".equals(value) && !"sign".equals(key) - && !"key".equals(key)) { + String value = params.get(key); + if (StringUtils.isNotEmpty(value) && !"sign".equals(key) && !"key".equals(key)) { toSign.append(key + "=" + value + "&"); } } toSign.append("key=" + signKey); - return DigestUtils.md5Hex(toSign.toString()).toUpperCase(); } + + @Override + public boolean checkSign(Object xmlBean) { + return checkSign(BeanUtils.xmlBean2Map(xmlBean) , this.config.getPartnerKey()); + } + + @Override + public boolean checkSign(Object xmlBean, String signKey) { + return checkSign(BeanUtils.xmlBean2Map(xmlBean) , signKey); + } + + @Override + public boolean checkSign(Map params) { + return checkSign(params , this.config.getPartnerKey()); + } + + @Override + public boolean checkSign(Map params, String signKey) { + String sign = this.createSign(params , signKey); + return sign.equals(params.get("sign")); + } + @Override public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxErrorException { @@ -247,13 +302,10 @@ public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) WxPayOrderQueryRequest request = new WxPayOrderQueryRequest(); request.setOutTradeNo(StringUtils.trimToNull(outTradeNo)); request.setTransactionId(StringUtils.trimToNull(transactionId)); - request.setAppid(this.wxMpService.getWxMpConfigStorage().getAppId()); - request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId()); + request.setAppid(this.config.getAppId()); + request.setMchId(this.config.getPartnerId()); request.setNonceStr(System.currentTimeMillis() + ""); - - String sign = this.createSign(BeanUtils.xmlBean2Map(request), - this.wxMpService.getWxMpConfigStorage().getPartnerKey()); - request.setSign(sign); + request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/pay/orderquery"; @@ -276,13 +328,10 @@ public WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxErrorExcepti WxPayOrderCloseRequest request = new WxPayOrderCloseRequest(); request.setOutTradeNo(StringUtils.trimToNull(outTradeNo)); - request.setAppid(this.wxMpService.getWxMpConfigStorage().getAppId()); - request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId()); + request.setAppid(this.config.getAppId()); + request.setMchId(this.config.getPartnerId()); request.setNonceStr(System.currentTimeMillis() + ""); - - String sign = this.createSign(BeanUtils.xmlBean2Map(request), - this.wxMpService.getWxMpConfigStorage().getPartnerKey()); - request.setSign(sign); + request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/pay/closeorder"; @@ -302,13 +351,25 @@ public WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) xstream.processAnnotations(WxPayUnifiedOrderRequest.class); xstream.processAnnotations(WxPayUnifiedOrderResult.class); - request.setAppid(this.wxMpService.getWxMpConfigStorage().getAppId()); - request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId()); - request.setNonceStr(System.currentTimeMillis() + ""); - - String sign = this.createSign(BeanUtils.xmlBean2Map(request), - this.wxMpService.getWxMpConfigStorage().getPartnerKey()); - request.setSign(sign); + WxMpConfigStorage config = this.config; + + //如果没有设置,则使用配置中默认值 + if(StringUtils.isBlank(request.getAppid())){ + request.setAppid(config.getAppId()); + } + if(StringUtils.isBlank(request.getMchId())){ + request.setMchId(config.getPartnerId()); + } + if(StringUtils.isBlank(request.getNotifyURL())){ + request.setNotifyURL(config.getNotifyURL()); + } + if(StringUtils.isBlank(request.getTradeType())){ + request.setTradeType(config.getTradeType()); + } + if(StringUtils.isBlank(request.getNonceStr())){ + request.setNonceStr(System.currentTimeMillis() + ""); + } + request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/pay/unifiedorder"; @@ -345,7 +406,7 @@ public Map getPayInfo(WxPayUnifiedOrderRequest request) throws W } Map payInfo = new HashMap<>(); - payInfo.put("appId", this.wxMpService.getWxMpConfigStorage().getAppId()); + payInfo.put("appId", this.config.getAppId()); // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符 payInfo.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000)); payInfo.put("nonceStr", System.currentTimeMillis() + ""); @@ -354,9 +415,7 @@ public Map getPayInfo(WxPayUnifiedOrderRequest request) throws W if ("NATIVE".equals(request.getTradeType())) { payInfo.put("codeUrl", unifiedOrderResult.getCodeURL()); } - - String finalSign = this.createSign(payInfo, this.wxMpService.getWxMpConfigStorage().getPartnerKey()); - payInfo.put("paySign", finalSign); + payInfo.put("paySign", this.createSign(payInfo)); return payInfo; } @@ -368,12 +427,10 @@ public WxEntPayResult entPay(WxEntPayRequest request, File keyFile) throws WxErr xstream.processAnnotations(WxEntPayRequest.class); xstream.processAnnotations(WxEntPayResult.class); - request.setMchAppid(this.wxMpService.getWxMpConfigStorage().getAppId()); - request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId()); + request.setMchAppid(this.config.getAppId()); + request.setMchId(this.config.getPartnerId()); request.setNonceStr(System.currentTimeMillis() + ""); - - String sign = this.createSign(BeanUtils.xmlBean2Map(request), this.wxMpService.getWxMpConfigStorage().getPartnerKey()); - request.setSign(sign); + request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/promotion/transfers"; @@ -390,12 +447,10 @@ public WxEntPayQueryResult queryEntPay(String partnerTradeNo, File keyFile) thro xstream.processAnnotations(WxEntPayQueryResult.class); WxEntPayQueryRequest request = new WxEntPayQueryRequest(); - request.setAppid(this.wxMpService.getWxMpConfigStorage().getAppId()); - request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId()); + request.setAppid(this.config.getAppId()); + request.setMchId(this.config.getPartnerId()); request.setNonceStr(System.currentTimeMillis() + ""); - - String sign = this.createSign(BeanUtils.xmlBean2Map(request), this.wxMpService.getWxMpConfigStorage().getPartnerKey()); - request.setSign(sign); + request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/gettransferinfo"; @@ -456,5 +511,4 @@ private String executeRequestWithKeyFile(String url, File keyFile, String reques throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg(e.getMessage()).build(), e); } } - } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMessage.java index 5b8b81e56a..c0b53d46a3 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMessage.java @@ -62,7 +62,8 @@ public void setMsgType(String msgType) { this.msgType = msgType; } - public String toXml() { + @SuppressWarnings("unchecked") + public String toXml() { return XStreamTransformer.toXml((Class) this.getClass(), this); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayJsSDKCallback.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayJsSDKCallback.java deleted file mode 100644 index 07a3fe1674..0000000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayJsSDKCallback.java +++ /dev/null @@ -1,267 +0,0 @@ -package me.chanjar.weixin.mp.bean.pay; - -import me.chanjar.weixin.common.util.ToStringUtils; - -import java.io.Serializable; - -/** - *
- * 订单支付状态回调
- * 支付结果通知(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7)
- * /pre>
- *
- * @author ukid
- */
-public class WxPayJsSDKCallback implements Serializable {
-  private static final long serialVersionUID = -4143804055690843641L;
-  private String return_code;
-  private String return_msg;
-
-  private String appid;
-  private String mch_id;
-  private String device_info;
-  private String nonce_str;
-  private String sign;
-  private String result_code;
-  private String err_code;
-  private String err_code_des;
-  private String openid;
-  private String is_subscribe;
-  private String trade_type;
-  private String bank_type;
-  private String total_fee;
-  private String fee_type;
-  private String cash_fee;
-  private String cash_fee_type;
-  private String coupon_fee;
-  private String coupon_count;
-  private String coupon_batch_id_$n;
-  private String coupon_id_$n;
-  private String coupon_fee_$n;
-  private String transaction_id;
-  private String out_trade_no;
-  private String attach;
-  private String time_end;
-
-  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 getDevice_info() {
-    return this.device_info;
-  }
-
-  public void setDevice_info(String device_info) {
-    this.device_info = device_info;
-  }
-
-  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 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 getOpenid() {
-    return this.openid;
-  }
-
-  public void setOpenid(String openid) {
-    this.openid = openid;
-  }
-
-  public String getIs_subscribe() {
-    return this.is_subscribe;
-  }
-
-  public void setIs_subscribe(String is_subscribe) {
-    this.is_subscribe = is_subscribe;
-  }
-
-  public String getTrade_type() {
-    return this.trade_type;
-  }
-
-  public void setTrade_type(String trade_type) {
-    this.trade_type = trade_type;
-  }
-
-  public String getBank_type() {
-    return this.bank_type;
-  }
-
-  public void setBank_type(String bank_type) {
-    this.bank_type = bank_type;
-  }
-
-  public String getTotal_fee() {
-    return this.total_fee;
-  }
-
-  public void setTotal_fee(String total_fee) {
-    this.total_fee = total_fee;
-  }
-
-  public String getFee_type() {
-    return this.fee_type;
-  }
-
-  public void setFee_type(String fee_type) {
-    this.fee_type = fee_type;
-  }
-
-  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;
-  }
-
-  public String getCoupon_fee() {
-    return this.coupon_fee;
-  }
-
-  public void setCoupon_fee(String coupon_fee) {
-    this.coupon_fee = coupon_fee;
-  }
-
-  public String getCoupon_count() {
-    return this.coupon_count;
-  }
-
-  public void setCoupon_count(String coupon_count) {
-    this.coupon_count = coupon_count;
-  }
-
-  public String getCoupon_batch_id_$n() {
-    return this.coupon_batch_id_$n;
-  }
-
-  public void setCoupon_batch_id_$n(String coupon_batch_id_$n) {
-    this.coupon_batch_id_$n = coupon_batch_id_$n;
-  }
-
-  public String getCoupon_id_$n() {
-    return this.coupon_id_$n;
-  }
-
-  public void setCoupon_id_$n(String coupon_id_$n) {
-    this.coupon_id_$n = coupon_id_$n;
-  }
-
-  public String getCoupon_fee_$n() {
-    return this.coupon_fee_$n;
-  }
-
-  public void setCoupon_fee_$n(String coupon_fee_$n) {
-    this.coupon_fee_$n = coupon_fee_$n;
-  }
-
-  public String getTransaction_id() {
-    return this.transaction_id;
-  }
-
-  public void setTransaction_id(String transaction_id) {
-    this.transaction_id = transaction_id;
-  }
-
-  public String getOut_trade_no() {
-    return this.out_trade_no;
-  }
-
-  public void setOut_trade_no(String out_trade_no) {
-    this.out_trade_no = out_trade_no;
-  }
-
-  public String getAttach() {
-    return this.attach;
-  }
-
-  public void setAttach(String attach) {
-    this.attach = attach;
-  }
-
-  public String getTime_end() {
-    return this.time_end;
-  }
-
-  public void setTime_end(String time_end) {
-    this.time_end = time_end;
-  }
-
-  @Override
-  public String toString() {
-    return ToStringUtils.toSimpleString(this);
-  }
-
-}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyCoupon.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyCoupon.java
new file mode 100644
index 0000000000..7cea57ba2b
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyCoupon.java
@@ -0,0 +1,59 @@
+package me.chanjar.weixin.mp.bean.pay;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+
+/**
+ * 支付异步通知代金券详细
+ */
+public class WxPayOrderNotifyCoupon implements Serializable {
+	/**
+	 * @fields serialVersionUID 
+	 */
+	private static final long serialVersionUID = -4165343733538156097L;
+	
+	@XStreamAlias("coupon_id")
+	private String couponId;
+	@XStreamAlias("coupon_type")
+	private String couponType;
+	@XStreamAlias("coupon_fee")
+	private Integer couponFee;
+	
+	public String getCouponId() {
+		return couponId;
+	}
+	public void setCouponId(String couponId) {
+		this.couponId = couponId;
+	}
+	public String getCouponType() {
+		return couponType;
+	}
+	public void setCouponType(String couponType) {
+		this.couponType = couponType;
+	}
+	public Integer getCouponFee() {
+		return couponFee;
+	}
+	public void setCouponFee(Integer couponFee) {
+		this.couponFee = couponFee;
+	}
+	
+	public Map toMap(int index){
+		Map map = new HashMap<>();
+		map.put("coupon_id_"+index, this.getCouponId());
+		map.put("coupon_type_"+index, this.getCouponType());
+		map.put("coupon_fee_"+index, this.getCouponFee()+"");
+		return map;
+	}
+	
+	@Override
+	public String toString() {
+		return ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE);
+	}
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyResponse.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyResponse.java
new file mode 100644
index 0000000000..54f4fc5658
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyResponse.java
@@ -0,0 +1,61 @@
+package me.chanjar.weixin.mp.bean.pay;
+
+
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import com.thoughtworks.xstream.annotations.XStreamOmitField;
+
+import me.chanjar.weixin.common.util.xml.XStreamInitializer;
+
+@XStreamAlias("xml")
+public class WxPayOrderNotifyResponse {
+	@XStreamOmitField
+	private transient static final String FAIL ="FAIL";
+	@XStreamOmitField
+	private transient static final String SUCCESS ="SUCCESS";
+	
+	@XStreamAlias("return_code")
+	private String returnCode;
+	@XStreamAlias("return_msg")
+	private String returnMsg;
+	
+	
+	public String getReturnCode() {
+		return returnCode;
+	}
+	public void setReturnCode(String returnCode) {
+		this.returnCode = returnCode;
+	}
+	public String getReturnMsg() {
+		return returnMsg;
+	}
+	public void setReturnMsg(String returnMsg) {
+		this.returnMsg = returnMsg;
+	}
+	
+
+	public WxPayOrderNotifyResponse() {
+		super();
+	}
+	public WxPayOrderNotifyResponse(String returnCode, String returnMsg) {
+		super();
+		this.returnCode = returnCode;
+		this.returnMsg = returnMsg;
+	}
+	
+	
+	public static String fail(String msg){
+		WxPayOrderNotifyResponse response =	new WxPayOrderNotifyResponse(FAIL,msg);
+		XStream xstream = XStreamInitializer.getInstance();
+		xstream.autodetectAnnotations(true);
+		return xstream.toXML(response);
+	}
+	
+	
+	public static String success(String msg){
+		WxPayOrderNotifyResponse response =	new WxPayOrderNotifyResponse(SUCCESS,msg);
+		XStream xstream = XStreamInitializer.getInstance();
+		xstream.autodetectAnnotations(true);
+		return xstream.toXML(response);
+	}
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyResultConverter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyResultConverter.java
new file mode 100644
index 0000000000..1f90f0b9e9
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyResultConverter.java
@@ -0,0 +1,130 @@
+package me.chanjar.weixin.mp.bean.pay;
+
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Maps;
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import com.thoughtworks.xstream.converters.MarshallingContext;
+import com.thoughtworks.xstream.converters.UnmarshallingContext;
+import com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter;
+import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
+import com.thoughtworks.xstream.io.HierarchicalStreamReader;
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+import com.thoughtworks.xstream.mapper.Mapper;
+
+import me.chanjar.weixin.mp.bean.pay.result.WxPayOrderNotifyResult;
+
+public class WxPayOrderNotifyResultConverter extends AbstractReflectionConverter {
+
+	public WxPayOrderNotifyResultConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
+		super(mapper, reflectionProvider);
+	}
+
+	@Override
+	@SuppressWarnings("rawtypes")
+	public boolean canConvert(Class type) {
+		return type.equals(WxPayOrderNotifyResult.class);
+	}
+
+	@Override
+	public void marshal(Object original, HierarchicalStreamWriter writer, MarshallingContext context) {
+		super.marshal(original, writer, context);
+		WxPayOrderNotifyResult obj = (WxPayOrderNotifyResult) original;
+		List list = obj.getCouponList();
+		if (list == null || list.size() == 0) {
+			return;
+		}
+		for (int i = 0; i < list.size(); i++) {
+			WxPayOrderNotifyCoupon coupon = list.get(i);
+			writer.startNode("coupon_id_" + i);
+			writer.setValue(coupon.getCouponId());
+			writer.endNode();
+			writer.startNode("coupon_type_" + i);
+			writer.setValue(coupon.getCouponType());
+			writer.endNode();
+			writer.startNode("coupon_fee_" + i);
+			writer.setValue(coupon.getCouponFee() + "");
+			writer.endNode();
+		}
+	}
+
+	@Override
+	protected void marshallField(MarshallingContext context, Object newObj, Field field) {
+		if (field.getName().equals("couponList")) {
+			return;
+		} else {
+			super.marshallField(context, newObj, field);
+		}
+	}
+
+	@Override
+	public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
+		WxPayOrderNotifyResult obj = new WxPayOrderNotifyResult();
+
+		List fields = new ArrayList<>(Arrays.asList(obj.getClass().getDeclaredFields()));
+		fields.addAll(Arrays.asList(obj.getClass().getSuperclass().getDeclaredFields()));
+		Map fieldMap = getFieldMap(fields);
+
+		List coupons = new ArrayList<>(10);
+		while (reader.hasMoreChildren()) {
+			reader.moveDown();
+			if (fieldMap.containsKey(reader.getNodeName())) {
+				Field field = fieldMap.get(reader.getNodeName());
+				setFieldValue(context, obj, field);
+			} else if (StringUtils.startsWith(reader.getNodeName(), "coupon_id_")) {
+				String id = (String) context.convertAnother(obj, String.class);
+				getIndex(coupons, reader.getNodeName()).setCouponId(id);
+			} else if (StringUtils.startsWith(reader.getNodeName(), "coupon_type_")) {
+				String type = (String) context.convertAnother(obj, String.class);
+				getIndex(coupons, reader.getNodeName()).setCouponType(type);
+			} else if (StringUtils.startsWith(reader.getNodeName(), "coupon_fee_")) {
+				Integer fee = (Integer) context.convertAnother(obj, Integer.class);
+				getIndex(coupons, reader.getNodeName()).setCouponFee(fee);
+			}
+			reader.moveUp();
+		}
+
+		obj.setCouponList(coupons);
+		return obj;
+	}
+
+	private void setFieldValue(UnmarshallingContext context, WxPayOrderNotifyResult obj, Field field) {
+		Object val = context.convertAnother(obj, field.getType());
+		try {
+			if (val != null) {
+				PropertyDescriptor pd = new PropertyDescriptor(field.getName(), obj.getClass());
+				pd.getWriteMethod().invoke(obj, val);
+			}
+		} catch (Exception e) {
+		}
+	}
+
+	private Map getFieldMap(List fields) {
+		Map fieldMap = Maps.uniqueIndex(fields, new Function() {
+			@Override
+			public String apply(Field field) {
+				if (field.isAnnotationPresent(XStreamAlias.class)) {
+					return field.getAnnotation(XStreamAlias.class).value();
+				}
+				return field.getName();
+			}
+		});
+		return fieldMap;
+	}
+
+	private WxPayOrderNotifyCoupon getIndex(List coupons, String nodeName) {
+		Integer index = Integer.valueOf(StringUtils.substring(nodeName, nodeName.lastIndexOf("_") + 1));
+		if (index >= coupons.size() || coupons.get(index) == null) {
+			coupons.add(index, new WxPayOrderNotifyCoupon());
+		}
+		return coupons.get(index);
+	}
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxEntPayQueryRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxEntPayQueryRequest.java
index 5982d3ee13..df2de9051c 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxEntPayQueryRequest.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxEntPayQueryRequest.java
@@ -30,7 +30,6 @@ public class WxEntPayQueryRequest extends WxPayBaseRequest {
    * 微信支付分配的商户号
    * 
*/ - @SuppressWarnings("hiding") @XStreamAlias("mchid") private String mchId; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java index 341c3b2e04..9ede16ec15 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java @@ -71,6 +71,10 @@ public String getAppid() { return this.appid; } + /** + * 如果配置中已经设置,可以不设置值 + * @param appid + */ public void setAppid(String appid) { this.appid = appid; } @@ -79,6 +83,10 @@ public String getMchId() { return this.mchId; } + /** + * 如果配置中已经设置,可以不设置值 + * @param mchId + */ public void setMchId(String mchId) { this.mchId = mchId; } @@ -87,6 +95,10 @@ public String getNonceStr() { return this.nonceStr; } + /** + * 默认采用时间戳为随机字符串,可以不设置 + * @param nonceStr + */ public void setNonceStr(String nonceStr) { this.nonceStr = nonceStr; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayUnifiedOrderRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayUnifiedOrderRequest.java index 195e13b0fe..cf4c008fdb 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayUnifiedOrderRequest.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayUnifiedOrderRequest.java @@ -360,6 +360,10 @@ public String getNotifyURL() { return this.notifyURL; } + /** + * 如果配置中已经设置,可以不设置值 + * @param notifyURL + */ public void setNotifyURL(String notifyURL) { this.notifyURL = notifyURL; } @@ -368,6 +372,10 @@ public String getTradeType() { return this.tradeType; } + /** + * 如果配置中已经设置,可以不设置值 + * @param tradeType 交易类型 + */ public void setTradeType(String tradeType) { this.tradeType = tradeType; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java index 6431013837..d74553770d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java @@ -1,6 +1,10 @@ package me.chanjar.weixin.mp.bean.pay.result; +import java.util.Map; + import com.thoughtworks.xstream.annotations.XStreamAlias; + +import me.chanjar.weixin.common.util.BeanUtils; import me.chanjar.weixin.common.util.ToStringUtils; /** @@ -141,4 +145,8 @@ public String getSign() { public void setSign(String sign) { this.sign = sign; } + + public Map toMap(){ + return BeanUtils.xmlBean2Map(this); + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java new file mode 100644 index 0000000000..0a6815d8c8 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java @@ -0,0 +1,414 @@ +package me.chanjar.weixin.mp.bean.pay.result; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +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.util.BeanUtils; +import me.chanjar.weixin.mp.bean.pay.WxPayOrderNotifyCoupon; + +/** + * 支付结果通用通知 ,文档见:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7 + * @author aimilin6688 + * @since 2.5.0 + */ +@XStreamAlias("xml") +public class WxPayOrderNotifyResult extends WxPayBaseResult implements Serializable { + + /** + * @fields serialVersionUID + */ + private static final long serialVersionUID = 5389718115223345496L; + + + /** + *
+	 * 设备号
+	 * device_info	
+	 * 否	
+	 * String(32)	
+	 * 013467007045764	
+	 * 微信支付分配的终端设备号,
+	 * 
+ * @fields deviceInfo + */ + @XStreamAlias("device_info") + private String deviceInfo; + + /** + *
+	 * 用户标识	
+	 * openid	
+	 * 是	
+	 * String(128)	
+	 * wxd930ea5d5a258f4f	
+	 * 用户在商户appid下的唯一标识
+	 * 
+ * @fields openid + */ + @XStreamAlias("openid") + private String openid; + + /** + *
+	 * 是否关注公众账号	
+	 * is_subscribe	
+	 * 否	
+	 * String(1)	
+	 * Y	
+	 * 用户是否关注公众账号,Y-关注,N-未关注,仅在公众账号类型支付有效
+	 * 
+ * @fields isSubscribe + */ + @XStreamAlias("is_subscribe") + private String isSubscribe; + + + /** + *
+	 * 交易类型	
+	 * trade_type	
+	 * 是	
+	 * String(16)	
+	 * JSAPI	JSAPI、NATIVE、APP
+	 * 
+ * @fields tradeType + */ + @XStreamAlias("trade_type") + private String tradeType; + + + /** + *
+	 * 付款银行	
+	 * bank_type	
+	 * 是	
+	 * String(16)	
+	 * CMC	
+	 * 银行类型,采用字符串类型的银行标识,银行类型见银行列表
+	 * 
+ * @fields bankType + */ + @XStreamAlias("bank_type") + private String bankType; + + + /** + *
+	 * 订单金额	
+	 * total_fee	
+	 * 是	
+	 * Int	
+	 * 100	
+	 * 订单总金额,单位为分
+	 * 
+ * @fields totalFee + */ + @XStreamAlias("total_fee") + private Integer totalFee; + /** + *
+	 * 应结订单金额	
+	 * settlement_total_fee	
+	 * 否	
+	 * Int	
+	 * 100	
+	 * 应结订单金额=订单金额-非充值代金券金额,应结订单金额<=订单金额。
+	 * 
+ * @fields settlementTotalFee + */ + @XStreamAlias("settlement_total_fee") + private Integer settlementTotalFee; + /** + *
+	 * 货币种类	
+	 * fee_type	
+	 * 否	
+	 * String(8)	
+	 * CNY	
+	 * 货币类型,符合ISO4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
+	 * 
+ * @fields feeType + */ + @XStreamAlias("fee_type") + private String feeType; + /** + *
+	 * 现金支付金额	
+	 * cash_fee	
+	 * 是	
+	 * Int	
+	 * 100	
+	 * 现金支付金额订单现金支付金额,详见支付金额
+	 * 
+ * @fields cashFee + */ + @XStreamAlias("cash_fee") + private Integer cashFee; + /** + *
+	 * 现金支付货币类型	
+	 * cash_fee_type	
+	 * 否	
+	 * String(16)	
+	 * CNY	
+	 * 货币类型,符合ISO4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
+	 * 
+ * @fields cashFeeType + */ + @XStreamAlias("cash_fee_type") + private String cashFeeType; + /** + *
+	 * 总代金券金额	
+	 * coupon_fee	
+	 * 否	
+	 * Int	
+	 * 10	
+	 * 代金券金额<=订单金额,订单金额-代金券金额=现金支付金额,详见支付金额
+	 * 
+ * @fields couponFee + */ + @XStreamAlias("coupon_fee") + private Integer couponFee; + + /** + *
+   * 代金券使用数量
+   * coupon_count
+   * 否
+   * Int
+   * 1
+   * 代金券使用数量
+   */
+	@XStreamAlias("coupon_count")
+	private Integer couponCount;
+	
+	private List couponList;
+	
+	
+	
+	/**
+	 * 
+	 * 微信支付订单号	
+	 * transaction_id	
+	 * 是	
+	 * String(32)	
+	 * 1217752501201407033233368018	
+	 * 微信支付订单号
+	 * 
+ * @fields transactionId + */ + @XStreamAlias("transaction_id") + private String transactionId; + + /** + *
+	 * 商户订单号	
+	 * out_trade_no	
+	 * 是	
+	 * String(32)	
+	 * 1212321211201407033568112322	
+	 * 商户系统的订单号,与请求一致。
+	 * 
+ * @fields outTradeNo + */ + @XStreamAlias("out_trade_no") + private String outTradeNo; + /** + *
+	 * 商家数据包	
+	 * attach	
+	 * 否	
+	 * String(128)	
+	 * 123456	
+	 * 商家数据包,原样返回
+	 * 
+ * @fields + */ + @XStreamAlias("attach") + private String attach; + /** + *
+	 * 支付完成时间	
+	 * time_end	
+	 * 是	
+	 * String(14)	
+	 * 20141030133525	
+	 * 支付完成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则
+	 * 
+ * @fields timeEnd + */ + @XStreamAlias("time_end") + private String timeEnd; + + + public Integer getCouponCount() { + return couponCount; + } + + public void setCouponCount(Integer couponCount) { + this.couponCount = couponCount; + } + + public List getCouponList() { + return couponList; + } + + public void setCouponList(List couponList) { + this.couponList = couponList; + } + + public String getDeviceInfo() { + return deviceInfo; + } + + public void setDeviceInfo(String deviceInfo) { + this.deviceInfo = deviceInfo; + } + + public String getOpenid() { + return openid; + } + + public void setOpenid(String openid) { + this.openid = openid; + } + + public String getIsSubscribe() { + return isSubscribe; + } + + public void setIsSubscribe(String isSubscribe) { + this.isSubscribe = isSubscribe; + } + + public String getTradeType() { + return tradeType; + } + + public void setTradeType(String tradeType) { + this.tradeType = tradeType; + } + + public String getBankType() { + return bankType; + } + + public void setBankType(String bankType) { + this.bankType = bankType; + } + + public Integer getTotalFee() { + return totalFee; + } + + public void setTotalFee(Integer totalFee) { + this.totalFee = totalFee; + } + + public Integer getSettlementTotalFee() { + return settlementTotalFee; + } + + public void setSettlementTotalFee(Integer settlementTotalFee) { + this.settlementTotalFee = settlementTotalFee; + } + + public String getFeeType() { + return feeType; + } + + public void setFeeType(String feeType) { + this.feeType = feeType; + } + + public Integer getCashFee() { + return cashFee; + } + + public void setCashFee(Integer cashFee) { + this.cashFee = cashFee; + } + + public String getCashFeeType() { + return cashFeeType; + } + + public void setCashFeeType(String cashFeeType) { + this.cashFeeType = cashFeeType; + } + + public Integer getCouponFee() { + return couponFee; + } + + public void setCouponFee(Integer couponFee) { + this.couponFee = couponFee; + } + + public String getTransactionId() { + return transactionId; + } + + public void setTransactionId(String transactionId) { + this.transactionId = transactionId; + } + + public String getOutTradeNo() { + return outTradeNo; + } + + public void setOutTradeNo(String outTradeNo) { + this.outTradeNo = outTradeNo; + } + + public String getAttach() { + return attach; + } + + public void setAttach(String attach) { + this.attach = attach; + } + + public String getTimeEnd() { + return timeEnd; + } + + public void setTimeEnd(String timeEnd) { + this.timeEnd = timeEnd; + } + + @Override + public Map toMap(){ + Map resultMap = BeanUtils.xmlBean2Map(this); + if(this.getCouponCount() > 0){ + for (int i = 0; i < this.getCouponCount(); i++) { + WxPayOrderNotifyCoupon coupon = couponList.get(i); + resultMap.putAll(coupon.toMap(i)); + } + } + return resultMap; + } + + + /** + * 将单位分转换成单位圆 + * @param fee + * @return + */ + public static String feeToYuan(Integer fee) { + return new BigDecimal(Double.valueOf(fee) / 100).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString(); + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE); + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/BaseBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/BaseBuilder.java index c5285d6f78..3e40d17836 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/BaseBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/BaseBuilder.java @@ -6,7 +6,8 @@ public class BaseBuilder { protected String msgType; protected String toUser; - public T toUser(String toUser) { + @SuppressWarnings("unchecked") + public T toUser(String toUser) { this.toUser = toUser; return (T) this; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/BaseBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/BaseBuilder.java index e594565cb7..60cf675d66 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/BaseBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/BaseBuilder.java @@ -8,12 +8,14 @@ public abstract class BaseBuilder { protected String fromUserName; - public BuilderType toUser(String touser) { + @SuppressWarnings("unchecked") + public BuilderType toUser(String touser) { this.toUserName = touser; return (BuilderType) this; } - public BuilderType fromUser(String fromusername) { + @SuppressWarnings("unchecked") + public BuilderType fromUser(String fromusername) { this.fromUserName = fromusername; return (BuilderType) this; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVoiceAndImageDownloadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVoiceAndImageDownloadRequestExecutor.java index c40366cab4..ceda65a687 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVoiceAndImageDownloadRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVoiceAndImageDownloadRequestExecutor.java @@ -23,7 +23,6 @@ public class MaterialVoiceAndImageDownloadRequestExecutor implements RequestExecutor { - private File tmpDirFile; public MaterialVoiceAndImageDownloadRequestExecutor() { super(); @@ -31,7 +30,6 @@ public MaterialVoiceAndImageDownloadRequestExecutor() { public MaterialVoiceAndImageDownloadRequestExecutor(File tmpDirFile) { super(); - this.tmpDirFile = tmpDirFile; } @Override From 8bb70942c327062f8e6fc9eade7f32dac16e8a14 Mon Sep 17 00:00:00 2001 From: aimilin Date: Fri, 9 Dec 2016 12:20:00 +0800 Subject: [PATCH 04/80] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/common/util/BeanUtils.java | 78 ++++--- .../mp/api/impl/WxMpPayServiceImpl.java | 107 ++++----- .../mp/bean/pay/WxPayOrderNotifyCoupon.java | 91 ++++---- .../mp/bean/pay/WxPayOrderNotifyResponse.java | 99 +++++---- .../pay/WxPayOrderNotifyResultConverter.java | 206 +++++++++--------- .../pay/result/WxPayOrderNotifyResult.java | 2 +- 6 files changed, 297 insertions(+), 286 deletions(-) diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/BeanUtils.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/BeanUtils.java index 8935bc32ec..7c3db11f80 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/BeanUtils.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/BeanUtils.java @@ -1,18 +1,22 @@ package me.chanjar.weixin.common.util; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.thoughtworks.xstream.annotations.XStreamAlias; + import me.chanjar.weixin.common.annotation.Required; import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - /** *
  * bean操作的一些工具类
@@ -21,6 +25,7 @@
  * 
*/ public class BeanUtils { + private static Logger log = LoggerFactory.getLogger(BeanUtils.class); /** * 检查bean里标记为@Required的field是否为空,为空则抛异常 @@ -48,41 +53,42 @@ public static void checkRequiredFields(Object bean) throws WxErrorException { } if (!nullFields.isEmpty()) { - throw new WxErrorException(WxError.newBuilder().setErrorMsg("必填字段 " + nullFields + " 必须提供值").build()); + String msg = "必填字段 " + nullFields + " 必须提供值"; + log.debug(msg); + throw new WxErrorException(WxError.newBuilder().setErrorMsg(msg).build()); } } - /** - * 将bean按照@XStreamAlias标识的字符串内容生成以之为key的map对象 - * @param bean 包含@XStreamAlias的xml bean对象 - * @return map对象 - */ - public static Map xmlBean2Map(Object bean) { - Map result = Maps.newHashMap(); - List fields = new ArrayList<>( Arrays.asList(bean.getClass().getDeclaredFields())); - fields.addAll(Arrays.asList(bean.getClass().getSuperclass().getDeclaredFields())); - for (Field field : fields) { - try { - boolean isAccessible = field.isAccessible(); - field.setAccessible(true); - if (field.get(bean) == null) { - field.setAccessible(isAccessible); - continue; - } + /** + * 将bean按照@XStreamAlias标识的字符串内容生成以之为key的map对象 + * + * @param bean 包含@XStreamAlias的xml bean对象 + * @return map对象 + */ + public static Map xmlBean2Map(Object bean) { + Map result = Maps.newHashMap(); + List fields = new ArrayList<>(Arrays.asList(bean.getClass().getDeclaredFields())); + fields.addAll(Arrays.asList(bean.getClass().getSuperclass().getDeclaredFields())); + for (Field field : fields) { + try { + boolean isAccessible = field.isAccessible(); + field.setAccessible(true); + if (field.get(bean) == null) { + field.setAccessible(isAccessible); + continue; + } - if (field.isAnnotationPresent(XStreamAlias.class)) { - result.put(field.getAnnotation(XStreamAlias.class).value(), - field.get(bean).toString()); - } + if (field.isAnnotationPresent(XStreamAlias.class)) { + result.put(field.getAnnotation(XStreamAlias.class).value(), field.get(bean).toString()); + } - field.setAccessible(isAccessible); - } catch (SecurityException | IllegalArgumentException - | IllegalAccessException e) { - e.printStackTrace(); - } + field.setAccessible(isAccessible); + } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + } - } + } - return result; - } + return result; + } } 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 df4c5a5efd..84655a86aa 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 @@ -73,11 +73,17 @@ public class WxMpPayServiceImpl implements WxMpPayService { "REFUND_SOURCE_UNSETTLED_FUNDS"}; protected final Logger log = LoggerFactory.getLogger(this.getClass()); private WxMpService wxMpService; - private WxMpConfigStorage config; + private WxMpConfigStorage config = null; public WxMpPayServiceImpl(WxMpService wxMpService) { this.wxMpService = wxMpService; - this.config = wxMpService.getWxMpConfigStorage(); + } + + private WxMpConfigStorage getConfig(){ + if(config == null){ + this.config = wxMpService.getWxMpConfigStorage(); + } + return this.config; } @Override @@ -89,8 +95,8 @@ public WxPayRefundResult refund(WxPayRefundRequest request, File keyFile) xstream.processAnnotations(WxPayRefundRequest.class); xstream.processAnnotations(WxPayRefundResult.class); - request.setAppid(this.config.getAppId()); - String partnerId = this.config.getPartnerId(); + request.setAppid(getConfig().getAppId()); + String partnerId = getConfig().getPartnerId(); request.setMchId(partnerId); request.setNonceStr(System.currentTimeMillis() + ""); request.setOpUserId(partnerId); @@ -120,8 +126,8 @@ public WxPayRefundQueryResult refundQuery(String transactionId, String outTradeN request.setOutRefundNo(StringUtils.trimToNull(outRefundNo)); request.setRefundId(StringUtils.trimToNull(refundId)); - request.setAppid(this.config.getAppId()); - request.setMchId(this.config.getPartnerId()); + request.setAppid(getConfig().getAppId()); + request.setMchId(getConfig().getPartnerId()); request.setNonceStr(System.currentTimeMillis() + ""); request.setSign(this.createSign(request)); @@ -138,17 +144,20 @@ public WxPayRefundQueryResult refundQuery(String transactionId, String outTradeN private void checkResult(WxPayBaseResult result) throws WxErrorException { //校验返回结果签名 if(!checkSign(result.toMap())){ + log.debug("校验结果签名失败,参数:{}",result.toMap()); throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("参数格式校验错误!").build()); } //校验结果是否成功 if (!"SUCCESS".equalsIgnoreCase(result.getReturnCode()) || !"SUCCESS".equalsIgnoreCase(result.getResultCode())) { - throw new WxErrorException(WxError.newBuilder().setErrorCode(-1) - .setErrorMsg("返回代码: " + result.getReturnCode() + ", 返回信息: " - + result.getReturnMsg() + ", 结果代码: " + result.getResultCode() + ", 错误代码: " - + result.getErrCode() + ", 错误详情: " + result.getErrCodeDes()) - .build()); + WxError error = WxError.newBuilder().setErrorCode(-1) + .setErrorMsg("返回代码: " + result.getReturnCode() + ", 返回信息: " + + result.getReturnMsg() + ", 结果代码: " + result.getResultCode() + ", 错误代码: " + + result.getErrCode() + ", 错误详情: " + result.getErrCodeDes()) + .build(); + log.debug("结果校验失败,参数:{},详细:{}",result.toMap(),error); + throw new WxErrorException(error); } } @@ -157,7 +166,7 @@ private void checkParameters(WxPayRefundRequest request) throws WxErrorException if (StringUtils.isNotBlank(request.getRefundAccount())) { if (!ArrayUtils.contains(REFUND_ACCOUNT, request.getRefundAccount())) { - throw new IllegalArgumentException("refund_account目前必须为" + Arrays.toString(REFUND_ACCOUNT) + "其中之一"); + throw new IllegalArgumentException("refund_account目前必须为" + Arrays.toString(REFUND_ACCOUNT) + "其中之一,实际值:"+ request.getRefundAccount()); } } @@ -169,10 +178,12 @@ private void checkParameters(WxPayRefundRequest request) throws WxErrorException @Override public WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxErrorException { try { + log.trace("微信支付回调参数详细:{}", xmlData); XStream xstream = XStreamInitializer.getInstance(); - xstream.autodetectAnnotations(true); + xstream.processAnnotations(WxPayOrderNotifyResult.class); xstream.registerConverter(new WxPayOrderNotifyResultConverter(xstream.getMapper(),xstream.getReflectionProvider())); WxPayOrderNotifyResult result = (WxPayOrderNotifyResult) xstream.fromXML(xmlData); + log.debug("微信支付回调结果对象:{}",result); this.checkResult(result); return result; }catch (WxErrorException e) { @@ -192,8 +203,8 @@ public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File xstream.processAnnotations(WxPaySendRedpackRequest.class); xstream.processAnnotations(WxPaySendRedpackResult.class); - request.setWxAppid(this.config.getAppId()); - String mchId = this.config.getPartnerId(); + request.setWxAppid(getConfig().getAppId()); + String mchId = getConfig().getPartnerId(); request.setMchId(mchId); request.setNonceStr(System.currentTimeMillis() + ""); request.setSign(this.createSign(request)); @@ -220,8 +231,8 @@ public WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) thro request.setMchBillNo(mchBillNo); request.setBillType("MCHT"); - request.setAppid(this.config.getAppId()); - String mchId = this.config.getPartnerId(); + request.setAppid(getConfig().getAppId()); + String mchId = getConfig().getPartnerId(); request.setMchId(mchId); request.setNonceStr(System.currentTimeMillis() + ""); @@ -237,7 +248,7 @@ public WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) thro @Override public String createSign(Object xmlBean) { - return createSign(BeanUtils.xmlBean2Map(xmlBean),this.config.getPartnerKey()); + return createSign(BeanUtils.xmlBean2Map(xmlBean),getConfig().getPartnerKey()); } @Override @@ -247,7 +258,7 @@ public String createSign(Object xmlBean, String signKey) { @Override public String createSign(Map params) { - return createSign(params,this.config.getPartnerKey()); + return createSign(params,getConfig().getPartnerKey()); } @Override @@ -268,7 +279,7 @@ public String createSign(Map params, String signKey) { @Override public boolean checkSign(Object xmlBean) { - return checkSign(BeanUtils.xmlBean2Map(xmlBean) , this.config.getPartnerKey()); + return checkSign(BeanUtils.xmlBean2Map(xmlBean) , getConfig().getPartnerKey()); } @Override @@ -278,7 +289,7 @@ public boolean checkSign(Object xmlBean, String signKey) { @Override public boolean checkSign(Map params) { - return checkSign(params , this.config.getPartnerKey()); + return checkSign(params , getConfig().getPartnerKey()); } @Override @@ -302,8 +313,8 @@ public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) WxPayOrderQueryRequest request = new WxPayOrderQueryRequest(); request.setOutTradeNo(StringUtils.trimToNull(outTradeNo)); request.setTransactionId(StringUtils.trimToNull(transactionId)); - request.setAppid(this.config.getAppId()); - request.setMchId(this.config.getPartnerId()); + request.setAppid(getConfig().getAppId()); + request.setMchId(getConfig().getPartnerId()); request.setNonceStr(System.currentTimeMillis() + ""); request.setSign(this.createSign(request)); @@ -328,8 +339,8 @@ public WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxErrorExcepti WxPayOrderCloseRequest request = new WxPayOrderCloseRequest(); request.setOutTradeNo(StringUtils.trimToNull(outTradeNo)); - request.setAppid(this.config.getAppId()); - request.setMchId(this.config.getPartnerId()); + request.setAppid(getConfig().getAppId()); + request.setMchId(getConfig().getPartnerId()); request.setNonceStr(System.currentTimeMillis() + ""); request.setSign(this.createSign(request)); @@ -345,37 +356,27 @@ public WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxErrorExcepti @Override public WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) throws WxErrorException { - checkParameters(request); XStream xstream = XStreamInitializer.getInstance(); xstream.processAnnotations(WxPayUnifiedOrderRequest.class); xstream.processAnnotations(WxPayUnifiedOrderResult.class); - WxMpConfigStorage config = this.config; + request.setAppid(getConfig().getAppId()); + request.setMchId(getConfig().getPartnerId()); + request.setNotifyURL(getConfig().getNotifyURL()); + request.setTradeType(getConfig().getTradeType()); + request.setNonceStr(System.currentTimeMillis() + ""); + + checkParameters(request);//校验参数 - //如果没有设置,则使用配置中默认值 - if(StringUtils.isBlank(request.getAppid())){ - request.setAppid(config.getAppId()); - } - if(StringUtils.isBlank(request.getMchId())){ - request.setMchId(config.getPartnerId()); - } - if(StringUtils.isBlank(request.getNotifyURL())){ - request.setNotifyURL(config.getNotifyURL()); - } - if(StringUtils.isBlank(request.getTradeType())){ - request.setTradeType(config.getTradeType()); - } - if(StringUtils.isBlank(request.getNonceStr())){ - request.setNonceStr(System.currentTimeMillis() + ""); - } request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/pay/unifiedorder"; + String xmlParam = xstream.toXML(request); + log.debug("微信统一下单接口,URL:{},参数:{}",url, xmlParam); - String responseContent = this.executeRequest(url, xstream.toXML(request)); - WxPayUnifiedOrderResult result = (WxPayUnifiedOrderResult) xstream - .fromXML(responseContent); + String responseContent = this.executeRequest(url, xmlParam); + log.debug("微信统一下单接口,URL:{},结果:{}",url, responseContent); + WxPayUnifiedOrderResult result = (WxPayUnifiedOrderResult) xstream.fromXML(responseContent); this.checkResult(result); return result; } @@ -384,7 +385,7 @@ private void checkParameters(WxPayUnifiedOrderRequest request) throws WxErrorExc BeanUtils.checkRequiredFields(request); if (!ArrayUtils.contains(TRADE_TYPES, request.getTradeType())) { - throw new IllegalArgumentException("trade_type目前必须为" + Arrays.toString(TRADE_TYPES) + "其中之一"); + throw new IllegalArgumentException("trade_type目前必须为" + Arrays.toString(TRADE_TYPES) + "其中之一,实际值:"+request.getTradeType()); } if ("JSAPI".equals(request.getTradeType()) && request.getOpenid() == null) { @@ -406,7 +407,7 @@ public Map getPayInfo(WxPayUnifiedOrderRequest request) throws W } Map payInfo = new HashMap<>(); - payInfo.put("appId", this.config.getAppId()); + payInfo.put("appId", getConfig().getAppId()); // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符 payInfo.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000)); payInfo.put("nonceStr", System.currentTimeMillis() + ""); @@ -427,8 +428,8 @@ public WxEntPayResult entPay(WxEntPayRequest request, File keyFile) throws WxErr xstream.processAnnotations(WxEntPayRequest.class); xstream.processAnnotations(WxEntPayResult.class); - request.setMchAppid(this.config.getAppId()); - request.setMchId(this.config.getPartnerId()); + request.setMchAppid(getConfig().getAppId()); + request.setMchId(getConfig().getPartnerId()); request.setNonceStr(System.currentTimeMillis() + ""); request.setSign(this.createSign(request)); @@ -447,8 +448,8 @@ public WxEntPayQueryResult queryEntPay(String partnerTradeNo, File keyFile) thro xstream.processAnnotations(WxEntPayQueryResult.class); WxEntPayQueryRequest request = new WxEntPayQueryRequest(); - request.setAppid(this.config.getAppId()); - request.setMchId(this.config.getPartnerId()); + request.setAppid(getConfig().getAppId()); + request.setMchId(getConfig().getPartnerId()); request.setNonceStr(System.currentTimeMillis() + ""); request.setSign(this.createSign(request)); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyCoupon.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyCoupon.java index 7cea57ba2b..60b3f6883b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyCoupon.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyCoupon.java @@ -13,47 +13,52 @@ * 支付异步通知代金券详细 */ public class WxPayOrderNotifyCoupon implements Serializable { - /** - * @fields serialVersionUID - */ - private static final long serialVersionUID = -4165343733538156097L; - - @XStreamAlias("coupon_id") - private String couponId; - @XStreamAlias("coupon_type") - private String couponType; - @XStreamAlias("coupon_fee") - private Integer couponFee; - - public String getCouponId() { - return couponId; - } - public void setCouponId(String couponId) { - this.couponId = couponId; - } - public String getCouponType() { - return couponType; - } - public void setCouponType(String couponType) { - this.couponType = couponType; - } - public Integer getCouponFee() { - return couponFee; - } - public void setCouponFee(Integer couponFee) { - this.couponFee = couponFee; - } - - public Map toMap(int index){ - Map map = new HashMap<>(); - map.put("coupon_id_"+index, this.getCouponId()); - map.put("coupon_type_"+index, this.getCouponType()); - map.put("coupon_fee_"+index, this.getCouponFee()+""); - return map; - } - - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE); - } + /** + * @fields serialVersionUID + */ + private static final long serialVersionUID = -4165343733538156097L; + + @XStreamAlias("coupon_id") + private String couponId; + @XStreamAlias("coupon_type") + private String couponType; + @XStreamAlias("coupon_fee") + private Integer couponFee; + + public String getCouponId() { + return couponId; + } + + public void setCouponId(String couponId) { + this.couponId = couponId; + } + + public String getCouponType() { + return couponType; + } + + public void setCouponType(String couponType) { + this.couponType = couponType; + } + + public Integer getCouponFee() { + return couponFee; + } + + public void setCouponFee(Integer couponFee) { + this.couponFee = couponFee; + } + + public Map toMap(int index) { + Map map = new HashMap<>(); + map.put("coupon_id_" + index, this.getCouponId()); + map.put("coupon_type_" + index, this.getCouponType()); + map.put("coupon_fee_" + index, this.getCouponFee() + ""); + return map; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyResponse.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyResponse.java index 54f4fc5658..a1313ea033 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyResponse.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyResponse.java @@ -1,6 +1,5 @@ package me.chanjar.weixin.mp.bean.pay; - import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamOmitField; @@ -9,53 +8,53 @@ @XStreamAlias("xml") public class WxPayOrderNotifyResponse { - @XStreamOmitField - private transient static final String FAIL ="FAIL"; - @XStreamOmitField - private transient static final String SUCCESS ="SUCCESS"; - - @XStreamAlias("return_code") - private String returnCode; - @XStreamAlias("return_msg") - private String returnMsg; - - - public String getReturnCode() { - return returnCode; - } - public void setReturnCode(String returnCode) { - this.returnCode = returnCode; - } - public String getReturnMsg() { - return returnMsg; - } - public void setReturnMsg(String returnMsg) { - this.returnMsg = returnMsg; - } - - - public WxPayOrderNotifyResponse() { - super(); - } - public WxPayOrderNotifyResponse(String returnCode, String returnMsg) { - super(); - this.returnCode = returnCode; - this.returnMsg = returnMsg; - } - - - public static String fail(String msg){ - WxPayOrderNotifyResponse response = new WxPayOrderNotifyResponse(FAIL,msg); - XStream xstream = XStreamInitializer.getInstance(); - xstream.autodetectAnnotations(true); - return xstream.toXML(response); - } - - - public static String success(String msg){ - WxPayOrderNotifyResponse response = new WxPayOrderNotifyResponse(SUCCESS,msg); - XStream xstream = XStreamInitializer.getInstance(); - xstream.autodetectAnnotations(true); - return xstream.toXML(response); - } + @XStreamOmitField + private transient static final String FAIL = "FAIL"; + @XStreamOmitField + private transient static final String SUCCESS = "SUCCESS"; + + @XStreamAlias("return_code") + private String returnCode; + @XStreamAlias("return_msg") + private String returnMsg; + + public String getReturnCode() { + return returnCode; + } + + public void setReturnCode(String returnCode) { + this.returnCode = returnCode; + } + + public String getReturnMsg() { + return returnMsg; + } + + public void setReturnMsg(String returnMsg) { + this.returnMsg = returnMsg; + } + + public WxPayOrderNotifyResponse() { + super(); + } + + public WxPayOrderNotifyResponse(String returnCode, String returnMsg) { + super(); + this.returnCode = returnCode; + this.returnMsg = returnMsg; + } + + public static String fail(String msg) { + WxPayOrderNotifyResponse response = new WxPayOrderNotifyResponse(FAIL, msg); + XStream xstream = XStreamInitializer.getInstance(); + xstream.autodetectAnnotations(true); + return xstream.toXML(response); + } + + public static String success(String msg) { + WxPayOrderNotifyResponse response = new WxPayOrderNotifyResponse(SUCCESS, msg); + XStream xstream = XStreamInitializer.getInstance(); + xstream.autodetectAnnotations(true); + return xstream.toXML(response); + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyResultConverter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyResultConverter.java index 1f90f0b9e9..bdd440b92d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyResultConverter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayOrderNotifyResultConverter.java @@ -24,107 +24,107 @@ public class WxPayOrderNotifyResultConverter extends AbstractReflectionConverter { - public WxPayOrderNotifyResultConverter(Mapper mapper, ReflectionProvider reflectionProvider) { - super(mapper, reflectionProvider); - } - - @Override - @SuppressWarnings("rawtypes") - public boolean canConvert(Class type) { - return type.equals(WxPayOrderNotifyResult.class); - } - - @Override - public void marshal(Object original, HierarchicalStreamWriter writer, MarshallingContext context) { - super.marshal(original, writer, context); - WxPayOrderNotifyResult obj = (WxPayOrderNotifyResult) original; - List list = obj.getCouponList(); - if (list == null || list.size() == 0) { - return; - } - for (int i = 0; i < list.size(); i++) { - WxPayOrderNotifyCoupon coupon = list.get(i); - writer.startNode("coupon_id_" + i); - writer.setValue(coupon.getCouponId()); - writer.endNode(); - writer.startNode("coupon_type_" + i); - writer.setValue(coupon.getCouponType()); - writer.endNode(); - writer.startNode("coupon_fee_" + i); - writer.setValue(coupon.getCouponFee() + ""); - writer.endNode(); - } - } - - @Override - protected void marshallField(MarshallingContext context, Object newObj, Field field) { - if (field.getName().equals("couponList")) { - return; - } else { - super.marshallField(context, newObj, field); - } - } - - @Override - public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { - WxPayOrderNotifyResult obj = new WxPayOrderNotifyResult(); - - List fields = new ArrayList<>(Arrays.asList(obj.getClass().getDeclaredFields())); - fields.addAll(Arrays.asList(obj.getClass().getSuperclass().getDeclaredFields())); - Map fieldMap = getFieldMap(fields); - - List coupons = new ArrayList<>(10); - while (reader.hasMoreChildren()) { - reader.moveDown(); - if (fieldMap.containsKey(reader.getNodeName())) { - Field field = fieldMap.get(reader.getNodeName()); - setFieldValue(context, obj, field); - } else if (StringUtils.startsWith(reader.getNodeName(), "coupon_id_")) { - String id = (String) context.convertAnother(obj, String.class); - getIndex(coupons, reader.getNodeName()).setCouponId(id); - } else if (StringUtils.startsWith(reader.getNodeName(), "coupon_type_")) { - String type = (String) context.convertAnother(obj, String.class); - getIndex(coupons, reader.getNodeName()).setCouponType(type); - } else if (StringUtils.startsWith(reader.getNodeName(), "coupon_fee_")) { - Integer fee = (Integer) context.convertAnother(obj, Integer.class); - getIndex(coupons, reader.getNodeName()).setCouponFee(fee); - } - reader.moveUp(); - } - - obj.setCouponList(coupons); - return obj; - } - - private void setFieldValue(UnmarshallingContext context, WxPayOrderNotifyResult obj, Field field) { - Object val = context.convertAnother(obj, field.getType()); - try { - if (val != null) { - PropertyDescriptor pd = new PropertyDescriptor(field.getName(), obj.getClass()); - pd.getWriteMethod().invoke(obj, val); - } - } catch (Exception e) { - } - } - - private Map getFieldMap(List fields) { - Map fieldMap = Maps.uniqueIndex(fields, new Function() { - @Override - public String apply(Field field) { - if (field.isAnnotationPresent(XStreamAlias.class)) { - return field.getAnnotation(XStreamAlias.class).value(); - } - return field.getName(); - } - }); - return fieldMap; - } - - private WxPayOrderNotifyCoupon getIndex(List coupons, String nodeName) { - Integer index = Integer.valueOf(StringUtils.substring(nodeName, nodeName.lastIndexOf("_") + 1)); - if (index >= coupons.size() || coupons.get(index) == null) { - coupons.add(index, new WxPayOrderNotifyCoupon()); - } - return coupons.get(index); - } + public WxPayOrderNotifyResultConverter(Mapper mapper, ReflectionProvider reflectionProvider) { + super(mapper, reflectionProvider); + } + + @Override + @SuppressWarnings("rawtypes") + public boolean canConvert(Class type) { + return type.equals(WxPayOrderNotifyResult.class); + } + + @Override + public void marshal(Object original, HierarchicalStreamWriter writer, MarshallingContext context) { + super.marshal(original, writer, context); + WxPayOrderNotifyResult obj = (WxPayOrderNotifyResult) original; + List list = obj.getCouponList(); + if (list == null || list.size() == 0) { + return; + } + for (int i = 0; i < list.size(); i++) { + WxPayOrderNotifyCoupon coupon = list.get(i); + writer.startNode("coupon_id_" + i); + writer.setValue(coupon.getCouponId()); + writer.endNode(); + writer.startNode("coupon_type_" + i); + writer.setValue(coupon.getCouponType()); + writer.endNode(); + writer.startNode("coupon_fee_" + i); + writer.setValue(coupon.getCouponFee() + ""); + writer.endNode(); + } + } + + @Override + protected void marshallField(MarshallingContext context, Object newObj, Field field) { + if (field.getName().equals("couponList")) { + return; + } else { + super.marshallField(context, newObj, field); + } + } + + @Override + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { + WxPayOrderNotifyResult obj = new WxPayOrderNotifyResult(); + + List fields = new ArrayList<>(Arrays.asList(obj.getClass().getDeclaredFields())); + fields.addAll(Arrays.asList(obj.getClass().getSuperclass().getDeclaredFields())); + Map fieldMap = getFieldMap(fields); + + List coupons = new ArrayList<>(10); + while (reader.hasMoreChildren()) { + reader.moveDown(); + if (fieldMap.containsKey(reader.getNodeName())) { + Field field = fieldMap.get(reader.getNodeName()); + setFieldValue(context, obj, field); + } else if (StringUtils.startsWith(reader.getNodeName(), "coupon_id_")) { + String id = (String) context.convertAnother(obj, String.class); + getIndex(coupons, reader.getNodeName()).setCouponId(id); + } else if (StringUtils.startsWith(reader.getNodeName(), "coupon_type_")) { + String type = (String) context.convertAnother(obj, String.class); + getIndex(coupons, reader.getNodeName()).setCouponType(type); + } else if (StringUtils.startsWith(reader.getNodeName(), "coupon_fee_")) { + Integer fee = (Integer) context.convertAnother(obj, Integer.class); + getIndex(coupons, reader.getNodeName()).setCouponFee(fee); + } + reader.moveUp(); + } + + obj.setCouponList(coupons); + return obj; + } + + private void setFieldValue(UnmarshallingContext context, WxPayOrderNotifyResult obj, Field field) { + Object val = context.convertAnother(obj, field.getType()); + try { + if (val != null) { + PropertyDescriptor pd = new PropertyDescriptor(field.getName(), obj.getClass()); + pd.getWriteMethod().invoke(obj, val); + } + } catch (Exception e) { + } + } + + private Map getFieldMap(List fields) { + Map fieldMap = Maps.uniqueIndex(fields, new Function() { + @Override + public String apply(Field field) { + if (field.isAnnotationPresent(XStreamAlias.class)) { + return field.getAnnotation(XStreamAlias.class).value(); + } + return field.getName(); + } + }); + return fieldMap; + } + + private WxPayOrderNotifyCoupon getIndex(List coupons, String nodeName) { + Integer index = Integer.valueOf(StringUtils.substring(nodeName, nodeName.lastIndexOf("_") + 1)); + if (index >= coupons.size() || coupons.get(index) == null) { + coupons.add(index, new WxPayOrderNotifyCoupon()); + } + return coupons.get(index); + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java index 0a6815d8c8..60a25c197a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java @@ -388,7 +388,7 @@ public void setTimeEnd(String timeEnd) { @Override public Map toMap(){ Map resultMap = BeanUtils.xmlBean2Map(this); - if(this.getCouponCount() > 0){ + if(this.getCouponCount() != null && this.getCouponCount() > 0){ for (int i = 0; i < this.getCouponCount(); i++) { WxPayOrderNotifyCoupon coupon = couponList.get(i); resultMap.putAll(coupon.toMap(i)); From 80034e50869836ca3df8fd1c0e84a38b3fa16e32 Mon Sep 17 00:00:00 2001 From: aimilin6688 Date: Fri, 9 Dec 2016 17:00:16 +0800 Subject: [PATCH 05/80] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=85=83=E8=BD=AC=E5=88=86=EF=BC=8C=E5=88=86=E8=BD=AC?= =?UTF-8?q?=E5=85=83=E6=96=B9=E6=B3=95=EF=BC=8C=E6=96=B9=E4=BE=BF=E5=8D=95?= =?UTF-8?q?=E4=BD=8D=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/bean/pay/request/WxPayBaseRequest.java | 12 ++++++++++++ .../weixin/mp/bean/pay/result/WxPayBaseResult.java | 10 ++++++++++ .../mp/bean/pay/result/WxPayOrderNotifyResult.java | 10 ---------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java index 9ede16ec15..d6926d0e8b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java @@ -1,5 +1,7 @@ package me.chanjar.weixin.mp.bean.pay.request; +import java.math.BigDecimal; + import com.thoughtworks.xstream.annotations.XStreamAlias; import me.chanjar.weixin.common.util.ToStringUtils; @@ -110,6 +112,16 @@ public String getSign() { public void setSign(String sign) { this.sign = sign; } + + /** + * 将单位为元转换为单位为分 + * + * @param yuan + * @return + */ + public static Integer yuanToFee(String yuan) { + return new BigDecimal(yuan).setScale(2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).intValue(); + } @Override public String toString() { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java index d74553770d..b719e3338b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean.pay.result; +import java.math.BigDecimal; import java.util.Map; import com.thoughtworks.xstream.annotations.XStreamAlias; @@ -146,6 +147,15 @@ public void setSign(String sign) { this.sign = sign; } + /** + * 将单位分转换成单位圆 + * @param fee + * @return + */ + public static String feeToYuan(Integer fee) { + return new BigDecimal(Double.valueOf(fee) / 100).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString(); + } + public Map toMap(){ return BeanUtils.xmlBean2Map(this); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java index 60a25c197a..eae67a360d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java @@ -397,16 +397,6 @@ public Map toMap(){ return resultMap; } - - /** - * 将单位分转换成单位圆 - * @param fee - * @return - */ - public static String feeToYuan(Integer fee) { - return new BigDecimal(Double.valueOf(fee) / 100).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString(); - } - @Override public String toString() { return ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE); From fd9898eec9f8111cbfc7b484d5f46a7151a34056 Mon Sep 17 00:00:00 2001 From: aimilin6688 Date: Fri, 9 Dec 2016 17:00:16 +0800 Subject: [PATCH 06/80] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=85=83=E8=BD=AC=E5=88=86=EF=BC=8C=E5=88=86=E8=BD=AC?= =?UTF-8?q?=E5=85=83=E6=96=B9=E6=B3=95=EF=BC=8C=E6=96=B9=E4=BE=BF=E5=8D=95?= =?UTF-8?q?=E4=BD=8D=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/bean/pay/request/WxPayBaseRequest.java | 12 ++++++++++++ .../weixin/mp/bean/pay/result/WxPayBaseResult.java | 10 ++++++++++ .../mp/bean/pay/result/WxPayOrderNotifyResult.java | 11 ----------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java index 9ede16ec15..d6926d0e8b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java @@ -1,5 +1,7 @@ package me.chanjar.weixin.mp.bean.pay.request; +import java.math.BigDecimal; + import com.thoughtworks.xstream.annotations.XStreamAlias; import me.chanjar.weixin.common.util.ToStringUtils; @@ -110,6 +112,16 @@ public String getSign() { public void setSign(String sign) { this.sign = sign; } + + /** + * 将单位为元转换为单位为分 + * + * @param yuan + * @return + */ + public static Integer yuanToFee(String yuan) { + return new BigDecimal(yuan).setScale(2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).intValue(); + } @Override public String toString() { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java index d74553770d..b719e3338b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean.pay.result; +import java.math.BigDecimal; import java.util.Map; import com.thoughtworks.xstream.annotations.XStreamAlias; @@ -146,6 +147,15 @@ public void setSign(String sign) { this.sign = sign; } + /** + * 将单位分转换成单位圆 + * @param fee + * @return + */ + public static String feeToYuan(Integer fee) { + return new BigDecimal(Double.valueOf(fee) / 100).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString(); + } + public Map toMap(){ return BeanUtils.xmlBean2Map(this); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java index 60a25c197a..3c78247717 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java @@ -1,7 +1,6 @@ package me.chanjar.weixin.mp.bean.pay.result; import java.io.Serializable; -import java.math.BigDecimal; import java.util.List; import java.util.Map; @@ -397,16 +396,6 @@ public Map toMap(){ return resultMap; } - - /** - * 将单位分转换成单位圆 - * @param fee - * @return - */ - public static String feeToYuan(Integer fee) { - return new BigDecimal(Double.valueOf(fee) / 100).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString(); - } - @Override public String toString() { return ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE); From 5224f342ed68f38c6745edb7e639fe73ef4fb178 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 12 Dec 2016 13:52:34 +0800 Subject: [PATCH 07/80] reformat code for PayService --- .../chanjar/weixin/mp/api/WxMpPayService.java | 58 +++---- .../mp/api/impl/WxMpPayServiceImpl.java | 157 ++++++++---------- 2 files changed, 96 insertions(+), 119 deletions(-) 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 024ce4a801..afe888f833 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 @@ -30,9 +30,8 @@ public interface WxMpPayService { * 接口地址:https://api.mch.weixin.qq.com/pay/orderquery *
* - * @param transactionId 微信支付分配的商户号 + * @param transactionId 微信订单号 * @param outTradeNo 商户系统内部的订单号,当没提供transaction_id时需要传这个。 - * @throws WxErrorException */ WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxErrorException; @@ -49,7 +48,6 @@ public interface WxMpPayService { * * * @param outTradeNo 商户系统内部的订单号,当没提供transaction_id时需要传这个。 - * @throws WxErrorException */ WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxErrorException; @@ -59,7 +57,6 @@ public interface WxMpPayService { * 接口地址:https://api.mch.weixin.qq.com/pay/unifiedorder * * @param request 请求对象,注意一些参数如appid、mchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置) - * @throws WxErrorException */ WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) throws WxErrorException; @@ -68,7 +65,6 @@ public interface WxMpPayService { * 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN * * @param request 请求对象,注意一些参数如appid、mchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置) - * @throws WxErrorException */ Map getPayInfo(WxPayUnifiedOrderRequest request) throws WxErrorException; @@ -93,7 +89,8 @@ public interface WxMpPayService { * 详见 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_5 * 接口链接:https://api.mch.weixin.qq.com/pay/refundquery * - * 以下四个参数四选一 + * 以下四个参数四选一 + * * @param transactionId 微信订单号 * @param outTradeNo 商户订单号 * @param outRefundNo 商户退款单号 @@ -107,81 +104,85 @@ public interface WxMpPayService { * 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7 */ WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxErrorException; - + /** * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) * * @param xmlbean Bean需要标记有XML注解,默认使用配置中的PartnerKey进行签名 - * @since 2.5.0 * @return 签名字符串 * @see #createSign(Map, String) + * @since 2.5.0 */ String createSign(Object xmlbean); - + /** * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) - * @param xmlbean Bean需要标记有XML注解 + * + * @param xmlbean Bean需要标记有XML注解 * @param signKey 签名Key * @return 签名字符串 * @see #createSign(Map, String) */ String createSign(Object xmlbean, String signKey); - + /** * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) - * @param prams 参数信息,默认使用配置中的PartnerKey进行签名 - * @param signKey 签名Key + * + * @param prams 参数信息,默认使用配置中的PartnerKey进行签名 * @return 签名字符串 * @see #createSign(Map, String) */ String createSign(Map prams); - - + + /** * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) - * @param prams 参数信息 + * + * @param prams 参数信息 * @param signKey 签名Key * @return 签名字符串 */ String createSign(Map prams, String signKey); - - + /** * 校验签名是否正确,默认使用配置中的PartnerKey进行签名 + * * @param xmlbean Bean需要标记有XML注解 * @return true - 签名校验成功,false - 签名校验失败 * @see #checkSign(Map, String) */ boolean checkSign(Object xmlbean); - + /** * 校验签名是否正确 + * * @param xmlbean Bean需要标记有XML注解 - * @param signKey 校验的签名Key + * @param signKey 校验的签名Key * @return true - 签名校验成功,false - 签名校验失败 * @see #checkSign(Map, String) */ boolean checkSign(Object xmlbean, String signKey); - + /** * 校验签名是否正确,默认使用配置中的PartnerKey进行签名 + * * @param prams 需要校验的参数Map * @return true - 签名校验成功,false - 签名校验失败 * @see #checkSign(Map, String) */ boolean checkSign(Map prams); - + /** * 校验签名是否正确 - * @param prams 需要校验的参数Map - * @param signKey 校验的签名Key + * + * @param params 需要校验的参数Map + * @param signKey 校验的签名Key * @return true - 签名校验成功,false - 签名校验失败 * @see #checkSign(Map, String) */ - boolean checkSign(Map prams, String signKey); - - + boolean checkSign(Map params, String signKey); + /** * 发送微信红包给个人用户 @@ -206,8 +207,9 @@ public interface WxMpPayService { * 是否需要证书 是(证书及使用说明详见商户证书) * 请求方式 POST * + * * @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890 - * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) + * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) */ WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) throws WxErrorException; 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 84655a86aa..f195f9228d 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,17 +1,16 @@ package me.chanjar.weixin.mp.api.impl; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.security.KeyStore; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; - -import javax.net.ssl.SSLContext; - +import com.thoughtworks.xstream.XStream; +import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.util.BeanUtils; +import me.chanjar.weixin.common.util.xml.XStreamInitializer; +import me.chanjar.weixin.mp.api.WxMpConfigStorage; +import me.chanjar.weixin.mp.api.WxMpPayService; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.pay.WxPayOrderNotifyResultConverter; +import me.chanjar.weixin.mp.bean.pay.request.*; +import me.chanjar.weixin.mp.bean.pay.result.*; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; @@ -29,36 +28,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.thoughtworks.xstream.XStream; - -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.common.util.BeanUtils; -import me.chanjar.weixin.common.util.xml.XStreamInitializer; -import me.chanjar.weixin.mp.api.WxMpConfigStorage; -import me.chanjar.weixin.mp.api.WxMpPayService; -import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.bean.pay.WxPayOrderNotifyResultConverter; -import me.chanjar.weixin.mp.bean.pay.request.WxEntPayQueryRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxEntPayRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPayOrderCloseRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPayOrderQueryRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPayRedpackQueryRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPayRefundQueryRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPayRefundRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPaySendRedpackRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPayUnifiedOrderRequest; -import me.chanjar.weixin.mp.bean.pay.result.WxEntPayQueryResult; -import me.chanjar.weixin.mp.bean.pay.result.WxEntPayResult; -import me.chanjar.weixin.mp.bean.pay.result.WxPayBaseResult; -import me.chanjar.weixin.mp.bean.pay.result.WxPayOrderCloseResult; -import me.chanjar.weixin.mp.bean.pay.result.WxPayOrderNotifyResult; -import me.chanjar.weixin.mp.bean.pay.result.WxPayOrderQueryResult; -import me.chanjar.weixin.mp.bean.pay.result.WxPayRedpackQueryResult; -import me.chanjar.weixin.mp.bean.pay.result.WxPayRefundQueryResult; -import me.chanjar.weixin.mp.bean.pay.result.WxPayRefundResult; -import me.chanjar.weixin.mp.bean.pay.result.WxPaySendRedpackResult; -import me.chanjar.weixin.mp.bean.pay.result.WxPayUnifiedOrderResult; +import javax.net.ssl.SSLContext; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.security.KeyStore; +import java.util.*; /** * Created by Binary Wang on 2016/7/28. @@ -71,16 +46,16 @@ public class WxMpPayServiceImpl implements WxMpPayService { private static final String[] TRADE_TYPES = new String[]{"JSAPI", "NATIVE", "APP"}; private static final String[] REFUND_ACCOUNT = new String[]{"REFUND_SOURCE_RECHARGE_FUNDS", "REFUND_SOURCE_UNSETTLED_FUNDS"}; - protected final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); private WxMpService wxMpService; private WxMpConfigStorage config = null; public WxMpPayServiceImpl(WxMpService wxMpService) { this.wxMpService = wxMpService; } - - private WxMpConfigStorage getConfig(){ - if(config == null){ + + private WxMpConfigStorage getConfig() { + if (config == null) { this.config = wxMpService.getWxMpConfigStorage(); } return this.config; @@ -139,24 +114,24 @@ public WxPayRefundQueryResult refundQuery(String transactionId, String outTradeN this.checkResult(result); return result; } - + private void checkResult(WxPayBaseResult result) throws WxErrorException { - //校验返回结果签名 - if(!checkSign(result.toMap())){ - log.debug("校验结果签名失败,参数:{}",result.toMap()); - throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("参数格式校验错误!").build()); - } - - //校验结果是否成功 + //校验返回结果签名 + if (!checkSign(result.toMap())) { + log.debug("校验结果签名失败,参数:{}", result.toMap()); + throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("参数格式校验错误!").build()); + } + + //校验结果是否成功 if (!"SUCCESS".equalsIgnoreCase(result.getReturnCode()) || !"SUCCESS".equalsIgnoreCase(result.getResultCode())) { WxError error = WxError.newBuilder().setErrorCode(-1) - .setErrorMsg("返回代码: " + result.getReturnCode() + ", 返回信息: " - + result.getReturnMsg() + ", 结果代码: " + result.getResultCode() + ", 错误代码: " - + result.getErrCode() + ", 错误详情: " + result.getErrCodeDes()) - .build(); - log.debug("结果校验失败,参数:{},详细:{}",result.toMap(),error); + .setErrorMsg("返回代码: " + result.getReturnCode() + ", 返回信息: " + + result.getReturnMsg() + ", 结果代码: " + result.getResultCode() + ", 错误代码: " + + result.getErrCode() + ", 错误详情: " + result.getErrCodeDes()) + .build(); + log.debug("结果校验失败,参数:{},详细:{}", result.toMap(), error); throw new WxErrorException(error); } } @@ -166,7 +141,7 @@ private void checkParameters(WxPayRefundRequest request) throws WxErrorException if (StringUtils.isNotBlank(request.getRefundAccount())) { if (!ArrayUtils.contains(REFUND_ACCOUNT, request.getRefundAccount())) { - throw new IllegalArgumentException("refund_account目前必须为" + Arrays.toString(REFUND_ACCOUNT) + "其中之一,实际值:"+ request.getRefundAccount()); + throw new IllegalArgumentException("refund_account目前必须为" + Arrays.toString(REFUND_ACCOUNT) + "其中之一,实际值:" + request.getRefundAccount()); } } @@ -181,16 +156,16 @@ public WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxErro log.trace("微信支付回调参数详细:{}", xmlData); XStream xstream = XStreamInitializer.getInstance(); xstream.processAnnotations(WxPayOrderNotifyResult.class); - xstream.registerConverter(new WxPayOrderNotifyResultConverter(xstream.getMapper(),xstream.getReflectionProvider())); - WxPayOrderNotifyResult result = (WxPayOrderNotifyResult) xstream.fromXML(xmlData); - log.debug("微信支付回调结果对象:{}",result); - this.checkResult(result); - return result; - }catch (WxErrorException e) { - log.error(e.getMessage(),e); - throw e; - }catch (Exception e) { - log.error(e.getMessage(),e); + xstream.registerConverter(new WxPayOrderNotifyResultConverter(xstream.getMapper(), xstream.getReflectionProvider())); + WxPayOrderNotifyResult result = (WxPayOrderNotifyResult) xstream.fromXML(xmlData); + log.debug("微信支付回调结果对象:{}", result); + this.checkResult(result); + return result; + } catch (WxErrorException e) { + log.error(e.getMessage(), e); + throw e; + } catch (Exception e) { + log.error(e.getMessage(), e); throw new WxErrorException(WxError.newBuilder().setErrorMsg("发生异常" + e.getMessage()).build()); } } @@ -245,20 +220,20 @@ public WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) thro this.checkResult(result); return result; } - + @Override public String createSign(Object xmlBean) { - return createSign(BeanUtils.xmlBean2Map(xmlBean),getConfig().getPartnerKey()); + return createSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey()); } - + @Override public String createSign(Object xmlBean, String signKey) { - return createSign(BeanUtils.xmlBean2Map(xmlBean), signKey); + return createSign(BeanUtils.xmlBean2Map(xmlBean), signKey); } - + @Override public String createSign(Map params) { - return createSign(params,getConfig().getPartnerKey()); + return createSign(params, getConfig().getPartnerKey()); } @Override @@ -276,28 +251,28 @@ public String createSign(Map params, String signKey) { toSign.append("key=" + signKey); return DigestUtils.md5Hex(toSign.toString()).toUpperCase(); } - + @Override public boolean checkSign(Object xmlBean) { - return checkSign(BeanUtils.xmlBean2Map(xmlBean) , getConfig().getPartnerKey()); + return checkSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey()); } - + @Override public boolean checkSign(Object xmlBean, String signKey) { - return checkSign(BeanUtils.xmlBean2Map(xmlBean) , signKey); + return checkSign(BeanUtils.xmlBean2Map(xmlBean), signKey); } - + @Override public boolean checkSign(Map params) { - return checkSign(params , getConfig().getPartnerKey()); + return checkSign(params, getConfig().getPartnerKey()); } - + @Override public boolean checkSign(Map params, String signKey) { - String sign = this.createSign(params , signKey); + String sign = this.createSign(params, signKey); return sign.equals(params.get("sign")); } - + @Override public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxErrorException { @@ -366,16 +341,16 @@ public WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) request.setNotifyURL(getConfig().getNotifyURL()); request.setTradeType(getConfig().getTradeType()); request.setNonceStr(System.currentTimeMillis() + ""); - + checkParameters(request);//校验参数 - + request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/pay/unifiedorder"; - String xmlParam = xstream.toXML(request); - log.debug("微信统一下单接口,URL:{},参数:{}",url, xmlParam); + String xmlParam = xstream.toXML(request); + log.debug("微信统一下单接口,URL:{},参数:{}", url, xmlParam); String responseContent = this.executeRequest(url, xmlParam); - log.debug("微信统一下单接口,URL:{},结果:{}",url, responseContent); + log.debug("微信统一下单接口,URL:{},结果:{}", url, responseContent); WxPayUnifiedOrderResult result = (WxPayUnifiedOrderResult) xstream.fromXML(responseContent); this.checkResult(result); return result; @@ -385,7 +360,7 @@ private void checkParameters(WxPayUnifiedOrderRequest request) throws WxErrorExc BeanUtils.checkRequiredFields(request); if (!ArrayUtils.contains(TRADE_TYPES, request.getTradeType())) { - throw new IllegalArgumentException("trade_type目前必须为" + Arrays.toString(TRADE_TYPES) + "其中之一,实际值:"+request.getTradeType()); + throw new IllegalArgumentException("trade_type目前必须为" + Arrays.toString(TRADE_TYPES) + "其中之一,实际值:" + request.getTradeType()); } if ("JSAPI".equals(request.getTradeType()) && request.getOpenid() == null) { From 28e7e454b90a7a10af701f340bc4926b8d83dcb6 Mon Sep 17 00:00:00 2001 From: aimilin6688 Date: Wed, 14 Dec 2016 11:41:37 +0800 Subject: [PATCH 08/80] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=BF=A1=E6=81=AF=E4=B8=8D=E8=83=BD=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E8=AE=BE=E7=BD=AEBUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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 84655a86aa..875d4e4eb2 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 @@ -73,17 +73,13 @@ public class WxMpPayServiceImpl implements WxMpPayService { "REFUND_SOURCE_UNSETTLED_FUNDS"}; protected final Logger log = LoggerFactory.getLogger(this.getClass()); private WxMpService wxMpService; - private WxMpConfigStorage config = null; public WxMpPayServiceImpl(WxMpService wxMpService) { this.wxMpService = wxMpService; } private WxMpConfigStorage getConfig(){ - if(config == null){ - this.config = wxMpService.getWxMpConfigStorage(); - } - return this.config; + return wxMpService.getWxMpConfigStorage(); } @Override From d18e11cc4e25e335087e61977a64969d0bc17203 Mon Sep 17 00:00:00 2001 From: aimilin6688 Date: Wed, 14 Dec 2016 12:07:01 +0800 Subject: [PATCH 09/80] =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 875d4e4eb2..84655a86aa 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 @@ -73,13 +73,17 @@ public class WxMpPayServiceImpl implements WxMpPayService { "REFUND_SOURCE_UNSETTLED_FUNDS"}; protected final Logger log = LoggerFactory.getLogger(this.getClass()); private WxMpService wxMpService; + private WxMpConfigStorage config = null; public WxMpPayServiceImpl(WxMpService wxMpService) { this.wxMpService = wxMpService; } private WxMpConfigStorage getConfig(){ - return wxMpService.getWxMpConfigStorage(); + if(config == null){ + this.config = wxMpService.getWxMpConfigStorage(); + } + return this.config; } @Override From 95d87231fa2d02e405724be08336a907b338470a Mon Sep 17 00:00:00 2001 From: aimilin6688 Date: Wed, 14 Dec 2016 12:10:47 +0800 Subject: [PATCH 10/80] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dconfig=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E6=8C=87=E5=AE=9ABug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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 f195f9228d..4675946c1d 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 @@ -48,17 +48,13 @@ public class WxMpPayServiceImpl implements WxMpPayService { "REFUND_SOURCE_UNSETTLED_FUNDS"}; private final Logger log = LoggerFactory.getLogger(this.getClass()); private WxMpService wxMpService; - private WxMpConfigStorage config = null; public WxMpPayServiceImpl(WxMpService wxMpService) { this.wxMpService = wxMpService; } private WxMpConfigStorage getConfig() { - if (config == null) { - this.config = wxMpService.getWxMpConfigStorage(); - } - return this.config; + return wxMpService.getWxMpConfigStorage(); } @Override From a7c72f613abdaf0af4242132722cfd6249698e83 Mon Sep 17 00:00:00 2001 From: dongfuqiang Date: Wed, 14 Dec 2016 16:29:50 +0800 Subject: [PATCH 11/80] update --- .../weixin/mp/api/WxMpDeviceService.java | 80 +++++++++++++ .../me/chanjar/weixin/mp/api/WxMpService.java | 7 ++ .../mp/api/impl/WxMpDeviceServiceImpl.java | 72 ++++++++++++ .../weixin/mp/api/impl/WxMpServiceImpl.java | 6 + .../mp/bean/device/AbstractDeviceBean.java | 12 ++ .../weixin/mp/bean/device/BaseResp.java | 55 +++++++++ .../weixin/mp/bean/device/RespMsg.java | 26 +++++ .../weixin/mp/bean/device/TransMsgResp.java | 49 ++++++++ .../weixin/mp/bean/device/WxDevice.java | 106 ++++++++++++++++++ .../mp/bean/device/WxDeviceAuthorize.java | 36 ++++++ .../bean/device/WxDeviceAuthorizeResult.java | 24 ++++ .../weixin/mp/bean/device/WxDeviceBind.java | 34 ++++++ .../mp/bean/device/WxDeviceBindResult.java | 22 ++++ .../weixin/mp/bean/device/WxDeviceMsg.java | 50 +++++++++ .../mp/bean/device/WxDeviceQrCodeResult.java | 49 ++++++++ .../api/impl/WxMpDeviceServiceImplTest.java | 40 +++++++ 16 files changed, 668 insertions(+) create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpDeviceService.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImpl.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/AbstractDeviceBean.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/BaseResp.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/RespMsg.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/TransMsgResp.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDevice.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorizeResult.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBind.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBindResult.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceMsg.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceQrCodeResult.java create mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpDeviceService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpDeviceService.java new file mode 100644 index 0000000000..a565011c1c --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpDeviceService.java @@ -0,0 +1,80 @@ +package me.chanjar.weixin.mp.api; + +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.bean.device.*; + +/** + * Created by keungtung on 10/12/2016. + */ +public interface WxMpDeviceService { + /** + *
+   * 主动发送消息给设备
+   * 详情请见:http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-3
+   * 
+ */ + TransMsgResp transMsg(WxDeviceMsg msg) throws WxErrorException; + + /** + *
+   *   获取一组新的deviceid和设备二维码
+   *   详情请见:http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-6
+   * 
+ * @param productId 产品id + * @return 返回WxDeviceQrCodeResult + */ + WxDeviceQrCodeResult getQrCode(String productId) throws WxErrorException; + + /** + *
+   *   将device id及其属性信息提交公众平台进行授权
+   *   详情请见:http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-6
+   * 
+ * @param wxDeviceAuthorize 授权请求对象 + * @return WxDeviceAuthorizeResult + */ + WxDeviceAuthorizeResult authorize(WxDeviceAuthorize wxDeviceAuthorize) throws WxErrorException; + + + /** + *
+   *   第三方后台绑定成功后,通知公众平台
+   *   详情请见:http://iot.weixin.qq.com/wiki/new/index.html/page=3-4-7
+   * 
+ * @param wxDeviceBind 绑定请求对象 + * @return WxDeviceBindResult + */ + WxDeviceBindResult bind(WxDeviceBind wxDeviceBind) throws WxErrorException; + + /** + *
+   *   强制绑定用户和设备
+   *   详情请见:http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-7
+   * 
+ * @param wxDeviceBind 强制绑定请求对象 + * @return WxDeviceBindResult + */ + WxDeviceBindResult compelBind(WxDeviceBind wxDeviceBind) throws WxErrorException; + + /** + *
+   *   第三方确认用户和设备的解绑操作
+   *   详情请见:http://iot.weixin.qq.com/wiki/new/index.html/page=3-4-7
+   * 
+ * @param wxDeviceBind 绑定请求对象 + * @return WxDeviceBidResult + */ + WxDeviceBindResult unbind(WxDeviceBind wxDeviceBind) throws WxErrorException; + + /** + *
+   *   强制解绑用户和设备
+   *   详情请见:http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-7
+   * 
+ * @param wxDeviceBind 强制解绑请求对象 + * @return WxDeviceBindResult + */ + WxDeviceBindResult compelUnbind(WxDeviceBind wxDeviceBind) 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 4fa91badf3..dc05a2eecd 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 @@ -345,4 +345,11 @@ public interface WxMpService { * @return WxMpTemplateMsgService */ WxMpTemplateMsgService getTemplateMsgService(); + + /** + * 返回硬件平台相关接口方法的实现类对象,以方便调用其各个接口 + * + * @return WxMpDeviceService + */ + WxMpDeviceService getDeviceService(); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImpl.java new file mode 100644 index 0000000000..e7dbea1b38 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImpl.java @@ -0,0 +1,72 @@ +package me.chanjar.weixin.mp.api.impl; + +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.api.WxMpDeviceService; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.device.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Created by keungtung on 10/12/2016. + */ +public class WxMpDeviceServiceImpl implements WxMpDeviceService { + private static final String API_URL_PREFIX = "https://api.weixin.qq.com/device"; + private static Logger log = LoggerFactory.getLogger(WxMpMenuServiceImpl.class); + + private WxMpService wxMpService; + + WxMpDeviceServiceImpl(WxMpService wxMpService) { + this.wxMpService = wxMpService; + } + + @Override + public TransMsgResp transMsg(WxDeviceMsg msg) throws WxErrorException { + String url = API_URL_PREFIX + "/transmsg"; + String response = this.wxMpService.post(url,msg.toJson()); + return TransMsgResp.fromJson(response); + } + + @Override + public WxDeviceQrCodeResult getQrCode(String productId) throws WxErrorException { + String url = API_URL_PREFIX + "/getqrcode"; + String response = this.wxMpService.get(url, "product_id=" + productId); + return WxDeviceQrCodeResult.fromJson(response); + } + + @Override + public WxDeviceAuthorizeResult authorize(WxDeviceAuthorize wxDeviceAuthorize) throws WxErrorException { + String url = API_URL_PREFIX + "/authorize_device"; + String response = this.wxMpService.post(url,wxDeviceAuthorize.toJson()); + return WxDeviceAuthorizeResult.fromJson(response); + } + + @Override + public WxDeviceBindResult bind(WxDeviceBind wxDeviceBind) throws WxErrorException { + String url = API_URL_PREFIX + "/bind"; + String response = this.wxMpService.post(url,wxDeviceBind.toJson()); + return WxDeviceBindResult.fromJson(response); + } + + @Override + public WxDeviceBindResult compelBind(WxDeviceBind wxDeviceBind) throws WxErrorException { + String url = API_URL_PREFIX + "/compel_bind"; + String response = this.wxMpService.post(url,wxDeviceBind.toJson()); + return WxDeviceBindResult.fromJson(response); + } + + @Override + public WxDeviceBindResult unbind(WxDeviceBind wxDeviceBind) throws WxErrorException { + String url = API_URL_PREFIX + "/unbind?"; + String response = this.wxMpService.post(url, wxDeviceBind.toJson()); + return WxDeviceBindResult.fromJson(response); + } + + @Override + public WxDeviceBindResult compelUnbind(WxDeviceBind wxDeviceBind) throws WxErrorException { + String url = API_URL_PREFIX + "/compel_unbind?"; + String response = this.wxMpService.post(url, wxDeviceBind.toJson()); + return WxDeviceBindResult.fromJson(response); + } +} + 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 46fa3157c9..3c60232501 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 @@ -62,6 +62,8 @@ public class WxMpServiceImpl implements WxMpService { private WxMpTemplateMsgService templateMsgService = new WxMpTemplateMsgServiceImpl(this); + private WxMpDeviceService deviceService = new WxMpDeviceServiceImpl(this); + private CloseableHttpClient httpClient; private HttpHost httpProxy; @@ -540,4 +542,8 @@ public WxMpTemplateMsgService getTemplateMsgService() { return this.templateMsgService; } + @Override + public WxMpDeviceService getDeviceService() { + return this.deviceService; + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/AbstractDeviceBean.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/AbstractDeviceBean.java new file mode 100644 index 0000000000..3a327069bc --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/AbstractDeviceBean.java @@ -0,0 +1,12 @@ +package me.chanjar.weixin.mp.bean.device; + +import me.chanjar.weixin.common.util.json.WxGsonBuilder; + +/** + * Created by keungtung on 14/12/2016. + */ +public abstract class AbstractDeviceBean { + public String toJson() { + return WxGsonBuilder.create().toJson(this); + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/BaseResp.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/BaseResp.java new file mode 100644 index 0000000000..5a3082f66b --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/BaseResp.java @@ -0,0 +1,55 @@ +package me.chanjar.weixin.mp.bean.device; + +/** + * Created by keungtung on 10/12/2016. + */ +public class BaseResp extends AbstractDeviceBean{ + private BaseInfo base_info; + private Integer errcode; + private String errmsg; + + public Integer getErrcode() { + return errcode; + } + + public void setErrcode(Integer errcode) { + this.errcode = errcode; + } + + public BaseInfo getBase_info() { + return base_info; + } + + public void setBase_info(BaseInfo base_info) { + this.base_info = base_info; + } + + public String getErrmsg() { + return errmsg; + } + + public void setErrmsg(String errmsg) { + this.errmsg = errmsg; + } + + private class BaseInfo { + private String device_type; + private String device_id; + + public String getDevice_type() { + return device_type; + } + + public void setDevice_type(String device_type) { + this.device_type = device_type; + } + + public String getDevice_id() { + return device_id; + } + + public void setDevice_id(String device_id) { + this.device_id = device_id; + } + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/RespMsg.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/RespMsg.java new file mode 100644 index 0000000000..e0291fbbe3 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/RespMsg.java @@ -0,0 +1,26 @@ +package me.chanjar.weixin.mp.bean.device; + +/** + * Created by keungtung on 10/12/2016. + */ + +public class RespMsg extends AbstractDeviceBean{ + private Integer retCode; + private String errorInfo; + + public Integer getRetCode() { + return retCode; + } + + public void setRetCode(Integer retCode) { + this.retCode = retCode; + } + + public String getErrorInfo() { + return errorInfo; + } + + public void setErrorInfo(String errorInfo) { + this.errorInfo = errorInfo; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/TransMsgResp.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/TransMsgResp.java new file mode 100644 index 0000000000..6d5fbe0642 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/TransMsgResp.java @@ -0,0 +1,49 @@ +package me.chanjar.weixin.mp.bean.device; + +import me.chanjar.weixin.common.util.json.WxGsonBuilder; + +/** + * Created by keungtung on 14/12/2016. + */ +public class TransMsgResp extends AbstractDeviceBean{ + private Integer ret; + private String ret_info; + private Integer errcode; + private String errmsg; + + public static TransMsgResp fromJson(String json) { + return WxGsonBuilder.create().fromJson(json, TransMsgResp.class); + } + + public Integer getRet() { + return ret; + } + + public void setRet(Integer ret) { + this.ret = ret; + } + + public String getRet_info() { + return ret_info; + } + + public void setRet_info(String ret_info) { + this.ret_info = ret_info; + } + + public Integer getErrcode() { + return errcode; + } + + public void setErrcode(Integer errcode) { + this.errcode = errcode; + } + + public String getErrmsg() { + return errmsg; + } + + public void setErrmsg(String errmsg) { + this.errmsg = errmsg; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDevice.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDevice.java new file mode 100644 index 0000000000..f36c4b1016 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDevice.java @@ -0,0 +1,106 @@ +package me.chanjar.weixin.mp.bean.device; + +/** + * Created by keungtung on 10/12/2016. + */ +public class WxDevice { + private String id; + private String mac; + private String connect_protocol; + private String auth_key; + private String close_strategy; + private String conn_strategy; + private String crypt_method; + private String auth_ver; + private String manu_mac_pos; + private String ser_mac_pos; + private String ble_simple_protocol; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getMac() { + return mac; + } + + public void setMac(String mac) { + this.mac = mac; + } + + public String getConnect_protocol() { + return connect_protocol; + } + + public void setConnect_protocol(String connect_protocol) { + this.connect_protocol = connect_protocol; + } + + public String getAuth_key() { + return auth_key; + } + + public void setAuth_key(String auth_key) { + this.auth_key = auth_key; + } + + public String getClose_strategy() { + return close_strategy; + } + + public void setClose_strategy(String close_strategy) { + this.close_strategy = close_strategy; + } + + public String getConn_strategy() { + return conn_strategy; + } + + public void setConn_strategy(String conn_strategy) { + this.conn_strategy = conn_strategy; + } + + public String getCrypt_method() { + return crypt_method; + } + + public void setCrypt_method(String crypt_method) { + this.crypt_method = crypt_method; + } + + public String getAuth_ver() { + return auth_ver; + } + + public void setAuth_ver(String auth_ver) { + this.auth_ver = auth_ver; + } + + public String getManu_mac_pos() { + return manu_mac_pos; + } + + public void setManu_mac_pos(String manu_mac_pos) { + this.manu_mac_pos = manu_mac_pos; + } + + public String getSer_mac_pos() { + return ser_mac_pos; + } + + public void setSer_mac_pos(String ser_mac_pos) { + this.ser_mac_pos = ser_mac_pos; + } + + public String getBle_simple_protocol() { + return ble_simple_protocol; + } + + public void setBle_simple_protocol(String ble_simple_protocol) { + this.ble_simple_protocol = ble_simple_protocol; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java new file mode 100644 index 0000000000..920a369e6c --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java @@ -0,0 +1,36 @@ +package me.chanjar.weixin.mp.bean.device; + +import java.util.List; + +/** + * Created by keungtung on 10/12/2016. + */ +public class WxDeviceAuthorize extends AbstractDeviceBean{ + private String deivce_num; + private String op_type; + private List device_list; + + public String getDeivce_num() { + return deivce_num; + } + + public void setDeivce_num(String deivce_num) { + this.deivce_num = deivce_num; + } + + public String getOp_type() { + return op_type; + } + + public void setOp_type(String op_type) { + this.op_type = op_type; + } + + public List getDevice_list() { + return device_list; + } + + public void setDevice_list(List device_list) { + this.device_list = device_list; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorizeResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorizeResult.java new file mode 100644 index 0000000000..dfe8d3b7fc --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorizeResult.java @@ -0,0 +1,24 @@ +package me.chanjar.weixin.mp.bean.device; + +import me.chanjar.weixin.common.util.json.WxGsonBuilder; + +import java.util.List; + +/** + * Created by keungtung on 10/12/2016. + */ +public class WxDeviceAuthorizeResult extends AbstractDeviceBean{ + private List resp; + + public static WxDeviceAuthorizeResult fromJson(String response) { + return WxGsonBuilder.create().fromJson(response, WxDeviceAuthorizeResult.class); + } + + public List getResp() { + return resp; + } + + public void setResp(List resp) { + this.resp = resp; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBind.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBind.java new file mode 100644 index 0000000000..e458847878 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBind.java @@ -0,0 +1,34 @@ +package me.chanjar.weixin.mp.bean.device; + +/** + * Created by keungtung on 10/12/2016. + */ +public class WxDeviceBind extends AbstractDeviceBean{ + private String ticket; + private String device_id; + private String openid; + + public String getTicket() { + return ticket; + } + + public void setTicket(String ticket) { + this.ticket = ticket; + } + + public String getDevice_id() { + return device_id; + } + + public void setDevice_id(String device_id) { + this.device_id = device_id; + } + + public String getOpenid() { + return openid; + } + + public void setOpenid(String openid) { + this.openid = openid; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBindResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBindResult.java new file mode 100644 index 0000000000..8f41a320b9 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBindResult.java @@ -0,0 +1,22 @@ +package me.chanjar.weixin.mp.bean.device; + +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; + +/** + * Created by keungtung on 10/12/2016. + */ +public class WxDeviceBindResult extends AbstractDeviceBean{ + private BaseResp base_resp; + + public static WxDeviceBindResult fromJson(String json) { + return WxMpGsonBuilder.create().fromJson(json, WxDeviceBindResult.class); + } + + public BaseResp getBase_resp() { + return base_resp; + } + + public void setBase_resp(BaseResp base_resp) { + this.base_resp = base_resp; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceMsg.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceMsg.java new file mode 100644 index 0000000000..e01f09abad --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceMsg.java @@ -0,0 +1,50 @@ +package me.chanjar.weixin.mp.bean.device; + +import me.chanjar.weixin.common.util.ToStringUtils; + +/** + * Created by keungtung on 10/12/2016. + */ +public class WxDeviceMsg extends AbstractDeviceBean{ + private String deviceType; + private String deviceId; + private String openId; + private String content; + + @Override + public String toString() { + return ToStringUtils.toSimpleString(this); + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public String getOpenId() { + return openId; + } + + public void setOpenId(String openId) { + this.openId = openId; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceQrCodeResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceQrCodeResult.java new file mode 100644 index 0000000000..c2f67c5f28 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceQrCodeResult.java @@ -0,0 +1,49 @@ +package me.chanjar.weixin.mp.bean.device; + +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; + +/** + * Created by keungtung on 10/12/2016. + */ +public class WxDeviceQrCodeResult extends AbstractDeviceBean{ + private String deviceid; + private String qrticket; + private String devcielicence; + private RespMsg resp_msg; + + public static WxDeviceQrCodeResult fromJson(String json) { + return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxDeviceQrCodeResult.class); + } + + public String getDevcielicence() { + return devcielicence; + } + + public void setDevcielicence(String devcielicence) { + this.devcielicence = devcielicence; + } + + public RespMsg getResp_msg() { + return resp_msg; + } + + public void setResp_msg(RespMsg resp_msg) { + this.resp_msg = resp_msg; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getQrticket() { + return qrticket; + } + + public void setQrticket(String qrticket) { + this.qrticket = qrticket; + } +} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java new file mode 100644 index 0000000000..e79dd25041 --- /dev/null +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java @@ -0,0 +1,40 @@ +package me.chanjar.weixin.mp.api.impl; + + +import com.google.inject.Inject; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.device.WxDeviceQrCodeResult; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +/** + * Created by keungtung on 14/12/2016. + */ +@Test(groups = "deviceApi") +@Guice(modules = ApiTestModule.class) +public class WxMpDeviceServiceImplTest { + @Inject + protected WxMpService wxService; + + @Test(dataProvider = "productId") + public void testGetQrcode(String productId) { + try { + WxDeviceQrCodeResult result = wxService.getDeviceService().getQrCode(productId); + println(result.toJson()); + } catch (WxErrorException e) { + println(e.getMessage()); + } + } + + private void println(String content) { + System.out.println(content); + } + + @DataProvider(name = "productId") + public Object[][] getProductId() { + return new Object[][]{new Object[]{"25639"}}; + } +} From 3e8b1a5dca8b9659b6292f93c149356af39ff0f5 Mon Sep 17 00:00:00 2001 From: dongfuqiang Date: Thu, 15 Dec 2016 12:09:13 +0800 Subject: [PATCH 12/80] update --- .../chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java index 920a369e6c..ce7317d615 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java @@ -1,11 +1,12 @@ package me.chanjar.weixin.mp.bean.device; +import java.util.Arrays; import java.util.List; /** * Created by keungtung on 10/12/2016. */ -public class WxDeviceAuthorize extends AbstractDeviceBean{ +public class WxDeviceAuthorize extends AbstractDeviceBean { private String deivce_num; private String op_type; private List device_list; @@ -33,4 +34,8 @@ public List getDevice_list() { public void setDevice_list(List device_list) { this.device_list = device_list; } + + public void addDevice(WxDevice... devices) { + this.device_list.addAll(Arrays.asList(devices)); + } } From 575458d12b8b99c2f310fb12f225f64e96865acd Mon Sep 17 00:00:00 2001 From: dongfuqiang Date: Thu, 15 Dec 2016 14:11:39 +0800 Subject: [PATCH 13/80] update --- .../me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java index ce7317d615..e1dcd9be12 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.bean.device; import java.util.Arrays; +import java.util.LinkedList; import java.util.List; /** @@ -9,7 +10,7 @@ public class WxDeviceAuthorize extends AbstractDeviceBean { private String deivce_num; private String op_type; - private List device_list; + private List device_list = new LinkedList<>(); public String getDeivce_num() { return deivce_num; From b8a9795cf5a67711ec77c56798e296a9b3a1fa4f Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 15 Dec 2016 15:23:29 +0800 Subject: [PATCH 14/80] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E9=87=8D=E8=AF=95=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E6=97=A0=E6=95=88=E7=AD=89=E5=BE=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/cp/api/WxCpServiceImpl.java | 12 ++++++++--- .../weixin/cp/api/WxCpBusyRetryTest.java | 14 ++++++------- .../weixin/mp/api/impl/WxMpServiceImpl.java | 11 ++++++++-- .../weixin/mp/api/WxMpBusyRetryTest.java | 20 +++++++++---------- 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java index d44bbf5f0d..734593d4ee 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java @@ -540,6 +540,12 @@ public T execute(RequestExecutor executor, String uri, E data) thro try { return executeInternal(executor, uri, data); } catch (WxErrorException e) { + if (retryTimes + 1 > this.maxRetryTimes) { + this.log.warn("重试达到最大次数【{}】", this.maxRetryTimes); + //最后一次重试失败后,直接抛出异常,不再等待 + throw new RuntimeException("微信服务端异常,超出重试次数"); + } + WxError error = e.getError(); /* * -1 系统繁忙, 1000ms后重试 @@ -547,8 +553,7 @@ public T execute(RequestExecutor executor, String uri, E data) thro if (error.getErrorCode() == -1) { int sleepMillis = this.retrySleepMillis * (1 << retryTimes); try { - this.log.debug("微信系统繁忙,{}ms 后重试(第{}次)", sleepMillis, - retryTimes + 1); + this.log.debug("微信系统繁忙,{} ms 后重试(第{}次)", sleepMillis, retryTimes + 1); Thread.sleep(sleepMillis); } catch (InterruptedException e1) { throw new RuntimeException(e1); @@ -557,8 +562,9 @@ public T execute(RequestExecutor executor, String uri, E data) thro throw e; } } - } while (++retryTimes < this.maxRetryTimes); + } while (retryTimes++ < this.maxRetryTimes); + this.log.warn("重试达到最大次数【{}】", this.maxRetryTimes); throw new RuntimeException("微信服务端异常,超出重试次数"); } diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBusyRetryTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBusyRetryTest.java index b3f96b1bb4..e1b005bd83 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBusyRetryTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBusyRetryTest.java @@ -1,17 +1,16 @@ package me.chanjar.weixin.cp.api; +import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.util.http.RequestExecutor; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.common.util.http.RequestExecutor; - @Test public class WxCpBusyRetryTest { @@ -23,6 +22,7 @@ public Object[][] getService() { protected synchronized T executeInternal( RequestExecutor executor, String uri, E data) throws WxErrorException { + this.log.info("Executed"); WxError error = new WxError(); error.setErrorCode(-1); throw new WxErrorException(error); 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 3c60232501..62b363a22d 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 @@ -369,12 +369,18 @@ public T execute(RequestExecutor executor, String uri, E data) thro this.log.debug("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}",uri, data, result); return result; } catch (WxErrorException e) { + if (retryTimes + 1 > this.maxRetryTimes) { + this.log.warn("重试达到最大次数【{}】", maxRetryTimes); + //最后一次重试失败后,直接抛出异常,不再等待 + throw new RuntimeException("微信服务端异常,超出重试次数"); + } + WxError error = e.getError(); // -1 系统繁忙, 1000ms后重试 if (error.getErrorCode() == -1) { int sleepMillis = this.retrySleepMillis * (1 << retryTimes); try { - this.log.debug("微信系统繁忙,{}ms 后重试(第{}次)", sleepMillis, retryTimes + 1); + this.log.warn("微信系统繁忙,{} ms 后重试(第{}次)", sleepMillis, retryTimes + 1); Thread.sleep(sleepMillis); } catch (InterruptedException e1) { throw new RuntimeException(e1); @@ -383,8 +389,9 @@ public T execute(RequestExecutor executor, String uri, E data) thro throw e; } } - } while (++retryTimes < this.maxRetryTimes); + } while (retryTimes++ < this.maxRetryTimes); + this.log.warn("重试达到最大次数【{}】", this.maxRetryTimes); throw new RuntimeException("微信服务端异常,超出重试次数"); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java index a302cc2fa4..8d46eba767 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java @@ -1,17 +1,16 @@ package me.chanjar.weixin.mp.api; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; @Test public class WxMpBusyRetryTest { @@ -24,6 +23,7 @@ public Object[][] getService() { protected synchronized T executeInternal( RequestExecutor executor, String uri, E data) throws WxErrorException { + this.log.info("Executed"); WxError error = new WxError(); error.setErrorCode(-1); throw new WxErrorException(error); @@ -32,9 +32,7 @@ protected synchronized T executeInternal( service.setMaxRetryTimes(3); service.setRetrySleepMillis(500); - return new Object[][] { - new Object[] { service } - }; + return new Object[][] { { service } }; } @Test(dataProvider = "getService", expectedExceptions = RuntimeException.class) From 00421c4e6fc1c431a9895f04beede02795bf1093 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 15 Dec 2016 15:26:12 +0800 Subject: [PATCH 15/80] =?UTF-8?q?=E4=B8=BA=E6=8E=A5=E5=8F=A3=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java index 734593d4ee..a2bd365912 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java @@ -538,7 +538,9 @@ public T execute(RequestExecutor executor, String uri, E data) thro int retryTimes = 0; do { try { - return executeInternal(executor, uri, data); + T result = this.executeInternal(executor, uri, data); + this.log.debug("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}",uri, data, result); + return result; } catch (WxErrorException e) { if (retryTimes + 1 > this.maxRetryTimes) { this.log.warn("重试达到最大次数【{}】", this.maxRetryTimes); @@ -578,8 +580,7 @@ protected synchronized T executeInternal(RequestExecutor executor, uriWithAccessToken += uri.indexOf('?') == -1 ? "?access_token=" + accessToken : "&access_token=" + accessToken; try { - return executor.execute(getHttpclient(), this.httpProxy, - uriWithAccessToken, data); + return executor.execute(getHttpclient(), this.httpProxy, uriWithAccessToken, data); } catch (WxErrorException e) { WxError error = e.getError(); /* @@ -592,11 +593,14 @@ protected synchronized T executeInternal(RequestExecutor executor, this.configStorage.expireAccessToken(); return 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; } catch (IOException e) { + this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[EXCEPTION]: {}", uri, data, e.getMessage()); throw new RuntimeException(e); } } From 84a79a9760e58db0daf776301834005ad7d2c8c2 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 15 Dec 2016 16:00:02 +0800 Subject: [PATCH 16/80] ".equals()" should not be used to test the values of "Atomic" classes --- .../weixin/common/session/StandardSession.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSession.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSession.java index 89d847d7bd..dc2a010545 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSession.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSession.java @@ -12,7 +12,7 @@ public class StandardSession implements WxSession, InternalSession { * The string manager for this package. */ protected static final StringManager sm = - StringManager.getManager(Constants.Package); + StringManager.getManager(Constants.Package); /** * Type array. */ @@ -73,7 +73,7 @@ public Object getAttribute(String name) { if (!isValidInternal()) throw new IllegalStateException - (sm.getString("sessionImpl.getAttribute.ise")); + (sm.getString("sessionImpl.getAttribute.ise")); if (name == null) return null; @@ -84,7 +84,7 @@ public Object getAttribute(String name) { public Enumeration getAttributeNames() { if (!isValidInternal()) throw new IllegalStateException - (sm.getString("sessionImpl.getAttributeNames.ise")); + (sm.getString("sessionImpl.getAttributeNames.ise")); Set names = new HashSet<>(); names.addAll(this.attributes.keySet()); @@ -96,7 +96,7 @@ public void setAttribute(String name, Object value) { // Name cannot be null if (name == null) throw new IllegalArgumentException - (sm.getString("sessionImpl.setAttribute.namenull")); + (sm.getString("sessionImpl.setAttribute.namenull")); // Null value is the same as removeAttribute() if (value == null) { @@ -107,7 +107,7 @@ public void setAttribute(String name, Object value) { // Validate our current state if (!isValidInternal()) throw new IllegalStateException(sm.getString( - "sessionImpl.setAttribute.ise", getIdInternal())); + "sessionImpl.setAttribute.ise", getIdInternal())); this.attributes.put(name, value); @@ -122,7 +122,7 @@ public void removeAttribute(String name) { public void invalidate() { if (!isValidInternal()) throw new IllegalStateException - (sm.getString("sessionImpl.invalidate.ise")); + (sm.getString("sessionImpl.invalidate.ise")); // Cause this session to expire expire(); @@ -305,7 +305,7 @@ public boolean equals(Object o) { if (this.isValid != session.isValid) return false; if (this.maxInactiveInterval != session.maxInactiveInterval) return false; if (this.thisAccessedTime != session.thisAccessedTime) return false; - if (!this.accessCount.equals(session.accessCount)) return false; + if (this.accessCount.get() != session.accessCount.get()) return false; if (!this.attributes.equals(session.attributes)) return false; if (!this.facade.equals(session.facade)) return false; if (!this.id.equals(session.id)) return false; From 761c570cad87432d0be557c749c30d289fd528b7 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 15 Dec 2016 16:13:49 +0800 Subject: [PATCH 17/80] =?UTF-8?q?=E6=B6=88=E7=81=AD=E4=B8=8D=E8=A7=84?= =?UTF-8?q?=E8=8C=83=E4=BB=A3=E7=A0=81=EF=BC=88=E7=94=B1sonatype=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E5=87=BA=E6=9D=A5=E7=9A=84=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/session/StandardSession.java | 110 +++++++++++------- 1 file changed, 69 insertions(+), 41 deletions(-) diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSession.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSession.java index dc2a010545..f9d61707e3 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSession.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSession.java @@ -11,12 +11,12 @@ public class StandardSession implements WxSession, InternalSession { /** * The string manager for this package. */ - protected static final StringManager sm = - StringManager.getManager(Constants.Package); + protected static final StringManager sm = StringManager.getManager(Constants.Package); /** * Type array. */ - protected static final String EMPTY_ARRAY[] = new String[0]; + private static final String[] EMPTY_ARRAY = new String[0]; + // ------------------------------ WxSession protected Map attributes = new ConcurrentHashMap<>(); /** @@ -71,20 +71,23 @@ public StandardSession(InternalSessionManager manager) { @Override public Object getAttribute(String name) { - if (!isValidInternal()) + if (!isValidInternal()) { throw new IllegalStateException (sm.getString("sessionImpl.getAttribute.ise")); + } - if (name == null) return null; + if (name == null) { + return null; + } - return (this.attributes.get(name)); + return this.attributes.get(name); } @Override public Enumeration getAttributeNames() { - if (!isValidInternal()) - throw new IllegalStateException - (sm.getString("sessionImpl.getAttributeNames.ise")); + if (!isValidInternal()) { + throw new IllegalStateException(sm.getString("sessionImpl.getAttributeNames.ise")); + } Set names = new HashSet<>(); names.addAll(this.attributes.keySet()); @@ -94,9 +97,9 @@ public Enumeration getAttributeNames() { @Override public void setAttribute(String name, Object value) { // Name cannot be null - if (name == null) - throw new IllegalArgumentException - (sm.getString("sessionImpl.setAttribute.namenull")); + if (name == null) { + throw new IllegalArgumentException(sm.getString("sessionImpl.setAttribute.namenull")); + } // Null value is the same as removeAttribute() if (value == null) { @@ -105,9 +108,9 @@ public void setAttribute(String name, Object value) { } // Validate our current state - if (!isValidInternal()) - throw new IllegalStateException(sm.getString( - "sessionImpl.setAttribute.ise", getIdInternal())); + if (!isValidInternal()) { + throw new IllegalStateException(sm.getString("sessionImpl.setAttribute.ise", getIdInternal())); + } this.attributes.put(name, value); @@ -121,8 +124,7 @@ public void removeAttribute(String name) { @Override public void invalidate() { if (!isValidInternal()) - throw new IllegalStateException - (sm.getString("sessionImpl.invalidate.ise")); + throw new IllegalStateException(sm.getString("sessionImpl.invalidate.ise")); // Cause this session to expire expire(); @@ -131,12 +133,11 @@ public void invalidate() { @Override public WxSession getSession() { - if (this.facade == null) { this.facade = new StandardSessionFacade(this); } - return (this.facade); + return this.facade; } /** @@ -185,12 +186,14 @@ public void setValid(boolean isValid) { @Override public String getIdInternal() { - return (this.id); + return this.id; } protected void removeAttributeInternal(String name) { // Avoid NPE - if (name == null) return; + if (name == null) { + return; + } // Remove this attribute from our collection this.attributes.remove(name); @@ -202,19 +205,22 @@ public void expire() { // Check to see if session has already been invalidated. // Do not check expiring at this point as expire should not return until // isValid is false - if (!this.isValid) + if (!this.isValid) { return; + } synchronized (this) { // Check again, now we are inside the sync so this code only runs once // Double check locking - isValid needs to be volatile // The check of expiring is to ensure that an infinite loop is not // entered as per bug 56339 - if (this.expiring || !this.isValid) + if (this.expiring || !this.isValid) { return; + } - if (this.manager == null) + if (this.manager == null) { return; + } // Mark this session as "being expired" this.expiring = true; @@ -230,9 +236,9 @@ public void expire() { this.expiring = false; // Unbind any objects associated with this session - String keys[] = keys(); - for (int i = 0; i < keys.length; i++) { - removeAttributeInternal(keys[i]); + String[] keys = keys(); + for (String key : keys) { + removeAttributeInternal(key); } } @@ -273,13 +279,15 @@ public void setMaxInactiveInterval(int interval) { @Override public void setId(String id) { - if ((this.id != null) && (this.manager != null)) + if ((this.id != null) && (this.manager != null)) { this.manager.remove(this); + } this.id = id; - if (this.manager != null) + if (this.manager != null) { this.manager.add(this); + } } /** @@ -295,21 +303,41 @@ protected String[] keys() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof StandardSession)) return false; + if (this == o) { + return true; + } + if (!(o instanceof StandardSession)) { + return false; + } StandardSession session = (StandardSession) o; - if (this.creationTime != session.creationTime) return false; - if (this.expiring != session.expiring) return false; - if (this.isValid != session.isValid) return false; - if (this.maxInactiveInterval != session.maxInactiveInterval) return false; - if (this.thisAccessedTime != session.thisAccessedTime) return false; - if (this.accessCount.get() != session.accessCount.get()) return false; - if (!this.attributes.equals(session.attributes)) return false; - if (!this.facade.equals(session.facade)) return false; - if (!this.id.equals(session.id)) return false; - return this.manager.equals(session.manager); + if (this.creationTime != session.creationTime) { + return false; + } + if (this.expiring != session.expiring) { + return false; + } + if (this.isValid != session.isValid) { + return false; + } + if (this.maxInactiveInterval != session.maxInactiveInterval) { + return false; + } + if (this.thisAccessedTime != session.thisAccessedTime) { + return false; + } + if (this.accessCount.get() != session.accessCount.get()) { + return false; + } + if (!this.attributes.equals(session.attributes)) { + return false; + } + if (!this.facade.equals(session.facade)) { + return false; + } + + return this.id.equals(session.id) && this.manager.equals(session.manager); } From 1524de26e62815ba37e2ecdbf0d037ebd8beb7df Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 15 Dec 2016 16:41:14 +0800 Subject: [PATCH 18/80] =?UTF-8?q?=E6=B6=88=E7=81=AD=E4=B8=8D=E8=A7=84?= =?UTF-8?q?=E8=8C=83=E4=BB=A3=E7=A0=81=EF=BC=88=E7=94=B1sonatype=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E5=87=BA=E6=9D=A5=E7=9A=84=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/me/chanjar/weixin/common/bean/result/WxError.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java index 54b8b1fdc4..46c0ae89be 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java @@ -20,8 +20,7 @@ public class WxError implements Serializable { private String json; public static WxError fromJson(String json) { - WxError error = WxGsonBuilder.create().fromJson(json, WxError.class); - return error; + return WxGsonBuilder.create().fromJson(json, WxError.class); } public static Builder newBuilder() { From 4812697b36f19c223637c5be335c2184e08e073b Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 15 Dec 2016 16:41:26 +0800 Subject: [PATCH 19/80] =?UTF-8?q?=E6=B6=88=E7=81=AD=E4=B8=8D=E8=A7=84?= =?UTF-8?q?=E8=8C=83=E4=BB=A3=E7=A0=81=EF=BC=88=E7=94=B1sonatype=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E5=87=BA=E6=9D=A5=E7=9A=84=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mp/bean/message/WxMpXmlMessageTest.java | 208 +++++++++--------- 1 file changed, 104 insertions(+), 104 deletions(-) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java index 8f49ce99e7..23de3fe667 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java @@ -10,63 +10,63 @@ public class WxMpXmlMessageTest { public void testFromXml() { String xml = "" - + "" - + " " - + "1348831860" - + "" - + "" - + "1234567890123456" - + "" - + "" - + "" - + "" - + "23.134521" - + "113.358803" - + "20" - + "" - + "" - + "" - + "<![CDATA[公众平台官网链接]]>" - + "" - + "" - + "" - + "23.137466" - + "113.352425" - + "119.385040" - + "" - + " " - + " " - + "" - + "" - + " 1\n" - + " " - + " " - + " " - + " " - + " " - + "" - + "" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + "" - + ""; + + "" + + " " + + "1348831860" + + "" + + "" + + "1234567890123456" + + "" + + "" + + "" + + "" + + "23.134521" + + "113.358803" + + "20" + + "" + + "" + + "" + + "<![CDATA[公众平台官网链接]]>" + + "" + + "" + + "" + + "23.137466" + + "113.352425" + + "119.385040" + + "" + + " " + + " " + + "" + + "" + + " 1\n" + + " " + + " " + + " " + + " " + + " " + + "" + + "" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "" + + ""; WxMpXmlMessage wxMessage = WxMpXmlMessage.fromXml(xml); Assert.assertEquals(wxMessage.getToUser(), "toUser"); Assert.assertEquals(wxMessage.getFromUser(), "fromUser"); - Assert.assertEquals(wxMessage.getCreateTime(), new Long(1348831860l)); + Assert.assertEquals(wxMessage.getCreateTime(), new Long(1348831860L)); Assert.assertEquals(wxMessage.getMsgType(), WxConsts.XML_MSG_TEXT); Assert.assertEquals(wxMessage.getContent(), "this is a test"); - Assert.assertEquals(wxMessage.getMsgId(), new Long(1234567890123456l)); + Assert.assertEquals(wxMessage.getMsgId(), new Long(1234567890123456L)); Assert.assertEquals(wxMessage.getPicUrl(), "this is a url"); Assert.assertEquals(wxMessage.getMediaId(), "media_id"); Assert.assertEquals(wxMessage.getFormat(), "Format"); Assert.assertEquals(wxMessage.getThumbMediaId(), "thumb_media_id"); - Assert.assertEquals(wxMessage.getLocationX(), new Double(23.134521d)); - Assert.assertEquals(wxMessage.getLocationY(), new Double(113.358803d)); - Assert.assertEquals(wxMessage.getScale(), new Double(20)); + Assert.assertEquals(wxMessage.getLocationX(), 23.134521d); + Assert.assertEquals(wxMessage.getLocationY(), 113.358803d); + Assert.assertEquals(wxMessage.getScale(), 20d); Assert.assertEquals(wxMessage.getLabel(), "位置信息"); Assert.assertEquals(wxMessage.getDescription(), "公众平台官网链接"); Assert.assertEquals(wxMessage.getUrl(), "url"); @@ -74,12 +74,12 @@ public void testFromXml() { Assert.assertEquals(wxMessage.getEvent(), "subscribe"); Assert.assertEquals(wxMessage.getEventKey(), "qrscene_123123"); Assert.assertEquals(wxMessage.getTicket(), "TICKET"); - Assert.assertEquals(wxMessage.getLatitude(), new Double(23.137466)); - Assert.assertEquals(wxMessage.getLongitude(), new Double(113.352425)); - Assert.assertEquals(wxMessage.getPrecision(), new Double(119.385040)); + Assert.assertEquals(wxMessage.getLatitude(), 23.137466); + Assert.assertEquals(wxMessage.getLongitude(), 113.352425); + Assert.assertEquals(wxMessage.getPrecision(), 119.385040); Assert.assertEquals(wxMessage.getScanCodeInfo().getScanType(), "qrcode"); Assert.assertEquals(wxMessage.getScanCodeInfo().getScanResult(), "1"); - Assert.assertEquals(wxMessage.getSendPicsInfo().getCount(), new Long(1l)); + Assert.assertEquals(wxMessage.getSendPicsInfo().getCount(), new Long(1L)); Assert.assertEquals(wxMessage.getSendPicsInfo().getPicList().get(0).getPicMd5Sum(), "1b5f7c23b5bf75682a53e7b6d163e185"); Assert.assertEquals(wxMessage.getSendLocationInfo().getLocationX(), "23"); Assert.assertEquals(wxMessage.getSendLocationInfo().getLocationY(), "113"); @@ -91,63 +91,63 @@ public void testFromXml() { public void testFromXml2() { String xml = "" - + "" - + " " - + "1348831860" - + "" - + "" - + "1234567890123456" - + "" - + "" - + "" - + "" - + "23.134521" - + "113.358803" - + "20" - + "" - + "" - + "" - + "<![CDATA[公众平台官网链接]]>" - + "" - + "" - + "" - + "23.137466" - + "113.352425" - + "119.385040" - + "" - + " " - + " " - + "" - + "" - + " 1\n" - + " " - + " " - + " " - + " " - + " " - + "" - + "" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + "" - + ""; + + "" + + " " + + "1348831860" + + "" + + "" + + "1234567890123456" + + "" + + "" + + "" + + "" + + "23.134521" + + "113.358803" + + "20" + + "" + + "" + + "" + + "<![CDATA[公众平台官网链接]]>" + + "" + + "" + + "" + + "23.137466" + + "113.352425" + + "119.385040" + + "" + + " " + + " " + + "" + + "" + + " 1\n" + + " " + + " " + + " " + + " " + + " " + + "" + + "" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "" + + ""; WxMpXmlMessage wxMessage = WxMpXmlMessage.fromXml(xml); Assert.assertEquals(wxMessage.getToUser(), "toUser"); Assert.assertEquals(wxMessage.getFromUser(), "fromUser"); - Assert.assertEquals(wxMessage.getCreateTime(), new Long(1348831860l)); + Assert.assertEquals(wxMessage.getCreateTime(), new Long(1348831860L)); Assert.assertEquals(wxMessage.getMsgType(), WxConsts.XML_MSG_TEXT); Assert.assertEquals(wxMessage.getContent(), "this is a test"); - Assert.assertEquals(wxMessage.getMsgId(), new Long(1234567890123456l)); + Assert.assertEquals(wxMessage.getMsgId(), new Long(1234567890123456L)); Assert.assertEquals(wxMessage.getPicUrl(), "this is a url"); Assert.assertEquals(wxMessage.getMediaId(), "media_id"); Assert.assertEquals(wxMessage.getFormat(), "Format"); Assert.assertEquals(wxMessage.getThumbMediaId(), "thumb_media_id"); - Assert.assertEquals(wxMessage.getLocationX(), new Double(23.134521d)); - Assert.assertEquals(wxMessage.getLocationY(), new Double(113.358803d)); - Assert.assertEquals(wxMessage.getScale(), new Double(20)); + Assert.assertEquals(wxMessage.getLocationX(), 23.134521d); + Assert.assertEquals(wxMessage.getLocationY(), 113.358803d); + Assert.assertEquals(wxMessage.getScale(), 20d); Assert.assertEquals(wxMessage.getLabel(), "位置信息"); Assert.assertEquals(wxMessage.getDescription(), "公众平台官网链接"); Assert.assertEquals(wxMessage.getUrl(), "url"); @@ -155,12 +155,12 @@ public void testFromXml2() { Assert.assertEquals(wxMessage.getEvent(), "subscribe"); Assert.assertEquals(wxMessage.getEventKey(), "qrscene_123123"); Assert.assertEquals(wxMessage.getTicket(), "TICKET"); - Assert.assertEquals(wxMessage.getLatitude(), new Double(23.137466)); - Assert.assertEquals(wxMessage.getLongitude(), new Double(113.352425)); - Assert.assertEquals(wxMessage.getPrecision(), new Double(119.385040)); + Assert.assertEquals(wxMessage.getLatitude(), 23.137466); + Assert.assertEquals(wxMessage.getLongitude(), 113.352425); + Assert.assertEquals(wxMessage.getPrecision(), 119.385040); Assert.assertEquals(wxMessage.getScanCodeInfo().getScanType(), "qrcode"); Assert.assertEquals(wxMessage.getScanCodeInfo().getScanResult(), "1"); - Assert.assertEquals(wxMessage.getSendPicsInfo().getCount(), new Long(1l)); + Assert.assertEquals(wxMessage.getSendPicsInfo().getCount(), new Long(1L)); Assert.assertEquals(wxMessage.getSendPicsInfo().getPicList().get(0).getPicMd5Sum(), "1b5f7c23b5bf75682a53e7b6d163e185"); Assert.assertEquals(wxMessage.getSendLocationInfo().getLocationX(), "23"); Assert.assertEquals(wxMessage.getSendLocationInfo().getLocationY(), "113"); From 52221e72fc1f234a15c30bd5c9cc71305d6c1444 Mon Sep 17 00:00:00 2001 From: dongfuqiang Date: Fri, 16 Dec 2016 11:15:24 +0800 Subject: [PATCH 20/80] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/bean/device/BaseResp.java | 13 ++- .../weixin/mp/bean/device/RespMsg.java | 4 + .../weixin/mp/bean/device/TransMsgResp.java | 12 ++- .../weixin/mp/bean/device/WxDevice.java | 101 ++++++++++-------- .../mp/bean/device/WxDeviceAuthorize.java | 39 ++++--- .../weixin/mp/bean/device/WxDeviceBind.java | 13 ++- .../mp/bean/device/WxDeviceBindResult.java | 12 ++- .../weixin/mp/bean/device/WxDeviceMsg.java | 4 + .../mp/bean/device/WxDeviceQrCodeResult.java | 45 ++++---- 9 files changed, 141 insertions(+), 102 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/BaseResp.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/BaseResp.java index 5a3082f66b..42c57f0b4d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/BaseResp.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/BaseResp.java @@ -1,10 +1,13 @@ package me.chanjar.weixin.mp.bean.device; +import com.google.gson.annotations.SerializedName; + /** * Created by keungtung on 10/12/2016. */ public class BaseResp extends AbstractDeviceBean{ - private BaseInfo base_info; + @SerializedName("base_info") + private BaseInfo baseInfo; private Integer errcode; private String errmsg; @@ -16,12 +19,12 @@ public void setErrcode(Integer errcode) { this.errcode = errcode; } - public BaseInfo getBase_info() { - return base_info; + public BaseInfo getBaseInfo() { + return baseInfo; } - public void setBase_info(BaseInfo base_info) { - this.base_info = base_info; + public void setBaseInfo(BaseInfo baseInfo) { + this.baseInfo = baseInfo; } public String getErrmsg() { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/RespMsg.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/RespMsg.java index e0291fbbe3..f1fdedff94 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/RespMsg.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/RespMsg.java @@ -1,11 +1,15 @@ package me.chanjar.weixin.mp.bean.device; +import com.google.gson.annotations.SerializedName; + /** * Created by keungtung on 10/12/2016. */ public class RespMsg extends AbstractDeviceBean{ + @SerializedName("ret_code") private Integer retCode; + @SerializedName("error_info") private String errorInfo; public Integer getRetCode() { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/TransMsgResp.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/TransMsgResp.java index 6d5fbe0642..d1f6484f85 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/TransMsgResp.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/TransMsgResp.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean.device; +import com.google.gson.annotations.SerializedName; import me.chanjar.weixin.common.util.json.WxGsonBuilder; /** @@ -7,7 +8,8 @@ */ public class TransMsgResp extends AbstractDeviceBean{ private Integer ret; - private String ret_info; + @SerializedName("ret_info") + private String retInfo; private Integer errcode; private String errmsg; @@ -23,12 +25,12 @@ public void setRet(Integer ret) { this.ret = ret; } - public String getRet_info() { - return ret_info; + public String getRetInfo() { + return retInfo; } - public void setRet_info(String ret_info) { - this.ret_info = ret_info; + public void setRetInfo(String retInfo) { + this.retInfo = retInfo; } public Integer getErrcode() { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDevice.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDevice.java index f36c4b1016..c0f95dbf2a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDevice.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDevice.java @@ -1,20 +1,31 @@ package me.chanjar.weixin.mp.bean.device; +import com.google.gson.annotations.SerializedName; + /** * Created by keungtung on 10/12/2016. */ public class WxDevice { private String id; private String mac; - private String connect_protocol; - private String auth_key; - private String close_strategy; - private String conn_strategy; - private String crypt_method; - private String auth_ver; - private String manu_mac_pos; - private String ser_mac_pos; - private String ble_simple_protocol; + @SerializedName("connect_protocol") + private String connectProtocol; + @SerializedName("auth_key") + private String authKey; + @SerializedName("close_strategy") + private String closeStrategy; + @SerializedName("conn_strategy") + private String connStrategy; + @SerializedName("crypt_method") + private String cryptMethod; + @SerializedName("auth_ver") + private String authVer; + @SerializedName("manu_mac_pos") + private String manuMacPos; + @SerializedName("ser_mac_pos") + private String serMacPos; + @SerializedName("ble_simple_protocol") + private String bleSimpleProtocol; public String getId() { return id; @@ -32,75 +43,75 @@ public void setMac(String mac) { this.mac = mac; } - public String getConnect_protocol() { - return connect_protocol; + public String getConnectProtocol() { + return connectProtocol; } - public void setConnect_protocol(String connect_protocol) { - this.connect_protocol = connect_protocol; + public void setConnectProtocol(String connectProtocol) { + this.connectProtocol = connectProtocol; } - public String getAuth_key() { - return auth_key; + public String getAuthKey() { + return authKey; } - public void setAuth_key(String auth_key) { - this.auth_key = auth_key; + public void setAuthKey(String authKey) { + this.authKey = authKey; } - public String getClose_strategy() { - return close_strategy; + public String getCloseStrategy() { + return closeStrategy; } - public void setClose_strategy(String close_strategy) { - this.close_strategy = close_strategy; + public void setCloseStrategy(String closeStrategy) { + this.closeStrategy = closeStrategy; } - public String getConn_strategy() { - return conn_strategy; + public String getConnStrategy() { + return connStrategy; } - public void setConn_strategy(String conn_strategy) { - this.conn_strategy = conn_strategy; + public void setConnStrategy(String connStrategy) { + this.connStrategy = connStrategy; } - public String getCrypt_method() { - return crypt_method; + public String getCryptMethod() { + return cryptMethod; } - public void setCrypt_method(String crypt_method) { - this.crypt_method = crypt_method; + public void setCryptMethod(String cryptMethod) { + this.cryptMethod = cryptMethod; } - public String getAuth_ver() { - return auth_ver; + public String getAuthVer() { + return authVer; } - public void setAuth_ver(String auth_ver) { - this.auth_ver = auth_ver; + public void setAuthVer(String authVer) { + this.authVer = authVer; } - public String getManu_mac_pos() { - return manu_mac_pos; + public String getManuMacPos() { + return manuMacPos; } - public void setManu_mac_pos(String manu_mac_pos) { - this.manu_mac_pos = manu_mac_pos; + public void setManuMacPos(String manuMacPos) { + this.manuMacPos = manuMacPos; } - public String getSer_mac_pos() { - return ser_mac_pos; + public String getSerMacPos() { + return serMacPos; } - public void setSer_mac_pos(String ser_mac_pos) { - this.ser_mac_pos = ser_mac_pos; + public void setSerMacPos(String serMacPos) { + this.serMacPos = serMacPos; } - public String getBle_simple_protocol() { - return ble_simple_protocol; + public String getBleSimpleProtocol() { + return bleSimpleProtocol; } - public void setBle_simple_protocol(String ble_simple_protocol) { - this.ble_simple_protocol = ble_simple_protocol; + public void setBleSimpleProtocol(String bleSimpleProtocol) { + this.bleSimpleProtocol = bleSimpleProtocol; } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java index e1dcd9be12..a37a8a420d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java @@ -1,5 +1,7 @@ package me.chanjar.weixin.mp.bean.device; +import com.google.gson.annotations.SerializedName; + import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -8,35 +10,38 @@ * Created by keungtung on 10/12/2016. */ public class WxDeviceAuthorize extends AbstractDeviceBean { - private String deivce_num; - private String op_type; - private List device_list = new LinkedList<>(); - - public String getDeivce_num() { - return deivce_num; + @SerializedName("device_num") + private String deviceNum; + @SerializedName("op_type") + private String opType; + @SerializedName("device_list") + private List deviceList = new LinkedList<>(); + + public String getDeviceNum() { + return deviceNum; } - public void setDeivce_num(String deivce_num) { - this.deivce_num = deivce_num; + public void setDeviceNum(String deviceNum) { + this.deviceNum = deviceNum; } - public String getOp_type() { - return op_type; + public String getOpType() { + return opType; } - public void setOp_type(String op_type) { - this.op_type = op_type; + public void setOpType(String opType) { + this.opType = opType; } - public List getDevice_list() { - return device_list; + public List getDeviceList() { + return deviceList; } - public void setDevice_list(List device_list) { - this.device_list = device_list; + public void setDeviceList(List deviceList) { + this.deviceList = deviceList; } public void addDevice(WxDevice... devices) { - this.device_list.addAll(Arrays.asList(devices)); + this.deviceList.addAll(Arrays.asList(devices)); } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBind.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBind.java index e458847878..1236048ce1 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBind.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBind.java @@ -1,11 +1,14 @@ package me.chanjar.weixin.mp.bean.device; +import com.google.gson.annotations.SerializedName; + /** * Created by keungtung on 10/12/2016. */ public class WxDeviceBind extends AbstractDeviceBean{ private String ticket; - private String device_id; + @SerializedName("device_id") + private String deviceId; private String openid; public String getTicket() { @@ -16,12 +19,12 @@ public void setTicket(String ticket) { this.ticket = ticket; } - public String getDevice_id() { - return device_id; + public String getDeviceId() { + return deviceId; } - public void setDevice_id(String device_id) { - this.device_id = device_id; + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; } public String getOpenid() { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBindResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBindResult.java index 8f41a320b9..26bdb84c6a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBindResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBindResult.java @@ -1,22 +1,24 @@ package me.chanjar.weixin.mp.bean.device; +import com.google.gson.annotations.SerializedName; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; /** * Created by keungtung on 10/12/2016. */ public class WxDeviceBindResult extends AbstractDeviceBean{ - private BaseResp base_resp; + @SerializedName("base_resp") + private BaseResp baseResp; public static WxDeviceBindResult fromJson(String json) { return WxMpGsonBuilder.create().fromJson(json, WxDeviceBindResult.class); } - public BaseResp getBase_resp() { - return base_resp; + public BaseResp getBaseResp() { + return baseResp; } - public void setBase_resp(BaseResp base_resp) { - this.base_resp = base_resp; + public void setBaseResp(BaseResp baseResp) { + this.baseResp = baseResp; } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceMsg.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceMsg.java index e01f09abad..bed1a8a23a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceMsg.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceMsg.java @@ -1,13 +1,17 @@ package me.chanjar.weixin.mp.bean.device; +import com.google.gson.annotations.SerializedName; import me.chanjar.weixin.common.util.ToStringUtils; /** * Created by keungtung on 10/12/2016. */ public class WxDeviceMsg extends AbstractDeviceBean{ + @SerializedName("device_type") private String deviceType; + @SerializedName("device_id") private String deviceId; + @SerializedName("open_id") private String openId; private String content; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceQrCodeResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceQrCodeResult.java index c2f67c5f28..9c89ff679e 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceQrCodeResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceQrCodeResult.java @@ -1,49 +1,54 @@ package me.chanjar.weixin.mp.bean.device; +import com.google.gson.annotations.SerializedName; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; /** * Created by keungtung on 10/12/2016. */ public class WxDeviceQrCodeResult extends AbstractDeviceBean{ - private String deviceid; - private String qrticket; - private String devcielicence; - private RespMsg resp_msg; + @SerializedName("deviceid") + private String deviceId; + @SerializedName("qrticket") + private String qrTicket; + @SerializedName("devicelicence") + private String deviceLicence; + @SerializedName("resp_msg") + private RespMsg respMsg; public static WxDeviceQrCodeResult fromJson(String json) { return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxDeviceQrCodeResult.class); } - public String getDevcielicence() { - return devcielicence; + public String getDeviceLicence() { + return deviceLicence; } - public void setDevcielicence(String devcielicence) { - this.devcielicence = devcielicence; + public void setDeviceLicence(String deviceLicence) { + this.deviceLicence = deviceLicence; } - public RespMsg getResp_msg() { - return resp_msg; + public RespMsg getRespMsg() { + return respMsg; } - public void setResp_msg(RespMsg resp_msg) { - this.resp_msg = resp_msg; + public void setRespMsg(RespMsg respMsg) { + this.respMsg = respMsg; } - public String getDeviceid() { - return deviceid; + public String getDeviceId() { + return deviceId; } - public void setDeviceid(String deviceid) { - this.deviceid = deviceid; + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; } - public String getQrticket() { - return qrticket; + public String getQrTicket() { + return qrTicket; } - public void setQrticket(String qrticket) { - this.qrticket = qrticket; + public void setQrTicket(String qrTicket) { + this.qrTicket = qrTicket; } } From a2106d30eca13f3ac584e3d715d2820722c1094c Mon Sep 17 00:00:00 2001 From: dongfuqiang Date: Fri, 16 Dec 2016 11:21:00 +0800 Subject: [PATCH 21/80] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/bean/device/BaseResp.java | 22 ++++++++++--------- .../weixin/mp/bean/device/TransMsgResp.java | 22 ++++++++++--------- .../weixin/mp/bean/device/WxDeviceBind.java | 11 +++++----- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/BaseResp.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/BaseResp.java index 42c57f0b4d..41629c55fe 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/BaseResp.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/BaseResp.java @@ -8,15 +8,17 @@ public class BaseResp extends AbstractDeviceBean{ @SerializedName("base_info") private BaseInfo baseInfo; - private Integer errcode; - private String errmsg; + @SerializedName("errcode") + private Integer errCode; + @SerializedName("errmsg") + private String errMsg; - public Integer getErrcode() { - return errcode; + public Integer getErrCode() { + return errCode; } - public void setErrcode(Integer errcode) { - this.errcode = errcode; + public void setErrCode(Integer errCode) { + this.errCode = errCode; } public BaseInfo getBaseInfo() { @@ -27,12 +29,12 @@ public void setBaseInfo(BaseInfo baseInfo) { this.baseInfo = baseInfo; } - public String getErrmsg() { - return errmsg; + public String getErrMsg() { + return errMsg; } - public void setErrmsg(String errmsg) { - this.errmsg = errmsg; + public void setErrMsg(String errMsg) { + this.errMsg = errMsg; } private class BaseInfo { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/TransMsgResp.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/TransMsgResp.java index d1f6484f85..8828b25c9e 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/TransMsgResp.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/TransMsgResp.java @@ -10,8 +10,10 @@ public class TransMsgResp extends AbstractDeviceBean{ private Integer ret; @SerializedName("ret_info") private String retInfo; - private Integer errcode; - private String errmsg; + @SerializedName("errcode") + private Integer errCode; + @SerializedName("errmsg") + private String errMsg; public static TransMsgResp fromJson(String json) { return WxGsonBuilder.create().fromJson(json, TransMsgResp.class); @@ -33,19 +35,19 @@ public void setRetInfo(String retInfo) { this.retInfo = retInfo; } - public Integer getErrcode() { - return errcode; + public Integer getErrCode() { + return errCode; } - public void setErrcode(Integer errcode) { - this.errcode = errcode; + public void setErrCode(Integer errCode) { + this.errCode = errCode; } - public String getErrmsg() { - return errmsg; + public String getErrMsg() { + return errMsg; } - public void setErrmsg(String errmsg) { - this.errmsg = errmsg; + public void setErrMsg(String errMsg) { + this.errMsg = errMsg; } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBind.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBind.java index 1236048ce1..467f3c42d9 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBind.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceBind.java @@ -9,7 +9,8 @@ public class WxDeviceBind extends AbstractDeviceBean{ private String ticket; @SerializedName("device_id") private String deviceId; - private String openid; + @SerializedName("openid") + private String openId; public String getTicket() { return ticket; @@ -27,11 +28,11 @@ public void setDeviceId(String deviceId) { this.deviceId = deviceId; } - public String getOpenid() { - return openid; + public String getOpenId() { + return openId; } - public void setOpenid(String openid) { - this.openid = openid; + public void setOpenId(String openId) { + this.openId = openId; } } From 12329d0a8ccb1dd35f2f3d3e0acb68b838bb2fdd Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 16 Dec 2016 17:27:19 +0800 Subject: [PATCH 22/80] Update .travis.yml --- .travis.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 65cf5e12a0..5fcb077e40 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,14 @@ language: java +sudo: false +install: true +addons: + sonarqube: + token: + secure: "834110c7191f97ecb226970c46dcaff8e681da5a" + jdk: - oraclejdk7 - -script: "mvn clean package -Dmaven.test.skip=true" +#script: "mvn clean package -Dmaven.test.skip=true" branches: only: @@ -11,3 +17,10 @@ branches: notifications: email: - binaryw@qq.com + +script: + - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar +cache: + directories: + - '$HOME/.m2/repository' + - '$HOME/.sonar/cache' From e4b37f97627ca849352578cfeebe14a7f14af3f9 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 16 Dec 2016 17:32:30 +0800 Subject: [PATCH 23/80] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5fcb077e40..ae9f5e6411 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ addons: secure: "834110c7191f97ecb226970c46dcaff8e681da5a" jdk: - - oraclejdk7 + - oraclejdk8 #script: "mvn clean package -Dmaven.test.skip=true" branches: From 4758440792525a0ee4757b5236fe26420f635c35 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 16 Dec 2016 17:40:04 +0800 Subject: [PATCH 24/80] Update .travis.yml --- .travis.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index ae9f5e6411..904ee9a47c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,18 +9,19 @@ addons: jdk: - oraclejdk8 #script: "mvn clean package -Dmaven.test.skip=true" - -branches: - only: - - develop - -notifications: - email: - - binaryw@qq.com script: - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar + +branches: + only: + - develop + cache: directories: - '$HOME/.m2/repository' - '$HOME/.sonar/cache' + +notifications: + email: + - binaryw@qq.com From 02679bb665c768938d856ea1db62b9becd8521fd Mon Sep 17 00:00:00 2001 From: aimilin6688 Date: Fri, 16 Dec 2016 19:40:32 +0800 Subject: [PATCH 25/80] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=EF=BC=8C=E4=B8=8D=E5=9C=A8=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E9=85=8D=E7=BD=AE=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mp/api/impl/WxMpPayServiceImpl.java | 210 ++++++++---------- .../mp/bean/pay/request/WxEntPayRequest.java | 55 +---- .../bean/pay/request/WxPayRefundRequest.java | 84 +------ .../pay/request/WxPaySendRedpackRequest.java | 55 +---- 4 files changed, 112 insertions(+), 292 deletions(-) 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 4675946c1d..9bd4dad250 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 @@ -44,8 +44,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { private static final String PAY_BASE_URL = "https://api.mch.weixin.qq.com"; private static final String[] TRADE_TYPES = new String[]{"JSAPI", "NATIVE", "APP"}; - private static final String[] REFUND_ACCOUNT = new String[]{"REFUND_SOURCE_RECHARGE_FUNDS", - "REFUND_SOURCE_UNSETTLED_FUNDS"}; + private static final String[] REFUND_ACCOUNT = new String[]{"REFUND_SOURCE_RECHARGE_FUNDS","REFUND_SOURCE_UNSETTLED_FUNDS"}; private final Logger log = LoggerFactory.getLogger(this.getClass()); private WxMpService wxMpService; @@ -58,23 +57,20 @@ private WxMpConfigStorage getConfig() { } @Override - public WxPayRefundResult refund(WxPayRefundRequest request, File keyFile) - throws WxErrorException { - checkParameters(request); - + public WxPayRefundResult refund(WxPayRefundRequest request, File keyFile) throws WxErrorException { XStream xstream = XStreamInitializer.getInstance(); xstream.processAnnotations(WxPayRefundRequest.class); xstream.processAnnotations(WxPayRefundResult.class); - - request.setAppid(getConfig().getAppId()); - String partnerId = getConfig().getPartnerId(); - request.setMchId(partnerId); - request.setNonceStr(System.currentTimeMillis() + ""); - request.setOpUserId(partnerId); + + initRequest(request); + if(StringUtils.isBlank(request.getOpUserId())){ + request.setOpUserId(getConfig().getPartnerId()); + } + checkParameters(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/secapi/pay/refund"; - String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), partnerId); + String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), request.getMchId()); WxPayRefundResult result = (WxPayRefundResult) xstream.fromXML(responseContent); this.checkResult(result); return result; @@ -92,18 +88,14 @@ public WxPayRefundQueryResult refundQuery(String transactionId, String outTradeN xstream.processAnnotations(WxPayRefundQueryResult.class); WxPayRefundQueryRequest request = new WxPayRefundQueryRequest(); + initRequest(request); request.setOutTradeNo(StringUtils.trimToNull(outTradeNo)); request.setTransactionId(StringUtils.trimToNull(transactionId)); request.setOutRefundNo(StringUtils.trimToNull(outRefundNo)); request.setRefundId(StringUtils.trimToNull(refundId)); - - request.setAppid(getConfig().getAppId()); - request.setMchId(getConfig().getPartnerId()); - request.setNonceStr(System.currentTimeMillis() + ""); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/pay/refundquery"; - String responseContent = this.executeRequest(url, xstream.toXML(request)); WxPayRefundQueryResult result = (WxPayRefundQueryResult) xstream.fromXML(responseContent); result.composeRefundRecords(responseContent); @@ -127,7 +119,7 @@ private void checkResult(WxPayBaseResult result) throws WxErrorException { + result.getReturnMsg() + ", 结果代码: " + result.getResultCode() + ", 错误代码: " + result.getErrCode() + ", 错误详情: " + result.getErrCodeDes()) .build(); - log.debug("结果校验失败,参数:{},详细:{}", result.toMap(), error); + log.error("结果业务代码异常,参数:{},详细:{}", result.toMap(), error); throw new WxErrorException(error); } } @@ -174,10 +166,7 @@ public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File xstream.processAnnotations(WxPaySendRedpackRequest.class); xstream.processAnnotations(WxPaySendRedpackResult.class); - request.setWxAppid(getConfig().getAppId()); - String mchId = getConfig().getPartnerId(); - request.setMchId(mchId); - request.setNonceStr(System.currentTimeMillis() + ""); + initRequest(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/sendredpack"; @@ -185,8 +174,7 @@ public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File //裂变红包 url = PAY_BASE_URL + "/mmpaymkttransfers/sendgroupredpack"; } - - String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), mchId); + String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), request.getMchId()); WxPaySendRedpackResult result = (WxPaySendRedpackResult) xstream.fromXML(responseContent); this.checkResult(result); return result; @@ -201,75 +189,16 @@ public WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) thro WxPayRedpackQueryRequest request = new WxPayRedpackQueryRequest(); request.setMchBillNo(mchBillNo); request.setBillType("MCHT"); - - request.setAppid(getConfig().getAppId()); - String mchId = getConfig().getPartnerId(); - request.setMchId(mchId); - request.setNonceStr(System.currentTimeMillis() + ""); - - String sign = this.createSign(request); - request.setSign(sign); + initRequest(request); + request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/gethbinfo"; - String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), mchId); + String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), request.getMchId()); WxPayRedpackQueryResult result = (WxPayRedpackQueryResult) xstream.fromXML(responseContent); this.checkResult(result); return result; } - @Override - public String createSign(Object xmlBean) { - return createSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey()); - } - - @Override - public String createSign(Object xmlBean, String signKey) { - return createSign(BeanUtils.xmlBean2Map(xmlBean), signKey); - } - - @Override - public String createSign(Map params) { - return createSign(params, getConfig().getPartnerKey()); - } - - @Override - public String createSign(Map params, String signKey) { - SortedMap sortedMap = new TreeMap<>(params); - - StringBuilder toSign = new StringBuilder(); - for (String key : sortedMap.keySet()) { - String value = params.get(key); - if (StringUtils.isNotEmpty(value) && !"sign".equals(key) && !"key".equals(key)) { - toSign.append(key + "=" + value + "&"); - } - } - - toSign.append("key=" + signKey); - return DigestUtils.md5Hex(toSign.toString()).toUpperCase(); - } - - @Override - public boolean checkSign(Object xmlBean) { - return checkSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey()); - } - - @Override - public boolean checkSign(Object xmlBean, String signKey) { - return checkSign(BeanUtils.xmlBean2Map(xmlBean), signKey); - } - - @Override - public boolean checkSign(Map params) { - return checkSign(params, getConfig().getPartnerKey()); - } - - @Override - public boolean checkSign(Map params, String signKey) { - String sign = this.createSign(params, signKey); - return sign.equals(params.get("sign")); - } - - @Override public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxErrorException { if ((StringUtils.isBlank(transactionId) && StringUtils.isBlank(outTradeNo)) || @@ -284,13 +213,10 @@ public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) WxPayOrderQueryRequest request = new WxPayOrderQueryRequest(); request.setOutTradeNo(StringUtils.trimToNull(outTradeNo)); request.setTransactionId(StringUtils.trimToNull(transactionId)); - request.setAppid(getConfig().getAppId()); - request.setMchId(getConfig().getPartnerId()); - request.setNonceStr(System.currentTimeMillis() + ""); + initRequest(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/pay/orderquery"; - String responseContent = this.executeRequest(url, xstream.toXML(request)); WxPayOrderQueryResult result = (WxPayOrderQueryResult) xstream.fromXML(responseContent); result.composeCoupons(responseContent); @@ -310,13 +236,10 @@ public WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxErrorExcepti WxPayOrderCloseRequest request = new WxPayOrderCloseRequest(); request.setOutTradeNo(StringUtils.trimToNull(outTradeNo)); - request.setAppid(getConfig().getAppId()); - request.setMchId(getConfig().getPartnerId()); - request.setNonceStr(System.currentTimeMillis() + ""); + initRequest(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/pay/closeorder"; - String responseContent = this.executeRequest(url, xstream.toXML(request)); WxPayOrderCloseResult result = (WxPayOrderCloseResult) xstream.fromXML(responseContent); this.checkResult(result); @@ -331,16 +254,17 @@ public WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) XStream xstream = XStreamInitializer.getInstance(); xstream.processAnnotations(WxPayUnifiedOrderRequest.class); xstream.processAnnotations(WxPayUnifiedOrderResult.class); - - request.setAppid(getConfig().getAppId()); - request.setMchId(getConfig().getPartnerId()); - request.setNotifyURL(getConfig().getNotifyURL()); - request.setTradeType(getConfig().getTradeType()); - request.setNonceStr(System.currentTimeMillis() + ""); - + + initRequest(request); + if(StringUtils.isBlank(request.getNotifyURL())){ + request.setNotifyURL(getConfig().getNotifyURL()); + } + if(StringUtils.isBlank(request.getTradeType())){ + request.setTradeType(getConfig().getTradeType()); + } checkParameters(request);//校验参数 - request.setSign(this.createSign(request)); + String url = PAY_BASE_URL + "/pay/unifiedorder"; String xmlParam = xstream.toXML(request); log.debug("微信统一下单接口,URL:{},参数:{}", url, xmlParam); @@ -351,6 +275,18 @@ public WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) this.checkResult(result); return result; } + + private void initRequest(WxPayBaseRequest request){ + if(StringUtils.isBlank(request.getAppid())){ + request.setAppid(getConfig().getAppId()); + } + if(StringUtils.isBlank(request.getMchId())){ + request.setMchId(getConfig().getPartnerId()); + } + if(StringUtils.isBlank(request.getNonceStr())){ + request.setNonceStr(String.valueOf(System.currentTimeMillis())); + } + } private void checkParameters(WxPayUnifiedOrderRequest request) throws WxErrorException { BeanUtils.checkRequiredFields(request); @@ -381,7 +317,7 @@ public Map getPayInfo(WxPayUnifiedOrderRequest request) throws W payInfo.put("appId", getConfig().getAppId()); // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符 payInfo.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000)); - payInfo.put("nonceStr", System.currentTimeMillis() + ""); + payInfo.put("nonceStr", String.valueOf(System.currentTimeMillis())); payInfo.put("package", "prepay_id=" + prepayId); payInfo.put("signType", "MD5"); if ("NATIVE".equals(request.getTradeType())) { @@ -393,15 +329,12 @@ public Map getPayInfo(WxPayUnifiedOrderRequest request) throws W @Override public WxEntPayResult entPay(WxEntPayRequest request, File keyFile) throws WxErrorException { - BeanUtils.checkRequiredFields(request); - XStream xstream = XStreamInitializer.getInstance(); xstream.processAnnotations(WxEntPayRequest.class); xstream.processAnnotations(WxEntPayResult.class); - - request.setMchAppid(getConfig().getAppId()); - request.setMchId(getConfig().getPartnerId()); - request.setNonceStr(System.currentTimeMillis() + ""); + + initRequest(request); + BeanUtils.checkRequiredFields(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/promotion/transfers"; @@ -419,13 +352,10 @@ public WxEntPayQueryResult queryEntPay(String partnerTradeNo, File keyFile) thro xstream.processAnnotations(WxEntPayQueryResult.class); WxEntPayQueryRequest request = new WxEntPayQueryRequest(); - request.setAppid(getConfig().getAppId()); - request.setMchId(getConfig().getPartnerId()); - request.setNonceStr(System.currentTimeMillis() + ""); + initRequest(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/gettransferinfo"; - String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), request.getMchId()); WxEntPayQueryResult result = (WxEntPayQueryResult) xstream.fromXML(responseContent); this.checkResult(result); @@ -483,4 +413,56 @@ private String executeRequestWithKeyFile(String url, File keyFile, String reques throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg(e.getMessage()).build(), e); } } + + @Override + public String createSign(Object xmlBean) { + return createSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey()); + } + + @Override + public String createSign(Object xmlBean, String signKey) { + return createSign(BeanUtils.xmlBean2Map(xmlBean), signKey); + } + + @Override + public String createSign(Map params) { + return createSign(params, getConfig().getPartnerKey()); + } + + @Override + public String createSign(Map params, String signKey) { + SortedMap sortedMap = new TreeMap<>(params); + + StringBuilder toSign = new StringBuilder(); + for (String key : sortedMap.keySet()) { + String value = params.get(key); + if (StringUtils.isNotEmpty(value) && !"sign".equals(key) && !"key".equals(key)) { + toSign.append(key + "=" + value + "&"); + } + } + + toSign.append("key=" + signKey); + return DigestUtils.md5Hex(toSign.toString()).toUpperCase(); + } + + @Override + public boolean checkSign(Object xmlBean) { + return checkSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey()); + } + + @Override + public boolean checkSign(Object xmlBean, String signKey) { + return checkSign(BeanUtils.xmlBean2Map(xmlBean), signKey); + } + + @Override + public boolean checkSign(Map params) { + return checkSign(params, getConfig().getPartnerKey()); + } + + @Override + public boolean checkSign(Map params, String signKey) { + String sign = this.createSign(params, signKey); + return sign.equals(params.get("sign")); + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxEntPayRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxEntPayRequest.java index ef6e8d0a54..bc6ae57468 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxEntPayRequest.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxEntPayRequest.java @@ -18,7 +18,7 @@ * @author binarywang (https://github.com/binarywang) */ @XStreamAlias("xml") -public class WxEntPayRequest { +public class WxEntPayRequest extends WxPayBaseRequest{ /** *
   * 公众账号appid
@@ -58,32 +58,6 @@ public class WxEntPayRequest {
   @XStreamAlias("device_info")
   private String deviceInfo;
 
-  /**
-   * 
-  * 随机字符串
-  * nonce_str
-  *是
-  *5K8264ILTKCH16CQ2502SI8ZNMTM67VS
-  *String(32)
-  *随机字符串,不长于32位
-   * 
- */ - @XStreamAlias("nonce_str") - private String nonceStr; - - /** - *
-  * 签名
-  * sign
-  * 是
-  * C380BEC2BFD727A4B6845133519F3AD6
-  * String(32)
-  *签名,详见签名算法
-   * 
- */ - @XStreamAlias("sign") - private String sign; - /** *
   * 商户订单号
@@ -178,18 +152,23 @@ public class WxEntPayRequest {
   @XStreamAlias("spbill_create_ip")
   private String spbillCreateIp;
 
-  public String getMchAppid() {
+
+  @Override
+  public String getAppid() {
     return this.mchAppid;
   }
 
-  public void setMchAppid(String mchAppid) {
-    this.mchAppid = mchAppid;
+  @Override
+  public void setAppid(String appid) {
+    this.mchAppid = appid;
   }
 
+  @Override
   public String getMchId() {
     return this.mchId;
   }
 
+  @Override
   public void setMchId(String mchId) {
     this.mchId = mchId;
   }
@@ -202,22 +181,6 @@ 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 getPartnerTradeNo() {
     return this.partnerTradeNo;
   }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayRefundRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayRefundRequest.java
index 9a0c0178ef..66ba5d347e 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayRefundRequest.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayRefundRequest.java
@@ -20,33 +20,7 @@
  *         Created by Binary Wang on 2016-10-08.
  */
 @XStreamAlias("xml")
-public class WxPayRefundRequest {
-  /**
-   * 
-   * 公众账号ID
-   * appid
-   * 是
-   * String(32)
-   * wx8888888888888888
-   * 微信分配的公众账号ID(企业号corpid即为此appId)
-   * 
- */ - @XStreamAlias("appid") - private String appid; - - /** - *
-   * 商户号
-   * mch_id
-   * 是
-   * String(32)
-   * 1900000109
-   * 微信支付分配的商户号
-   * 
- */ - @XStreamAlias("mch_id") - private String mchId; - +public class WxPayRefundRequest extends WxPayBaseRequest { /** *
    * 设备号
@@ -60,32 +34,6 @@ public class WxPayRefundRequest {
   @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; - /** *
    * 微信订单号
@@ -196,21 +144,7 @@ public class WxPayRefundRequest {
   @XStreamAlias("refund_account")
   private String refundAccount;
 
-  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;
@@ -220,22 +154,6 @@ 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 getTransactionId() {
     return this.transactionId;
   }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPaySendRedpackRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPaySendRedpackRequest.java
index 535b2941c5..95cdac2295 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPaySendRedpackRequest.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPaySendRedpackRequest.java
@@ -8,7 +8,7 @@
  * @author binarywang (https://github.com/binarywang)
  */
 @XStreamAlias("xml")
-public class WxPaySendRedpackRequest {
+public class WxPaySendRedpackRequest extends WxPayBaseRequest{
   /**
   * mch_billno
   * 商户订单号(每个订单号必须唯一)  组成:mch_id+yyyymmdd+10位一天内不能重复的数字。  接口根据商户订单号支持重入,如出现超时可再调用。
@@ -90,27 +90,6 @@ public class WxPaySendRedpackRequest {
   @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
@@ -237,36 +216,14 @@ public void setRemark(String remark) {
     this.remark = remark;
   }
 
-  public String getWxAppid() {
+  @Override
+  public String getAppid() {
     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;
+  @Override
+  public void setAppid(String appid) {
+    this.wxAppid = appid;
   }
 
   public String getSceneId() {

From da5fe8bd9c014fa78c2b15af49662588bd9e40a9 Mon Sep 17 00:00:00 2001
From: Binary Wang 
Date: Mon, 19 Dec 2016 10:17:50 +0800
Subject: [PATCH 26/80] ignore sonar files

---
 .gitignore | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/.gitignore b/.gitignore
index fbf348aef9..4ee3979b32 100644
--- a/.gitignore
+++ b/.gitignore
@@ -48,3 +48,5 @@ Icon
 Network Trash Folder
 Temporary Items
 .apdisk
+/.sonar/
+sonar-project.properties

From d18921b36d3002204449d321c9a8e542e7373e84 Mon Sep 17 00:00:00 2001
From: Binary Wang 
Date: Mon, 19 Dec 2016 10:24:01 +0800
Subject: [PATCH 27/80] release 2.4.4-beta

---
 pom.xml                                                        | 2 +-
 weixin-java-common/pom.xml                                     | 2 +-
 weixin-java-cp/pom.xml                                         | 2 +-
 weixin-java-mp/pom.xml                                         | 2 +-
 .../java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java    | 3 +--
 weixin-java-osgi/pom.xml                                       | 2 +-
 6 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/pom.xml b/pom.xml
index ef459ec1b4..1e6f77db41 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
   4.0.0
   com.github.binarywang
   weixin-java-parent
-  2.5.0-SNAPSHOT
+  2.4.4-beta
   pom
   WeiXin Java Tools - Parent
   微信公众号、企业号上级POM
diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml
index 11d31bdd27..25265a9152 100644
--- a/weixin-java-common/pom.xml
+++ b/weixin-java-common/pom.xml
@@ -6,7 +6,7 @@
   
     com.github.binarywang
     weixin-java-parent
-    2.5.0-SNAPSHOT
+    2.4.4-beta
   
 
   weixin-java-common
diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml
index 2398a12cf5..2e8a5515ac 100644
--- a/weixin-java-cp/pom.xml
+++ b/weixin-java-cp/pom.xml
@@ -6,7 +6,7 @@
     
         com.github.binarywang
         weixin-java-parent
-        2.5.0-SNAPSHOT
+        2.4.4-beta
     
 
     weixin-java-cp
diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml
index 7f3a8b39f6..5c817853a3 100644
--- a/weixin-java-mp/pom.xml
+++ b/weixin-java-mp/pom.xml
@@ -6,7 +6,7 @@
     
         com.github.binarywang
         weixin-java-parent
-        2.5.0-SNAPSHOT
+        2.4.4-beta
     
     weixin-java-mp
     WeiXin Java Tools - MP
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 62b363a22d..ccb0bd2ec4 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
@@ -422,8 +422,7 @@ protected synchronized  T executeInternal(RequestExecutor executor,
       }
 
       if (error.getErrorCode() != 0) {
-        this.log.error("\n[URL]:  {}\n[PARAMS]: {}\n[RESPONSE]: {}", uri, data,
-            error);
+        this.log.error("\n[URL]:  {}\n[PARAMS]: {}\n[RESPONSE]: {}", uri, data, error);
         throw new WxErrorException(error);
       }
       return null;
diff --git a/weixin-java-osgi/pom.xml b/weixin-java-osgi/pom.xml
index ec9d1b7d09..0c7c1f6d90 100644
--- a/weixin-java-osgi/pom.xml
+++ b/weixin-java-osgi/pom.xml
@@ -6,7 +6,7 @@
   
     com.github.binarywang
     weixin-java-parent
-    2.5.0-SNAPSHOT
+    2.4.4-beta
   
 
   weixin-java-osgi

From 515ef7cd3a8e965c89201b21127c4186c0c313ee Mon Sep 17 00:00:00 2001
From: Binary Wang 
Date: Mon, 19 Dec 2016 14:11:16 +0800
Subject: [PATCH 28/80] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B4=A1=E7=8C=AE?=
 =?UTF-8?q?=E8=80=85=E4=BF=A1=E6=81=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 pom.xml | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/pom.xml b/pom.xml
index 1e6f77db41..5d10472bff 100644
--- a/pom.xml
+++ b/pom.xml
@@ -69,6 +69,11 @@
       dongfuqiang1988@163.com
       https://github.com/johnnytung
     
+    
+      Jonk
+      aimilin@yeah.net
+      https://github.com/aimilin6688
+    
   
 
   

From f221ea3487b451c2619b92e985045c62549ae1ca Mon Sep 17 00:00:00 2001
From: Binary Wang 
Date: Tue, 20 Dec 2016 16:48:07 +0800
Subject: [PATCH 29/80] =?UTF-8?q?=E5=85=AC=E4=BC=97=E5=B9=B3=E5=8F=B0?=
 =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BE=A4=E5=8F=91=E6=8E=A5=E5=8F=A3=E5=AF=B9?=
 =?UTF-8?q?=E5=8E=9F=E5=88=9B=E6=A0=A1=E9=AA=8C=E9=80=BB=E8=BE=91=E7=9A=84?=
 =?UTF-8?q?=E6=94=AF=E6=8C=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../mp/bean/WxMpMassOpenIdsMessage.java       | 22 ++++++++---
 .../weixin/mp/bean/WxMpMassTagMessage.java    | 39 +++++++++++++------
 .../mp/bean/result/WxMpMassSendResult.java    | 13 +++----
 .../WxMpMassOpenIdsMessageGsonAdapter.java    |  5 ++-
 .../util/json/WxMpMassSendResultAdapter.java  |  4 +-
 .../json/WxMpMassTagMessageGsonAdapter.java   | 24 ++++++------
 6 files changed, 65 insertions(+), 42 deletions(-)

diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassOpenIdsMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassOpenIdsMessage.java
index 982cb78f5b..e0b33f0dd7 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassOpenIdsMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassOpenIdsMessage.java
@@ -1,28 +1,29 @@
 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;
 
-import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
-
 /**
  * openid列表群发的消息
- * 
+ *
  * @author chanjarster
  */
 public class WxMpMassOpenIdsMessage implements Serializable {
   private static final long serialVersionUID = -8022910911104788999L;
-  
+
   private List toUsers = new ArrayList<>();
   private String msgType;
   private String content;
   private String mediaId;
+  private boolean sendIgnoreReprint = false;
 
   public WxMpMassOpenIdsMessage() {
     super();
   }
-  
+
   public String getMsgType() {
     return this.msgType;
   }
@@ -86,4 +87,15 @@ public void setToUsers(List toUsers) {
     this.toUsers = toUsers;
   }
 
+  public boolean isSendIgnoreReprint() {
+    return sendIgnoreReprint;
+  }
+
+  /**
+   *
+   * @param sendIgnoreReprint 文章被判定为转载时,是否继续进行群发操作。
+   */
+  public void setSendIgnoreReprint(boolean sendIgnoreReprint) {
+    this.sendIgnoreReprint = sendIgnoreReprint;
+  }
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java
index 300b4f9067..083e5605a6 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java
@@ -1,28 +1,29 @@
 package me.chanjar.weixin.mp.bean;
 
-import java.io.Serializable;
-
 import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
 
+import java.io.Serializable;
+
 /**
  * 按标签群发的消息
- * 
+ *
  * @author chanjarster
  */
 public class WxMpMassTagMessage implements Serializable {
-  
+
   private static final long serialVersionUID = -6625914040986749286L;
   private Long tagId;
-  private String msgtype;
+  private String msgType;
   private String content;
   private String mediaId;
+  private boolean sendIgnoreReprint = false;
 
   public WxMpMassTagMessage() {
     super();
   }
-  
-  public String getMsgtype() {
-    return this.msgtype;
+
+  public String getMsgType() {
+    return this.msgType;
   }
 
   /**
@@ -35,10 +36,11 @@ public String getMsgtype() {
    * {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_VOICE}
    * 如果msgtype和media_id不匹配的话,会返回系统繁忙的错误
    * 
- * @param msgtype + * + * @param msgType 消息类型 */ - public void setMsgtype(String msgtype) { - this.msgtype = msgtype; + public void setMsgType(String msgType) { + this.msgType = msgType; } public String getContent() { @@ -67,10 +69,23 @@ public Long getTagId() { /** * 如果不设置则就意味着发给所有用户 - * @param tagId + * + * @param tagId 标签id */ public void setTagId(Long tagId) { this.tagId = tagId; } + public boolean isSendIgnoreReprint() { + return sendIgnoreReprint; + } + + /** + * + * @param sendIgnoreReprint 文章被判定为转载时,是否继续进行群发操作。 + */ + public void setSendIgnoreReprint(boolean sendIgnoreReprint) { + this.sendIgnoreReprint = sendIgnoreReprint; + } + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassSendResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassSendResult.java index 0e9a158d7d..ffb8f0267a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassSendResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassSendResult.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.bean.result; +import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import java.io.Serializable; @@ -7,19 +8,15 @@ /** *
  * 群发消息一发送就返回的结果
- * 
+ *
  * 真正的群发消息是否发送成功要看
  * http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口#.E4.BA.8B.E4.BB.B6.E6.8E.A8.E9.80.81.E7.BE.A4.E5.8F.91.E7.BB.93.E6.9E.9C
- * 
+ *
  * 
* @author chanjarster * */ public class WxMpMassSendResult implements Serializable { - - /** - * - */ private static final long serialVersionUID = -4816336807575562818L; private String errorCode; private String errorMsg; @@ -64,7 +61,7 @@ public static WxMpMassSendResult fromJson(String json) { @Override public String toString() { - return "WxMassSendResult [errcode=" + this.errorCode + ", errmsg=" + this.errorMsg + ", msg_id=" + this.msgId + "]"; + return ToStringUtils.toSimpleString(this); } - + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassOpenIdsMessageGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassOpenIdsMessageGsonAdapter.java index cfb1f37429..64dfbb1234 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassOpenIdsMessageGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassOpenIdsMessageGsonAdapter.java @@ -19,13 +19,13 @@ public class WxMpMassOpenIdsMessageGsonAdapter implements JsonSerializer { @@ -40,5 +38,5 @@ public WxMpMassSendResult deserialize(JsonElement json, Type typeOfT, JsonDeseri } return sendResult; } - + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassTagMessageGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassTagMessageGsonAdapter.java index 6514ed5924..38e9515f2e 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassTagMessageGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassTagMessageGsonAdapter.java @@ -8,57 +8,57 @@ */ package me.chanjar.weixin.mp.util.json; -import java.lang.reflect.Type; - import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; - import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; +import java.lang.reflect.Type; + public class WxMpMassTagMessageGsonAdapter implements JsonSerializer { @Override public JsonElement serialize(WxMpMassTagMessage message, Type typeOfSrc, JsonSerializationContext context) { JsonObject messageJson = new JsonObject(); - + JsonObject filter = new JsonObject(); - if(null == message.getTagId()) { + if (null == message.getTagId()) { filter.addProperty("is_to_all", true); } else { filter.addProperty("is_to_all", false); filter.addProperty("tag_id", message.getTagId()); } messageJson.add("filter", filter); - - if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgtype())) { + + if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", message.getMediaId()); messageJson.add(WxConsts.MASS_MSG_NEWS, sub); } - if (WxConsts.MASS_MSG_TEXT.equals(message.getMsgtype())) { + if (WxConsts.MASS_MSG_TEXT.equals(message.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("content", message.getContent()); messageJson.add(WxConsts.MASS_MSG_TEXT, sub); } - if (WxConsts.MASS_MSG_VOICE.equals(message.getMsgtype())) { + if (WxConsts.MASS_MSG_VOICE.equals(message.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", message.getMediaId()); messageJson.add(WxConsts.MASS_MSG_VOICE, sub); } - if (WxConsts.MASS_MSG_IMAGE.equals(message.getMsgtype())) { + if (WxConsts.MASS_MSG_IMAGE.equals(message.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", message.getMediaId()); messageJson.add(WxConsts.MASS_MSG_IMAGE, sub); } - if (WxConsts.MASS_MSG_VIDEO.equals(message.getMsgtype())) { + if (WxConsts.MASS_MSG_VIDEO.equals(message.getMsgType())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", message.getMediaId()); messageJson.add(WxConsts.MASS_MSG_VIDEO, sub); } - messageJson.addProperty("msgtype", message.getMsgtype()); + messageJson.addProperty("msgtype", message.getMsgType()); + messageJson.addProperty("send_ignore_reprint", message.isSendIgnoreReprint() ? 0 : 1); return messageJson; } From dc33436d5128c4a116da0d424abb0dc227e72c46 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 20 Dec 2016 16:48:26 +0800 Subject: [PATCH 30/80] reformat some code --- .../mp/util/json/WxMpCardGsonAdapter.java | 13 +++------ .../util/json/WxMpCardResultGsonAdapter.java | 15 ++++------ .../weixin/mp/util/json/WxMpGsonBuilder.java | 29 +++---------------- .../mp/util/json/WxMpIndustryGsonAdapter.java | 26 ++++++++--------- .../util/json/WxMpKefuMessageGsonAdapter.java | 2 +- .../json/WxMpMassUploadResultAdapter.java | 4 +-- .../mp/util/json/WxMpMassVideoAdapter.java | 2 -- .../WxMpMaterialNewsArticleGsonAdapter.java | 4 +-- .../json/WxMpOAuth2AccessTokenAdapter.java | 13 +++------ .../json/WxMpSemanticQueryResultAdapter.java | 4 +-- .../json/WxMpTemplateMessageGsonAdapter.java | 1 - .../json/WxMpUserCumulateGsonAdapter.java | 22 +++++--------- .../mp/util/json/WxMpUserGsonAdapter.java | 13 +++------ .../util/json/WxMpUserSummaryGsonAdapter.java | 20 +++++-------- .../mp/util/json/WxQrCodeTicketAdapter.java | 4 +-- 15 files changed, 54 insertions(+), 118 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpCardGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpCardGsonAdapter.java index 3314857782..022a59f111 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpCardGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpCardGsonAdapter.java @@ -1,16 +1,11 @@ package me.chanjar.weixin.mp.util.json; -import java.lang.reflect.Type; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; - +import com.google.gson.*; import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.mp.bean.WxMpCard; +import java.lang.reflect.Type; + /** * Created by YuJian on 15/11/11. * @@ -21,7 +16,7 @@ public class WxMpCardGsonAdapter implements JsonDeserializer { @Override public WxMpCard deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext - jsonDeserializationContext) throws JsonParseException { + jsonDeserializationContext) throws JsonParseException { WxMpCard card = new WxMpCard(); JsonObject jsonObject = jsonElement.getAsJsonObject(); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpCardResultGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpCardResultGsonAdapter.java index f595cf7c8d..9d7866494b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpCardResultGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpCardResultGsonAdapter.java @@ -1,18 +1,13 @@ package me.chanjar.weixin.mp.util.json; -import java.lang.reflect.Type; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; +import com.google.gson.*; import com.google.gson.reflect.TypeToken; - import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.mp.bean.WxMpCard; import me.chanjar.weixin.mp.bean.result.WxMpCardResult; +import java.lang.reflect.Type; + /** * Created by YuJian on 15/11/11. * @@ -32,8 +27,8 @@ public WxMpCardResult deserialize(JsonElement jsonElement, Type type, JsonDeseri cardResult.setUserCardStatus(GsonHelper.getString(jsonObject, "user_card_status")); WxMpCard card = WxMpGsonBuilder.INSTANCE.create().fromJson(jsonObject.get("card"), - new TypeToken() { - }.getType()); + new TypeToken() { + }.getType()); cardResult.setCard(card); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java index 37a3970635..286778ad4b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java @@ -2,33 +2,12 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; - -import me.chanjar.weixin.mp.bean.WxMpCard; -import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; -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.material.WxMpMaterialArticleUpdate; -import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; +import me.chanjar.weixin.mp.bean.*; import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate; import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary; -import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult; -import me.chanjar.weixin.mp.bean.result.WxMpCardResult; -import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; -import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; -import me.chanjar.weixin.mp.bean.material.WxMpMaterialCountResult; -import me.chanjar.weixin.mp.bean.material.WxMpMaterialFileBatchGetResult; -import me.chanjar.weixin.mp.bean.material.WxMpMaterialNewsBatchGetResult; -import me.chanjar.weixin.mp.bean.material.WxMpMaterialUploadResult; -import me.chanjar.weixin.mp.bean.material.WxMpMaterialVideoInfoResult; -import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; -import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; -import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; -import me.chanjar.weixin.mp.bean.result.WxMpUser; -import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; -import me.chanjar.weixin.mp.bean.result.WxMpUserList; +import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; +import me.chanjar.weixin.mp.bean.material.*; +import me.chanjar.weixin.mp.bean.result.*; import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry; import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpIndustryGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpIndustryGsonAdapter.java index 68106bb656..eb0972bcdc 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpIndustryGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpIndustryGsonAdapter.java @@ -10,10 +10,17 @@ * @author miller */ public class WxMpIndustryGsonAdapter - implements JsonSerializer, JsonDeserializer { + implements JsonSerializer, JsonDeserializer { + private static WxMpTemplateIndustry.Industry convertFromJson(JsonObject json) { + WxMpTemplateIndustry.Industry industry = new WxMpTemplateIndustry.Industry(); + industry.setFirstClass(GsonHelper.getString(json, "first_class")); + industry.setSecondClass(GsonHelper.getString(json, "second_class")); + return industry; + } + @Override public JsonElement serialize(WxMpTemplateIndustry wxMpIndustry, Type type, - JsonSerializationContext jsonSerializationContext) { + JsonSerializationContext jsonSerializationContext) { JsonObject json = new JsonObject(); json.addProperty("industry_id1", wxMpIndustry.getPrimaryIndustry().getId()); json.addProperty("industry_id2", wxMpIndustry.getSecondIndustry().getId()); @@ -22,22 +29,15 @@ public JsonElement serialize(WxMpTemplateIndustry wxMpIndustry, Type type, @Override public WxMpTemplateIndustry deserialize(JsonElement jsonElement, Type type, - JsonDeserializationContext jsonDeserializationContext) - throws JsonParseException { + JsonDeserializationContext jsonDeserializationContext) + throws JsonParseException { WxMpTemplateIndustry wxMpIndustry = new WxMpTemplateIndustry(); JsonObject primaryIndustry = jsonElement.getAsJsonObject() - .get("primary_industry").getAsJsonObject(); + .get("primary_industry").getAsJsonObject(); wxMpIndustry.setPrimaryIndustry(convertFromJson(primaryIndustry)); JsonObject secondaryIndustry = jsonElement.getAsJsonObject() - .get("secondary_industry").getAsJsonObject(); + .get("secondary_industry").getAsJsonObject(); wxMpIndustry.setSecondIndustry(convertFromJson(secondaryIndustry)); return wxMpIndustry; } - - private static WxMpTemplateIndustry.Industry convertFromJson(JsonObject json) { - WxMpTemplateIndustry.Industry industry = new WxMpTemplateIndustry.Industry(); - industry.setFirstClass(GsonHelper.getString(json, "first_class")); - industry.setSecondClass(GsonHelper.getString(json, "second_class")); - return industry; - } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpKefuMessageGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpKefuMessageGsonAdapter.java index abab87a11e..56297ce2bd 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpKefuMessageGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpKefuMessageGsonAdapter.java @@ -87,7 +87,7 @@ public JsonElement serialize(WxMpKefuMessage message, Type typeOfSrc, JsonSerial messageJson.add("wxcard", wxcard); } - if (StringUtils.isNotBlank(message.getKfAccount())){ + if (StringUtils.isNotBlank(message.getKfAccount())) { JsonObject newsJsonObject = new JsonObject(); newsJsonObject.addProperty("kf_account", message.getKfAccount()); messageJson.add("customservice", newsJsonObject); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassUploadResultAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassUploadResultAdapter.java index 75564b6317..e20175d767 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassUploadResultAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassUploadResultAdapter.java @@ -15,9 +15,7 @@ import java.lang.reflect.Type; /** - * * @author Daniel Qian - * */ public class WxMpMassUploadResultAdapter implements JsonDeserializer { @@ -37,5 +35,5 @@ public WxMpMassUploadResult deserialize(JsonElement json, Type typeOfT, JsonDese } return uploadResult; } - + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassVideoAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassVideoAdapter.java index 264a57b313..e7bd8c3997 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassVideoAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassVideoAdapter.java @@ -17,9 +17,7 @@ import java.lang.reflect.Type; /** - * * @author Daniel Qian - * */ public class WxMpMassVideoAdapter implements JsonSerializer { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialNewsArticleGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialNewsArticleGsonAdapter.java index b3791ec937..a74877f126 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialNewsArticleGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialNewsArticleGsonAdapter.java @@ -21,7 +21,7 @@ public JsonElement serialize(WxMpMaterialNews.WxMpMaterialNewsArticle article, T JsonObject articleJson = new JsonObject(); articleJson.addProperty("thumb_media_id", article.getThumbMediaId()); - articleJson.addProperty("thumb_url",article.getThumbUrl()); + articleJson.addProperty("thumb_url", article.getThumbUrl()); articleJson.addProperty("title", article.getTitle()); articleJson.addProperty("content", article.getContent()); if (null != article.getAuthor()) { @@ -70,7 +70,7 @@ public WxMpMaterialNews.WxMpMaterialNewsArticle deserialize(JsonElement jsonElem article.setThumbMediaId(GsonHelper.getAsString(thumbMediaId)); } JsonElement thumbUrl = articleInfo.get("thumb_url"); - if(thumbUrl != null && !thumbUrl.isJsonNull()) { + if (thumbUrl != null && !thumbUrl.isJsonNull()) { article.setThumbUrl(GsonHelper.getAsString(thumbUrl)); } JsonElement showCoverPic = articleInfo.get("show_cover_pic"); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpOAuth2AccessTokenAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpOAuth2AccessTokenAdapter.java index d4f8fd5526..c832ef8dae 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpOAuth2AccessTokenAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpOAuth2AccessTokenAdapter.java @@ -1,21 +1,16 @@ package me.chanjar.weixin.mp.util.json; -import java.lang.reflect.Type; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; - +import com.google.gson.*; import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; +import java.lang.reflect.Type; + public class WxMpOAuth2AccessTokenAdapter implements JsonDeserializer { @Override public WxMpOAuth2AccessToken deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws - JsonParseException { + JsonParseException { WxMpOAuth2AccessToken accessToken = new WxMpOAuth2AccessToken(); JsonObject accessTokenJsonObject = json.getAsJsonObject(); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpSemanticQueryResultAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpSemanticQueryResultAdapter.java index 2e35459716..247182d2c4 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpSemanticQueryResultAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpSemanticQueryResultAdapter.java @@ -15,9 +15,7 @@ import java.lang.reflect.Type; /** - * * @author Daniel Qian - * */ public class WxMpSemanticQueryResultAdapter implements JsonDeserializer { @@ -46,5 +44,5 @@ public WxMpSemanticQueryResult deserialize(JsonElement json, Type typeOfT, JsonD } return result; } - + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpTemplateMessageGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpTemplateMessageGsonAdapter.java index 5cc0d9c8cd..be6f5dc711 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpTemplateMessageGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpTemplateMessageGsonAdapter.java @@ -12,7 +12,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; - import me.chanjar.weixin.mp.bean.template.WxMpTemplateData; import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserCumulateGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserCumulateGsonAdapter.java index 74ccd154ff..7897096e34 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserCumulateGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserCumulateGsonAdapter.java @@ -8,29 +8,21 @@ */ package me.chanjar.weixin.mp.util.json; -import java.lang.reflect.Type; -import java.text.ParseException; - -import org.apache.commons.lang3.time.FastDateFormat; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; - +import com.google.gson.*; import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate; +import org.apache.commons.lang3.time.FastDateFormat; + +import java.lang.reflect.Type; +import java.text.ParseException; /** - * * @author Daniel Qian - * */ public class WxMpUserCumulateGsonAdapter implements JsonDeserializer { private static final FastDateFormat DATE_FORMAT = FastDateFormat - .getInstance("yyyy-MM-dd"); + .getInstance("yyyy-MM-dd"); @Override public WxDataCubeUserCumulate deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { @@ -49,5 +41,5 @@ public WxDataCubeUserCumulate deserialize(JsonElement json, Type typeOfT, JsonDe return cumulate; } - + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserGsonAdapter.java index 7bd1ed8073..f351a79d32 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserGsonAdapter.java @@ -8,17 +8,12 @@ */ package me.chanjar.weixin.mp.util.json; -import java.lang.reflect.Type; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; - +import com.google.gson.*; import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.mp.bean.result.WxMpUser; +import java.lang.reflect.Type; + public class WxMpUserGsonAdapter implements JsonDeserializer { @Override @@ -43,7 +38,7 @@ public WxMpUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationC wxMpUser.setGroupId(GsonHelper.getInteger(o, "groupid")); wxMpUser.setTagIds(GsonHelper.getIntArray(o, "tagid_list")); wxMpUser.setSexId(sexId); - if(new Integer(1).equals(sexId)) { + if (new Integer(1).equals(sexId)) { wxMpUser.setSex("男"); } else if (new Integer(2).equals(sexId)) { wxMpUser.setSex("女"); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserSummaryGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserSummaryGsonAdapter.java index 2e0791f84c..b101e01ff4 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserSummaryGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserSummaryGsonAdapter.java @@ -8,19 +8,13 @@ */ package me.chanjar.weixin.mp.util.json; -import java.lang.reflect.Type; -import java.text.ParseException; - -import org.apache.commons.lang3.time.FastDateFormat; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; - +import com.google.gson.*; import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary; +import org.apache.commons.lang3.time.FastDateFormat; + +import java.lang.reflect.Type; +import java.text.ParseException; /** * @author Daniel Qian @@ -28,11 +22,11 @@ public class WxMpUserSummaryGsonAdapter implements JsonDeserializer { private static final FastDateFormat DATE_FORMAT = FastDateFormat - .getInstance("yyyy-MM-dd"); + .getInstance("yyyy-MM-dd"); @Override public WxDataCubeUserSummary deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) - throws JsonParseException { + throws JsonParseException { WxDataCubeUserSummary summary = new WxDataCubeUserSummary(); JsonObject summaryJsonObject = json.getAsJsonObject(); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxQrCodeTicketAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxQrCodeTicketAdapter.java index c08614e541..bd1bbd90ff 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxQrCodeTicketAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxQrCodeTicketAdapter.java @@ -15,9 +15,7 @@ import java.lang.reflect.Type; /** - * * @author Daniel Qian - * */ public class WxQrCodeTicketAdapter implements JsonDeserializer { @@ -37,5 +35,5 @@ public WxMpQrCodeTicket deserialize(JsonElement json, Type typeOfT, JsonDeserial } return ticket; } - + } From 9246243fae40c8e00c7172af8da574d4be520bf3 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 20 Dec 2016 16:53:32 +0800 Subject: [PATCH 31/80] fix test code --- .../weixin/mp/api/WxMpMassMessageAPITest.java | 74 +++++++++---------- 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java index bab9b7ab7d..99b7a52c30 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java @@ -1,15 +1,6 @@ package me.chanjar.weixin.mp.api; -import java.io.IOException; -import java.io.InputStream; - -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; - import com.google.inject.Inject; - import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.exception.WxErrorException; @@ -19,13 +10,20 @@ import me.chanjar.weixin.mp.bean.WxMpMassVideo; import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.io.InputStream; /** * 测试群发消息 - * @author chanjarster * + * @author chanjarster */ -@Test(groups = "massAPI", dependsOnGroups = { "baseAPI", "mediaAPI", "groupAPI"}) +@Test(groups = "massAPI", dependsOnGroups = {"baseAPI", "mediaAPI", "groupAPI"}) @Guice(modules = ApiTestModule.class) public class WxMpMassMessageAPITest { @@ -36,31 +34,31 @@ public class WxMpMassMessageAPITest { public void testTextMassOpenIdsMessageSend() throws WxErrorException { // 发送群发消息 WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService - .getWxMpConfigStorage(); + .getWxMpConfigStorage(); WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); massMessage.setMsgType(WxConsts.MASS_MSG_TEXT); massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); massMessage.getToUsers().add(configProvider.getOpenid()); WxMpMassSendResult massResult = this.wxService - .massOpenIdsMessageSend(massMessage); + .massOpenIdsMessageSend(massMessage); Assert.assertNotNull(massResult); Assert.assertNotNull(massResult.getMsgId()); } - @Test(dataProvider="massMessages") + @Test(dataProvider = "massMessages") public void testMediaMassOpenIdsMessageSend(String massMsgType, - String mediaId) throws WxErrorException { + String mediaId) throws WxErrorException { // 发送群发消息 WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService - .getWxMpConfigStorage(); + .getWxMpConfigStorage(); WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); massMessage.setMsgType(massMsgType); massMessage.setMediaId(mediaId); massMessage.getToUsers().add(configProvider.getOpenid()); WxMpMassSendResult massResult = this.wxService - .massOpenIdsMessageSend(massMessage); + .massOpenIdsMessageSend(massMessage); Assert.assertNotNull(massResult); Assert.assertNotNull(massResult.getMsgId()); } @@ -68,28 +66,28 @@ public void testMediaMassOpenIdsMessageSend(String massMsgType, @Test public void testTextMassGroupMessageSend() throws WxErrorException { WxMpMassTagMessage massMessage = new WxMpMassTagMessage(); - massMessage.setMsgtype(WxConsts.MASS_MSG_TEXT); + massMessage.setMsgType(WxConsts.MASS_MSG_TEXT); massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); massMessage - .setTagId(this.wxService.getUserTagService().tagGet().get(0).getId()); + .setTagId(this.wxService.getUserTagService().tagGet().get(0).getId()); WxMpMassSendResult massResult = this.wxService - .massGroupMessageSend(massMessage); + .massGroupMessageSend(massMessage); Assert.assertNotNull(massResult); Assert.assertNotNull(massResult.getMsgId()); } - @Test(dataProvider="massMessages") + @Test(dataProvider = "massMessages") public void testMediaMassGroupMessageSend(String massMsgType, String mediaId) - throws WxErrorException { + throws WxErrorException { WxMpMassTagMessage massMessage = new WxMpMassTagMessage(); - massMessage.setMsgtype(massMsgType); + massMessage.setMsgType(massMsgType); massMessage.setMediaId(mediaId); massMessage - .setTagId(this.wxService.getUserTagService().tagGet().get(0).getId()); + .setTagId(this.wxService.getUserTagService().tagGet().get(0).getId()); WxMpMassSendResult massResult = this.wxService - .massGroupMessageSend(massMessage); + .massGroupMessageSend(massMessage); Assert.assertNotNull(massResult); Assert.assertNotNull(massResult.getMsgId()); } @@ -102,10 +100,10 @@ public Object[][] massMessages() throws WxErrorException, IOException { * 视频素材 */ try (InputStream inputStream = ClassLoader - .getSystemResourceAsStream("mm.mp4")) { + .getSystemResourceAsStream("mm.mp4")) { // 上传视频到媒体库 WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService() - .mediaUpload(WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, inputStream); + .mediaUpload(WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, inputStream); Assert.assertNotNull(uploadMediaRes); Assert.assertNotNull(uploadMediaRes.getMediaId()); @@ -117,41 +115,41 @@ public Object[][] massMessages() throws WxErrorException, IOException { WxMpMassUploadResult uploadResult = this.wxService.massVideoUpload(video); Assert.assertNotNull(uploadResult); Assert.assertNotNull(uploadResult.getMediaId()); - messages[0] = new Object[] { WxConsts.MASS_MSG_VIDEO, uploadResult.getMediaId() }; + messages[0] = new Object[]{WxConsts.MASS_MSG_VIDEO, uploadResult.getMediaId()}; } /** * 图片素材 */ try (InputStream inputStream = ClassLoader - .getSystemResourceAsStream("mm.jpeg")) { + .getSystemResourceAsStream("mm.jpeg")) { WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService() - .mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream); + .mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream); Assert.assertNotNull(uploadMediaRes); Assert.assertNotNull(uploadMediaRes.getMediaId()); - messages[1] = new Object[] { WxConsts.MASS_MSG_IMAGE, uploadMediaRes.getMediaId() }; + messages[1] = new Object[]{WxConsts.MASS_MSG_IMAGE, uploadMediaRes.getMediaId()}; } /** * 语音素材 */ try (InputStream inputStream = ClassLoader - .getSystemResourceAsStream("mm.mp3")) { + .getSystemResourceAsStream("mm.mp3")) { WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService() - .mediaUpload(WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, inputStream); + .mediaUpload(WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, inputStream); Assert.assertNotNull(uploadMediaRes); Assert.assertNotNull(uploadMediaRes.getMediaId()); - messages[2] = new Object[] { WxConsts.MASS_MSG_VOICE, uploadMediaRes.getMediaId() }; + messages[2] = new Object[]{WxConsts.MASS_MSG_VOICE, uploadMediaRes.getMediaId()}; } /** * 图文素材 */ try (InputStream inputStream = ClassLoader - .getSystemResourceAsStream("mm.jpeg")) { + .getSystemResourceAsStream("mm.jpeg")) { // 上传照片到媒体库 WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService() - .mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream); + .mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream); Assert.assertNotNull(uploadMediaRes); Assert.assertNotNull(uploadMediaRes.getMediaId()); @@ -174,10 +172,10 @@ public Object[][] massMessages() throws WxErrorException, IOException { news.addArticle(article2); WxMpMassUploadResult massUploadResult = this.wxService - .massNewsUpload(news); + .massNewsUpload(news); Assert.assertNotNull(massUploadResult); Assert.assertNotNull(uploadMediaRes.getMediaId()); - messages[3] = new Object[] { WxConsts.MASS_MSG_NEWS, massUploadResult.getMediaId() }; + messages[3] = new Object[]{WxConsts.MASS_MSG_NEWS, massUploadResult.getMediaId()}; } return messages; From 637fc87c0dfb11f0027c45b1476a88e538fa6873 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 23 Dec 2016 11:03:08 +0800 Subject: [PATCH 32/80] =?UTF-8?q?=E4=B8=BAWxMenuButton=E5=92=8CWxMenuRule?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BA=8F=E5=88=97=E5=8C=96=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/common/bean/menu/WxMenuButton.java | 4 +++- .../java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuButton.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuButton.java index 02efac31df..48979f7c4d 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuButton.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuButton.java @@ -2,10 +2,12 @@ import me.chanjar.weixin.common.util.ToStringUtils; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; -public class WxMenuButton { +public class WxMenuButton implements Serializable { + private static final long serialVersionUID = -1070939403109776555L; private String type; private String name; diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java index 714466f2c9..e0182c9678 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java @@ -2,7 +2,11 @@ import me.chanjar.weixin.common.util.ToStringUtils; -public class WxMenuRule { +import java.io.Serializable; + +public class WxMenuRule implements Serializable { + private static final long serialVersionUID = -4587181819499286670L; + private String tagId; private String sex; private String country; From c70bf9b0c3941862eb54a743bda50eee558563b5 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 23 Dec 2016 14:14:01 +0800 Subject: [PATCH 33/80] =?UTF-8?q?=E7=94=9F=E6=88=90=E5=B8=A6=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=9A=84=E4=BA=8C=E7=BB=B4=E7=A0=81=E6=97=B6=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E5=9C=BA=E6=99=AF=E5=80=BC=E7=9A=84=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=20#106?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpQrcodeService.java | 14 +++++----- .../mp/api/impl/WxMpQrcodeServiceImpl.java | 28 ++++++++++++------- .../api/impl/WxMpQrCodeServiceImplTest.java | 17 +++++++---- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java index 7997a70dfb..893712081e 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java @@ -18,10 +18,10 @@ public interface WxMpQrcodeService { * 详情请见: 生成带参数的二维码 *
* - * @param scene_id 参数。 - * @param expire_seconds 过期秒数,默认60秒,最小60秒,最大1800秒 + * @param sceneId 参数。 + * @param expireSeconds 过期秒数,默认60秒,最小60秒,最大1800秒 */ - WxMpQrCodeTicket qrCodeCreateTmpTicket(int scene_id, Integer expire_seconds) throws WxErrorException; + WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException; /** *
@@ -29,9 +29,9 @@ public interface WxMpQrcodeService {
    * 详情请见: 生成带参数的二维码
    * 
* - * @param scene_id 参数。永久二维码时最大值为100000(目前参数只支持1--100000) + * @param sceneId 参数。永久二维码时最大值为100000(目前参数只支持1--100000) */ - WxMpQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorException; + WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId) throws WxErrorException; /** *
@@ -39,9 +39,9 @@ public interface WxMpQrcodeService {
    * 详情请见: 生成带参数的二维码
    * 
* - * @param scene_str 参数。字符串类型长度现在为1到64 + * @param sceneStr 参数。字符串类型长度现在为1到64 */ - WxMpQrCodeTicket qrCodeCreateLastTicket(String scene_str) throws WxErrorException; + WxMpQrCodeTicket qrCodeCreateLastTicket(String sceneStr) throws WxErrorException; /** *
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java
index bb0e112cec..9726b37383 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java
@@ -26,16 +26,20 @@ public WxMpQrcodeServiceImpl(WxMpService wxMpService) {
   }
 
   @Override
-  public WxMpQrCodeTicket qrCodeCreateTmpTicket(int scene_id, Integer expire_seconds) throws WxErrorException {
+  public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException {
+    if (sceneId == 0) {
+      throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("临时二维码场景只不能为0!").build());
+    }
+
     String url = API_URL_PREFIX + "/create";
     JsonObject json = new JsonObject();
     json.addProperty("action_name", "QR_SCENE");
-    if (expire_seconds != null) {
-      json.addProperty("expire_seconds", expire_seconds);
+    if (expireSeconds != null) {
+      json.addProperty("expire_seconds", expireSeconds);
     }
     JsonObject actionInfo = new JsonObject();
     JsonObject scene = new JsonObject();
-    scene.addProperty("scene_id", scene_id);
+    scene.addProperty("scene_id", sceneId);
     actionInfo.add("scene", scene);
     json.add("action_info", actionInfo);
     String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
@@ -43,13 +47,17 @@ public WxMpQrCodeTicket qrCodeCreateTmpTicket(int scene_id, Integer expire_secon
   }
 
   @Override
-  public WxMpQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorException {
+  public WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId) throws WxErrorException {
+    if (sceneId < 1 || sceneId > 100000) {
+      throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("永久二维码的场景值目前只支持1--100000!").build());
+    }
+
     String url = API_URL_PREFIX + "/create";
     JsonObject json = new JsonObject();
     json.addProperty("action_name", "QR_LIMIT_SCENE");
     JsonObject actionInfo = new JsonObject();
     JsonObject scene = new JsonObject();
-    scene.addProperty("scene_id", scene_id);
+    scene.addProperty("scene_id", sceneId);
     actionInfo.add("scene", scene);
     json.add("action_info", actionInfo);
     String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
@@ -57,13 +65,13 @@ public WxMpQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorExcep
   }
 
   @Override
-  public WxMpQrCodeTicket qrCodeCreateLastTicket(String scene_str) throws WxErrorException {
+  public WxMpQrCodeTicket qrCodeCreateLastTicket(String sceneStr) throws WxErrorException {
     String url = API_URL_PREFIX + "/create";
     JsonObject json = new JsonObject();
     json.addProperty("action_name", "QR_LIMIT_STR_SCENE");
     JsonObject actionInfo = new JsonObject();
     JsonObject scene = new JsonObject();
-    scene.addProperty("scene_str", scene_str);
+    scene.addProperty("scene_str", sceneStr);
     actionInfo.add("scene", scene);
     json.add("action_info", actionInfo);
     String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
@@ -81,7 +89,7 @@ public String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErr
     String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s";
     try {
       String resultUrl = String.format(url,
-              URLEncoder.encode(ticket, StandardCharsets.UTF_8.name()));
+        URLEncoder.encode(ticket, StandardCharsets.UTF_8.name()));
       if (needShortUrl) {
         return this.wxMpService.shortUrl(resultUrl);
       }
@@ -89,7 +97,7 @@ public String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErr
       return resultUrl;
     } catch (UnsupportedEncodingException e) {
       WxError error = WxError.newBuilder().setErrorCode(-1)
-              .setErrorMsg(e.getMessage()).build();
+        .setErrorMsg(e.getMessage()).build();
       throw new WxErrorException(error);
     }
   }
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java
index 4c53ac1768..a2ab5328ef 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java
@@ -6,6 +6,7 @@
 import me.chanjar.weixin.mp.api.WxMpService;
 import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
 import org.testng.Assert;
+import org.testng.annotations.DataProvider;
 import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
 
@@ -19,20 +20,26 @@
 @Test(groups = "qrCodeAPI")
 @Guice(modules = ApiTestModule.class)
 public class WxMpQrCodeServiceImplTest {
-
   @Inject
   protected WxMpService wxService;
 
-  public void testQrCodeCreateTmpTicket() throws WxErrorException {
-    WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateTmpTicket(1, null);
+  @DataProvider
+  public Object[][] sceneIds() {
+    return new Object[][]{{-1}, {0}, {1}, {200000}};
+  }
+
+  @Test(dataProvider = "sceneIds")
+  public void testQrCodeCreateTmpTicket(int sceneId) throws WxErrorException {
+    WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateTmpTicket(sceneId, null);
     Assert.assertNotNull(ticket.getUrl());
     Assert.assertNotNull(ticket.getTicket());
     Assert.assertTrue(ticket.getExpire_seconds() != -1);
     System.out.println(ticket);
   }
 
-  public void testQrCodeCreateLastTicket() throws WxErrorException {
-    WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateLastTicket(1);
+  @Test(dataProvider = "sceneIds")
+  public void testQrCodeCreateLastTicket(int sceneId) throws WxErrorException {
+    WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateLastTicket(sceneId);
     Assert.assertNotNull(ticket.getUrl());
     Assert.assertNotNull(ticket.getTicket());
     Assert.assertTrue(ticket.getExpire_seconds() == -1);

From 55c6ea500e3fc14e6b547ade328da4323e5add26 Mon Sep 17 00:00:00 2001
From: Binary Wang 
Date: Fri, 23 Dec 2016 18:14:11 +0800
Subject: [PATCH 34/80] release 2.4.5.BETA

---
 pom.xml                    | 2 +-
 weixin-java-common/pom.xml | 2 +-
 weixin-java-cp/pom.xml     | 2 +-
 weixin-java-mp/pom.xml     | 2 +-
 weixin-java-osgi/pom.xml   | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/pom.xml b/pom.xml
index 5d10472bff..5676302345 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
   4.0.0
   com.github.binarywang
   weixin-java-parent
-  2.4.4-beta
+  2.4.5.BETA
   pom
   WeiXin Java Tools - Parent
   微信公众号、企业号上级POM
diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml
index 25265a9152..60f734d9ff 100644
--- a/weixin-java-common/pom.xml
+++ b/weixin-java-common/pom.xml
@@ -6,7 +6,7 @@
   
     com.github.binarywang
     weixin-java-parent
-    2.4.4-beta
+    2.4.5.BETA
   
 
   weixin-java-common
diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml
index 2e8a5515ac..43e5d414d5 100644
--- a/weixin-java-cp/pom.xml
+++ b/weixin-java-cp/pom.xml
@@ -6,7 +6,7 @@
     
         com.github.binarywang
         weixin-java-parent
-        2.4.4-beta
+        2.4.5.BETA
     
 
     weixin-java-cp
diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml
index 5c817853a3..9952c4cb77 100644
--- a/weixin-java-mp/pom.xml
+++ b/weixin-java-mp/pom.xml
@@ -6,7 +6,7 @@
     
         com.github.binarywang
         weixin-java-parent
-        2.4.4-beta
+        2.4.5.BETA
     
     weixin-java-mp
     WeiXin Java Tools - MP
diff --git a/weixin-java-osgi/pom.xml b/weixin-java-osgi/pom.xml
index 0c7c1f6d90..a0f8d7e825 100644
--- a/weixin-java-osgi/pom.xml
+++ b/weixin-java-osgi/pom.xml
@@ -6,7 +6,7 @@
   
     com.github.binarywang
     weixin-java-parent
-    2.4.4-beta
+    2.4.5.BETA
   
 
   weixin-java-osgi

From f2858c4042e5c672de96881811cd89376a453179 Mon Sep 17 00:00:00 2001
From: Binary Wang 
Date: Fri, 23 Dec 2016 18:14:11 +0800
Subject: [PATCH 35/80] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=91=E9=80=81?=
 =?UTF-8?q?=E7=BA=A2=E5=8C=85=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 pom.xml                    | 2 +-
 weixin-java-common/pom.xml | 2 +-
 weixin-java-cp/pom.xml     | 2 +-
 weixin-java-mp/pom.xml     | 2 +-
 weixin-java-osgi/pom.xml   | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/pom.xml b/pom.xml
index 5d10472bff..5676302345 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
   4.0.0
   com.github.binarywang
   weixin-java-parent
-  2.4.4-beta
+  2.4.5.BETA
   pom
   WeiXin Java Tools - Parent
   微信公众号、企业号上级POM
diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml
index 25265a9152..60f734d9ff 100644
--- a/weixin-java-common/pom.xml
+++ b/weixin-java-common/pom.xml
@@ -6,7 +6,7 @@
   
     com.github.binarywang
     weixin-java-parent
-    2.4.4-beta
+    2.4.5.BETA
   
 
   weixin-java-common
diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml
index 2e8a5515ac..43e5d414d5 100644
--- a/weixin-java-cp/pom.xml
+++ b/weixin-java-cp/pom.xml
@@ -6,7 +6,7 @@
     
         com.github.binarywang
         weixin-java-parent
-        2.4.4-beta
+        2.4.5.BETA
     
 
     weixin-java-cp
diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml
index 5c817853a3..9952c4cb77 100644
--- a/weixin-java-mp/pom.xml
+++ b/weixin-java-mp/pom.xml
@@ -6,7 +6,7 @@
     
         com.github.binarywang
         weixin-java-parent
-        2.4.4-beta
+        2.4.5.BETA
     
     weixin-java-mp
     WeiXin Java Tools - MP
diff --git a/weixin-java-osgi/pom.xml b/weixin-java-osgi/pom.xml
index 0c7c1f6d90..a0f8d7e825 100644
--- a/weixin-java-osgi/pom.xml
+++ b/weixin-java-osgi/pom.xml
@@ -6,7 +6,7 @@
   
     com.github.binarywang
     weixin-java-parent
-    2.4.4-beta
+    2.4.5.BETA
   
 
   weixin-java-osgi

From ec0d1740e35d8ae6df660280344cd431406ddda2 Mon Sep 17 00:00:00 2001
From: "408033187@qq.com" 
Date: Sun, 25 Dec 2016 17:56:59 +0800
Subject: [PATCH 36/80] =?UTF-8?q?=E5=9C=A8=E5=8E=9F=E6=9D=A5=E7=9A=84?=
 =?UTF-8?q?=E5=9F=BA=E7=A1=80=E4=B8=8A=E5=88=9B=E5=BB=BA=E6=9B=B4=E7=AE=80?=
 =?UTF-8?q?=E6=B4=81=E7=9A=84=E8=B0=83=E7=94=A8=E7=BA=A2=E5=8C=85=E6=8E=A5?=
 =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E8=AF=B7=E5=9C=A8=E8=BF=99=E4=B9=8B=E5=89=8D?=
 =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=85=8D=E7=BD=AE=E4=B8=AD=E7=9A=84?=
 =?UTF-8?q?SslContext=EF=BC=8C=E6=96=B0=E5=A2=9ESslContext=E7=9A=84get|set?=
 =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E6=96=B9=E4=BE=BFspring=E6=B3=A8?=
 =?UTF-8?q?=E5=85=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../weixin/mp/api/WxMpConfigStorage.java      | 13 ++++
 .../mp/api/WxMpInMemoryConfigStorage.java     | 43 +++++++++--
 .../chanjar/weixin/mp/api/WxMpPayService.java | 31 ++++++++
 .../mp/api/impl/WxMpPayServiceImpl.java       | 76 ++++++++++++++++++-
 .../weixin/mp/api/impl/WxMpServiceImpl.java   | 18 ++---
 5 files changed, 163 insertions(+), 18 deletions(-)

diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java
index d93c30804a..b9b11fd734 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java
@@ -118,7 +118,20 @@ public interface WxMpConfigStorage {
 
   File getTmpDirFile();
 
+  @Deprecated
   SSLContext getSSLContext();
+  
+  SSLContext getSslContext();
+  
+  void setSslContext(SSLContext sslContext);
+  
+	/**
+	 * 在此之前,必须将partnerId进行赋值
+	 * 
+	 * @param filePath
+	 *          apiclient_cert.p12的文件的绝对路径
+	 */
+	void setSslContextFilePath(String filePath) throws Exception;
 
   /**
    * http client builder
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java
index 61b75fbbaa..9fec33f84d 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java
@@ -1,14 +1,19 @@
 package me.chanjar.weixin.mp.api;
 
-import me.chanjar.weixin.common.bean.WxAccessToken;
-import me.chanjar.weixin.common.util.ToStringUtils;
-import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
-
-import javax.net.ssl.SSLContext;
 import java.io.File;
+import java.io.FileInputStream;
+import java.security.KeyStore;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
+import javax.net.ssl.SSLContext;
+
+import org.apache.http.ssl.SSLContexts;
+
+import me.chanjar.weixin.common.bean.WxAccessToken;
+import me.chanjar.weixin.common.util.ToStringUtils;
+import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
+
 /**
  * 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化
  * @author chanjarster
@@ -300,11 +305,33 @@ public void setTmpDirFile(File tmpDirFile) {
   public SSLContext getSSLContext() {
     return this.sslContext;
   }
-
-  public void setSSLContext(SSLContext context) {
-    this.sslContext = context;
+  
+  @Override
+  public SSLContext getSslContext() {
+  	return this.sslContext;
   }
 
+	@Override
+	public void setSslContextFilePath(String filePath) throws Exception {
+		if (null == partnerId) {
+			throw new Exception("请先将partnerId进行赋值");
+		}
+			File file = new File(filePath);
+			if (!file.exists()) {
+				throw new RuntimeException(file.getPath() + ":文件不存在!在设置SSLContext的时候");
+			}
+			FileInputStream inputStream = new FileInputStream(file);
+			KeyStore keystore = KeyStore.getInstance("PKCS12");
+			char[] partnerId2charArray = partnerId.toCharArray();
+			keystore.load(inputStream, partnerId2charArray);
+			this.sslContext = SSLContexts.custom().loadKeyMaterial(keystore, partnerId2charArray).build();
+	}
+	
+	@Override
+	public void setSslContext(SSLContext context) {
+		this.sslContext = context;
+	}
+  
   @Override
   public ApacheHttpClientBuilder getApacheHttpClientBuilder() {
     return this.apacheHttpClientBuilder;
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 afe888f833..b4dd3b2945 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
@@ -197,8 +197,24 @@ public interface WxMpPayService {
    * @param request 请求对象
    * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3)
    */
+  @Deprecated
   WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File keyFile) throws WxErrorException;
 
+  /**
+   * 发送微信红包给个人用户
+   * 
+   * 文档详见:
+   * 发送普通红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
+   *  接口地址:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack
+   * 发送裂变红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4
+   *  接口地址:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack
+   * 
+ * + * @param request 请求对象 + * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) + */ + WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxErrorException; + /** *
    *   查询红包记录
@@ -211,7 +227,22 @@ public interface WxMpPayService {
    * @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890
    * @param keyFile   证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3)
    */
+  @Deprecated
   WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) throws WxErrorException;
+  
+  /**
+   * 
+   *   查询红包记录
+   *   用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。
+   *   请求Url	https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo
+   *   是否需要证书	是(证书及使用说明详见商户证书)
+   *   请求方式	POST
+   * 
+ * + * @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890 + * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) + */ + WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxErrorException; /** *
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 9bd4dad250..8751fc6c86 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
@@ -160,6 +160,7 @@ public WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxErro
 
 
   @Override
+  @Deprecated
   public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File keyFile)
     throws WxErrorException {
     XStream xstream = XStreamInitializer.getInstance();
@@ -179,8 +180,30 @@ public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File
     this.checkResult(result);
     return result;
   }
+  
+  @Override
+  public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request)
+  		throws WxErrorException {
+  	XStream xstream = XStreamInitializer.getInstance();
+  	xstream.processAnnotations(WxPaySendRedpackRequest.class);
+  	xstream.processAnnotations(WxPaySendRedpackResult.class);
+  	
+  	initRequest(request);
+  	request.setSign(this.createSign(request));
+  	
+  	String url = PAY_BASE_URL + "/mmpaymkttransfers/sendredpack";
+  	if (request.getAmtType() != null) {
+  		//裂变红包
+  		url = PAY_BASE_URL + "/mmpaymkttransfers/sendgroupredpack";
+  	}
+  	String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request));
+  	WxPaySendRedpackResult result = (WxPaySendRedpackResult) xstream.fromXML(responseContent);
+  	this.checkResult(result);
+  	return result;
+  }
 
   @Override
+  @Deprecated
   public WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) throws WxErrorException {
     XStream xstream = XStreamInitializer.getInstance();
     xstream.processAnnotations(WxPayRedpackQueryRequest.class);
@@ -198,6 +221,25 @@ public WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) thro
     this.checkResult(result);
     return result;
   }
+  
+  @Override
+  public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxErrorException {
+  	XStream xstream = XStreamInitializer.getInstance();
+  	xstream.processAnnotations(WxPayRedpackQueryRequest.class);
+  	xstream.processAnnotations(WxPayRedpackQueryResult.class);
+  	
+  	WxPayRedpackQueryRequest request = new WxPayRedpackQueryRequest();
+  	request.setMchBillNo(mchBillNo);
+  	request.setBillType("MCHT");
+  	initRequest(request);
+  	request.setSign(this.createSign(request));
+  	
+  	String url = PAY_BASE_URL + "/mmpaymkttransfers/gethbinfo";
+  	String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request));
+  	WxPayRedpackQueryResult result = (WxPayRedpackQueryResult) xstream.fromXML(responseContent);
+  	this.checkResult(result);
+  	return result;
+  }
 
   @Override
   public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxErrorException {
@@ -383,7 +425,8 @@ private String executeRequest(String url, String requestStr) throws WxErrorExcep
       httpPost.releaseConnection();
     }
   }
-
+  
+  @Deprecated
   private String executeRequestWithKeyFile(String url, File keyFile, String requestStr, String mchId) throws WxErrorException {
     try (FileInputStream inputStream = new FileInputStream(keyFile)) {
       KeyStore keyStore = KeyStore.getInstance("PKCS12");
@@ -414,6 +457,37 @@ private String executeRequestWithKeyFile(String url, File keyFile, String reques
     }
   }
   
+  private String executeRequestWithKeyFile(String url, String requestStr) throws WxErrorException {
+  	try {
+  		
+  		SSLContext sslcontext = getConfig().getSSLContext();
+  		if(null==sslcontext){
+  			throw new Exception("请将配置类(WxMpInMemoryConfigStorage)中的SSLContext初始化");
+  		}
+  		SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1"}, null,
+  				new DefaultHostnameVerifier());
+  		
+  		HttpPost httpPost = new HttpPost(url);
+  		if (this.wxMpService.getHttpProxy() != null) {
+  			httpPost.setConfig(RequestConfig.custom().setProxy(this.wxMpService.getHttpProxy()).build());
+  		}
+  		
+  		try (CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build()) {
+  			httpPost.setEntity(new StringEntity(new String(requestStr.getBytes("UTF-8"), "ISO-8859-1")));
+  			try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
+  				String result = EntityUtils.toString(response.getEntity(), Consts.UTF_8);
+  				this.log.debug("\n[URL]:  {}\n[PARAMS]: {}\n[RESPONSE]: {}", url, requestStr, result);
+  				return result;
+  			}
+  		} finally {
+  			httpPost.releaseConnection();
+  		}
+  	} catch (Exception e) {
+  		this.log.error("\n[URL]:  {}\n[PARAMS]: {}\n[EXCEPTION]: {}", url, requestStr, e.getMessage());
+  		throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg(e.getMessage()).build(), e);
+  	}
+  }
+  
   @Override
   public String createSign(Object xmlBean) {
     return createSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey());
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 ccb0bd2ec4..0008e20dd6 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
@@ -20,8 +20,8 @@
 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.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;
@@ -33,7 +33,7 @@
 public class WxMpServiceImpl implements WxMpService {
 
   private static final JsonParser JSON_PARSER = new JsonParser();
-
+  
   protected final Logger log = LoggerFactory.getLogger(this.getClass());
 
   private WxMpConfigStorage configStorage;
@@ -459,12 +459,12 @@ private void initHttpClient() {
         .httpProxyUsername(this.configStorage.getHttpProxyUsername())
         .httpProxyPassword(this.configStorage.getHttpProxyPassword());
 
-    if (this.configStorage.getSSLContext() != null) {
-      SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
-          this.configStorage.getSSLContext(), new String[] { "TLSv1" }, null,
-          new DefaultHostnameVerifier());
-      apacheHttpClientBuilder.sslConnectionSocketFactory(sslsf);
-    }
+		// if (this.configStorage.getSSLContext() != null) {
+		// SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
+		// 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());

From 38d817cab2d06f989a03554f38d113211da37b74 Mon Sep 17 00:00:00 2001
From: Binary Wang 
Date: Mon, 26 Dec 2016 16:50:57 +0800
Subject: [PATCH 37/80] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BB=A3=E7=A0=81?=
 =?UTF-8?q?=E6=A0=BC=E5=BC=8F=EF=BC=8C=E5=B9=B6=E7=A7=BB=E9=99=A4=E4=B8=8D?=
 =?UTF-8?q?=E5=BF=85=E8=A6=81=E7=9A=84=E5=A4=9A=E4=BD=99=E4=BB=A3=E7=A0=81?=
 =?UTF-8?q?=20#107?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../weixin/mp/api/WxMpConfigStorage.java      |  46 +++---
 .../mp/api/WxMpInMemoryConfigStorage.java     | 156 +++++++++---------
 .../chanjar/weixin/mp/api/WxMpPayService.java |  49 +-----
 .../mp/api/impl/WxMpPayServiceImpl.java       | 144 ++++------------
 .../weixin/mp/api/impl/WxMpServiceImpl.java   |  78 ++++-----
 .../mp/api/impl/WxMpPayServiceImplTest.java   |  24 ++-
 6 files changed, 178 insertions(+), 319 deletions(-)

diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java
index b9b11fd734..7dc29d4dbd 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java
@@ -4,14 +4,13 @@
 import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
 
 import javax.net.ssl.SSLContext;
-
 import java.io.File;
 import java.util.concurrent.locks.Lock;
 
 /**
  * 微信客户端配置存储
- * @author chanjarster
  *
+ * @author chanjarster
  */
 public interface WxMpConfigStorage {
 
@@ -28,13 +27,15 @@ public interface WxMpConfigStorage {
 
   /**
    * 应该是线程安全的
+   *
    * @param accessToken 要更新的WxAccessToken对象
    */
   void updateAccessToken(WxAccessToken accessToken);
 
   /**
    * 应该是线程安全的
-   * @param accessToken 新的accessToken值
+   *
+   * @param accessToken      新的accessToken值
    * @param expiresInSeconds 过期时间,以秒为单位
    */
   void updateAccessToken(String accessToken, int expiresInSeconds);
@@ -52,7 +53,8 @@ public interface WxMpConfigStorage {
 
   /**
    * 应该是线程安全的
-   * @param jsapiTicket 新的jsapi ticket值
+   *
+   * @param jsapiTicket      新的jsapi ticket值
    * @param expiresInSeconds 过期时间,以秒为单位
    */
   void updateJsapiTicket(String jsapiTicket, int expiresInSeconds);
@@ -70,7 +72,8 @@ public interface WxMpConfigStorage {
 
   /**
    * 应该是线程安全的
-   * @param cardApiTicket 新的cardApi ticket值
+   *
+   * @param cardApiTicket    新的cardApi ticket值
    * @param expiresInSeconds 过期时间,以秒为单位
    */
   void updateCardApiTicket(String cardApiTicket, int expiresInSeconds);
@@ -82,21 +85,23 @@ public interface WxMpConfigStorage {
   String getPartnerId();
 
   String getPartnerKey();
-  
+
   /**
    * 微信支付异步回掉地址,通知url必须为直接可访问的url,不能携带参数。
-   * @since 2.5.0
+   *
    * @return
+   * @since 2.5.0
    */
   String getNotifyURL();
-  
+
   /**
    * 交易类型
    * 
    * JSAPI--公众号支付、NATIVE--原生扫码支付、APP--app支付
    * 
- * @since 2.5.0 + * * @return + * @since 2.5.0 */ String getTradeType(); @@ -118,23 +123,20 @@ public interface WxMpConfigStorage { File getTmpDirFile(); - @Deprecated - SSLContext getSSLContext(); - SSLContext getSslContext(); - + void setSslContext(SSLContext sslContext); - - /** - * 在此之前,必须将partnerId进行赋值 - * - * @param filePath - * apiclient_cert.p12的文件的绝对路径 - */ - void setSslContextFilePath(String filePath) throws Exception; + + /** + * 在此之前,必须将partnerId进行赋值 + * + * @param filePath apiclient_cert.p12的文件的绝对路径 + */ + void setSslContextFilePath(String filePath) throws Exception; /** * http client builder + * * @return ApacheHttpClientBuilder */ ApacheHttpClientBuilder getApacheHttpClientBuilder(); @@ -143,5 +145,5 @@ public interface WxMpConfigStorage { * 是否自动刷新token */ boolean autoRefreshToken(); - + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java index 9fec33f84d..5172a5d76a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java @@ -1,23 +1,21 @@ package me.chanjar.weixin.mp.api; +import me.chanjar.weixin.common.bean.WxAccessToken; +import me.chanjar.weixin.common.util.ToStringUtils; +import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder; +import org.apache.http.ssl.SSLContexts; + +import javax.net.ssl.SSLContext; import java.io.File; import java.io.FileInputStream; import java.security.KeyStore; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; -import javax.net.ssl.SSLContext; - -import org.apache.http.ssl.SSLContexts; - -import me.chanjar.weixin.common.bean.WxAccessToken; -import me.chanjar.weixin.common.util.ToStringUtils; -import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder; - /** * 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化 - * @author chanjarster * + * @author chanjarster */ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage { @@ -63,6 +61,10 @@ public String getAccessToken() { return this.accessToken; } + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + @Override public Lock getAccessTokenLock() { return this.accessTokenLock; @@ -94,15 +96,15 @@ public String getJsapiTicket() { return this.jsapiTicket; } + public void setJsapiTicket(String jsapiTicket) { + this.jsapiTicket = jsapiTicket; + } + @Override public Lock getJsapiTicketLock() { return this.jsapiTicketLock; } - public void setJsapiTicket(String jsapiTicket) { - this.jsapiTicket = jsapiTicket; - } - public long getJsapiTicketExpiresTime() { return this.jsapiTicketExpiresTime; } @@ -163,31 +165,35 @@ public String getAppId() { return this.appId; } + public void setAppId(String appId) { + this.appId = appId; + } + @Override public String getSecret() { return this.secret; } + public void setSecret(String secret) { + this.secret = secret; + } + @Override public String getToken() { return this.token; } + public void setToken(String token) { + this.token = token; + } + @Override public long getExpiresTime() { return this.expiresTime; } - public void setAppId(String appId) { - this.appId = appId; - } - - public void setSecret(String secret) { - this.secret = secret; - } - - public void setToken(String token) { - this.token = token; + public void setExpiresTime(long expiresTime) { + this.expiresTime = expiresTime; } @Override @@ -199,14 +205,6 @@ public void setAesKey(String aesKey) { this.aesKey = aesKey; } - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } - - public void setExpiresTime(long expiresTime) { - this.expiresTime = expiresTime; - } - @Override public String getOauth2redirectUri() { return this.oauth2redirectUri; @@ -259,40 +257,40 @@ public String toString() { @Override public String getPartnerId() { - return this.partnerId; + return this.partnerId; } public void setPartnerId(String partnerId) { - this.partnerId = partnerId; + this.partnerId = partnerId; } @Override public String getPartnerKey() { - return this.partnerKey; + return this.partnerKey; } public void setPartnerKey(String partnerKey) { - this.partnerKey = partnerKey; + this.partnerKey = partnerKey; + } + + + public String getNotifyURL() { + return notifyURL; } - - - public String getNotifyURL() { - return notifyURL; - } - public void setNotifyURL(String notifyURL) { - this.notifyURL = notifyURL; - } + public void setNotifyURL(String notifyURL) { + this.notifyURL = notifyURL; + } - public String getTradeType() { - return tradeType; - } + public String getTradeType() { + return tradeType; + } - public void setTradeType(String tradeType) { - this.tradeType = tradeType; - } + public void setTradeType(String tradeType) { + this.tradeType = tradeType; + } - @Override + @Override public File getTmpDirFile() { return this.tmpDirFile; } @@ -302,47 +300,43 @@ public void setTmpDirFile(File tmpDirFile) { } @Override - public SSLContext getSSLContext() { + public SSLContext getSslContext() { return this.sslContext; } - + @Override - public SSLContext getSslContext() { - return this.sslContext; - } - - @Override - public void setSslContextFilePath(String filePath) throws Exception { - if (null == partnerId) { - throw new Exception("请先将partnerId进行赋值"); - } - File file = new File(filePath); - if (!file.exists()) { - throw new RuntimeException(file.getPath() + ":文件不存在!在设置SSLContext的时候"); - } - FileInputStream inputStream = new FileInputStream(file); - KeyStore keystore = KeyStore.getInstance("PKCS12"); - char[] partnerId2charArray = partnerId.toCharArray(); - keystore.load(inputStream, partnerId2charArray); - this.sslContext = SSLContexts.custom().loadKeyMaterial(keystore, partnerId2charArray).build(); - } - - @Override - public void setSslContext(SSLContext context) { - this.sslContext = context; - } - + public void setSslContext(SSLContext context) { + this.sslContext = context; + } + @Override - public ApacheHttpClientBuilder getApacheHttpClientBuilder() { - return this.apacheHttpClientBuilder; + public void setSslContextFilePath(String filePath) throws Exception { + if (null == partnerId) { + throw new Exception("请先将partnerId进行赋值"); + } + + File file = new File(filePath); + if (!file.exists()) { + throw new RuntimeException(file.getPath() + ":文件不存在!在设置SSLContext的时候"); + } + FileInputStream inputStream = new FileInputStream(file); + KeyStore keystore = KeyStore.getInstance("PKCS12"); + char[] partnerId2charArray = partnerId.toCharArray(); + keystore.load(inputStream, partnerId2charArray); + this.sslContext = SSLContexts.custom().loadKeyMaterial(keystore, partnerId2charArray).build(); } @Override - public boolean autoRefreshToken() { - return true; + public ApacheHttpClientBuilder getApacheHttpClientBuilder() { + return this.apacheHttpClientBuilder; } public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) { this.apacheHttpClientBuilder = apacheHttpClientBuilder; } + + @Override + public boolean autoRefreshToken() { + return true; + } } 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 b4dd3b2945..797877441d 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 @@ -7,7 +7,6 @@ import me.chanjar.weixin.mp.bean.pay.request.WxPayUnifiedOrderRequest; import me.chanjar.weixin.mp.bean.pay.result.*; -import java.io.File; import java.util.Map; /** @@ -76,10 +75,9 @@ public interface WxMpPayService { *
* * @param request 请求对象 - * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) * @return 退款操作结果 */ - WxPayRefundResult refund(WxPayRefundRequest request, File keyFile) throws WxErrorException; + WxPayRefundResult refund(WxPayRefundRequest request) throws WxErrorException; /** *
@@ -128,7 +126,7 @@ public interface WxMpPayService {
   /**
    * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3)
    *
-   * @param prams   参数信息,默认使用配置中的PartnerKey进行签名
+   * @param prams 参数信息,默认使用配置中的PartnerKey进行签名
    * @return 签名字符串
    * @see #createSign(Map, String)
    */
@@ -176,7 +174,7 @@ public interface WxMpPayService {
   /**
    * 校验签名是否正确
    *
-   * @param params   需要校验的参数Map
+   * @param params  需要校验的参数Map
    * @param signKey 校验的签名Key
    * @return true - 签名校验成功,false - 签名校验失败
    * @see #checkSign(Map, String)
@@ -195,41 +193,9 @@ public interface WxMpPayService {
    * 
* * @param request 请求对象 - * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) - */ - @Deprecated - WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File keyFile) throws WxErrorException; - - /** - * 发送微信红包给个人用户 - *
-   * 文档详见:
-   * 发送普通红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
-   *  接口地址:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack
-   * 发送裂变红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4
-   *  接口地址:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack
-   * 
- * - * @param request 请求对象 - * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) */ WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxErrorException; - - /** - *
-   *   查询红包记录
-   *   用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。
-   *   请求Url	https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo
-   *   是否需要证书	是(证书及使用说明详见商户证书)
-   *   请求方式	POST
-   * 
- * - * @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890 - * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) - */ - @Deprecated - WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) throws WxErrorException; - + /** *
    *   查询红包记录
@@ -240,7 +206,6 @@ public interface WxMpPayService {
    * 
* * @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890 - * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) */ WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxErrorException; @@ -255,9 +220,8 @@ public interface WxMpPayService { *
* * @param request 请求对象 - * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) */ - WxEntPayResult entPay(WxEntPayRequest request, File keyFile) throws WxErrorException; + WxEntPayResult entPay(WxEntPayRequest request) throws WxErrorException; /** *
@@ -268,8 +232,7 @@ public interface WxMpPayService {
    * 
* * @param partnerTradeNo 商户订单号 - * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) */ - WxEntPayQueryResult queryEntPay(String partnerTradeNo, File keyFile) throws WxErrorException; + WxEntPayQueryResult queryEntPay(String partnerTradeNo) throws WxErrorException; } 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 8751fc6c86..8ad6ed35bc 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 @@ -23,16 +23,12 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; -import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.net.ssl.SSLContext; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.security.KeyStore; import java.util.*; /** @@ -44,7 +40,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { private static final String PAY_BASE_URL = "https://api.mch.weixin.qq.com"; private static final String[] TRADE_TYPES = new String[]{"JSAPI", "NATIVE", "APP"}; - private static final String[] REFUND_ACCOUNT = new String[]{"REFUND_SOURCE_RECHARGE_FUNDS","REFUND_SOURCE_UNSETTLED_FUNDS"}; + private static final String[] REFUND_ACCOUNT = new String[]{"REFUND_SOURCE_RECHARGE_FUNDS", "REFUND_SOURCE_UNSETTLED_FUNDS"}; private final Logger log = LoggerFactory.getLogger(this.getClass()); private WxMpService wxMpService; @@ -57,20 +53,20 @@ private WxMpConfigStorage getConfig() { } @Override - public WxPayRefundResult refund(WxPayRefundRequest request, File keyFile) throws WxErrorException { + public WxPayRefundResult refund(WxPayRefundRequest request) throws WxErrorException { XStream xstream = XStreamInitializer.getInstance(); xstream.processAnnotations(WxPayRefundRequest.class); xstream.processAnnotations(WxPayRefundResult.class); - + initRequest(request); - if(StringUtils.isBlank(request.getOpUserId())){ + if (StringUtils.isBlank(request.getOpUserId())) { request.setOpUserId(getConfig().getPartnerId()); } checkParameters(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/secapi/pay/refund"; - String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), request.getMchId()); + String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); WxPayRefundResult result = (WxPayRefundResult) xstream.fromXML(responseContent); this.checkResult(result); return result; @@ -158,10 +154,8 @@ public WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxErro } } - @Override - @Deprecated - public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File keyFile) + public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxErrorException { XStream xstream = XStreamInitializer.getInstance(); xstream.processAnnotations(WxPaySendRedpackRequest.class); @@ -175,36 +169,14 @@ public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File //裂变红包 url = PAY_BASE_URL + "/mmpaymkttransfers/sendgroupredpack"; } - String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), request.getMchId()); + String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); WxPaySendRedpackResult result = (WxPaySendRedpackResult) xstream.fromXML(responseContent); this.checkResult(result); return result; } - - @Override - public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) - throws WxErrorException { - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPaySendRedpackRequest.class); - xstream.processAnnotations(WxPaySendRedpackResult.class); - - initRequest(request); - request.setSign(this.createSign(request)); - - String url = PAY_BASE_URL + "/mmpaymkttransfers/sendredpack"; - if (request.getAmtType() != null) { - //裂变红包 - url = PAY_BASE_URL + "/mmpaymkttransfers/sendgroupredpack"; - } - String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); - WxPaySendRedpackResult result = (WxPaySendRedpackResult) xstream.fromXML(responseContent); - this.checkResult(result); - return result; - } @Override - @Deprecated - public WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) throws WxErrorException { + public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxErrorException { XStream xstream = XStreamInitializer.getInstance(); xstream.processAnnotations(WxPayRedpackQueryRequest.class); xstream.processAnnotations(WxPayRedpackQueryResult.class); @@ -216,30 +188,11 @@ public WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) thro request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/gethbinfo"; - String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), request.getMchId()); + String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); WxPayRedpackQueryResult result = (WxPayRedpackQueryResult) xstream.fromXML(responseContent); this.checkResult(result); return result; } - - @Override - public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxErrorException { - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPayRedpackQueryRequest.class); - xstream.processAnnotations(WxPayRedpackQueryResult.class); - - WxPayRedpackQueryRequest request = new WxPayRedpackQueryRequest(); - request.setMchBillNo(mchBillNo); - request.setBillType("MCHT"); - initRequest(request); - request.setSign(this.createSign(request)); - - String url = PAY_BASE_URL + "/mmpaymkttransfers/gethbinfo"; - String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); - WxPayRedpackQueryResult result = (WxPayRedpackQueryResult) xstream.fromXML(responseContent); - this.checkResult(result); - return result; - } @Override public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxErrorException { @@ -296,17 +249,17 @@ public WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) XStream xstream = XStreamInitializer.getInstance(); xstream.processAnnotations(WxPayUnifiedOrderRequest.class); xstream.processAnnotations(WxPayUnifiedOrderResult.class); - + initRequest(request); - if(StringUtils.isBlank(request.getNotifyURL())){ + if (StringUtils.isBlank(request.getNotifyURL())) { request.setNotifyURL(getConfig().getNotifyURL()); } - if(StringUtils.isBlank(request.getTradeType())){ + if (StringUtils.isBlank(request.getTradeType())) { request.setTradeType(getConfig().getTradeType()); } checkParameters(request);//校验参数 request.setSign(this.createSign(request)); - + String url = PAY_BASE_URL + "/pay/unifiedorder"; String xmlParam = xstream.toXML(request); log.debug("微信统一下单接口,URL:{},参数:{}", url, xmlParam); @@ -317,15 +270,15 @@ public WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) this.checkResult(result); return result; } - - private void initRequest(WxPayBaseRequest request){ - if(StringUtils.isBlank(request.getAppid())){ + + private void initRequest(WxPayBaseRequest request) { + if (StringUtils.isBlank(request.getAppid())) { request.setAppid(getConfig().getAppId()); } - if(StringUtils.isBlank(request.getMchId())){ + if (StringUtils.isBlank(request.getMchId())) { request.setMchId(getConfig().getPartnerId()); } - if(StringUtils.isBlank(request.getNonceStr())){ + if (StringUtils.isBlank(request.getNonceStr())) { request.setNonceStr(String.valueOf(System.currentTimeMillis())); } } @@ -370,25 +323,25 @@ public Map getPayInfo(WxPayUnifiedOrderRequest request) throws W } @Override - public WxEntPayResult entPay(WxEntPayRequest request, File keyFile) throws WxErrorException { + public WxEntPayResult entPay(WxEntPayRequest request) throws WxErrorException { XStream xstream = XStreamInitializer.getInstance(); xstream.processAnnotations(WxEntPayRequest.class); xstream.processAnnotations(WxEntPayResult.class); - + initRequest(request); BeanUtils.checkRequiredFields(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/promotion/transfers"; - String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), request.getMchId()); + String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); WxEntPayResult result = (WxEntPayResult) xstream.fromXML(responseContent); this.checkResult(result); return result; } @Override - public WxEntPayQueryResult queryEntPay(String partnerTradeNo, File keyFile) throws WxErrorException { + public WxEntPayQueryResult queryEntPay(String partnerTradeNo) throws WxErrorException { XStream xstream = XStreamInitializer.getInstance(); xstream.processAnnotations(WxEntPayQueryRequest.class); xstream.processAnnotations(WxEntPayQueryResult.class); @@ -398,7 +351,7 @@ public WxEntPayQueryResult queryEntPay(String partnerTradeNo, File keyFile) thro request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/gettransferinfo"; - String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), request.getMchId()); + String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); WxEntPayQueryResult result = (WxEntPayQueryResult) xstream.fromXML(responseContent); this.checkResult(result); return result; @@ -425,15 +378,15 @@ private String executeRequest(String url, String requestStr) throws WxErrorExcep httpPost.releaseConnection(); } } - - @Deprecated - private String executeRequestWithKeyFile(String url, File keyFile, String requestStr, String mchId) throws WxErrorException { - try (FileInputStream inputStream = new FileInputStream(keyFile)) { - KeyStore keyStore = KeyStore.getInstance("PKCS12"); - keyStore.load(inputStream, mchId.toCharArray()); - - SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, mchId.toCharArray()).build(); - SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1"}, null, + + private String executeRequestWithKeyFile(String url, String requestStr) throws WxErrorException { + try { + SSLContext sslContext = getConfig().getSslContext(); + if (null == sslContext) { + throw new Exception("请将配置类(即WxMpConfigStorage的实现类)中的SSLContext初始化"); + } + + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[]{"TLSv1"}, null, new DefaultHostnameVerifier()); HttpPost httpPost = new HttpPost(url); @@ -456,38 +409,7 @@ private String executeRequestWithKeyFile(String url, File keyFile, String reques throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg(e.getMessage()).build(), e); } } - - private String executeRequestWithKeyFile(String url, String requestStr) throws WxErrorException { - try { - - SSLContext sslcontext = getConfig().getSSLContext(); - if(null==sslcontext){ - throw new Exception("请将配置类(WxMpInMemoryConfigStorage)中的SSLContext初始化"); - } - SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1"}, null, - new DefaultHostnameVerifier()); - - HttpPost httpPost = new HttpPost(url); - if (this.wxMpService.getHttpProxy() != null) { - httpPost.setConfig(RequestConfig.custom().setProxy(this.wxMpService.getHttpProxy()).build()); - } - - try (CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build()) { - httpPost.setEntity(new StringEntity(new String(requestStr.getBytes("UTF-8"), "ISO-8859-1"))); - try (CloseableHttpResponse response = httpclient.execute(httpPost)) { - String result = EntityUtils.toString(response.getEntity(), Consts.UTF_8); - this.log.debug("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", url, requestStr, result); - return result; - } - } finally { - httpPost.releaseConnection(); - } - } catch (Exception e) { - this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[EXCEPTION]: {}", url, requestStr, e.getMessage()); - throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg(e.getMessage()).build(), e); - } - } - + @Override public String createSign(Object xmlBean) { return createSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey()); 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 0008e20dd6..d2aa2a2c44 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 @@ -20,8 +20,6 @@ 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; @@ -30,55 +28,39 @@ import java.io.IOException; import java.util.concurrent.locks.Lock; +//import org.apache.http.conn.ssl.DefaultHostnameVerifier; +//import org.apache.http.conn.ssl.SSLConnectionSocketFactory; + public class WxMpServiceImpl implements WxMpService { private static final JsonParser JSON_PARSER = new JsonParser(); - - protected final Logger log = LoggerFactory.getLogger(this.getClass()); + protected final Logger log = LoggerFactory.getLogger(this.getClass()); + protected WxSessionManager sessionManager = new StandardSessionManager(); private WxMpConfigStorage configStorage; - private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this); - private WxMpMaterialService materialService = new WxMpMaterialServiceImpl(this); - private WxMpMenuService menuService = new WxMpMenuServiceImpl(this); - private WxMpUserService userService = new WxMpUserServiceImpl(this); - private WxMpUserTagService tagService = new WxMpUserTagServiceImpl(this); - private WxMpQrcodeService qrCodeService = new WxMpQrcodeServiceImpl(this); - private WxMpCardService cardService = new WxMpCardServiceImpl(this); - 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 WxMpTemplateMsgService templateMsgService = new WxMpTemplateMsgServiceImpl(this); - private WxMpDeviceService deviceService = new WxMpDeviceServiceImpl(this); - private CloseableHttpClient httpClient; - private HttpHost httpProxy; - private int retrySleepMillis = 1000; - private int maxRetryTimes = 5; - protected WxSessionManager sessionManager = new StandardSessionManager(); - @Override public boolean checkSignature(String timestamp, String nonce, String signature) { try { return SHA1.gen(this.configStorage.getToken(), timestamp, nonce) - .equals(signature); + .equals(signature); } catch (Exception e) { return false; } @@ -101,8 +83,8 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException { if (this.configStorage.isAccessTokenExpired()) { String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential" + - "&appid=" + this.configStorage.getAppId() + "&secret=" - + this.configStorage.getSecret(); + "&appid=" + this.configStorage.getAppId() + "&secret=" + + this.configStorage.getSecret(); try { HttpGet httpGet = new HttpGet(url); if (this.httpProxy != null) { @@ -117,8 +99,8 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException { } WxAccessToken accessToken = WxAccessToken.fromJson(resultContent); this.configStorage.updateAccessToken(accessToken.getAccessToken(), - accessToken.getExpiresIn()); - }finally { + accessToken.getExpiresIn()); + } finally { httpGet.releaseConnection(); } } catch (IOException e) { @@ -167,7 +149,7 @@ public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException String noncestr = RandomUtils.getRandomStr(); String jsapiTicket = getJsapiTicket(false); String signature = SHA1.genWithAmple("jsapi_ticket=" + jsapiTicket, - "noncestr=" + noncestr, "timestamp=" + timestamp, "url=" + url); + "noncestr=" + noncestr, "timestamp=" + timestamp, "url=" + url); WxJsapiSignature jsapiSignature = new WxJsapiSignature(); jsapiSignature.setAppid(this.configStorage.getAppId()); jsapiSignature.setTimestamp(timestamp); @@ -247,7 +229,7 @@ public String oauth2buildAuthorizationUrl(String redirectURI, String scope, Stri @Override public String buildQrConnectUrl(String redirectURI, String scope, - String state) { + String state) { StringBuilder url = new StringBuilder(); url.append("https://open.weixin.qq.com/connect/qrconnect?"); url.append("appid=").append(this.configStorage.getAppId()); @@ -366,7 +348,7 @@ public T execute(RequestExecutor executor, String uri, E data) thro do { try { T result = executeInternal(executor, uri, data); - this.log.debug("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}",uri, data, result); + this.log.debug("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", uri, data, result); return result; } catch (WxErrorException e) { if (retryTimes + 1 > this.maxRetryTimes) { @@ -416,7 +398,7 @@ protected synchronized T executeInternal(RequestExecutor executor, if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001) { // 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token this.configStorage.expireAccessToken(); - if(this.configStorage.autoRefreshToken()){ + if (this.configStorage.autoRefreshToken()) { return this.execute(executor, uri, data); } } @@ -441,30 +423,24 @@ public CloseableHttpClient getHttpclient() { return this.httpClient; } - @Override - public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider) { - this.configStorage = wxConfigProvider; - this.initHttpClient(); - } - private void initHttpClient() { ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage - .getApacheHttpClientBuilder(); + .getApacheHttpClientBuilder(); if (null == apacheHttpClientBuilder) { apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get(); } apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost()) - .httpProxyPort(this.configStorage.getHttpProxyPort()) - .httpProxyUsername(this.configStorage.getHttpProxyUsername()) - .httpProxyPassword(this.configStorage.getHttpProxyPassword()); + .httpProxyPort(this.configStorage.getHttpProxyPort()) + .httpProxyUsername(this.configStorage.getHttpProxyUsername()) + .httpProxyPassword(this.configStorage.getHttpProxyPassword()); - // if (this.configStorage.getSSLContext() != null) { - // SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( - // this.configStorage.getSSLContext(), new String[] { "TLSv1" }, null, - // new DefaultHostnameVerifier()); - // apacheHttpClientBuilder.sslConnectionSocketFactory(sslsf); - // } + // if (this.configStorage.getSSLContext() != null) { + // SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( + // 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()); @@ -478,6 +454,12 @@ public WxMpConfigStorage getWxMpConfigStorage() { return this.configStorage; } + @Override + public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider) { + this.configStorage = wxConfigProvider; + this.initHttpClient(); + } + @Override public void setRetrySleepMillis(int retrySleepMillis) { this.retrySleepMillis = retrySleepMillis; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index 7b2a9dea4e..31fc0c06d6 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -34,7 +34,7 @@ public void testGetPayInfo() throws Exception { } /** - * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#refund(WxPayRefundRequest, File)} . + * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#refund(WxPayRefundRequest)} . */ @Test public void testRefund() throws Exception { @@ -43,8 +43,7 @@ public void testRefund() throws Exception { request.setOutTradeNo("1111"); request.setTotalFee(1222); request.setRefundFee(111); - File keyFile = new File("E:\\dlt.p12"); - WxPayRefundResult result = this.wxService.getPayService().refund(request, keyFile); + WxPayRefundResult result = this.wxService.getPayService().refund(request); System.err.println(result); } @@ -72,7 +71,7 @@ public void testCheckJSSDKCallbackDataSignature() throws Exception { } /** - * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#sendRedpack(WxPaySendRedpackRequest, File)} . + * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#sendRedpack(WxPaySendRedpackRequest)} . */ @Test public void testSendRedpack() throws Exception { @@ -82,18 +81,17 @@ public void testSendRedpack() throws Exception { request.setMchBillNo("aaaa"); request .setReOpenid(((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); - File keyFile = new File("E:\\dlt.p12"); - WxPaySendRedpackResult redpackResult = this.wxService.getPayService().sendRedpack(request, keyFile); + WxPaySendRedpackResult redpackResult = this.wxService.getPayService().sendRedpack(request); System.err.println(redpackResult); } /** - * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryRedpack(String, File)}. + * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryRedpack(String)}. */ @Test public void testQueryRedpack() throws Exception { File keyFile = new File("E:\\dlt.p12"); - WxPayRedpackQueryResult redpackResult = this.wxService.getPayService().queryRedpack("aaaa", keyFile); + WxPayRedpackQueryResult redpackResult = this.wxService.getPayService().queryRedpack("aaaa"); System.err.println(redpackResult); } @@ -128,21 +126,19 @@ public final void testCloseOrder() throws WxErrorException { } /** - * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#entPay(WxEntPayRequest, File)}. + * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#entPay(WxEntPayRequest)}. */ @Test public final void testEntPay() throws WxErrorException { - File keyFile = new File("E:\\dlt.p12"); WxEntPayRequest request = new WxEntPayRequest(); - System.err.println(this.wxService.getPayService().entPay(request, keyFile)); + System.err.println(this.wxService.getPayService().entPay(request)); } /** - * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryEntPay(String, File)}. + * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryEntPay(String)}. */ @Test public final void testQueryEntPay() throws WxErrorException { - File keyFile = new File("E:\\dlt.p12"); - System.err.println(this.wxService.getPayService().queryEntPay("11212121", keyFile)); + System.err.println(this.wxService.getPayService().queryEntPay("11212121")); } } From 76f4e0b12094a7ab27bff2e6cb44593343c7fd5e Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 26 Dec 2016 17:01:10 +0800 Subject: [PATCH 38/80] release 2.4.6.BETA --- pom.xml | 2 +- weixin-java-common/pom.xml | 2 +- weixin-java-cp/pom.xml | 2 +- weixin-java-mp/pom.xml | 2 +- weixin-java-osgi/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 5676302345..24e46e3951 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.github.binarywang weixin-java-parent - 2.4.5.BETA + 2.4.6.BETA pom WeiXin Java Tools - Parent 微信公众号、企业号上级POM diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml index 60f734d9ff..5b55b6afb4 100644 --- a/weixin-java-common/pom.xml +++ b/weixin-java-common/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.5.BETA + 2.4.6.BETA weixin-java-common diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index 43e5d414d5..3b8072c696 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.5.BETA + 2.4.6.BETA weixin-java-cp diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index 9952c4cb77..9db06d7ab3 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.5.BETA + 2.4.6.BETA weixin-java-mp WeiXin Java Tools - MP diff --git a/weixin-java-osgi/pom.xml b/weixin-java-osgi/pom.xml index a0f8d7e825..8667d33036 100644 --- a/weixin-java-osgi/pom.xml +++ b/weixin-java-osgi/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.5.BETA + 2.4.6.BETA weixin-java-osgi From 87770f4b3f97a8588767f36c407a3272eee73b65 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 26 Dec 2016 17:42:26 +0800 Subject: [PATCH 39/80] fix some javadoc warnings --- .../weixin/mp/api/WxMpConfigStorage.java | 2 - .../mp/bean/pay/request/WxPayBaseRequest.java | 15 +- .../mp/bean/pay/result/WxPayBaseResult.java | 14 +- .../pay/result/WxPayOrderNotifyResult.java | 784 +++++++++--------- 4 files changed, 394 insertions(+), 421 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java index 7dc29d4dbd..cff903bf33 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java @@ -89,7 +89,6 @@ public interface WxMpConfigStorage { /** * 微信支付异步回掉地址,通知url必须为直接可访问的url,不能携带参数。 * - * @return * @since 2.5.0 */ String getNotifyURL(); @@ -100,7 +99,6 @@ public interface WxMpConfigStorage { * JSAPI--公众号支付、NATIVE--原生扫码支付、APP--app支付 *
* - * @return * @since 2.5.0 */ String getTradeType(); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java index d6926d0e8b..3bfe556f4f 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java @@ -1,10 +1,10 @@ package me.chanjar.weixin.mp.bean.pay.request; -import java.math.BigDecimal; - import com.thoughtworks.xstream.annotations.XStreamAlias; import me.chanjar.weixin.common.util.ToStringUtils; +import java.math.BigDecimal; + /** *
  * Created by Binary Wang on 2016-10-24.
@@ -75,7 +75,7 @@ public String getAppid() {
 
   /**
    * 如果配置中已经设置,可以不设置值
-   * @param appid
+   * @param appid 微信公众号appid
    */
   public void setAppid(String appid) {
     this.appid = appid;
@@ -87,7 +87,7 @@ public String getMchId() {
 
   /**
    * 如果配置中已经设置,可以不设置值
-   * @param mchId
+   * @param mchId 微信商户号
    */
   public void setMchId(String mchId) {
     this.mchId = mchId;
@@ -99,7 +99,7 @@ public String getNonceStr() {
 
   /**
    * 默认采用时间戳为随机字符串,可以不设置
-   * @param nonceStr
+   * @param nonceStr 随机字符串
    */
   public void setNonceStr(String nonceStr) {
     this.nonceStr = nonceStr;
@@ -112,12 +112,11 @@ public String getSign() {
   public void setSign(String sign) {
     this.sign = sign;
   }
-  
+
   /**
    * 将单位为元转换为单位为分
    *
-   * @param yuan
-   * @return
+   * @param yuan 将要转换的元的数值字符串
    */
   public static Integer yuanToFee(String yuan) {
     return  new BigDecimal(yuan).setScale(2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).intValue();
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java
index b719e3338b..cafd8a5687 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java
@@ -1,13 +1,12 @@
 package me.chanjar.weixin.mp.bean.pay.result;
 
-import java.math.BigDecimal;
-import java.util.Map;
-
 import com.thoughtworks.xstream.annotations.XStreamAlias;
-
 import me.chanjar.weixin.common.util.BeanUtils;
 import me.chanjar.weixin.common.util.ToStringUtils;
 
+import java.math.BigDecimal;
+import java.util.Map;
+
 /**
  * 
  * 微信支付结果共用属性类
@@ -146,16 +145,15 @@ public String getSign() {
   public void setSign(String sign) {
     this.sign = sign;
   }
-  
+
   /**
    * 将单位分转换成单位圆
-   * @param fee
-   * @return
+   * @param fee 将要被转换为元的分的数值
    */
   public static String feeToYuan(Integer fee) {
     return new BigDecimal(Double.valueOf(fee) / 100).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString();
   }
-  
+
   public Map toMap(){
   	return BeanUtils.xmlBean2Map(this);
   }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java
index 3c78247717..a5770873da 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java
@@ -1,403 +1,381 @@
-package me.chanjar.weixin.mp.bean.pay.result;
-
-import java.io.Serializable;
-import java.util.List;
-import java.util.Map;
-
-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.util.BeanUtils;
-import me.chanjar.weixin.mp.bean.pay.WxPayOrderNotifyCoupon;
-
-/**
- * 支付结果通用通知 ,文档见:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7
- * @author aimilin6688
- * @since 2.5.0
- */
-@XStreamAlias("xml")
-public class WxPayOrderNotifyResult  extends WxPayBaseResult implements Serializable {
-
-	/**
-	 * @fields serialVersionUID 
-	 */
-	private static final long serialVersionUID = 5389718115223345496L;
-	
-	
-	/**
-	 * 
-	 * 设备号
-	 * device_info	
-	 * 否	
-	 * String(32)	
-	 * 013467007045764	
-	 * 微信支付分配的终端设备号,
-	 * 
- * @fields deviceInfo - */ - @XStreamAlias("device_info") - private String deviceInfo; - - /** - *
-	 * 用户标识	
-	 * openid	
-	 * 是	
-	 * String(128)	
-	 * wxd930ea5d5a258f4f	
-	 * 用户在商户appid下的唯一标识
-	 * 
- * @fields openid - */ - @XStreamAlias("openid") - private String openid; - - /** - *
-	 * 是否关注公众账号	
-	 * is_subscribe	
-	 * 否	
-	 * String(1)	
-	 * Y	
-	 * 用户是否关注公众账号,Y-关注,N-未关注,仅在公众账号类型支付有效
-	 * 
- * @fields isSubscribe - */ - @XStreamAlias("is_subscribe") - private String isSubscribe; - - - /** - *
-	 * 交易类型	
-	 * trade_type	
-	 * 是	
-	 * String(16)	
-	 * JSAPI	JSAPI、NATIVE、APP
-	 * 
- * @fields tradeType - */ - @XStreamAlias("trade_type") - private String tradeType; - - - /** - *
-	 * 付款银行	
-	 * bank_type	
-	 * 是	
-	 * String(16)	
-	 * CMC	
-	 * 银行类型,采用字符串类型的银行标识,银行类型见银行列表
-	 * 
- * @fields bankType - */ - @XStreamAlias("bank_type") - private String bankType; - - - /** - *
-	 * 订单金额	
-	 * total_fee	
-	 * 是	
-	 * Int	
-	 * 100	
-	 * 订单总金额,单位为分
-	 * 
- * @fields totalFee - */ - @XStreamAlias("total_fee") - private Integer totalFee; - /** - *
-	 * 应结订单金额	
-	 * settlement_total_fee	
-	 * 否	
-	 * Int	
-	 * 100	
-	 * 应结订单金额=订单金额-非充值代金券金额,应结订单金额<=订单金额。
-	 * 
- * @fields settlementTotalFee - */ - @XStreamAlias("settlement_total_fee") - private Integer settlementTotalFee; - /** - *
-	 * 货币种类	
-	 * fee_type	
-	 * 否	
-	 * String(8)	
-	 * CNY	
-	 * 货币类型,符合ISO4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
-	 * 
- * @fields feeType - */ - @XStreamAlias("fee_type") - private String feeType; - /** - *
-	 * 现金支付金额	
-	 * cash_fee	
-	 * 是	
-	 * Int	
-	 * 100	
-	 * 现金支付金额订单现金支付金额,详见支付金额
-	 * 
- * @fields cashFee - */ - @XStreamAlias("cash_fee") - private Integer cashFee; - /** - *
-	 * 现金支付货币类型	
-	 * cash_fee_type	
-	 * 否	
-	 * String(16)	
-	 * CNY	
-	 * 货币类型,符合ISO4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
-	 * 
- * @fields cashFeeType - */ - @XStreamAlias("cash_fee_type") - private String cashFeeType; - /** - *
-	 * 总代金券金额	
-	 * coupon_fee	
-	 * 否	
-	 * Int	
-	 * 10	
-	 * 代金券金额<=订单金额,订单金额-代金券金额=现金支付金额,详见支付金额
-	 * 
- * @fields couponFee - */ - @XStreamAlias("coupon_fee") - private Integer couponFee; - - /** - *
-   * 代金券使用数量
-   * coupon_count
-   * 否
-   * Int
-   * 1
-   * 代金券使用数量
-   */
-	@XStreamAlias("coupon_count")
-	private Integer couponCount;
-	
-	private List couponList;
-	
-	
-	
-	/**
-	 * 
-	 * 微信支付订单号	
-	 * transaction_id	
-	 * 是	
-	 * String(32)	
-	 * 1217752501201407033233368018	
-	 * 微信支付订单号
-	 * 
- * @fields transactionId - */ - @XStreamAlias("transaction_id") - private String transactionId; - - /** - *
-	 * 商户订单号	
-	 * out_trade_no	
-	 * 是	
-	 * String(32)	
-	 * 1212321211201407033568112322	
-	 * 商户系统的订单号,与请求一致。
-	 * 
- * @fields outTradeNo - */ - @XStreamAlias("out_trade_no") - private String outTradeNo; - /** - *
-	 * 商家数据包	
-	 * attach	
-	 * 否	
-	 * String(128)	
-	 * 123456	
-	 * 商家数据包,原样返回
-	 * 
- * @fields - */ - @XStreamAlias("attach") - private String attach; - /** - *
-	 * 支付完成时间	
-	 * time_end	
-	 * 是	
-	 * String(14)	
-	 * 20141030133525	
-	 * 支付完成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则
-	 * 
- * @fields timeEnd - */ - @XStreamAlias("time_end") - private String timeEnd; - - - public Integer getCouponCount() { - return couponCount; - } - - public void setCouponCount(Integer couponCount) { - this.couponCount = couponCount; - } - - public List getCouponList() { - return couponList; - } - - public void setCouponList(List couponList) { - this.couponList = couponList; - } - - public String getDeviceInfo() { - return deviceInfo; - } - - public void setDeviceInfo(String deviceInfo) { - this.deviceInfo = deviceInfo; - } - - public String getOpenid() { - return openid; - } - - public void setOpenid(String openid) { - this.openid = openid; - } - - public String getIsSubscribe() { - return isSubscribe; - } - - public void setIsSubscribe(String isSubscribe) { - this.isSubscribe = isSubscribe; - } - - public String getTradeType() { - return tradeType; - } - - public void setTradeType(String tradeType) { - this.tradeType = tradeType; - } - - public String getBankType() { - return bankType; - } - - public void setBankType(String bankType) { - this.bankType = bankType; - } - - public Integer getTotalFee() { - return totalFee; - } - - public void setTotalFee(Integer totalFee) { - this.totalFee = totalFee; - } - - public Integer getSettlementTotalFee() { - return settlementTotalFee; - } - - public void setSettlementTotalFee(Integer settlementTotalFee) { - this.settlementTotalFee = settlementTotalFee; - } - - public String getFeeType() { - return feeType; - } - - public void setFeeType(String feeType) { - this.feeType = feeType; - } - - public Integer getCashFee() { - return cashFee; - } - - public void setCashFee(Integer cashFee) { - this.cashFee = cashFee; - } - - public String getCashFeeType() { - return cashFeeType; - } - - public void setCashFeeType(String cashFeeType) { - this.cashFeeType = cashFeeType; - } - - public Integer getCouponFee() { - return couponFee; - } - - public void setCouponFee(Integer couponFee) { - this.couponFee = couponFee; - } - - public String getTransactionId() { - return transactionId; - } - - public void setTransactionId(String transactionId) { - this.transactionId = transactionId; - } - - public String getOutTradeNo() { - return outTradeNo; - } - - public void setOutTradeNo(String outTradeNo) { - this.outTradeNo = outTradeNo; - } - - public String getAttach() { - return attach; - } - - public void setAttach(String attach) { - this.attach = attach; - } - - public String getTimeEnd() { - return timeEnd; - } - - public void setTimeEnd(String timeEnd) { - this.timeEnd = timeEnd; - } - - @Override - public Map toMap(){ - Map resultMap = BeanUtils.xmlBean2Map(this); - if(this.getCouponCount() != null && this.getCouponCount() > 0){ - for (int i = 0; i < this.getCouponCount(); i++) { - WxPayOrderNotifyCoupon coupon = couponList.get(i); - resultMap.putAll(coupon.toMap(i)); - } - } - return resultMap; - } - - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE); - } -} +package me.chanjar.weixin.mp.bean.pay.result; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import me.chanjar.weixin.common.util.BeanUtils; +import me.chanjar.weixin.mp.bean.pay.WxPayOrderNotifyCoupon; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +/** + * 支付结果通用通知 ,文档见:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7 + * @author aimilin6688 + * @since 2.5.0 + */ +@XStreamAlias("xml") +public class WxPayOrderNotifyResult extends WxPayBaseResult implements Serializable { + + private static final long serialVersionUID = 5389718115223345496L; + + + /** + *
+	 * 设备号
+	 * device_info
+	 * 否
+	 * String(32)
+	 * 013467007045764
+	 * 微信支付分配的终端设备号,
+	 * 
+ */ + @XStreamAlias("device_info") + private String deviceInfo; + + /** + *
+	 * 用户标识
+	 * openid
+	 * 是
+	 * String(128)
+	 * wxd930ea5d5a258f4f
+	 * 用户在商户appid下的唯一标识
+	 * 
+ */ + @XStreamAlias("openid") + private String openid; + + /** + *
+	 * 是否关注公众账号
+	 * is_subscribe
+	 * 否
+	 * String(1)
+	 * Y
+	 * 用户是否关注公众账号,Y-关注,N-未关注,仅在公众账号类型支付有效
+	 * 
+ */ + @XStreamAlias("is_subscribe") + private String isSubscribe; + + + /** + *
+	 * 交易类型
+	 * trade_type
+	 * 是
+	 * String(16)
+	 * JSAPI	JSAPI、NATIVE、APP
+	 * 
+ */ + @XStreamAlias("trade_type") + private String tradeType; + + + /** + *
+	 * 付款银行
+	 * bank_type
+	 * 是
+	 * String(16)
+	 * CMC
+	 * 银行类型,采用字符串类型的银行标识,银行类型见银行列表
+	 * 
+ */ + @XStreamAlias("bank_type") + private String bankType; + + + /** + *
+	 * 订单金额
+	 * total_fee
+	 * 是
+	 * Int
+	 * 100
+	 * 订单总金额,单位为分
+	 * 
+ */ + @XStreamAlias("total_fee") + private Integer totalFee; + /** + *
+	 * 应结订单金额
+	 * settlement_total_fee
+	 * 否
+	 * Int
+	 * 100
+	 * 应结订单金额=订单金额-非充值代金券金额,应结订单金额<=订单金额。
+	 * 
+ */ + @XStreamAlias("settlement_total_fee") + private Integer settlementTotalFee; + /** + *
+	 * 货币种类
+	 * fee_type
+	 * 否
+	 * String(8)
+	 * CNY
+	 * 货币类型,符合ISO4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
+	 * 
+ */ + @XStreamAlias("fee_type") + private String feeType; + /** + *
+	 * 现金支付金额
+	 * cash_fee
+	 * 是
+	 * Int
+	 * 100
+	 * 现金支付金额订单现金支付金额,详见支付金额
+	 * 
+ */ + @XStreamAlias("cash_fee") + private Integer cashFee; + /** + *
+	 * 现金支付货币类型
+	 * cash_fee_type
+	 * 否
+	 * String(16)
+	 * CNY
+	 * 货币类型,符合ISO4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
+	 * 
+ */ + @XStreamAlias("cash_fee_type") + private String cashFeeType; + /** + *
+	 * 总代金券金额
+	 * coupon_fee
+	 * 否
+	 * Int
+	 * 10
+	 * 代金券金额<=订单金额,订单金额-代金券金额=现金支付金额,详见支付金额
+	 * 
+ */ + @XStreamAlias("coupon_fee") + private Integer couponFee; + + /** + *
+   * 代金券使用数量
+   * coupon_count
+   * 否
+   * Int
+   * 1
+   * 代金券使用数量
+   * 
+ */ + @XStreamAlias("coupon_count") + private Integer couponCount; + + private List couponList; + + /** + *
+	 * 微信支付订单号
+	 * transaction_id
+	 * 是
+	 * String(32)
+	 * 1217752501201407033233368018
+	 * 微信支付订单号
+	 * 
+ */ + @XStreamAlias("transaction_id") + private String transactionId; + + /** + *
+	 * 商户订单号
+	 * out_trade_no
+	 * 是
+	 * String(32)
+	 * 1212321211201407033568112322
+	 * 商户系统的订单号,与请求一致。
+	 * 
+ */ + @XStreamAlias("out_trade_no") + private String outTradeNo; + /** + *
+	 * 商家数据包
+	 * attach
+	 * 否
+	 * String(128)
+	 * 123456
+	 * 商家数据包,原样返回
+	 * 
+ */ + @XStreamAlias("attach") + private String attach; + /** + *
+	 * 支付完成时间
+	 * time_end
+	 * 是
+	 * String(14)
+	 * 20141030133525
+	 * 支付完成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则
+	 * 
+ */ + @XStreamAlias("time_end") + private String timeEnd; + + public Integer getCouponCount() { + return couponCount; + } + + public void setCouponCount(Integer couponCount) { + this.couponCount = couponCount; + } + + public List getCouponList() { + return couponList; + } + + public void setCouponList(List couponList) { + this.couponList = couponList; + } + + public String getDeviceInfo() { + return deviceInfo; + } + + public void setDeviceInfo(String deviceInfo) { + this.deviceInfo = deviceInfo; + } + + public String getOpenid() { + return openid; + } + + public void setOpenid(String openid) { + this.openid = openid; + } + + public String getIsSubscribe() { + return isSubscribe; + } + + public void setIsSubscribe(String isSubscribe) { + this.isSubscribe = isSubscribe; + } + + public String getTradeType() { + return tradeType; + } + + public void setTradeType(String tradeType) { + this.tradeType = tradeType; + } + + public String getBankType() { + return bankType; + } + + public void setBankType(String bankType) { + this.bankType = bankType; + } + + public Integer getTotalFee() { + return totalFee; + } + + public void setTotalFee(Integer totalFee) { + this.totalFee = totalFee; + } + + public Integer getSettlementTotalFee() { + return settlementTotalFee; + } + + public void setSettlementTotalFee(Integer settlementTotalFee) { + this.settlementTotalFee = settlementTotalFee; + } + + public String getFeeType() { + return feeType; + } + + public void setFeeType(String feeType) { + this.feeType = feeType; + } + + public Integer getCashFee() { + return cashFee; + } + + public void setCashFee(Integer cashFee) { + this.cashFee = cashFee; + } + + public String getCashFeeType() { + return cashFeeType; + } + + public void setCashFeeType(String cashFeeType) { + this.cashFeeType = cashFeeType; + } + + public Integer getCouponFee() { + return couponFee; + } + + public void setCouponFee(Integer couponFee) { + this.couponFee = couponFee; + } + + public String getTransactionId() { + return transactionId; + } + + public void setTransactionId(String transactionId) { + this.transactionId = transactionId; + } + + public String getOutTradeNo() { + return outTradeNo; + } + + public void setOutTradeNo(String outTradeNo) { + this.outTradeNo = outTradeNo; + } + + public String getAttach() { + return attach; + } + + public void setAttach(String attach) { + this.attach = attach; + } + + public String getTimeEnd() { + return timeEnd; + } + + public void setTimeEnd(String timeEnd) { + this.timeEnd = timeEnd; + } + + @Override + public Map toMap(){ + Map resultMap = BeanUtils.xmlBean2Map(this); + if(this.getCouponCount() != null && this.getCouponCount() > 0){ + for (int i = 0; i < this.getCouponCount(); i++) { + WxPayOrderNotifyCoupon coupon = couponList.get(i); + resultMap.putAll(coupon.toMap(i)); + } + } + return resultMap; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE); + } +} From cb6712065dca1b8817584a5f797732bd04acf14f Mon Sep 17 00:00:00 2001 From: Zhao Jingchen Date: Mon, 26 Dec 2016 19:27:59 +0800 Subject: [PATCH 40/80] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=8E=88=E6=9D=83=E6=8E=A5=E5=8F=A3=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=AD=97=E6=AE=B5=E7=BC=BA=E5=A4=B1=20=E5=8F=82?= =?UTF-8?q?=E8=A7=81=20http://iot.weixin.qq.com/wiki/new/index.html=3Fpage?= =?UTF-8?q?=3D3-4-5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/bean/device/WxDeviceAuthorize.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java index a37a8a420d..0318754e57 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java @@ -14,6 +14,8 @@ public class WxDeviceAuthorize extends AbstractDeviceBean { private String deviceNum; @SerializedName("op_type") private String opType; + @SerializedName("product_id") + private String productId; @SerializedName("device_list") private List deviceList = new LinkedList<>(); @@ -33,6 +35,14 @@ public void setOpType(String opType) { this.opType = opType; } + public String getProductId() { + return productId; + } + + public void setProductId(String productId) { + this.productId = productId; + } + public List getDeviceList() { return deviceList; } From 013da38f00757ff901f0d7214ae1f00c93b7b2a6 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 29 Dec 2016 19:00:32 +0800 Subject: [PATCH 41/80] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=B8=AD=E5=A2=9E=E5=8A=A0=E8=AF=81=E4=B9=A6=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E7=9A=84=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/mp/api/ApiTestModule.java | 5 ++-- .../src/test/resources/test-config.sample.xml | 27 ++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java index 2b749b9f09..13491d2097 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java @@ -15,10 +15,11 @@ public class ApiTestModule implements Module { @Override public void configure(Binder binder) { try (InputStream is1 = ClassLoader - .getSystemResourceAsStream("test-config.xml")) { + .getSystemResourceAsStream("test-config.xml")) { WxXmlMpInMemoryConfigStorage config = this - .fromXml(WxXmlMpInMemoryConfigStorage.class, is1); + .fromXml(WxXmlMpInMemoryConfigStorage.class, is1); config.setAccessTokenLock(new ReentrantLock()); + config.setSslContextFilePath(config.getKeyPath()); WxMpService wxService = new WxMpServiceImpl(); wxService.setWxMpConfigStorage(config); diff --git a/weixin-java-mp/src/test/resources/test-config.sample.xml b/weixin-java-mp/src/test/resources/test-config.sample.xml index 2bbc8d8e33..3df1de9d57 100644 --- a/weixin-java-mp/src/test/resources/test-config.sample.xml +++ b/weixin-java-mp/src/test/resources/test-config.sample.xml @@ -1,15 +1,16 @@ - 公众号appID - 公众号appsecret - 公众号Token - 公众号EncodingAESKey - 可以不填写 - 可以不填写 - 某个加你公众号的用户的openId - 微信商户平台ID - 商户平台设置的API密钥 - 模版消息的模版ID - 网页授权获取用户信息回调地址 - 网页应用授权登陆回调地址 - 完整客服账号,格式为:账号前缀@公众号微信号 + 公众号appID + 公众号appsecret + 公众号Token + 公众号EncodingAESKey + 可以不填写 + 可以不填写 + 某个加你公众号的用户的openId + 微信商户平台ID + 商户平台设置的API密钥 + 商户平台的证书文件地址 + 模版消息的模版ID + 网页授权获取用户信息回调地址 + 网页应用授权登陆回调地址 + 完整客服账号,格式为:账号前缀@公众号微信号 From a638189ec823321049b83e7c9be8501fbb9c5d87 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 29 Dec 2016 19:02:20 +0800 Subject: [PATCH 42/80] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=B8=AD=E5=A2=9E=E5=8A=A0=E8=AF=81=E4=B9=A6=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E7=9A=84=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxXmlMpInMemoryConfigStorage.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java index 75494efeaf..1ab04cf101 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java @@ -14,6 +14,16 @@ public class WxXmlMpInMemoryConfigStorage private String qrconnectRedirectUrl; private String templateId; + public String getKeyPath() { + return keyPath; + } + + public void setKeyPath(String keyPath) { + this.keyPath = keyPath; + } + + private String keyPath; + public String getOpenid() { return this.openid; } From 22723f9f2bc7f51d2950719e6cc4e177d00ecbcb Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 29 Dec 2016 19:05:21 +0800 Subject: [PATCH 43/80] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=80=80=E6=AC=BE=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=B9=B6=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E9=83=A8=E5=88=86=E6=94=AF=E4=BB=98=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E7=8E=B0=EF=BC=8C=E7=AE=80=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- weixin-java-mp/pom.xml | 140 +++++++++--------- .../mp/api/WxMpInMemoryConfigStorage.java | 21 ++- .../mp/api/impl/WxMpPayServiceImpl.java | 119 +++++---------- .../mp/bean/pay/request/WxPayBaseRequest.java | 30 ++-- .../bean/pay/request/WxPayRefundRequest.java | 4 +- .../mp/bean/pay/result/WxPayBaseResult.java | 107 ++++++++++--- .../pay/result/WxPayOrderNotifyResult.java | 17 ++- .../pay/result/WxPayRefundQueryResult.java | 71 +++++++-- .../mp/api/impl/WxMpPayServiceImplTest.java | 3 - .../result/WxPayRefundQueryResultTest.java | 49 ++++++ 10 files changed, 351 insertions(+), 210 deletions(-) create mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index 9db06d7ab3..abde021509 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -1,73 +1,79 @@ - 4.0.0 - - com.github.binarywang - weixin-java-parent - 2.4.6.BETA - - weixin-java-mp - WeiXin Java Tools - MP - 微信公众号Java SDK + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"> + 4.0.0 + + com.github.binarywang + weixin-java-parent + 2.4.6.BETA + + weixin-java-mp + WeiXin Java Tools - MP + 微信公众号Java SDK - - - com.github.binarywang - weixin-java-common - ${project.version} - - - junit - junit - test - - - org.testng - testng - test - - - org.mockito - mockito-all - test - - - com.google.inject - guice - test - - - org.eclipse.jetty - jetty-server - test - - - org.eclipse.jetty - jetty-servlet - test - - - joda-time - joda-time - 2.9.4 - test - - + + + com.github.binarywang + weixin-java-common + ${project.version} + + + junit + junit + test + + + org.testng + testng + test + + + org.mockito + mockito-all + test + + + com.google.inject + guice + test + + + org.eclipse.jetty + jetty-server + test + + + org.eclipse.jetty + jetty-servlet + test + + + joda-time + joda-time + 2.9.4 + test + + + io.rest-assured + xml-path + 3.0.1 + - - - - org.apache.maven.plugins - maven-surefire-plugin - - - src/test/resources/testng.xml - - - - - + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/resources/testng.xml + + + + + diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java index 5172a5d76a..29fbed63c6 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java @@ -310,20 +310,25 @@ public void setSslContext(SSLContext context) { } @Override - public void setSslContextFilePath(String filePath) throws Exception { + public void setSslContextFilePath(String filePath) { if (null == partnerId) { - throw new Exception("请先将partnerId进行赋值"); + throw new IllegalArgumentException("请设置partnerId的值"); } File file = new File(filePath); if (!file.exists()) { - throw new RuntimeException(file.getPath() + ":文件不存在!在设置SSLContext的时候"); + throw new RuntimeException("证书文件:【" + file.getPath() + "】不存在!"); + } + + try { + FileInputStream inputStream = new FileInputStream(file); + KeyStore keystore = KeyStore.getInstance("PKCS12"); + char[] partnerId2charArray = partnerId.toCharArray(); + keystore.load(inputStream, partnerId2charArray); + this.sslContext = SSLContexts.custom().loadKeyMaterial(keystore, partnerId2charArray).build(); + } catch (Exception e) { + throw new RuntimeException("证书文件有问题,请核实!", e); } - FileInputStream inputStream = new FileInputStream(file); - KeyStore keystore = KeyStore.getInstance("PKCS12"); - char[] partnerId2charArray = partnerId.toCharArray(); - keystore.load(inputStream, partnerId2charArray); - this.sslContext = SSLContexts.custom().loadKeyMaterial(keystore, partnerId2charArray).build(); } @Override 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 8ad6ed35bc..6ab639f1dc 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,14 +1,11 @@ package me.chanjar.weixin.mp.api.impl; -import com.thoughtworks.xstream.XStream; import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.BeanUtils; -import me.chanjar.weixin.common.util.xml.XStreamInitializer; import me.chanjar.weixin.mp.api.WxMpConfigStorage; import me.chanjar.weixin.mp.api.WxMpPayService; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.bean.pay.WxPayOrderNotifyResultConverter; import me.chanjar.weixin.mp.bean.pay.request.*; import me.chanjar.weixin.mp.bean.pay.result.*; import org.apache.commons.codec.digest.DigestUtils; @@ -54,20 +51,16 @@ private WxMpConfigStorage getConfig() { @Override public WxPayRefundResult refund(WxPayRefundRequest request) throws WxErrorException { - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPayRefundRequest.class); - xstream.processAnnotations(WxPayRefundResult.class); - - initRequest(request); + this.initRequest(request); if (StringUtils.isBlank(request.getOpUserId())) { - request.setOpUserId(getConfig().getPartnerId()); + request.setOpUserId(this.getConfig().getPartnerId()); } - checkParameters(request); + this.checkParameters(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/secapi/pay/refund"; - String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); - WxPayRefundResult result = (WxPayRefundResult) xstream.fromXML(responseContent); + String responseContent = this.executeWithKey(url, request.toXML()); + WxPayRefundResult result = WxPayRefundResult.fromXML(responseContent, WxPayRefundResult.class); this.checkResult(result); return result; } @@ -79,12 +72,8 @@ public WxPayRefundQueryResult refundQuery(String transactionId, String outTradeN throw new IllegalArgumentException("transaction_id , out_trade_no,out_refund_no, refund_id 必须四选一"); } - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPayRefundQueryRequest.class); - xstream.processAnnotations(WxPayRefundQueryResult.class); - WxPayRefundQueryRequest request = new WxPayRefundQueryRequest(); - initRequest(request); + this.initRequest(request); request.setOutTradeNo(StringUtils.trimToNull(outTradeNo)); request.setTransactionId(StringUtils.trimToNull(transactionId)); request.setOutRefundNo(StringUtils.trimToNull(outRefundNo)); @@ -92,8 +81,8 @@ public WxPayRefundQueryResult refundQuery(String transactionId, String outTradeN request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/pay/refundquery"; - String responseContent = this.executeRequest(url, xstream.toXML(request)); - WxPayRefundQueryResult result = (WxPayRefundQueryResult) xstream.fromXML(responseContent); + String responseContent = this.executeRequest(url, request.toXML()); + WxPayRefundQueryResult result = WxPayRefundQueryResult.fromXML(responseContent, WxPayRefundQueryResult.class); result.composeRefundRecords(responseContent); this.checkResult(result); return result; @@ -102,8 +91,9 @@ public WxPayRefundQueryResult refundQuery(String transactionId, String outTradeN private void checkResult(WxPayBaseResult result) throws WxErrorException { //校验返回结果签名 - if (!checkSign(result.toMap())) { - log.debug("校验结果签名失败,参数:{}", result.toMap()); + Map map = result.toMap(); + if (!this.checkSign(map)) { + log.debug("校验结果签名失败,参数:{}", map); throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("参数格式校验错误!").build()); } @@ -115,7 +105,7 @@ private void checkResult(WxPayBaseResult result) throws WxErrorException { + result.getReturnMsg() + ", 结果代码: " + result.getResultCode() + ", 错误代码: " + result.getErrCode() + ", 错误详情: " + result.getErrCodeDes()) .build(); - log.error("结果业务代码异常,参数:{},详细:{}", result.toMap(), error); + log.error("结果业务代码异常,参数:{},详细:{}", map, error); throw new WxErrorException(error); } } @@ -138,10 +128,7 @@ private void checkParameters(WxPayRefundRequest request) throws WxErrorException public WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxErrorException { try { log.trace("微信支付回调参数详细:{}", xmlData); - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPayOrderNotifyResult.class); - xstream.registerConverter(new WxPayOrderNotifyResultConverter(xstream.getMapper(), xstream.getReflectionProvider())); - WxPayOrderNotifyResult result = (WxPayOrderNotifyResult) xstream.fromXML(xmlData); + WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlData); log.debug("微信支付回调结果对象:{}", result); this.checkResult(result); return result; @@ -157,11 +144,7 @@ public WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxErro @Override public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxErrorException { - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPaySendRedpackRequest.class); - xstream.processAnnotations(WxPaySendRedpackResult.class); - - initRequest(request); + this.initRequest(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/sendredpack"; @@ -169,18 +152,14 @@ public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) //裂变红包 url = PAY_BASE_URL + "/mmpaymkttransfers/sendgroupredpack"; } - String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); - WxPaySendRedpackResult result = (WxPaySendRedpackResult) xstream.fromXML(responseContent); + String responseContent = this.executeWithKey(url, request.toXML()); + WxPaySendRedpackResult result = WxPaySendRedpackResult.fromXML(responseContent, WxPaySendRedpackResult.class); this.checkResult(result); return result; } @Override public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxErrorException { - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPayRedpackQueryRequest.class); - xstream.processAnnotations(WxPayRedpackQueryResult.class); - WxPayRedpackQueryRequest request = new WxPayRedpackQueryRequest(); request.setMchBillNo(mchBillNo); request.setBillType("MCHT"); @@ -188,8 +167,8 @@ public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxErrorExce request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/gethbinfo"; - String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); - WxPayRedpackQueryResult result = (WxPayRedpackQueryResult) xstream.fromXML(responseContent); + String responseContent = this.executeWithKey(url, request.toXML()); + WxPayRedpackQueryResult result = WxPayRedpackQueryResult.fromXML(responseContent, WxPayRedpackQueryResult.class); this.checkResult(result); return result; } @@ -201,10 +180,6 @@ public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throw new IllegalArgumentException("transaction_id 和 out_trade_no 不能同时存在或同时为空,必须二选一"); } - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPayOrderQueryRequest.class); - xstream.processAnnotations(WxPayOrderQueryResult.class); - WxPayOrderQueryRequest request = new WxPayOrderQueryRequest(); request.setOutTradeNo(StringUtils.trimToNull(outTradeNo)); request.setTransactionId(StringUtils.trimToNull(transactionId)); @@ -212,8 +187,8 @@ public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/pay/orderquery"; - String responseContent = this.executeRequest(url, xstream.toXML(request)); - WxPayOrderQueryResult result = (WxPayOrderQueryResult) xstream.fromXML(responseContent); + String responseContent = this.executeRequest(url, request.toXML()); + WxPayOrderQueryResult result = WxPayOrderQueryResult.fromXML(responseContent, WxPayOrderQueryResult.class); result.composeCoupons(responseContent); this.checkResult(result); return result; @@ -225,18 +200,14 @@ public WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxErrorExcepti throw new IllegalArgumentException("out_trade_no 不能为空"); } - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPayOrderCloseRequest.class); - xstream.processAnnotations(WxPayOrderCloseResult.class); - WxPayOrderCloseRequest request = new WxPayOrderCloseRequest(); request.setOutTradeNo(StringUtils.trimToNull(outTradeNo)); initRequest(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/pay/closeorder"; - String responseContent = this.executeRequest(url, xstream.toXML(request)); - WxPayOrderCloseResult result = (WxPayOrderCloseResult) xstream.fromXML(responseContent); + String responseContent = this.executeRequest(url, request.toXML()); + WxPayOrderCloseResult result = WxPayOrderCloseResult.fromXML(responseContent, WxPayOrderCloseResult.class); this.checkResult(result); return result; @@ -246,11 +217,7 @@ public WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxErrorExcepti public WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) throws WxErrorException { - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPayUnifiedOrderRequest.class); - xstream.processAnnotations(WxPayUnifiedOrderResult.class); - - initRequest(request); + this.initRequest(request); if (StringUtils.isBlank(request.getNotifyURL())) { request.setNotifyURL(getConfig().getNotifyURL()); } @@ -261,12 +228,12 @@ public WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/pay/unifiedorder"; - String xmlParam = xstream.toXML(request); + String xmlParam = request.toXML(); log.debug("微信统一下单接口,URL:{},参数:{}", url, xmlParam); String responseContent = this.executeRequest(url, xmlParam); log.debug("微信统一下单接口,URL:{},结果:{}", url, responseContent); - WxPayUnifiedOrderResult result = (WxPayUnifiedOrderResult) xstream.fromXML(responseContent); + WxPayUnifiedOrderResult result = WxPayUnifiedOrderResult.fromXML(responseContent, WxPayUnifiedOrderResult.class); this.checkResult(result); return result; } @@ -324,35 +291,27 @@ public Map getPayInfo(WxPayUnifiedOrderRequest request) throws W @Override public WxEntPayResult entPay(WxEntPayRequest request) throws WxErrorException { - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxEntPayRequest.class); - xstream.processAnnotations(WxEntPayResult.class); - - initRequest(request); + this.initRequest(request); BeanUtils.checkRequiredFields(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/promotion/transfers"; - String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); - WxEntPayResult result = (WxEntPayResult) xstream.fromXML(responseContent); + String responseContent = this.executeWithKey(url, request.toXML()); + WxEntPayResult result = WxEntPayResult.fromXML(responseContent, WxEntPayResult.class); this.checkResult(result); return result; } @Override public WxEntPayQueryResult queryEntPay(String partnerTradeNo) throws WxErrorException { - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxEntPayQueryRequest.class); - xstream.processAnnotations(WxEntPayQueryResult.class); - WxEntPayQueryRequest request = new WxEntPayQueryRequest(); - initRequest(request); + this.initRequest(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/gettransferinfo"; - String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); - WxEntPayQueryResult result = (WxEntPayQueryResult) xstream.fromXML(responseContent); + String responseContent = this.executeWithKey(url, request.toXML()); + WxEntPayQueryResult result = WxEntPayQueryResult.fromXML(responseContent, WxEntPayQueryResult.class); this.checkResult(result); return result; } @@ -379,11 +338,11 @@ private String executeRequest(String url, String requestStr) throws WxErrorExcep } } - private String executeRequestWithKeyFile(String url, String requestStr) throws WxErrorException { + private String executeWithKey(String url, String requestStr) throws WxErrorException { try { SSLContext sslContext = getConfig().getSslContext(); if (null == sslContext) { - throw new Exception("请将配置类(即WxMpConfigStorage的实现类)中的SSLContext初始化"); + throw new IllegalArgumentException("请先初始化配置类(即WxMpConfigStorage的实现类)中的SSLContext!"); } SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[]{"TLSv1"}, null, @@ -412,17 +371,17 @@ private String executeRequestWithKeyFile(String url, String requestStr) throws W @Override public String createSign(Object xmlBean) { - return createSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey()); + return this.createSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey()); } @Override public String createSign(Object xmlBean, String signKey) { - return createSign(BeanUtils.xmlBean2Map(xmlBean), signKey); + return this.createSign(BeanUtils.xmlBean2Map(xmlBean), signKey); } @Override public String createSign(Map params) { - return createSign(params, getConfig().getPartnerKey()); + return this.createSign(params, this.getConfig().getPartnerKey()); } @Override @@ -443,17 +402,17 @@ public String createSign(Map params, String signKey) { @Override public boolean checkSign(Object xmlBean) { - return checkSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey()); + return this.checkSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey()); } @Override public boolean checkSign(Object xmlBean, String signKey) { - return checkSign(BeanUtils.xmlBean2Map(xmlBean), signKey); + return this.checkSign(BeanUtils.xmlBean2Map(xmlBean), signKey); } @Override public boolean checkSign(Map params) { - return checkSign(params, getConfig().getPartnerKey()); + return this.checkSign(params, getConfig().getPartnerKey()); } @Override diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java index 3bfe556f4f..c13f1b8fcb 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java @@ -1,7 +1,9 @@ package me.chanjar.weixin.mp.bean.pay.request; +import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.XStreamAlias; import me.chanjar.weixin.common.util.ToStringUtils; +import me.chanjar.weixin.common.util.xml.XStreamInitializer; import java.math.BigDecimal; @@ -17,6 +19,7 @@ *
  • 示例值 *
  • 描述 *
  • + * * @author binarywang(Binary Wang) */ public abstract class WxPayBaseRequest { @@ -69,12 +72,22 @@ public abstract class WxPayBaseRequest { @XStreamAlias("sign") protected String sign; + /** + * 将单位为元转换为单位为分 + * + * @param yuan 将要转换的元的数值字符串 + */ + public static Integer yuanToFee(String yuan) { + return new BigDecimal(yuan).setScale(2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).intValue(); + } + public String getAppid() { return this.appid; } /** * 如果配置中已经设置,可以不设置值 + * * @param appid 微信公众号appid */ public void setAppid(String appid) { @@ -87,6 +100,7 @@ public String getMchId() { /** * 如果配置中已经设置,可以不设置值 + * * @param mchId 微信商户号 */ public void setMchId(String mchId) { @@ -99,6 +113,7 @@ public String getNonceStr() { /** * 默认采用时间戳为随机字符串,可以不设置 + * * @param nonceStr 随机字符串 */ public void setNonceStr(String nonceStr) { @@ -113,17 +128,14 @@ public void setSign(String sign) { this.sign = sign; } - /** - * 将单位为元转换为单位为分 - * - * @param yuan 将要转换的元的数值字符串 - */ - public static Integer yuanToFee(String yuan) { - return new BigDecimal(yuan).setScale(2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).intValue(); - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); } + + public String toXML() { + XStream xstream = XStreamInitializer.getInstance(); + xstream.processAnnotations(this.getClass()); + return xstream.toXML(this); + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayRefundRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayRefundRequest.java index 66ba5d347e..22bc6ae22d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayRefundRequest.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayRefundRequest.java @@ -1,7 +1,6 @@ package me.chanjar.weixin.mp.bean.pay.request; import com.thoughtworks.xstream.annotations.XStreamAlias; - import me.chanjar.weixin.common.annotation.Required; /** @@ -144,8 +143,6 @@ public class WxPayRefundRequest extends WxPayBaseRequest { @XStreamAlias("refund_account") private String refundAccount; - - public String getDeviceInfo() { return this.deviceInfo; } @@ -217,4 +214,5 @@ public String getRefundAccount() { public void setRefundAccount(String refundAccount) { this.refundAccount = refundAccount; } + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java index cafd8a5687..b06f3cca14 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java @@ -1,10 +1,19 @@ package me.chanjar.weixin.mp.bean.pay.result; +import com.google.common.collect.Maps; +import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.XStreamAlias; -import me.chanjar.weixin.common.util.BeanUtils; +import io.restassured.internal.path.xml.NodeChildrenImpl; +import io.restassured.path.xml.XmlPath; +import io.restassured.path.xml.element.Node; +import io.restassured.path.xml.element.NodeChildren; import me.chanjar.weixin.common.util.ToStringUtils; +import me.chanjar.weixin.common.util.xml.XStreamInitializer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.math.BigDecimal; +import java.util.Iterator; import java.util.Map; /** @@ -15,65 +24,90 @@ *
    */ public abstract class WxPayBaseResult { - @Override - public String toString() { - return ToStringUtils.toSimpleString(this); - } - /** * 返回状态码 */ @XStreamAlias("return_code") protected String returnCode; - /** * 返回信息 */ @XStreamAlias("return_msg") protected String returnMsg; - + private String xmlString; /** * 业务结果 */ @XStreamAlias("result_code") private String resultCode; - /** * 错误代码 */ @XStreamAlias("err_code") private String errCode; - /** * 错误代码描述 */ @XStreamAlias("err_code_des") private String errCodeDes; - /** * 公众账号ID */ @XStreamAlias("appid") private String appid; - /** * 商户号 */ @XStreamAlias("mch_id") private String mchId; - /** * 随机字符串 */ @XStreamAlias("nonce_str") private String nonceStr; - /** * 签名 */ @XStreamAlias("sign") private String sign; + /** + * 将单位分转换成单位圆 + * + * @param fee 将要被转换为元的分的数值 + */ + public static String feeToYuan(Integer fee) { + return new BigDecimal(Double.valueOf(fee) / 100).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString(); + } + + /** + * 从xml字符串创建bean对象 + */ + public static T fromXML(String xmlString, Class clz) { + XStream xstream = XStreamInitializer.getInstance(); + xstream.processAnnotations(clz); + T result = (T) xstream.fromXML(xmlString); + result.setXmlString(xmlString); + return result; + } + + public String getXmlString() { + return this.xmlString; + } + + public void setXmlString(String xmlString) { + this.xmlString = xmlString; + } + + protected Logger getLogger() { + return LoggerFactory.getLogger(this.getClass()); + } + + @Override + public String toString() { + return ToStringUtils.toSimpleString(this); + } + public String getReturnCode() { return this.returnCode; } @@ -147,14 +181,43 @@ public void setSign(String sign) { } /** - * 将单位分转换成单位圆 - * @param fee 将要被转换为元的分的数值 + * 将bean通过保存的xml字符串转换成map */ - public static String feeToYuan(Integer fee) { - return new BigDecimal(Double.valueOf(fee) / 100).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString(); - } - - public Map toMap(){ - return BeanUtils.xmlBean2Map(this); + public Map toMap() { + Map result = Maps.newHashMap(); + XmlPath xmlPath = new XmlPath(this.xmlString); + NodeChildren nodeChildren = xmlPath.getNodeChildren("xml"); + Iterator iterator = nodeChildren.nodeIterator(); + while (iterator.hasNext()) { + Node node = iterator.next(); + result.put(node.name(), node.value()); + } + return result; + } + + private String getXmlValueIfExists(XmlPath xmlPath, String path) { + if (xmlPath.get(path) instanceof NodeChildrenImpl) { + if (((NodeChildrenImpl) xmlPath.get(path)).size() == 0) { + return null; + } + } + + return xmlPath.getString(path); + } + + protected T getXmlValueIfExists(XmlPath xmlPath, String path, Class clz) { + String value = this.getXmlValueIfExists(xmlPath, path); + if (value == null) { + return null; + } + + switch (clz.getSimpleName()) { + case "String": + return (T) value; + case "Integer": + return (T) Integer.valueOf(value); + } + + throw new UnsupportedOperationException("暂时不支持此种类型的数据"); } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java index a5770873da..1cf783a891 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java @@ -1,10 +1,12 @@ package me.chanjar.weixin.mp.bean.pay.result; +import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.XStreamAlias; import me.chanjar.weixin.common.util.BeanUtils; +import me.chanjar.weixin.common.util.ToStringUtils; +import me.chanjar.weixin.common.util.xml.XStreamInitializer; import me.chanjar.weixin.mp.bean.pay.WxPayOrderNotifyCoupon; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; +import me.chanjar.weixin.mp.bean.pay.WxPayOrderNotifyResultConverter; import java.io.Serializable; import java.util.List; @@ -376,6 +378,15 @@ public Map toMap(){ @Override public String toString() { - return ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE); + return ToStringUtils.toSimpleString(this); } + + public static WxPayOrderNotifyResult fromXML(String xmlString) { + XStream xstream = XStreamInitializer.getInstance(); + xstream.processAnnotations(WxPayOrderNotifyResult.class); + xstream.registerConverter(new WxPayOrderNotifyResultConverter(xstream.getMapper(), xstream.getReflectionProvider())); + WxPayOrderNotifyResult result = (WxPayOrderNotifyResult) xstream.fromXML(xmlString); + result.setXmlString(xmlString); + return result; + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java index 430288466a..146c35dfad 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java @@ -2,6 +2,7 @@ import com.google.common.collect.Lists; import com.thoughtworks.xstream.annotations.XStreamAlias; +import io.restassured.path.xml.XmlPath; import java.util.List; @@ -186,7 +187,38 @@ public void setRefundRecords(List refundRecords) { public void composeRefundRecords(String xmlString) { if (this.refundCount != null && this.refundCount > 0) { this.refundRecords = Lists.newArrayList(); - //TODO 暂时待实现 + XmlPath xmlPath = new XmlPath(xmlString); + + for (int i = 0; i < this.refundCount; i++) { + RefundRecord refundRecord = new RefundRecord(); + this.refundRecords.add(refundRecord); + + refundRecord.setOutRefundNo(this.getXmlValueIfExists(xmlPath, "xml.out_refund_no_" + i, String.class)); + refundRecord.setRefundId(this.getXmlValueIfExists(xmlPath, "xml.refund_id_" + i, String.class)); + refundRecord.setRefundChannel(this.getXmlValueIfExists(xmlPath, "xml.refund_channel_" + i, String.class)); + refundRecord.setRefundFee(this.getXmlValueIfExists(xmlPath, "xml.refund_fee_" + i, Integer.class)); + refundRecord.setSettlementRefundFee(this.getXmlValueIfExists(xmlPath, "xml.settlement_refund_fee_" + i, Integer.class)); + refundRecord.setCouponType(this.getXmlValueIfExists(xmlPath, "xml.coupon_type_" + i, String.class)); + refundRecord.setCouponRefundFee(this.getXmlValueIfExists(xmlPath, "xml.coupon_refund_fee_" + i, Integer.class)); + refundRecord.setCouponRefundCount(this.getXmlValueIfExists(xmlPath, "xml.coupon_refund_count_" + i, Integer.class)); + refundRecord.setRefundStatus(this.getXmlValueIfExists(xmlPath, "xml.refund_status_" + i, String.class)); + refundRecord.setRefundRecvAccout(this.getXmlValueIfExists(xmlPath, "xml.refund_recv_accout_" + i, String.class)); + + if (refundRecord.getCouponRefundCount() == null || refundRecord.getCouponRefundCount() == 0) { + continue; + } + + List coupons = Lists.newArrayList(); + for (int j = 0; j < refundRecord.getCouponRefundCount(); j++) { + coupons.add( + new RefundRecord.RefundCoupon( + this.getXmlValueIfExists(xmlPath, "xml.coupon_refund_id_" + i + "_" + j, String.class), + this.getXmlValueIfExists(xmlPath, "xml.coupon_refund_fee_" + i + "_" + j, Integer.class) + ) + ); + } + } + } } @@ -241,7 +273,7 @@ public static class RefundRecord { *
    */ @XStreamAlias("refund_fee") - private String refundFee; + private Integer refundFee; /** *
    @@ -254,7 +286,7 @@ public static class RefundRecord {
          * 
    */ @XStreamAlias("settlement_refund_fee") - private String settlementRefundFee; + private Integer settlementRefundFee; /** *
    @@ -293,7 +325,7 @@ public static class RefundRecord {
          * 
    */ @XStreamAlias("coupon_refund_fee") - private String couponRefundFee; + private Integer couponRefundFee; /** *
    @@ -306,7 +338,7 @@ public static class RefundRecord {
          * 
    */ @XStreamAlias("coupon_refund_count") - private String couponRefundCount; + private Integer couponRefundCount; private List refundCoupons; @@ -364,19 +396,19 @@ public void setRefundChannel(String refundChannel) { this.refundChannel = refundChannel; } - public String getRefundFee() { + public Integer getRefundFee() { return refundFee; } - public void setRefundFee(String refundFee) { + public void setRefundFee(Integer refundFee) { this.refundFee = refundFee; } - public String getSettlementRefundFee() { + public Integer getSettlementRefundFee() { return settlementRefundFee; } - public void setSettlementRefundFee(String settlementRefundFee) { + public void setSettlementRefundFee(Integer settlementRefundFee) { this.settlementRefundFee = settlementRefundFee; } @@ -396,19 +428,19 @@ public void setCouponType(String couponType) { this.couponType = couponType; } - public String getCouponRefundFee() { + public Integer getCouponRefundFee() { return couponRefundFee; } - public void setCouponRefundFee(String couponRefundFee) { + public void setCouponRefundFee(Integer couponRefundFee) { this.couponRefundFee = couponRefundFee; } - public String getCouponRefundCount() { + public Integer getCouponRefundCount() { return couponRefundCount; } - public void setCouponRefundCount(String couponRefundCount) { + public void setCouponRefundCount(Integer couponRefundCount) { this.couponRefundCount = couponRefundCount; } @@ -446,6 +478,8 @@ public static class RefundCoupon { * 100 * 退款代金券批次ID ,$n为下标,$m为下标,从0开始编号 *
    + * + * @deprecated 貌似是被去掉了,但不知是何时! */ @XStreamAlias("coupon_refund_batch_id") private String couponRefundBatchId; @@ -474,9 +508,15 @@ public static class RefundCoupon { *
    */ @XStreamAlias("coupon_refund_fee") - private String couponRefundFee; + private Integer couponRefundFee; - public RefundCoupon(String couponRefundBatchId, String couponRefundId, String couponRefundFee) { + public RefundCoupon(String couponRefundId, Integer couponRefundFee) { + this.couponRefundId = couponRefundId; + this.couponRefundFee = couponRefundFee; + } + + @Deprecated + public RefundCoupon(String couponRefundBatchId, String couponRefundId, Integer couponRefundFee) { this.couponRefundBatchId = couponRefundBatchId; this.couponRefundId = couponRefundId; this.couponRefundFee = couponRefundFee; @@ -484,5 +524,6 @@ public RefundCoupon(String couponRefundBatchId, String couponRefundId, String co } } + } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index 31fc0c06d6..418b710bae 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -13,8 +13,6 @@ import org.testng.annotations.Guice; import org.testng.annotations.Test; -import java.io.File; - /** * 测试支付相关接口 * Created by Binary Wang on 2016/7/28. @@ -90,7 +88,6 @@ public void testSendRedpack() throws Exception { */ @Test public void testQueryRedpack() throws Exception { - File keyFile = new File("E:\\dlt.p12"); WxPayRedpackQueryResult redpackResult = this.wxService.getPayService().queryRedpack("aaaa"); System.err.println(redpackResult); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java new file mode 100644 index 0000000000..9427bd0109 --- /dev/null +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java @@ -0,0 +1,49 @@ +package me.chanjar.weixin.mp.bean.pay.result; + + +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + *
    + * Created by Binary Wang on 2016-12-29.
    + * @author binarywang(Binary Wang)
    + * 
    + */ +public class WxPayRefundQueryResultTest { + @Test + public void composeRefundRecords() throws Exception { + /* + 该xml字符串来自于官方文档示例 + */ + String xmlString = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 1\n" + + " 1\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + WxPayRefundQueryResult result = new WxPayRefundQueryResult(); + result.setRefundCount(1); + result.composeRefundRecords(xmlString); + + Assert.assertNotNull(result.getRefundRecords()); + Assert.assertEquals(result.getRefundRecords().size(), 1); + Assert.assertEquals(result.getRefundRecords().get(0).getRefundId(), "2008450740201411110000174436"); + Assert.assertEquals(result.getRefundRecords().get(0).getRefundFee().intValue(), 1); + Assert.assertEquals(result.getRefundRecords().get(0).getOutRefundNo(), "1415701182"); + Assert.assertEquals(result.getRefundRecords().get(0).getRefundStatus(), "PROCESSING"); + + } + +} From 96d4597e0fb3f0c06d485a3b9536480854fdf025 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 29 Dec 2016 19:54:45 +0800 Subject: [PATCH 44/80] release 2.4.7.BETA --- pom.xml | 2 +- weixin-java-common/pom.xml | 2 +- weixin-java-cp/pom.xml | 2 +- weixin-java-mp/pom.xml | 2 +- weixin-java-osgi/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 24e46e3951..a8f2f42456 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.github.binarywang weixin-java-parent - 2.4.6.BETA + 2.4.7.BETA pom WeiXin Java Tools - Parent 微信公众号、企业号上级POM diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml index 5b55b6afb4..8f78458dfa 100644 --- a/weixin-java-common/pom.xml +++ b/weixin-java-common/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.6.BETA + 2.4.7.BETA weixin-java-common diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index 3b8072c696..2adec10e3e 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.6.BETA + 2.4.7.BETA weixin-java-cp diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index abde021509..335fe3a3b0 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.6.BETA + 2.4.7.BETA weixin-java-mp WeiXin Java Tools - MP diff --git a/weixin-java-osgi/pom.xml b/weixin-java-osgi/pom.xml index 8667d33036..ee96e71f89 100644 --- a/weixin-java-osgi/pom.xml +++ b/weixin-java-osgi/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.6.BETA + 2.4.7.BETA weixin-java-osgi From 0350182db137c540528fe2b8be430a854fe06599 Mon Sep 17 00:00:00 2001 From: cty Date: Wed, 7 Dec 2016 11:43:17 +0800 Subject: [PATCH 45/80] =?UTF-8?q?oauth2=E8=AE=A4=E8=AF=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=BF=94=E5=9B=9E=E5=80=BC=E4=B8=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?openid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java index a2bd365912..8d0c47daae 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java @@ -491,7 +491,7 @@ public String[] oauth2getUserInfo(Integer agentId, String code) throws WxErrorEx String responseText = get(url, null); JsonElement je = new JsonParser().parse(responseText); JsonObject jo = je.getAsJsonObject(); - return new String[]{GsonHelper.getString(jo, "UserId"), GsonHelper.getString(jo, "DeviceId")}; + return new String[]{GsonHelper.getString(jo, "UserId"), GsonHelper.getString(jo, "DeviceId"), GsonHelper.getString(jo, "OpenId")}; } @Override From 2e3a33a74e55ef87c3ca4cf0fdac2f5119e1cd63 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 3 Jan 2017 11:02:53 +0800 Subject: [PATCH 46/80] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=90=8D=EF=BC=8C=E4=BF=9D=E6=8C=81=E8=B7=9Fset=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/impl/WxMpServiceImpl.java | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) 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 d2aa2a2c44..2d250035c8 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 @@ -37,7 +37,7 @@ public class WxMpServiceImpl implements WxMpService { protected final Logger log = LoggerFactory.getLogger(this.getClass()); protected WxSessionManager sessionManager = new StandardSessionManager(); - private WxMpConfigStorage configStorage; + private WxMpConfigStorage wxMpConfigStorage; private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this); private WxMpMaterialService materialService = new WxMpMaterialServiceImpl(this); private WxMpMenuService menuService = new WxMpMenuServiceImpl(this); @@ -59,7 +59,7 @@ public class WxMpServiceImpl implements WxMpService { @Override public boolean checkSignature(String timestamp, String nonce, String signature) { try { - return SHA1.gen(this.configStorage.getToken(), timestamp, nonce) + return SHA1.gen(this.wxMpConfigStorage.getToken(), timestamp, nonce) .equals(signature); } catch (Exception e) { return false; @@ -73,18 +73,18 @@ public String getAccessToken() throws WxErrorException { @Override public String getAccessToken(boolean forceRefresh) throws WxErrorException { - Lock lock = this.configStorage.getAccessTokenLock(); + Lock lock = this.wxMpConfigStorage.getAccessTokenLock(); try { lock.lock(); if (forceRefresh) { - this.configStorage.expireAccessToken(); + this.wxMpConfigStorage.expireAccessToken(); } - if (this.configStorage.isAccessTokenExpired()) { + if (this.wxMpConfigStorage.isAccessTokenExpired()) { String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential" + - "&appid=" + this.configStorage.getAppId() + "&secret=" - + this.configStorage.getSecret(); + "&appid=" + this.wxMpConfigStorage.getAppId() + "&secret=" + + this.wxMpConfigStorage.getSecret(); try { HttpGet httpGet = new HttpGet(url); if (this.httpProxy != null) { @@ -98,7 +98,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException { throw new WxErrorException(error); } WxAccessToken accessToken = WxAccessToken.fromJson(resultContent); - this.configStorage.updateAccessToken(accessToken.getAccessToken(), + this.wxMpConfigStorage.updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn()); } finally { httpGet.releaseConnection(); @@ -110,7 +110,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException { } finally { lock.unlock(); } - return this.configStorage.getAccessToken(); + return this.wxMpConfigStorage.getAccessToken(); } @Override @@ -120,27 +120,27 @@ public String getJsapiTicket() throws WxErrorException { @Override public String getJsapiTicket(boolean forceRefresh) throws WxErrorException { - Lock lock = this.configStorage.getJsapiTicketLock(); + Lock lock = this.wxMpConfigStorage.getJsapiTicketLock(); try { lock.lock(); if (forceRefresh) { - this.configStorage.expireJsapiTicket(); + this.wxMpConfigStorage.expireJsapiTicket(); } - if (this.configStorage.isJsapiTicketExpired()) { + if (this.wxMpConfigStorage.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.configStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds); + this.wxMpConfigStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds); } } finally { lock.unlock(); } - return this.configStorage.getJsapiTicket(); + return this.wxMpConfigStorage.getJsapiTicket(); } @Override @@ -151,7 +151,7 @@ public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException String signature = SHA1.genWithAmple("jsapi_ticket=" + jsapiTicket, "noncestr=" + noncestr, "timestamp=" + timestamp, "url=" + url); WxJsapiSignature jsapiSignature = new WxJsapiSignature(); - jsapiSignature.setAppid(this.configStorage.getAppId()); + jsapiSignature.setAppid(this.wxMpConfigStorage.getAppId()); jsapiSignature.setTimestamp(timestamp); jsapiSignature.setNoncestr(noncestr); jsapiSignature.setUrl(url); @@ -216,7 +216,7 @@ public WxMpSemanticQueryResult semanticQuery(WxMpSemanticQuery semanticQuery) th 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.configStorage.getAppId()); + url.append("appid=").append(this.wxMpConfigStorage.getAppId()); url.append("&redirect_uri=").append(URIUtil.encodeURIComponent(redirectURI)); url.append("&response_type=code"); url.append("&scope=").append(scope); @@ -232,7 +232,7 @@ public String buildQrConnectUrl(String redirectURI, String scope, String state) { StringBuilder url = new StringBuilder(); url.append("https://open.weixin.qq.com/connect/qrconnect?"); - url.append("appid=").append(this.configStorage.getAppId()); + url.append("appid=").append(this.wxMpConfigStorage.getAppId()); url.append("&redirect_uri=").append(URIUtil.encodeURIComponent(redirectURI)); url.append("&response_type=code"); url.append("&scope=").append(scope); @@ -258,8 +258,8 @@ private WxMpOAuth2AccessToken getOAuth2AccessToken(StringBuilder url) throws WxE 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.configStorage.getAppId()); - url.append("&secret=").append(this.configStorage.getSecret()); + url.append("appid=").append(this.wxMpConfigStorage.getAppId()); + url.append("&secret=").append(this.wxMpConfigStorage.getSecret()); url.append("&code=").append(code); url.append("&grant_type=authorization_code"); @@ -270,7 +270,7 @@ public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorExc 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.configStorage.getAppId()); + url.append("appid=").append(this.wxMpConfigStorage.getAppId()); url.append("&grant_type=refresh_token"); url.append("&refresh_token=").append(refreshToken); @@ -397,8 +397,8 @@ protected synchronized T executeInternal(RequestExecutor executor, */ if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001) { // 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token - this.configStorage.expireAccessToken(); - if (this.configStorage.autoRefreshToken()) { + this.wxMpConfigStorage.expireAccessToken(); + if (this.wxMpConfigStorage.autoRefreshToken()) { return this.execute(executor, uri, data); } } @@ -424,26 +424,26 @@ public CloseableHttpClient getHttpclient() { } private void initHttpClient() { - ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage + ApacheHttpClientBuilder apacheHttpClientBuilder = this.wxMpConfigStorage .getApacheHttpClientBuilder(); if (null == apacheHttpClientBuilder) { apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get(); } - apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost()) - .httpProxyPort(this.configStorage.getHttpProxyPort()) - .httpProxyUsername(this.configStorage.getHttpProxyUsername()) - .httpProxyPassword(this.configStorage.getHttpProxyPassword()); + apacheHttpClientBuilder.httpProxyHost(this.wxMpConfigStorage.getHttpProxyHost()) + .httpProxyPort(this.wxMpConfigStorage.getHttpProxyPort()) + .httpProxyUsername(this.wxMpConfigStorage.getHttpProxyUsername()) + .httpProxyPassword(this.wxMpConfigStorage.getHttpProxyPassword()); - // if (this.configStorage.getSSLContext() != null) { + // if (this.wxMpConfigStorage.getSSLContext() != null) { // SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( - // this.configStorage.getSSLContext(), new String[] { "TLSv1" }, null, + // this.wxMpConfigStorage.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()); + if (this.wxMpConfigStorage.getHttpProxyHost() != null && this.wxMpConfigStorage.getHttpProxyPort() > 0) { + this.httpProxy = new HttpHost(this.wxMpConfigStorage.getHttpProxyHost(), this.wxMpConfigStorage.getHttpProxyPort()); } this.httpClient = apacheHttpClientBuilder.build(); @@ -451,12 +451,12 @@ private void initHttpClient() { @Override public WxMpConfigStorage getWxMpConfigStorage() { - return this.configStorage; + return this.wxMpConfigStorage; } @Override public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider) { - this.configStorage = wxConfigProvider; + this.wxMpConfigStorage = wxConfigProvider; this.initHttpClient(); } From c47b8eceba4824581c6ad8a76a585e5fb226d9b2 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Wed, 4 Jan 2017 19:23:03 +0800 Subject: [PATCH 47/80] =?UTF-8?q?=E4=BF=AE=E5=A4=8DtoMap=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E7=9A=84bug=EF=BC=8C=E5=B9=B6=E5=8A=A0=E5=85=A5=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mp/bean/pay/result/WxPayBaseResult.java | 18 +++++-- .../bean/pay/result/WxPayBaseResultTest.java | 49 +++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResultTest.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java index b06f3cca14..bbb0fe27f6 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java @@ -4,9 +4,10 @@ import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.XStreamAlias; import io.restassured.internal.path.xml.NodeChildrenImpl; +import io.restassured.internal.path.xml.NodeImpl; import io.restassured.path.xml.XmlPath; import io.restassured.path.xml.element.Node; -import io.restassured.path.xml.element.NodeChildren; +import io.restassured.path.xml.exception.XmlPathException; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.common.util.xml.XStreamInitializer; import org.slf4j.Logger; @@ -186,12 +187,23 @@ public void setSign(String sign) { public Map toMap() { Map result = Maps.newHashMap(); XmlPath xmlPath = new XmlPath(this.xmlString); - NodeChildren nodeChildren = xmlPath.getNodeChildren("xml"); - Iterator iterator = nodeChildren.nodeIterator(); + NodeImpl rootNode = null; + try { + rootNode = xmlPath.get("xml"); + } catch (XmlPathException e) { + throw new RuntimeException("xml数据有问题,请核实!"); + } + + if (rootNode == null) { + throw new RuntimeException("xml数据有问题,请核实!"); + } + + Iterator iterator = rootNode.children().nodeIterator(); while (iterator.hasNext()) { Node node = iterator.next(); result.put(node.name(), node.value()); } + return result; } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResultTest.java new file mode 100644 index 0000000000..0b1e7ac9f7 --- /dev/null +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResultTest.java @@ -0,0 +1,49 @@ +package me.chanjar.weixin.mp.bean.pay.result; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.util.Map; + +/** + *
    + * Created by Binary Wang on 2017-01-04.
    + * @author binarywang(Binary Wang)
    + * 
    + */ +public class WxPayBaseResultTest { + @Test + public void testToMap() throws Exception { + WxPayOrderQueryResult result = new WxPayOrderQueryResult(); + result.setXmlString("\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 1\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""); + Map map = result.toMap(); + System.out.println(map); + + Assert.assertEquals("SUCCESS", map.get("return_code")); + Assert.assertEquals("订单额外描述", map.get("attach")); + + result.setXmlString(""); + System.out.println(result.toMap()); + } + +} From cbf78114f724327795562dc2afff4d11d5c00e5f Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 5 Jan 2017 12:28:58 +0800 Subject: [PATCH 48/80] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=BB=93=E6=9E=9C=E5=AF=B9=E8=B1=A1=E4=B8=AD?= =?UTF-8?q?coupon=E7=9A=84=E7=BB=84=E8=A3=85=E9=80=BB=E8=BE=91=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=EF=BC=8C=E5=B9=B6=E5=8A=A0=E5=85=A5=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pay/result/WxPayOrderQueryResult.java | 157 +++++++++--------- .../pay/result/WxPayOrderQueryResultTest.java | 65 ++++++++ 2 files changed, 146 insertions(+), 76 deletions(-) create mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java index 373497f37c..150cac38d7 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java @@ -2,6 +2,7 @@ import com.google.common.collect.Lists; import com.thoughtworks.xstream.annotations.XStreamAlias; +import io.restassured.path.xml.XmlPath; import java.util.List; @@ -17,6 +18,7 @@ *
  • 示例值 *
  • 描述 *
  • + * * @author binarywang(Binary Wang) */ @XStreamAlias("xml") @@ -179,75 +181,6 @@ public class WxPayOrderQueryResult extends WxPayBaseResult { private Integer couponCount; private List coupons; - - public static class Coupon { - /** - *
    代金券类型
    -     * coupon_type_$n
    -     * 否
    -     * String
    -     * CASH
    -     * 
  • CASH--充值代金券 - *
  • NO_CASH---非充值代金券 - * 订单使用代金券时有返回(取值:CASH、NO_CASH)。$n为下标,从0开始编号,举例:coupon_type_$0 - *
  • - */ - private String couponType; - - /** - *
    代金券ID
    -     * coupon_id_$n
    -     * 否
    -     * String(20)
    -     * 10000
    -     * 代金券ID, $n为下标,从0开始编号
    -     * 
    - */ - private String couponId; - - /** - *
    单个代金券支付金额
    -     * coupon_fee_$n
    -     * 否
    -     * Int
    -     * 100
    -     * 单个代金券支付金额, $n为下标,从0开始编号
    -     * 
    - */ - private Integer couponFee; - - public Coupon(String couponType, String couponId, Integer couponFee) { - this.couponType = couponType; - this.couponId = couponId; - this.couponFee = couponFee; - } - - public String getCouponType() { - return this.couponType; - } - - public void setCouponType(String couponType) { - this.couponType = couponType; - } - - public String getCouponId() { - return this.couponId; - } - - public void setCouponId(String couponId) { - this.couponId = couponId; - } - - public Integer getCouponFee() { - return this.couponFee; - } - - public void setCouponFee(Integer couponFee) { - this.couponFee = couponFee; - } - - } - /** *
    微信支付订单号
        * transaction_id
    @@ -259,7 +192,6 @@ public void setCouponFee(Integer couponFee) {
        */
       @XStreamAlias("transaction_id")
       private String transactionId;
    -
       /**
        * 
    商户订单号
        * out_trade_no
    @@ -271,7 +203,6 @@ public void setCouponFee(Integer couponFee) {
        */
       @XStreamAlias("out_trade_no")
       private String outTradeNo;
    -
       /**
        * 
    附加数据
        * attach
    @@ -283,7 +214,6 @@ public void setCouponFee(Integer couponFee) {
        */
       @XStreamAlias("attach")
       private String attach;
    -
       /**
        * 
    支付完成时间
        * time_end
    @@ -295,7 +225,6 @@ public void setCouponFee(Integer couponFee) {
        */
       @XStreamAlias("time_end")
       private String timeEnd;
    -
       /**
        * 
    交易状态描述
        * trade_state_desc
    @@ -460,10 +389,86 @@ public void setTradeStateDesc(String tradeStateDesc) {
         this.tradeStateDesc = tradeStateDesc;
       }
     
    -  public void composeCoupons(String xmlString){
    -    if(this.couponCount != null && this.couponCount > 0 ){
    +  /**
    +   * 通过xml组装coupons属性内容
    +   */
    +  public void composeCoupons() {
    +    if (this.couponCount != null && this.couponCount > 0) {
           this.coupons = Lists.newArrayList();
    -      //TODO 暂时待实现
    +      XmlPath xmlPath = new XmlPath(this.getXmlString());
    +      for (int i = 0; i < this.couponCount; i++){
    +        this.coupons.add(new Coupon(this.getXmlValueIfExists(xmlPath, "xml.coupon_type_" + i, String.class),
    +          this.getXmlValueIfExists(xmlPath, "xml.coupon_id_" + i, String.class),
    +          this.getXmlValueIfExists(xmlPath, "xml.coupon_fee_" + i, Integer.class)));
    +      }
    +    }
    +  }
    +
    +  public static class Coupon {
    +    /**
    +     * 
    代金券类型
    +     * coupon_type_$n
    +     * 否
    +     * String
    +     * CASH
    +     * 
  • CASH--充值代金券 + *
  • NO_CASH---非充值代金券 + * 订单使用代金券时有返回(取值:CASH、NO_CASH)。$n为下标,从0开始编号,举例:coupon_type_$0 + *
  • + */ + private String couponType; + + /** + *
    代金券ID
    +     * coupon_id_$n
    +     * 否
    +     * String(20)
    +     * 10000
    +     * 代金券ID, $n为下标,从0开始编号
    +     * 
    + */ + private String couponId; + + /** + *
    单个代金券支付金额
    +     * coupon_fee_$n
    +     * 否
    +     * Int
    +     * 100
    +     * 单个代金券支付金额, $n为下标,从0开始编号
    +     * 
    + */ + private Integer couponFee; + + public Coupon(String couponType, String couponId, Integer couponFee) { + this.couponType = couponType; + this.couponId = couponId; + this.couponFee = couponFee; + } + + public String getCouponType() { + return this.couponType; + } + + public void setCouponType(String couponType) { + this.couponType = couponType; } + + public String getCouponId() { + return this.couponId; + } + + public void setCouponId(String couponId) { + this.couponId = couponId; + } + + public Integer getCouponFee() { + return this.couponFee; + } + + public void setCouponFee(Integer couponFee) { + this.couponFee = couponFee; + } + } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java new file mode 100644 index 0000000000..1582ea176a --- /dev/null +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java @@ -0,0 +1,65 @@ +package me.chanjar.weixin.mp.bean.pay.result; + +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + *
    + * Created by Binary Wang on 2017-01-04.
    + * @author binarywang(Binary Wang)
    + * 
    + */ +public class WxPayOrderQueryResultTest { + @Test + public void testComposeCoupons() throws Exception { + /** + * xml样例字符串来自于官方文档,并稍加改造加入了coupon相关的数据便于测试 + */ + String xmlString = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 1\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 2\n" + + " \n" + + " 10000\n" + + " 100\n" + + " \n" + + " 10001\n" + + " 200\n" + + ""; + + WxPayOrderQueryResult orderQueryResult = WxPayOrderQueryResult.fromXML(xmlString, WxPayOrderQueryResult.class); + orderQueryResult.composeCoupons(); + + Assert.assertEquals(orderQueryResult.getCouponCount().intValue(), 2); + Assert.assertNotNull(orderQueryResult.getCoupons()); + Assert.assertEquals(orderQueryResult.getCoupons().size(), 2); + + Assert.assertEquals(orderQueryResult.getCoupons().get(0).getCouponFee().intValue(), 100); + Assert.assertEquals(orderQueryResult.getCoupons().get(1).getCouponFee().intValue(), 200); + + Assert.assertEquals(orderQueryResult.getCoupons().get(0).getCouponType(), "CASH"); + Assert.assertEquals(orderQueryResult.getCoupons().get(1).getCouponType(), "NO_CASH"); + + Assert.assertEquals(orderQueryResult.getCoupons().get(0).getCouponId(), "10000"); + Assert.assertEquals(orderQueryResult.getCoupons().get(1).getCouponId(), "10001"); + + } + +} From 55d66ac7c9c40dd8acbdff423e3ee4ba2517c97d Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 5 Jan 2017 12:29:26 +0800 Subject: [PATCH 49/80] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=94=AF=E4=BB=98=E7=9B=B8=E5=85=B3=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java | 4 ++-- .../mp/bean/pay/result/WxPayRedpackQueryResult.java | 10 +++++----- .../mp/bean/pay/result/WxPayRefundQueryResult.java | 7 +++++-- .../mp/bean/pay/result/WxPayRefundQueryResultTest.java | 5 ++--- 4 files changed, 14 insertions(+), 12 deletions(-) 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 6ab639f1dc..8103993ce2 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 @@ -83,7 +83,7 @@ public WxPayRefundQueryResult refundQuery(String transactionId, String outTradeN String url = PAY_BASE_URL + "/pay/refundquery"; String responseContent = this.executeRequest(url, request.toXML()); WxPayRefundQueryResult result = WxPayRefundQueryResult.fromXML(responseContent, WxPayRefundQueryResult.class); - result.composeRefundRecords(responseContent); + result.composeRefundRecords(); this.checkResult(result); return result; } @@ -189,7 +189,7 @@ public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) String url = PAY_BASE_URL + "/pay/orderquery"; String responseContent = this.executeRequest(url, request.toXML()); WxPayOrderQueryResult result = WxPayOrderQueryResult.fromXML(responseContent, WxPayOrderQueryResult.class); - result.composeCoupons(responseContent); + result.composeCoupons(); this.checkResult(result); return result; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRedpackQueryResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRedpackQueryResult.java index 8a2e37fabf..6febaa37c3 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRedpackQueryResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRedpackQueryResult.java @@ -52,11 +52,11 @@ public class WxPayRedpackQueryResult extends WxPayBaseResult { * RECEIVED * string(16) * SENDING:发放中, - * SENT:已发放待领取, - * FAILED:发放失败, - * RECEIVED:已领取, - * RFUND_ING:退款中, - * REFUND:已退款 + * SENT:已发放待领取, + * FAILED:发放失败, + * RECEIVED:已领取, + * RFUND_ING:退款中, + * REFUND:已退款 *
    */ @XStreamAlias("status") diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java index 146c35dfad..a75946a318 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java @@ -184,10 +184,13 @@ public void setRefundRecords(List refundRecords) { this.refundRecords = refundRecords; } - public void composeRefundRecords(String xmlString) { + /** + * 组装生成退款记录属性的内容 + */ + public void composeRefundRecords() { if (this.refundCount != null && this.refundCount > 0) { this.refundRecords = Lists.newArrayList(); - XmlPath xmlPath = new XmlPath(xmlString); + XmlPath xmlPath = new XmlPath(this.getXmlString()); for (int i = 0; i < this.refundCount; i++) { RefundRecord refundRecord = new RefundRecord(); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java index 9427bd0109..34672417f9 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java @@ -33,9 +33,8 @@ public void composeRefundRecords() throws Exception { " \n" + ""; - WxPayRefundQueryResult result = new WxPayRefundQueryResult(); - result.setRefundCount(1); - result.composeRefundRecords(xmlString); + WxPayRefundQueryResult result = WxPayRefundQueryResult.fromXML(xmlString, WxPayRefundQueryResult.class); + result.composeRefundRecords(); Assert.assertNotNull(result.getRefundRecords()); Assert.assertEquals(result.getRefundRecords().size(), 1); From 2d072e909f2d8a6ba937526d8205b72eceae054a Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 5 Jan 2017 14:07:28 +0800 Subject: [PATCH 50/80] =?UTF-8?q?=E9=87=8D=E6=9E=84=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mp/bean/pay/result/WxPayBaseResult.java | 6 ++--- .../pay/result/WxPayOrderQueryResult.java | 6 ++--- .../pay/result/WxPayRefundQueryResult.java | 24 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java index bbb0fe27f6..4dd133abea 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java @@ -207,7 +207,7 @@ public Map toMap() { return result; } - private String getXmlValueIfExists(XmlPath xmlPath, String path) { + private String getXmlValue(XmlPath xmlPath, String path) { if (xmlPath.get(path) instanceof NodeChildrenImpl) { if (((NodeChildrenImpl) xmlPath.get(path)).size() == 0) { return null; @@ -217,8 +217,8 @@ private String getXmlValueIfExists(XmlPath xmlPath, String path) { return xmlPath.getString(path); } - protected T getXmlValueIfExists(XmlPath xmlPath, String path, Class clz) { - String value = this.getXmlValueIfExists(xmlPath, path); + protected T getXmlValue(XmlPath xmlPath, String path, Class clz) { + String value = this.getXmlValue(xmlPath, path); if (value == null) { return null; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java index 150cac38d7..8cdf4e6d95 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java @@ -397,9 +397,9 @@ public void composeCoupons() { this.coupons = Lists.newArrayList(); XmlPath xmlPath = new XmlPath(this.getXmlString()); for (int i = 0; i < this.couponCount; i++){ - this.coupons.add(new Coupon(this.getXmlValueIfExists(xmlPath, "xml.coupon_type_" + i, String.class), - this.getXmlValueIfExists(xmlPath, "xml.coupon_id_" + i, String.class), - this.getXmlValueIfExists(xmlPath, "xml.coupon_fee_" + i, Integer.class))); + this.coupons.add(new Coupon(this.getXmlValue(xmlPath, "xml.coupon_type_" + i, String.class), + this.getXmlValue(xmlPath, "xml.coupon_id_" + i, String.class), + this.getXmlValue(xmlPath, "xml.coupon_fee_" + i, Integer.class))); } } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java index a75946a318..1e569ac19a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java @@ -196,16 +196,16 @@ public void composeRefundRecords() { RefundRecord refundRecord = new RefundRecord(); this.refundRecords.add(refundRecord); - refundRecord.setOutRefundNo(this.getXmlValueIfExists(xmlPath, "xml.out_refund_no_" + i, String.class)); - refundRecord.setRefundId(this.getXmlValueIfExists(xmlPath, "xml.refund_id_" + i, String.class)); - refundRecord.setRefundChannel(this.getXmlValueIfExists(xmlPath, "xml.refund_channel_" + i, String.class)); - refundRecord.setRefundFee(this.getXmlValueIfExists(xmlPath, "xml.refund_fee_" + i, Integer.class)); - refundRecord.setSettlementRefundFee(this.getXmlValueIfExists(xmlPath, "xml.settlement_refund_fee_" + i, Integer.class)); - refundRecord.setCouponType(this.getXmlValueIfExists(xmlPath, "xml.coupon_type_" + i, String.class)); - refundRecord.setCouponRefundFee(this.getXmlValueIfExists(xmlPath, "xml.coupon_refund_fee_" + i, Integer.class)); - refundRecord.setCouponRefundCount(this.getXmlValueIfExists(xmlPath, "xml.coupon_refund_count_" + i, Integer.class)); - refundRecord.setRefundStatus(this.getXmlValueIfExists(xmlPath, "xml.refund_status_" + i, String.class)); - refundRecord.setRefundRecvAccout(this.getXmlValueIfExists(xmlPath, "xml.refund_recv_accout_" + i, String.class)); + refundRecord.setOutRefundNo(this.getXmlValue(xmlPath, "xml.out_refund_no_" + i, String.class)); + refundRecord.setRefundId(this.getXmlValue(xmlPath, "xml.refund_id_" + i, String.class)); + refundRecord.setRefundChannel(this.getXmlValue(xmlPath, "xml.refund_channel_" + i, String.class)); + refundRecord.setRefundFee(this.getXmlValue(xmlPath, "xml.refund_fee_" + i, Integer.class)); + refundRecord.setSettlementRefundFee(this.getXmlValue(xmlPath, "xml.settlement_refund_fee_" + i, Integer.class)); + refundRecord.setCouponType(this.getXmlValue(xmlPath, "xml.coupon_type_" + i, String.class)); + refundRecord.setCouponRefundFee(this.getXmlValue(xmlPath, "xml.coupon_refund_fee_" + i, Integer.class)); + refundRecord.setCouponRefundCount(this.getXmlValue(xmlPath, "xml.coupon_refund_count_" + i, Integer.class)); + refundRecord.setRefundStatus(this.getXmlValue(xmlPath, "xml.refund_status_" + i, String.class)); + refundRecord.setRefundRecvAccout(this.getXmlValue(xmlPath, "xml.refund_recv_accout_" + i, String.class)); if (refundRecord.getCouponRefundCount() == null || refundRecord.getCouponRefundCount() == 0) { continue; @@ -215,8 +215,8 @@ public void composeRefundRecords() { for (int j = 0; j < refundRecord.getCouponRefundCount(); j++) { coupons.add( new RefundRecord.RefundCoupon( - this.getXmlValueIfExists(xmlPath, "xml.coupon_refund_id_" + i + "_" + j, String.class), - this.getXmlValueIfExists(xmlPath, "xml.coupon_refund_fee_" + i + "_" + j, Integer.class) + this.getXmlValue(xmlPath, "xml.coupon_refund_id_" + i + "_" + j, String.class), + this.getXmlValue(xmlPath, "xml.coupon_refund_fee_" + i + "_" + j, Integer.class) ) ); } From c142daa734ad9dee6b017469a38ab6a31c259e8f Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 6 Jan 2017 11:40:46 +0800 Subject: [PATCH 51/80] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=AB=E7=A0=81?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E7=94=9F=E6=88=90=E4=BA=8C=E7=BB=B4=E7=A0=81?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3=E5=8F=8A=E5=85=B6=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=EF=BC=8C#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- weixin-java-mp/pom.xml | 6 +- .../chanjar/weixin/mp/api/WxMpPayService.java | 29 ++++++++++ .../mp/api/impl/WxMpPayServiceImpl.java | 38 +++++++++++++ .../chanjar/weixin/mp/api/ApiTestModule.java | 1 - .../mp/api/impl/WxMpPayServiceImplTest.java | 55 +++++++++++++++---- 5 files changed, 115 insertions(+), 14 deletions(-) diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index 335fe3a3b0..759ee7ff1d 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -59,7 +59,11 @@ xml-path 3.0.1 - + + com.github.binarywang + qrcode-utils + 1.0 + 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 797877441d..d0b21109db 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 @@ -7,6 +7,7 @@ import me.chanjar.weixin.mp.bean.pay.request.WxPayUnifiedOrderRequest; import me.chanjar.weixin.mp.bean.pay.result.*; +import java.io.File; import java.util.Map; /** @@ -235,4 +236,32 @@ public interface WxMpPayService { */ WxEntPayQueryResult queryEntPay(String partnerTradeNo) throws WxErrorException; + /** + *
    +   * 扫码支付模式一生成二维码的方法
    +   * 二维码中的内容为链接,形式为:
    +   * weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXX&mch_id=XXXXX&product_id=XXXXXX&time_stamp=XXXXXX&nonce_str=XXXXX
    +   * 其中XXXXX为商户需要填写的内容,商户将该链接生成二维码,如需要打印发布二维码,需要采用此格式。商户可调用第三方库生成二维码图片。
    +   * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_4
    +   * 
    + * @param productId 产品Id + * @param sideLength 要生成的二维码的边长,如果为空,则取默认值400 + * @param logoFile 商户logo图片的文件对象,可以为空 + * @return 生成的二维码的字节数组 + */ + byte[] createScanPayQrcodeMode1(String productId, File logoFile, Integer sideLength); + + /** + *
    +   * 扫码支付模式二生成二维码的方法
    +   * 对应链接格式:weixin://wxpay/bizpayurl?sr=XXXXX。请商户调用第三方库将code_url生成二维码图片。
    +   * 该模式链接较短,生成的二维码打印到结账小票上的识别率较高。
    +   * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_5
    +   * 
    + * @param codeUrl 微信返回的交易会话的二维码链接 + * @param logoFile 商户logo图片的文件对象,可以为空 + * @param sideLength 要生成的二维码的边长,如果为空,则取默认值400 + * @return 生成的二维码的字节数组 + */ + byte[] createScanPayQrcodeMode2(String codeUrl, File logoFile, Integer sideLength); } 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 8103993ce2..33bf6cdfc1 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,5 +1,7 @@ package me.chanjar.weixin.mp.api.impl; +import com.github.binarywang.utils.qrcode.QrcodeUtils; +import com.google.common.collect.Maps; import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.BeanUtils; @@ -25,6 +27,7 @@ import org.slf4j.LoggerFactory; import javax.net.ssl.SSLContext; +import java.io.File; import java.io.IOException; import java.util.*; @@ -316,6 +319,41 @@ public WxEntPayQueryResult queryEntPay(String partnerTradeNo) throws WxErrorExce return result; } + @Override + public byte[] createScanPayQrcodeMode1(String productId, File logoFile, Integer sideLength) { + //weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXX&mch_id=XXXXX&product_id=XXXXXX&time_stamp=XXXXXX&nonce_str=XXXXX + StringBuilder codeUrl = new StringBuilder("weixin://wxpay/bizpayurl?"); + Map params = Maps.newHashMap(); + params.put("appid", this.getConfig().getAppId()); + params.put("mch_id", this.getConfig().getPartnerId()); + params.put("product_id", productId); + params.put("time_stamp", String.valueOf(System.currentTimeMillis())); + params.put("nonce_str", String.valueOf(System.currentTimeMillis())); + + String sign = this.createSign(params); + params.put("sign", sign); + + for (String key : params.keySet()) { + codeUrl.append(key + "=" + params.get(key) + "&"); + } + + String content = codeUrl.toString().substring(0, codeUrl.length() - 1); + if (sideLength == null || sideLength < 1) { + return QrcodeUtils.createQrcode(content, logoFile); + } + + return QrcodeUtils.createQrcode(content, sideLength, logoFile); + } + + @Override + public byte[] createScanPayQrcodeMode2(String codeUrl, File logoFile, Integer sideLength) { + if (sideLength == null || sideLength < 1) { + return QrcodeUtils.createQrcode(codeUrl, logoFile); + } + + return QrcodeUtils.createQrcode(codeUrl, sideLength, logoFile); + } + private String executeRequest(String url, String requestStr) throws WxErrorException { HttpPost httpPost = new HttpPost(url); if (this.wxMpService.getHttpProxy() != null) { diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java index 13491d2097..c506df0f83 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java @@ -19,7 +19,6 @@ public void configure(Binder binder) { WxXmlMpInMemoryConfigStorage config = this .fromXml(WxXmlMpInMemoryConfigStorage.class, is1); config.setAccessTokenLock(new ReentrantLock()); - config.setSslContextFilePath(config.getKeyPath()); WxMpService wxService = new WxMpServiceImpl(); wxService.setWxMpConfigStorage(config); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index 418b710bae..248fc7dd98 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.api.impl; +import com.github.binarywang.utils.qrcode.QrcodeUtils; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.ApiTestModule; @@ -10,9 +11,13 @@ import me.chanjar.weixin.mp.bean.pay.request.WxPaySendRedpackRequest; import me.chanjar.weixin.mp.bean.pay.request.WxPayUnifiedOrderRequest; import me.chanjar.weixin.mp.bean.pay.result.*; +import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; +import java.nio.file.Files; +import java.nio.file.Path; + /** * 测试支付相关接口 * Created by Binary Wang on 2016/7/28. @@ -22,7 +27,6 @@ @Test @Guice(modules = ApiTestModule.class) public class WxMpPayServiceImplTest { - @Inject protected WxMpService wxService; @@ -32,9 +36,17 @@ public void testGetPayInfo() throws Exception { } /** - * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#refund(WxPayRefundRequest)} . + * 需要证书的接口需要先执行该方法 */ @Test + public void setSSLKey(){ + WxXmlMpInMemoryConfigStorage config = (WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); + config.setSslContextFilePath(config.getKeyPath()); + } + /** + * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#refund(WxPayRefundRequest)} . + */ + @Test(dependsOnMethods = {"setSSLKey"}) public void testRefund() throws Exception { WxPayRefundRequest request = new WxPayRefundRequest(); request.setOutRefundNo("aaa"); @@ -45,7 +57,6 @@ public void testRefund() throws Exception { System.err.println(result); } - /** * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#refundQuery(String, String, String, String)} . */ @@ -63,15 +74,10 @@ public void testRefundQuery() throws Exception { System.err.println(result); } - @Test - public void testCheckJSSDKCallbackDataSignature() throws Exception { - - } - /** * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#sendRedpack(WxPaySendRedpackRequest)} . */ - @Test + @Test(dependsOnMethods = {"setSSLKey"}) public void testSendRedpack() throws Exception { WxPaySendRedpackRequest request = new WxPaySendRedpackRequest(); request.setActName("abc"); @@ -86,7 +92,7 @@ public void testSendRedpack() throws Exception { /** * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryRedpack(String)}. */ - @Test + @Test(dependsOnMethods = {"setSSLKey"}) public void testQueryRedpack() throws Exception { WxPayRedpackQueryResult redpackResult = this.wxService.getPayService().queryRedpack("aaaa"); System.err.println(redpackResult); @@ -125,7 +131,7 @@ public final void testCloseOrder() throws WxErrorException { /** * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#entPay(WxEntPayRequest)}. */ - @Test + @Test(dependsOnMethods = {"setSSLKey"}) public final void testEntPay() throws WxErrorException { WxEntPayRequest request = new WxEntPayRequest(); System.err.println(this.wxService.getPayService().entPay(request)); @@ -134,8 +140,33 @@ public final void testEntPay() throws WxErrorException { /** * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryEntPay(String)}. */ - @Test + @Test(dependsOnMethods = {"setSSLKey"}) public final void testQueryEntPay() throws WxErrorException { System.err.println(this.wxService.getPayService().queryEntPay("11212121")); } + + @Test + public void testCreateScanPayQrcodeMode1() throws Exception { + String productId = "abc"; + byte[] bytes = this.wxService.getPayService().createScanPayQrcodeMode1(productId, null, null); + Path qrcodeFilePath = Files.createTempFile("qrcode_", ".jpg"); + Files.write(qrcodeFilePath, bytes); + String qrcodeContent = QrcodeUtils.decodeQrcode(qrcodeFilePath.toFile()); + System.out.println(qrcodeContent); + + Assert.assertTrue(qrcodeContent.startsWith("weixin://wxpay/bizpayurl?")); + Assert.assertTrue(qrcodeContent.contains("product_id=" + productId)); + } + + @Test + public void testCreateScanPayQrcodeMode2() throws Exception { + String qrcodeContent = "abc"; + byte[] bytes = this.wxService.getPayService().createScanPayQrcodeMode2(qrcodeContent, null, null); + Path qrcodeFilePath = Files.createTempFile("qrcode_", ".jpg"); + Files.write(qrcodeFilePath, bytes); + + Assert.assertEquals(QrcodeUtils.decodeQrcode(qrcodeFilePath.toFile()), qrcodeContent); + } + + } From c02b2e2cac15ec98417a7fc4689f9bd36018ecc3 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 6 Jan 2017 12:14:10 +0800 Subject: [PATCH 52/80] release 2.4.8.BETA --- pom.xml | 2 +- weixin-java-common/pom.xml | 2 +- weixin-java-cp/pom.xml | 2 +- weixin-java-mp/pom.xml | 2 +- weixin-java-osgi/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index a8f2f42456..c1bf3143db 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.github.binarywang weixin-java-parent - 2.4.7.BETA + 2.4.8.BETA pom WeiXin Java Tools - Parent 微信公众号、企业号上级POM diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml index 8f78458dfa..26fdff4a3c 100644 --- a/weixin-java-common/pom.xml +++ b/weixin-java-common/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.7.BETA + 2.4.8.BETA weixin-java-common diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index 2adec10e3e..9b5f38771e 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.7.BETA + 2.4.8.BETA weixin-java-cp diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index 759ee7ff1d..197e54c290 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.7.BETA + 2.4.8.BETA weixin-java-mp WeiXin Java Tools - MP diff --git a/weixin-java-osgi/pom.xml b/weixin-java-osgi/pom.xml index ee96e71f89..5d749f8fd8 100644 --- a/weixin-java-osgi/pom.xml +++ b/weixin-java-osgi/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.7.BETA + 2.4.8.BETA weixin-java-osgi From 81159c241999aa273c29b0fd501457da348bda81 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 6 Jan 2017 16:59:06 +0800 Subject: [PATCH 53/80] =?UTF-8?q?=E5=B0=86=E5=8F=91=E5=B8=83=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E9=85=8D=E7=BD=AE=E6=94=B9=E4=B8=BA=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E5=90=8E=E8=87=AA=E5=8A=A8=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c1bf3143db..2092494c40 100644 --- a/pom.xml +++ b/pom.xml @@ -307,7 +307,7 @@ ossrh https://oss.sonatype.org/ - false + true From 13136589db95bed580c6db5d55fbd250755f4744 Mon Sep 17 00:00:00 2001 From: jkli Date: Sat, 7 Jan 2017 16:29:29 +0800 Subject: [PATCH 54/80] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=8E=A5=E6=94=B6=E7=A1=AC=E4=BB=B6=E8=AE=BE=E5=A4=87=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E7=9A=84OpenID=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 参考 http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-1 --- .../weixin/mp/bean/message/WxMpXmlMessage.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java index 36b4c10470..0f1a3ffe62 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java @@ -281,6 +281,12 @@ public class WxMpXmlMessage implements Serializable { @XStreamConverter(value = XStreamCDataConverter.class) private String deviceId; + /** + * 微信用户账号的OpenID + */ + @XStreamAlias("OpenID") + @XStreamConverter(value = XStreamCDataConverter.class) + private String openId; @XStreamAlias("HardWare") private HardWare hardWare = new HardWare(); @@ -375,6 +381,14 @@ public void setDeviceId(String deviceId) { this.deviceId = deviceId; } + public String getOpenId() { + return openId; + } + + public void setOpenId(String openId) { + this.openId = openId; + } + public Long getExpiredTime() { return this.expiredTime; } From fa7360d0ca076882ae5d869ea92990923bee561d Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sun, 8 Jan 2017 23:27:30 +0800 Subject: [PATCH 55/80] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E4=BA=A4=E6=98=93=E4=BF=9D=E9=9A=9C=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20#56?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/mp/api/WxMpPayService.java | 19 +- .../mp/api/impl/WxMpPayServiceImpl.java | 13 +- .../bean/pay/request/WxPayReportRequest.java | 273 ++++++++++++++++++ .../mp/bean/pay/result/WxPayBaseResult.java | 3 +- .../mp/api/impl/WxMpPayServiceImplTest.java | 17 +- 5 files changed, 314 insertions(+), 11 deletions(-) create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayReportRequest.java 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 d0b21109db..a6dd6654e7 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,7 @@ package me.chanjar.weixin.mp.api; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.bean.pay.request.WxEntPayRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPayRefundRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPaySendRedpackRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPayUnifiedOrderRequest; +import me.chanjar.weixin.mp.bean.pay.request.*; import me.chanjar.weixin.mp.bean.pay.result.*; import java.io.File; @@ -182,7 +179,6 @@ public interface WxMpPayService { */ boolean checkSign(Map params, String signKey); - /** * 发送微信红包给个人用户 *
    @@ -264,4 +260,17 @@ public interface WxMpPayService {
        * @return 生成的二维码的字节数组
        */
       byte[] createScanPayQrcodeMode2(String codeUrl, File logoFile, Integer sideLength);
    +
    +  /**
    +   * 
    +   * 交易保障
    +   * 应用场景:
    +   *  商户在调用微信支付提供的相关接口时,会得到微信支付返回的相关信息以及获得整个接口的响应时间。
    +   *  为提高整体的服务水平,协助商户一起提高服务质量,微信支付提供了相关接口调用耗时和返回信息的主动上报接口,
    +   *  微信支付可以根据商户侧上报的数据进一步优化网络部署,完善服务监控,和商户更好的协作为用户提供更好的业务体验。
    +   * 接口地址: https://api.mch.weixin.qq.com/payitil/report
    +   * 是否需要证书:不需要
    +   * 
    + */ + void report(WxPayReportRequest request) throws WxErrorException; } 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 33bf6cdfc1..a9ef983b8b 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 @@ -95,7 +95,7 @@ public WxPayRefundQueryResult refundQuery(String transactionId, String outTradeN private void checkResult(WxPayBaseResult result) throws WxErrorException { //校验返回结果签名 Map map = result.toMap(); - if (!this.checkSign(map)) { + if (result.getSign() != null &&!this.checkSign(map)) { log.debug("校验结果签名失败,参数:{}", map); throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("参数格式校验错误!").build()); } @@ -354,6 +354,17 @@ public byte[] createScanPayQrcodeMode2(String codeUrl, File logoFile, Integer si return QrcodeUtils.createQrcode(codeUrl, sideLength, logoFile); } + public void report(WxPayReportRequest request) throws WxErrorException { + BeanUtils.checkRequiredFields(request); + this.initRequest(request); + request.setSign(this.createSign(request)); + + String url = PAY_BASE_URL + "/payitil/report"; + String responseContent = this.wxMpService.post(url, request.toXML()); + WxPayBaseResult result = WxPayBaseResult.fromXML(responseContent, WxPayBaseResult.class); + this.checkResult(result); + } + private String executeRequest(String url, String requestStr) throws WxErrorException { HttpPost httpPost = new HttpPost(url); if (this.wxMpService.getHttpProxy() != null) { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayReportRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayReportRequest.java new file mode 100644 index 0000000000..44b047f86f --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayReportRequest.java @@ -0,0 +1,273 @@ +package me.chanjar.weixin.mp.bean.pay.request; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import me.chanjar.weixin.common.annotation.Required; + +/** + *
    + * 微信支付-交易保障请求参数
    + * 注释中各行每个字段描述对应如下:
    + * 
  • 字段名 + *
  • 变量名 + *
  • 是否必填 + *
  • 类型 + *
  • 示例值 + *
  • 描述 + *
  • + * + * @author binarywang(Binary Wang) + */ +@XStreamAlias("xml") +public class WxPayReportRequest extends WxPayBaseRequest { + /** + *
    +   * 设备号
    +   * device_info
    +   * 否
    +   * String(32)
    +   * 013467007045764
    +   * 商户自定义的终端设备号,如门店编号、设备的ID等
    +   * 
    + */ + @XStreamAlias("device_info") + private String deviceInfo; + + /** + *
    +   * 签名类型
    +   * sign_type
    +   * 否
    +   * String(32)
    +   * HMAC-SHA256
    +   * 签名类型,目前支持HMAC-SHA256和MD5,默认为MD5
    +   * 
    + */ + @XStreamAlias("sign_type") + private String signType; + + /** + *
    +   * 接口URL
    +   * interface_url
    +   * 是
    +   * String(127)
    +   * https://api.mch.weixin.qq.com/pay/unifiedorder
    +   * 报对应的接口的完整URL,类似:https://api.mch.weixin.qq.com/pay/unifiedorder,
    +   * 对于刷卡支付,为更好的和商户共同分析一次业务行为的整体耗时情况,
    +   * 对于两种接入模式,请都在门店侧对一次刷卡支付进行一次单独的整体上报,
    +   * 上报URL指定为:https://api.mch.weixin.qq.com/pay/micropay/total,关于两种接入模式具体可参考本文档章节:
    +   * 刷卡支付商户接入模式,其它接口调用仍然按照调用一次,上报一次来进行。
    +   * 
    + */ + @Required + @XStreamAlias("interface_url") + private String interfaceUrl; + /** + *
    +   * 接口耗时
    +   * execute_time
    +   * 是
    +   * Int
    +   * 1000
    +   * 接口耗时情况,单位为毫秒
    +   * 
    + */ + @Required + @XStreamAlias("execute_time_")//估计是官方接口搞错了 + private Integer executeTime; + /** + *
    +   * 返回状态码
    +   * return_code
    +   * 是
    +   * String(16)
    +   * SUCCESS
    +   * SUCCESS/FAIL,此字段是通信标识,非交易标识,交易是否成功需要查看trade_state来判断
    +   * 
    + */ + @Required + @XStreamAlias("return_code") + private String returnCode; + /** + *
    +   * 返回信息
    +   * return_msg
    +   * 否
    +   * String(128)
    +   * 签名失败
    +   * 返回信息,如非空,为错误原因,签名失败,参数格式校验错误
    +   * 
    + */ + @XStreamAlias("return_msg") + private String returnMsg; + /** + *
    +   * 业务结果
    +   * result_code
    +   * 是
    +   * String(16)
    +   * SUCCESS
    +   * SUCCESS/FAIL
    +   * 
    + */ + @Required + @XStreamAlias("result_code") + private String resultCode; + /** + *
    +   * 错误代码
    +   * err_code
    +   * 否
    +   * String(32)
    +   * SYSTEMERROR
    +   * ORDERNOTEXIST—订单不存在,SYSTEMERROR—系统错误
    +   * 
    + */ + @XStreamAlias("err_code") + private String errCode; + /** + *
    +   * 错误代码描述
    +   * err_code_des
    +   * 否
    +   * String(128)
    +   * 系统错误
    +   * 结果信息描述
    +   * 
    + */ + @XStreamAlias("err_code_des") + private String errCodeDes; + /** + *
    +   * 商户订单号
    +   * out_trade_no
    +   * 否
    +   * String(32)
    +   * 1217752501201407033233368018
    +   * 商户系统内部的订单号,商户可以在上报时提供相关商户订单号方便微信支付更好的提高服务质量。
    +   * 
    + */ + @XStreamAlias("out_trade_no") + private String outTradeNo; + /** + *
    +   * 访问接口IP
    +   * user_ip
    +   * 是
    +   * String(16)
    +   * 8.8.8.8
    +   * 发起接口调用时的机器IP
    +   * 
    + */ + @Required + @XStreamAlias("user_ip") + private String userIp; + /** + *
    +   * 商户上报时间
    +   * time
    +   * 否
    +   * String(14)
    +   * 20091227091010
    +   * 系统时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则
    +   * 
    + */ + @XStreamAlias("time") + private String time; + + public String getDeviceInfo() { + return deviceInfo; + } + + public void setDeviceInfo(String deviceInfo) { + this.deviceInfo = deviceInfo; + } + + public String getSignType() { + return signType; + } + + public void setSignType(String signType) { + this.signType = signType; + } + + public String getInterfaceUrl() { + return interfaceUrl; + } + + public void setInterfaceUrl(String interfaceUrl) { + this.interfaceUrl = interfaceUrl; + } + + public Integer getExecuteTime() { + return executeTime; + } + + public void setExecuteTime(Integer executeTime) { + this.executeTime = executeTime; + } + + public String getReturnCode() { + return returnCode; + } + + public void setReturnCode(String returnCode) { + this.returnCode = returnCode; + } + + public String getReturnMsg() { + return returnMsg; + } + + public void setReturnMsg(String returnMsg) { + this.returnMsg = returnMsg; + } + + public String getResultCode() { + return resultCode; + } + + public void setResultCode(String resultCode) { + this.resultCode = resultCode; + } + + public String getErrCode() { + return errCode; + } + + public void setErrCode(String errCode) { + this.errCode = errCode; + } + + public String getErrCodeDes() { + return errCodeDes; + } + + public void setErrCodeDes(String errCodeDes) { + this.errCodeDes = errCodeDes; + } + + public String getOutTradeNo() { + return outTradeNo; + } + + public void setOutTradeNo(String outTradeNo) { + this.outTradeNo = outTradeNo; + } + + public String getUserIp() { + return userIp; + } + + public void setUserIp(String userIp) { + this.userIp = userIp; + } + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java index 4dd133abea..88334aa76d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java @@ -24,7 +24,8 @@ * @author binarywang(Binary Wang) *
    */ -public abstract class WxPayBaseResult { +@XStreamAlias("xml") +public class WxPayBaseResult { /** * 返回状态码 */ diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index 248fc7dd98..7e28cb43a2 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -6,10 +6,7 @@ import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; -import me.chanjar.weixin.mp.bean.pay.request.WxEntPayRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPayRefundRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPaySendRedpackRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPayUnifiedOrderRequest; +import me.chanjar.weixin.mp.bean.pay.request.*; import me.chanjar.weixin.mp.bean.pay.result.*; import org.testng.Assert; import org.testng.annotations.Guice; @@ -35,6 +32,18 @@ public void testGetPayInfo() throws Exception { } + @Test + public void testReport() throws Exception { + WxPayReportRequest request = new WxPayReportRequest(); + request.setInterfaceUrl("hahahah"); + request.setSignType("HMAC-SHA256");//貌似接口未校验此字段 + request.setExecuteTime(1000); + request.setReturnCode("aaa"); + request.setResultCode("aaa"); + request.setUserIp("8.8.8"); + this.wxService.getPayService().report(request); + } + /** * 需要证书的接口需要先执行该方法 */ From 245bec709a21f6889bb3743843d6c543c0188b26 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 9 Jan 2017 13:47:36 +0800 Subject: [PATCH 56/80] =?UTF-8?q?=E5=BC=95=E5=85=A5=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E4=BD=BF=E5=BE=97=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E8=83=BD=E5=A4=9F=E6=94=AF=E6=8C=81=E4=BB=BF?= =?UTF-8?q?=E7=9C=9F=E6=B5=8B=E8=AF=95=E7=8E=AF=E5=A2=83=20#119?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpConfigStorage.java | 4 ++ .../mp/api/WxMpInMemoryConfigStorage.java | 5 +++ .../mp/api/impl/WxMpPayServiceImpl.java | 37 +++++++++++++------ .../mp/bean/pay/result/WxPayBaseResult.java | 3 +- .../mp/bean/pay/result/WxPayCommonResult.java | 15 ++++++++ .../mp/api/WxXmlMpInMemoryConfigStorage.java | 5 +++ .../mp/api/impl/WxMpPayServiceImplTest.java | 10 +++-- 7 files changed, 61 insertions(+), 18 deletions(-) create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayCommonResult.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java index cff903bf33..79ae931894 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java @@ -144,4 +144,8 @@ public interface WxMpConfigStorage { */ boolean autoRefreshToken(); + /** + * 微信支付是否使用仿真测试环境 + */ + boolean useSandboxForWxPay(); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java index 29fbed63c6..f229268418 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java @@ -344,4 +344,9 @@ public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientB public boolean autoRefreshToken() { return true; } + + @Override + public boolean useSandboxForWxPay() { + return false; + } } 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 a9ef983b8b..dde6431a13 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 @@ -52,6 +52,14 @@ private WxMpConfigStorage getConfig() { return wxMpService.getWxMpConfigStorage(); } + private String getPayBaseUrl(){ + if(this.getConfig().useSandboxForWxPay()){ + return PAY_BASE_URL + "/sandboxnew"; + } + + return PAY_BASE_URL; + } + @Override public WxPayRefundResult refund(WxPayRefundRequest request) throws WxErrorException { this.initRequest(request); @@ -61,7 +69,7 @@ public WxPayRefundResult refund(WxPayRefundRequest request) throws WxErrorExcept this.checkParameters(request); request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/secapi/pay/refund"; + String url = this.getPayBaseUrl() + "/secapi/pay/refund"; String responseContent = this.executeWithKey(url, request.toXML()); WxPayRefundResult result = WxPayRefundResult.fromXML(responseContent, WxPayRefundResult.class); this.checkResult(result); @@ -83,7 +91,7 @@ public WxPayRefundQueryResult refundQuery(String transactionId, String outTradeN request.setRefundId(StringUtils.trimToNull(refundId)); request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/pay/refundquery"; + String url = this.getPayBaseUrl() + "/pay/refundquery"; String responseContent = this.executeRequest(url, request.toXML()); WxPayRefundQueryResult result = WxPayRefundQueryResult.fromXML(responseContent, WxPayRefundQueryResult.class); result.composeRefundRecords(); @@ -150,10 +158,10 @@ public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) this.initRequest(request); request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/mmpaymkttransfers/sendredpack"; + String url = this.getPayBaseUrl() + "/mmpaymkttransfers/sendredpack"; if (request.getAmtType() != null) { //裂变红包 - url = PAY_BASE_URL + "/mmpaymkttransfers/sendgroupredpack"; + url = this.getPayBaseUrl() + "/mmpaymkttransfers/sendgroupredpack"; } String responseContent = this.executeWithKey(url, request.toXML()); WxPaySendRedpackResult result = WxPaySendRedpackResult.fromXML(responseContent, WxPaySendRedpackResult.class); @@ -169,7 +177,7 @@ public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxErrorExce initRequest(request); request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/mmpaymkttransfers/gethbinfo"; + String url = this.getPayBaseUrl() + "/mmpaymkttransfers/gethbinfo"; String responseContent = this.executeWithKey(url, request.toXML()); WxPayRedpackQueryResult result = WxPayRedpackQueryResult.fromXML(responseContent, WxPayRedpackQueryResult.class); this.checkResult(result); @@ -189,7 +197,7 @@ public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) initRequest(request); request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/pay/orderquery"; + String url = this.getPayBaseUrl() + "/pay/orderquery"; String responseContent = this.executeRequest(url, request.toXML()); WxPayOrderQueryResult result = WxPayOrderQueryResult.fromXML(responseContent, WxPayOrderQueryResult.class); result.composeCoupons(); @@ -208,7 +216,7 @@ public WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxErrorExcepti initRequest(request); request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/pay/closeorder"; + String url = this.getPayBaseUrl() + "/pay/closeorder"; String responseContent = this.executeRequest(url, request.toXML()); WxPayOrderCloseResult result = WxPayOrderCloseResult.fromXML(responseContent, WxPayOrderCloseResult.class); this.checkResult(result); @@ -230,7 +238,7 @@ public WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) checkParameters(request);//校验参数 request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/pay/unifiedorder"; + String url = this.getPayBaseUrl() + "/pay/unifiedorder"; String xmlParam = request.toXML(); log.debug("微信统一下单接口,URL:{},参数:{}", url, xmlParam); @@ -298,7 +306,7 @@ public WxEntPayResult entPay(WxEntPayRequest request) throws WxErrorException { BeanUtils.checkRequiredFields(request); request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/mmpaymkttransfers/promotion/transfers"; + String url = this.getPayBaseUrl() + "/mmpaymkttransfers/promotion/transfers"; String responseContent = this.executeWithKey(url, request.toXML()); WxEntPayResult result = WxEntPayResult.fromXML(responseContent, WxEntPayResult.class); @@ -312,7 +320,7 @@ public WxEntPayQueryResult queryEntPay(String partnerTradeNo) throws WxErrorExce this.initRequest(request); request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/mmpaymkttransfers/gettransferinfo"; + String url = this.getPayBaseUrl() + "/mmpaymkttransfers/gettransferinfo"; String responseContent = this.executeWithKey(url, request.toXML()); WxEntPayQueryResult result = WxEntPayQueryResult.fromXML(responseContent, WxEntPayQueryResult.class); this.checkResult(result); @@ -359,9 +367,9 @@ public void report(WxPayReportRequest request) throws WxErrorException { this.initRequest(request); request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/payitil/report"; + String url = this.getPayBaseUrl() + "/payitil/report"; String responseContent = this.wxMpService.post(url, request.toXML()); - WxPayBaseResult result = WxPayBaseResult.fromXML(responseContent, WxPayBaseResult.class); + WxPayCommonResult result = WxPayBaseResult.fromXML(responseContent, WxPayCommonResult.class); this.checkResult(result); } @@ -435,6 +443,11 @@ public String createSign(Map params) { @Override public String createSign(Map params, String signKey) { + if(this.getConfig().useSandboxForWxPay()){ + //使用仿真测试环境 + return "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456"; + } + SortedMap sortedMap = new TreeMap<>(params); StringBuilder toSign = new StringBuilder(); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java index 88334aa76d..4dd133abea 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java @@ -24,8 +24,7 @@ * @author binarywang(Binary Wang) *
    */ -@XStreamAlias("xml") -public class WxPayBaseResult { +public abstract class WxPayBaseResult { /** * 返回状态码 */ diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayCommonResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayCommonResult.java new file mode 100644 index 0000000000..a6e7de5fe8 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayCommonResult.java @@ -0,0 +1,15 @@ +package me.chanjar.weixin.mp.bean.pay.result; + +import com.thoughtworks.xstream.annotations.XStreamAlias; + +/** + *
    + * 微信支付结果仅包含有return 和result等相关信息的的属性类
    + * Created by Binary Wang on 2017-01-09.
    + * @author binarywang(Binary Wang)
    + * 
    + */ + +@XStreamAlias("xml") +public class WxPayCommonResult extends WxPayBaseResult { +} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java index 1ab04cf101..f2a54d49be 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java @@ -64,4 +64,9 @@ public void setTemplateId(String templateId) { public void setAccessTokenLock(Lock lock){ super.accessTokenLock = lock; } + + @Override + public boolean useSandboxForWxPay() { + return true; + } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index 7e28cb43a2..abdfb63a24 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -8,13 +8,14 @@ import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; import me.chanjar.weixin.mp.bean.pay.request.*; import me.chanjar.weixin.mp.bean.pay.result.*; -import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; import java.nio.file.Files; import java.nio.file.Path; +import static org.testng.Assert.*; + /** * 测试支付相关接口 * Created by Binary Wang on 2016/7/28. @@ -52,6 +53,7 @@ public void setSSLKey(){ WxXmlMpInMemoryConfigStorage config = (WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); config.setSslContextFilePath(config.getKeyPath()); } + /** * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#refund(WxPayRefundRequest)} . */ @@ -163,8 +165,8 @@ public void testCreateScanPayQrcodeMode1() throws Exception { String qrcodeContent = QrcodeUtils.decodeQrcode(qrcodeFilePath.toFile()); System.out.println(qrcodeContent); - Assert.assertTrue(qrcodeContent.startsWith("weixin://wxpay/bizpayurl?")); - Assert.assertTrue(qrcodeContent.contains("product_id=" + productId)); + assertTrue(qrcodeContent.startsWith("weixin://wxpay/bizpayurl?")); + assertTrue(qrcodeContent.contains("product_id=" + productId)); } @Test @@ -174,7 +176,7 @@ public void testCreateScanPayQrcodeMode2() throws Exception { Path qrcodeFilePath = Files.createTempFile("qrcode_", ".jpg"); Files.write(qrcodeFilePath, bytes); - Assert.assertEquals(QrcodeUtils.decodeQrcode(qrcodeFilePath.toFile()), qrcodeContent); + assertEquals(QrcodeUtils.decodeQrcode(qrcodeFilePath.toFile()), qrcodeContent); } From eeb0452d649096ab1a604c6176a3f27cff47029d Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 9 Jan 2017 13:57:05 +0800 Subject: [PATCH 57/80] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B0=83=E6=95=B4pom?= =?UTF-8?q?=E6=96=87=E4=BB=B6=EF=BC=8C=E5=B0=86jedis=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E7=A7=BB=E5=85=A5cp=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 11 +--- weixin-java-cp/pom.xml | 128 +++++++++++++++++++++-------------------- 2 files changed, 69 insertions(+), 70 deletions(-) diff --git a/pom.xml b/pom.xml index 2092494c40..7a3697ce81 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"> 4.0.0 com.github.binarywang weixin-java-parent @@ -99,7 +99,6 @@ 4.5 1.7.10 1.1.2 - 2.9.0 2.7 19.0 3.5 @@ -150,12 +149,6 @@ commons-lang3 ${commons-lang3.version} - - redis.clients - jedis - ${jedis.version} - true - com.google.guava guava diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index 9b5f38771e..79d6830877 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -1,68 +1,74 @@ - 4.0.0 - - com.github.binarywang - weixin-java-parent - 2.4.8.BETA - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"> + 4.0.0 + + com.github.binarywang + weixin-java-parent + 2.4.8.BETA + - weixin-java-cp - WeiXin Java Tools - CP - 微信企业号Java SDK + weixin-java-cp + WeiXin Java Tools - CP + 微信企业号Java SDK - - - com.github.binarywang - weixin-java-common - ${project.version} - - - junit - junit - test - - - org.testng - testng - test - - - org.mockito - mockito-all - test - - - com.google.inject - guice - test - - - org.eclipse.jetty - jetty-server - test - - - org.eclipse.jetty - jetty-servlet - test - - + + + com.github.binarywang + weixin-java-common + ${project.version} + + + junit + junit + test + + + org.testng + testng + test + + + org.mockito + mockito-all + test + + + com.google.inject + guice + test + + + org.eclipse.jetty + jetty-server + test + + + org.eclipse.jetty + jetty-servlet + test + + + redis.clients + jedis + 2.9.0 + true + + - - - - org.apache.maven.plugins - maven-surefire-plugin - - - src/test/resources/testng.xml - - - - - + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/resources/testng.xml + + + + + From b1f3b71a091c6def2109853c579aff3190c2510e Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 9 Jan 2017 16:11:54 +0800 Subject: [PATCH 58/80] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=B8=A6=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=9A=84=E4=BA=8C=E7=BB=B4=E7=A0=81=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=96=87=E6=A1=A3=E6=B3=A8=E9=87=8A=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E5=8A=A0=E5=85=A5=E5=AF=B9=E6=9C=89=E6=95=88=E6=9C=9F?= =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpQrcodeService.java | 20 +++++++++---------- .../mp/api/impl/WxMpQrcodeServiceImpl.java | 12 ++++++++++- .../api/impl/WxMpQrCodeServiceImplTest.java | 2 +- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java index 893712081e..ddfd02a57d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java @@ -7,7 +7,7 @@ /** * 二维码相关操作接口 - * + * 文档地址:https://mp.weixin.qq.com/wiki?action=doc&id=mp1443433542&t=0.9274944716856435 * @author Binary Wang */ public interface WxMpQrcodeService { @@ -15,28 +15,28 @@ public interface WxMpQrcodeService { /** *
        * 换取临时二维码ticket
    -   * 详情请见: 生成带参数的二维码
    +   * 详情请见: 生成带参数的二维码
        * 
    * - * @param sceneId 参数。 - * @param expireSeconds 过期秒数,默认60秒,最小60秒,最大1800秒 + * @param sceneId 场景值ID,临时二维码时为32位非0整型 + * @param expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。 */ WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException; /** *
        * 换取永久二维码ticket
    -   * 详情请见: 生成带参数的二维码
    +   * 详情请见: 生成带参数的二维码
        * 
    * - * @param sceneId 参数。永久二维码时最大值为100000(目前参数只支持1--100000) + * @param sceneId 场景值ID,最大值为100000(目前参数只支持1--100000) */ WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId) throws WxErrorException; /** *
        * 换取永久字符串二维码ticket
    -   * 详情请见: 生成带参数的二维码
    +   * 详情请见: 生成带参数的二维码
        * 
    * * @param sceneStr 参数。字符串类型长度现在为1到64 @@ -46,7 +46,7 @@ public interface WxMpQrcodeService { /** *
        * 换取二维码图片文件,jpg格式
    -   * 详情请见: 生成带参数的二维码
    +   * 详情请见: 生成带参数的二维码
        * 
    * * @param ticket 二维码ticket @@ -56,7 +56,7 @@ public interface WxMpQrcodeService { /** *
        * 换取二维码图片url地址(可以选择是否生成压缩的网址)
    -   * 详情请见: 生成带参数的二维码
    +   * 详情请见: 生成带参数的二维码
        * 
    * * @param ticket 二维码ticket @@ -67,7 +67,7 @@ public interface WxMpQrcodeService { /** *
        * 换取二维码图片url地址
    -   * 详情请见: 生成带参数的二维码
    +   * 详情请见: 生成带参数的二维码
        * 
    * * @param ticket 二维码ticket diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java index 9726b37383..5b00720a0d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java @@ -28,7 +28,17 @@ public WxMpQrcodeServiceImpl(WxMpService wxMpService) { @Override public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException { if (sceneId == 0) { - throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("临时二维码场景只不能为0!").build()); + throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("临时二维码场景值不能为0!").build()); + } + + //expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。 + if (expireSeconds != null && expireSeconds > 2592000) { + throw new WxErrorException(WxError.newBuilder().setErrorCode(-1) + .setErrorMsg("临时二维码有效时间最大不能超过2592000(即30天)!").build()); + } + + if (expireSeconds == null) { + expireSeconds = 30; } String url = API_URL_PREFIX + "/create"; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java index a2ab5328ef..d1475dfe57 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java @@ -19,7 +19,7 @@ */ @Test(groups = "qrCodeAPI") @Guice(modules = ApiTestModule.class) -public class WxMpQrCodeServiceImplTest { +public class WxMpQrcodeServiceImplTest { @Inject protected WxMpService wxService; From c5bf83c57b9dfc92d4c3f79bed7692652493312f Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 9 Jan 2017 16:13:20 +0800 Subject: [PATCH 59/80] rename file --- ...QrCodeServiceImplTest.java => WxMpQrcodeServiceImplTest1.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/{WxMpQrCodeServiceImplTest.java => WxMpQrcodeServiceImplTest1.java} (100%) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest1.java similarity index 100% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest1.java From b9908af8fb97ffb13eddb5e8d76e23ebee9c8e7e Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 9 Jan 2017 16:13:34 +0800 Subject: [PATCH 60/80] rename file --- .../chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest1.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest1.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest1.java index d1475dfe57..c7c6965a11 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest1.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest1.java @@ -19,7 +19,7 @@ */ @Test(groups = "qrCodeAPI") @Guice(modules = ApiTestModule.class) -public class WxMpQrcodeServiceImplTest { +public class WxMpQrcodeServiceImplTest1 { @Inject protected WxMpService wxService; From 5d30aa3ada5d8e5f765eb701f4dd2b1f5b542f3b Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 9 Jan 2017 16:13:59 +0800 Subject: [PATCH 61/80] rename file --- ...QrcodeServiceImplTest1.java => WxMpQrcodeServiceImplTest.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/{WxMpQrcodeServiceImplTest1.java => WxMpQrcodeServiceImplTest.java} (100%) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest1.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java similarity index 100% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest1.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java From ab3b2249a9f6cfe01898305fe37aea71fa48d0b9 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 9 Jan 2017 16:14:07 +0800 Subject: [PATCH 62/80] rename file --- .../chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java index c7c6965a11..d1475dfe57 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java @@ -19,7 +19,7 @@ */ @Test(groups = "qrCodeAPI") @Guice(modules = ApiTestModule.class) -public class WxMpQrcodeServiceImplTest1 { +public class WxMpQrcodeServiceImplTest { @Inject protected WxMpService wxService; From 9e0fcb34d03fbce012eff83ba265cd1196d7d0a8 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 9 Jan 2017 16:14:41 +0800 Subject: [PATCH 63/80] =?UTF-8?q?=E5=BC=95=E5=85=A5=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E4=BD=BF=E5=BE=97=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E8=83=BD=E5=A4=9F=E6=94=AF=E6=8C=81=E4=BB=BF?= =?UTF-8?q?=E7=9C=9F=E6=B5=8B=E8=AF=95=E7=8E=AF=E5=A2=83=20#119?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java | 4 +++- .../chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java | 5 ++++- weixin-java-mp/src/test/resources/testng.xml | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) 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 dde6431a13..b4813a339e 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 @@ -445,7 +445,9 @@ public String createSign(Map params) { public String createSign(Map params, String signKey) { if(this.getConfig().useSandboxForWxPay()){ //使用仿真测试环境 - return "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456"; + //TODO 目前测试发现,以下两行代码都会出问题,所以暂不建议使用这个仿真测试环境 + signKey = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456"; + //return "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456"; } SortedMap sortedMap = new TreeMap<>(params); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index abdfb63a24..783bdb8608 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -73,7 +73,10 @@ public void testRefund() throws Exception { */ @Test public void testRefundQuery() throws Exception { - WxPayRefundQueryResult result = this.wxService.getPayService().refundQuery("1", "", "", ""); + WxPayRefundQueryResult result; + + result = this.wxService.getPayService().refundQuery("1", "", "", ""); + System.err.println(result); result = this.wxService.getPayService().refundQuery("", "2", "", ""); System.err.println(result); result = this.wxService.getPayService().refundQuery("", "", "3", ""); diff --git a/weixin-java-mp/src/test/resources/testng.xml b/weixin-java-mp/src/test/resources/testng.xml index d14999835a..a358cf1ceb 100644 --- a/weixin-java-mp/src/test/resources/testng.xml +++ b/weixin-java-mp/src/test/resources/testng.xml @@ -7,7 +7,7 @@ - + From 8e831ac96184ecb5d86451f070da1707e63e0d58 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Wed, 11 Jan 2017 17:52:48 +0800 Subject: [PATCH 64/80] =?UTF-8?q?=E7=BE=A4=E5=8F=91=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0isSendAll=E5=B1=9E=E6=80=A7=E5=8F=8A=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=96=B9=E6=B3=95=EF=BC=8C=E7=94=A8=E4=BA=8E=E6=98=BE?= =?UTF-8?q?=E5=BC=8F=E6=8C=87=E5=AE=9A=E6=98=AF=E5=90=A6=E7=BE=A4=E5=8F=91?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E8=87=B3=E6=89=80=E6=9C=89=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/bean/WxMpMassTagMessage.java | 15 +++++++++++++++ .../util/json/WxMpMassTagMessageGsonAdapter.java | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java index 083e5605a6..bf1ded1a92 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java @@ -16,6 +16,7 @@ public class WxMpMassTagMessage implements Serializable { private String msgType; private String content; private String mediaId; + private boolean isSendAll = false; private boolean sendIgnoreReprint = false; public WxMpMassTagMessage() { @@ -88,4 +89,18 @@ public void setSendIgnoreReprint(boolean sendIgnoreReprint) { this.sendIgnoreReprint = sendIgnoreReprint; } + /** + * 是否群发给所有用户 + */ + public boolean isSendAll() { + return isSendAll; + } + + public void setSendAll(boolean sendAll) { + if(sendAll){ + this.tagId = null; + } + + isSendAll = sendAll; + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassTagMessageGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassTagMessageGsonAdapter.java index 38e9515f2e..5b133b0ed1 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassTagMessageGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassTagMessageGsonAdapter.java @@ -24,7 +24,7 @@ public JsonElement serialize(WxMpMassTagMessage message, Type typeOfSrc, JsonSer JsonObject messageJson = new JsonObject(); JsonObject filter = new JsonObject(); - if (null == message.getTagId()) { + if (message.isSendAll() || null == message.getTagId()) { filter.addProperty("is_to_all", true); } else { filter.addProperty("is_to_all", false); From e640b058b50f467d5132be643ac6026b4fd33174 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 12 Jan 2017 11:09:24 +0800 Subject: [PATCH 65/80] =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=B8=AD=E6=9A=82=E6=97=B6=E5=B1=8F=E8=94=BD=E6=8E=89=E6=B2=99?= =?UTF-8?q?=E7=AE=B1=E6=B5=8B=E8=AF=95=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java index f2a54d49be..e51ffeb6e5 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java @@ -67,6 +67,8 @@ public void setAccessTokenLock(Lock lock){ @Override public boolean useSandboxForWxPay() { - return true; + return false; + //沙箱环境不成熟,有问题无法使用,暂时屏蔽掉 + // return true; } } From c8441650d0e27b33f97bb8c8754db2758eb1800b Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 12 Jan 2017 11:09:50 +0800 Subject: [PATCH 66/80] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=A1=A5=E5=85=85?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mp/bean/pay/result/WxPayUnifiedOrderResult.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayUnifiedOrderResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayUnifiedOrderResult.java index 70c135192e..5097cd10de 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayUnifiedOrderResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayUnifiedOrderResult.java @@ -13,12 +13,21 @@ @XStreamAlias("xml") public class WxPayUnifiedOrderResult extends WxPayBaseResult { + /** + * 微信生成的预支付回话标识,用于后续接口调用中使用,该值有效期为2小时 + */ @XStreamAlias("prepay_id") private String prepayId; + /** + * 交易类型,取值为:JSAPI,NATIVE,APP等 + */ @XStreamAlias("trade_type") private String tradeType; + /** + * trade_type为NATIVE时有返回,用于生成二维码,展示给用户进行扫码支付 + */ @XStreamAlias("code_url") private String codeURL; From a2398ddeb1ee16a87bfb827098289c4bd258474b Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 12 Jan 2017 11:10:42 +0800 Subject: [PATCH 67/80] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/common/util/BeanUtils.java | 94 ++++++++++--------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/BeanUtils.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/BeanUtils.java index 7c3db11f80..630821e954 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/BeanUtils.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/BeanUtils.java @@ -1,21 +1,20 @@ package me.chanjar.weixin.common.util; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.thoughtworks.xstream.annotations.XStreamAlias; - import me.chanjar.weixin.common.annotation.Required; import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; /** *
    @@ -25,25 +24,28 @@
      * 
    */ public class BeanUtils { - private static Logger log = LoggerFactory.getLogger(BeanUtils.class); + private static Logger log = LoggerFactory.getLogger(BeanUtils.class); /** * 检查bean里标记为@Required的field是否为空,为空则抛异常 + * * @param bean 要检查的bean对象 * @throws WxErrorException */ public static void checkRequiredFields(Object bean) throws WxErrorException { - List nullFields = Lists.newArrayList(); + List requiredFields = Lists.newArrayList(); - List fields = new ArrayList<>( Arrays.asList(bean.getClass().getDeclaredFields())); + List fields = new ArrayList<>(Arrays.asList(bean.getClass().getDeclaredFields())); fields.addAll(Arrays.asList(bean.getClass().getSuperclass().getDeclaredFields())); for (Field field : fields) { try { boolean isAccessible = field.isAccessible(); field.setAccessible(true); - if (field.isAnnotationPresent(Required.class) - && field.get(bean) == null) { - nullFields.add(field.getName()); + if (field.isAnnotationPresent(Required.class)) { + if (field.get(bean) == null || (field.get(bean) instanceof String && StringUtils.isBlank(field.get(bean).toString()))) { + //两种情况,一种是值为null,另外一种情况是类型为字符串,但是字符串内容为空的,都认为是没有提供值 + requiredFields.add(field.getName()); + } } field.setAccessible(isAccessible); } catch (SecurityException | IllegalArgumentException @@ -52,43 +54,43 @@ public static void checkRequiredFields(Object bean) throws WxErrorException { } } - if (!nullFields.isEmpty()) { - String msg = "必填字段 " + nullFields + " 必须提供值"; + if (!requiredFields.isEmpty()) { + String msg = "必填字段 " + requiredFields + " 必须提供值"; log.debug(msg); throw new WxErrorException(WxError.newBuilder().setErrorMsg(msg).build()); } } - /** - * 将bean按照@XStreamAlias标识的字符串内容生成以之为key的map对象 - * - * @param bean 包含@XStreamAlias的xml bean对象 - * @return map对象 - */ - public static Map xmlBean2Map(Object bean) { - Map result = Maps.newHashMap(); - List fields = new ArrayList<>(Arrays.asList(bean.getClass().getDeclaredFields())); - fields.addAll(Arrays.asList(bean.getClass().getSuperclass().getDeclaredFields())); - for (Field field : fields) { - try { - boolean isAccessible = field.isAccessible(); - field.setAccessible(true); - if (field.get(bean) == null) { - field.setAccessible(isAccessible); - continue; - } + /** + * 将bean按照@XStreamAlias标识的字符串内容生成以之为key的map对象 + * + * @param bean 包含@XStreamAlias的xml bean对象 + * @return map对象 + */ + public static Map xmlBean2Map(Object bean) { + Map result = Maps.newHashMap(); + List fields = new ArrayList<>(Arrays.asList(bean.getClass().getDeclaredFields())); + fields.addAll(Arrays.asList(bean.getClass().getSuperclass().getDeclaredFields())); + for (Field field : fields) { + try { + boolean isAccessible = field.isAccessible(); + field.setAccessible(true); + if (field.get(bean) == null) { + field.setAccessible(isAccessible); + continue; + } - if (field.isAnnotationPresent(XStreamAlias.class)) { - result.put(field.getAnnotation(XStreamAlias.class).value(), field.get(bean).toString()); - } + if (field.isAnnotationPresent(XStreamAlias.class)) { + result.put(field.getAnnotation(XStreamAlias.class).value(), field.get(bean).toString()); + } - field.setAccessible(isAccessible); - } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { - e.printStackTrace(); - } + field.setAccessible(isAccessible); + } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + } - } + } - return result; - } + return result; + } } From e97c15b6cef83216d6798afd24ce6c69ad9a9460 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 12 Jan 2017 11:12:08 +0800 Subject: [PATCH 68/80] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E4=B8=8B=E8=BD=BD=E5=AF=B9=E8=B4=A6=E5=8D=95?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3=EF=BC=8C=E8=BF=98=E6=9C=AA=E5=AE=8C?= =?UTF-8?q?=E6=88=90=EF=BC=8C=E5=BE=85=E8=B0=83=E8=AF=95=20#65?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/mp/api/WxMpPayService.java | 31 ++++- .../mp/api/impl/WxMpPayServiceImpl.java | 34 +++++ .../pay/request/WxPayDownloadBillRequest.java | 123 ++++++++++++++++++ .../mp/api/impl/WxMpPayServiceImplTest.java | 13 +- 4 files changed, 195 insertions(+), 6 deletions(-) create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayDownloadBillRequest.java 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 a6dd6654e7..004cd5bcc5 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 @@ -240,9 +240,10 @@ public interface WxMpPayService { * 其中XXXXX为商户需要填写的内容,商户将该链接生成二维码,如需要打印发布二维码,需要采用此格式。商户可调用第三方库生成二维码图片。 * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_4 *
    - * @param productId 产品Id + * + * @param productId 产品Id * @param sideLength 要生成的二维码的边长,如果为空,则取默认值400 - * @param logoFile 商户logo图片的文件对象,可以为空 + * @param logoFile 商户logo图片的文件对象,可以为空 * @return 生成的二维码的字节数组 */ byte[] createScanPayQrcodeMode1(String productId, File logoFile, Integer sideLength); @@ -254,8 +255,9 @@ public interface WxMpPayService { * 该模式链接较短,生成的二维码打印到结账小票上的识别率较高。 * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_5 *
    - * @param codeUrl 微信返回的交易会话的二维码链接 - * @param logoFile 商户logo图片的文件对象,可以为空 + * + * @param codeUrl 微信返回的交易会话的二维码链接 + * @param logoFile 商户logo图片的文件对象,可以为空 * @param sideLength 要生成的二维码的边长,如果为空,则取默认值400 * @return 生成的二维码的字节数组 */ @@ -273,4 +275,25 @@ public interface WxMpPayService { *
    */ void report(WxPayReportRequest request) throws WxErrorException; + + /** + *
    +   * 下载对账单
    +   * 商户可以通过该接口下载历史交易清单。比如掉单、系统错误等导致商户侧和微信侧数据不一致,通过对账单核对后可校正支付状态。
    +   * 注意:
    +   * 1、微信侧未成功下单的交易不会出现在对账单中。支付成功后撤销的交易会出现在对账单中,跟原支付单订单号一致,bill_type为REVOKED;
    +   * 2、微信在次日9点启动生成前一天的对账单,建议商户10点后再获取;
    +   * 3、对账单中涉及金额的字段单位为“元”。
    +   * 4、对账单接口只能下载三个月以内的账单。
    +   * 接口链接:https://api.mch.weixin.qq.com/pay/downloadbill
    +   * 详情请见: 下载对账单
    +   * 
    + * + * @param billDate 对账单日期 bill_date 下载对账单的日期,格式:20140603 + * @param billType 账单类型 bill_type ALL,返回当日所有订单信息,默认值,SUCCESS,返回当日成功支付的订单,REFUND,返回当日退款订单 + * @param tarType 压缩账单 tar_type 非必传参数,固定值:GZIP,返回格式为.gzip的压缩包账单。不传则默认为数据流形式。 + * @param deviceInfo 设备号 device_info 非必传参数,终端设备号 + * @return 保存到本地的临时文件 + */ + File downloadBill(String billDate, String billType, String tarType, String deviceInfo) throws WxErrorException; } 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 b4813a339e..b0ccacd94e 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 @@ -41,6 +41,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { private static final String PAY_BASE_URL = "https://api.mch.weixin.qq.com"; private static final String[] TRADE_TYPES = new String[]{"JSAPI", "NATIVE", "APP"}; private static final String[] REFUND_ACCOUNT = new String[]{"REFUND_SOURCE_RECHARGE_FUNDS", "REFUND_SOURCE_UNSETTLED_FUNDS"}; + private static final String[] BILL_TYPE = new String[]{"ALL","REFUND","SUCCESS"};; private final Logger log = LoggerFactory.getLogger(this.getClass()); private WxMpService wxMpService; @@ -121,6 +122,19 @@ private void checkResult(WxPayBaseResult result) throws WxErrorException { } } + private void checkParameters(WxPayDownloadBillRequest request) throws WxErrorException { + BeanUtils.checkRequiredFields(request); + + if (StringUtils.isNotBlank(request.getTarType()) && !"GZIP".equals(request.getTarType())) { + throw new IllegalArgumentException("tar_type值如果存在,只能为GZIP"); + } + + if ( !ArrayUtils.contains(BILL_TYPE, request.getBillType())) { + throw new IllegalArgumentException("bill_tpye目前必须为" + Arrays.toString(BILL_TYPE) + "其中之一,实际值:" + request.getBillType()); + } + + } + private void checkParameters(WxPayRefundRequest request) throws WxErrorException { BeanUtils.checkRequiredFields(request); @@ -373,6 +387,26 @@ public void report(WxPayReportRequest request) throws WxErrorException { this.checkResult(result); } + @Override + public File downloadBill(String billDate, String billType, String tarType, String deviceInfo) throws WxErrorException { + WxPayDownloadBillRequest request = new WxPayDownloadBillRequest(); + this.initRequest(request); + request.setBillType(billType); + request.setBillDate(billDate); + request.setTarType(tarType); + request.setDeviceInfo(deviceInfo); + this.checkParameters(request); + request.setSign(this.createSign(request)); + + String url = this.getPayBaseUrl() + "/pay/downloadbill"; + //TODO 返回的内容可能是文件流,也有可能是xml,需要区分对待 + String responseContent = this.wxMpService.post(url, request.toXML()); + + WxPayCommonResult result = WxPayBaseResult.fromXML(responseContent, WxPayCommonResult.class); + this.checkResult(result); + return null; + } + private String executeRequest(String url, String requestStr) throws WxErrorException { HttpPost httpPost = new HttpPost(url); if (this.wxMpService.getHttpProxy() != null) { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayDownloadBillRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayDownloadBillRequest.java new file mode 100644 index 0000000000..9e1ab4dcf8 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayDownloadBillRequest.java @@ -0,0 +1,123 @@ +package me.chanjar.weixin.mp.bean.pay.request; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import me.chanjar.weixin.common.annotation.Required; + +/** + *
    + *   微信支付下载对账单请求参数类
    + * Created by Binary Wang on 2017-01-11.
    + * @author binarywang(Binary Wang)
    + * 
    + */ +@XStreamAlias("xml") +public class WxPayDownloadBillRequest extends WxPayBaseRequest { + /** + *
    +   * 设备号
    +   * device_info
    +   * 否
    +   * String(32)
    +   * 13467007045764
    +   * 终端设备号
    +   * 
    + */ + @XStreamAlias("device_info") + private String deviceInfo; + + /** + *
    +   * 签名类型
    +   * sign_type
    +   * 否
    +   * String(32)
    +   * HMAC-SHA256
    +   * 签名类型,目前支持HMAC-SHA256和MD5,默认为MD5
    +   * 
    + */ + @XStreamAlias("sign_type") + private String signType; + + /** + *
    +   * 账单类型
    +   * bill_type
    +   * 是
    +   * ALL
    +   * String(8)
    +   * --ALL,返回当日所有订单信息,默认值
    +   * --SUCCESS,返回当日成功支付的订单
    +   * --REFUND,返回当日退款订单
    +   * 
    + */ + @Required + @XStreamAlias("bill_type") + private String billType; + + /** + *
    +   * 对账单日期
    +   * bill_date
    +   * 是
    +   * String(8)
    +   * 20140603
    +   * 下载对账单的日期,格式:20140603
    +   * 
    + */ + @Required + @XStreamAlias("bill_date") + private String billDate; + + /** + *
    +   * 压缩账单
    +   * tar_type
    +   * 否
    +   * String(8)
    +   * GZIP
    +   * 非必传参数,固定值:GZIP,返回格式为.gzip的压缩包账单。不传则默认为数据流形式。
    +   * 
    + */ + @XStreamAlias("tar_type") + private String tarType; + + public String getDeviceInfo() { + return deviceInfo; + } + + public void setDeviceInfo(String deviceInfo) { + this.deviceInfo = deviceInfo; + } + + public String getSignType() { + return signType; + } + + public void setSignType(String signType) { + this.signType = signType; + } + + public String getBillType() { + return billType; + } + + public void setBillType(String billType) { + this.billType = billType; + } + + public String getBillDate() { + return billDate; + } + + public void setBillDate(String billDate) { + this.billDate = billDate; + } + + public String getTarType() { + return tarType; + } + + public void setTarType(String tarType) { + this.tarType = tarType; + } +} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index 783bdb8608..f46765c77d 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -8,9 +8,9 @@ import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; import me.chanjar.weixin.mp.bean.pay.request.*; import me.chanjar.weixin.mp.bean.pay.result.*; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.annotations.*; +import java.io.File; import java.nio.file.Files; import java.nio.file.Path; @@ -25,6 +25,7 @@ @Test @Guice(modules = ApiTestModule.class) public class WxMpPayServiceImplTest { + @Inject protected WxMpService wxService; @@ -33,6 +34,14 @@ public void testGetPayInfo() throws Exception { } + @Test + public void testDownloadBill() throws Exception { + File file = this.wxService.getPayService().downloadBill("20170101","ALL","GZIP","1111111"); + assertNotNull(file); + //必填字段为空时,抛出异常 + this.wxService.getPayService().downloadBill("","","",null); + } + @Test public void testReport() throws Exception { WxPayReportRequest request = new WxPayReportRequest(); From 69aaa74eefb282a4b3ee725d70792e6ccec16d03 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 16 Jan 2017 18:12:08 +0800 Subject: [PATCH 69/80] =?UTF-8?q?=E4=BF=AE=E5=A4=8DmenuTryMatch=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E8=AF=B7=E6=B1=82=E6=96=B9=E5=BC=8F=E7=94=B1?= =?UTF-8?q?get=E5=8F=98=E6=9B=B4=E4=B8=BApost=EF=BC=8C#125?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java | 5 ++++- .../chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) 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 579d5c72dd..e05b6a8076 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,5 +1,6 @@ package me.chanjar.weixin.mp.api.impl; +import com.google.gson.JsonObject; import me.chanjar.weixin.common.bean.menu.WxMenu; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.WxMpMenuService; @@ -68,8 +69,10 @@ public WxMenu menuGet() throws WxErrorException { @Override public WxMenu menuTryMatch(String userid) throws WxErrorException { String url = API_URL_PREFIX + "/trymatch"; + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("user_id",userid); try { - String resultContent = this.wxMpService.get(url, "user_id=" + userid); + String resultContent = this.wxMpService.post(url, jsonObject.toString()); return WxMenu.fromJson(resultContent); } catch (WxErrorException e) { // 46003 不存在的菜单数据 46002 不存在的菜单版本 diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java index a312b15d6f..526859205f 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java @@ -34,7 +34,8 @@ public void testMenuCreate(WxMenu wxMenu) throws WxErrorException { @Test public void testMenuTryMatch() throws Exception { - //TODO + WxMenu menu = this.wxService.getMenuService().menuTryMatch("..."); + System.out.println(menu); } @Test From 41d596654c3918bafb1ff6b181d2970e9b6c5fe9 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 17 Jan 2017 12:11:15 +0800 Subject: [PATCH 70/80] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E4=B8=AA=E6=80=A7=E5=8C=96=E8=8F=9C=E5=8D=95=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=20#127?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/me/chanjar/weixin/mp/api/WxMpMenuService.java | 8 ++++---- .../weixin/mp/api/impl/WxMpMenuServiceImpl.java | 10 ++++++---- .../weixin/mp/api/impl/WxMpMenuServiceImplTest.java | 6 ++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java index 9435902535..47ec17ec51 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java @@ -24,7 +24,7 @@ public interface WxMpMenuService { /** *
        * 自定义菜单删除接口
    -   * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单删除接口
    +   * 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141015&token=&lang=zh_CN
        * 
    */ void menuDelete() throws WxErrorException; @@ -32,12 +32,12 @@ public interface WxMpMenuService { /** *
        * 删除个性化菜单接口
    -   * 详情请见: http://mp.weixin.qq.com/wiki/0/c48ccd12b69ae023159b4bfaa7c39c20.html
    +   * 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1455782296&token=&lang=zh_CN
        * 
    * - * @param menuid + * @param menuId 个性化菜单的menuid */ - void menuDelete(String menuid) throws WxErrorException; + void menuDelete(String menuId) throws WxErrorException; /** *
    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 e05b6a8076..866e4c106f 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
    @@ -45,10 +45,12 @@ public void menuDelete() throws WxErrorException {
       }
     
       @Override
    -  public void menuDelete(String menuid) throws WxErrorException {
    +  public void menuDelete(String menuId) throws WxErrorException {
         String url = API_URL_PREFIX + "/delconditional";
    -    String result = this.wxMpService.get(url, "menuid=" + menuid);
    -    log.debug("根据MeunId({})删除菜单结果:{}", menuid, result);
    +    JsonObject jsonObject = new JsonObject();
    +    jsonObject.addProperty("menuid", menuId);
    +    String result = this.wxMpService.post(url, jsonObject.toString());
    +    log.debug("根据MeunId({})删除菜单结果:{}", menuId, result);
       }
     
       @Override
    @@ -70,7 +72,7 @@ public WxMenu menuGet() throws WxErrorException {
       public WxMenu menuTryMatch(String userid) throws WxErrorException {
         String url = API_URL_PREFIX + "/trymatch";
         JsonObject jsonObject = new JsonObject();
    -    jsonObject.addProperty("user_id",userid);
    +    jsonObject.addProperty("user_id", userid);
         try {
           String resultContent = this.wxMpService.post(url, jsonObject.toString());
           return WxMenu.fromJson(resultContent);
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java
    index 526859205f..1452c0567e 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java
    @@ -100,6 +100,12 @@ public void testMenuDelete() throws WxErrorException {
         this.wxService.getMenuService().menuDelete();
       }
     
    +  @Test
    +  public void testDeleteConditionalMenu() throws WxErrorException {
    +    String menuId = "123";
    +    this.wxService.getMenuService().menuDelete(menuId);
    +  }
    +
       @DataProvider(name="menu")
       public Object[][] getMenu() {
         WxMenu menu = new WxMenu();
    
    From d81a5e39c15dbecc834d4d44c95293c8ad97dc31 Mon Sep 17 00:00:00 2001
    From: Binary Wang 
    Date: Tue, 17 Jan 2017 13:57:56 +0800
    Subject: [PATCH 71/80] =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BB=A3=E7=A0=81?=
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    
    ---
     .../chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java  | 7 +++----
     1 file changed, 3 insertions(+), 4 deletions(-)
    
    diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java
    index 5b00720a0d..26d86baa86 100644
    --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java
    +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java
    @@ -3,7 +3,6 @@
     import com.google.gson.JsonObject;
     import me.chanjar.weixin.common.bean.result.WxError;
     import me.chanjar.weixin.common.exception.WxErrorException;
    -import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
     import me.chanjar.weixin.mp.api.WxMpQrcodeService;
     import me.chanjar.weixin.mp.api.WxMpService;
     import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
    @@ -52,7 +51,7 @@ public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds
         scene.addProperty("scene_id", sceneId);
         actionInfo.add("scene", scene);
         json.add("action_info", actionInfo);
    -    String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
    +    String responseContent = this.wxMpService.post(url, json.toString());
         return WxMpQrCodeTicket.fromJson(responseContent);
       }
     
    @@ -70,7 +69,7 @@ public WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId) throws WxErrorExcept
         scene.addProperty("scene_id", sceneId);
         actionInfo.add("scene", scene);
         json.add("action_info", actionInfo);
    -    String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
    +    String responseContent = this.wxMpService.post(url, json.toString());
         return WxMpQrCodeTicket.fromJson(responseContent);
       }
     
    @@ -84,7 +83,7 @@ public WxMpQrCodeTicket qrCodeCreateLastTicket(String sceneStr) throws WxErrorEx
         scene.addProperty("scene_str", sceneStr);
         actionInfo.add("scene", scene);
         json.add("action_info", actionInfo);
    -    String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
    +    String responseContent = this.wxMpService.post(url, json.toString());
         return WxMpQrCodeTicket.fromJson(responseContent);
       }
     
    
    From 5018c31e60996a5c44ebf4010d1771198f6d5c3e Mon Sep 17 00:00:00 2001
    From: Binary Wang 
    Date: Tue, 17 Jan 2017 14:45:42 +0800
    Subject: [PATCH 72/80] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=8C=E5=96=84?=
     =?UTF-8?q?=E8=8F=9C=E5=8D=95=E7=89=B9=E5=88=AB=E6=98=AF=E4=B8=AA=E6=80=A7?=
     =?UTF-8?q?=E5=8C=96=E8=8F=9C=E5=8D=95=E7=9A=84=E5=88=9B=E5=BB=BA=E5=92=8C?=
     =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?=
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    
    ---
     .../common/util/json/WxMenuGsonAdapter.java   |  29 ++--
     .../weixin/mp/api/WxMpMenuService.java        |  18 ++-
     .../mp/api/impl/WxMpMenuServiceImpl.java      |  30 +++-
     .../mp/api/impl/WxMpMenuServiceImplTest.java  | 149 +++++++++++-------
     4 files changed, 153 insertions(+), 73 deletions(-)
    
    diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java
    index 2cfbe2525a..eaaeec74a4 100644
    --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java
    +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java
    @@ -8,21 +8,13 @@
      */
     package me.chanjar.weixin.common.util.json;
     
    -import java.lang.reflect.Type;
    -
    -import com.google.gson.JsonArray;
    -import com.google.gson.JsonDeserializationContext;
    -import com.google.gson.JsonDeserializer;
    -import com.google.gson.JsonElement;
    -import com.google.gson.JsonObject;
    -import com.google.gson.JsonParseException;
    -import com.google.gson.JsonSerializationContext;
    -import com.google.gson.JsonSerializer;
    -
    +import com.google.gson.*;
     import me.chanjar.weixin.common.bean.menu.WxMenu;
     import me.chanjar.weixin.common.bean.menu.WxMenuButton;
     import me.chanjar.weixin.common.bean.menu.WxMenuRule;
     
    +import java.lang.reflect.Type;
    +
     
     /**
      * @author Daniel Qian
    @@ -76,6 +68,18 @@ protected JsonObject convertToJson(WxMenuRule menuRule) {
         return matchRule;
       }
     
    +  private WxMenuRule convertToRule(JsonObject json) {
    +    WxMenuRule menuRule = new WxMenuRule();
    +    menuRule.setTagId(GsonHelper.getString(json,"tag_id"));
    +    menuRule.setSex(GsonHelper.getString(json,"sex"));
    +    menuRule.setCountry(GsonHelper.getString(json,"country"));
    +    menuRule.setProvince(GsonHelper.getString(json,"province"));
    +    menuRule.setCity(GsonHelper.getString(json,"city"));
    +    menuRule.setClientPlatformType(GsonHelper.getString(json,"client_platform_type"));
    +    menuRule.setLanguage(GsonHelper.getString(json,"language"));
    +    return menuRule;
    +  }
    +
       @Override
       public WxMenu deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
         /*
    @@ -84,8 +88,7 @@ public WxMenu deserialize(JsonElement json, Type typeOfT, JsonDeserializationCon
          * 查询菜单时是 { menu : { button : ... } }
          */
         WxMenu menu = new WxMenu();
    -    JsonObject menuJson = json.getAsJsonObject().get("menu").getAsJsonObject();
    -    JsonArray buttonsJson = menuJson.get("button").getAsJsonArray();
    +    JsonArray buttonsJson = json.getAsJsonObject().get("menu").getAsJsonObject().get("button").getAsJsonArray();
         for (int i = 0; i < buttonsJson.size(); i++) {
           JsonObject buttonJson = buttonsJson.get(i).getAsJsonObject();
           WxMenuButton button = convertFromJson(buttonJson);
    diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java
    index 47ec17ec51..73660d3f9c 100644
    --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java
    +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java
    @@ -14,12 +14,24 @@ public interface WxMpMenuService {
       /**
        * 
        * 自定义菜单创建接口
    -   * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单创建接口
    +   * 详情请见:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141013&token=&lang=zh_CN
        * 如果要创建个性化菜单,请设置matchrule属性
    -   * 详情请见:http://mp.weixin.qq.com/wiki/0/c48ccd12b69ae023159b4bfaa7c39c20.html
    +   * 详情请见:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1455782296&token=&lang=zh_CN
        * 
    + * @return 如果是个性化菜单,则返回menuid,否则返回null */ - void menuCreate(WxMenu menu) throws WxErrorException; + String menuCreate(WxMenu menu) throws WxErrorException; + + /** + *
    +   * 自定义菜单创建接口
    +   * 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141013&token=&lang=zh_CN
    +   * 如果要创建个性化菜单,请设置matchrule属性
    +   * 详情请见:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1455782296&token=&lang=zh_CN
    +   * 
    + * @return 如果是个性化菜单,则返回menuid,否则返回null + */ + String menuCreate(String json) throws WxErrorException; /** *
    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 866e4c106f..20590e5a60 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,6 +1,7 @@
     package me.chanjar.weixin.mp.api.impl;
     
     import com.google.gson.JsonObject;
    +import com.google.gson.JsonParser;
     import me.chanjar.weixin.common.bean.menu.WxMenu;
     import me.chanjar.weixin.common.exception.WxErrorException;
     import me.chanjar.weixin.mp.api.WxMpMenuService;
    @@ -24,7 +25,7 @@ public WxMpMenuServiceImpl(WxMpService wxMpService) {
       }
     
       @Override
    -  public void menuCreate(WxMenu menu) throws WxErrorException {
    +  public String menuCreate(WxMenu menu) throws WxErrorException {
         String menuJson = menu.toJson();
         String url = API_URL_PREFIX + "/create";
         if (menu.getMatchRule() != null) {
    @@ -35,6 +36,29 @@ public void menuCreate(WxMenu menu) throws WxErrorException {
     
         String result = this.wxMpService.post(url, menuJson);
         log.debug("创建菜单:{},结果:{}", menuJson, result);
    +
    +    if (menu.getMatchRule() != null) {
    +      return new JsonParser().parse(result).getAsJsonObject().get("menuid").getAsString();
    +    }
    +
    +    return null;
    +  }
    +
    +  @Override
    +  public String menuCreate(String json) throws WxErrorException {
    +    JsonParser jsonParser = new JsonParser();
    +    JsonObject jsonObject = jsonParser.parse(json).getAsJsonObject();
    +    String url = API_URL_PREFIX + "/create";
    +    if (jsonObject.get("matchrule") != null) {
    +      url = API_URL_PREFIX + "/addconditional";
    +    }
    +
    +    String result = this.wxMpService.post(url, json);
    +    if (jsonObject.get("matchrule") != null) {
    +      return jsonParser.parse(result).getAsJsonObject().get("menuid").getAsString();
    +    }
    +
    +    return null;
       }
     
       @Override
    @@ -50,7 +74,7 @@ public void menuDelete(String menuId) throws WxErrorException {
         JsonObject jsonObject = new JsonObject();
         jsonObject.addProperty("menuid", menuId);
         String result = this.wxMpService.post(url, jsonObject.toString());
    -    log.debug("根据MeunId({})删除菜单结果:{}", menuId, result);
    +    log.debug("根据MeunId({})删除个性化菜单结果:{}", menuId, result);
       }
     
       @Override
    @@ -77,7 +101,7 @@ public WxMenu menuTryMatch(String userid) throws WxErrorException {
           String resultContent = this.wxMpService.post(url, jsonObject.toString());
           return WxMenu.fromJson(resultContent);
         } catch (WxErrorException e) {
    -      // 46003 不存在的菜单数据     46002 不存在的菜单版本
    +      // 46003 不存在的菜单数据;46002 不存在的菜单版本
           if (e.getError().getErrorCode() == 46003
             || e.getError().getErrorCode() == 46002) {
             return null;
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java
    index 1452c0567e..04e1b3e6b9 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java
    @@ -8,23 +8,22 @@
     import me.chanjar.weixin.mp.api.ApiTestModule;
     import me.chanjar.weixin.mp.api.WxMpService;
     import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
    -import org.testng.Assert;
    -import org.testng.annotations.DataProvider;
    -import org.testng.annotations.Guice;
    -import org.testng.annotations.Test;
    +import org.testng.*;
    +import org.testng.annotations.*;
     
     /**
      * 测试菜单
    + *
      * @author chanjarster
      * @author Binary Wang
    - *
      */
    -@Test(groups="menuAPI")
    +@Test(groups = "menuAPI")
     @Guice(modules = ApiTestModule.class)
     public class WxMpMenuServiceImplTest {
     
       @Inject
       protected WxMpService wxService;
    +  private String menuId = null;
     
       @Test(dataProvider = "menu")
       public void testMenuCreate(WxMenu wxMenu) throws WxErrorException {
    @@ -44,69 +43,111 @@ public void testGetSelfMenuInfo() throws Exception {
         System.out.println(selfMenuInfo);
       }
     
    +  @Test
    +  public void testCreateConditionalMenu() throws WxErrorException {
    +    String json = "{\n" +
    +      " 	\"button\":[\n" +
    +      " 	{	\n" +
    +      "    	\"type\":\"click\",\n" +
    +      "    	\"name\":\"今日歌曲\",\n" +
    +      "     	\"key\":\"V1001_TODAY_MUSIC\" \n" +
    +      "	},\n" +
    +      "	{ \n" +
    +      "		\"name\":\"菜单\",\n" +
    +      "		\"sub_button\":[\n" +
    +      "		{	\n" +
    +      "			\"type\":\"view\",\n" +
    +      "			\"name\":\"搜索\",\n" +
    +      "			\"url\":\"http://www.soso.com/\"\n" +
    +      "		},\n" +
    +      "		{\n" +
    +      "			\"type\":\"view\",\n" +
    +      "			\"name\":\"视频\",\n" +
    +      "			\"url\":\"http://v.qq.com/\"\n" +
    +      "		},\n" +
    +      "		{\n" +
    +      "			\"type\":\"click\",\n" +
    +      "			\"name\":\"赞一下我们\",\n" +
    +      "			\"key\":\"V1001_GOOD\"\n" +
    +      "		}]\n" +
    +      " }],\n" +
    +      "\"matchrule\":{\n" +
    +      "  \"tag_id\":\"2\",\n" +
    +      "  \"sex\":\"1\",\n" +
    +      "  \"country\":\"中国\",\n" +
    +      "  \"province\":\"广东\",\n" +
    +      "  \"city\":\"广州\",\n" +
    +      "  \"client_platform_type\":\"2\",\n" +
    +      "  \"language\":\"zh_CN\"\n" +
    +      "  }\n" +
    +      "}";
    +
    +    this.menuId = this.wxService.getMenuService().menuCreate(json);
    +    System.out.println(this.menuId);
    +  }
    +
    +  @Test(dependsOnMethods = {"testCreateConditionalMenu"})
    +  public void testDeleteConditionalMenu() throws WxErrorException {
    +    this.wxService.getMenuService().menuDelete(menuId);
    +  }
    +
       @Test
       public void testCreateMenu2() throws WxErrorException {
         String a = "{\n"
    -        + "  \"menu\": {\n"
    -        + "    \"button\": [\n"
    -        + "      {\n"
    -        + "        \"type\": \"click\",\n"
    -        + "        \"name\": \"今日歌曲\",\n"
    -        + "        \"key\": \"V1001_TODAY_MUSIC\"\n"
    -        + "      },\n"
    -        + "      {\n"
    -        + "        \"type\": \"click\",\n"
    -        + "        \"name\": \"歌手简介\",\n"
    -        + "        \"key\": \"V1001_TODAY_SINGER\"\n"
    -        + "      },\n"
    -        + "      {\n"
    -        + "        \"name\": \"菜单\",\n"
    -        + "        \"sub_button\": [\n"
    -        + "          {\n"
    -        + "            \"type\": \"view\",\n"
    -        + "            \"name\": \"搜索\",\n"
    -        + "            \"url\": \"http://www.soso.com/\"\n"
    -        + "          },\n"
    -        + "          {\n"
    -        + "            \"type\": \"view\",\n"
    -        + "            \"name\": \"视频\",\n"
    -        + "            \"url\": \"http://v.qq.com/\"\n"
    -        + "          },\n"
    -        + "          {\n"
    -        + "            \"type\": \"click\",\n"
    -        + "            \"name\": \"赞一下我们\",\n"
    -        + "            \"key\": \"V1001_GOOD\"\n"
    -        + "          }\n"
    -        + "        ]\n"
    -        + "      }\n"
    -        + "    ]\n"
    -        + "  }\n"
    -        + "}";
    +      + "  \"menu\": {\n"
    +      + "    \"button\": [\n"
    +      + "      {\n"
    +      + "        \"type\": \"click\",\n"
    +      + "        \"name\": \"今日歌曲\",\n"
    +      + "        \"key\": \"V1001_TODAY_MUSIC\"\n"
    +      + "      },\n"
    +      + "      {\n"
    +      + "        \"type\": \"click\",\n"
    +      + "        \"name\": \"歌手简介\",\n"
    +      + "        \"key\": \"V1001_TODAY_SINGER\"\n"
    +      + "      },\n"
    +      + "      {\n"
    +      + "        \"name\": \"菜单\",\n"
    +      + "        \"sub_button\": [\n"
    +      + "          {\n"
    +      + "            \"type\": \"view\",\n"
    +      + "            \"name\": \"搜索\",\n"
    +      + "            \"url\": \"http://www.soso.com/\"\n"
    +      + "          },\n"
    +      + "          {\n"
    +      + "            \"type\": \"view\",\n"
    +      + "            \"name\": \"视频\",\n"
    +      + "            \"url\": \"http://v.qq.com/\"\n"
    +      + "          },\n"
    +      + "          {\n"
    +      + "            \"type\": \"click\",\n"
    +      + "            \"name\": \"赞一下我们\",\n"
    +      + "            \"key\": \"V1001_GOOD\"\n"
    +      + "          }\n"
    +      + "        ]\n"
    +      + "      }\n"
    +      + "    ]\n"
    +      + "  }\n"
    +      + "}";
     
         WxMenu menu = WxMenu.fromJson(a);
         System.out.println(menu.toJson());
         this.wxService.getMenuService().menuCreate(menu);
       }
     
    -  @Test(dependsOnMethods = { "testMenuCreate"})
    +  @Test(dependsOnMethods = {"testMenuCreate"})
       public void testMenuGet() throws WxErrorException {
         WxMenu wxMenu = this.wxService.getMenuService().menuGet();
         Assert.assertNotNull(wxMenu);
         System.out.println(wxMenu.toJson());
       }
     
    -  @Test(dependsOnMethods = { "testMenuGet"})
    +  @Test(dependsOnMethods = {"testMenuGet"})
       public void testMenuDelete() throws WxErrorException {
         this.wxService.getMenuService().menuDelete();
       }
     
    -  @Test
    -  public void testDeleteConditionalMenu() throws WxErrorException {
    -    String menuId = "123";
    -    this.wxService.getMenuService().menuDelete(menuId);
    -  }
    -
    -  @DataProvider(name="menu")
    +  @DataProvider(name = "menu")
       public Object[][] getMenu() {
         WxMenu menu = new WxMenu();
         WxMenuButton button1 = new WxMenuButton();
    @@ -145,10 +186,10 @@ public Object[][] getMenu() {
         button3.getSubButtons().add(button32);
         button3.getSubButtons().add(button33);
     
    -    return new Object[][] {
    -        new Object[] {
    -            menu
    -        }
    +    return new Object[][]{
    +      new Object[]{
    +        menu
    +      }
         };
     
       }
    
    From 39c7f7cd9f502091d0c5b23af5cb941dec5bb744 Mon Sep 17 00:00:00 2001
    From: Binary Wang 
    Date: Tue, 17 Jan 2017 15:15:21 +0800
    Subject: [PATCH 73/80] =?UTF-8?q?=E6=94=B9=E9=80=A0=E6=9F=A5=E8=AF=A2?=
     =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=8E=A5=E5=8F=A3=EF=BC=8C=E4=BB=A5=E6=94=AF?=
     =?UTF-8?q?=E6=8C=81=E4=B8=AA=E6=80=A7=E5=8C=96=E8=8F=9C=E5=8D=95=E7=9A=84?=
     =?UTF-8?q?conditionalmenu=E5=92=8Cmenuid=E5=B1=9E=E6=80=A7=EF=BC=8C=20#12?=
     =?UTF-8?q?6?=
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    
    ---
     .../weixin/mp/api/WxMpMenuService.java        |  5 +-
     .../mp/api/impl/WxMpMenuServiceImpl.java      |  5 +-
     .../chanjar/weixin/mp/bean/menu/WxMpMenu.java | 92 +++++++++++++++++++
     .../mp/api/impl/WxMpMenuServiceImplTest.java  |  3 +-
     4 files changed, 100 insertions(+), 5 deletions(-)
     create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpMenu.java
    
    diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java
    index 73660d3f9c..f1c9fd47d9 100644
    --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java
    +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java
    @@ -3,6 +3,7 @@
     import me.chanjar.weixin.common.bean.menu.WxMenu;
     import me.chanjar.weixin.common.exception.WxErrorException;
     import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
    +import me.chanjar.weixin.mp.bean.menu.WxMpMenu;
     
     /**
      * 菜单相关操作接口
    @@ -54,10 +55,10 @@ public interface WxMpMenuService {
       /**
        * 
        * 自定义菜单查询接口
    -   * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单查询接口
    +   * 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141014&token=&lang=zh_CN
        * 
    */ - WxMenu menuGet() throws WxErrorException; + WxMpMenu menuGet() throws WxErrorException; /** *
    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 20590e5a60..b28ac6a16f 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
    @@ -7,6 +7,7 @@
     import me.chanjar.weixin.mp.api.WxMpMenuService;
     import me.chanjar.weixin.mp.api.WxMpService;
     import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
    +import me.chanjar.weixin.mp.bean.menu.WxMpMenu;
     import org.slf4j.Logger;
     import org.slf4j.LoggerFactory;
     
    @@ -78,11 +79,11 @@ public void menuDelete(String menuId) throws WxErrorException {
       }
     
       @Override
    -  public WxMenu menuGet() throws WxErrorException {
    +  public WxMpMenu menuGet() throws WxErrorException {
         String url = API_URL_PREFIX + "/get";
         try {
           String resultContent = this.wxMpService.get(url, null);
    -      return WxMenu.fromJson(resultContent);
    +      return WxMpMenu.fromJson(resultContent);
         } catch (WxErrorException e) {
           // 46003 不存在的菜单数据
           if (e.getError().getErrorCode() == 46003) {
    diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpMenu.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpMenu.java
    new file mode 100644
    index 0000000000..366ca2f1ba
    --- /dev/null
    +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpMenu.java
    @@ -0,0 +1,92 @@
    +package me.chanjar.weixin.mp.bean.menu;
    +
    +import com.google.gson.annotations.SerializedName;
    +import me.chanjar.weixin.common.bean.menu.WxMenuButton;
    +import me.chanjar.weixin.common.bean.menu.WxMenuRule;
    +import me.chanjar.weixin.common.util.ToStringUtils;
    +import me.chanjar.weixin.common.util.json.WxGsonBuilder;
    +
    +import java.util.List;
    +
    +/**
    + * 
    + *   公众号专用的菜单类,可能包含个性化菜单
    + * Created by Binary Wang on 2017-1-17.
    + * @author binarywang(Binary Wang)
    + * 
    + */ +public class WxMpMenu { + @SerializedName("menu") + private WxMpConditionalMenu menu; + + @SerializedName("conditionalmenu") + private List conditionalMenu; + + public static WxMpMenu fromJson(String json) { + return WxGsonBuilder.create().fromJson(json, WxMpMenu.class); + } + + public WxMpConditionalMenu getMenu() { + return menu; + } + + public void setMenu(WxMpConditionalMenu menu) { + this.menu = menu; + } + + public List getConditionalMenu() { + return conditionalMenu; + } + + public void setConditionalMenu(List conditionalMenu) { + this.conditionalMenu = conditionalMenu; + } + + @Override + public String toString() { + return ToStringUtils.toSimpleString(this); + } + + public String toJson() { + return WxGsonBuilder.create().toJson(this); + } + + public static class WxMpConditionalMenu { + @SerializedName("button") + private List buttons; + @SerializedName("matchrule") + private WxMenuRule rule; + @SerializedName("menuid") + private String menuId; + + @Override + public String toString() { + return ToStringUtils.toSimpleString(this); + } + + public List getButtons() { + return buttons; + } + + public void setButtons(List buttons) { + this.buttons = buttons; + } + + public WxMenuRule getRule() { + return rule; + } + + public void setRule(WxMenuRule rule) { + this.rule = rule; + } + + public String getMenuId() { + return menuId; + } + + public void setMenuId(String menuId) { + this.menuId = menuId; + } + } + +} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java index 04e1b3e6b9..08980a2bba 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java @@ -8,6 +8,7 @@ import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult; +import me.chanjar.weixin.mp.bean.menu.WxMpMenu; import org.testng.*; import org.testng.annotations.*; @@ -137,7 +138,7 @@ public void testCreateMenu2() throws WxErrorException { @Test(dependsOnMethods = {"testMenuCreate"}) public void testMenuGet() throws WxErrorException { - WxMenu wxMenu = this.wxService.getMenuService().menuGet(); + WxMpMenu wxMenu = this.wxService.getMenuService().menuGet(); Assert.assertNotNull(wxMenu); System.out.println(wxMenu.toJson()); } From 3a87bdaaefc258c362a2730c019959cdc35ced16 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 17 Jan 2017 15:50:45 +0800 Subject: [PATCH 74/80] release 2.4.9.BETA --- pom.xml | 2 +- weixin-java-common/pom.xml | 2 +- weixin-java-cp/pom.xml | 2 +- weixin-java-mp/pom.xml | 2 +- weixin-java-osgi/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 7a3697ce81..a0dfd704db 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.github.binarywang weixin-java-parent - 2.4.8.BETA + 2.4.9.BETA pom WeiXin Java Tools - Parent 微信公众号、企业号上级POM diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml index 26fdff4a3c..a635fca97e 100644 --- a/weixin-java-common/pom.xml +++ b/weixin-java-common/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.8.BETA + 2.4.9.BETA weixin-java-common diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index 79d6830877..26175c9c01 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.8.BETA + 2.4.9.BETA weixin-java-cp diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index 197e54c290..d595950e42 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.8.BETA + 2.4.9.BETA weixin-java-mp WeiXin Java Tools - MP diff --git a/weixin-java-osgi/pom.xml b/weixin-java-osgi/pom.xml index 5d749f8fd8..19cc0bb7ef 100644 --- a/weixin-java-osgi/pom.xml +++ b/weixin-java-osgi/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.8.BETA + 2.4.9.BETA weixin-java-osgi From 1f110dc984185ebaf2f5750fa143ca1b87a191e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=8C=E4=BA=91?= Date: Sun, 22 Jan 2017 11:24:35 +0800 Subject: [PATCH 75/80] =?UTF-8?q?=E4=BF=AE=E6=94=B9WxJsapiSignature?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/common/bean/WxJsapiSignature.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java index 1779905862..7837158361 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java @@ -8,9 +8,9 @@ public class WxJsapiSignature implements Serializable { private static final long serialVersionUID = -1116808193154384804L; - private String appid; + private String appId; - private String noncestr; + private String nonceStr; private long timestamp; @@ -26,12 +26,12 @@ public void setSignature(String signature) { this.signature = signature; } - public String getNoncestr() { - return this.noncestr; + public String getNonceStr() { + return nonceStr; } - public void setNoncestr(String noncestr) { - this.noncestr = noncestr; + public void setNonceStr(String nonceStr) { + this.nonceStr = nonceStr; } public long getTimestamp() { @@ -50,12 +50,11 @@ public void setUrl(String url) { this.url = url; } - public String getAppid() { - return this.appid; + public String getAppId() { + return appId; } - public void setAppid(String appid) { - this.appid = appid; + public void setAppId(String appId) { + this.appId = appId; } - } From 89a92c245297500d64ebb66357a2383f3cfe32db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=8C=E4=BA=91?= Date: Sun, 22 Jan 2017 11:28:32 +0800 Subject: [PATCH 76/80] =?UTF-8?q?=E4=BF=AE=E6=94=B9WxJsapiSignature?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1,=E5=B1=9E=E6=80=A7=E5=90=8D=E5=AD=97?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E5=86=99=E4=B8=8E=E5=BE=AE=E4=BF=A1=E4=B8=80?= =?UTF-8?q?=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java | 4 ++-- .../java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java index 8d0c47daae..a10eb42ebb 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java @@ -166,12 +166,12 @@ public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException ); WxJsapiSignature jsapiSignature = new WxJsapiSignature(); jsapiSignature.setTimestamp(timestamp); - jsapiSignature.setNoncestr(noncestr); + jsapiSignature.setNonceStr(noncestr); jsapiSignature.setUrl(url); jsapiSignature.setSignature(signature); // Fixed bug - jsapiSignature.setAppid(this.configStorage.getCorpId()); + jsapiSignature.setAppId(this.configStorage.getCorpId()); return jsapiSignature; } 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 2d250035c8..eb1e58aa17 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 @@ -151,9 +151,9 @@ public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException String signature = SHA1.genWithAmple("jsapi_ticket=" + jsapiTicket, "noncestr=" + noncestr, "timestamp=" + timestamp, "url=" + url); WxJsapiSignature jsapiSignature = new WxJsapiSignature(); - jsapiSignature.setAppid(this.wxMpConfigStorage.getAppId()); + jsapiSignature.setAppId(this.wxMpConfigStorage.getAppId()); jsapiSignature.setTimestamp(timestamp); - jsapiSignature.setNoncestr(noncestr); + jsapiSignature.setNonceStr(noncestr); jsapiSignature.setUrl(url); jsapiSignature.setSignature(signature); return jsapiSignature; From 123eb5088d06292435d157f3f18b44e26f095c12 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 23 Jan 2017 16:48:00 +0800 Subject: [PATCH 77/80] =?UTF-8?q?=E9=87=8D=E6=9E=84=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=B1=BB=E7=9A=84=E5=8C=85=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/mp/api/WxMpBaseAPITest.java | 1 + .../chanjar/weixin/mp/api/WxMpJsAPITest.java | 1 + .../weixin/mp/api/WxMpMassMessageAPITest.java | 18 +++++++++--------- .../chanjar/weixin/mp/api/WxMpMiscAPITest.java | 1 + .../weixin/mp/api/WxMpShortUrlAPITest.java | 1 + .../mp/api/impl/WxMpCardServiceImplTest.java | 2 +- .../api/impl/WxMpDataCubeServiceImplTest.java | 2 +- .../mp/api/impl/WxMpDeviceServiceImplTest.java | 2 +- .../mp/api/impl/WxMpKefuServiceImplTest.java | 14 +++++++------- .../api/impl/WxMpMaterialServiceImplTest.java | 2 +- .../mp/api/impl/WxMpMenuServiceImplTest.java | 2 +- .../mp/api/impl/WxMpPayServiceImplTest.java | 8 ++++---- .../mp/api/impl/WxMpQrcodeServiceImplTest.java | 2 +- .../mp/api/impl/WxMpServiceImplTest.java | 6 +++--- .../mp/api/impl/WxMpStoreServiceImplTest.java | 2 +- .../impl/WxMpTemplateMsgServiceImplTest.java | 6 +++--- .../impl/WxMpUserBlacklistServiceImplTest.java | 10 +++++----- .../mp/api/impl/WxMpUserServiceImplTest.java | 8 ++++---- .../api/impl/WxMpUserTagServiceImplTest.java | 10 +++++----- .../mp/api/{ => test}/ApiTestModule.java | 11 ++++++----- .../TestConfigStorage.java} | 11 +++++------ 21 files changed, 62 insertions(+), 58 deletions(-) rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/{ => test}/ApiTestModule.java (77%) rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/{WxXmlMpInMemoryConfigStorage.java => test/TestConfigStorage.java} (87%) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java index b6904eb1eb..c3b53d66ca 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java @@ -2,6 +2,7 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import org.apache.commons.lang3.StringUtils; import org.testng.Assert; import org.testng.annotations.Guice; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java index 54dcdc04b6..8355f21625 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.api; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java index 99b7a52c30..0fd5fcabf0 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java @@ -4,6 +4,8 @@ import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.api.test.ApiTestModule; +import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.WxMpMassNews; import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; @@ -33,7 +35,7 @@ public class WxMpMassMessageAPITest { @Test public void testTextMassOpenIdsMessageSend() throws WxErrorException { // 发送群发消息 - WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configProvider = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); massMessage.setMsgType(WxConsts.MASS_MSG_TEXT); @@ -47,10 +49,9 @@ public void testTextMassOpenIdsMessageSend() throws WxErrorException { } @Test(dataProvider = "massMessages") - public void testMediaMassOpenIdsMessageSend(String massMsgType, - String mediaId) throws WxErrorException { + public void testMediaMassOpenIdsMessageSend(String massMsgType, String mediaId) throws WxErrorException { // 发送群发消息 - WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configProvider = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); massMessage.setMsgType(massMsgType); @@ -83,8 +84,7 @@ public void testMediaMassGroupMessageSend(String massMsgType, String mediaId) WxMpMassTagMessage massMessage = new WxMpMassTagMessage(); massMessage.setMsgType(massMsgType); massMessage.setMediaId(mediaId); - massMessage - .setTagId(this.wxService.getUserTagService().tagGet().get(0).getId()); + massMessage.setTagId(this.wxService.getUserTagService().tagGet().get(0).getId()); WxMpMassSendResult massResult = this.wxService .massGroupMessageSend(massMessage); @@ -118,7 +118,7 @@ public Object[][] massMessages() throws WxErrorException, IOException { messages[0] = new Object[]{WxConsts.MASS_MSG_VIDEO, uploadResult.getMediaId()}; } - /** + /* * 图片素材 */ try (InputStream inputStream = ClassLoader @@ -130,7 +130,7 @@ public Object[][] massMessages() throws WxErrorException, IOException { messages[1] = new Object[]{WxConsts.MASS_MSG_IMAGE, uploadMediaRes.getMediaId()}; } - /** + /* * 语音素材 */ try (InputStream inputStream = ClassLoader @@ -142,7 +142,7 @@ public Object[][] massMessages() throws WxErrorException, IOException { messages[2] = new Object[]{WxConsts.MASS_MSG_VOICE, uploadMediaRes.getMediaId()}; } - /** + /* * 图文素材 */ try (InputStream inputStream = ClassLoader diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMiscAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMiscAPITest.java index 656c7162ff..dd30538f75 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMiscAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMiscAPITest.java @@ -2,6 +2,7 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java index 87cf740635..f8b0ce6f88 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java @@ -2,6 +2,7 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java index 97619223bc..1f28f4bb54 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java @@ -2,7 +2,7 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.bean.WxCardApiSignature; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.result.WxMpCardResult; import org.testng.annotations.Guice; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java index 3e2257a344..22d0cc3ee1 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java @@ -14,7 +14,7 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult; import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleTotal; import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java index e79dd25041..0f621e3e16 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java @@ -3,7 +3,7 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.device.WxDeviceQrCodeResult; import org.testng.annotations.DataProvider; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java index 3150dec36c..105f078d96 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java @@ -3,9 +3,9 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; import me.chanjar.weixin.mp.bean.kefu.result.*; @@ -31,7 +31,7 @@ public class WxMpKefuServiceImplTest { protected WxMpService wxService; public void testSendKefuMpNewsMessage() throws WxErrorException { - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); message.setMsgType(WxConsts.CUSTOM_MSG_MPNEWS); @@ -42,7 +42,7 @@ public void testSendKefuMpNewsMessage() throws WxErrorException { } public void testSendKefuMessage() throws WxErrorException { - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); @@ -54,7 +54,7 @@ public void testSendKefuMessage() throws WxErrorException { } public void testSendKefuMessageWithKfAccount() throws WxErrorException { - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); @@ -85,7 +85,7 @@ public void testKfOnlineList() throws WxErrorException { @DataProvider public Object[][] getKfAccount() { - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); return new Object[][] { { configStorage.getKfAccount() } }; } @@ -131,7 +131,7 @@ public void testKfAccountDel(String kfAccount) throws WxErrorException { @DataProvider public Object[][] getKfAccountAndOpenid() { - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); return new Object[][] { { configStorage.getKfAccount(), configStorage.getOpenid() } }; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java index 043a49ecda..a3d8f47fe9 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java @@ -5,7 +5,7 @@ import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.material.WxMpMaterial; import me.chanjar.weixin.mp.bean.material.WxMpMaterialArticleUpdate; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java index 08980a2bba..45703b7b32 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java @@ -5,7 +5,7 @@ import me.chanjar.weixin.common.bean.menu.WxMenu; import me.chanjar.weixin.common.bean.menu.WxMenuButton; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult; import me.chanjar.weixin.mp.bean.menu.WxMpMenu; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index f46765c77d..e890deda6a 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -3,9 +3,9 @@ import com.github.binarywang.utils.qrcode.QrcodeUtils; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.pay.request.*; import me.chanjar.weixin.mp.bean.pay.result.*; import org.testng.annotations.*; @@ -59,7 +59,7 @@ public void testReport() throws Exception { */ @Test public void setSSLKey(){ - WxXmlMpInMemoryConfigStorage config = (WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); + TestConfigStorage config = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); config.setSslContextFilePath(config.getKeyPath()); } @@ -107,7 +107,7 @@ public void testSendRedpack() throws Exception { request.setClientIp("aaa"); request.setMchBillNo("aaaa"); request - .setReOpenid(((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); + .setReOpenid(((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); WxPaySendRedpackResult redpackResult = this.wxService.getPayService().sendRedpack(request); System.err.println(redpackResult); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java index d1475dfe57..b7957e7f5d 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java @@ -2,7 +2,7 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; import org.testng.Assert; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java index c6b8689f97..ffb5563656 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java @@ -2,9 +2,9 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.test.TestConfigStorage; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; @@ -103,7 +103,7 @@ public void testOauth2buildAuthorizationUrl() { @Test public void testBuildQrConnectUrl() { - String qrconnectRedirectUrl = ((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getQrconnectRedirectUrl(); + String qrconnectRedirectUrl = ((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getQrconnectRedirectUrl(); String qrConnectUrl = this.wxService.buildQrConnectUrl(qrconnectRedirectUrl, WxConsts.QRCONNECT_SCOPE_SNSAPI_LOGIN, null); Assert.assertNotNull(qrConnectUrl); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java index 636092933b..0a6b561046 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java @@ -2,7 +2,7 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo; import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java index b37278e236..289323625f 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java @@ -2,9 +2,9 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.template.WxMpTemplate; import me.chanjar.weixin.mp.bean.template.WxMpTemplateData; import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry; @@ -33,7 +33,7 @@ public class WxMpTemplateMsgServiceImplTest { public void testSendTemplateMsg() throws WxErrorException { SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss.SSS"); - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder() .toUser(configStorage.getOpenid()) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java index 2bcc3aeabe..14796f9c30 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java @@ -1,8 +1,8 @@ package me.chanjar.weixin.mp.api.impl; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; import org.testng.Assert; import org.testng.annotations.Guice; @@ -23,7 +23,7 @@ public class WxMpUserBlacklistServiceImplTest { @Test public void testGetBlacklist() throws Exception { - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpUserBlacklistGetResult wxMpUserBlacklistGetResult = this.wxService.getBlackListService().getBlacklist(configStorage.getOpenid()); Assert.assertNotNull(wxMpUserBlacklistGetResult); @@ -35,7 +35,7 @@ public void testGetBlacklist() throws Exception { @Test public void testPushToBlacklist() throws Exception { - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); List openidList = new ArrayList<>(); openidList.add(configStorage.getOpenid()); @@ -44,7 +44,7 @@ public void testPushToBlacklist() throws Exception { @Test public void testPullFromBlacklist() throws Exception { - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); List openidList = new ArrayList<>(); openidList.add(configStorage.getOpenid()); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java index 02252800f7..3163ed6911 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java @@ -13,8 +13,8 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.ApiTestModule; -import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.test.ApiTestModule; +import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.WxMpUserQuery; import me.chanjar.weixin.mp.bean.result.WxMpUser; import me.chanjar.weixin.mp.bean.result.WxMpUserList; @@ -32,11 +32,11 @@ public class WxMpUserServiceImplTest { @Inject private WxMpService wxService; - private WxXmlMpInMemoryConfigStorage configProvider; + private TestConfigStorage configProvider; @BeforeTest public void setup() { - this.configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService + this.configProvider = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java index bca04a06d4..54743ac41e 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java @@ -9,8 +9,8 @@ import com.google.inject.Inject; -import me.chanjar.weixin.mp.api.ApiTestModule; -import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.test.ApiTestModule; +import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.tag.WxTagListUser; import me.chanjar.weixin.mp.bean.tag.WxUserTag; @@ -67,7 +67,7 @@ public void testTagListUser() throws Exception { @Test public void testBatchTagging() throws Exception { - String[] openids = new String[]{((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()}; + String[] openids = new String[]{((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()}; boolean res = this.wxService.getUserTagService().batchTagging(this.tagId, openids); System.out.println(res); Assert.assertTrue(res); @@ -75,7 +75,7 @@ public void testBatchTagging() throws Exception { @Test public void testBatchUntagging() throws Exception { - String[] openids = new String[]{((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()}; + String[] openids = new String[]{((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()}; boolean res = this.wxService.getUserTagService().batchUntagging(this.tagId, openids); System.out.println(res); Assert.assertTrue(res); @@ -84,7 +84,7 @@ public void testBatchUntagging() throws Exception { @Test public void testUserTagList() throws Exception { List res = this.wxService.getUserTagService().userTagList( - ((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); + ((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); System.out.println(res); Assert.assertNotNull(res); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/ApiTestModule.java similarity index 77% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/ApiTestModule.java index c506df0f83..c957bde865 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/ApiTestModule.java @@ -1,9 +1,11 @@ -package me.chanjar.weixin.mp.api; +package me.chanjar.weixin.mp.api.test; import com.google.inject.Binder; import com.google.inject.Module; import com.thoughtworks.xstream.XStream; import me.chanjar.weixin.common.util.xml.XStreamInitializer; +import me.chanjar.weixin.mp.api.WxMpConfigStorage; +import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; import java.io.IOException; @@ -14,10 +16,9 @@ public class ApiTestModule implements Module { @Override public void configure(Binder binder) { - try (InputStream is1 = ClassLoader - .getSystemResourceAsStream("test-config.xml")) { - WxXmlMpInMemoryConfigStorage config = this - .fromXml(WxXmlMpInMemoryConfigStorage.class, is1); + try (InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml")) { + TestConfigStorage config = this + .fromXml(TestConfigStorage.class, is1); config.setAccessTokenLock(new ReentrantLock()); WxMpService wxService = new WxMpServiceImpl(); wxService.setWxMpConfigStorage(config); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/TestConfigStorage.java similarity index 87% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/TestConfigStorage.java index e51ffeb6e5..0dc9115134 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/TestConfigStorage.java @@ -1,18 +1,19 @@ -package me.chanjar.weixin.mp.api; +package me.chanjar.weixin.mp.api.test; import com.thoughtworks.xstream.annotations.XStreamAlias; +import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage; import org.apache.commons.lang3.builder.ToStringBuilder; import java.util.concurrent.locks.Lock; @XStreamAlias("xml") -public class WxXmlMpInMemoryConfigStorage - extends WxMpInMemoryConfigStorage { +public class TestConfigStorage extends WxMpInMemoryConfigStorage { private String openid; private String kfAccount; private String qrconnectRedirectUrl; private String templateId; + private String keyPath; public String getKeyPath() { return keyPath; @@ -22,8 +23,6 @@ public void setKeyPath(String keyPath) { this.keyPath = keyPath; } - private String keyPath; - public String getOpenid() { return this.openid; } @@ -61,7 +60,7 @@ public void setTemplateId(String templateId) { this.templateId = templateId; } - public void setAccessTokenLock(Lock lock){ + public void setAccessTokenLock(Lock lock) { super.accessTokenLock = lock; } From ff1b69a38f5a68601fc3bcf6cff0ce270e8a187a Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 23 Jan 2017 16:54:48 +0800 Subject: [PATCH 78/80] =?UTF-8?q?=E4=BD=BF=E7=94=A8IDEA=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpBaseAPITest.java | 7 +- .../weixin/mp/api/WxMpBusyRetryTest.java | 11 +- .../chanjar/weixin/mp/api/WxMpJsAPITest.java | 17 +-- .../weixin/mp/api/WxMpMassMessageAPITest.java | 6 +- .../weixin/mp/api/WxMpMessageRouterTest.java | 134 +++++++++--------- .../weixin/mp/api/WxMpMiscAPITest.java | 7 +- .../weixin/mp/api/WxMpShortUrlAPITest.java | 5 +- .../mp/api/impl/WxMpCardServiceImplTest.java | 8 +- .../api/impl/WxMpDataCubeServiceImplTest.java | 95 ++++++------- .../api/impl/WxMpDeviceServiceImplTest.java | 6 +- .../mp/api/impl/WxMpKefuServiceImplTest.java | 66 +++++---- .../api/impl/WxMpMaterialServiceImplTest.java | 74 +++++----- .../mp/api/impl/WxMpMenuServiceImplTest.java | 2 +- .../mp/api/impl/WxMpPayServiceImplTest.java | 8 +- .../api/impl/WxMpQrcodeServiceImplTest.java | 8 +- .../mp/api/impl/WxMpServiceImplTest.java | 9 +- .../mp/api/impl/WxMpStoreServiceImplTest.java | 17 ++- .../impl/WxMpTemplateMsgServiceImplTest.java | 11 +- .../WxMpUserBlacklistServiceImplTest.java | 7 +- .../mp/api/impl/WxMpUserServiceImplTest.java | 27 ++-- .../api/impl/WxMpUserTagServiceImplTest.java | 20 ++- .../mp/bean/kefu/WxMpKefuMessageTest.java | 18 +-- .../mp/bean/kefu/result/WxMpKfListTest.java | 50 +++---- .../kefu/result/WxMpKfOnlineListTest.java | 42 +++--- .../mp/bean/message/WxMpXmlMessageTest.java | 4 +- .../message/WxMpXmlOutImageMessageTest.java | 44 +++--- .../message/WxMpXmlOutMusicMessageTest.java | 74 +++++----- .../message/WxMpXmlOutNewsMessageTest.java | 100 ++++++------- .../message/WxMpXmlOutTextMessageTest.java | 34 ++--- .../WxMpXmlOutTransferKefuMessageTest.java | 4 +- .../message/WxMpXmlOutVideoMessageTest.java | 62 ++++---- .../message/WxMpXmlOutVoiceMessageTest.java | 34 ++--- .../bean/pay/result/WxPayBaseResultTest.java | 4 +- .../pay/result/WxPayOrderQueryResultTest.java | 4 +- .../result/WxPayRefundQueryResultTest.java | 4 +- .../result/WxPaySendRedpackResultTest.java | 57 ++++---- .../mp/demo/DemoGuessNumberHandler.java | 50 +++---- .../weixin/mp/demo/DemoImageHandler.java | 16 +-- .../weixin/mp/demo/DemoLogHandler.java | 2 +- .../weixin/mp/demo/DemoOAuth2Handler.java | 12 +- .../weixin/mp/demo/DemoTextHandler.java | 6 +- .../demo/WxMpDemoInMemoryConfigStorage.java | 13 +- .../weixin/mp/demo/WxMpDemoServer.java | 33 +++-- .../weixin/mp/demo/WxMpEndpointServlet.java | 8 +- .../weixin/mp/demo/WxMpOAuth2Servlet.java | 13 +- 45 files changed, 591 insertions(+), 642 deletions(-) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java index c3b53d66ca..c8b616fa96 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java @@ -4,14 +4,13 @@ import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.test.ApiTestModule; import org.apache.commons.lang3.StringUtils; -import org.testng.Assert; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; /** * 基础API测试 - * @author chanjarster * + * @author chanjarster */ @Test(groups = "baseAPI") @Guice(modules = ApiTestModule.class) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java index 8d46eba767..da6460878e 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java @@ -4,8 +4,7 @@ import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.testng.annotations.*; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -15,14 +14,14 @@ @Test public class WxMpBusyRetryTest { - @DataProvider(name="getService") + @DataProvider(name = "getService") public Object[][] getService() { WxMpService service = new WxMpServiceImpl() { @Override protected synchronized T executeInternal( - RequestExecutor executor, String uri, E data) - throws WxErrorException { + RequestExecutor executor, String uri, E data) + throws WxErrorException { this.log.info("Executed"); WxError error = new WxError(); error.setErrorCode(-1); @@ -32,7 +31,7 @@ protected synchronized T executeInternal( service.setMaxRetryTimes(3); service.setRetrySleepMillis(500); - return new Object[][] { { service } }; + return new Object[][]{{service}}; } @Test(dataProvider = "getService", expectedExceptions = RuntimeException.class) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java index 8355f21625..9fd3227893 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java @@ -1,14 +1,11 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.mp.api.test.ApiTestModule; -import org.testng.Assert; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; - import com.google.inject.Inject; - import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.crypto.SHA1; +import me.chanjar.weixin.mp.api.test.ApiTestModule; +import org.testng.*; +import org.testng.annotations.*; /** * 测试jsapi ticket接口 @@ -35,10 +32,10 @@ public void test() { String noncestr = "82693e11-b9bc-448e-892f-f5289f46cd0f"; String jsapiTicket = "bxLdikRXVbTPdHSM05e5u4RbEYQn7pNQMPrfzl8lJNb1foLDa3HIwI3BRMkQmSO_5F64VFa75uURcq6Uz7QHgA"; String result = SHA1.genWithAmple( - "jsapi_ticket=" + jsapiTicket, - "noncestr=" + noncestr, - "timestamp=" + timestamp, - "url=" + url + "jsapi_ticket=" + jsapiTicket, + "noncestr=" + noncestr, + "timestamp=" + timestamp, + "url=" + url ); Assert.assertEquals(result, "c6f04b64d6351d197b71bd23fb7dd2d44c0db486"); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java index 0fd5fcabf0..3c42f66c10 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java @@ -12,10 +12,8 @@ import me.chanjar.weixin.mp.bean.WxMpMassVideo; import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; import java.io.IOException; import java.io.InputStream; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java index dc922aab3b..4360440f04 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java @@ -5,16 +5,15 @@ import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; import java.util.Map; /** * 测试消息路由器 - * @author chanjarster * + * @author chanjarster */ @Test public class WxMpMessageRouterTest { @@ -23,19 +22,19 @@ public class WxMpMessageRouterTest { public void prepare(boolean async, StringBuffer sb, WxMpMessageRouter router) { router .rule() - .async(async) - .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1") - .handler(new WxEchoMpMessageHandler(sb, "COMBINE_4")) + .async(async) + .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1") + .handler(new WxEchoMpMessageHandler(sb, "COMBINE_4")) .end() .rule() - .async(async) - .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1") - .handler(new WxEchoMpMessageHandler(sb, "COMBINE_3")) + .async(async) + .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1") + .handler(new WxEchoMpMessageHandler(sb, "COMBINE_3")) .end() .rule() - .async(async) - .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK) - .handler(new WxEchoMpMessageHandler(sb, "COMBINE_2")) + .async(async) + .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK) + .handler(new WxEchoMpMessageHandler(sb, "COMBINE_2")) .end() .rule().async(async).msgType(WxConsts.XML_MSG_TEXT).handler(new WxEchoMpMessageHandler(sb, WxConsts.XML_MSG_TEXT)).end() .rule().async(async).event(WxConsts.EVT_CLICK).handler(new WxEchoMpMessageHandler(sb, WxConsts.EVT_CLICK)).end() @@ -43,15 +42,15 @@ public void prepare(boolean async, StringBuffer sb, WxMpMessageRouter router) { .rule().async(async).content("CONTENT_1").handler(new WxEchoMpMessageHandler(sb, "CONTENT_1")).end() .rule().async(async).rContent(".*bc.*").handler(new WxEchoMpMessageHandler(sb, "abcd")).end() .rule().async(async).matcher(new WxMpMessageMatcher() { - @Override - public boolean match(WxMpXmlMessage message) { - return "strangeformat".equals(message.getFormat()); - } - }).handler(new WxEchoMpMessageHandler(sb, "matcher")).end() + @Override + public boolean match(WxMpXmlMessage message) { + return "strangeformat".equals(message.getFormat()); + } + }).handler(new WxEchoMpMessageHandler(sb, "matcher")).end() .rule().async(async).handler(new WxEchoMpMessageHandler(sb, "ALL")).end(); } - @Test(dataProvider="messages-1") + @Test(dataProvider = "messages-1") public void testSync(WxMpXmlMessage message, String expected) { StringBuffer sb = new StringBuffer(); WxMpMessageRouter router = new WxMpMessageRouter(null); @@ -60,11 +59,11 @@ public void testSync(WxMpXmlMessage message, String expected) { Assert.assertEquals(sb.toString(), expected); } - @Test(dataProvider="messages-1") + @Test(dataProvider = "messages-1") public void testAsync(WxMpXmlMessage message, String expected) throws InterruptedException { StringBuffer sb = new StringBuffer(); WxMpMessageRouter router = new WxMpMessageRouter(null); - prepare(true, sb, router); + prepare(true, sb, router); router.route(message); Thread.sleep(500l); Assert.assertEquals(sb.toString(), expected); @@ -75,7 +74,7 @@ public void testConcurrency() throws InterruptedException { router.rule().handler(new WxMpMessageHandler() { @Override public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context, WxMpService wxMpService, - WxSessionManager sessionManager) { + WxSessionManager sessionManager) { return null; } }).end(); @@ -97,7 +96,8 @@ public void run() { Thread.sleep(1000l * 2); } - @DataProvider(name="messages-1") + + @DataProvider(name = "messages-1") public Object[][] messages2() { WxMpXmlMessage message1 = new WxMpXmlMessage(); message1.setMsgType(WxConsts.XML_MSG_TEXT); @@ -135,40 +135,21 @@ public Object[][] messages2() { c4.setEventKey("KEY_1"); c4.setContent("CONTENT_1"); - return new Object[][] { - new Object[] { message1, WxConsts.XML_MSG_TEXT + "," }, - new Object[] { message2, WxConsts.EVT_CLICK + "," }, - new Object[] { message3, "KEY_1," }, - new Object[] { message4, "CONTENT_1," }, - new Object[] { message5, "ALL," }, - new Object[] { message6, "abcd," }, - new Object[] { message7, "matcher," }, - new Object[] { c2, "COMBINE_2," }, - new Object[] { c3, "COMBINE_3," }, - new Object[] { c4, "COMBINE_4," } + return new Object[][]{ + new Object[]{message1, WxConsts.XML_MSG_TEXT + ","}, + new Object[]{message2, WxConsts.EVT_CLICK + ","}, + new Object[]{message3, "KEY_1,"}, + new Object[]{message4, "CONTENT_1,"}, + new Object[]{message5, "ALL,"}, + new Object[]{message6, "abcd,"}, + new Object[]{message7, "matcher,"}, + new Object[]{c2, "COMBINE_2,"}, + new Object[]{c3, "COMBINE_3,"}, + new Object[]{c4, "COMBINE_4,"} }; } - public static class WxEchoMpMessageHandler implements WxMpMessageHandler { - - private StringBuffer sb; - private String echoStr; - - public WxEchoMpMessageHandler(StringBuffer sb, String echoStr) { - this.sb = sb; - this.echoStr = echoStr; - } - - @Override - public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context, WxMpService wxMpService, - WxSessionManager sessionManager) { - this.sb.append(this.echoStr).append(','); - return null; - } - - } - @DataProvider public Object[][] standardSessionManager() { @@ -178,8 +159,8 @@ public Object[][] standardSessionManager() { ism.setProcessExpiresFrequency(1); ism.setBackgroundProcessorDelay(1); - return new Object[][] { - new Object[] { ism } + return new Object[][]{ + new Object[]{ism} }; } @@ -191,8 +172,8 @@ public void testSessionClean1(StandardSessionManager ism) throws InterruptedExce final WxMpMessageRouter router = new WxMpMessageRouter(null); router.setSessionManager(ism); router - .rule().async(false).handler(new WxSessionMessageHandler()).next() - .rule().async(false).handler(new WxSessionMessageHandler()).end(); + .rule().async(false).handler(new WxSessionMessageHandler()).next() + .rule().async(false).handler(new WxSessionMessageHandler()).end(); WxMpXmlMessage msg = new WxMpXmlMessage(); msg.setFromUser("abc"); @@ -211,8 +192,8 @@ public void testSessionClean2(StandardSessionManager ism) throws InterruptedExce final WxMpMessageRouter router = new WxMpMessageRouter(null); router.setSessionManager(ism); router - .rule().async(false).handler(new WxSessionMessageHandler()).next() - .rule().async(true).handler(new WxSessionMessageHandler()).end(); + .rule().async(false).handler(new WxSessionMessageHandler()).next() + .rule().async(true).handler(new WxSessionMessageHandler()).end(); WxMpXmlMessage msg = new WxMpXmlMessage(); msg.setFromUser("abc"); @@ -225,8 +206,8 @@ public void testSessionClean2(StandardSessionManager ism) throws InterruptedExce final WxMpMessageRouter router = new WxMpMessageRouter(null); router.setSessionManager(ism); router - .rule().async(true).handler(new WxSessionMessageHandler()).next() - .rule().async(false).handler(new WxSessionMessageHandler()).end(); + .rule().async(true).handler(new WxSessionMessageHandler()).next() + .rule().async(false).handler(new WxSessionMessageHandler()).end(); WxMpXmlMessage msg = new WxMpXmlMessage(); msg.setFromUser("abc"); @@ -245,8 +226,8 @@ public void testSessionClean3(StandardSessionManager ism) throws InterruptedExce final WxMpMessageRouter router = new WxMpMessageRouter(null); router.setSessionManager(ism); router - .rule().async(true).handler(new WxSessionMessageHandler()).next() - .rule().async(true).handler(new WxSessionMessageHandler()).end(); + .rule().async(true).handler(new WxSessionMessageHandler()).next() + .rule().async(true).handler(new WxSessionMessageHandler()).end(); WxMpXmlMessage msg = new WxMpXmlMessage(); msg.setFromUser("abc"); @@ -265,7 +246,7 @@ public void testSessionClean4(StandardSessionManager ism) throws InterruptedExce final WxMpMessageRouter router = new WxMpMessageRouter(null); router.setSessionManager(ism); router - .rule().async(false).handler(new WxSessionMessageHandler()).end(); + .rule().async(false).handler(new WxSessionMessageHandler()).end(); WxMpXmlMessage msg = new WxMpXmlMessage(); msg.setFromUser("abc"); @@ -279,7 +260,7 @@ public void testSessionClean4(StandardSessionManager ism) throws InterruptedExce final WxMpMessageRouter router = new WxMpMessageRouter(null); router.setSessionManager(ism); router - .rule().async(true).handler(new WxSessionMessageHandler()).end(); + .rule().async(true).handler(new WxSessionMessageHandler()).end(); WxMpXmlMessage msg = new WxMpXmlMessage(); msg.setFromUser("abc"); @@ -290,11 +271,30 @@ public void testSessionClean4(StandardSessionManager ism) throws InterruptedExce } } - public static class WxSessionMessageHandler implements WxMpMessageHandler { + public static class WxEchoMpMessageHandler implements WxMpMessageHandler { + + private StringBuffer sb; + private String echoStr; + + public WxEchoMpMessageHandler(StringBuffer sb, String echoStr) { + this.sb = sb; + this.echoStr = echoStr; + } + + @Override + public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context, WxMpService wxMpService, + WxSessionManager sessionManager) { + this.sb.append(this.echoStr).append(','); + return null; + } + + } + + public static class WxSessionMessageHandler implements WxMpMessageHandler { @Override public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context, WxMpService wxMpService, - WxSessionManager sessionManager) { + WxSessionManager sessionManager) { sessionManager.getSession(wxMessage.getFromUser()); return null; } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMiscAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMiscAPITest.java index dd30538f75..8c61a56059 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMiscAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMiscAPITest.java @@ -3,16 +3,13 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.test.ApiTestModule; -import org.testng.Assert; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; import java.util.Arrays; /** - * * @author chanjarster - * */ @Test(groups = "miscAPI") @Guice(modules = ApiTestModule.class) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java index f8b0ce6f88..3e8a45c361 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java @@ -3,9 +3,8 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.test.ApiTestModule; -import org.testng.Assert; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; /** * 测试短连接 diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java index 1f28f4bb54..3036013a7e 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java @@ -2,17 +2,17 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.bean.WxCardApiSignature; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.result.WxMpCardResult; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.annotations.*; -import static org.testng.AssertJUnit.assertNotNull; +import static org.testng.AssertJUnit.*; /** * 测试代码仅供参考,未做严格测试,因原接口作者并未提供单元测试代码 * Created by Binary Wang on 2016/7/27. + * * @author binarywang (https://github.com/binarywang) */ @Test diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java index 22d0cc3ee1..0f465d4a47 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java @@ -1,83 +1,74 @@ package me.chanjar.weixin.mp.api.impl; -import java.text.ParseException; -import java.util.Date; -import java.util.List; - -import me.chanjar.weixin.mp.api.WxMpService; -import org.apache.commons.lang3.time.FastDateFormat; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; - import com.google.inject.Inject; - import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; -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.bean.datacube.*; +import org.apache.commons.lang3.time.FastDateFormat; +import org.testng.*; +import org.testng.annotations.*; + +import java.text.ParseException; +import java.util.Date; +import java.util.List; /** * 测试统计分析相关的接口 - * Created by Binary Wang on 2016/8/23. + * Created by Binary Wang on 2016/8/23. + * * @author binarywang (https://github.com/binarywang) */ @Guice(modules = ApiTestModule.class) public class WxMpDataCubeServiceImplTest { - private FastDateFormat simpleDateFormat = FastDateFormat - .getInstance("yyyy-MM-dd"); - @Inject protected WxMpService wxService; + private FastDateFormat simpleDateFormat = FastDateFormat + .getInstance("yyyy-MM-dd"); @DataProvider public Object[][] oneDay() throws ParseException { - return new Object[][] { { this.simpleDateFormat.parse("2016-08-22") } }; + return new Object[][]{{this.simpleDateFormat.parse("2016-08-22")}}; } @DataProvider public Object[][] threeDays() throws ParseException { - return new Object[][] { { this.simpleDateFormat.parse("2016-08-20"), - this.simpleDateFormat.parse("2016-08-22") } }; + return new Object[][]{{this.simpleDateFormat.parse("2016-08-20"), + this.simpleDateFormat.parse("2016-08-22")}}; } @DataProvider public Object[][] sevenDays() throws ParseException { - return new Object[][] { { this.simpleDateFormat.parse("2016-08-16"), - this.simpleDateFormat.parse("2016-08-22") } }; + return new Object[][]{{this.simpleDateFormat.parse("2016-08-16"), + this.simpleDateFormat.parse("2016-08-22")}}; } @DataProvider public Object[][] fifteenDays() throws ParseException { - return new Object[][] { { this.simpleDateFormat.parse("2016-08-14"), - this.simpleDateFormat.parse("2016-08-27") } }; + return new Object[][]{{this.simpleDateFormat.parse("2016-08-14"), + this.simpleDateFormat.parse("2016-08-27")}}; } @DataProvider public Object[][] thirtyDays() throws ParseException { - return new Object[][] { { this.simpleDateFormat.parse("2016-07-30"), - this.simpleDateFormat.parse("2016-08-27") } }; + return new Object[][]{{this.simpleDateFormat.parse("2016-07-30"), + this.simpleDateFormat.parse("2016-08-27")}}; } @Test(dataProvider = "sevenDays") public void testGetUserSummary(Date beginDate, Date endDate) - throws WxErrorException { + throws WxErrorException { List summaries = this.wxService.getDataCubeService() - .getUserSummary(beginDate, endDate); + .getUserSummary(beginDate, endDate); Assert.assertNotNull(summaries); System.out.println(summaries); } @Test(dataProvider = "sevenDays") public void testGetUserCumulate(Date beginDate, Date endDate) - throws WxErrorException { + throws WxErrorException { List result = this.wxService.getDataCubeService() - .getUserCumulate(beginDate, endDate); + .getUserCumulate(beginDate, endDate); Assert.assertNotNull(result); System.out.println(result); } @@ -85,7 +76,7 @@ public void testGetUserCumulate(Date beginDate, Date endDate) @Test(dataProvider = "oneDay") public void testGetArticleSummary(Date date) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getArticleSummary(date, date); + .getArticleSummary(date, date); Assert.assertNotNull(results); System.out.println(results); } @@ -96,16 +87,16 @@ public void testGetArticleSummary(Date date) throws WxErrorException { @Test(dataProvider = "oneDay") public void testGetArticleTotal(Date date) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getArticleTotal(date, date); + .getArticleTotal(date, date); Assert.assertNotNull(results); System.out.println(results); } @Test(dataProvider = "threeDays") public void testGetUserRead(Date beginDate, Date endDate) - throws WxErrorException { + throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUserRead(beginDate, endDate); + .getUserRead(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @@ -113,16 +104,16 @@ public void testGetUserRead(Date beginDate, Date endDate) @Test(dataProvider = "oneDay") public void testGetUserReadHour(Date date) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUserReadHour(date, date); + .getUserReadHour(date, date); Assert.assertNotNull(results); System.out.println(results); } @Test(dataProvider = "sevenDays") public void testGetUserShare(Date beginDate, Date endDate) - throws WxErrorException { + throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUserShare(beginDate, endDate); + .getUserShare(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @@ -130,7 +121,7 @@ public void testGetUserShare(Date beginDate, Date endDate) @Test(dataProvider = "oneDay") public void testGetUserShareHour(Date date) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUserShareHour(date, date); + .getUserShareHour(date, date); Assert.assertNotNull(results); System.out.println(results); } @@ -138,7 +129,7 @@ public void testGetUserShareHour(Date date) throws WxErrorException { @Test(dataProvider = "sevenDays") public void testGetUpstreamMsg(Date beginDate, Date endDate) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUpstreamMsg(beginDate, endDate); + .getUpstreamMsg(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @@ -146,7 +137,7 @@ public void testGetUpstreamMsg(Date beginDate, Date endDate) throws WxErrorExcep @Test(dataProvider = "oneDay") public void testGetUpstreamMsgHour(Date date) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUpstreamMsgHour(date, date); + .getUpstreamMsgHour(date, date); Assert.assertNotNull(results); System.out.println(results); } @@ -154,7 +145,7 @@ public void testGetUpstreamMsgHour(Date date) throws WxErrorException { @Test(dataProvider = "thirtyDays") public void testGetUpstreamMsgWeek(Date beginDate, Date endDate) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUpstreamMsgWeek(beginDate, endDate); + .getUpstreamMsgWeek(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @@ -165,7 +156,7 @@ public void testGetUpstreamMsgWeek(Date beginDate, Date endDate) throws WxErrorE @Test(dataProvider = "thirtyDays") public void testGetUpstreamMsgMonth(Date beginDate, Date endDate) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUpstreamMsgMonth(beginDate, endDate); + .getUpstreamMsgMonth(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @@ -173,7 +164,7 @@ public void testGetUpstreamMsgMonth(Date beginDate, Date endDate) throws WxError @Test(dataProvider = "fifteenDays") public void testGetUpstreamMsgDist(Date beginDate, Date endDate) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUpstreamMsgDist(beginDate, endDate); + .getUpstreamMsgDist(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @@ -181,7 +172,7 @@ public void testGetUpstreamMsgDist(Date beginDate, Date endDate) throws WxErrorE @Test(dataProvider = "thirtyDays") public void testGetUpstreamMsgDistWeek(Date beginDate, Date endDate) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUpstreamMsgDistWeek(beginDate, endDate); + .getUpstreamMsgDistWeek(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @@ -192,7 +183,7 @@ public void testGetUpstreamMsgDistWeek(Date beginDate, Date endDate) throws WxEr @Test(dataProvider = "thirtyDays") public void testGetUpstreamMsgDistMonth(Date beginDate, Date endDate) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUpstreamMsgDistMonth(beginDate, endDate); + .getUpstreamMsgDistMonth(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @@ -200,7 +191,7 @@ public void testGetUpstreamMsgDistMonth(Date beginDate, Date endDate) throws WxE @Test(dataProvider = "thirtyDays") public void testGetInterfaceSummary(Date beginDate, Date endDate) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getInterfaceSummary(beginDate, endDate); + .getInterfaceSummary(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @@ -208,7 +199,7 @@ public void testGetInterfaceSummary(Date beginDate, Date endDate) throws WxError @Test(dataProvider = "oneDay") public void testGetInterfaceSummaryHour(Date date) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getInterfaceSummaryHour(date, date); + .getInterfaceSummaryHour(date, date); Assert.assertNotNull(results); System.out.println(results); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java index 0f621e3e16..d48161e354 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java @@ -3,12 +3,10 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.device.WxDeviceQrCodeResult; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.annotations.*; /** * Created by keungtung on 14/12/2016. diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java index 105f078d96..2bf5de1dc4 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java @@ -3,25 +3,23 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; import me.chanjar.weixin.mp.bean.kefu.result.*; import org.joda.time.DateTime; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; import java.io.File; import java.util.Date; /** * 测试客服相关接口 - * @author Binary Wang * + * @author Binary Wang */ @Test @Guice(modules = ApiTestModule.class) @@ -43,25 +41,25 @@ public void testSendKefuMpNewsMessage() throws WxErrorException { public void testSendKefuMessage() throws WxErrorException { TestConfigStorage configStorage = (TestConfigStorage) this.wxService - .getWxMpConfigStorage(); + .getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); message.setToUser(configStorage.getOpenid()); message.setContent( - "欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); + "欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); this.wxService.getKefuService().sendKefuMessage(message); } public void testSendKefuMessageWithKfAccount() throws WxErrorException { TestConfigStorage configStorage = (TestConfigStorage) this.wxService - .getWxMpConfigStorage(); + .getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); message.setToUser(configStorage.getOpenid()); message.setKfAccount(configStorage.getKfAccount()); message.setContent( - "欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); + "欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); this.wxService.getKefuService().sendKefuMessage(message); } @@ -76,7 +74,7 @@ public void testKfList() throws WxErrorException { public void testKfOnlineList() throws WxErrorException { WxMpKfOnlineList kfOnlineList = this.wxService.getKefuService() - .kfOnlineList(); + .kfOnlineList(); Assert.assertNotNull(kfOnlineList); for (WxMpKfInfo k : kfOnlineList.getKfOnlineList()) { System.err.println(k); @@ -86,40 +84,40 @@ public void testKfOnlineList() throws WxErrorException { @DataProvider public Object[][] getKfAccount() { TestConfigStorage configStorage = (TestConfigStorage) this.wxService - .getWxMpConfigStorage(); - return new Object[][] { { configStorage.getKfAccount() } }; + .getWxMpConfigStorage(); + return new Object[][]{{configStorage.getKfAccount()}}; } @Test(dataProvider = "getKfAccount") public void testKfAccountAdd(String kfAccount) throws WxErrorException { WxMpKfAccountRequest request = WxMpKfAccountRequest.builder() - .kfAccount(kfAccount).nickName("我晕").build(); + .kfAccount(kfAccount).nickName("我晕").build(); Assert.assertTrue(this.wxService.getKefuService().kfAccountAdd(request)); } @Test(dependsOnMethods = { - "testKfAccountAdd" }, dataProvider = "getKfAccount") + "testKfAccountAdd"}, dataProvider = "getKfAccount") public void testKfAccountUpdate(String kfAccount) throws WxErrorException { WxMpKfAccountRequest request = WxMpKfAccountRequest.builder() - .kfAccount(kfAccount).nickName("我晕").build(); + .kfAccount(kfAccount).nickName("我晕").build(); Assert.assertTrue(this.wxService.getKefuService().kfAccountUpdate(request)); } @Test(dependsOnMethods = { - "testKfAccountAdd" }, dataProvider = "getKfAccount") + "testKfAccountAdd"}, dataProvider = "getKfAccount") public void testKfAccountInviteWorker(String kfAccount) throws WxErrorException { WxMpKfAccountRequest request = WxMpKfAccountRequest.builder() - .kfAccount(kfAccount).inviteWx(" ").build(); + .kfAccount(kfAccount).inviteWx(" ").build(); Assert.assertTrue(this.wxService.getKefuService().kfAccountInviteWorker(request)); } @Test(dependsOnMethods = { - "testKfAccountUpdate" }, dataProvider = "getKfAccount") + "testKfAccountUpdate"}, dataProvider = "getKfAccount") public void testKfAccountUploadHeadImg(String kfAccount) - throws WxErrorException { + throws WxErrorException { File imgFile = new File("src\\test\\resources\\mm.jpeg"); boolean result = this.wxService.getKefuService() - .kfAccountUploadHeadImg(kfAccount, imgFile); + .kfAccountUploadHeadImg(kfAccount, imgFile); Assert.assertTrue(result); } @@ -132,32 +130,32 @@ public void testKfAccountDel(String kfAccount) throws WxErrorException { @DataProvider public Object[][] getKfAccountAndOpenid() { TestConfigStorage configStorage = (TestConfigStorage) this.wxService - .getWxMpConfigStorage(); - return new Object[][] { - { configStorage.getKfAccount(), configStorage.getOpenid() } }; + .getWxMpConfigStorage(); + return new Object[][]{ + {configStorage.getKfAccount(), configStorage.getOpenid()}}; } @Test(dataProvider = "getKfAccountAndOpenid") public void testKfSessionCreate(String kfAccount, String openid) - throws WxErrorException { + throws WxErrorException { boolean result = this.wxService.getKefuService().kfSessionCreate(openid, - kfAccount); + kfAccount); Assert.assertTrue(result); } @Test(dataProvider = "getKfAccountAndOpenid") public void testKfSessionClose(String kfAccount, String openid) - throws WxErrorException { + throws WxErrorException { boolean result = this.wxService.getKefuService().kfSessionClose(openid, - kfAccount); + kfAccount); Assert.assertTrue(result); } @Test(dataProvider = "getKfAccountAndOpenid") public void testKfSessionGet(@SuppressWarnings("unused") String kfAccount, - String openid) throws WxErrorException { + String openid) throws WxErrorException { WxMpKfSessionGetResult result = this.wxService.getKefuService() - .kfSessionGet(openid); + .kfSessionGet(openid); Assert.assertNotNull(result); System.err.println(result); } @@ -165,7 +163,7 @@ public void testKfSessionGet(@SuppressWarnings("unused") String kfAccount, @Test(dataProvider = "getKfAccount") public void testKfSessionList(String kfAccount) throws WxErrorException { WxMpKfSessionList result = this.wxService.getKefuService() - .kfSessionList(kfAccount); + .kfSessionList(kfAccount); Assert.assertNotNull(result); System.err.println(result); } @@ -173,7 +171,7 @@ public void testKfSessionList(String kfAccount) throws WxErrorException { @Test public void testKfSessionGetWaitCase() throws WxErrorException { WxMpKfSessionWaitCaseList result = this.wxService.getKefuService() - .kfSessionGetWaitCase(); + .kfSessionGetWaitCase(); Assert.assertNotNull(result); System.err.println(result); } @@ -182,7 +180,7 @@ public void testKfSessionGetWaitCase() throws WxErrorException { public void testKfMsgList() throws WxErrorException { Date startTime = DateTime.now().minusDays(1).toDate(); Date endTime = DateTime.now().minusDays(0).toDate(); - WxMpKfMsgList result = this.wxService.getKefuService().kfMsgList(startTime,endTime, 1L, 50); + WxMpKfMsgList result = this.wxService.getKefuService().kfMsgList(startTime, endTime, 1L, 50); Assert.assertNotNull(result); System.err.println(result); } @@ -191,7 +189,7 @@ public void testKfMsgList() throws WxErrorException { public void testKfMsgListAll() throws WxErrorException { Date startTime = DateTime.now().minusDays(1).toDate(); Date endTime = DateTime.now().minusDays(0).toDate(); - WxMpKfMsgList result = this.wxService.getKefuService().kfMsgList(startTime,endTime); + WxMpKfMsgList result = this.wxService.getKefuService().kfMsgList(startTime, endTime); Assert.assertNotNull(result); System.err.println(result); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java index a3d8f47fe9..ca90a7b5ff 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java @@ -5,15 +5,10 @@ import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.bean.material.WxMpMaterial; -import me.chanjar.weixin.mp.bean.material.WxMpMaterialArticleUpdate; -import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.material.*; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.annotations.*; import java.io.File; import java.io.IOException; @@ -44,14 +39,16 @@ public class WxMpMaterialServiceImplTest { private String multiNewsMediaId = ""; // 先查询保存测试开始前永久素材数据 private WxMpMaterialCountResult wxMaterialCountResultBeforeTest; + // 以下为media接口的测试 + private List mediaIdsToDownload = new ArrayList<>(); @DataProvider public Object[][] mediaFiles() { - return new Object[][] { - new Object[] { WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, "mm.jpeg" }, - new Object[] { WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, "mm.mp3" }, - new Object[] { WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, "mm.mp4" }, - new Object[] { WxConsts.MEDIA_THUMB, WxConsts.FILE_JPG, "mm.jpeg" } + return new Object[][]{ + new Object[]{WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, "mm.jpeg"}, + new Object[]{WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, "mm.mp3"}, + new Object[]{WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, "mm.mp4"}, + new Object[]{WxConsts.MEDIA_THUMB, WxConsts.FILE_JPG, "mm.jpeg"} }; } @@ -59,13 +56,13 @@ public Object[][] mediaFiles() { public void testUploadMaterial(String mediaType, String fileType, String fileName) throws WxErrorException, IOException { if (this.wxMaterialCountResultBeforeTest == null) { this.wxMaterialCountResultBeforeTest = this.wxService.getMaterialService() - .materialCount(); + .materialCount(); } try (InputStream inputStream = ClassLoader - .getSystemResourceAsStream(fileName)) { + .getSystemResourceAsStream(fileName)) { File tempFile = FileUtils.createTmpFile(inputStream, - UUID.randomUUID().toString(), fileType); + UUID.randomUUID().toString(), fileType); WxMpMaterial wxMaterial = new WxMpMaterial(); wxMaterial.setFile(tempFile); wxMaterial.setName(fileName); @@ -75,11 +72,11 @@ public void testUploadMaterial(String mediaType, String fileType, String fileNam } WxMpMaterialUploadResult res = this.wxService.getMaterialService() - .materialFileUpload(mediaType, wxMaterial); + .materialFileUpload(mediaType, wxMaterial); assertNotNull(res.getMediaId()); if (WxConsts.MEDIA_IMAGE.equals(mediaType) - || WxConsts.MEDIA_THUMB.equals(mediaType)) { + || WxConsts.MEDIA_THUMB.equals(mediaType)) { assertNotNull(res.getUrl()); } @@ -145,16 +142,16 @@ public void testMaterialCount() throws WxErrorException { WxMpMaterialCountResult wxMaterialCountResult = this.wxService.getMaterialService().materialCount(); // 测试上传过程中添加了一个音频,一个视频,两个图片,两个图文消息 assertEquals( - this.wxMaterialCountResultBeforeTest.getVoiceCount() + 1, - wxMaterialCountResult.getVoiceCount()); + this.wxMaterialCountResultBeforeTest.getVoiceCount() + 1, + wxMaterialCountResult.getVoiceCount()); assertEquals( - this.wxMaterialCountResultBeforeTest.getVideoCount() + 1, - wxMaterialCountResult.getVideoCount()); + this.wxMaterialCountResultBeforeTest.getVideoCount() + 1, + wxMaterialCountResult.getVideoCount()); assertEquals( - this.wxMaterialCountResultBeforeTest.getImageCount() + 2, - wxMaterialCountResult.getImageCount()); + this.wxMaterialCountResultBeforeTest.getImageCount() + 2, + wxMaterialCountResult.getImageCount()); assertEquals(this.wxMaterialCountResultBeforeTest.getNewsCount() + 2, - wxMaterialCountResult.getNewsCount()); + wxMaterialCountResult.getNewsCount()); } @Test(dependsOnMethods = {"testMaterialCount"}, dataProvider = "downloadMaterial") @@ -164,7 +161,7 @@ public void testDownloadMaterial(String mediaId) throws WxErrorException, IOExce String filename = materialInfo.get("filename").toString(); if (filename.endsWith(".mp3") || filename.endsWith(".jpeg")) { try (InputStream inputStream = this.wxService.getMaterialService() - .materialImageOrVoiceDownload(mediaId)) { + .materialImageOrVoiceDownload(mediaId)) { assertNotNull(inputStream); } } @@ -178,9 +175,9 @@ public void testDownloadMaterial(String mediaId) throws WxErrorException, IOExce @Test(dependsOnMethods = {"testAddNews"}) public void testGetNewsInfo() throws WxErrorException { WxMpMaterialNews wxMpMaterialNewsSingle = this.wxService - .getMaterialService().materialNewsInfo(this.singleNewsMediaId); + .getMaterialService().materialNewsInfo(this.singleNewsMediaId); WxMpMaterialNews wxMpMaterialNewsMultiple = this.wxService - .getMaterialService().materialNewsInfo(this.multiNewsMediaId); + .getMaterialService().materialNewsInfo(this.multiNewsMediaId); assertNotNull(wxMpMaterialNewsSingle); assertNotNull(wxMpMaterialNewsMultiple); } @@ -188,7 +185,7 @@ public void testGetNewsInfo() throws WxErrorException { @Test(dependsOnMethods = {"testGetNewsInfo"}) public void testUpdateNewsInfo() throws WxErrorException { WxMpMaterialNews wxMpMaterialNewsSingle = this.wxService - .getMaterialService().materialNewsInfo(this.singleNewsMediaId); + .getMaterialService().materialNewsInfo(this.singleNewsMediaId); assertNotNull(wxMpMaterialNewsSingle); WxMpMaterialArticleUpdate wxMpMaterialArticleUpdateSingle = new WxMpMaterialArticleUpdate(); WxMpMaterialNews.WxMpMaterialNewsArticle articleSingle = wxMpMaterialNewsSingle.getArticles().get(0); @@ -199,13 +196,13 @@ public void testUpdateNewsInfo() throws WxErrorException { boolean resultSingle = this.wxService.getMaterialService().materialNewsUpdate(wxMpMaterialArticleUpdateSingle); assertTrue(resultSingle); wxMpMaterialNewsSingle = this.wxService.getMaterialService() - .materialNewsInfo(this.singleNewsMediaId); + .materialNewsInfo(this.singleNewsMediaId); assertNotNull(wxMpMaterialNewsSingle); assertEquals("content single update", - wxMpMaterialNewsSingle.getArticles().get(0).getContent()); + wxMpMaterialNewsSingle.getArticles().get(0).getContent()); WxMpMaterialNews wxMpMaterialNewsMultiple = this.wxService - .getMaterialService().materialNewsInfo(this.multiNewsMediaId); + .getMaterialService().materialNewsInfo(this.multiNewsMediaId); assertNotNull(wxMpMaterialNewsMultiple); WxMpMaterialArticleUpdate wxMpMaterialArticleUpdateMulti = new WxMpMaterialArticleUpdate(); WxMpMaterialNews.WxMpMaterialNewsArticle articleMulti = wxMpMaterialNewsMultiple.getArticles().get(1); @@ -216,10 +213,10 @@ public void testUpdateNewsInfo() throws WxErrorException { boolean resultMulti = this.wxService.getMaterialService().materialNewsUpdate(wxMpMaterialArticleUpdateMulti); assertTrue(resultMulti); wxMpMaterialNewsMultiple = this.wxService.getMaterialService() - .materialNewsInfo(this.multiNewsMediaId); + .materialNewsInfo(this.multiNewsMediaId); assertNotNull(wxMpMaterialNewsMultiple); assertEquals("content 2 update", - wxMpMaterialNewsMultiple.getArticles().get(1).getContent()); + wxMpMaterialNewsMultiple.getArticles().get(1).getContent()); } @Test(dependsOnMethods = {"testUpdateNewsInfo"}) @@ -266,12 +263,9 @@ public Iterator allTestMaterial() { return params.iterator(); } - // 以下为media接口的测试 - private List mediaIdsToDownload = new ArrayList<>(); - - @Test(dataProvider="mediaFiles") + @Test(dataProvider = "mediaFiles") public void testUploadMedia(String mediaType, String fileType, String fileName) throws WxErrorException, IOException { - try(InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName)){ + try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName)) { WxMediaUploadResult res = this.wxService.getMaterialService().mediaUpload(mediaType, fileType, inputStream); assertNotNull(res.getType()); assertNotNull(res.getCreatedAt()); @@ -294,12 +288,12 @@ public void testUploadMedia(String mediaType, String fileType, String fileName) public Object[][] downloadMedia() { Object[][] params = new Object[this.mediaIdsToDownload.size()][]; for (int i = 0; i < this.mediaIdsToDownload.size(); i++) { - params[i] = new Object[] { this.mediaIdsToDownload.get(i) }; + params[i] = new Object[]{this.mediaIdsToDownload.get(i)}; } return params; } - @Test(dependsOnMethods = { "testUploadMedia" }, dataProvider="downloadMedia") + @Test(dependsOnMethods = {"testUploadMedia"}, dataProvider = "downloadMedia") public void testDownloadMedia(String mediaId) throws WxErrorException { File file = this.wxService.getMaterialService().mediaDownload(mediaId); assertNotNull(file); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java index 45703b7b32..42819b2f60 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java @@ -5,8 +5,8 @@ import me.chanjar.weixin.common.bean.menu.WxMenu; import me.chanjar.weixin.common.bean.menu.WxMenuButton; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult; import me.chanjar.weixin.mp.bean.menu.WxMpMenu; import org.testng.*; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index e890deda6a..2783ee7f71 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -3,8 +3,8 @@ import com.github.binarywang.utils.qrcode.QrcodeUtils; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.pay.request.*; import me.chanjar.weixin.mp.bean.pay.result.*; @@ -36,10 +36,10 @@ public void testGetPayInfo() throws Exception { @Test public void testDownloadBill() throws Exception { - File file = this.wxService.getPayService().downloadBill("20170101","ALL","GZIP","1111111"); + File file = this.wxService.getPayService().downloadBill("20170101", "ALL", "GZIP", "1111111"); assertNotNull(file); //必填字段为空时,抛出异常 - this.wxService.getPayService().downloadBill("","","",null); + this.wxService.getPayService().downloadBill("", "", "", null); } @Test @@ -58,7 +58,7 @@ public void testReport() throws Exception { * 需要证书的接口需要先执行该方法 */ @Test - public void setSSLKey(){ + public void setSSLKey() { TestConfigStorage config = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); config.setSslContextFilePath(config.getKeyPath()); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java index b7957e7f5d..c61e38339c 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java @@ -2,13 +2,11 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; import java.io.File; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java index ffb5563656..d5bf621287 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java @@ -2,12 +2,11 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; -import org.testng.Assert; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test @Guice(modules = ApiTestModule.class) @@ -105,7 +104,7 @@ public void testOauth2buildAuthorizationUrl() { public void testBuildQrConnectUrl() { String qrconnectRedirectUrl = ((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getQrconnectRedirectUrl(); String qrConnectUrl = this.wxService.buildQrConnectUrl(qrconnectRedirectUrl, - WxConsts.QRCONNECT_SCOPE_SNSAPI_LOGIN, null); + WxConsts.QRCONNECT_SCOPE_SNSAPI_LOGIN, null); Assert.assertNotNull(qrConnectUrl); System.out.println(qrConnectUrl); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java index 0a6b561046..e4edca7491 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java @@ -2,13 +2,12 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; 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 org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.annotations.*; import java.math.BigDecimal; import java.util.List; @@ -18,7 +17,6 @@ /** * @author binarywang(Binary Wang) * Created by Binary Wang on 2016-09-23. - * */ @Test @Guice(modules = ApiTestModule.class) @@ -28,16 +26,17 @@ public class WxMpStoreServiceImplTest { /** * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpStoreServiceImpl#add(me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo)}. + * * @throws WxErrorException */ public void testAdd() throws WxErrorException { this.wxMpService.getStoreService().add(WxMpStoreBaseInfo.builder().build()); this.wxMpService.getStoreService() - .add(WxMpStoreBaseInfo.builder().businessName("haha").branchName("abc") - .province("aaa").district("aaa").telephone("122").address("abc").categories(new String[] { "美食,江浙菜" }) - .longitude(new BigDecimal("115.32375")) - .latitude(new BigDecimal("25.097486")).city("aaa").offsetType(1) - .build()); + .add(WxMpStoreBaseInfo.builder().businessName("haha").branchName("abc") + .province("aaa").district("aaa").telephone("122").address("abc").categories(new String[]{"美食,江浙菜"}) + .longitude(new BigDecimal("115.32375")) + .latitude(new BigDecimal("25.097486")).city("aaa").offsetType(1) + .build()); } public void testUpdate() throws WxErrorException { diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java index 289323625f..2c348702ca 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java @@ -2,17 +2,16 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.template.WxMpTemplate; import me.chanjar.weixin.mp.bean.template.WxMpTemplateData; import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry; import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; import org.apache.commons.lang3.RandomStringUtils; -import org.testng.Assert; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; import java.text.SimpleDateFormat; import java.util.Date; @@ -39,7 +38,7 @@ public void testSendTemplateMsg() throws WxErrorException { .toUser(configStorage.getOpenid()) .templateId(configStorage.getTemplateId()).build(); templateMessage.addWxMpTemplateData( - new WxMpTemplateData("first", dateFormat.format(new Date()),"#FF00FF")); + new WxMpTemplateData("first", dateFormat.format(new Date()), "#FF00FF")); templateMessage.addWxMpTemplateData( new WxMpTemplateData("remark", RandomStringUtils.randomAlphanumeric(100), "#FF00FF")); templateMessage.setUrl(" "); @@ -58,7 +57,7 @@ public void testGetIndustry() throws Exception { @Test public void testSetIndustry() throws Exception { WxMpTemplateIndustry industry = new WxMpTemplateIndustry(new WxMpTemplateIndustry.Industry("1"), - new WxMpTemplateIndustry.Industry("04")); + new WxMpTemplateIndustry.Industry("04")); boolean result = this.wxService.getTemplateMsgService().setIndustry(industry); Assert.assertTrue(result); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java index 14796f9c30..528ca2908e 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java @@ -1,12 +1,11 @@ package me.chanjar.weixin.mp.api.impl; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; -import org.testng.Assert; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; import javax.inject.Inject; import java.util.ArrayList; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java index 3163ed6911..09ba9e99e3 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java @@ -1,23 +1,18 @@ - package me.chanjar.weixin.mp.api.impl; -import java.util.ArrayList; -import java.util.List; - -import me.chanjar.weixin.mp.api.WxMpService; -import org.testng.Assert; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; - import com.google.inject.Inject; - import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.WxMpUserQuery; import me.chanjar.weixin.mp.bean.result.WxMpUser; import me.chanjar.weixin.mp.bean.result.WxMpUserList; +import org.testng.*; +import org.testng.annotations.*; + +import java.util.ArrayList; +import java.util.List; /** * 测试用户相关的接口 @@ -37,17 +32,17 @@ public class WxMpUserServiceImplTest { @BeforeTest public void setup() { this.configProvider = (TestConfigStorage) this.wxService - .getWxMpConfigStorage(); + .getWxMpConfigStorage(); } public void testUserUpdateRemark() throws WxErrorException { this.wxService.getUserService() - .userUpdateRemark(this.configProvider.getOpenid(), "测试备注名"); + .userUpdateRemark(this.configProvider.getOpenid(), "测试备注名"); } public void testUserInfo() throws WxErrorException { WxMpUser user = this.wxService.getUserService() - .userInfo(this.configProvider.getOpenid(), null); + .userInfo(this.configProvider.getOpenid(), null); Assert.assertNotNull(user); System.out.println(user); } @@ -56,7 +51,7 @@ public void testUserInfoList() throws WxErrorException { List openids = new ArrayList<>(); openids.add(this.configProvider.getOpenid()); List userList = this.wxService.getUserService() - .userInfoList(openids); + .userInfoList(openids); Assert.assertEquals(userList.size(), 1); System.out.println(userList); } @@ -65,7 +60,7 @@ public void testUserInfoListByWxMpUserQuery() throws WxErrorException { WxMpUserQuery query = new WxMpUserQuery(); query.add(this.configProvider.getOpenid(), "zh_CN"); List userList = this.wxService.getUserService() - .userInfoList(query); + .userInfoList(query); Assert.assertEquals(userList.size(), 1); System.out.println(userList); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java index 54743ac41e..cc8676d477 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java @@ -1,21 +1,17 @@ package me.chanjar.weixin.mp.api.impl; -import java.util.List; - -import me.chanjar.weixin.mp.api.WxMpService; -import org.testng.Assert; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; - import com.google.inject.Inject; - +import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.tag.WxTagListUser; import me.chanjar.weixin.mp.bean.tag.WxUserTag; +import org.testng.*; +import org.testng.annotations.*; + +import java.util.List; /** - * * @author binarywang(Binary Wang) * Created by Binary Wang on 2016/9/2. */ @@ -43,7 +39,7 @@ public void testTagGet() throws Exception { Assert.assertNotNull(res); } - @Test(dependsOnMethods = { "testTagCreate" }) + @Test(dependsOnMethods = {"testTagCreate"}) public void testTagUpdate() throws Exception { String tagName = "修改标签" + System.currentTimeMillis(); Boolean res = this.wxService.getUserTagService().tagUpdate(this.tagId, tagName); @@ -51,7 +47,7 @@ public void testTagUpdate() throws Exception { Assert.assertTrue(res); } - @Test(dependsOnMethods = { "testTagCreate" }) + @Test(dependsOnMethods = {"testTagCreate"}) public void testTagDelete() throws Exception { Boolean res = this.wxService.getUserTagService().tagDelete(this.tagId); System.out.println(res); @@ -84,7 +80,7 @@ public void testBatchUntagging() throws Exception { @Test public void testUserTagList() throws Exception { List res = this.wxService.getUserTagService().userTagList( - ((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); + ((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); System.out.println(res); Assert.assertNotNull(res); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessageTest.java index 9f19029e8c..c25c502495 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessageTest.java @@ -2,8 +2,8 @@ import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage.WxArticle; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpKefuMessageTest { @@ -77,13 +77,13 @@ public void testMusicReply() { public void testMusicBuild() { WxMpKefuMessage reply = WxMpKefuMessage.MUSIC() - .toUser("OPENID") - .title("TITLE") - .thumbMediaId("MEDIA_ID") - .description("DESCRIPTION") - .musicUrl("MUSIC_URL") - .hqMusicUrl("HQ_MUSIC_URL") - .build(); + .toUser("OPENID") + .title("TITLE") + .thumbMediaId("MEDIA_ID") + .description("DESCRIPTION") + .musicUrl("MUSIC_URL") + .hqMusicUrl("HQ_MUSIC_URL") + .build(); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}"); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfListTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfListTest.java index 0f52ae0260..282890e0e2 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfListTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfListTest.java @@ -1,36 +1,36 @@ package me.chanjar.weixin.mp.bean.kefu.result; import org.apache.commons.lang3.builder.ToStringBuilder; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpKfListTest { public void testFromJson() { - String json=" {\r\n" + - " \"kf_list\" : [\r\n" + - " {\r\n" + - " \"kf_account\" : \"test1@test\",\r\n" + - " \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" + - " \"kf_id\" : \"1001\",\r\n" + - " \"kf_nick\" : \"ntest1\"\r\n" + - " },\r\n" + - " {\r\n" + - " \"kf_account\" : \"test2@test\",\r\n" + - " \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" + - " \"kf_id\" : \"1002\",\r\n" + - " \"kf_nick\" : \"ntest2\"\r\n" + - " },\r\n" + - " {\r\n" + - " \"kf_account\" : \"test3@test\",\r\n" + - " \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" + - " \"kf_id\" : \"1003\",\r\n" + - " \"kf_nick\" : \"ntest3\"\r\n" + - " }\r\n" + - " ]\r\n" + - " }"; - + String json = " {\r\n" + + " \"kf_list\" : [\r\n" + + " {\r\n" + + " \"kf_account\" : \"test1@test\",\r\n" + + " \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" + + " \"kf_id\" : \"1001\",\r\n" + + " \"kf_nick\" : \"ntest1\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"kf_account\" : \"test2@test\",\r\n" + + " \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" + + " \"kf_id\" : \"1002\",\r\n" + + " \"kf_nick\" : \"ntest2\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"kf_account\" : \"test3@test\",\r\n" + + " \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" + + " \"kf_id\" : \"1003\",\r\n" + + " \"kf_nick\" : \"ntest3\"\r\n" + + " }\r\n" + + " ]\r\n" + + " }"; + WxMpKfList wxMpKfList = WxMpKfList.fromJson(json); Assert.assertNotNull(wxMpKfList); System.err.println(ToStringBuilder.reflectionToString(wxMpKfList)); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfOnlineListTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfOnlineListTest.java index fa514aba7a..daf98ab167 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfOnlineListTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfOnlineListTest.java @@ -1,34 +1,32 @@ package me.chanjar.weixin.mp.bean.kefu.result; import org.apache.commons.lang3.builder.ToStringBuilder; -import org.testng.Assert; -import org.testng.annotations.Test; - -import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfOnlineList; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpKfOnlineListTest { @Test public void testFromJson() { - String json = "{\r\n" + - " \"kf_online_list\": [\r\n" + - " {\r\n" + - " \"kf_account\": \"test1@test\", \r\n" + - " \"status\": 1, \r\n" + - " \"kf_id\": \"1001\", \r\n" + - " \"auto_accept\": 0, \r\n" + - " \"accepted_case\": 1\r\n" + - " },\r\n" + - " {\r\n" + - " \"kf_account\": \"test2@test\", \r\n" + - " \"status\": 1, \r\n" + - " \"kf_id\": \"1002\", \r\n" + - " \"auto_accept\": 0, \r\n" + - " \"accepted_case\": 2\r\n" + - " }\r\n" + - " ]\r\n" + - "}"; + String json = "{\r\n" + + " \"kf_online_list\": [\r\n" + + " {\r\n" + + " \"kf_account\": \"test1@test\", \r\n" + + " \"status\": 1, \r\n" + + " \"kf_id\": \"1001\", \r\n" + + " \"auto_accept\": 0, \r\n" + + " \"accepted_case\": 1\r\n" + + " },\r\n" + + " {\r\n" + + " \"kf_account\": \"test2@test\", \r\n" + + " \"status\": 1, \r\n" + + " \"kf_id\": \"1002\", \r\n" + + " \"auto_accept\": 0, \r\n" + + " \"accepted_case\": 2\r\n" + + " }\r\n" + + " ]\r\n" + + "}"; WxMpKfOnlineList wxMpKfOnlineList = WxMpKfOnlineList.fromJson(json); Assert.assertNotNull(wxMpKfOnlineList); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java index 23de3fe667..bbb8ce83ee 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java @@ -1,8 +1,8 @@ package me.chanjar.weixin.mp.bean.message; import me.chanjar.weixin.common.api.WxConsts; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpXmlMessageTest { diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutImageMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutImageMessageTest.java index 3addedb530..ab732c315c 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutImageMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutImageMessageTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.bean.message; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpXmlOutImageMessageTest { @@ -14,12 +14,12 @@ public void test() { m.setToUserName("to"); String expected = "" - + "" - + "" - + "1122" - + "" - + "" - + ""; + + "" + + "" + + "1122" + + "" + + "" + + ""; System.out.println(m.toXml()); Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); } @@ -27,22 +27,22 @@ public void test() { public void testBuild() { WxMpXmlOutImageMessage m = WxMpXmlOutMessage.IMAGE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build(); String expected = "" - + "" - + "" - + "1122" - + "" - + "" - + ""; + + "" + + "" + + "1122" + + "" + + "" + + ""; System.out.println(m.toXml()); Assert.assertEquals( - m - .toXml() - .replaceAll("\\s", "") - .replaceAll(".*?", ""), - expected - .replaceAll("\\s", "") - .replaceAll(".*?", "") - ); + m + .toXml() + .replaceAll("\\s", "") + .replaceAll(".*?", ""), + expected + .replaceAll("\\s", "") + .replaceAll(".*?", "") + ); } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessageTest.java index 3e7a96f0aa..f75e6321e6 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessageTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.bean.message; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpXmlOutMusicMessageTest { @@ -18,55 +18,55 @@ public void test() { m.setToUserName("toUser"); String expected = "" - + "" - + "" - + "1122" - + "" - + "" - + " <![CDATA[title]]>" - + " " - + " " - + " " - + " " - + " " - + ""; + + "" + + "" + + "1122" + + "" + + "" + + " <![CDATA[title]]>" + + " " + + " " + + " " + + " " + + " " + + ""; System.out.println(m.toXml()); Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); } public void testBuild() { WxMpXmlOutMusicMessage m = WxMpXmlOutMessage.MUSIC() - .fromUser("fromUser") - .toUser("toUser") - .title("title") - .description("ddfff") - .hqMusicUrl("hQMusicUrl") - .musicUrl("musicUrl") - .thumbMediaId("thumbMediaId") - .build(); + .fromUser("fromUser") + .toUser("toUser") + .title("title") + .description("ddfff") + .hqMusicUrl("hQMusicUrl") + .musicUrl("musicUrl") + .thumbMediaId("thumbMediaId") + .build(); String expected = "" - + "" - + "" - + "1122" - + "" - + "" - + " <![CDATA[title]]>" - + " " - + " " - + " " - + " " - + " " - + ""; + + "" + + "" + + "1122" + + "" + + "" + + " <![CDATA[title]]>" + + " " + + " " + + " " + + " " + + " " + + ""; System.out.println(m.toXml()); Assert.assertEquals( - m + m .toXml() .replaceAll("\\s", "") .replaceAll(".*?", ""), - expected + expected .replaceAll("\\s", "") .replaceAll(".*?", "") - ); + ); } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutNewsMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutNewsMessageTest.java index 60d8571af0..c9a1f98264 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutNewsMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutNewsMessageTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.bean.message; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpXmlOutNewsMessageTest { @@ -20,26 +20,26 @@ public void test() { m.addArticle(item); m.addArticle(item); String expected = "" - + "" - + "" - + "1122" - + "" - + " 2" - + " " - + " " - + " <![CDATA[title]]>" - + " " - + " " - + " " - + " " - + " " - + " <![CDATA[title]]>" - + " " - + " " - + " " - + " " - + " " - + ""; + + "" + + "" + + "1122" + + "" + + " 2" + + " " + + " " + + " <![CDATA[title]]>" + + " " + + " " + + " " + + " " + + " " + + " <![CDATA[title]]>" + + " " + + " " + + " " + + " " + + " " + + ""; System.out.println(m.toXml()); Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); } @@ -52,42 +52,42 @@ public void testBuild() { item.setUrl("url"); WxMpXmlOutNewsMessage m = WxMpXmlOutMessage.NEWS() - .fromUser("fromUser") - .toUser("toUser") - .addArticle(item) - .addArticle(item) - .build(); + .fromUser("fromUser") + .toUser("toUser") + .addArticle(item) + .addArticle(item) + .build(); String expected = "" - + "" - + "" - + "1122" - + "" - + " 2" - + " " - + " " - + " <![CDATA[title]]>" - + " " - + " " - + " " - + " " - + " " - + " <![CDATA[title]]>" - + " " - + " " - + " " - + " " - + " " - + ""; + + "" + + "" + + "1122" + + "" + + " 2" + + " " + + " " + + " <![CDATA[title]]>" + + " " + + " " + + " " + + " " + + " " + + " <![CDATA[title]]>" + + " " + + " " + + " " + + " " + + " " + + ""; System.out.println(m.toXml()); Assert.assertEquals( - m + m .toXml() .replaceAll("\\s", "") .replaceAll(".*?", ""), - expected + expected .replaceAll("\\s", "") .replaceAll(".*?", "") - ); + ); } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTextMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTextMessageTest.java index 566589671a..c005c26107 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTextMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTextMessageTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.bean.message; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpXmlOutTextMessageTest { @@ -14,12 +14,12 @@ public void test() { m.setToUserName("to"); String expected = "" - + "" - + "" - + "1122" - + "" - + "" - + ""; + + "" + + "" + + "1122" + + "" + + "" + + ""; System.out.println(m.toXml()); Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); } @@ -27,22 +27,22 @@ public void test() { public void testBuild() { WxMpXmlOutTextMessage m = WxMpXmlOutMessage.TEXT().content("content").fromUser("from").toUser("to").build(); String expected = "" - + "" - + "" - + "1122" - + "" - + "" - + ""; + + "" + + "" + + "1122" + + "" + + "" + + ""; System.out.println(m.toXml()); Assert.assertEquals( - m + m .toXml() .replaceAll("\\s", "") .replaceAll(".*?", ""), - expected + expected .replaceAll("\\s", "") .replaceAll(".*?", "") - ); + ); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTransferKefuMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTransferKefuMessageTest.java index 222f563f2e..97dfdd96e9 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTransferKefuMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTransferKefuMessageTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.bean.message; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; /** * Created by ben on 2015/12/29. diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVideoMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVideoMessageTest.java index 0c53b28ad9..2ba9f549de 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVideoMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVideoMessageTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.bean.message; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpXmlOutVideoMessageTest { @@ -16,49 +16,49 @@ public void test() { m.setToUserName("toUser"); String expected = "" - + "" - + "" - + "1122" - + "" - + " " - + ""; + + "" + + "" + + "1122" + + "" + + " " + + ""; System.out.println(m.toXml()); Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); } public void testBuild() { WxMpXmlOutVideoMessage m = WxMpXmlOutMessage.VIDEO() - .mediaId("media_id") - .fromUser("fromUser") - .toUser("toUser") - .title("title") - .description("ddfff") - .build(); + .mediaId("media_id") + .fromUser("fromUser") + .toUser("toUser") + .title("title") + .description("ddfff") + .build(); String expected = "" - + "" - + "" - + "1122" - + "" - + " " - + ""; + + "" + + "" + + "1122" + + "" + + " " + + ""; System.out.println(m.toXml()); Assert.assertEquals( - m + m .toXml() .replaceAll("\\s", "") .replaceAll(".*?", ""), - expected + expected .replaceAll("\\s", "") .replaceAll(".*?", "") - ); + ); } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVoiceMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVoiceMessageTest.java index 3431439047..d3f1346fec 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVoiceMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVoiceMessageTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.bean.message; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpXmlOutVoiceMessageTest { @@ -14,12 +14,12 @@ public void test() { m.setToUserName("to"); String expected = "" - + "" - + "" - + "1122" - + "" - + "" - + ""; + + "" + + "" + + "1122" + + "" + + "" + + ""; System.out.println(m.toXml()); Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); } @@ -27,22 +27,22 @@ public void test() { public void testBuild() { WxMpXmlOutVoiceMessage m = WxMpXmlOutMessage.VOICE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build(); String expected = "" - + "" - + "" - + "1122" - + "" - + "" - + ""; + + "" + + "" + + "1122" + + "" + + "" + + ""; System.out.println(m.toXml()); Assert.assertEquals( - m + m .toXml() .replaceAll("\\s", "") .replaceAll(".*?", ""), - expected + expected .replaceAll("\\s", "") .replaceAll(".*?", "") - ); + ); } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResultTest.java index 0b1e7ac9f7..aaab37a2bd 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResultTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResultTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.bean.pay.result; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; import java.util.Map; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java index 1582ea176a..e0fd980810 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.bean.pay.result; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; /** *
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java
    index 34672417f9..6b8a9ae913 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java
    @@ -1,8 +1,8 @@
     package me.chanjar.weixin.mp.bean.pay.result;
     
     
    -import org.testng.Assert;
    -import org.testng.annotations.Test;
    +import org.testng.*;
    +import org.testng.annotations.*;
     
     /**
      * 
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPaySendRedpackResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPaySendRedpackResultTest.java
    index a07ec9723c..f2aa0a9449 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPaySendRedpackResultTest.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPaySendRedpackResultTest.java
    @@ -2,9 +2,8 @@
     
     import com.thoughtworks.xstream.XStream;
     import me.chanjar.weixin.common.util.xml.XStreamInitializer;
    -import org.testng.Assert;
    -import org.testng.annotations.BeforeTest;
    -import org.testng.annotations.Test;
    +import org.testng.*;
    +import org.testng.annotations.*;
     
     public class WxPaySendRedpackResultTest {
     
    @@ -12,26 +11,26 @@ public class WxPaySendRedpackResultTest {
     
       @BeforeTest
       public void setup() {
    -     this.xstream = XStreamInitializer.getInstance();
    -     this.xstream.processAnnotations(WxPaySendRedpackResult.class);
    +    this.xstream = XStreamInitializer.getInstance();
    +    this.xstream.processAnnotations(WxPaySendRedpackResult.class);
       }
     
       @Test
       public void loadSuccessResult() {
         final String successSample = "\n" +
    -        "\n" +
    -        "\n" +
    -        "\n" +
    -        "\n" +
    -        "\n" +
    -        "\n" +
    -        "10010404\n" +
    -        "\n" +
    -        "\n" +
    -        "1\n" +
    -        "100000000020150520314766074200\n" +
    -        "20150520102602\n" +
    -        "";
    +      "\n" +
    +      "\n" +
    +      "\n" +
    +      "\n" +
    +      "\n" +
    +      "\n" +
    +      "10010404\n" +
    +      "\n" +
    +      "\n" +
    +      "1\n" +
    +      "100000000020150520314766074200\n" +
    +      "20150520102602\n" +
    +      "";
         WxPaySendRedpackResult wxMpRedpackResult = (WxPaySendRedpackResult) this.xstream.fromXML(successSample);
         Assert.assertEquals("SUCCESS", wxMpRedpackResult.getReturnCode());
         Assert.assertEquals("SUCCESS", wxMpRedpackResult.getResultCode());
    @@ -41,17 +40,17 @@ public void loadSuccessResult() {
       @Test
       public void loadFailureResult() {
         final String failureSample = "\n" +
    -        "\n" +
    -        "\n" +
    -        "\n" +
    -        "\n" +
    -        "\n" +
    -        "\n" +
    -        "10010404\n" +
    -        "\n" +
    -        "\n" +
    -        "1\n" +
    -        "";
    +      "\n" +
    +      "\n" +
    +      "\n" +
    +      "\n" +
    +      "\n" +
    +      "\n" +
    +      "10010404\n" +
    +      "\n" +
    +      "\n" +
    +      "1\n" +
    +      "";
         WxPaySendRedpackResult wxMpRedpackResult = (WxPaySendRedpackResult) this.xstream.fromXML(failureSample);
         Assert.assertEquals("FAIL", wxMpRedpackResult.getReturnCode());
         Assert.assertEquals("FAIL", wxMpRedpackResult.getResultCode());
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoGuessNumberHandler.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoGuessNumberHandler.java
    index 69636d0bd0..1743b1f955 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoGuessNumberHandler.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoGuessNumberHandler.java
    @@ -1,9 +1,5 @@
     package me.chanjar.weixin.mp.demo;
     
    -import java.util.Map;
    -import java.util.Random;
    -import java.util.regex.Pattern;
    -
     import me.chanjar.weixin.common.exception.WxErrorException;
     import me.chanjar.weixin.common.session.WxSession;
     import me.chanjar.weixin.common.session.WxSessionManager;
    @@ -14,6 +10,10 @@
     import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
     import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
     
    +import java.util.Map;
    +import java.util.Random;
    +import java.util.regex.Pattern;
    +
     public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMatcher {
     
       private Random random = new Random();
    @@ -35,7 +35,7 @@ private boolean isUserAnswering(WxMpXmlMessage message) {
     
       @Override
       public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context, WxMpService wxMpService,
    -      WxSessionManager sessionManager) throws WxErrorException {
    +                                  WxSessionManager sessionManager) throws WxErrorException {
     
         if (isUserWantGuess(wxMessage)) {
           letsGo(wxMessage, wxMpService, sessionManager);
    @@ -53,17 +53,17 @@ protected void letsGo(WxMpXmlMessage wxMessage, WxMpService wxMpService, WxSessi
         WxSession session = sessionManager.getSession(wxMessage.getFromUser());
         if (session.getAttribute("guessing") == null) {
           WxMpKefuMessage m = WxMpKefuMessage
    -          .TEXT()
    -          .toUser(wxMessage.getFromUser())
    -          .content("请猜一个100以内的数字")
    -          .build();
    +        .TEXT()
    +        .toUser(wxMessage.getFromUser())
    +        .content("请猜一个100以内的数字")
    +        .build();
           wxMpService.getKefuService().sendKefuMessage(m);
         } else {
           WxMpKefuMessage m = WxMpKefuMessage
    -          .TEXT()
    -          .toUser(wxMessage.getFromUser())
    -          .content("放弃了吗?那请重新猜一个100以内的数字")
    -          .build();
    +        .TEXT()
    +        .toUser(wxMessage.getFromUser())
    +        .content("放弃了吗?那请重新猜一个100以内的数字")
    +        .build();
           wxMpService.getKefuService().sendKefuMessage(m);
         }
     
    @@ -88,25 +88,25 @@ protected void giveHint(WxMpXmlMessage wxMessage, WxMpService wxMpService, WxSes
         int guessNumber = Integer.valueOf(wxMessage.getContent());
         if (guessNumber < answer) {
           WxMpKefuMessage m = WxMpKefuMessage
    -          .TEXT()
    -          .toUser(wxMessage.getFromUser())
    -          .content("小了")
    -          .build();
    +        .TEXT()
    +        .toUser(wxMessage.getFromUser())
    +        .content("小了")
    +        .build();
           wxMpService.getKefuService().sendKefuMessage(m);
     
         } else if (guessNumber > answer) {
           WxMpKefuMessage m = WxMpKefuMessage
    -          .TEXT()
    -          .toUser(wxMessage.getFromUser())
    -          .content("大了")
    -          .build();
    +        .TEXT()
    +        .toUser(wxMessage.getFromUser())
    +        .content("大了")
    +        .build();
           wxMpService.getKefuService().sendKefuMessage(m);
         } else {
           WxMpKefuMessage m = WxMpKefuMessage
    -          .TEXT()
    -          .toUser(wxMessage.getFromUser())
    -          .content("Bingo!")
    -          .build();
    +        .TEXT()
    +        .toUser(wxMessage.getFromUser())
    +        .content("Bingo!")
    +        .build();
           session.removeAttribute("guessing");
           wxMpService.getKefuService().sendKefuMessage(m);
         }
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoImageHandler.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoImageHandler.java
    index 145a01307e..2cfb8ce362 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoImageHandler.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoImageHandler.java
    @@ -15,17 +15,17 @@
     public class DemoImageHandler implements WxMpMessageHandler {
       @Override
       public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context,
    -      WxMpService wxMpService, WxSessionManager sessionManager) {
    +                                  WxMpService wxMpService, WxSessionManager sessionManager) {
         try {
           WxMediaUploadResult wxMediaUploadResult = wxMpService.getMaterialService()
    -          .mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, ClassLoader.getSystemResourceAsStream("mm.jpeg"));
    +        .mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, ClassLoader.getSystemResourceAsStream("mm.jpeg"));
           WxMpXmlOutImageMessage m
    -          = WxMpXmlOutMessage
    -          .IMAGE()
    -          .mediaId(wxMediaUploadResult.getMediaId())
    -          .fromUser(wxMessage.getToUser())
    -          .toUser(wxMessage.getFromUser())
    -          .build();
    +        = WxMpXmlOutMessage
    +        .IMAGE()
    +        .mediaId(wxMediaUploadResult.getMediaId())
    +        .fromUser(wxMessage.getToUser())
    +        .toUser(wxMessage.getFromUser())
    +        .build();
           return m;
         } catch (WxErrorException e) {
           e.printStackTrace();
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoLogHandler.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoLogHandler.java
    index 8e38b3f789..7eb684f9c6 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoLogHandler.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoLogHandler.java
    @@ -14,7 +14,7 @@
     public class DemoLogHandler implements WxMpMessageHandler {
       @Override
       public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context, WxMpService wxMpService,
    -      WxSessionManager sessionManager) {
    +                                  WxSessionManager sessionManager) {
         System.out.println(wxMessage.toString());
         return null;
       }
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoOAuth2Handler.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoOAuth2Handler.java
    index 8204645277..6460f851d0 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoOAuth2Handler.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoOAuth2Handler.java
    @@ -15,13 +15,13 @@
     public class DemoOAuth2Handler implements WxMpMessageHandler {
       @Override
       public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
    -      Map context, WxMpService wxMpService,
    -      WxSessionManager sessionManager) {
    +                                  Map context, WxMpService wxMpService,
    +                                  WxSessionManager sessionManager) {
         String href = "测试oauth2";
    +      wxMpService.getWxMpConfigStorage().getOauth2redirectUri(),
    +      WxConsts.OAUTH2_SCOPE_USER_INFO, null) + "\">测试oauth2";
         return WxMpXmlOutMessage.TEXT().content(href)
    -        .fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())
    -        .build();
    +      .fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())
    +      .build();
       }
     }
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoTextHandler.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoTextHandler.java
    index 5934eff249..c4540433d8 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoTextHandler.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoTextHandler.java
    @@ -15,10 +15,10 @@
     public class DemoTextHandler implements WxMpMessageHandler {
       @Override
       public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context,
    -      WxMpService wxMpService, WxSessionManager sessionManager) {
    +                                  WxMpService wxMpService, WxSessionManager sessionManager) {
         WxMpXmlOutTextMessage m
    -        = WxMpXmlOutMessage.TEXT().content("测试加密消息").fromUser(wxMessage.getToUser())
    -        .toUser(wxMessage.getFromUser()).build();
    +      = WxMpXmlOutMessage.TEXT().content("测试加密消息").fromUser(wxMessage.getToUser())
    +      .toUser(wxMessage.getFromUser()).build();
         return m;
       }
     
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoInMemoryConfigStorage.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoInMemoryConfigStorage.java
    index 44b80647f1..e42a192b1f 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoInMemoryConfigStorage.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoInMemoryConfigStorage.java
    @@ -13,17 +13,16 @@
     @XStreamAlias("xml")
     class WxMpDemoInMemoryConfigStorage extends WxMpInMemoryConfigStorage {
     
    -  @Override
    -  public String toString() {
    -    return "SimpleWxConfigProvider [appId=" + this.appId + ", secret=" + this.secret + ", accessToken=" + this.accessToken
    -        + ", expiresTime=" + this.expiresTime + ", token=" + this.token + ", aesKey=" + this.aesKey + "]";
    -  }
    -
    -
       public static WxMpDemoInMemoryConfigStorage fromXml(InputStream is) {
         XStream xstream = XStreamInitializer.getInstance();
         xstream.processAnnotations(WxMpDemoInMemoryConfigStorage.class);
         return (WxMpDemoInMemoryConfigStorage) xstream.fromXML(is);
       }
     
    +  @Override
    +  public String toString() {
    +    return "SimpleWxConfigProvider [appId=" + this.appId + ", secret=" + this.secret + ", accessToken=" + this.accessToken
    +      + ", expiresTime=" + this.expiresTime + ", token=" + this.token + ", aesKey=" + this.aesKey + "]";
    +  }
    +
     }
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServer.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServer.java
    index 98b8d0cce9..1c1893762f 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServer.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServer.java
    @@ -1,18 +1,17 @@
     package me.chanjar.weixin.mp.demo;
     
    -import java.io.IOException;
    -import java.io.InputStream;
    -
    -import org.eclipse.jetty.server.Server;
    -import org.eclipse.jetty.servlet.ServletHandler;
    -import org.eclipse.jetty.servlet.ServletHolder;
    -
     import me.chanjar.weixin.common.api.WxConsts;
     import me.chanjar.weixin.mp.api.WxMpConfigStorage;
     import me.chanjar.weixin.mp.api.WxMpMessageHandler;
     import me.chanjar.weixin.mp.api.WxMpMessageRouter;
     import me.chanjar.weixin.mp.api.WxMpService;
     import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
    +import org.eclipse.jetty.server.Server;
    +import org.eclipse.jetty.servlet.ServletHandler;
    +import org.eclipse.jetty.servlet.ServletHolder;
    +
    +import java.io.IOException;
    +import java.io.InputStream;
     
     public class WxMpDemoServer {
     
    @@ -29,12 +28,12 @@ public static void main(String[] args) throws Exception {
         server.setHandler(servletHandler);
     
         ServletHolder endpointServletHolder = new ServletHolder(
    -        new WxMpEndpointServlet(wxMpConfigStorage, wxMpService,
    -            wxMpMessageRouter));
    +      new WxMpEndpointServlet(wxMpConfigStorage, wxMpService,
    +        wxMpMessageRouter));
         servletHandler.addServletWithMapping(endpointServletHolder, "/*");
     
         ServletHolder oauthServletHolder = new ServletHolder(
    -        new WxMpOAuth2Servlet(wxMpService));
    +      new WxMpOAuth2Servlet(wxMpService));
         servletHandler.addServletWithMapping(oauthServletHolder, "/oauth2/*");
     
         server.start();
    @@ -43,9 +42,9 @@ public static void main(String[] args) throws Exception {
     
       private static void initWeixin() {
         try (InputStream is1 = ClassLoader
    -        .getSystemResourceAsStream("test-config.xml")) {
    +      .getSystemResourceAsStream("test-config.xml")) {
           WxMpDemoInMemoryConfigStorage config = WxMpDemoInMemoryConfigStorage
    -          .fromXml(is1);
    +        .fromXml(is1);
     
           wxMpConfigStorage = config;
           wxMpService = new WxMpServiceImpl();
    @@ -59,11 +58,11 @@ private static void initWeixin() {
     
           wxMpMessageRouter = new WxMpMessageRouter(wxMpService);
           wxMpMessageRouter.rule().handler(logHandler).next().rule()
    -          .msgType(WxConsts.XML_MSG_TEXT).matcher(guessNumberHandler)
    -          .handler(guessNumberHandler).end().rule().async(false).content("哈哈")
    -          .handler(textHandler).end().rule().async(false).content("图片")
    -          .handler(imageHandler).end().rule().async(false).content("oauth")
    -          .handler(oauth2handler).end();
    +        .msgType(WxConsts.XML_MSG_TEXT).matcher(guessNumberHandler)
    +        .handler(guessNumberHandler).end().rule().async(false).content("哈哈")
    +        .handler(textHandler).end().rule().async(false).content("图片")
    +        .handler(imageHandler).end().rule().async(false).content("oauth")
    +        .handler(oauth2handler).end();
         } catch (IOException e) {
           e.printStackTrace();
         }
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpEndpointServlet.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpEndpointServlet.java
    index 4a6fd85b14..3f32d9c94a 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpEndpointServlet.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpEndpointServlet.java
    @@ -23,7 +23,7 @@ public class WxMpEndpointServlet extends HttpServlet {
       protected WxMpMessageRouter wxMpMessageRouter;
     
       public WxMpEndpointServlet(WxMpConfigStorage wxMpConfigStorage, WxMpService wxMpService,
    -      WxMpMessageRouter wxMpMessageRouter) {
    +                             WxMpMessageRouter wxMpMessageRouter) {
         this.wxMpConfigStorage = wxMpConfigStorage;
         this.wxMpService = wxMpService;
         this.wxMpMessageRouter = wxMpMessageRouter;
    @@ -31,7 +31,7 @@ public WxMpEndpointServlet(WxMpConfigStorage wxMpConfigStorage, WxMpService wxMp
     
       @Override
       protected void service(HttpServletRequest request, HttpServletResponse response)
    -      throws IOException {
    +    throws IOException {
     
         response.setContentType("text/html;charset=utf-8");
         response.setStatus(HttpServletResponse.SC_OK);
    @@ -54,8 +54,8 @@ protected void service(HttpServletRequest request, HttpServletResponse response)
         }
     
         String encryptType = StringUtils.isBlank(request.getParameter("encrypt_type")) ?
    -        "raw" :
    -        request.getParameter("encrypt_type");
    +      "raw" :
    +      request.getParameter("encrypt_type");
     
         if ("raw".equals(encryptType)) {
           // 明文传输的消息
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpOAuth2Servlet.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpOAuth2Servlet.java
    index 8eeb9052ac..e739a93689 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpOAuth2Servlet.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpOAuth2Servlet.java
    @@ -1,16 +1,15 @@
     package me.chanjar.weixin.mp.demo;
     
    -import java.io.IOException;
    -
    -import javax.servlet.http.HttpServlet;
    -import javax.servlet.http.HttpServletRequest;
    -import javax.servlet.http.HttpServletResponse;
    -
     import me.chanjar.weixin.common.exception.WxErrorException;
     import me.chanjar.weixin.mp.api.WxMpService;
     import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
     import me.chanjar.weixin.mp.bean.result.WxMpUser;
     
    +import javax.servlet.http.HttpServlet;
    +import javax.servlet.http.HttpServletRequest;
    +import javax.servlet.http.HttpServletResponse;
    +import java.io.IOException;
    +
     public class WxMpOAuth2Servlet extends HttpServlet {
       private static final long serialVersionUID = 1L;
     
    @@ -22,7 +21,7 @@ public WxMpOAuth2Servlet(WxMpService wxMpService) {
     
       @Override
       protected void service(HttpServletRequest request, HttpServletResponse response)
    -      throws IOException {
    +    throws IOException {
     
         response.setContentType("text/html;charset=utf-8");
         response.setStatus(HttpServletResponse.SC_OK);
    
    From 6c9afe8a8aae3fac4bb4ca98ee79cbaff03c8fbf Mon Sep 17 00:00:00 2001
    From: Binary Wang 
    Date: Thu, 9 Feb 2017 22:53:23 +0800
    Subject: [PATCH 79/80] =?UTF-8?q?=E4=BF=AE=E5=A4=8DWxMenuRule=E4=B8=80?=
     =?UTF-8?q?=E4=B8=AA=E5=8F=98=E6=80=81=E5=B1=9E=E6=80=A7=E7=9A=84=E9=97=AE?=
     =?UTF-8?q?=E9=A2=98=20#136?=
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    
    ---
     .../common/util/json/WxMenuGsonAdapter.java      | 16 +++++++++-------
     .../weixin/mp/api/impl/WxMpMenuServiceImpl.java  |  3 +--
     2 files changed, 10 insertions(+), 9 deletions(-)
    
    diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java
    index eaaeec74a4..578aa41cea 100644
    --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java
    +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java
    @@ -70,13 +70,15 @@ protected JsonObject convertToJson(WxMenuRule menuRule) {
     
       private WxMenuRule convertToRule(JsonObject json) {
         WxMenuRule menuRule = new WxMenuRule();
    -    menuRule.setTagId(GsonHelper.getString(json,"tag_id"));
    -    menuRule.setSex(GsonHelper.getString(json,"sex"));
    -    menuRule.setCountry(GsonHelper.getString(json,"country"));
    -    menuRule.setProvince(GsonHelper.getString(json,"province"));
    -    menuRule.setCity(GsonHelper.getString(json,"city"));
    -    menuRule.setClientPlatformType(GsonHelper.getString(json,"client_platform_type"));
    -    menuRule.setLanguage(GsonHelper.getString(json,"language"));
    +    //变态的微信接口,这里居然反人类的使用和序列化时不一样的名字
    +    //menuRule.setTagId(GsonHelper.getString(json,"tag_id"));
    +    menuRule.setTagId(GsonHelper.getString(json, "group_id"));
    +    menuRule.setSex(GsonHelper.getString(json, "sex"));
    +    menuRule.setCountry(GsonHelper.getString(json, "country"));
    +    menuRule.setProvince(GsonHelper.getString(json, "province"));
    +    menuRule.setCity(GsonHelper.getString(json, "city"));
    +    menuRule.setClientPlatformType(GsonHelper.getString(json, "client_platform_type"));
    +    menuRule.setLanguage(GsonHelper.getString(json, "language"));
         return menuRule;
       }
     
    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 b28ac6a16f..d22f4c82e2 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
    @@ -16,8 +16,7 @@
      */
     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 static Logger log = LoggerFactory.getLogger(WxMpMenuServiceImpl.class);
     
       private WxMpService wxMpService;
     
    
    From a5682cdfd926e383b7edbb816debac73b6675c78 Mon Sep 17 00:00:00 2001
    From: Binary Wang 
    Date: Sun, 12 Feb 2017 13:44:55 +0800
    Subject: [PATCH 80/80] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E7=89=88=E6=9C=AC?=
     =?UTF-8?q?=E5=8F=B7=E4=B8=BA2.5.0=EF=BC=8C=E5=87=86=E5=A4=87=E5=8F=91?=
     =?UTF-8?q?=E5=B8=83=E6=96=B0=E7=9A=84=E6=AD=A3=E5=BC=8F=E7=89=88?=
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    
    ---
     pom.xml                    | 2 +-
     weixin-java-common/pom.xml | 2 +-
     weixin-java-cp/pom.xml     | 2 +-
     weixin-java-mp/pom.xml     | 2 +-
     weixin-java-osgi/pom.xml   | 2 +-
     5 files changed, 5 insertions(+), 5 deletions(-)
    
    diff --git a/pom.xml b/pom.xml
    index a0dfd704db..57ae6b92c8 100644
    --- a/pom.xml
    +++ b/pom.xml
    @@ -5,7 +5,7 @@
       4.0.0
       com.github.binarywang
       weixin-java-parent
    -  2.4.9.BETA
    +  2.5.0
       pom
       WeiXin Java Tools - Parent
       微信公众号、企业号上级POM
    diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml
    index a635fca97e..12611c1274 100644
    --- a/weixin-java-common/pom.xml
    +++ b/weixin-java-common/pom.xml
    @@ -6,7 +6,7 @@
       
         com.github.binarywang
         weixin-java-parent
    -    2.4.9.BETA
    +    2.5.0
       
     
       weixin-java-common
    diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml
    index 26175c9c01..6478ada2fc 100644
    --- a/weixin-java-cp/pom.xml
    +++ b/weixin-java-cp/pom.xml
    @@ -6,7 +6,7 @@
       
         com.github.binarywang
         weixin-java-parent
    -    2.4.9.BETA
    +    2.5.0
       
     
       weixin-java-cp
    diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml
    index d595950e42..7070d01858 100644
    --- a/weixin-java-mp/pom.xml
    +++ b/weixin-java-mp/pom.xml
    @@ -6,7 +6,7 @@
       
         com.github.binarywang
         weixin-java-parent
    -    2.4.9.BETA
    +    2.5.0
       
       weixin-java-mp
       WeiXin Java Tools - MP
    diff --git a/weixin-java-osgi/pom.xml b/weixin-java-osgi/pom.xml
    index 19cc0bb7ef..fbcfaba61a 100644
    --- a/weixin-java-osgi/pom.xml
    +++ b/weixin-java-osgi/pom.xml
    @@ -6,7 +6,7 @@
       
         com.github.binarywang
         weixin-java-parent
    -    2.4.9.BETA
    +    2.5.0
       
     
       weixin-java-osgi