初步添加微信支付配置类

This commit is contained in:
2025-06-30 19:00:19 +08:00
parent 8d766edec3
commit 6c248d1da3
12 changed files with 251 additions and 5 deletions

View File

@ -214,6 +214,11 @@
<version>2.6.9</version>
</dependency>
<!-- rabbitmq依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>

View File

@ -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();
}
}

View File

@ -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;
}
}
}

View File

@ -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();
}
}

View File

@ -56,9 +56,6 @@ public class CourseController {
@Resource
private CommonService commonService;
@Resource
private WechatGetQrcodeService wechatGetQrcodeService;
/**
* 小程序端用户查看热门课程列表

View File

@ -0,0 +1,17 @@
package com.greenorange.promotion.controller.wechat;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@Tag(name = "微信支付")
@RequestMapping("/wxPay")
public class WechatPayController {
}

View File

@ -26,7 +26,6 @@ import java.util.Map;
public class WechatPayoutsController {
/**
* 微信小程序积分提现到银行卡
*/

View File

@ -37,7 +37,6 @@ public class UserInfoVO implements Serializable {
@Schema(description = "手机号", example = "15888610253")
private String phoneNumber;
/**
* 账号
*/

View File

@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.greenorange.promotion.common.ErrorCode;
import com.greenorange.promotion.config.WxOpenConfig;
import com.greenorange.promotion.constant.CommonConstant;
import com.greenorange.promotion.constant.SystemConstant;
import com.greenorange.promotion.constant.UserConstant;
@ -95,6 +96,8 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
/**
* 获取查询条件
*/

View File

@ -0,0 +1,7 @@
package com.greenorange.promotion.service.wechat;
/**
* @author 陈新知
*/
public interface WechatPayService {
}

View File

@ -0,0 +1,13 @@
package com.greenorange.promotion.service.wechat.impl;
import com.greenorange.promotion.service.wechat.WechatPayService;
import org.springframework.stereotype.Service;
/**
* @author 陈新知
*/
@Service
public class WechatPayServiceImpl implements WechatPayService {
}

View File

@ -0,0 +1,59 @@
package com.greenorange.promotion.utils;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Data
@NoArgsConstructor
public class MultiDelayMessage<T> implements Serializable {
/**
* 消息体
*/
private T data;
/**
* 记录延时时间的集合
*/
private List<Long> delayMillis;
public MultiDelayMessage(T data, List<Long> delayMillis) {
this.data = data;
this.delayMillis = delayMillis;
}
public MultiDelayMessage(T data, Long...delayMillis) {
this.data = data;
this.delayMillis = new ArrayList<>(Arrays.asList(delayMillis));
}
/**
* 获取并移除下一个延迟时间
* @return 集合中第一个延迟时间
*/
public Long removeNextDelay() {
return delayMillis.remove(0);
}
/**
* 是否有下一个延迟时间
*/
public boolean hasNextDelay() {
return !delayMillis.isEmpty();
}
@Serial
private static final long serialVersionUID = 1L;
}