🐛 #1338 微信支付修复发送小程序红包接口的参数问题

This commit is contained in:
Binary Wang
2019-12-26 14:15:28 +08:00
parent 3e3d4e8345
commit fa1f085e1d
7 changed files with 296 additions and 151 deletions

View File

@@ -0,0 +1,76 @@
package com.github.binarywang.wxpay.service;
import com.github.binarywang.wxpay.bean.request.WxPayRedpackQueryRequest;
import com.github.binarywang.wxpay.bean.request.WxPaySendMiniProgramRedpackRequest;
import com.github.binarywang.wxpay.bean.request.WxPaySendRedpackRequest;
import com.github.binarywang.wxpay.bean.result.WxPayRedpackQueryResult;
import com.github.binarywang.wxpay.bean.result.WxPaySendMiniProgramRedpackResult;
import com.github.binarywang.wxpay.bean.result.WxPaySendRedpackResult;
import com.github.binarywang.wxpay.exception.WxPayException;
/**
* 红包相关接口.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2019-12-26
*/
public interface RedpackService {
/**
* <pre>
* 发送小程序红包.
* 文档详见: https://pay.weixin.qq.com/wiki/doc/api/tools/miniprogram_hb.php?chapter=13_9&index=2
* 接口地址https://api.mch.weixin.qq.com/mmpaymkttransfers/sendminiprogramhb
* </pre>
*
* @param request 请求对象
* @return the result
* @throws WxPayException the exception
*/
WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request) throws WxPayException;
/**
* 发送微信红包给个人用户.
* <pre>
* 文档详见:
* 发送普通红包 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
* </pre>
*
* @param request 请求对象
* @return the wx pay send redpack result
* @throws WxPayException the wx pay exception
*/
WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException;
/**
* <pre>
* 查询红包记录.
* 用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。
* 请求Urlhttps://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo
* 是否需要证书:是(证书及使用说明详见商户证书)
* 请求方式POST
* </pre>
*
* @param mchBillNo 商户发放红包的商户订单号比如10000098201411111234567890
* @return the wx pay redpack query result
* @throws WxPayException the wx pay exception
*/
WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException;
/**
* <pre>
* 查询红包记录.
* 用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。
* 请求Urlhttps://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo
* 是否需要证书:是(证书及使用说明详见商户证书)
* 请求方式POST
* </pre>
*
* @param request 红包查询请求
* @return the wx pay redpack query result
* @throws WxPayException the wx pay exception
*/
WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException;
}

View File

@@ -60,6 +60,13 @@ public interface WxPayService {
*/
EntPayService getEntPayService();
/**
* 获取红包接口服务类.
*
* @return .
*/
RedpackService getRedpackService();
/**
* 获取分账服务类.
*
@@ -277,62 +284,27 @@ public interface WxPayService {
WxScanPayNotifyResult parseScanPayNotifyResult(String xmlData) throws WxPayException;
/**
* <pre>
* 发送小程序红包.
* 文档详见: https://pay.weixin.qq.com/wiki/doc/api/tools/miniprogram_hb.php?chapter=13_9&index=2
* 接口地址https://api.mch.weixin.qq.com/mmpaymkttransfers/sendminiprogramhb
* </pre>
*
* @param request 请求对象
* @return the result
* @throws WxPayException the exception
* @deprecated 建议使用 {@link RedpackService#sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest)}
*/
@Deprecated
WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request) throws WxPayException;
/**
* 发送微信红包给个人用户.
* <pre>
* 文档详见:
* 发送普通红包 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
* </pre>
*
* @param request 请求对象
* @return the wx pay send redpack result
* @throws WxPayException the wx pay exception
* @deprecated 建议使用 {@link RedpackService#sendRedpack(WxPaySendRedpackRequest)}
*/
@Deprecated
WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException;
/**
* <pre>
* 查询红包记录.
* 用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。
* 请求Urlhttps://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo
* 是否需要证书:是(证书及使用说明详见商户证书)
* 请求方式POST
* </pre>
*
* @param mchBillNo 商户发放红包的商户订单号比如10000098201411111234567890
* @return the wx pay redpack query result
* @throws WxPayException the wx pay exception
* @deprecated 建议使用 {@link RedpackService#queryRedpack(String)}
*/
@Deprecated
WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException;
/**
* <pre>
* 查询红包记录.
* 用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。
* 请求Urlhttps://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo
* 是否需要证书:是(证书及使用说明详见商户证书)
* 请求方式POST
* </pre>
*
* @param request 红包查询请求
* @return the wx pay redpack query result
* @throws WxPayException the wx pay exception
* @deprecated 建议使用 {@link RedpackService#queryRedpack(WxPayRedpackQueryRequest)}
*/
@Deprecated
WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException;
/**

View File

@@ -13,12 +13,12 @@ import com.github.binarywang.wxpay.bean.order.WxPayNativeOrderResult;
import com.github.binarywang.wxpay.bean.request.*;
import com.github.binarywang.wxpay.bean.result.*;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.constant.WxPayConstants.BillType;
import com.github.binarywang.wxpay.constant.WxPayConstants.SignType;
import com.github.binarywang.wxpay.constant.WxPayConstants.TradeType;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.EntPayService;
import com.github.binarywang.wxpay.service.ProfitSharingService;
import com.github.binarywang.wxpay.service.RedpackService;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.util.SignUtils;
import com.google.common.base.Joiner;
@@ -61,6 +61,8 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
private EntPayService entPayService = new EntPayServiceImpl(this);
private ProfitSharingService profitSharingService = new ProfitSharingServiceImpl(this);
private RedpackService redpackService = new RedpackServiceImpl(this);
/**
* The Config.
*/
@@ -76,6 +78,11 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
return profitSharingService;
}
@Override
public RedpackService getRedpackService() {
return this.redpackService;
}
@Override
public void setEntPayService(EntPayService entPayService) {
this.entPayService = entPayService;
@@ -182,51 +189,25 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
}
@Override
public WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request)
throws WxPayException {
request.checkAndSign(this.getConfig());
String url = this.getPayBaseUrl() + "/mmpaymkttransfers/sendminiprogramhb";
String responseContent = this.post(url, request.toXML(), true);
@Override
public WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request)
throws WxPayException {
return this.redpackService.sendMiniProgramRedpack(request);
}
WxPaySendMiniProgramRedpackResult result = BaseWxPayResult.fromXML(responseContent, WxPaySendMiniProgramRedpackResult.class);
result.checkResult(this, request.getSignType(), true);
return result;
}
@Override
@Override
public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException {
request.checkAndSign(this.getConfig());
String url = this.getPayBaseUrl() + "/mmpaymkttransfers/sendredpack";
if (request.getAmtType() != null) {
//裂变红包
url = this.getPayBaseUrl() + "/mmpaymkttransfers/sendgroupredpack";
}
String responseContent = this.post(url, request.toXML(), true);
final WxPaySendRedpackResult result = BaseWxPayResult.fromXML(responseContent, WxPaySendRedpackResult.class);
result.checkResult(this, request.getSignType(), true);
return result;
return this.redpackService.sendRedpack(request);
}
@Override
public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException {
WxPayRedpackQueryRequest request = new WxPayRedpackQueryRequest();
request.setMchBillNo(mchBillNo);
return this.queryRedpack(request);
return this.redpackService.queryRedpack(mchBillNo);
}
@Override
public WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException {
request.setBillType(BillType.MCHT);
request.checkAndSign(this.getConfig());
String url = this.getPayBaseUrl() + "/mmpaymkttransfers/gethbinfo";
String responseContent = this.post(url, request.toXML(), true);
WxPayRedpackQueryResult result = BaseWxPayResult.fromXML(responseContent, WxPayRedpackQueryResult.class);
result.checkResult(this, request.getSignType(), true);
return result;
return this.redpackService.queryRedpack(request);
}
@Override

