Skip to content

Commit fa1f085

Browse files
committed
🐛 #1338 微信支付修复发送小程序红包接口的参数问题
1 parent 3e3d4e8 commit fa1f085

File tree

7 files changed

+296
-151
lines changed

7 files changed

+296
-151
lines changed

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPaySendMiniProgramRedpackRequest.java

+20
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,28 @@ protected String[] getIgnoredParamsForSign() {
105105
@XStreamAlias("scene_id")
106106
private String sceneId;
107107

108+
/**
109+
* wxappid.
110+
* 微信分配的公众账号ID(企业号corpid即为此appId)。
111+
* 接口传入的所有appid应该为公众号的appid(在mp.weixin.qq.com申请的),
112+
* 不能为APP的appid(在open.weixin.qq.com申请的)
113+
*/
114+
@XStreamAlias("wxappid")
115+
private String wxAppid;
116+
108117
@Override
109118
protected void checkConstraints() {
110119

111120
}
121+
122+
@Override
123+
public String getAppid() {
124+
return this.wxAppid;
125+
}
126+
127+
@Override
128+
public void setAppid(String appid) {
129+
this.wxAppid = appid;
130+
}
131+
112132
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.github.binarywang.wxpay.service;
2+
3+
import com.github.binarywang.wxpay.bean.request.WxPayRedpackQueryRequest;
4+
import com.github.binarywang.wxpay.bean.request.WxPaySendMiniProgramRedpackRequest;
5+
import com.github.binarywang.wxpay.bean.request.WxPaySendRedpackRequest;
6+
import com.github.binarywang.wxpay.bean.result.WxPayRedpackQueryResult;
7+
import com.github.binarywang.wxpay.bean.result.WxPaySendMiniProgramRedpackResult;
8+
import com.github.binarywang.wxpay.bean.result.WxPaySendRedpackResult;
9+
import com.github.binarywang.wxpay.exception.WxPayException;
10+
11+
/**
12+
* 红包相关接口.
13+
*
14+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
15+
* @date 2019-12-26
16+
*/
17+
public interface RedpackService {
18+
/**
19+
* <pre>
20+
* 发送小程序红包.
21+
* 文档详见: https://pay.weixin.qq.com/wiki/doc/api/tools/miniprogram_hb.php?chapter=13_9&index=2
22+
* 接口地址:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendminiprogramhb
23+
* </pre>
24+
*
25+
* @param request 请求对象
26+
* @return the result
27+
* @throws WxPayException the exception
28+
*/
29+
WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request) throws WxPayException;
30+
31+
/**
32+
* 发送微信红包给个人用户.
33+
* <pre>
34+
* 文档详见:
35+
* 发送普通红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
36+
* 接口地址:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack
37+
* 发送裂变红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4
38+
* 接口地址:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack
39+
* </pre>
40+
*
41+
* @param request 请求对象
42+
* @return the wx pay send redpack result
43+
* @throws WxPayException the wx pay exception
44+
*/
45+
WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException;
46+
47+
/**
48+
* <pre>
49+
* 查询红包记录.
50+
* 用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。
51+
* 请求Url:https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo
52+
* 是否需要证书:是(证书及使用说明详见商户证书)
53+
* 请求方式:POST
54+
* </pre>
55+
*
56+
* @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890
57+
* @return the wx pay redpack query result
58+
* @throws WxPayException the wx pay exception
59+
*/
60+
WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException;
61+
62+
/**
63+
* <pre>
64+
* 查询红包记录.
65+
* 用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。
66+
* 请求Url:https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo
67+
* 是否需要证书:是(证书及使用说明详见商户证书)
68+
* 请求方式:POST
69+
* </pre>
70+
*
71+
* @param request 红包查询请求
72+
* @return the wx pay redpack query result
73+
* @throws WxPayException the wx pay exception
74+
*/
75+
WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException;
76+
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java

+15-43
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ public interface WxPayService {
6060
*/
6161
EntPayService getEntPayService();
6262

63+
/**
64+
* 获取红包接口服务类.
65+
*
66+
* @return .
67+
*/
68+
RedpackService getRedpackService();
69+
6370
/**
6471
* 获取分账服务类.
6572
*
@@ -277,62 +284,27 @@ WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, Stri
277284
WxScanPayNotifyResult parseScanPayNotifyResult(String xmlData) throws WxPayException;
278285

279286
/**
280-
* <pre>
281-
* 发送小程序红包.
282-
* 文档详见: https://pay.weixin.qq.com/wiki/doc/api/tools/miniprogram_hb.php?chapter=13_9&index=2
283-
* 接口地址:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendminiprogramhb
284-
* </pre>
285-
*
286-
* @param request 请求对象
287-
* @return the result
288-
* @throws WxPayException the exception
287+
* @deprecated 建议使用 {@link RedpackService#sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest)}
289288
*/
289+
@Deprecated
290290
WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request) throws WxPayException;
291291

292292
/**
293-
* 发送微信红包给个人用户.
294-
* <pre>
295-
* 文档详见:
296-
* 发送普通红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
297-
* 接口地址:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack
298-
* 发送裂变红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4
299-
* 接口地址:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack
300-
* </pre>
301-
*
302-
* @param request 请求对象
303-
* @return the wx pay send redpack result
304-
* @throws WxPayException the wx pay exception
293+
* @deprecated 建议使用 {@link RedpackService#sendRedpack(WxPaySendRedpackRequest)}
305294
*/
295+
@Deprecated
306296
WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException;
307297

308298
/**
309-
* <pre>
310-
* 查询红包记录.
311-
* 用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。
312-
* 请求Url:https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo
313-
* 是否需要证书:是(证书及使用说明详见商户证书)
314-
* 请求方式:POST
315-
* </pre>
316-
*
317-
* @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890
318-
* @return the wx pay redpack query result
319-
* @throws WxPayException the wx pay exception
299+
* @deprecated 建议使用 {@link RedpackService#queryRedpack(String)}
320300
*/
301+
@Deprecated
321302
WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException;
322303

323304
/**
324-
* <pre>
325-
* 查询红包记录.
326-
* 用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。
327-
* 请求Url:https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo
328-
* 是否需要证书:是(证书及使用说明详见商户证书)
329-
* 请求方式:POST
330-
* </pre>
331-
*
332-
* @param request 红包查询请求
333-
* @return the wx pay redpack query result
334-
* @throws WxPayException the wx pay exception
305+
* @deprecated 建议使用 {@link RedpackService#queryRedpack(WxPayRedpackQueryRequest)}
335306
*/
307+
@Deprecated
336308
WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException;
337309

338310
/**

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java

+17-36
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
import com.github.binarywang.wxpay.bean.request.*;
1414
import com.github.binarywang.wxpay.bean.result.*;
1515
import com.github.binarywang.wxpay.config.WxPayConfig;
16-
import com.github.binarywang.wxpay.constant.WxPayConstants.BillType;
1716
import com.github.binarywang.wxpay.constant.WxPayConstants.SignType;
1817
import com.github.binarywang.wxpay.constant.WxPayConstants.TradeType;
1918
import com.github.binarywang.wxpay.exception.WxPayException;
2019
import com.github.binarywang.wxpay.service.EntPayService;
2120
import com.github.binarywang.wxpay.service.ProfitSharingService;
21+
import com.github.binarywang.wxpay.service.RedpackService;
2222
import com.github.binarywang.wxpay.service.WxPayService;
2323
import com.github.binarywang.wxpay.util.SignUtils;
2424
import com.google.common.base.Joiner;
@@ -61,6 +61,8 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
6161

6262
private EntPayService entPayService = new EntPayServiceImpl(this);
6363
private ProfitSharingService profitSharingService = new ProfitSharingServiceImpl(this);
64+
private RedpackService redpackService = new RedpackServiceImpl(this);
65+
6466
/**
6567
* The Config.
6668
*/
@@ -76,6 +78,11 @@ public ProfitSharingService getProfitSharingService() {
7678
return profitSharingService;
7779
}
7880

81+
@Override
82+
public RedpackService getRedpackService() {
83+
return this.redpackService;
84+
}
85+
7986
@Override
8087
public void setEntPayService(EntPayService entPayService) {
8188
this.entPayService = entPayService;
@@ -182,51 +189,25 @@ public WxScanPayNotifyResult parseScanPayNotifyResult(String xmlData) throws WxP
182189

183190
}
184191

185-
@Override
186-
public WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request)
187-
throws WxPayException {
188-
request.checkAndSign(this.getConfig());
189-
String url = this.getPayBaseUrl() + "/mmpaymkttransfers/sendminiprogramhb";
190-
String responseContent = this.post(url, request.toXML(), true);
191-
192-
WxPaySendMiniProgramRedpackResult result = BaseWxPayResult.fromXML(responseContent, WxPaySendMiniProgramRedpackResult.class);
193-
result.checkResult(this, request.getSignType(), true);
194-
return result;
195-
}
192+
@Override
193+
public WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request)
194+
throws WxPayException {
195+
return this.redpackService.sendMiniProgramRedpack(request);
196+
}
196197

