初步添加微信支付配置类
This commit is contained in:
@ -0,0 +1,25 @@
|
||||
package com.greenorange.promotion.config;
|
||||
|
||||
import org.springframework.amqp.support.converter.DefaultClassMapper;
|
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||
import org.springframework.amqp.support.converter.MessageConverter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class RabbitMQConfig {
|
||||
|
||||
@Bean
|
||||
public MessageConverter jsonToMapMessageConverter() {
|
||||
DefaultClassMapper defaultClassMapper = new DefaultClassMapper();
|
||||
defaultClassMapper.setTrustedPackages("com.greenorange.promotion.utils.MultiDelayMessage"); // trusted packages
|
||||
Jackson2JsonMessageConverter jackson2JsonMessageConverter = new Jackson2JsonMessageConverter();
|
||||
jackson2JsonMessageConverter.setClassMapper(defaultClassMapper);
|
||||
return jackson2JsonMessageConverter;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageConverter messageConverter(){
|
||||
return new Jackson2JsonMessageConverter();
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.greenorange.promotion.config;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
||||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Data
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "wx.mini")
|
||||
public class WxOpenConfig {
|
||||
|
||||
private String appId;
|
||||
|
||||
private String appSecret;
|
||||
|
||||
private WxMaService wxMaService;
|
||||
|
||||
/**
|
||||
* 单例模式
|
||||
*/
|
||||
public WxMaService getWxMaService() {
|
||||
if (wxMaService != null) {
|
||||
return wxMaService;
|
||||
}
|
||||
synchronized (this) {
|
||||
if (wxMaService != null) {
|
||||
return wxMaService;
|
||||
}
|
||||
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
|
||||
config.setAppid(appId);
|
||||
config.setSecret(appSecret);
|
||||
WxMaService service = new WxMaServiceImpl();
|
||||
service.setWxMaConfig(config);
|
||||
wxMaService = service;
|
||||
return wxMaService;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package com.greenorange.promotion.config;
|
||||
|
||||
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
||||
import com.wechat.pay.java.core.util.IOUtil;
|
||||
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||
import com.wechat.pay.java.service.refund.RefundService;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Data
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@Component("WxPayConfig")
|
||||
@ConfigurationProperties(prefix = "wx.pay")
|
||||
public class WxPayConfig {
|
||||
|
||||
private String appId;
|
||||
|
||||
private String apiV3Key;
|
||||
|
||||
private String notifyUrl;
|
||||
|
||||
private String merchantId;
|
||||
|
||||
private String privateKeyPath;
|
||||
|
||||
private String merchantSerialNumber;
|
||||
|
||||
// RSA配置
|
||||
private RSAAutoCertificateConfig RSAConfig;
|
||||
|
||||
// JSAPI支付
|
||||
private JsapiServiceExtension jsapiServiceExtension;
|
||||
|
||||
// 退款
|
||||
private RefundService refundService;
|
||||
|
||||
/**
|
||||
* 初始化配置
|
||||
*/
|
||||
@Bean
|
||||
public boolean initWxPayConfig() throws IOException {
|
||||
this.RSAConfig = buildRSAAutoCertificateConfig();
|
||||
this.jsapiServiceExtension = buildJsapiServiceExtension(RSAConfig);
|
||||
this.refundService = buildRefundService(RSAConfig);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 构建并使用自动更新平台证书的RSA配置,一个商户号只能初始化一个配置,否则会因为重复的下载任务报错
|
||||
private RSAAutoCertificateConfig buildRSAAutoCertificateConfig() throws IOException {
|
||||
// 将 resource 目录下的文件转为 InputStream,然后利用 IOUtil.toString(inputStream) 转化为密钥
|
||||
String privateKey = IOUtil.toString(new ClassPathResource(privateKeyPath).getInputStream());
|
||||
return new RSAAutoCertificateConfig.Builder()
|
||||
.merchantId(merchantId)
|
||||
.privateKey(privateKey)
|
||||
.merchantSerialNumber(merchantSerialNumber)
|
||||
.apiV3Key(apiV3Key)
|
||||
.build();
|
||||
}
|
||||
|
||||
// 构建JSAPI支付
|
||||
private JsapiServiceExtension buildJsapiServiceExtension(RSAAutoCertificateConfig config) {
|
||||
return new JsapiServiceExtension.Builder().config(config).build();
|
||||
}
|
||||
|
||||
// 构建退款
|
||||
private RefundService buildRefundService(RSAAutoCertificateConfig config) {
|
||||
return new RefundService.Builder().config(config).build();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user