View File

@@ -0,0 +1,72 @@
package com.github.binarywang.wxpay.service.impl;
import com.github.binarywang.wxpay.bean.request.WxPayRedpackQueryRequest;
import com.github.binarywang.wxpay.bean.request.WxPaySendMiniProgramRedpackRequest;
import com.github.binarywang.wxpay.bean.request.WxPaySendRedpackRequest;
import com.github.binarywang.wxpay.bean.result.BaseWxPayResult;
import com.github.binarywang.wxpay.bean.result.WxPayRedpackQueryResult;
import com.github.binarywang.wxpay.bean.result.WxPaySendMiniProgramRedpackResult;
import com.github.binarywang.wxpay.bean.result.WxPaySendRedpackResult;
import com.github.binarywang.wxpay.constant.WxPayConstants;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.RedpackService;
import com.github.binarywang.wxpay.service.WxPayService;
import lombok.RequiredArgsConstructor;
/**
* 老板加点注释吧.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2019-12-26
*/
@RequiredArgsConstructor
public class RedpackServiceImpl implements RedpackService {
private final WxPayService payService;
@Override
public WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request)
throws WxPayException {
request.checkAndSign(this.payService.getConfig());
String url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/sendminiprogramhb";
String responseContent = this.payService.post(url, request.toXML(), true);
WxPaySendMiniProgramRedpackResult result = BaseWxPayResult.fromXML(responseContent, WxPaySendMiniProgramRedpackResult.class);
result.checkResult(this.payService, request.getSignType(), true);
return result;
}
@Override
public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException {
request.checkAndSign(this.payService.getConfig());
String url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/sendredpack";
if (request.getAmtType() != null) {
//裂变红包
url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/sendgroupredpack";
}
String responseContent = this.payService.post(url, request.toXML(), true);
final WxPaySendRedpackResult result = BaseWxPayResult.fromXML(responseContent, WxPaySendRedpackResult.class);
result.checkResult(this.payService, request.getSignType(), true);
return result;
}
@Override
public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException {
WxPayRedpackQueryRequest request = new WxPayRedpackQueryRequest();
request.setMchBillNo(mchBillNo);
return this.queryRedpack(request);
}
@Override
public WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException {
request.setBillType(WxPayConstants.BillType.MCHT);
request.checkAndSign(this.payService.getConfig());
String url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/gethbinfo";
String responseContent = this.payService.post(url, request.toXML(), true);
WxPayRedpackQueryResult result = BaseWxPayResult.fromXML(responseContent, WxPayRedpackQueryResult.class);
result.checkResult(this.payService, request.getSignType(), true);
return result;
}
}