197-
@Override
198+
@Override
198199
public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException {
199-
request.checkAndSign(this.getConfig());
200-
201-
String url = this.getPayBaseUrl() + "/mmpaymkttransfers/sendredpack";
202-
if (request.getAmtType() != null) {
203-
//裂变红包
204-
url = this.getPayBaseUrl() + "/mmpaymkttransfers/sendgroupredpack";
205-
}
206-
207-
String responseContent = this.post(url, request.toXML(), true);
208-
final WxPaySendRedpackResult result = BaseWxPayResult.fromXML(responseContent, WxPaySendRedpackResult.class);
209-
result.checkResult(this, request.getSignType(), true);
210-
return result;
200+
return this.redpackService.sendRedpack(request);
211201
}
212202

213203
@Override
214204
public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException {
215-
WxPayRedpackQueryRequest request = new WxPayRedpackQueryRequest();
216-
request.setMchBillNo(mchBillNo);
217-
return this.queryRedpack(request);
205+
return this.redpackService.queryRedpack(mchBillNo);
218206
}
219207

220208
@Override
221209
public WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException {
222-
request.setBillType(BillType.MCHT);
223-
request.checkAndSign(this.getConfig());
224-
225-
String url = this.getPayBaseUrl() + "/mmpaymkttransfers/gethbinfo";
226-
String responseContent = this.post(url, request.toXML(), true);
227-
WxPayRedpackQueryResult result = BaseWxPayResult.fromXML(responseContent, WxPayRedpackQueryResult.class);
228-
result.checkResult(this, request.getSignType(), true);
229-
return result;
210+
return this.redpackService.queryRedpack(request);
230211
}
231212

