支付配置改为RSAPublicKeyConfig,增加公钥配置,但是WXCertUtil.exe 生成的apiclient_cert.pem格式不正确
This commit is contained in:
parent
17d4235e42
commit
e2f9b2356f
@ -74,6 +74,13 @@
|
|||||||
<version>${hutool.version}</version>
|
<version>${hutool.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Java Servlet -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-validation</artifactId>
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package com.cdzy.payment.config;
|
package com.cdzy.payment.config;
|
||||||
|
|
||||||
import com.wechat.pay.java.core.Config;
|
import com.wechat.pay.java.core.Config;
|
||||||
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
import com.wechat.pay.java.core.RSAPublicKeyConfig;
|
||||||
import com.wechat.pay.java.core.cipher.RSASigner;
|
import com.wechat.pay.java.core.cipher.RSASigner;
|
||||||
import com.wechat.pay.java.core.util.PemUtil;
|
import com.wechat.pay.java.core.util.PemUtil;
|
||||||
import com.wechat.pay.java.service.payments.jsapi.JsapiService;
|
import com.wechat.pay.java.service.payments.jsapi.JsapiService;
|
||||||
@ -33,9 +33,17 @@ public class WxPayConfig {
|
|||||||
*/
|
*/
|
||||||
private String merchantId;
|
private String merchantId;
|
||||||
/**
|
/**
|
||||||
* 微信支付商户密钥文件路径
|
* 微信支付商户私钥文件路径
|
||||||
*/
|
*/
|
||||||
private String privateKeyPath;
|
private String privateKeyPath;
|
||||||
|
/**
|
||||||
|
* 微信支付商户公钥文件路径
|
||||||
|
*/
|
||||||
|
private String publicKeyPath;
|
||||||
|
/**
|
||||||
|
* 微信支付商户公钥ID
|
||||||
|
*/
|
||||||
|
private String publicKeyId;
|
||||||
/**
|
/**
|
||||||
* 微信支付商户证书序列号
|
* 微信支付商户证书序列号
|
||||||
*/
|
*/
|
||||||
@ -58,13 +66,16 @@ public class WxPayConfig {
|
|||||||
*/
|
*/
|
||||||
private Integer expireMinute = 5;
|
private Integer expireMinute = 5;
|
||||||
|
|
||||||
|
@Bean
|
||||||
public Config certificateConfig() {
|
public Config certificateConfig() {
|
||||||
return new RSAAutoCertificateConfig.Builder()
|
return new RSAPublicKeyConfig.Builder()
|
||||||
.merchantId(merchantId)
|
.merchantId(merchantId)
|
||||||
// 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
|
// 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
|
||||||
.privateKeyFromPath(privateKeyPath)
|
.privateKeyFromPath(privateKeyPath)
|
||||||
|
.publicKeyFromPath(publicKeyPath)
|
||||||
.merchantSerialNumber(merchantSerialNumber)
|
.merchantSerialNumber(merchantSerialNumber)
|
||||||
.apiV3Key(apiV3Key)
|
.apiV3Key(apiV3Key)
|
||||||
|
.publicKeyId(publicKeyId)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,8 +4,8 @@ import com.alibaba.fastjson2.JSONObject;
|
|||||||
import com.cdzy.payment.model.dto.HandleNotifyResult;
|
import com.cdzy.payment.model.dto.HandleNotifyResult;
|
||||||
import com.cdzy.payment.service.WxPayService;
|
import com.cdzy.payment.service.WxPayService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|||||||
@ -75,7 +75,7 @@ public class EbikeWxPaymentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 调用微信退款接口
|
* 调用退款接口
|
||||||
*
|
*
|
||||||
* @param orderId 订单id
|
* @param orderId 订单id
|
||||||
* @return 退款成功返回true,否则返回false
|
* @return 退款成功返回true,否则返回false
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package com.cdzy.payment.service;
|
|||||||
|
|
||||||
import com.mybatisflex.core.service.IService;
|
import com.mybatisflex.core.service.IService;
|
||||||
import com.cdzy.payment.model.entity.EbikeRefund;
|
import com.cdzy.payment.model.entity.EbikeRefund;
|
||||||
import com.wechat.pay.java.service.payments.model.Transaction;
|
|
||||||
import com.wechat.pay.java.service.refund.model.Refund;
|
import com.wechat.pay.java.service.refund.model.Refund;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@ -2,12 +2,11 @@ package com.cdzy.payment.service;
|
|||||||
|
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.cdzy.payment.model.dto.AmountRefundDto;
|
|
||||||
import com.cdzy.payment.model.dto.HandleNotifyResult;
|
import com.cdzy.payment.model.dto.HandleNotifyResult;
|
||||||
import com.wechat.pay.java.service.payments.model.Transaction;
|
import com.wechat.pay.java.service.payments.model.Transaction;
|
||||||
import com.wechat.pay.java.service.refund.model.Refund;
|
import com.wechat.pay.java.service.refund.model.Refund;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信支付服务类(JSAPI支付),小程序
|
* 微信支付服务类(JSAPI支付),小程序
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package com.cdzy.payment.service.impl;
|
package com.cdzy.payment.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.util.RandomUtil;
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.cdzy.common.model.JsonResult;
|
import com.cdzy.common.model.JsonResult;
|
||||||
@ -27,6 +26,7 @@ import com.wechat.pay.java.core.exception.ValidationException;
|
|||||||
import com.wechat.pay.java.core.notification.NotificationConfig;
|
import com.wechat.pay.java.core.notification.NotificationConfig;
|
||||||
import com.wechat.pay.java.core.notification.NotificationParser;
|
import com.wechat.pay.java.core.notification.NotificationParser;
|
||||||
import com.wechat.pay.java.core.notification.RequestParam;
|
import com.wechat.pay.java.core.notification.RequestParam;
|
||||||
|
import com.wechat.pay.java.core.util.NonceUtil;
|
||||||
import com.wechat.pay.java.service.payments.jsapi.model.*;
|
import com.wechat.pay.java.service.payments.jsapi.model.*;
|
||||||
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
|
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
|
||||||
import com.wechat.pay.java.service.payments.jsapi.model.GoodsDetail;
|
import com.wechat.pay.java.service.payments.jsapi.model.GoodsDetail;
|
||||||
@ -38,7 +38,7 @@ import jakarta.annotation.Resource;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.*;
|
import java.time.*;
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|||||||
r.put("error", "查询订单失败, "+result.getMessage());
|
r.put("error", "查询订单失败, "+result.getMessage());
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
EbikePaymentDto paymentDto = JSON.parseObject(JSON.toJSONString(result.getData()), EbikePaymentDto.class);
|
EbikePaymentDto paymentDto = JSON.parseObject(JSONObject.toJSONString(result.getData()), EbikePaymentDto.class);
|
||||||
return prepay(paymentDto, ebikePayment);
|
return prepay(paymentDto, ebikePayment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +188,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|||||||
WxJsapiPromptDto wxJsapiPromptDto = new WxJsapiPromptDto();
|
WxJsapiPromptDto wxJsapiPromptDto = new WxJsapiPromptDto();
|
||||||
wxJsapiPromptDto.setAppId(wxPayConfig.getAppId());
|
wxJsapiPromptDto.setAppId(wxPayConfig.getAppId());
|
||||||
wxJsapiPromptDto.setTimeStamp(String.valueOf(Instant.now().getEpochSecond()));
|
wxJsapiPromptDto.setTimeStamp(String.valueOf(Instant.now().getEpochSecond()));
|
||||||
wxJsapiPromptDto.setNonceStr(RandomUtil.randomStringUpper(32));
|
wxJsapiPromptDto.setNonceStr(NonceUtil.createNonce(32));
|
||||||
wxJsapiPromptDto.setExtension("prepay_id=" + payId);
|
wxJsapiPromptDto.setExtension("prepay_id=" + payId);
|
||||||
return wxJsapiPromptDto.toJson(wxRsaSigner);
|
return wxJsapiPromptDto.toJson(wxRsaSigner);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package com.cdzy.payment.utils;
|
package com.cdzy.payment.utils;
|
||||||
|
|
||||||
import jakarta.servlet.ServletInputStream;
|
import javax.servlet.ServletInputStream;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
|||||||
@ -2,7 +2,7 @@ server:
|
|||||||
port: 10017
|
port: 10017
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: ebike-pay
|
name: ebike-payment
|
||||||
cloud:
|
cloud:
|
||||||
nacos:
|
nacos:
|
||||||
server-addr: 127.0.0.1:8848 # nacos
|
server-addr: 127.0.0.1:8848 # nacos
|
||||||
@ -33,11 +33,13 @@ mybatis-flex:
|
|||||||
mapper-locations: classpath:mapper/*.xml
|
mapper-locations: classpath:mapper/*.xml
|
||||||
payment:
|
payment:
|
||||||
wx-pay:
|
wx-pay:
|
||||||
app-id: wx097b305458b0757c
|
app-id: wx327d788d7bd6eddf
|
||||||
merchant-id: 1668000369
|
merchant-id: 1715147005
|
||||||
private-key-path: D:\Projects\eBIKE\docs\wechatpay\apiclient_key.pem
|
private-key-path: D:/Projects/eBIKE/docs/secrets/apiclient_key.pem
|
||||||
merchant-serial-number: 5157F09EFDC096DE15EBE81A47057A72********
|
public-key-path: D:/Projects/eBIKE/docs/secrets/apiclient_cert.pem
|
||||||
api-v3-key: 5157F09EFDC096DE15EBE81A47057A72********
|
merchant-serial-number: 7873E3E694ADD0368EA3E9FAC929F496EECB8DF9
|
||||||
|
api-v3-key: 1715147005V3Key20250425174554633
|
||||||
|
public-key-id: PUB_KEY_ID_0117151470052025042500331704000601
|
||||||
pay-notify_url: http://192.168.2.156:10017/wxPayment/pay-notify
|
pay-notify_url: http://192.168.2.156:10017/wxPayment/pay-notify
|
||||||
refund-notify_url: http://192.168.2.156:10017/wxPayment/refund-notify
|
refund-notify_url: http://192.168.2.156:10017/wxPayment/refund-notify
|
||||||
expire-minutes: 5
|
expire-minutes: 5
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user