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>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-miniapp</artifactId>
<version>4.6.0</version>
<version>4.5.0</version>
</dependency>
<dependency>
@@ -148,6 +148,7 @@
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-wechat-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
@@ -55,4 +55,4 @@ public class ProfitSharingProperties {
*/
@Builder.Default
private int asyncPoolSize = 5;
}
}
@@ -1,145 +1,145 @@
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 lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.beans.factory.annotation.Qualifier;
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;
}
}
//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 lombok.Getter;
//import lombok.Setter;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.boot.context.properties.EnableConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
//import org.springframework.beans.factory.annotation.Qualifier;
//
//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 +1,25 @@
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;
}
//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 +1,9 @@
package com.central.order.config;
import lombok.Data;
@Data
public class WxMaProperties {
private String appId;
private String secret;
}
//package com.central.order.config;
//
//import lombok.Data;
//
//@Data
//public class WxMaProperties {
// private String appId;
// private String secret;
//}
@@ -1,68 +1,68 @@
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 lombok.RequiredArgsConstructor;
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.context.annotation.Configuration;
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;
}
}
//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 lombok.RequiredArgsConstructor;
//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.context.annotation.Configuration;
//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 +1,54 @@
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;
}
}
//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;
// }
//}
@@ -8,7 +8,6 @@ import com.central.common.model.LoginAppUser;
import com.central.common.model.PageResult;
import com.central.common.model.Result;
import com.central.log.annotation.AuditLog;
import com.central.order.config.TencentPayProperties;
import com.central.order.enums.CommonStatus;
import com.central.order.enums.OrderStatus;
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.model.*;
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 io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@@ -70,15 +68,9 @@ public class OrderController {
@Autowired
private FileCenterService fileCenterService;
@Autowired
private JsapiServiceExtension service;
@Autowired
private IQrCodeService qrCodeService;
@Autowired
private TencentPayProperties tencentPayProperties;
@Value("${file.oss-url}")
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.enums.ParameterIn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
@@ -27,7 +28,7 @@ import java.util.Map;
@RequestMapping("/refund")
public class RefundController {
@Autowired
@Qualifier
private RefundService service;
@Autowired
@@ -20,6 +20,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
@@ -44,7 +45,7 @@ public class WxPayController {
@Autowired
private IProfitSharingService profitSharingService;
@Autowired
@Qualifier
private NotificationConfig config;
@PostMapping("/pay/notify")
@@ -27,8 +27,8 @@ public class WxTestController {
// 发送消息
templateMessageService.sendPaymentSuccessNotice(
openId, orderNo, serviceName, rank);
// templateMessageService.sendPaymentSuccessNotice(
// openId, orderNo, serviceName, rank);
return Result.succeed("发送成功");
} catch (Exception e) {
@@ -6,7 +6,6 @@ import com.central.order.service.IWxTemplateMessageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;
@@ -18,7 +17,7 @@ import java.time.LocalDateTime;
@RequiredArgsConstructor
public class WxMessageHandler {
private final WxMpService wxMpService;
// private final WxMpService wxMpService;
private final IWxTemplateMessageService templateMessageService;
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.zlt.wechat.config.WxPayConfigFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class PaymentService {
private final WxPayConfigFactory wxPayConfigFactory;
private final UserCenterService userCenterService;
private final IOrderService orderService;
private final IQrCodeService qrCodeService;
private final IProfitSharingService profitSharingService;
private final WechatConfigService configService;
@Qualifier
private WxPayConfigFactory wxPayConfigFactory;
public PaymentService(WxPayConfigFactory wxPayConfigFactory,
UserCenterService userCenterService,
IOrderService orderService,
IQrCodeService qrCodeService,
IProfitSharingService profitSharingService,
WechatConfigService configService) {
this.wxPayConfigFactory = wxPayConfigFactory;
this.userCenterService = userCenterService;
this.orderService = orderService;
this.qrCodeService = qrCodeService;
this.profitSharingService = profitSharingService;
this.configService = configService;
}
@Autowired
private UserCenterService userCenterService;
@Autowired
private IOrderService orderService;
@Autowired
private IQrCodeService qrCodeService;
@Autowired
private IProfitSharingService profitSharingService;
@Autowired
private WechatConfigService configService;
public PrepayWithRequestPaymentResponse createPayment(Long orderId) {
// 1. 获取用户和订单信息
@@ -6,7 +6,6 @@ import com.central.common.exception.BusinessException;
import com.central.common.model.PageResult;
import com.central.common.service.impl.SuperServiceImpl;
import com.central.order.config.ProfitSharingProperties;
import com.central.order.config.TencentPayProperties;
import com.central.order.constants.ProfitSharingConstants;
import com.central.order.enums.ProfitSharingStatusEnum;
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.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
@@ -43,10 +43,7 @@ import java.util.stream.Collectors;
@Service
public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapper, ProfitSharing> implements IProfitSharingService {
@Autowired
private TencentPayProperties tencentPayProperties;
@Autowired
@Qualifier
private ProfitsharingService profitsharingService;
@Autowired
@@ -55,7 +52,7 @@ public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapp
@Autowired
private ProfitSharingProperties profitSharingProperties;
@Autowired(required = false)
@Qualifier
private Executor profitSharingExecutor;
@Value("${wechat.pay.platform-rate:0.30}")
@@ -225,7 +222,8 @@ public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapp
// 2. 构建添加接收方请求
AddReceiverRequest request = new AddReceiverRequest();
request.setAppid(tencentPayProperties.getAppId());
//@TODO 动态获取appId
// request.setAppid(tencentPayProperties.getAppId());
// 设置接收方类型
try {
@@ -635,8 +633,8 @@ public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapp
// 1. 创建分账请求对象
CreateOrderRequest request = new CreateOrderRequest();
// 2. 设置基本信息
request.setAppid(tencentPayProperties.getAppId());
// 2. 设置基本信息 //@TODO 动态获取appId
// request.setAppid(tencentPayProperties.getAppId());
request.setTransactionId(profitSharing.getTransactionId());
request.setOutOrderNo(generateProfitSharingNo());
@@ -8,6 +8,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
@@ -23,7 +24,7 @@ import java.util.concurrent.TimeUnit;
@RequiredArgsConstructor
public class WxAccessTokenServiceImpl implements IWxAccessTokenService {
@Autowired
@Qualifier
private WxMpService wxMpService;
@Autowired
private StringRedisTemplate redisTemplate;
@@ -4,8 +4,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import com.central.order.service.WxMiniSubscribeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@@ -16,13 +15,13 @@ import java.util.List;
@Service
public class WxMiniSubscribeServiceImpl implements WxMiniSubscribeService {
@Value("${wx.mini.template.pay-success}")
private String templateId;
// @Value("${wx.mini.template.pay-success}")
// private String templateId;
//
// @Value("${wx.mini.template.service-process}")
// private String serviceProcessTemplateId;
@Value("${wx.mini.template.service-process}")
private String serviceProcessTemplateId;
@Autowired
@Qualifier
private WxMaService wxMaService;
@Override
@@ -30,7 +29,7 @@ public class WxMiniSubscribeServiceImpl implements WxMiniSubscribeService {
try {
WxMaSubscribeMessage msg = new WxMaSubscribeMessage();
msg.setToUser(openId);
msg.setTemplateId(templateId);
msg.setTemplateId("templateId");
msg.setPage("pages/task/task"); // 可选跳转页面
List<WxMaSubscribeMessage.MsgData> dataList = new ArrayList<>();
@@ -63,7 +62,7 @@ public class WxMiniSubscribeServiceImpl implements WxMiniSubscribeService {
try {
WxMaSubscribeMessage msg = new WxMaSubscribeMessage();
msg.setToUser(openId);
msg.setTemplateId(serviceProcessTemplateId);
msg.setTemplateId("serviceProcessTemplateId");
msg.setPage(pageUrl); // 可选跳转页面 "pages/task/task"
List<WxMaSubscribeMessage.MsgData> dataList = new ArrayList<>();
@@ -1,9 +1,6 @@
package com.central.order.service.impl;
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.service.IWxMessageRecordService;
import com.central.order.service.IWxTemplateMessageService;
@@ -12,10 +9,10 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.apache.commons.lang3.StringUtils;
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.Recover;
import org.springframework.retry.annotation.Retryable;
@@ -25,23 +22,18 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
@Slf4j
@Service
@RequiredArgsConstructor
public class WxTemplateMessageServiceImpl implements IWxTemplateMessageService {
@Autowired
@Qualifier
private WxMpService wxMpService;
@Autowired
private WxMpProperties wxMpProperties;
@Autowired
private IWxUserService wxUserService;
@Autowired
private TencentPayProperties tencentPayProperties;
@Autowired
private IWxMessageRecordService wxMessageRecordService;
@@ -57,41 +49,33 @@ public class WxTemplateMessageServiceImpl implements IWxTemplateMessageService {
throw new BusinessException("参数不能为空");
}
try {
String openId = wxUserService.getMpOpenIdByUnionId(unionId);
log.info("获取到服务号openId={}", openId);
// 构建模板消息
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
.toUser(openId)
.templateId(wxMpProperties.getTemplateId().getPaymentSuccess())
.data(Arrays.asList(
new WxMpTemplateData("thing2", tourismName+"提示: 您当前排在第"+rank+"位!"),
new WxMpTemplateData("time3", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))),
new WxMpTemplateData("character_string1", orderNo)
// new WxMpTemplateData("amount4", "19.90")
))
.miniProgram(new WxMpTemplateMessage.MiniProgram(
tencentPayProperties.getAppId(),
"pages/index/index",
true))
.build();
String openId = wxUserService.getMpOpenIdByUnionId(unionId);
log.info("获取到服务号openId={}", openId);
// 构建模板消息
// WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
// .toUser(openId)
//// .templateId(wxMpProperties.getTemplateId().getPaymentSuccess())
// .data(Arrays.asList(
// new WxMpTemplateData("thing2", tourismName+"提示: 您当前排在第"+rank+"位!"),
// new WxMpTemplateData("time3", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))),
// new WxMpTemplateData("character_string1", orderNo)
//// new WxMpTemplateData("amount4", "19.90")
// ))
// .miniProgram(new WxMpTemplateMessage.MiniProgram(
// tencentPayProperties.getAppId(),
// "pages/index/index",
// true))
// .build();
// 发送消息并获取消息ID
String msgId = wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
// 发送消息并获取消息ID
// 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());
throw new BusinessException("发送失败:" + e.getError().getErrorMsg());
}
}
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.bean.result.WxMpUser;
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.Recover;
import org.springframework.retry.annotation.Retryable;
@@ -17,7 +17,7 @@ import org.springframework.stereotype.Service;
@Service
public class WxUserServiceImpl implements IWxUserService {
@Autowired
@Qualifier
private WxMpService wxMpService;
@Override
@@ -25,10 +25,10 @@ public class WxUserServiceImpl implements IWxUserService {
public String getMpOpenIdByUnionId(String targetUnionId) {
try {
log.info("开始查找 unionId: {} 对应的 openId", targetUnionId);
WxMpUserService userService = wxMpService.getUserService();
String nextOpenId = null;
do {
// 获取关注者列表
WxMpUserList userList = userService.userList(nextOpenId);
@@ -36,7 +36,7 @@ public class WxUserServiceImpl implements IWxUserService {
log.warn("未找到关注用户");
break;
}
// 批量获取用户信息
for (String openId : userList.getOpenids()) {
try {
@@ -50,23 +50,23 @@ public class WxUserServiceImpl implements IWxUserService {
continue; // 单个用户获取失败继续处理下一个
}
}
nextOpenId = userList.getNextOpenid();
} while (nextOpenId != null && !nextOpenId.isEmpty());
log.warn("未找到 unionId: {} 对应的 openId", targetUnionId);
return null;
} catch (WxErrorException e) {
log.error("获取 MP openId 失败,unionId: {},错误: {}", targetUnionId, e.getMessage(), e);
throw new RuntimeException("获取 MP openId 失败", e);
}
}
@Recover
public String recover(Exception e, String targetUnionId) {
log.error("获取 MP openId 重试耗尽,unionId: {},最终错误: {}", targetUnionId, e.getMessage());
// 可以在这里添加告警通知
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.config.impl.WxMaDefaultConfigImpl;
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.feign.PrivateKeyService;
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.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 lombok.extern.slf4j.Slf4j;
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.autoconfigure.condition.ConditionalOnBean;
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.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
@@ -33,7 +28,6 @@ import java.util.concurrent.ThreadPoolExecutor;
@Slf4j
@Configuration
@EnableConfigurationProperties(WechatProperties.class)
public class WechatAutoConfiguration {
@Bean
@@ -82,7 +76,7 @@ public class WechatAutoConfiguration {
@Bean
public WxPayConfigFactory wxPayConfigFactory(
WechatConfigService configService,
WechatConfigService configService,
PrivateKeyService privateKeyService) {
return new WxPayConfigFactory(configService, privateKeyService);
}
@@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
@@ -88,7 +89,7 @@ public class TencentAuthenticationProvider extends BaseAuthenticationProvider {
String openId = wxLoginResult.get("openid").toString();
String sessionKey = wxLoginResult.get("session_key").toString();
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);
userDetails = userDetailsServiceFactory.getService(authToken).loadUserByWxOpenId(openId,mobile, unionId);