232213
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.github.binarywang.wxpay.service.impl;
2+
3+
import com.github.binarywang.wxpay.bean.request.WxPayRedpackQueryRequest;
4+
import com.github.binarywang.wxpay.bean.request.WxPaySendMiniProgramRedpackRequest;
5+
import com.github.binarywang.wxpay.bean.request.WxPaySendRedpackRequest;
6+
import com.github.binarywang.wxpay.bean.result.BaseWxPayResult;
7+
import com.github.binarywang.wxpay.bean.result.WxPayRedpackQueryResult;
8+
import com.github.binarywang.wxpay.bean.result.WxPaySendMiniProgramRedpackResult;
9+
import com.github.binarywang.wxpay.bean.result.WxPaySendRedpackResult;
10+
import com.github.binarywang.wxpay.constant.WxPayConstants;
11+
import com.github.binarywang.wxpay.exception.WxPayException;
12+
import com.github.binarywang.wxpay.service.RedpackService;
13+
import com.github.binarywang.wxpay.service.WxPayService;
14+
import lombok.RequiredArgsConstructor;
15+
16+
/**
17+
* 老板加点注释吧.
18+
*
19+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
20+
* @date 2019-12-26
21+
*/
22+
@RequiredArgsConstructor
23+
public class RedpackServiceImpl implements RedpackService {
24+
private final WxPayService payService;
25+
26+
@Override
27+
public WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request)
28+
throws WxPayException {
29+
request.checkAndSign(this.payService.getConfig());
30+
String url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/sendminiprogramhb";
31+
String responseContent = this.payService.post(url, request.toXML(), true);
32+
33+
WxPaySendMiniProgramRedpackResult result = BaseWxPayResult.fromXML(responseContent, WxPaySendMiniProgramRedpackResult.class);
34+
result.checkResult(this.payService, request.getSignType(), true);
35+
return result;
36+
}
37+
38+
@Override
39+
public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException {
40+
request.checkAndSign(this.payService.getConfig());
41+
42+
String url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/sendredpack";
43+
if (request.getAmtType() != null) {
44+
//裂变红包
45+
url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/sendgroupredpack";
46+
}
47+
48+
String responseContent = this.payService.post(url, request.toXML(), true);
49+
final WxPaySendRedpackResult result = BaseWxPayResult.fromXML(responseContent, WxPaySendRedpackResult.class);
50+
result.checkResult(this.payService, request.getSignType(), true);
51+
return result;
52+
}
53+
54+
@Override
55+
public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException {
56+
WxPayRedpackQueryRequest request = new WxPayRedpackQueryRequest();
57+
request.setMchBillNo(mchBillNo);
58+
return this.queryRedpack(request);
59+
}
60+
61+
@Override
62+
public WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException {
63+
request.setBillType(WxPayConstants.BillType.MCHT);
64+
request.checkAndSign(this.payService.getConfig());
65+
66+
String url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/gethbinfo";
67+
String responseContent = this.payService.post(url, request.toXML(), true);
68+
WxPayRedpackQueryResult result = BaseWxPayResult.fromXML(responseContent, WxPayRedpackQueryResult.class);
69+
result.checkResult(this.payService, request.getSignType(), true);
70+
return result;
71+
}
72+
}

0 commit comments

Comments
 (0)