🐛 #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

@ -105,8 +105,28 @@ public class WxPaySendMiniProgramRedpackRequest extends BaseWxPayRequest {
@XStreamAlias("scene_id") @XStreamAlias("scene_id")
private String sceneId; private String sceneId;
/**
* wxappid.
* 微信分配的公众账号ID企业号corpid即为此appId
* 接口传入的所有appid应该为公众号的appid在mp.weixin.qq.com申请的
* 不能为APP的appid在open.weixin.qq.com申请的
*/
@XStreamAlias("wxappid")
private String wxAppid;
@Override @Override
protected void checkConstraints() { protected void checkConstraints() {
} }
@Override
public String getAppid() {
return this.wxAppid;
}
@Override
public void setAppid(String appid) {
this.wxAppid = appid;
}
} }

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(); EntPayService getEntPayService();
/**
* 获取红包接口服务类.
*
* @return .
*/
RedpackService getRedpackService();
/** /**
* 获取分账服务类. * 获取分账服务类.
* *
@ -277,62 +284,27 @@ public interface WxPayService {
WxScanPayNotifyResult parseScanPayNotifyResult(String xmlData) throws WxPayException; WxScanPayNotifyResult parseScanPayNotifyResult(String xmlData) throws WxPayException;
/** /**
* <pre> * @deprecated 建议使用 {@link RedpackService#sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest)}
* 发送小程序红包.
* 文档详见: 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
WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request) throws WxPayException; WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request) throws WxPayException;
/** /**
* 发送微信红包给个人用户. * @deprecated 建议使用 {@link RedpackService#sendRedpack(WxPaySendRedpackRequest)}
* <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
WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException; WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException;
/** /**
* <pre> * @deprecated 建议使用 {@link RedpackService#queryRedpack(String)}
* 查询红包记录.
* 用于商户对已发放的红包进行查询红包的具体信息可支持普通红包和裂变包
* 请求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
WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException; WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException;
/** /**
* <pre> * @deprecated 建议使用 {@link RedpackService#queryRedpack(WxPayRedpackQueryRequest)}
* 查询红包记录.
* 用于商户对已发放的红包进行查询红包的具体信息可支持普通红包和裂变包
* 请求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
WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException; 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.request.*;
import com.github.binarywang.wxpay.bean.result.*; import com.github.binarywang.wxpay.bean.result.*;
import com.github.binarywang.wxpay.config.WxPayConfig; 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.SignType;
import com.github.binarywang.wxpay.constant.WxPayConstants.TradeType; import com.github.binarywang.wxpay.constant.WxPayConstants.TradeType;
import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.EntPayService; import com.github.binarywang.wxpay.service.EntPayService;
import com.github.binarywang.wxpay.service.ProfitSharingService; 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.service.WxPayService;
import com.github.binarywang.wxpay.util.SignUtils; import com.github.binarywang.wxpay.util.SignUtils;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
@ -61,6 +61,8 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
private EntPayService entPayService = new EntPayServiceImpl(this); private EntPayService entPayService = new EntPayServiceImpl(this);
private ProfitSharingService profitSharingService = new ProfitSharingServiceImpl(this); private ProfitSharingService profitSharingService = new ProfitSharingServiceImpl(this);
private RedpackService redpackService = new RedpackServiceImpl(this);
/** /**
* The Config. * The Config.
*/ */
@ -76,6 +78,11 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
return profitSharingService; return profitSharingService;
} }
@Override
public RedpackService getRedpackService() {
return this.redpackService;
}
@Override @Override
public void setEntPayService(EntPayService entPayService) { public void setEntPayService(EntPayService entPayService) {
this.entPayService = entPayService; this.entPayService = entPayService;
@ -185,48 +192,22 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
@Override @Override
public WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request) public WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request)
throws WxPayException { throws WxPayException {
request.checkAndSign(this.getConfig()); return this.redpackService.sendMiniProgramRedpack(request);
String url = this.getPayBaseUrl() + "/mmpaymkttransfers/sendminiprogramhb";
String responseContent = this.post(url, request.toXML(), true);
WxPaySendMiniProgramRedpackResult result = BaseWxPayResult.fromXML(responseContent, WxPaySendMiniProgramRedpackResult.class);
result.checkResult(this, request.getSignType(), true);
return result;
} }
@Override @Override
public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException { public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException {
request.checkAndSign(this.getConfig()); return this.redpackService.sendRedpack(request);
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;
} }
@Override @Override
public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException { public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException {
WxPayRedpackQueryRequest request = new WxPayRedpackQueryRequest(); return this.redpackService.queryRedpack(mchBillNo);
request.setMchBillNo(mchBillNo);
return this.queryRedpack(request);
} }
@Override @Override
public WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException { public WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException {
request.setBillType(BillType.MCHT); return this.redpackService.queryRedpack(request);
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;
} }
@Override @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;
}
}

