mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
多商户配置
This commit is contained in:
@@ -2,6 +2,7 @@ package com.jsowell.adapay.config;
|
||||
|
||||
import com.huifu.adapay.Adapay;
|
||||
import com.huifu.adapay.model.MerConfig;
|
||||
import com.jsowell.adapay.factory.AdapayConfigFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -9,11 +10,15 @@ import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Order(value = 3)
|
||||
@Component
|
||||
public class AdapayConfig implements CommandLineRunner {
|
||||
public class InitializeAdapayConfig implements CommandLineRunner {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(AdapayConfig.class);
|
||||
private Logger logger = LoggerFactory.getLogger(InitializeAdapayConfig.class);
|
||||
|
||||
@Value("${adapay.debugFlag}")
|
||||
private boolean DEBUG_FLAG;
|
||||
@@ -32,6 +37,22 @@ public class AdapayConfig implements CommandLineRunner {
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
/*
|
||||
单商户
|
||||
*/
|
||||
singleMerchant();
|
||||
|
||||
/*
|
||||
多商户
|
||||
目前有jsowell和xixiao
|
||||
*/
|
||||
// multiMerchant();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单商户配置
|
||||
*/
|
||||
public void singleMerchant() throws Exception {
|
||||
/**
|
||||
* debug 模式,开启后有详细的日志
|
||||
*/
|
||||
@@ -59,4 +80,43 @@ public class AdapayConfig implements CommandLineRunner {
|
||||
logger.info("汇付配置初始化成功,debug:{}, prodMode:{}, apiKey:{}, mockApiKey:{}, rsaPrivateKey:{}"
|
||||
, DEBUG_FLAG, PROD_MODE, JSOWELL_API_KEY, JSOWELL_MOCK_API_KEY, JSOWELL_RSA_PRIVATE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 多商户配置
|
||||
* @throws Exception
|
||||
*/
|
||||
public void multiMerchant() throws Exception {
|
||||
/**
|
||||
* debug 模式,开启后与详细的日志
|
||||
*/
|
||||
Adapay.debug = true;
|
||||
|
||||
/**
|
||||
* prodMode 模式,默认为生产模式,false可以使用mock模式
|
||||
*/
|
||||
Adapay.prodMode = true;
|
||||
|
||||
/**
|
||||
* 初始化每个商户配置,服务器启动前,必须通过该方式初始化商户配置完成
|
||||
* apiKey为prod模式的API KEY
|
||||
* mockApiKey为mock模式的API KEY
|
||||
* rsaPrivateKey为商户发起请求时,用于请求参数加签所需要的RSA私钥
|
||||
*/
|
||||
Map<String, MerConfig> configPathMap = new HashMap<>();
|
||||
List<AbstractAdapayConfig> allConfig = AdapayConfigFactory.getAllConfig();
|
||||
for (AbstractAdapayConfig config : allConfig) {
|
||||
String apiKey = config.getApiKey();
|
||||
String mockApiKey = config.getMockApiKey();
|
||||
String rsaPrivateKey = config.getRsaPrivateKey();
|
||||
MerConfig merConfig = new MerConfig();
|
||||
merConfig.setApiKey(apiKey);
|
||||
merConfig.setApiMockKey(mockApiKey);
|
||||
merConfig.setRSAPrivateKey(rsaPrivateKey);
|
||||
// 定义一个商户的B的唯一标识,交易发起时,用于定位是哪个商户发起交易
|
||||
configPathMap.put(config.getWechatAppId(), merConfig);
|
||||
}
|
||||
|
||||
// 将商户A和B的商户配置放入本地缓存
|
||||
Adapay.initWithMerConfigs(configPathMap);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user