AdapayInit.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package com.ym.mec.thirdparty.adapay;
  2. import java.util.HashMap;
  3. import java.util.List;
  4. import java.util.Map;
  5. import com.huifu.adapay.Adapay;
  6. import com.huifu.adapay.model.MerConfig;
  7. import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
  8. import com.ym.mec.thirdparty.exception.ThirdpartyException;
  9. /**
  10. * 系统初始化
  11. */
  12. public class AdapayInit {
  13. /**
  14. * debug 模式,开启后与详细的日志
  15. */
  16. private boolean debug;
  17. /**
  18. * prodMode 模式,默认为生产模式,false可以使用mock模式
  19. */
  20. private boolean prodMode;
  21. private static AdapayInit init;
  22. private AdapayInit(boolean debug, boolean prodMode) {
  23. this.debug = debug;
  24. this.prodMode = prodMode;
  25. }
  26. public static AdapayInit getInstance(boolean debug, boolean prodMode) {
  27. if (init == null) {
  28. init = new AdapayInit(debug, prodMode);
  29. }
  30. return init;
  31. }
  32. public boolean initWithMerConfig(List<HfMerchantConfig> adapayMerConfigList) {
  33. Adapay.debug = debug;
  34. Adapay.prodMode = prodMode;
  35. Map<String, MerConfig> configPathMap = new HashMap<String, MerConfig>();
  36. for (HfMerchantConfig adapayMerConfig : adapayMerConfigList) {
  37. MerConfig merConfig = new MerConfig();
  38. merConfig.setApiKey(adapayMerConfig.getApiKey());
  39. merConfig.setApiMockKey(adapayMerConfig.getMockApiKey());
  40. merConfig.setRSAPrivateKey(adapayMerConfig.getRsaPrivateKey());
  41. configPathMap.put(adapayMerConfig.getMerKey(), merConfig);
  42. }
  43. try {
  44. Adapay.initWithMerConfigs(configPathMap);
  45. } catch (Exception e) {
  46. throw new ThirdpartyException("汇付商户配置初始化失败:{}", e, e.getMessage());
  47. }
  48. return true;
  49. }
  50. }