View File

@ -18,6 +18,7 @@ import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.testbase.ApiTestModule; import com.github.binarywang.wxpay.testbase.ApiTestModule;
import com.github.binarywang.wxpay.testbase.XmlWxPayConfig; import com.github.binarywang.wxpay.testbase.XmlWxPayConfig;
import com.google.inject.Inject; import com.google.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
@ -39,10 +40,10 @@ import static org.testng.Assert.*;
* *
* @author <a href="https://github.com/binarywang">Binary Wang</a> * @author <a href="https://github.com/binarywang">Binary Wang</a>
*/ */
@Slf4j
@Test @Test
@Guice(modules = ApiTestModule.class) @Guice(modules = ApiTestModule.class)
public class BaseWxPayServiceImplTest { public class BaseWxPayServiceImplTest {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Inject @Inject
private WxPayService payService; private WxPayService payService;
@ -65,8 +66,8 @@ public class BaseWxPayServiceImplTest {
.build(); .build();
request.setSignType(SignType.HMAC_SHA256); request.setSignType(SignType.HMAC_SHA256);
WxPayUnifiedOrderResult result = this.payService.unifiedOrder(request); WxPayUnifiedOrderResult result = this.payService.unifiedOrder(request);
this.logger.info(result.toString()); log.info(result.toString());
this.logger.warn(this.payService.getWxApiData().toString()); log.warn(this.payService.getWxApiData().toString());
} }
/** /**
@ -96,8 +97,8 @@ public class BaseWxPayServiceImplTest {
.openid(((XmlWxPayConfig) this.payService.getConfig()).getOpenid()) .openid(((XmlWxPayConfig) this.payService.getConfig()).getOpenid())
.outTradeNo("1111112") .outTradeNo("1111112")
.build()); .build());
this.logger.info(result.toString()); log.info(result.toString());
this.logger.warn(this.payService.getWxApiData().toString()); log.warn(this.payService.getWxApiData().toString());
} }
/** /**
@ -116,8 +117,8 @@ public class BaseWxPayServiceImplTest {
.tradeType(TradeType.APP) .tradeType(TradeType.APP)
.outTradeNo("1111112") .outTradeNo("1111112")
.build()); .build());
this.logger.info(result.toString()); log.info(result.toString());
this.logger.warn(this.payService.getWxApiData().toString()); log.warn(this.payService.getWxApiData().toString());
} }
/** /**
@ -137,8 +138,8 @@ public class BaseWxPayServiceImplTest {
.tradeType(TradeType.NATIVE) .tradeType(TradeType.NATIVE)
.outTradeNo("111111290") .outTradeNo("111111290")
.build()); .build());
this.logger.info(result.toString()); log.info(result.toString());
this.logger.warn(this.payService.getWxApiData().toString()); log.warn(this.payService.getWxApiData().toString());
} }
/** /**
@ -158,8 +159,8 @@ public class BaseWxPayServiceImplTest {
*/ */
@Test @Test
public void testQueryOrder() throws WxPayException { public void testQueryOrder() throws WxPayException {
this.logger.info(this.payService.queryOrder("11212121", null).toString()); log.info(this.payService.queryOrder("11212121", null).toString());
this.logger.info(this.payService.queryOrder(null, "11111").toString()); log.info(this.payService.queryOrder(null, "11111").toString());
} }
/** /**
@ -169,7 +170,7 @@ public class BaseWxPayServiceImplTest {
*/ */
@Test @Test
public void testCloseOrder() throws WxPayException { public void testCloseOrder() throws WxPayException {
this.logger.info(this.payService.closeOrder("11212121").toString()); log.info(this.payService.closeOrder("11212121").toString());
} }
/** /**
@ -205,7 +206,7 @@ public class BaseWxPayServiceImplTest {
String tarType, String deviceInfo) throws Exception { String tarType, String deviceInfo) throws Exception {
WxPayBillResult billResult = this.payService.downloadBill(billDate, billType, tarType, deviceInfo); WxPayBillResult billResult = this.payService.downloadBill(billDate, billType, tarType, deviceInfo);
assertThat(billResult).isNotNull(); assertThat(billResult).isNotNull();
this.logger.info(billResult.toString()); log.info(billResult.toString());
} }
/** /**
@ -248,7 +249,7 @@ public class BaseWxPayServiceImplTest {
public void testDownloadFundFlow(String billDate, String accountType, String tarType) throws Exception { public void testDownloadFundFlow(String billDate, String accountType, String tarType) throws Exception {
WxPayFundFlowResult fundFlowResult = this.payService.downloadFundFlow(billDate, accountType, tarType); WxPayFundFlowResult fundFlowResult = this.payService.downloadFundFlow(billDate, accountType, tarType);
assertThat(fundFlowResult).isNotNull(); assertThat(fundFlowResult).isNotNull();
this.logger.info(fundFlowResult.toString()); log.info(fundFlowResult.toString());
} }
/** /**
@ -293,7 +294,7 @@ public class BaseWxPayServiceImplTest {
.totalFee(1222) .totalFee(1222)
.refundFee(111) .refundFee(111)
.build()); .build());
this.logger.info(result.toString()); log.info(result.toString());
} }
/** /**
@ -306,20 +307,20 @@ public class BaseWxPayServiceImplTest {
WxPayRefundQueryResult result; WxPayRefundQueryResult result;
result = this.payService.refundQuery("1", "", "", ""); result = this.payService.refundQuery("1", "", "", "");
this.logger.info(result.toString()); log.info(result.toString());
result = this.payService.refundQuery("", "2", "", ""); result = this.payService.refundQuery("", "2", "", "");
this.logger.info(result.toString()); log.info(result.toString());
result = this.payService.refundQuery("", "", "3", ""); result = this.payService.refundQuery("", "", "3", "");
this.logger.info(result.toString()); log.info(result.toString());
result = this.payService.refundQuery("", "", "", "4"); result = this.payService.refundQuery("", "", "", "4");
this.logger.info(result.toString()); log.info(result.toString());
//测试四个参数都填的情况应该报异常的 //测试四个参数都填的情况应该报异常的
result = this.payService.refundQuery("1", "2", "3", "4"); result = this.payService.refundQuery("1", "2", "3", "4");
this.logger.info(result.toString()); log.info(result.toString());
} }
/** /**
@ -332,37 +333,6 @@ public class BaseWxPayServiceImplTest {
// 请参考com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResultTest里的单元测试 // 请参考com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResultTest里的单元测试
} }
/**
* Test method for {@link WxPayService#sendRedpack(WxPaySendRedpackRequest)} .
*
* @throws Exception the exception
*/
@Test
public void testSendRedpack() throws Exception {
WxPaySendRedpackRequest request = new WxPaySendRedpackRequest();
request.setActName("abc");
request.setClientIp("aaa");
request.setMchBillNo("aaaa");
request.setWishing("what");
request.setSendName("111");
request.setTotalAmount(1);
request.setTotalNum(1);
request.setReOpenid(((XmlWxPayConfig) this.payService.getConfig()).getOpenid());
WxPaySendRedpackResult redpackResult = this.payService.sendRedpack(request);
this.logger.info(redpackResult.toString());
}
/**
* Test method for {@link WxPayService#queryRedpack(String)}.
*
* @throws Exception the exception
*/
@Test
public void testQueryRedpack() throws Exception {
WxPayRedpackQueryResult redpackResult = this.payService.queryRedpack("aaaa");
this.logger.info(redpackResult.toString());
}
/** /**
* Test create scan pay qrcode mode 1. * Test create scan pay qrcode mode 1.
* *
@ -375,7 +345,7 @@ public class BaseWxPayServiceImplTest {
Path qrcodeFilePath = Files.createTempFile("qrcode_", ".jpg"); Path qrcodeFilePath = Files.createTempFile("qrcode_", ".jpg");
Files.write(qrcodeFilePath, bytes); Files.write(qrcodeFilePath, bytes);
String qrcodeContent = QrcodeUtils.decodeQrcode(qrcodeFilePath.toFile()); String qrcodeContent = QrcodeUtils.decodeQrcode(qrcodeFilePath.toFile());
this.logger.info(qrcodeContent); log.info(qrcodeContent);
assertTrue(qrcodeContent.startsWith("weixin://wxpay/bizpayurl?")); assertTrue(qrcodeContent.startsWith("weixin://wxpay/bizpayurl?"));
assertTrue(qrcodeContent.contains("product_id=" + productId)); assertTrue(qrcodeContent.contains("product_id=" + productId));
@ -411,7 +381,7 @@ public class BaseWxPayServiceImplTest {
.spbillCreateIp("127.0.0.1") .spbillCreateIp("127.0.0.1")
.authCode("aaa") .authCode("aaa")
.build()); .build());
this.logger.info(result.toString()); log.info(result.toString());
} }
/** /**
@ -446,7 +416,7 @@ public class BaseWxPayServiceImplTest {
.outTradeNo("1111") .outTradeNo("1111")
.build()); .build());
assertNotNull(result); assertNotNull(result);
this.logger.info(result.toString()); log.info(result.toString());
} }
/** /**
@ -460,11 +430,11 @@ public class BaseWxPayServiceImplTest {
String result = this.payService.shorturl(new WxPayShorturlRequest(longUrl)); String result = this.payService.shorturl(new WxPayShorturlRequest(longUrl));
assertNotNull(result); assertNotNull(result);
this.logger.info(result); log.info(result);
result = this.payService.shorturl(longUrl); result = this.payService.shorturl(longUrl);
assertNotNull(result); assertNotNull(result);
this.logger.info(result); log.info(result);
} }
/** /**
@ -478,11 +448,11 @@ public class BaseWxPayServiceImplTest {
String result = this.payService.authcode2Openid(new WxPayAuthcode2OpenidRequest(authCode)); String result = this.payService.authcode2Openid(new WxPayAuthcode2OpenidRequest(authCode));
assertNotNull(result); assertNotNull(result);
this.logger.info(result); log.info(result);
result = this.payService.authcode2Openid(authCode); result = this.payService.authcode2Openid(authCode);
assertNotNull(result); assertNotNull(result);
this.logger.info(result); log.info(result);
} }
/** /**
@ -494,7 +464,7 @@ public class BaseWxPayServiceImplTest {
public void testGetSandboxSignKey() throws Exception { public void testGetSandboxSignKey() throws Exception {
final String signKey = this.payService.getSandboxSignKey(); final String signKey = this.payService.getSandboxSignKey();
assertNotNull(signKey); assertNotNull(signKey);
this.logger.info(signKey); log.info(signKey);
} }
/** /**
@ -510,7 +480,7 @@ public class BaseWxPayServiceImplTest {
.partnerTradeNo("1212") .partnerTradeNo("1212")
.openidCount(1) .openidCount(1)
.build()); .build());
this.logger.info(result.toString()); log.info(result.toString());
} }
/** /**
@ -524,7 +494,7 @@ public class BaseWxPayServiceImplTest {
WxPayCouponStockQueryRequest.newBuilder() WxPayCouponStockQueryRequest.newBuilder()
.couponStockId("123") .couponStockId("123")
.build()); .build());
this.logger.info(result.toString()); log.info(result.toString());
} }
/** /**
@ -540,7 +510,7 @@ public class BaseWxPayServiceImplTest {
.couponId("11") .couponId("11")
.stockId("1121") .stockId("1121")
.build()); .build());
this.logger.info(result.toString()); log.info(result.toString());
} }
/** /**
@ -556,7 +526,7 @@ public class BaseWxPayServiceImplTest {
calendar.add(Calendar.DAY_OF_MONTH, -88); calendar.add(Calendar.DAY_OF_MONTH, -88);
Date beginDate = calendar.getTime(); Date beginDate = calendar.getTime();
String result = this.payService.queryComment(beginDate, endDate, 0, 1); String result = this.payService.queryComment(beginDate, endDate, 0, 1);
this.logger.info(result); log.info(result);
} }
/** /**
@ -610,15 +580,6 @@ public class BaseWxPayServiceImplTest {
//see test in testUnifiedOrder() //see test in testUnifiedOrder()
} }
@Test
public void testSendMiniProgramRedpack() throws WxPayException {
final WxPaySendMiniProgramRedpackResult result = this.payService
.sendMiniProgramRedpack(new WxPaySendMiniProgramRedpackRequest()
.setReOpenid("ojOQA0y9o-Eb6Aep7uVTdbkJqrP4")
.setTotalAmount(1));
System.out.println(result);
}
@Test @Test
public void testDownloadRawBill() { public void testDownloadRawBill() {
} }

View File

@ -0,0 +1,63 @@
package com.github.binarywang.wxpay.service.impl;
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;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.testbase.ApiTestModule;
import com.github.binarywang.wxpay.testbase.XmlWxPayConfig;
import com.google.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
/**
* 测试类.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2019-12-26
*/
@Slf4j
@Test
@Guice(modules = ApiTestModule.class)
public class RedpackServiceImplTest {
@Inject
private WxPayService payService;
@Test
public void testSendRedpack() throws Exception {
WxPaySendRedpackRequest request = new WxPaySendRedpackRequest();
request.setActName("abc");
request.setClientIp("aaa");
request.setMchBillNo("aaaa");
request.setWishing("what");
request.setSendName("111");
request.setTotalAmount(1);
request.setTotalNum(1);
request.setReOpenid(((XmlWxPayConfig) this.payService.getConfig()).getOpenid());
WxPaySendRedpackResult redpackResult = this.payService.getRedpackService().sendRedpack(request);
log.info(redpackResult.toString());
}
@Test
public void testQueryRedpack() throws Exception {
WxPayRedpackQueryResult redpackResult = this.payService.getRedpackService().queryRedpack("aaaa");
log.info(redpackResult.toString());
}
@Test
public void testSendMiniProgramRedpack() throws WxPayException {
final WxPaySendMiniProgramRedpackResult result = this.payService.getRedpackService()
.sendMiniProgramRedpack(new WxPaySendMiniProgramRedpackRequest()
.setReOpenid("ojOQA0y9o-Eb6Aep7uVTdbkJqrP4")
.setWishing("haha")
.setMchBillNo("123")
.setActName("11")
.setSendName("111")
.setTotalAmount(1));
System.out.println(result);
}
}