fix:【PAY 支付】支付宝回调时,区分公钥模式、证书模式
This commit is contained in:
parent
a2bfa7a95a
commit
be86acb9b6
@ -41,6 +41,7 @@ import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeC
|
|||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0;
|
||||||
import static cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayPayClientConfig.MODE_CERTIFICATE;
|
import static cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayPayClientConfig.MODE_CERTIFICATE;
|
||||||
|
import static cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayPayClientConfig.MODE_PUBLIC_KEY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付宝抽象类,实现支付宝统一的接口、以及部分实现(退款)
|
* 支付宝抽象类,实现支付宝统一的接口、以及部分实现(退款)
|
||||||
@ -82,8 +83,17 @@ public abstract class AbstractAlipayPayClient extends AbstractPayClient<AlipayPa
|
|||||||
public PayOrderRespDTO doParseOrderNotify(Map<String, String> params, String body, Map<String, String> headers) throws Throwable {
|
public PayOrderRespDTO doParseOrderNotify(Map<String, String> params, String body, Map<String, String> headers) throws Throwable {
|
||||||
// 1. 校验回调数据
|
// 1. 校验回调数据
|
||||||
Map<String, String> bodyObj = HttpUtil.decodeParamMap(body, StandardCharsets.UTF_8);
|
Map<String, String> bodyObj = HttpUtil.decodeParamMap(body, StandardCharsets.UTF_8);
|
||||||
AlipaySignature.rsaCheckV1(bodyObj, config.getAlipayPublicKey(),
|
boolean verify;
|
||||||
StandardCharsets.UTF_8.name(), config.getSignType());
|
if (Objects.equals(config.getMode(), MODE_PUBLIC_KEY)) {
|
||||||
|
verify = AlipaySignature.rsaCheckV1(params, config.getAlipayPublicKey(),
|
||||||
|
StandardCharsets.UTF_8.name(), config.getSignType());
|
||||||
|
} else if (Objects.equals(config.getMode(), MODE_CERTIFICATE)) {
|
||||||
|
verify = AlipaySignature.rsaCertCheckV1(params, config.getAlipayPublicCertContent(),
|
||||||
|
StandardCharsets.UTF_8.name(), config.getSignType());
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("未知的公钥类型:" + config.getMode());
|
||||||
|
}
|
||||||
|
Assert.isTrue(verify, "验签结果不通过");
|
||||||
|
|
||||||
// 2. 解析订单的状态
|
// 2. 解析订单的状态
|
||||||
// 额外说明:支付宝不仅仅支付成功会回调,再各种触发支付单数据变化时,都会进行回调,所以这里 status 的解析会写的比较复杂
|
// 额外说明:支付宝不仅仅支付成功会回调,再各种触发支付单数据变化时,都会进行回调,所以这里 status 的解析会写的比较复杂
|
||||||
|
@ -60,7 +60,7 @@ public class PayClientFactoryImplIntegrationTest {
|
|||||||
config.setMchId("1545083881");
|
config.setMchId("1545083881");
|
||||||
config.setApiVersion(WxPayClientConfig.API_VERSION_V3);
|
config.setApiVersion(WxPayClientConfig.API_VERSION_V3);
|
||||||
config.setPrivateKeyContent(IoUtil.readUtf8(new FileInputStream("/Users/yunai/Downloads/wx_pay/apiclient_key.pem")));
|
config.setPrivateKeyContent(IoUtil.readUtf8(new FileInputStream("/Users/yunai/Downloads/wx_pay/apiclient_key.pem")));
|
||||||
config.setPrivateCertContent(IoUtil.readUtf8(new FileInputStream("/Users/yunai/Downloads/wx_pay/apiclient_cert.pem")));
|
// config.setPrivateCertContent(IoUtil.readUtf8(new FileInputStream("/Users/yunai/Downloads/wx_pay/apiclient_cert.pem")));
|
||||||
config.setApiV3Key("joerVi8y5DJ3o4ttA0o1uH47Xz1u2Ase");
|
config.setApiV3Key("joerVi8y5DJ3o4ttA0o1uH47Xz1u2Ase");
|
||||||
// 创建客户端
|
// 创建客户端
|
||||||
Long channelId = RandomUtil.randomLong();
|
Long channelId = RandomUtil.randomLong();
|
||||||
|
Loading…
Reference in New Issue
Block a user