package com.ruoyi.admin.config;
|
|
import javax.annotation.PostConstruct;
|
|
import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner;
|
import com.wechat.pay.java.service.refund.RefundService;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Primary;
|
|
import com.wechat.pay.java.core.Config;
|
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
import com.wechat.pay.java.core.notification.NotificationConfig;
|
import com.wechat.pay.java.core.notification.NotificationParser;
|
import com.wechat.pay.java.service.payments.h5.H5Service;
|
import com.wechat.pay.java.service.payments.jsapi.JsapiService;
|
import com.wechat.pay.java.service.payments.nativepay.NativePayService;
|
|
import lombok.Getter;
|
|
import java.security.PrivateKey;
|
|
/**
|
* @desc: 微信config
|
* @author: shy
|
* @date: 2024/4/9 10:06
|
*/
|
@Configuration
|
@Getter
|
public class WeChatConfig {
|
|
/**
|
* 商户号
|
*/
|
@Value("${wx.mchId}")
|
public String merchantId;
|
/**
|
* 商户API私钥路径
|
*/
|
@Value("${wx.privateKeyPath}")
|
public String privateKeyPath;
|
/**
|
* 商户证书序列号
|
*/
|
@Value("${wx.merchantSerialNumber}")
|
public String merchantSerialNumber;
|
/**
|
* 商户APIV3密钥
|
*/
|
@Value("${wx.apiV3Key}")
|
public String apiV3Key;
|
/**
|
* AppId
|
*/
|
@Value("${wx.appId}")
|
public String appId;
|
|
private Config config;
|
|
@Getter
|
private PrivateKey privateKey;
|
|
|
@PostConstruct
|
public void initConfig() {
|
// 使用自动更新平台证书的RSA配置
|
// 一个商户号只能初始化一个配置,否则会因为重复的下载任务报错
|
config = new RSAAutoCertificateConfig.Builder()
|
.merchantId(merchantId)
|
.privateKeyFromPath(privateKeyPath)
|
.merchantSerialNumber(merchantSerialNumber)
|
.apiV3Key(apiV3Key)
|
.build();
|
}
|
|
@Primary
|
@Bean()
|
public H5Service h5Service() {
|
return new H5Service.Builder()
|
.config(config)
|
.build();
|
}
|
|
@Primary
|
@Bean()
|
public JsapiService jsapiService() {
|
return new JsapiService.Builder()
|
.config(config)
|
.build();
|
}
|
|
@Primary
|
@Bean()
|
public NativePayService nativePayService() {
|
return new NativePayService.Builder()
|
.config(config)
|
.build();
|
}
|
@Primary
|
@Bean()
|
public RefundService refundService() {
|
return new RefundService.Builder()
|
.config(config)
|
.build();
|
}
|
|
@Primary
|
@Bean
|
public NotificationParser notificationParser() {
|
return new NotificationParser((NotificationConfig) config);
|
}
|
|
@Primary
|
@Bean
|
public PrivateKeySigner privateKeySigner() {
|
return new PrivateKeySigner(merchantSerialNumber, privateKey);
|
}
|
|
|
}
|