From f7f7d12347c0a753148d316a7001959905832883 Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Sun, 9 Oct 2016 19:00:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E9=80=81=E7=BA=A2=E5=8C=85=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=A2=9E=E5=8A=A0=E8=AF=81=E4=B9=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/me/chanjar/weixin/mp/api/WxMpPayService.java | 3 ++- .../me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java | 7 ++++--- .../chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java | 3 ++- 3 files changed, 8 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 45973443..bdba22ad 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 @@ -74,8 +74,9 @@ public interface WxMpPayService { * 发送普通红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3 * 发送裂变红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4 * + * @param keyFile 证书文件对象 */ - WxRedpackResult sendRedpack(WxSendRedpackRequest request) throws WxErrorException; + WxRedpackResult sendRedpack(WxSendRedpackRequest request, 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 a8d5dc3f..8e3e015e 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,14 +160,15 @@ public class WxMpPayServiceImpl implements WxMpPayService {
   }
 
   @Override
-  public WxRedpackResult sendRedpack(WxSendRedpackRequest request)
+  public WxRedpackResult sendRedpack(WxSendRedpackRequest request, File keyFile)
       throws WxErrorException {
     XStream xstream = XStreamInitializer.getInstance();
     xstream.processAnnotations(WxSendRedpackRequest.class);
     xstream.processAnnotations(WxRedpackResult.class);
 
     request.setWxAppid(this.wxMpService.getWxMpConfigStorage().getAppId());
-    request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId());
+    String mchId = this.wxMpService.getWxMpConfigStorage().getPartnerId();
+    request.setMchId(mchId);
     request.setNonceStr(System.currentTimeMillis() + "");
 
     String sign = this.createSign(this.xmlBean2Map(request),
@@ -180,7 +181,7 @@ public class WxMpPayServiceImpl implements WxMpPayService {
       url = PAY_BASE_URL + "/mmpaymkttransfers/sendgroupredpack";
     }
 
-    String responseContent = this.wxMpService.post(url, xstream.toXML(request));
+    String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request), keyFile, mchId);
     WxRedpackResult redpackResult = (WxRedpackResult) xstream
         .fromXML(responseContent);
     if ("FAIL".equals(redpackResult.getResultCode())) {
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 7f524fd1..6d0b8a5c 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
@@ -62,7 +62,8 @@ public class WxMpPayServiceImplTest {
     request.setMchBillno("aaaa");
     request
         .setReOpenid(((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid());
-    WxRedpackResult redpackResult = this.wxService.getPayService().sendRedpack(request);
+    File keyFile = new File("E:\\dlt.p12");
+    WxRedpackResult redpackResult = this.wxService.getPayService().sendRedpack(request, keyFile);
     System.err.println(redpackResult);
   }