feat:微信功能模块类功能实现

This commit is contained in:
2025-06-04 11:09:06 +08:00
parent 91dcb0b99e
commit 22fa478fef
5 changed files with 0 additions and 294 deletions
@@ -1,140 +0,0 @@
package com.central.order.config;
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.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.payments.jsapi.model.SettleInfo;
import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
import com.wechat.pay.java.service.refund.RefundService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* 支付配置类
*
* @author lsl
* @date 2025-01-14
*
*/
//@Getter
//@Setter
//@Configuration
//@ConfigurationProperties(prefix = "tencent")
//@EnableConfigurationProperties(ProfitSharingProperties.class)
public class TencentPayConfiguration {
private String merchantId;
private String merchantSerialNumber;
private String apiV3Key;
private String privateKeyPath;
private String appId;
private String appSecret;
private String notifyUrl;
/**
* jsapi支付方式 支持小程序公众号支付
* @return
*/
@Bean
public JsapiServiceExtension initialJsapiServiceExtension() {
// 构建service
return new JsapiServiceExtension.Builder().config(getConfig()).build();
}
@Bean
public RefundService initialRefundService() {
// 构建service
return new RefundService.Builder().config(getConfig()).build();
}
/**
* 微信支付配置获取
* @return
*/
public Config getConfig() {
return new RSAAutoCertificateConfig.Builder()
.merchantId(merchantId)
.privateKeyFromPath(privateKeyPath)
.merchantSerialNumber(merchantSerialNumber)
.apiV3Key(apiV3Key)
.build();
}
@Bean
public NotificationConfig initialNotificationConfig() {
// . 如果你仍在使用微信支付平台证书,则使用 RSAAutoCertificateConfig
return new RSAAutoCertificateConfig.Builder()
.merchantId(merchantId)
.privateKeyFromPath(privateKeyPath)
.merchantSerialNumber(merchantSerialNumber)
.apiV3Key(apiV3Key)
.build();
}
@Bean
public TencentPayProperties initTencentPayProperties() {
TencentPayProperties tencentPayProperties = new TencentPayProperties();
tencentPayProperties.setApiV3Key(apiV3Key);
tencentPayProperties.setMerchantId(merchantId);
tencentPayProperties.setMerchantSerialNumber(merchantSerialNumber);
tencentPayProperties.setAppId(appId);
tencentPayProperties.setAppSecret(appSecret);
tencentPayProperties.setNotifyUrl(notifyUrl);
return tencentPayProperties;
}
@Value("${wechat.pay.profit-sharing.enabled:true}")
private boolean profitSharingEnabled;
@Bean
public SettleInfo defaultSettleInfo() {
SettleInfo settleInfo = new SettleInfo();
settleInfo.setProfitSharing(profitSharingEnabled);
return settleInfo;
}
@Bean
public NotificationParser notificationParser(NotificationConfig config) {
return new NotificationParser(config);
}
@Bean
public ProfitsharingService profitsharingService() {
// 使用已有的配置方法
Config config = getConfig();
return new ProfitsharingService.Builder()
.config(config)
.build();
}
@Bean
public Executor profitSharingExecutor(@Qualifier("wechat.pay.profit-sharing-com.central.order.config.ProfitSharingProperties")
ProfitSharingProperties properties) {
if (!properties.isAsyncEnabled()) {
return null;
}
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(properties.getAsyncPoolSize());
executor.setMaxPoolSize(properties.getAsyncPoolSize());
executor.setQueueCapacity(100);
executor.setThreadNamePrefix("profit-sharing-");
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.initialize();
return executor;
}
}
@@ -1,25 +0,0 @@
package com.central.order.config;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class TencentPayProperties {
private String merchantId;
private String merchantSerialNumber;
private String apiV3Key;
private String privateKeyPath;
private String appId;
private String appSecret;
private String notifyUrl;
}
@@ -1,9 +0,0 @@
package com.central.order.config;
import lombok.Data;
@Data
public class WxMaProperties {
private String appId;
private String secret;
}
@@ -1,66 +0,0 @@
package com.central.order.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 com.fasterxml.jackson.databind.ObjectMapper;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;
import java.nio.charset.StandardCharsets;
//@Configuration
//@RequiredArgsConstructor
public class WxMpConfiguration {
@Bean
@ConfigurationProperties(prefix = "wx.mp")
public WxMpProperties wxMpProperties() {
return new WxMpProperties();
}
@Bean
public WxMpService wxMpService(WxMpProperties wxMpProperties) {
WxMpService service = new WxMpServiceImpl();
WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
config.setAppId(wxMpProperties.getAppId());
config.setSecret(wxMpProperties.getSecret());
service.setWxMpConfigStorage(config);
return service;
}
@Bean
public RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
return restTemplate;
}
@Bean
public ObjectMapper objectMapper() {
return new ObjectMapper();
}
@Bean
@ConfigurationProperties(prefix = "wx.mini")
public WxMaProperties wxMaProperties() {
return new WxMaProperties();
}
@Bean
public WxMaService wxMaService(WxMaProperties wxMaProperties) {
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setAppid(wxMaProperties.getAppId());
config.setSecret(wxMaProperties.getSecret());
WxMaService service = new WxMaServiceImpl();
service.setWxMaConfig(config);
return service;
}
}
@@ -1,54 +0,0 @@
package com.central.order.config;
import lombok.Data;
@Data
public class WxMpProperties {
/**
* 设置微信公众号的appid
*/
private String appId;
/**
* 设置微信公众号的app secret
*/
private String secret;
/**
* 设置云托管环境ID
*/
private String cloudEnv;
/**
* 设置服务基础URL
*/
private String baseUrl;
/**
* 模板ID配置
*/
private TemplateConfig templateId = new TemplateConfig();
@Data
public static class TemplateConfig {
/**
* 支付成功通知模板ID
* 模板内容:
* 服务名称:{{thing2.DATA}}
* 出行时间:{{time3.DATA}}
* 订单号:{{character_string1.DATA}}
* 支付金额:{{amount4.DATA}}
*/
private String paymentSuccess;
/**
* 视频处理完成通知模板ID
*/
private String videoComplete;
/**
* 视频处理失败通知模板ID
*/
private String videoFail;
}
}