【功能优化】PAY:微信支付使用 certSerialNo 替代 privateCertContent

pull/123/MERGE
YunaiV 2024-07-26 09:23:32 +08:00
parent 41f56969e1
commit 5fc4b5a64b
3 changed files with 20 additions and 32 deletions

View File

@ -157,7 +157,7 @@ public class DeptDataPermissionRule implements DataPermissionRule {
// 拼接条件 // 拼接条件
return new InExpression(MyBatisUtils.buildColumn(tableName, tableAlias, columnName), return new InExpression(MyBatisUtils.buildColumn(tableName, tableAlias, columnName),
// Parenthesis 的目的,是提供 (1,2,3) 的 () 左右括号 // Parenthesis 的目的,是提供 (1,2,3) 的 () 左右括号
new Parenthesis(new ExpressionList<>(CollectionUtils.convertList(deptIds, LongValue::new)))); new Parenthesis(new ExpressionList<LongValue>(CollectionUtils.convertList(deptIds, LongValue::new))));
} }
private Expression buildUserExpression(String tableName, Alias tableAlias, Boolean self, Long userId) { private Expression buildUserExpression(String tableName, Alias tableAlias, Boolean self, Long userId) {

View File

@ -36,6 +36,7 @@ import java.util.Objects;
import static cn.hutool.core.date.DatePattern.*; import static cn.hutool.core.date.DatePattern.*;
import static cn.iocoder.yudao.framework.pay.core.client.impl.weixin.WxPayClientConfig.API_VERSION_V2; import static cn.iocoder.yudao.framework.pay.core.client.impl.weixin.WxPayClientConfig.API_VERSION_V2;
import static cn.iocoder.yudao.framework.pay.core.client.impl.weixin.WxPayClientConfig.API_VERSION_V3;
/** /**
* 退 * 退
@ -59,19 +60,14 @@ public abstract class AbstractWxPayClient extends AbstractPayClient<WxPayClientC
protected void doInit(String tradeType) { protected void doInit(String tradeType) {
// 创建 config 配置 // 创建 config 配置
WxPayConfig payConfig = new WxPayConfig(); WxPayConfig payConfig = new WxPayConfig();
BeanUtil.copyProperties(config, payConfig, "keyContent", "privateKeyContent", "privateCertContent"); BeanUtil.copyProperties(config, payConfig, "keyContent", "privateKeyContent");
payConfig.setTradeType(tradeType); payConfig.setTradeType(tradeType);
// weixin-pay-java 无法设置内容,只允许读取文件,所以这里要创建临时文件来解决 // weixin-pay-java 无法设置内容,只允许读取文件,所以这里要创建临时文件来解决
if (Base64.isBase64(config.getKeyContent())) { if (Objects.equals(config.getApiVersion(), API_VERSION_V2)) {
payConfig.setKeyPath(FileUtils.createTempFile(Base64.decode(config.getKeyContent())).getPath()); payConfig.setKeyPath(FileUtils.createTempFile(Base64.decode(config.getKeyContent())).getPath());
} } else if (Objects.equals(config.getApiVersion(), API_VERSION_V3)) {
if (StrUtil.isNotEmpty(config.getPrivateKeyContent())) {
payConfig.setPrivateKeyPath(FileUtils.createTempFile(config.getPrivateKeyContent()).getPath()); payConfig.setPrivateKeyPath(FileUtils.createTempFile(config.getPrivateKeyContent()).getPath());
} }
if (StrUtil.isNotEmpty(config.getPrivateCertContent())) {
payConfig.setPrivateCertPath(FileUtils.createTempFile(config.getPrivateCertContent()).getPath());
}
// payConfig.setCertSerialNo();
// 创建 client 客户端 // 创建 client 客户端
client = new WxPayServiceImpl(); client = new WxPayServiceImpl();
@ -86,7 +82,7 @@ public abstract class AbstractWxPayClient extends AbstractPayClient<WxPayClientC
switch (config.getApiVersion()) { switch (config.getApiVersion()) {
case API_VERSION_V2: case API_VERSION_V2:
return doUnifiedOrderV2(reqDTO); return doUnifiedOrderV2(reqDTO);
case WxPayClientConfig.API_VERSION_V3: case API_VERSION_V3:
return doUnifiedOrderV3(reqDTO); return doUnifiedOrderV3(reqDTO);
default: default:
throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion()));
@ -157,7 +153,7 @@ public abstract class AbstractWxPayClient extends AbstractPayClient<WxPayClientC
switch (config.getApiVersion()) { switch (config.getApiVersion()) {
case API_VERSION_V2: case API_VERSION_V2:
return doParseOrderNotifyV2(body); return doParseOrderNotifyV2(body);
case WxPayClientConfig.API_VERSION_V3: case API_VERSION_V3:
return doParseOrderNotifyV3(body); return doParseOrderNotifyV3(body);
default: default:
throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion()));
@ -192,7 +188,7 @@ public abstract class AbstractWxPayClient extends AbstractPayClient<WxPayClientC
switch (config.getApiVersion()) { switch (config.getApiVersion()) {
case API_VERSION_V2: case API_VERSION_V2:
return doGetOrderV2(outTradeNo); return doGetOrderV2(outTradeNo);
case WxPayClientConfig.API_VERSION_V3: case API_VERSION_V3:
return doGetOrderV3(outTradeNo); return doGetOrderV3(outTradeNo);
default: default:
throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion()));
@ -261,7 +257,7 @@ public abstract class AbstractWxPayClient extends AbstractPayClient<WxPayClientC
switch (config.getApiVersion()) { switch (config.getApiVersion()) {
case API_VERSION_V2: case API_VERSION_V2:
return doUnifiedRefundV2(reqDTO); return doUnifiedRefundV2(reqDTO);
case WxPayClientConfig.API_VERSION_V3: case API_VERSION_V3:
return doUnifiedRefundV3(reqDTO); return doUnifiedRefundV3(reqDTO);
default: default:
throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion()));
@ -321,7 +317,7 @@ public abstract class AbstractWxPayClient extends AbstractPayClient<WxPayClientC
switch (config.getApiVersion()) { switch (config.getApiVersion()) {
case API_VERSION_V2: case API_VERSION_V2:
return doParseRefundNotifyV2(body); return doParseRefundNotifyV2(body);
case WxPayClientConfig.API_VERSION_V3: case API_VERSION_V3:
return parseRefundNotifyV3(body); return parseRefundNotifyV3(body);
default: default:
throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion()));
@ -358,7 +354,7 @@ public abstract class AbstractWxPayClient extends AbstractPayClient<WxPayClientC
switch (config.getApiVersion()) { switch (config.getApiVersion()) {
case API_VERSION_V2: case API_VERSION_V2:
return doGetRefundV2(outTradeNo, outRefundNo); return doGetRefundV2(outTradeNo, outRefundNo);
case WxPayClientConfig.API_VERSION_V3: case API_VERSION_V3:
return doGetRefundV3(outTradeNo, outRefundNo); return doGetRefundV3(outTradeNo, outRefundNo);
default: default:
throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion()));
@ -431,7 +427,7 @@ public abstract class AbstractWxPayClient extends AbstractPayClient<WxPayClientC
@Override @Override
protected PayTransferRespDTO doUnifiedTransfer(PayTransferUnifiedReqDTO reqDTO) { protected PayTransferRespDTO doUnifiedTransfer(PayTransferUnifiedReqDTO reqDTO) {
throw new UnsupportedOperationException("待实现"); throw new UnsupportedOperationException("待实现");
} }
@Override @Override

View File

@ -1,15 +1,11 @@
package cn.iocoder.yudao.framework.pay.core.client.impl.weixin; package cn.iocoder.yudao.framework.pay.core.client.impl.weixin;
import cn.hutool.core.io.IoUtil;
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig;
import jakarta.validation.Validator; import jakarta.validation.Validator;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import lombok.Data; import lombok.Data;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
/** /**
* PayClientConfig * PayClientConfig
* {@link com.github.binarywang.wxpay.config.WxPayConfig} * {@link com.github.binarywang.wxpay.config.WxPayConfig}
@ -71,16 +67,19 @@ public class WxPayClientConfig implements PayClientConfig {
*/ */
@NotBlank(message = "apiclient_key 不能为空", groups = V3.class) @NotBlank(message = "apiclient_key 不能为空", groups = V3.class)
private String privateKeyContent; private String privateKeyContent;
/**
* apiclient_cert.pem
*/
@NotBlank(message = "apiclient_cert 不能为空", groups = V3.class)
private String privateCertContent;
/** /**
* apiV3 * apiV3
*/ */
@NotBlank(message = "apiV3 密钥值不能为空", groups = V3.class) @NotBlank(message = "apiV3 密钥值不能为空", groups = V3.class)
private String apiV3Key; private String apiV3Key;
/**
*
*/
@NotBlank(message = "证书序列号不能为空", groups = V3.class)
private String certSerialNo;
@Deprecated // TODO 芋艿V2.3.0 进行移除
private String privateCertContent;
/** /**
* v2 * v2
@ -100,11 +99,4 @@ public class WxPayClientConfig implements PayClientConfig {
API_VERSION_V2.equals(this.getApiVersion()) ? V2.class : V3.class); API_VERSION_V2.equals(this.getApiVersion()) ? V2.class : V3.class);
} }
public static void main(String[] args) throws FileNotFoundException {
String path = "/Users/yunai/Downloads/wx_pay/apiclient_cert.p12";
/// String path = "/Users/yunai/Downloads/wx_pay/apiclient_key.pem";
/// String path = "/Users/yunai/Downloads/wx_pay/apiclient_cert.pem";
System.out.println(IoUtil.readUtf8(new FileInputStream(path)));
}
} }