xiaoyong931011
2023-05-12 aba1e755f98bc6c89caabe590850161b903db420
支付设置
1 files added
3 files modified
58 ■■■■■ changed files
src/main/java/cc/mrbird/febs/pay/configure/WxPayConfiguration.java 42 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/pay/controller/PayCallBackController.java 4 ●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/pay/service/impl/WxPayServiceImpl.java 4 ●●● patch | view | raw | blame | history
src/main/resources/application-dev.yml 8 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/pay/configure/WxPayConfiguration.java
New file
@@ -0,0 +1,42 @@
package cc.mrbird.febs.pay.configure;
import cc.mrbird.febs.pay.properties.WxPayProperties;
import cn.hutool.core.util.StrUtil;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
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;
/**
 * @author wzy
 * @date 2023-04-07
 **/
@Configuration
@ConditionalOnClass(WxPayService.class)
@EnableConfigurationProperties(WxPayProperties.class)
@AllArgsConstructor
public class WxPayConfiguration {
    private WxPayProperties properties;
    @Bean
    @ConditionalOnMissingBean
    public WxPayService wxService() {
        WxPayConfig payConfig = new WxPayConfig();
        payConfig.setAppId(StrUtil.trim(this.properties.getAppId()));
        payConfig.setMchId(StrUtil.trim(this.properties.getMchId()));
        payConfig.setMchKey(StrUtil.trim(this.properties.getMchKey()));
        payConfig.setKeyPath(StrUtil.trim(this.properties.getKeyPath()));
        // 可以指定是否使用沙箱环境
        payConfig.setUseSandboxEnv(false);
        WxPayService wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(payConfig);
        return wxPayService;
    }
}
src/main/java/cc/mrbird/febs/pay/controller/PayCallBackController.java
@@ -36,7 +36,9 @@
    @Resource
    private AliPayProperties aliPayProperties;
    private WxPayService wxPayService = new com.github.binarywang.wxpay.service.impl.WxPayServiceImpl();
    @Autowired
    private WxPayService wxPayService;
//    private WxPayService wxPayService = new com.github.binarywang.wxpay.service.impl.WxPayServiceImpl();
    @Autowired
    private IPayService wechatPayService;
src/main/java/cc/mrbird/febs/pay/service/impl/WxPayServiceImpl.java
@@ -53,7 +53,9 @@
    @Autowired
    private MallOrderInfoMapper orderInfoMapper;
    private WxPayService wxPayService = new com.github.binarywang.wxpay.service.impl.WxPayServiceImpl();
    @Autowired
    private WxPayService wxPayService;
//    private WxPayService wxPayService = new com.github.binarywang.wxpay.service.impl.WxPayServiceImpl();
    @Autowired
    private WxPayProperties wxPayProperties;
src/main/resources/application-dev.yml
@@ -62,3 +62,11 @@
    # 回调地址
    noticeUrl: http://120.27.238.55:8801/api/pay/aliCallBack
    domain: https://openapi.alipaydev.com/gateway.do
  wx:
    appId: wxdf3340fe7591375d
    mchId: 1644265360
    mchKey: wqri51aCfiG31o4IcdX3dW12qnX3u4hp
    keyPath: classpath:cert/apiclient_cert.p12
    noticeUrl: https://gzypapi.meiao.biz/api/pay/wxPayCallBack