BasePay.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Collections.Generic;
  3. namespace BasePaySdk
  4. {
  5. public class BasePay{
  6. // 是否调试模式
  7. public static bool debug = false;
  8. // 是否生产模式
  9. public static bool prodMode = true;
  10. // sdk版本号
  11. public const string sdk_version = "1.0.13";
  12. // 接口生产基础地址
  13. public const string BASE_URL = "https://api.huifu.com";
  14. // 接口测试基础地址
  15. public const string BASE_URL_MOCK = "https://spin-test.cloudpnr.com";
  16. // 汇付默认公钥(未配置公钥时使用)
  17. public const string HUIFU_DEFAULT_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtEqXg6GQ5uQJdjFJC31FW/tvNNvNNFGGo2TH2+Lu2MCejINLcydesLr7MzvkcYybedh9nFv3xq71HdLj2joSE7df/weSh0o8HXHJzNTyHTEGhkIAtu48cbNZKL64fZlo6+EzqHhBI2wfr0Jx3Gj7UTkPn4tJ0T0j7u6NtQ2tC8TBGxp/uVhScvTvqHXWlnwLPXmV+58lj5KK5HPvD8qmYIZQUtaJ1S2Urlt+iQ24yRYpSdcF19aVp/fB5u9lGIszhu051EKgrjvubZ8r/XCC0Ku+Ek3zFoH+3QGd3yL6XGunXYrnwPAam8hqdimzHzgnK7EEFrEc0RKxi1s9ZFDzEwIDAQAB";
  18. // 商户配置信息表
  19. private static Dictionary<string, MerConfig> merchantConfigs = new Dictionary<string, MerConfig>();
  20. // 初始化默认商户配置
  21. public static void initWithMerConfig(MerConfig config) {
  22. if (null == merchantConfigs)
  23. {
  24. merchantConfigs = new Dictionary<string, MerConfig>();
  25. }
  26. if (null != config )
  27. {
  28. if (!merchantConfigs.ContainsKey("default"))
  29. {
  30. merchantConfigs.Add("default", config);
  31. }
  32. }
  33. else {
  34. throw new Exception("configs cannot be null");
  35. }
  36. }
  37. // 多套商户配置初始化
  38. public static void initWithMerConfigs(Dictionary<string, MerConfig> configs)
  39. {
  40. if (null == merchantConfigs)
  41. {
  42. merchantConfigs = new Dictionary<string, MerConfig>();
  43. }
  44. if (null != configs)
  45. {
  46. foreach(KeyValuePair<string, MerConfig> item in configs)
  47. {
  48. merchantConfigs.Add(item.Key, item.Value);
  49. }
  50. }
  51. else
  52. {
  53. throw new Exception("configs cannot be null");
  54. }
  55. }
  56. // 跟据配置名获取商户配置信息
  57. public static MerConfig fetchConfig(string merchantKey)
  58. {
  59. if (string.IsNullOrEmpty(merchantKey))
  60. {
  61. merchantKey = "default";
  62. }
  63. if (null == merchantConfigs)
  64. {
  65. throw new Exception("Please config merchant config info at first");
  66. }
  67. MerConfig config = null;
  68. merchantConfigs.TryGetValue(merchantKey, out config);
  69. if (null == config)
  70. {
  71. throw new Exception("config Info for merchantkey-" + merchantKey + " is not configed");
  72. }
  73. return config;
  74. }
  75. public static void cleanMerConfigs()
  76. {
  77. if (null != merchantConfigs)
  78. {
  79. merchantConfigs.Clear();
  80. }
  81. }
  82. }
  83. }