Browse Source

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

dev1
Binary Wang 5 years ago
parent
commit
fa1f085e1d
7 changed files with 296 additions and 151 deletions
  1. +20
    -0
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPaySendMiniProgramRedpackRequest.java
  2. +76
    -0
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/RedpackService.java
  3. +15
    -43
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java
  4. +17
    -36
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java
  5. +72
    -0
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/RedpackServiceImpl.java
  6. +33
    -72
      weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImplTest.java
  7. +63
    -0
      weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/RedpackServiceImplTest.java

+ 20
- 0
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPaySendMiniProgramRedpackRequest.java View File

@@ -105,8 +105,28 @@ public class WxPaySendMiniProgramRedpackRequest extends BaseWxPayRequest {
@XStreamAlias("scene_id")
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
protected void checkConstraints() {

}

@Override
public String getAppid() {
return this.wxAppid;
}

@Override
public void setAppid(String appid) {
this.wxAppid = appid;
}

}

+ 76
- 0
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/RedpackService.java 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>
* 查询红包记录.
* 用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。
* 请求Url:https://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>
* 查询红包记录.
* 用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。
* 请求Url:https://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;
}

+ 15
- 43
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java 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>
* 查询红包记录.
* 用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。
* 请求Url:https://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>
* 查询红包记录.
* 用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。
* 请求Url:https://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;

/**


+ 17
- 36
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java 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);

WxPaySendMiniProgramRedpackResult result = BaseWxPayResult.fromXML(responseContent, WxPaySendMiniProgramRedpackResult.class);
result.checkResult(this, request.getSignType(), true);
return result;
}
@Override
public WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request)
throws WxPayException {
return this.redpackService.sendMiniProgramRedpack(request);
}

@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


+ 72
- 0
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/RedpackServiceImpl.java 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;
}
}

+ 33
- 72
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImplTest.java 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.XmlWxPayConfig;
import com.google.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.DataProvider;
@@ -39,10 +40,10 @@ import static org.testng.Assert.*;
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Slf4j
@Test
@Guice(modules = ApiTestModule.class)
public class BaseWxPayServiceImplTest {
private final Logger logger = LoggerFactory.getLogger(this.getClass());

@Inject
private WxPayService payService;
@@ -65,8 +66,8 @@ public class BaseWxPayServiceImplTest {
.build();
request.setSignType(SignType.HMAC_SHA256);
WxPayUnifiedOrderResult result = this.payService.unifiedOrder(request);
this.logger.info(result.toString());
this.logger.warn(this.payService.getWxApiData().toString());
log.info(result.toString());
log.warn(this.payService.getWxApiData().toString());
}

/**
@@ -96,8 +97,8 @@ public class BaseWxPayServiceImplTest {
.openid(((XmlWxPayConfig) this.payService.getConfig()).getOpenid())
.outTradeNo("1111112")
.build());
this.logger.info(result.toString());
this.logger.warn(this.payService.getWxApiData().toString());
log.info(result.toString());
log.warn(this.payService.getWxApiData().toString());
}

/**
@@ -116,8 +117,8 @@ public class BaseWxPayServiceImplTest {
.tradeType(TradeType.APP)
.outTradeNo("1111112")
.build());
this.logger.info(result.toString());
this.logger.warn(this.payService.getWxApiData().toString());
log.info(result.toString());
log.warn(this.payService.getWxApiData().toString());
}

/**
@@ -137,8 +138,8 @@ public class BaseWxPayServiceImplTest {
.tradeType(TradeType.NATIVE)
.outTradeNo("111111290")
.build());
this.logger.info(result.toString());
this.logger.warn(this.payService.getWxApiData().toString());
log.info(result.toString());
log.warn(this.payService.getWxApiData().toString());
}

/**
@@ -158,8 +159,8 @@ public class BaseWxPayServiceImplTest {
*/
@Test
public void testQueryOrder() throws WxPayException {
this.logger.info(this.payService.queryOrder("11212121", null).toString());
this.logger.info(this.payService.queryOrder(null, "11111").toString());
log.info(this.payService.queryOrder("11212121", null).toString());
log.info(this.payService.queryOrder(null, "11111").toString());
}

