fix:登录测试通过

This commit is contained in:
2025-06-03 10:43:31 +08:00
parent 1455923724
commit 57968ae2e8
20 changed files with 381 additions and 415 deletions
+2 -1
View File
@@ -111,7 +111,7 @@
<dependency> <dependency>
<groupId>com.github.binarywang</groupId> <groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-miniapp</artifactId> <artifactId>weixin-java-miniapp</artifactId>
<version>4.6.0</version> <version>4.5.0</version>
</dependency> </dependency>
<dependency> <dependency>
@@ -148,6 +148,7 @@
<dependency> <dependency>
<groupId>com.zlt</groupId> <groupId>com.zlt</groupId>
<artifactId>zlt-wechat-spring-boot-starter</artifactId> <artifactId>zlt-wechat-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>
@@ -55,4 +55,4 @@ public class ProfitSharingProperties {
*/ */
@Builder.Default @Builder.Default
private int asyncPoolSize = 5; private int asyncPoolSize = 5;
} }
@@ -1,145 +1,145 @@
package com.central.order.config; //package com.central.order.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.RSAAutoCertificateConfig;
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.service.payments.jsapi.JsapiServiceExtension; //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.payments.jsapi.model.SettleInfo;
import com.wechat.pay.java.service.profitsharing.ProfitsharingService; //import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
import com.wechat.pay.java.service.refund.RefundService; //import com.wechat.pay.java.service.refund.RefundService;
import lombok.Getter; //import lombok.Getter;
import lombok.Setter; //import lombok.Setter;
import org.springframework.beans.factory.annotation.Value; //import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties; //import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties; //import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; //import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; //import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; //import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.beans.factory.annotation.Qualifier; //import org.springframework.beans.factory.annotation.Qualifier;
//
import java.util.concurrent.Executor; //import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor; //import java.util.concurrent.ThreadPoolExecutor;
//
/** ///**
* 支付配置类 // * 支付配置类
* // *
* @author lsl // * @author lsl
* @date 2025-01-14 // * @date 2025-01-14
* // *
*/ // */
@Getter //@Getter
@Setter //@Setter
@Configuration //@Configuration
@ConfigurationProperties(prefix = "tencent") //@ConfigurationProperties(prefix = "tencent")
@EnableConfigurationProperties(ProfitSharingProperties.class) //@EnableConfigurationProperties(ProfitSharingProperties.class)
public class TencentPayConfiguration { //public class TencentPayConfiguration {
//
private String merchantId; // private String merchantId;
//
private String merchantSerialNumber; // private String merchantSerialNumber;
//
private String apiV3Key; // private String apiV3Key;
//
private String privateKeyPath; // private String privateKeyPath;
//
private String appId; // private String appId;
//
private String appSecret; // private String appSecret;
//
private String notifyUrl; // private String notifyUrl;
//
/** // /**
* jsapi支付方式 支持小程序公众号支付 // * jsapi支付方式 支持小程序公众号支付
* @return // * @return
*/ // */
@Bean // @Bean
public JsapiServiceExtension initialJsapiServiceExtension() { // public JsapiServiceExtension initialJsapiServiceExtension() {
// 构建service // // 构建service
return new JsapiServiceExtension.Builder().config(getConfig()).build(); // return new JsapiServiceExtension.Builder().config(getConfig()).build();
} // }
//
@Bean // @Bean
public RefundService initialRefundService() { // public RefundService initialRefundService() {
// 构建service // // 构建service
return new RefundService.Builder().config(getConfig()).build(); // return new RefundService.Builder().config(getConfig()).build();
} // }
//
/** // /**
* 微信支付配置获取 // * 微信支付配置获取
* @return // * @return
*/ // */
public Config getConfig() { // public Config getConfig() {
return new RSAAutoCertificateConfig.Builder() // return new RSAAutoCertificateConfig.Builder()
.merchantId(merchantId) // .merchantId(merchantId)
.privateKeyFromPath(privateKeyPath) // .privateKeyFromPath(privateKeyPath)
.merchantSerialNumber(merchantSerialNumber) // .merchantSerialNumber(merchantSerialNumber)
.apiV3Key(apiV3Key) // .apiV3Key(apiV3Key)
.build(); // .build();
} // }
//
//
@Bean // @Bean
public NotificationConfig initialNotificationConfig() { // public NotificationConfig initialNotificationConfig() {
// . 如果你仍在使用微信支付平台证书,则使用 RSAAutoCertificateConfig // // . 如果你仍在使用微信支付平台证书,则使用 RSAAutoCertificateConfig
return new RSAAutoCertificateConfig.Builder() // return new RSAAutoCertificateConfig.Builder()
.merchantId(merchantId) // .merchantId(merchantId)
.privateKeyFromPath(privateKeyPath) // .privateKeyFromPath(privateKeyPath)
.merchantSerialNumber(merchantSerialNumber) // .merchantSerialNumber(merchantSerialNumber)
.apiV3Key(apiV3Key) // .apiV3Key(apiV3Key)
.build(); // .build();
} // }
//
@Bean // @Bean
public TencentPayProperties initTencentPayProperties() { // public TencentPayProperties initTencentPayProperties() {
TencentPayProperties tencentPayProperties = new TencentPayProperties(); // TencentPayProperties tencentPayProperties = new TencentPayProperties();
tencentPayProperties.setApiV3Key(apiV3Key); // tencentPayProperties.setApiV3Key(apiV3Key);
tencentPayProperties.setMerchantId(merchantId); // tencentPayProperties.setMerchantId(merchantId);
tencentPayProperties.setMerchantSerialNumber(merchantSerialNumber); // tencentPayProperties.setMerchantSerialNumber(merchantSerialNumber);
tencentPayProperties.setAppId(appId); // tencentPayProperties.setAppId(appId);
tencentPayProperties.setAppSecret(appSecret); // tencentPayProperties.setAppSecret(appSecret);
tencentPayProperties.setNotifyUrl(notifyUrl); // tencentPayProperties.setNotifyUrl(notifyUrl);
return tencentPayProperties; // return tencentPayProperties;
} // }
//
@Value("${wechat.pay.profit-sharing.enabled:true}") // @Value("${wechat.pay.profit-sharing.enabled:true}")
private boolean profitSharingEnabled; // private boolean profitSharingEnabled;
//
@Bean // @Bean
public SettleInfo defaultSettleInfo() { // public SettleInfo defaultSettleInfo() {
SettleInfo settleInfo = new SettleInfo(); // SettleInfo settleInfo = new SettleInfo();
settleInfo.setProfitSharing(profitSharingEnabled); // settleInfo.setProfitSharing(profitSharingEnabled);
return settleInfo; // return settleInfo;
} // }
//
@Bean // @Bean
public NotificationParser notificationParser(NotificationConfig config) { // public NotificationParser notificationParser(NotificationConfig config) {
return new NotificationParser(config); // return new NotificationParser(config);
} // }
//
@Bean // @Bean
public ProfitsharingService profitsharingService() { // public ProfitsharingService profitsharingService() {
// 使用已有的配置方法 // // 使用已有的配置方法
Config config = getConfig(); // Config config = getConfig();
return new ProfitsharingService.Builder() // return new ProfitsharingService.Builder()
.config(config) // .config(config)
.build(); // .build();
} // }
//
@Bean // @Bean
public Executor profitSharingExecutor(@Qualifier("wechat.pay.profit-sharing-com.central.order.config.ProfitSharingProperties") // public Executor profitSharingExecutor(@Qualifier("wechat.pay.profit-sharing-com.central.order.config.ProfitSharingProperties")
ProfitSharingProperties properties) { // ProfitSharingProperties properties) {
if (!properties.isAsyncEnabled()) { // if (!properties.isAsyncEnabled()) {
return null; // return null;
} // }
//
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); // ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(properties.getAsyncPoolSize()); // executor.setCorePoolSize(properties.getAsyncPoolSize());
executor.setMaxPoolSize(properties.getAsyncPoolSize()); // executor.setMaxPoolSize(properties.getAsyncPoolSize());
executor.setQueueCapacity(100); // executor.setQueueCapacity(100);
executor.setThreadNamePrefix("profit-sharing-"); // executor.setThreadNamePrefix("profit-sharing-");
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.initialize(); // executor.initialize();
return executor; // return executor;
} // }
} //}
@@ -1,25 +1,25 @@
package com.central.order.config; //package com.central.order.config;
//
//
import lombok.Getter; //import lombok.Getter;
import lombok.Setter; //import lombok.Setter;
//
@Getter //@Getter
@Setter //@Setter
public class TencentPayProperties { //public class TencentPayProperties {
//
private String merchantId; // private String merchantId;
//
private String merchantSerialNumber; // private String merchantSerialNumber;
//
private String apiV3Key; // private String apiV3Key;
//
private String privateKeyPath; // private String privateKeyPath;
//
private String appId; // private String appId;
//
private String appSecret; // private String appSecret;
//
private String notifyUrl; // private String notifyUrl;
//
} //}
@@ -1,9 +1,9 @@
package com.central.order.config; //package com.central.order.config;
//
import lombok.Data; //import lombok.Data;
//
@Data //@Data
public class WxMaProperties { //public class WxMaProperties {
private String appId; // private String appId;
private String secret; // private String secret;
} //}
@@ -1,68 +1,68 @@
package com.central.order.config; //package com.central.order.config;
//
import cn.binarywang.wx.miniapp.api.WxMaService; //import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; //import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; //import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import com.fasterxml.jackson.databind.ObjectMapper; //import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor; //import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.mp.api.WxMpService; //import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; //import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; //import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.boot.context.properties.ConfigurationProperties; //import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean; //import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; //import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.StringHttpMessageConverter; //import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate; //import org.springframework.web.client.RestTemplate;
//
import java.nio.charset.StandardCharsets; //import java.nio.charset.StandardCharsets;
//
@Configuration //@Configuration
@RequiredArgsConstructor //@RequiredArgsConstructor
public class WxMpConfiguration { //public class WxMpConfiguration {
//
@Bean // @Bean
@ConfigurationProperties(prefix = "wx.mp") // @ConfigurationProperties(prefix = "wx.mp")
public WxMpProperties wxMpProperties() { // public WxMpProperties wxMpProperties() {
return new WxMpProperties(); // return new WxMpProperties();
} // }
//
@Bean // @Bean
public WxMpService wxMpService(WxMpProperties wxMpProperties) { // public WxMpService wxMpService(WxMpProperties wxMpProperties) {
WxMpService service = new WxMpServiceImpl(); // WxMpService service = new WxMpServiceImpl();
WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl(); // WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
//
config.setAppId(wxMpProperties.getAppId()); // config.setAppId(wxMpProperties.getAppId());
config.setSecret(wxMpProperties.getSecret()); // config.setSecret(wxMpProperties.getSecret());
//
service.setWxMpConfigStorage(config); // service.setWxMpConfigStorage(config);
return service; // return service;
} // }
//
@Bean // @Bean
public RestTemplate restTemplate() { // public RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplate(); // RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8)); // restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
return restTemplate; // return restTemplate;
} // }
//
@Bean // @Bean
public ObjectMapper objectMapper() { // public ObjectMapper objectMapper() {
return new ObjectMapper(); // return new ObjectMapper();
} // }
//
@Bean // @Bean
@ConfigurationProperties(prefix = "wx.mini") // @ConfigurationProperties(prefix = "wx.mini")
public WxMaProperties wxMaProperties() { // public WxMaProperties wxMaProperties() {
return new WxMaProperties(); // return new WxMaProperties();
} // }
//
@Bean // @Bean
public WxMaService wxMaService(WxMaProperties wxMaProperties) { // public WxMaService wxMaService(WxMaProperties wxMaProperties) {
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); // WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setAppid(wxMaProperties.getAppId()); // config.setAppid(wxMaProperties.getAppId());
config.setSecret(wxMaProperties.getSecret()); // config.setSecret(wxMaProperties.getSecret());
WxMaService service = new WxMaServiceImpl(); // WxMaService service = new WxMaServiceImpl();
service.setWxMaConfig(config); // service.setWxMaConfig(config);
return service; // return service;
} // }
} //}
@@ -1,54 +1,54 @@
package com.central.order.config; //package com.central.order.config;
//
import lombok.Data; //import lombok.Data;
//
@Data //@Data
public class WxMpProperties { //public class WxMpProperties {
/** // /**
* 设置微信公众号的appid // * 设置微信公众号的appid
*/ // */
private String appId; // private String appId;
//
/** // /**
* 设置微信公众号的app secret // * 设置微信公众号的app secret
*/ // */
private String secret; // private String secret;
//
/** // /**
* 设置云托管环境ID // * 设置云托管环境ID
*/ // */
private String cloudEnv; // private String cloudEnv;
//
/** // /**
* 设置服务基础URL // * 设置服务基础URL
*/ // */
private String baseUrl; // private String baseUrl;
//
/** // /**
* 模板ID配置 // * 模板ID配置
*/ // */
private TemplateConfig templateId = new TemplateConfig(); // private TemplateConfig templateId = new TemplateConfig();
//
@Data // @Data
public static class TemplateConfig { // public static class TemplateConfig {
/** // /**
* 支付成功通知模板ID // * 支付成功通知模板ID
* 模板内容: // * 模板内容:
* 服务名称:{{thing2.DATA}} // * 服务名称:{{thing2.DATA}}
* 出行时间:{{time3.DATA}} // * 出行时间:{{time3.DATA}}
* 订单号:{{character_string1.DATA}} // * 订单号:{{character_string1.DATA}}
* 支付金额:{{amount4.DATA}} // * 支付金额:{{amount4.DATA}}
*/ // */
private String paymentSuccess; // private String paymentSuccess;
//
/** // /**
* 视频处理完成通知模板ID // * 视频处理完成通知模板ID
*/ // */
private String videoComplete; // private String videoComplete;
//
/** // /**
* 视频处理失败通知模板ID // * 视频处理失败通知模板ID
*/ // */
private String videoFail; // private String videoFail;
} // }
} //}
@@ -8,7 +8,6 @@ import com.central.common.model.LoginAppUser;
import com.central.common.model.PageResult; import com.central.common.model.PageResult;
import com.central.common.model.Result; import com.central.common.model.Result;
import com.central.log.annotation.AuditLog; import com.central.log.annotation.AuditLog;
import com.central.order.config.TencentPayProperties;
import com.central.order.enums.CommonStatus; import com.central.order.enums.CommonStatus;
import com.central.order.enums.OrderStatus; import com.central.order.enums.OrderStatus;
import com.central.order.feign.DeviceCenterService; import com.central.order.feign.DeviceCenterService;
@@ -16,7 +15,6 @@ import com.central.order.feign.FileCenterService;
import com.central.order.feign.UserCenterService; import com.central.order.feign.UserCenterService;
import com.central.order.model.*; import com.central.order.model.*;
import com.central.order.service.*; import com.central.order.service.*;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse; import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
@@ -70,15 +68,9 @@ public class OrderController {
@Autowired @Autowired
private FileCenterService fileCenterService; private FileCenterService fileCenterService;
@Autowired
private JsapiServiceExtension service;
@Autowired @Autowired
private IQrCodeService qrCodeService; private IQrCodeService qrCodeService;
@Autowired
private TencentPayProperties tencentPayProperties;
@Value("${file.oss-url}") @Value("${file.oss-url}")
private String cdnOssUrl; private String cdnOssUrl;
@@ -16,6 +16,7 @@ import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.enums.ParameterIn;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@@ -27,7 +28,7 @@ import java.util.Map;
@RequestMapping("/refund") @RequestMapping("/refund")
public class RefundController { public class RefundController {
@Autowired @Qualifier
private RefundService service; private RefundService service;
@Autowired @Autowired
@@ -20,6 +20,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data; import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@@ -44,7 +45,7 @@ public class WxPayController {
@Autowired @Autowired
private IProfitSharingService profitSharingService; private IProfitSharingService profitSharingService;
@Autowired @Qualifier
private NotificationConfig config; private NotificationConfig config;
@PostMapping("/pay/notify") @PostMapping("/pay/notify")
@@ -27,8 +27,8 @@ public class WxTestController {
// 发送消息 // 发送消息
templateMessageService.sendPaymentSuccessNotice( // templateMessageService.sendPaymentSuccessNotice(
openId, orderNo, serviceName, rank); // openId, orderNo, serviceName, rank);
return Result.succeed("发送成功"); return Result.succeed("发送成功");
} catch (Exception e) { } catch (Exception e) {
@@ -6,7 +6,6 @@ import com.central.order.service.IWxTemplateMessageService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -18,7 +17,7 @@ import java.time.LocalDateTime;
@RequiredArgsConstructor @RequiredArgsConstructor
public class WxMessageHandler { public class WxMessageHandler {
private final WxMpService wxMpService; // private final WxMpService wxMpService;
private final IWxTemplateMessageService templateMessageService; private final IWxTemplateMessageService templateMessageService;
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage) { public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage) {
@@ -12,31 +12,26 @@ import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.payments.jsapi.model.*; import com.wechat.pay.java.service.payments.jsapi.model.*;
import com.zlt.wechat.config.WxPayConfigFactory; import com.zlt.wechat.config.WxPayConfigFactory;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Slf4j @Slf4j
@Service @Service
public class PaymentService { public class PaymentService {
private final WxPayConfigFactory wxPayConfigFactory; @Qualifier
private final UserCenterService userCenterService; private WxPayConfigFactory wxPayConfigFactory;
private final IOrderService orderService;
private final IQrCodeService qrCodeService;
private final IProfitSharingService profitSharingService;
private final WechatConfigService configService;
public PaymentService(WxPayConfigFactory wxPayConfigFactory, @Autowired
UserCenterService userCenterService, private UserCenterService userCenterService;
IOrderService orderService, @Autowired
IQrCodeService qrCodeService, private IOrderService orderService;
IProfitSharingService profitSharingService, @Autowired
WechatConfigService configService) { private IQrCodeService qrCodeService;
this.wxPayConfigFactory = wxPayConfigFactory; @Autowired
this.userCenterService = userCenterService; private IProfitSharingService profitSharingService;
this.orderService = orderService; @Autowired
this.qrCodeService = qrCodeService; private WechatConfigService configService;
this.profitSharingService = profitSharingService;
this.configService = configService;
}
public PrepayWithRequestPaymentResponse createPayment(Long orderId) { public PrepayWithRequestPaymentResponse createPayment(Long orderId) {
// 1. 获取用户和订单信息 // 1. 获取用户和订单信息
@@ -6,7 +6,6 @@ import com.central.common.exception.BusinessException;
import com.central.common.model.PageResult; import com.central.common.model.PageResult;
import com.central.common.service.impl.SuperServiceImpl; import com.central.common.service.impl.SuperServiceImpl;
import com.central.order.config.ProfitSharingProperties; import com.central.order.config.ProfitSharingProperties;
import com.central.order.config.TencentPayProperties;
import com.central.order.constants.ProfitSharingConstants; import com.central.order.constants.ProfitSharingConstants;
import com.central.order.enums.ProfitSharingStatusEnum; import com.central.order.enums.ProfitSharingStatusEnum;
import com.central.order.mapper.ProfitSharingMapper; import com.central.order.mapper.ProfitSharingMapper;
@@ -24,6 +23,7 @@ import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -43,10 +43,7 @@ import java.util.stream.Collectors;
@Service @Service
public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapper, ProfitSharing> implements IProfitSharingService { public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapper, ProfitSharing> implements IProfitSharingService {
@Autowired @Qualifier
private TencentPayProperties tencentPayProperties;
@Autowired
private ProfitsharingService profitsharingService; private ProfitsharingService profitsharingService;
@Autowired @Autowired
@@ -55,7 +52,7 @@ public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapp
@Autowired @Autowired
private ProfitSharingProperties profitSharingProperties; private ProfitSharingProperties profitSharingProperties;
@Autowired(required = false) @Qualifier
private Executor profitSharingExecutor; private Executor profitSharingExecutor;
@Value("${wechat.pay.platform-rate:0.30}") @Value("${wechat.pay.platform-rate:0.30}")
@@ -225,7 +222,8 @@ public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapp
// 2. 构建添加接收方请求 // 2. 构建添加接收方请求
AddReceiverRequest request = new AddReceiverRequest(); AddReceiverRequest request = new AddReceiverRequest();
request.setAppid(tencentPayProperties.getAppId()); //@TODO 动态获取appId
// request.setAppid(tencentPayProperties.getAppId());
// 设置接收方类型 // 设置接收方类型
try { try {
@@ -635,8 +633,8 @@ public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapp
// 1. 创建分账请求对象 // 1. 创建分账请求对象
CreateOrderRequest request = new CreateOrderRequest(); CreateOrderRequest request = new CreateOrderRequest();
// 2. 设置基本信息 // 2. 设置基本信息 //@TODO 动态获取appId
request.setAppid(tencentPayProperties.getAppId()); // request.setAppid(tencentPayProperties.getAppId());
request.setTransactionId(profitSharing.getTransactionId()); request.setTransactionId(profitSharing.getTransactionId());
request.setOutOrderNo(generateProfitSharingNo()); request.setOutOrderNo(generateProfitSharingNo());
@@ -8,6 +8,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.retry.annotation.Backoff; import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover; import org.springframework.retry.annotation.Recover;
@@ -23,7 +24,7 @@ import java.util.concurrent.TimeUnit;
@RequiredArgsConstructor @RequiredArgsConstructor
public class WxAccessTokenServiceImpl implements IWxAccessTokenService { public class WxAccessTokenServiceImpl implements IWxAccessTokenService {
@Autowired @Qualifier
private WxMpService wxMpService; private WxMpService wxMpService;
@Autowired @Autowired
private StringRedisTemplate redisTemplate; private StringRedisTemplate redisTemplate;
@@ -4,8 +4,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage; import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import com.central.order.service.WxMiniSubscribeService; import com.central.order.service.WxMiniSubscribeService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
@@ -16,13 +15,13 @@ import java.util.List;
@Service @Service
public class WxMiniSubscribeServiceImpl implements WxMiniSubscribeService { public class WxMiniSubscribeServiceImpl implements WxMiniSubscribeService {
@Value("${wx.mini.template.pay-success}") // @Value("${wx.mini.template.pay-success}")
private String templateId; // private String templateId;
//
// @Value("${wx.mini.template.service-process}")
// private String serviceProcessTemplateId;
@Value("${wx.mini.template.service-process}") @Qualifier
private String serviceProcessTemplateId;
@Autowired
private WxMaService wxMaService; private WxMaService wxMaService;
@Override @Override
@@ -30,7 +29,7 @@ public class WxMiniSubscribeServiceImpl implements WxMiniSubscribeService {
try { try {
WxMaSubscribeMessage msg = new WxMaSubscribeMessage(); WxMaSubscribeMessage msg = new WxMaSubscribeMessage();
msg.setToUser(openId); msg.setToUser(openId);
msg.setTemplateId(templateId); msg.setTemplateId("templateId");
msg.setPage("pages/task/task"); // 可选跳转页面 msg.setPage("pages/task/task"); // 可选跳转页面
List<WxMaSubscribeMessage.MsgData> dataList = new ArrayList<>(); List<WxMaSubscribeMessage.MsgData> dataList = new ArrayList<>();
@@ -63,7 +62,7 @@ public class WxMiniSubscribeServiceImpl implements WxMiniSubscribeService {
try { try {
WxMaSubscribeMessage msg = new WxMaSubscribeMessage(); WxMaSubscribeMessage msg = new WxMaSubscribeMessage();
msg.setToUser(openId); msg.setToUser(openId);
msg.setTemplateId(serviceProcessTemplateId); msg.setTemplateId("serviceProcessTemplateId");
msg.setPage(pageUrl); // 可选跳转页面 "pages/task/task" msg.setPage(pageUrl); // 可选跳转页面 "pages/task/task"
List<WxMaSubscribeMessage.MsgData> dataList = new ArrayList<>(); List<WxMaSubscribeMessage.MsgData> dataList = new ArrayList<>();
@@ -1,9 +1,6 @@
package com.central.order.service.impl; package com.central.order.service.impl;
import com.central.common.exception.BusinessException; import com.central.common.exception.BusinessException;
import com.central.order.config.TencentPayProperties;
import com.central.order.config.WxMpProperties;
import com.central.order.enums.CommonStatus;
import com.central.order.model.WxMessageRecord; import com.central.order.model.WxMessageRecord;
import com.central.order.service.IWxMessageRecordService; import com.central.order.service.IWxMessageRecordService;
import com.central.order.service.IWxTemplateMessageService; import com.central.order.service.IWxTemplateMessageService;
@@ -12,10 +9,10 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.retry.annotation.Backoff; import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover; import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable; import org.springframework.retry.annotation.Retryable;
@@ -25,23 +22,18 @@ import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Arrays;
@Slf4j @Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class WxTemplateMessageServiceImpl implements IWxTemplateMessageService { public class WxTemplateMessageServiceImpl implements IWxTemplateMessageService {
@Autowired @Qualifier
private WxMpService wxMpService; private WxMpService wxMpService;
@Autowired
private WxMpProperties wxMpProperties;
@Autowired @Autowired
private IWxUserService wxUserService; private IWxUserService wxUserService;
@Autowired
private TencentPayProperties tencentPayProperties;
@Autowired @Autowired
private IWxMessageRecordService wxMessageRecordService; private IWxMessageRecordService wxMessageRecordService;
@@ -57,41 +49,33 @@ public class WxTemplateMessageServiceImpl implements IWxTemplateMessageService {
throw new BusinessException("参数不能为空"); throw new BusinessException("参数不能为空");
} }
try { String openId = wxUserService.getMpOpenIdByUnionId(unionId);
String openId = wxUserService.getMpOpenIdByUnionId(unionId); log.info("获取到服务号openId={}", openId);
log.info("获取到服务号openId={}", openId); // 构建模板消息
// 构建模板消息 // WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder() // .toUser(openId)
.toUser(openId) //// .templateId(wxMpProperties.getTemplateId().getPaymentSuccess())
.templateId(wxMpProperties.getTemplateId().getPaymentSuccess()) // .data(Arrays.asList(
.data(Arrays.asList( // new WxMpTemplateData("thing2", tourismName+"提示: 您当前排在第"+rank+"位!"),
new WxMpTemplateData("thing2", tourismName+"提示: 您当前排在第"+rank+"位!"), // new WxMpTemplateData("time3", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))),
new WxMpTemplateData("time3", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))), // new WxMpTemplateData("character_string1", orderNo)
new WxMpTemplateData("character_string1", orderNo) //// new WxMpTemplateData("amount4", "19.90")
// new WxMpTemplateData("amount4", "19.90") // ))
)) // .miniProgram(new WxMpTemplateMessage.MiniProgram(
.miniProgram(new WxMpTemplateMessage.MiniProgram( // tencentPayProperties.getAppId(),
tencentPayProperties.getAppId(), // "pages/index/index",
"pages/index/index", // true))
true)) // .build();
.build();
// 发送消息并获取消息ID // 发送消息并获取消息ID
String msgId = wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage); // String msgId = wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
// 记录发送结果 // 记录发送结果
log.info("模板消息发送成功: openId={}, orderNo={}, msgId={}", openId, orderNo, msgId); // log.info("模板消息发送成功: openId={}, orderNo={}, msgId={}", openId, orderNo, msgId);
// 保存发送记录 // 保存发送记录
saveMessageRecord(openId, msgId, templateMessage,CommonStatus.ENABLE.getId());
} catch (WxErrorException e) {
log.error("发送模板消息失败: unionId={}, orderNo={}, errorCode={}, errorMsg={}",
unionId, orderNo, e.getError().getErrorCode(), e.getError().getErrorMsg());
// 保存发送记录 @TODO
// saveMessageRecord(openId, msgId, templateMessage,CommonStatus.ENABLE.getId()); // saveMessageRecord(openId, msgId, templateMessage,CommonStatus.ENABLE.getId());
throw new BusinessException("发送失败:" + e.getError().getErrorMsg());
}
} }
private String formatDateTime(LocalDateTime dateTime) { private String formatDateTime(LocalDateTime dateTime) {
@@ -7,7 +7,7 @@ import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxMpUserService; import me.chanjar.weixin.mp.api.WxMpUserService;
import me.chanjar.weixin.mp.bean.result.WxMpUser; import me.chanjar.weixin.mp.bean.result.WxMpUser;
import me.chanjar.weixin.mp.bean.result.WxMpUserList; import me.chanjar.weixin.mp.bean.result.WxMpUserList;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.retry.annotation.Backoff; import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover; import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable; import org.springframework.retry.annotation.Retryable;
@@ -17,7 +17,7 @@ import org.springframework.stereotype.Service;
@Service @Service
public class WxUserServiceImpl implements IWxUserService { public class WxUserServiceImpl implements IWxUserService {
@Autowired @Qualifier
private WxMpService wxMpService; private WxMpService wxMpService;
@Override @Override
@@ -25,10 +25,10 @@ public class WxUserServiceImpl implements IWxUserService {
public String getMpOpenIdByUnionId(String targetUnionId) { public String getMpOpenIdByUnionId(String targetUnionId) {
try { try {
log.info("开始查找 unionId: {} 对应的 openId", targetUnionId); log.info("开始查找 unionId: {} 对应的 openId", targetUnionId);
WxMpUserService userService = wxMpService.getUserService(); WxMpUserService userService = wxMpService.getUserService();
String nextOpenId = null; String nextOpenId = null;
do { do {
// 获取关注者列表 // 获取关注者列表
WxMpUserList userList = userService.userList(nextOpenId); WxMpUserList userList = userService.userList(nextOpenId);
@@ -36,7 +36,7 @@ public class WxUserServiceImpl implements IWxUserService {
log.warn("未找到关注用户"); log.warn("未找到关注用户");
break; break;
} }
// 批量获取用户信息 // 批量获取用户信息
for (String openId : userList.getOpenids()) { for (String openId : userList.getOpenids()) {
try { try {
@@ -50,23 +50,23 @@ public class WxUserServiceImpl implements IWxUserService {
continue; // 单个用户获取失败继续处理下一个 continue; // 单个用户获取失败继续处理下一个
} }
} }
nextOpenId = userList.getNextOpenid(); nextOpenId = userList.getNextOpenid();
} while (nextOpenId != null && !nextOpenId.isEmpty()); } while (nextOpenId != null && !nextOpenId.isEmpty());
log.warn("未找到 unionId: {} 对应的 openId", targetUnionId); log.warn("未找到 unionId: {} 对应的 openId", targetUnionId);
return null; return null;
} catch (WxErrorException e) { } catch (WxErrorException e) {
log.error("获取 MP openId 失败,unionId: {},错误: {}", targetUnionId, e.getMessage(), e); log.error("获取 MP openId 失败,unionId: {},错误: {}", targetUnionId, e.getMessage(), e);
throw new RuntimeException("获取 MP openId 失败", e); throw new RuntimeException("获取 MP openId 失败", e);
} }
} }
@Recover @Recover
public String recover(Exception e, String targetUnionId) { public String recover(Exception e, String targetUnionId) {
log.error("获取 MP openId 重试耗尽,unionId: {},最终错误: {}", targetUnionId, e.getMessage()); log.error("获取 MP openId 重试耗尽,unionId: {},最终错误: {}", targetUnionId, e.getMessage());
// 可以在这里添加告警通知 // 可以在这里添加告警通知
return null; return null;
} }
} }
@@ -4,7 +4,6 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import com.central.common.context.TenantContextHolder; import com.central.common.context.TenantContextHolder;
import com.central.wechat.wechat.config.WechatProperties;
import com.central.wechat.wechat.entity.WechatConfig; import com.central.wechat.wechat.entity.WechatConfig;
import com.central.wechat.wechat.feign.PrivateKeyService; import com.central.wechat.wechat.feign.PrivateKeyService;
import com.central.wechat.wechat.feign.WechatConfigService; import com.central.wechat.wechat.feign.WechatConfigService;
@@ -12,20 +11,16 @@ import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig; import com.wechat.pay.java.core.RSAAutoCertificateConfig;
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.service.payments.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.payments.jsapi.model.SettleInfo; import com.wechat.pay.java.service.payments.jsapi.model.SettleInfo;
import com.wechat.pay.java.service.profitsharing.ProfitsharingService; import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
import com.wechat.pay.java.service.refund.RefundService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@@ -33,7 +28,6 @@ import java.util.concurrent.ThreadPoolExecutor;
@Slf4j @Slf4j
@Configuration @Configuration
@EnableConfigurationProperties(WechatProperties.class)
public class WechatAutoConfiguration { public class WechatAutoConfiguration {
@Bean @Bean
@@ -82,7 +76,7 @@ public class WechatAutoConfiguration {
@Bean @Bean
public WxPayConfigFactory wxPayConfigFactory( public WxPayConfigFactory wxPayConfigFactory(
WechatConfigService configService, WechatConfigService configService,
PrivateKeyService privateKeyService) { PrivateKeyService privateKeyService) {
return new WxPayConfigFactory(configService, privateKeyService); return new WxPayConfigFactory(configService, privateKeyService);
} }
@@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
@@ -88,7 +89,7 @@ public class TencentAuthenticationProvider extends BaseAuthenticationProvider {
String openId = wxLoginResult.get("openid").toString(); String openId = wxLoginResult.get("openid").toString();
String sessionKey = wxLoginResult.get("session_key").toString(); String sessionKey = wxLoginResult.get("session_key").toString();
log.info("openId:{},sessionKey:{},res:{}", openId, sessionKey,wxLoginResult); log.info("openId:{},sessionKey:{},res:{}", openId, sessionKey,wxLoginResult);
String unionId = wxLoginResult.get("unionid").toString(); String unionId = MapUtils.getString(wxLoginResult, "unionid");
String mobile = decryptPhoneNumber(encryptedData,sessionKey,iv); String mobile = decryptPhoneNumber(encryptedData,sessionKey,iv);
userDetails = userDetailsServiceFactory.getService(authToken).loadUserByWxOpenId(openId,mobile, unionId); userDetails = userDetailsServiceFactory.getService(authToken).loadUserByWxOpenId(openId,mobile, unionId);