🐛 #1338 微信支付修复发送小程序红包接口的参数问题
This commit is contained in:
@@ -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() {
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user