2023-05-11 16:45:44 +08:00
|
|
|
|
package com.jsowell.adapay.config;
|
|
|
|
|
|
|
|
|
|
|
|
import com.huifu.adapay.Adapay;
|
|
|
|
|
|
import com.huifu.adapay.model.MerConfig;
|
2023-06-08 09:58:19 +08:00
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
2023-05-11 16:45:44 +08:00
|
|
|
|
import org.springframework.boot.CommandLineRunner;
|
|
|
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
|
|
@Order(value = 3)
|
|
|
|
|
|
@Component
|
|
|
|
|
|
public class AdapayConfig implements CommandLineRunner {
|
|
|
|
|
|
|
2023-06-08 09:58:19 +08:00
|
|
|
|
private Logger logger = LoggerFactory.getLogger(AdapayConfig.class);
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${adapay.apiKey}")
|
|
|
|
|
|
private String API_KEY;
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${adapay.mockApiKey}")
|
|
|
|
|
|
private String MOCK_API_KEY;
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${adapay.rsaPrivateKey}")
|
|
|
|
|
|
private String RSA_PRIVATE_KEY;
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${adapay.debugFlag}")
|
|
|
|
|
|
private boolean DEBUG_FLAG;
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${adapay.prodMode}")
|
|
|
|
|
|
private boolean PROD_MODE;
|
|
|
|
|
|
|
2023-05-11 16:45:44 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public void run(String... args) throws Exception {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* debug 模式,开启后有详细的日志
|
|
|
|
|
|
*/
|
2023-06-08 09:58:19 +08:00
|
|
|
|
Adapay.debug = DEBUG_FLAG;
|
2023-05-11 16:45:44 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* prodMode 模式,默认为生产模式,false可以使用mock模式
|
|
|
|
|
|
*/
|
2023-06-08 09:58:19 +08:00
|
|
|
|
Adapay.prodMode = PROD_MODE;
|
2023-05-11 16:45:44 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 初始化商户配置,服务器启动前,必须通过该方式初始化商户配置完成
|
|
|
|
|
|
* apiKey为prod模式的API KEY
|
|
|
|
|
|
* mockApiKey为mock模式的API KEY
|
|
|
|
|
|
* rsaPrivateKey为商户发起请求时,用于请求参数加签所需要的RSA私钥
|
|
|
|
|
|
*/
|
2023-06-08 09:58:19 +08:00
|
|
|
|
String apiKey = API_KEY;
|
|
|
|
|
|
String mockApiKey = MOCK_API_KEY;
|
|
|
|
|
|
String rsaPrivateKey = RSA_PRIVATE_KEY;
|
2023-05-11 16:45:44 +08:00
|
|
|
|
MerConfig merConfig = new MerConfig();
|
|
|
|
|
|
merConfig.setApiKey(apiKey);
|
|
|
|
|
|
merConfig.setApiMockKey(mockApiKey);
|
|
|
|
|
|
merConfig.setRSAPrivateKey(rsaPrivateKey);
|
|
|
|
|
|
Adapay.initWithMerConfig(merConfig);
|
2023-06-08 09:58:19 +08:00
|
|
|
|
logger.info("汇付配置初始化成功,debug:{}, prodMode:{}, apiKey:{}, mockApiKey:{}, rsaPrivateKey:{}"
|
|
|
|
|
|
, DEBUG_FLAG, PROD_MODE, API_KEY, MOCK_API_KEY, RSA_PRIVATE_KEY);
|
2023-05-11 16:45:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|