办学质量监测教学评价系统
ageer
2025-04-20 9f257cf71242aee732409215fa7197483867b16d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package org.ruoyi.common.config;
 
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
 
import org.ruoyi.common.core.service.ConfigService;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
 
/**
 * @author Binary Wang
 */
@Configuration
@RequiredArgsConstructor
public class WxPayConfiguration {
 
    private final ConfigService configService;
 
    private WxPayService wxPayService;
 
    @PostConstruct
    public void init() {
        WxPayConfig payConfig = new WxPayConfig();
        payConfig.setAppId(StringUtils.trimToNull(getKey("appId")));
        payConfig.setMchId(StringUtils.trimToNull(getKey("mchId")));
        payConfig.setMchKey(StringUtils.trimToNull(getKey("appSecret")));
        payConfig.setUseSandboxEnv(false);
        wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(payConfig);
    }
 
    @Bean
    @ConditionalOnMissingBean
    public WxPayService wxService() {
        return wxPayService;
    }
 
    public String getKey(String key) {
        return configService.getConfigValue("weixin", key);
    }
 
}