Skip to content

Commit f7f7d12

Browse files
committed
发送红包接口增加证书
1 parent a464289 commit f7f7d12

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo)
7474
* 发送普通红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
7575
* 发送裂变红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4
7676
* </pre>
77+
* @param keyFile 证书文件对象
7778
*/
78-
WxRedpackResult sendRedpack(WxSendRedpackRequest request) throws WxErrorException;
79+
WxRedpackResult sendRedpack(WxSendRedpackRequest request, File keyFile) throws WxErrorException;
7980

8081
/**
8182
* <pre>

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,15 @@ public boolean checkJSSDKCallbackDataSignature(Map<String, String> kvm,
160160
}
161161

162162
@Override
163-
public WxRedpackResult sendRedpack(WxSendRedpackRequest request)
163+
public WxRedpackResult sendRedpack(WxSendRedpackRequest request, File keyFile)
164164
throws WxErrorException {
165165
XStream xstream = XStreamInitializer.getInstance();
166166
xstream.processAnnotations(WxSendRedpackRequest.class);
167167
xstream.processAnnotations(WxRedpackResult.class);
168168

169169
request.setWxAppid(this.wxMpService.getWxMpConfigStorage().getAppId());
170-
request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId());
170+
String mchId = this.wxMpService.getWxMpConfigStorage().getPartnerId();
171+
request.setMchId(mchId);
171172
request.setNonceStr(System.currentTimeMillis() + "");
172173

173174
String sign = this.createSign(this.xmlBean2Map(request),
@@ -180,7 +181,7 @@ public WxRedpackResult sendRedpack(WxSendRedpackRequest request)
180181
url = PAY_BASE_URL + "/mmpaymkttransfers/sendgroupredpack";
181182
}
182183

183-
String responseContent = this.wxMpService.post(url, xstream.toXML(request));
184+
String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request), keyFile, mchId);
184185
WxRedpackResult redpackResult = (WxRedpackResult) xstream
185186
.fromXML(responseContent);
186187
if ("FAIL".equals(redpackResult.getResultCode())) {

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public void testSendRedpack() throws Exception {
6262
request.setMchBillno("aaaa");
6363
request
6464
.setReOpenid(((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid());
65-
WxRedpackResult redpackResult = this.wxService.getPayService().sendRedpack(request);
65+
File keyFile = new File("E:\\dlt.p12");
66+
WxRedpackResult redpackResult = this.wxService.getPayService().sendRedpack(request, keyFile);
6667
System.err.println(redpackResult);
6768
}
6869

0 commit comments

Comments
 (0)