|
|
@@ -83,8 +83,9 @@ public class MerchantWechatPaymentStrategyImpl implements MerchantPaymentStrateg
|
|
|
}
|
|
|
if (StringUtils.isBlank(config.getWechatAppId()) || StringUtils.isBlank(config.getWechatMchId())
|
|
|
|| StringUtils.isBlank(config.getMerchantSerialNumber()) || StringUtils.isBlank(config.getApiV3Key())
|
|
|
- || StringUtils.isBlank(config.getWechatPayPublicKeyId()) || StringUtils.isBlank(config.getWechatPrivateKeyFile())
|
|
|
- || StringUtils.isBlank(config.getWechatPayPublicKeyFile())) {
|
|
|
+ || StringUtils.isBlank(config.getWechatPayPublicKeyId())
|
|
|
+ || config.getWechatPrivateKeyFile() == null || config.getWechatPrivateKeyFile().length == 0
|
|
|
+ || config.getWechatPayPublicKeyFile() == null || config.getWechatPayPublicKeyFile().length == 0) {
|
|
|
return R.fail("门店微信支付配置不完整");
|
|
|
}
|
|
|
UserReservationOrder order = userReservationOrderService.getById(orderId);
|
|
|
@@ -138,7 +139,7 @@ public class MerchantWechatPaymentStrategyImpl implements MerchantPaymentStrateg
|
|
|
merchantPaymentOrderService.save(paymentOrder);
|
|
|
|
|
|
try {
|
|
|
- PrivateKey privateKey = WXPayUtility.loadPrivateKeyFromString(config.getWechatPrivateKeyFile());
|
|
|
+ PrivateKey privateKey = WXPayUtility.loadPrivateKeyFromString(bytesToUtf8String(config.getWechatPrivateKeyFile()));
|
|
|
|
|
|
WeChatPaymentStrategyImpl.CommonPrepayRequest request = new WeChatPaymentStrategyImpl.CommonPrepayRequest();
|
|
|
request.appid = config.getWechatAppId();
|
|
|
@@ -207,8 +208,8 @@ public class MerchantWechatPaymentStrategyImpl implements MerchantPaymentStrateg
|
|
|
return R.fail("预订订单不存在");
|
|
|
}
|
|
|
try {
|
|
|
- PrivateKey privateKey = WXPayUtility.loadPrivateKeyFromString(config.getWechatPrivateKeyFile());
|
|
|
- PublicKey wechatPayPublicKey = WXPayUtility.loadPublicKeyFromString(config.getWechatPayPublicKeyFile());
|
|
|
+ PrivateKey privateKey = WXPayUtility.loadPrivateKeyFromString(bytesToUtf8String(config.getWechatPrivateKeyFile()));
|
|
|
+ PublicKey wechatPayPublicKey = WXPayUtility.loadPublicKeyFromString(bytesToUtf8String(config.getWechatPayPublicKeyFile()));
|
|
|
|
|
|
WeChatPaymentStrategyImpl.QueryByWxTradeNoRequest req = new WeChatPaymentStrategyImpl.QueryByWxTradeNoRequest();
|
|
|
req.transactionId = outTradeNo;
|
|
|
@@ -276,8 +277,8 @@ public class MerchantWechatPaymentStrategyImpl implements MerchantPaymentStrateg
|
|
|
return R.fail("订单未支付或已退款,无法退款");
|
|
|
}
|
|
|
try {
|
|
|
- PrivateKey privateKey = WXPayUtility.loadPrivateKeyFromString(config.getWechatPrivateKeyFile());
|
|
|
- PublicKey wechatPayPublicKey = WXPayUtility.loadPublicKeyFromString(config.getWechatPayPublicKeyFile());
|
|
|
+ PrivateKey privateKey = WXPayUtility.loadPrivateKeyFromString(bytesToUtf8String(config.getWechatPrivateKeyFile()));
|
|
|
+ PublicKey wechatPayPublicKey = WXPayUtility.loadPublicKeyFromString(bytesToUtf8String(config.getWechatPayPublicKeyFile()));
|
|
|
|
|
|
WeChatPaymentStrategyImpl.CreateRequest request = new WeChatPaymentStrategyImpl.CreateRequest();
|
|
|
request.outTradeNo = outTradeNo;
|
|
|
@@ -360,7 +361,7 @@ public class MerchantWechatPaymentStrategyImpl implements MerchantPaymentStrateg
|
|
|
try (Response httpResponse = client.newCall(reqBuilder.build()).execute()) {
|
|
|
String respBody = WXPayUtility.extractBody(httpResponse);
|
|
|
if (httpResponse.code() >= 200 && httpResponse.code() < 300) {
|
|
|
- PublicKey publicKey = WXPayUtility.loadPublicKeyFromString(config.getWechatPayPublicKeyFile());
|
|
|
+ PublicKey publicKey = WXPayUtility.loadPublicKeyFromString(bytesToUtf8String(config.getWechatPayPublicKeyFile()));
|
|
|
WXPayUtility.validateResponse(config.getWechatPayPublicKeyId(), publicKey, httpResponse.headers(), respBody);
|
|
|
return WXPayUtility.fromJson(respBody, WeChatPaymentStrategyImpl.DirectAPIv3AppPrepayResponse.class);
|
|
|
}
|
|
|
@@ -369,9 +370,9 @@ public class MerchantWechatPaymentStrategyImpl implements MerchantPaymentStrateg
|
|
|
}
|
|
|
|
|
|
private WeChatPaymentStrategyImpl.DirectAPIv3QueryResponse searchOrderRun(StorePaymentConfig config,
|
|
|
- PrivateKey privateKey,
|
|
|
- PublicKey wechatPayPublicKey,
|
|
|
- WeChatPaymentStrategyImpl.QueryByWxTradeNoRequest request) throws IOException {
|
|
|
+ PrivateKey privateKey,
|
|
|
+ PublicKey wechatPayPublicKey,
|
|
|
+ WeChatPaymentStrategyImpl.QueryByWxTradeNoRequest request) throws IOException {
|
|
|
String uri = searchOrderByOutTradeNoPath.replace("{out_trade_no}", WXPayUtility.urlEncode(request.transactionId));
|
|
|
Map<String, Object> args = new HashMap<>();
|
|
|
args.put("mchid", config.getWechatMchId());
|
|
|
@@ -419,4 +420,9 @@ public class MerchantWechatPaymentStrategyImpl implements MerchantPaymentStrateg
|
|
|
throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /** 仅在使用处将证书 byte[] 转为 String(UTF-8),不参与存储,保证存取一致 */
|
|
|
+ private static String bytesToUtf8String(byte[] bytes) {
|
|
|
+ return bytes == null ? null : new String(bytes, StandardCharsets.UTF_8);
|
|
|
+ }
|
|
|
}
|