🎨 #2985【企业微信】增加会话存档常量类型支持
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package com.github.binarywang.wxpay.bean.notify;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||
|
||||
/**
|
||||
* 微信支付订单和退款的异步通知,V3版本共用的响应类.
|
||||
@@ -33,7 +33,7 @@ public class WxPayNotifyV3Response {
|
||||
*/
|
||||
public static String success(String msg) {
|
||||
WxPayNotifyV3Response response = new WxPayNotifyV3Response(SUCCESS, msg);
|
||||
return new Gson().toJson(response);
|
||||
return WxGsonBuilder.create().toJson(response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,7 +44,7 @@ public class WxPayNotifyV3Response {
|
||||
*/
|
||||
public static String fail(String msg) {
|
||||
WxPayNotifyV3Response response = new WxPayNotifyV3Response(FAIL, msg);
|
||||
return new Gson().toJson(response);
|
||||
return WxGsonBuilder.create().toJson(response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -157,6 +157,13 @@ public abstract class BaseWxPayRequest implements Serializable {
|
||||
return yuan.multiply(BigDecimal.valueOf(100)).setScale(2, BigDecimal.ROUND_HALF_UP).intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分转元
|
||||
*/
|
||||
public static BigDecimal fen2Yuan(BigDecimal fen) {
|
||||
return fen.divide(BigDecimal.valueOf(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查请求参数内容,包括必填参数以及特殊约束.
|
||||
*/
|
||||
|
||||
@@ -779,7 +779,7 @@ public class BaseWxPayServiceImplTest {
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void testParseOrderNotifyV3Result(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
public String testParseOrderNotifyV3Result(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
|
||||
String timestamp = request.getHeader("Wechatpay-Timestamp");
|
||||
Optional.ofNullable(timestamp).orElseThrow(() -> new RuntimeException("时间戳不能为空"));
|
||||
@@ -799,6 +799,8 @@ public class BaseWxPayServiceImplTest {
|
||||
final WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = this.payService.parseOrderNotifyV3Result(RequestUtils.readData(request),
|
||||
new SignatureHeader(timestamp, nonce, signature, serialNo));
|
||||
log.info(GSON.toJson(wxPayOrderNotifyV3Result));
|
||||
|
||||
return WxPayNotifyV3Response.success("成功");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -808,7 +810,7 @@ public class BaseWxPayServiceImplTest {
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void testParseRefundNotifyV3Result(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
public String testParseRefundNotifyV3Result(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
|
||||
String timestamp = request.getHeader("Wechatpay-Timestamp");
|
||||
Optional.ofNullable(timestamp).orElseThrow(() -> new RuntimeException("时间戳不能为空"));
|
||||
@@ -827,6 +829,21 @@ public class BaseWxPayServiceImplTest {
|
||||
final WxPayRefundNotifyV3Result wxPayRefundNotifyV3Result = this.payService.parseRefundNotifyV3Result(RequestUtils.readData(request),
|
||||
new SignatureHeader(timestamp, nonce, signature, serialNo));
|
||||
log.info(GSON.toJson(wxPayRefundNotifyV3Result));
|
||||
|
||||
// 退款金额
|
||||
final WxPayRefundNotifyV3Result.DecryptNotifyResult result = wxPayRefundNotifyV3Result.getResult();
|
||||
final BigDecimal total = BaseWxPayRequest.fen2Yuan(BigDecimal.valueOf(result.getAmount().getTotal()));
|
||||
final BigDecimal payerRefund = BaseWxPayRequest.fen2Yuan(BigDecimal.valueOf(result.getAmount().getPayerRefund()));
|
||||
|
||||
// 处理业务逻辑 ...
|
||||
|
||||
return WxPayNotifyV3Response.success("成功");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWxPayNotifyV3Response() {
|
||||
System.out.println(WxPayNotifyV3Response.success("success"));
|
||||
System.out.println(WxPayNotifyV3Response.fail("fail"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
<xml>
|
||||
<appId>公众号appid</appId>
|
||||
<mchId>微信商户平台ID</mchId>
|
||||
<!---
|
||||
以下为官网文档所提供样例参数,仅供部分接口测试使用
|
||||
<appId>wxd930ea5d5a258f4f</appId>
|
||||
<mchId>10000100</mchId>
|
||||
<mchKey>192006250b4c09247ec02edce69f6a2d</mchKey>
|
||||
-->
|
||||
|
||||
<appId>appid</appId>
|
||||
<mchId>微信商户平台ID</mchId>
|
||||
|
||||
<!-- v2版本 -->
|
||||
<mchKey>商户平台设置的API密钥</mchKey>
|
||||
<keyPath>商户平台的证书文件地址</keyPath>
|
||||
|
||||
Reference in New Issue
Block a user