fix: 微信支付,登录接口。
This commit is contained in:
@@ -4,6 +4,7 @@ import com.github.binarywang.wxpay.config.WxPayConfig;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -13,27 +14,55 @@ import org.springframework.context.annotation.Configuration;
|
||||
*
|
||||
* @author intc
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnProperty(prefix = "wx.pay", name = "mch-id")
|
||||
public class WxPayConfiguration {
|
||||
|
||||
private final WxPayProperties wxPayProperties;
|
||||
private final WxMaProperties wxMaProperties;
|
||||
|
||||
@Bean
|
||||
public WxPayService wxPayService() {
|
||||
WxPayConfig config = new WxPayConfig();
|
||||
config.setMchId(wxPayProperties.getMchId());
|
||||
config.setMchKey(wxPayProperties.getMchKey());
|
||||
config.setKeyPath(wxPayProperties.getKeyPath());
|
||||
config.setApiV3Key(wxPayProperties.getApiV3Key());
|
||||
config.setCertSerialNo(wxPayProperties.getCertSerialNo());
|
||||
config.setPrivateKeyPath(wxPayProperties.getPrivateKeyPath());
|
||||
config.setPrivateCertPath(wxPayProperties.getPrivateContent());
|
||||
WxPayConfig payConfig = new WxPayConfig();
|
||||
|
||||
WxPayService service = new WxPayServiceImpl();
|
||||
service.setConfig(config);
|
||||
return service;
|
||||
// 基础配置
|
||||
payConfig.setAppId(wxMaProperties.getAppId());
|
||||
payConfig.setMchId(wxPayProperties.getMchId());
|
||||
|
||||
// V2配置
|
||||
if (wxPayProperties.getMchKey() != null) {
|
||||
payConfig.setMchKey(wxPayProperties.getMchKey());
|
||||
}
|
||||
|
||||
// V3配置
|
||||
if (wxPayProperties.getApiV3Key() != null) {
|
||||
payConfig.setApiV3Key(wxPayProperties.getApiV3Key());
|
||||
}
|
||||
|
||||
if (wxPayProperties.getCertSerialNo() != null) {
|
||||
payConfig.setCertSerialNo(wxPayProperties.getCertSerialNo());
|
||||
}
|
||||
|
||||
// 证书配置
|
||||
if (wxPayProperties.getKeyPath() != null) {
|
||||
payConfig.setKeyPath(wxPayProperties.getKeyPath());
|
||||
}
|
||||
|
||||
if (wxPayProperties.getPrivateKeyPath() != null) {
|
||||
payConfig.setPrivateKeyPath(wxPayProperties.getPrivateKeyPath());
|
||||
}
|
||||
|
||||
if (wxPayProperties.getPrivateContent() != null) {
|
||||
payConfig.setPrivateCertContent(wxPayProperties.getPrivateContent().getBytes());
|
||||
}
|
||||
|
||||
WxPayService wxPayService = new WxPayServiceImpl();
|
||||
wxPayService.setConfig(payConfig);
|
||||
|
||||
log.info("微信支付服务初始化完成,商户号: {}", wxPayProperties.getMchId());
|
||||
|
||||
return wxPayService;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.intc.weixin.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 微信支付套餐配置
|
||||
*
|
||||
* @author intc
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "wx.pay-item")
|
||||
public class WxPayItemProperties {
|
||||
|
||||
/**
|
||||
* 支付选项列表
|
||||
*/
|
||||
private List<PayItem> payItems = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 根据ID获取支付选项
|
||||
*
|
||||
* @param id 支付选项ID
|
||||
* @return 支付选项
|
||||
*/
|
||||
public PayItem getPayItemById(Integer id) {
|
||||
if (payItems == null || id == null) {
|
||||
return null;
|
||||
}
|
||||
return payItems.stream()
|
||||
.filter(item -> id.equals(item.getId()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付选项
|
||||
*/
|
||||
@Data
|
||||
public static class PayItem {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 金额,单位:分
|
||||
*/
|
||||
private Integer amount;
|
||||
|
||||
/**
|
||||
* 增加月份
|
||||
*/
|
||||
private Integer addMonth;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.intc.weixin.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 微信支付通知配置
|
||||
*
|
||||
* @author intc
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "wx.pay-notify")
|
||||
public class WxPayNotifyProperties {
|
||||
|
||||
/**
|
||||
* 支付回调通知URL
|
||||
*/
|
||||
private String notifyUrl;
|
||||
|
||||
/**
|
||||
* 微信商户号
|
||||
*/
|
||||
private String mchId;
|
||||
}
|
||||
@@ -20,17 +20,17 @@ public class WxPayProperties {
|
||||
private String mchId;
|
||||
|
||||
/**
|
||||
* 商户密钥
|
||||
* 商户密钥(V2版本)
|
||||
*/
|
||||
private String mchKey;
|
||||
|
||||
/**
|
||||
* apiclient_cert.p12文件的绝对路径或者以classpath:开头的类路径
|
||||
* 证书路径
|
||||
*/
|
||||
private String keyPath;
|
||||
|
||||
/**
|
||||
* apiV3秘钥
|
||||
* APIv3秘钥
|
||||
*/
|
||||
private String apiV3Key;
|
||||
|
||||
@@ -48,5 +48,4 @@ public class WxPayProperties {
|
||||
* 私钥内容
|
||||
*/
|
||||
private String privateContent;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user