/**
@@ -169,7 +170,7 @@ public class BaseWxPayServiceImplTest {
*/
@Test
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 {
WxPayBillResult billResult = this.payService.downloadBill(billDate, billType, tarType, deviceInfo);
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 {
WxPayFundFlowResult fundFlowResult = this.payService.downloadFundFlow(billDate, accountType, tarType);
assertThat(fundFlowResult).isNotNull();
this.logger.info(fundFlowResult.toString());
log.info(fundFlowResult.toString());
}

/**
@@ -293,7 +294,7 @@ public class BaseWxPayServiceImplTest {
.totalFee(1222)
.refundFee(111)
.build());
this.logger.info(result.toString());
log.info(result.toString());
}

/**
@@ -306,20 +307,20 @@ public class BaseWxPayServiceImplTest {
WxPayRefundQueryResult result;

result = this.payService.refundQuery("1", "", "", "");
this.logger.info(result.toString());
log.info(result.toString());

result = this.payService.refundQuery("", "2", "", "");
this.logger.info(result.toString());
log.info(result.toString());

result = this.payService.refundQuery("", "", "3", "");
this.logger.info(result.toString());
log.info(result.toString());

result = this.payService.refundQuery("", "", "", "4");
this.logger.info(result.toString());
log.info(result.toString());

//测试四个参数都填的情况,应该报异常的
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里的单元测试
}

/**
* 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.
*
@@ -375,7 +345,7 @@ public class BaseWxPayServiceImplTest {
Path qrcodeFilePath = Files.createTempFile("qrcode_", ".jpg");
Files.write(qrcodeFilePath, bytes);
String qrcodeContent = QrcodeUtils.decodeQrcode(qrcodeFilePath.toFile());
this.logger.info(qrcodeContent);
log.info(qrcodeContent);

assertTrue(qrcodeContent.startsWith("weixin://wxpay/bizpayurl?"));
assertTrue(qrcodeContent.contains("product_id=" + productId));
@@ -411,7 +381,7 @@ public class BaseWxPayServiceImplTest {
.spbillCreateIp("127.0.0.1")
.authCode("aaa")
.build());
this.logger.info(result.toString());
log.info(result.toString());
}

/**
@@ -446,7 +416,7 @@ public class BaseWxPayServiceImplTest {
.outTradeNo("1111")
.build());
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));
assertNotNull(result);
this.logger.info(result);
log.info(result);

result = this.payService.shorturl(longUrl);
assertNotNull(result);
this.logger.info(result);
log.info(result);
}

/**
@@ -478,11 +448,11 @@ public class BaseWxPayServiceImplTest {

String result = this.payService.authcode2Openid(new WxPayAuthcode2OpenidRequest(authCode));
assertNotNull(result);
this.logger.info(result);
log.info(result);

result = this.payService.authcode2Openid(authCode);
assertNotNull(result);
this.logger.info(result);
log.info(result);
}

/**
@@ -494,7 +464,7 @@ public class BaseWxPayServiceImplTest {
public void testGetSandboxSignKey() throws Exception {
final String signKey = this.payService.getSandboxSignKey();
assertNotNull(signKey);
this.logger.info(signKey);
log.info(signKey);
}

/**
@@ -510,7 +480,7 @@ public class BaseWxPayServiceImplTest {
.partnerTradeNo("1212")
.openidCount(1)
.build());
this.logger.info(result.toString());
log.info(result.toString());
}

/**
@@ -524,7 +494,7 @@ public class BaseWxPayServiceImplTest {
WxPayCouponStockQueryRequest.newBuilder()
.couponStockId("123")
.build());
this.logger.info(result.toString());
log.info(result.toString());
}

/**
@@ -540,7 +510,7 @@ public class BaseWxPayServiceImplTest {
.couponId("11")
.stockId("1121")
.build());
this.logger.info(result.toString());
log.info(result.toString());
}

/**
@@ -556,7 +526,7 @@ public class BaseWxPayServiceImplTest {
calendar.add(Calendar.DAY_OF_MONTH, -88);
Date beginDate = calendar.getTime();
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()
}

@Test
public void testSendMiniProgramRedpack() throws WxPayException {
final WxPaySendMiniProgramRedpackResult result = this.payService
.sendMiniProgramRedpack(new WxPaySendMiniProgramRedpackRequest()
.setReOpenid("ojOQA0y9o-Eb6Aep7uVTdbkJqrP4")
.setTotalAmount(1));
System.out.println(result);
}

@Test
public void testDownloadRawBill() {
}


+ 63
- 0
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/RedpackServiceImplTest.java 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);
}
}

Loading…
Cancel
Save