Commit be86acb9b6bfe0c0cd946114e873ed84a79fdf63
1 parent
a2bfa7a9
fix:【PAY 支付】支付宝回调时,区分公钥模式、证书模式
Showing
2 changed files
with
13 additions
and
3 deletions
yudao-module-pay/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayPayClient.java
| ... | ... | @@ -41,6 +41,7 @@ import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeC |
| 41 | 41 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 42 | 42 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0; |
| 43 | 43 | import static cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayPayClientConfig.MODE_CERTIFICATE; |
| 44 | +import static cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayPayClientConfig.MODE_PUBLIC_KEY; | |
| 44 | 45 | |
| 45 | 46 | /** |
| 46 | 47 | * 支付宝抽象类,实现支付宝统一的接口、以及部分实现(退款) |
| ... | ... | @@ -82,8 +83,17 @@ public abstract class AbstractAlipayPayClient extends AbstractPayClient<AlipayPa |
| 82 | 83 | public PayOrderRespDTO doParseOrderNotify(Map<String, String> params, String body, Map<String, String> headers) throws Throwable { |
| 83 | 84 | // 1. 校验回调数据 |
| 84 | 85 | Map<String, String> bodyObj = HttpUtil.decodeParamMap(body, StandardCharsets.UTF_8); |
| 85 | - AlipaySignature.rsaCheckV1(bodyObj, config.getAlipayPublicKey(), | |
| 86 | - StandardCharsets.UTF_8.name(), config.getSignType()); | |
| 86 | + boolean verify; | |
| 87 | + if (Objects.equals(config.getMode(), MODE_PUBLIC_KEY)) { | |
| 88 | + verify = AlipaySignature.rsaCheckV1(params, config.getAlipayPublicKey(), | |
| 89 | + StandardCharsets.UTF_8.name(), config.getSignType()); | |
| 90 | + } else if (Objects.equals(config.getMode(), MODE_CERTIFICATE)) { | |
| 91 | + verify = AlipaySignature.rsaCertCheckV1(params, config.getAlipayPublicCertContent(), | |
| 92 | + StandardCharsets.UTF_8.name(), config.getSignType()); | |
| 93 | + } else { | |
| 94 | + throw new IllegalArgumentException("未知的公钥类型:" + config.getMode()); | |
| 95 | + } | |
| 96 | + Assert.isTrue(verify, "验签结果不通过"); | |
| 87 | 97 | |
| 88 | 98 | // 2. 解析订单的状态 |
| 89 | 99 | // 额外说明:支付宝不仅仅支付成功会回调,再各种触发支付单数据变化时,都会进行回调,所以这里 status 的解析会写的比较复杂 | ... | ... |
yudao-module-pay/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImplIntegrationTest.java
| ... | ... | @@ -60,7 +60,7 @@ public class PayClientFactoryImplIntegrationTest { |
| 60 | 60 | config.setMchId("1545083881"); |
| 61 | 61 | config.setApiVersion(WxPayClientConfig.API_VERSION_V3); |
| 62 | 62 | config.setPrivateKeyContent(IoUtil.readUtf8(new FileInputStream("/Users/yunai/Downloads/wx_pay/apiclient_key.pem"))); |
| 63 | - config.setPrivateCertContent(IoUtil.readUtf8(new FileInputStream("/Users/yunai/Downloads/wx_pay/apiclient_cert.pem"))); | |
| 63 | +// config.setPrivateCertContent(IoUtil.readUtf8(new FileInputStream("/Users/yunai/Downloads/wx_pay/apiclient_cert.pem"))); | |
| 64 | 64 | config.setApiV3Key("joerVi8y5DJ3o4ttA0o1uH47Xz1u2Ase"); |
| 65 | 65 | // 创建客户端 |
| 66 | 66 | Long channelId = RandomUtil.randomLong(); | ... | ... |