105 lines
2.9 KiB
Java
105 lines
2.9 KiB
Java
package com.cdzy.payment.config;
|
||
|
||
import com.wechat.pay.java.core.Config;
|
||
import com.wechat.pay.java.core.RSAPublicKeyConfig;
|
||
import com.wechat.pay.java.core.cipher.Signer;
|
||
import com.wechat.pay.java.service.payments.jsapi.JsapiService;
|
||
import com.wechat.pay.java.service.refund.RefundService;
|
||
import lombok.Data;
|
||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||
import org.springframework.context.annotation.Bean;
|
||
import org.springframework.context.annotation.Configuration;
|
||
|
||
/**
|
||
* 微信支付配置参数
|
||
*
|
||
* @author dingchao
|
||
* @date 2025/4/24
|
||
* @modified by:
|
||
*/
|
||
@Data
|
||
@Configuration
|
||
@ConfigurationProperties(prefix = "payment.wx-pay")
|
||
public class WxPayConfig {
|
||
/**
|
||
* 微信小程序 appId
|
||
*/
|
||
private String appId;
|
||
/**
|
||
* 微信支付商户号
|
||
*/
|
||
private String merchantId;
|
||
/**
|
||
* 微信支付商户私钥文件路径
|
||
*/
|
||
private String privateKeyPath;
|
||
/**
|
||
* 微信支付商户公钥文件路径
|
||
*/
|
||
private String publicKeyPath;
|
||
/**
|
||
* 微信支付商户公钥ID
|
||
*/
|
||
private String publicKeyId;
|
||
/**
|
||
* 微信支付商户证书序列号
|
||
*/
|
||
private String merchantSerialNumber;
|
||
/**
|
||
* 微信支付商户 APIv3 密钥
|
||
*/
|
||
private String apiV3Key;
|
||
/**
|
||
* 微信支付回调地址
|
||
*/
|
||
private String payNotifyUrl;
|
||
/**
|
||
* 微信支付退款回调地址
|
||
*/
|
||
private String refundNotifyUrl;
|
||
/**
|
||
* 支付、退款过期时间(分钟)
|
||
* 默认24小时,超过24小时订单会自动关闭
|
||
*/
|
||
private Integer expireMinute = 1440;
|
||
/**
|
||
* 支付状态检查定时任务执行表达式
|
||
* 默认每12小时执行1次
|
||
*/
|
||
private String paySchedule = "0 0 0/12 * * ?";
|
||
/**
|
||
* 退款状态检查定时任务执行表达式
|
||
* 默认每30分钟执行1次
|
||
*/
|
||
private String refundSchedule = "0 0/30 * * * ?";
|
||
|
||
@Bean
|
||
public Config certificateConfig() {
|
||
return new RSAPublicKeyConfig.Builder()
|
||
.merchantId(merchantId)
|
||
// 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
|
||
.privateKeyFromPath(privateKeyPath)
|
||
.publicKeyFromPath(publicKeyPath)
|
||
.merchantSerialNumber(merchantSerialNumber)
|
||
.apiV3Key(apiV3Key)
|
||
.publicKeyId(publicKeyId)
|
||
.build();
|
||
}
|
||
|
||
@Bean
|
||
public JsapiService wxJsapiService(Config certificateConfig) {
|
||
return new JsapiService.Builder().config(certificateConfig).build();
|
||
}
|
||
|
||
@Bean
|
||
public RefundService wxRefundService(Config certificateConfig) {
|
||
return new RefundService.Builder().config(certificateConfig).build();
|
||
}
|
||
|
||
@Bean
|
||
public Signer wxRsaSigner(Config certificateConfig){
|
||
return certificateConfig.createSigner();
|
||
}
|
||
|
||
}
|