Config.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //using System.Linq;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Reflection;
  6. using System.Web;
  7. using System.Xml.Serialization;
  8. /// <summary>
  9. /// Summary description for Config
  10. /// </summary>
  11. namespace WayneCloud.PaymentProcessors.Alipay.FromSDK
  12. {
  13. //public sealed class AliPayConfig
  14. //{
  15. // public string alipay_public_key { get; set; }
  16. // //这里要配置没有经过PKCS8转换的原始私钥
  17. // public string merchant_private_key { get; set; }
  18. // public string merchant_public_key { get; set; }
  19. // public string appId { get; set; }
  20. // public string serverUrl { get; set; }
  21. // public string mapiUrl { get; set; }
  22. // public string pid { get; set; }
  23. // public string charset { get; set; }
  24. // public string sign_type { get; set; }
  25. // public string version { get; set; }
  26. // private const string CONFIG_PATH = @"\AliPaymentProcessor\Alipay\Config\";
  27. // private const string CONFIG_FILE = @"\AliPayConfig.xml";
  28. // private const string CERT_PATH = @"\AliPaymentProcessor\Alipay\Pems\";
  29. // private static volatile AliPayConfig instance = null;
  30. // private static volatile Dictionary<string, AliPayConfig> instances = new Dictionary<string, AliPayConfig>();
  31. // private static object syncRoot = new Object();
  32. // //public static AliPayConfig Instance
  33. // //{
  34. // // get
  35. // // {
  36. // // if (instance == null)
  37. // // {
  38. // // lock (syncRoot)
  39. // // {
  40. // // if (instance == null)
  41. // // instance = new AliPayConfig(0);
  42. // // }
  43. // // }
  44. // // return instance;
  45. // // }
  46. // //}
  47. // public static AliPayConfig Instances(string buId)
  48. // {
  49. // if (string.IsNullOrEmpty(buId))
  50. // {
  51. // if (instance == null)
  52. // {
  53. // lock (syncRoot)
  54. // {
  55. // if (instance == null)
  56. // instance = new AliPayConfig(0);
  57. // }
  58. // }
  59. // return instance;
  60. // }
  61. // if (!instances.ContainsKey(buId))
  62. // {
  63. // var newConfig = new AliPayConfig(buId);
  64. // instances.Add(buId, newConfig);
  65. // return newConfig;
  66. // }
  67. // else
  68. // {
  69. // return instances[buId];
  70. // }
  71. // }
  72. // // used for serilization and deserilization
  73. // private AliPayConfig()
  74. // { }
  75. // // used for singleton instance
  76. // private AliPayConfig(int dummy)
  77. // {
  78. // var executionFolder = AppDomain.CurrentDomain.BaseDirectory;
  79. // var cfgFilePath = executionFolder + CONFIG_PATH + CONFIG_FILE;
  80. // XmlSerializer deserializer = new XmlSerializer(typeof(AliPayConfig));
  81. // TextReader reader = new StreamReader(cfgFilePath);
  82. // object obj = deserializer.Deserialize(reader);
  83. // AliPayConfig XmlData = (AliPayConfig)obj;
  84. // reader.Close();
  85. // alipay_public_key = executionFolder + CERT_PATH + XmlData.alipay_public_key;
  86. // merchant_private_key = executionFolder + CERT_PATH + XmlData.merchant_private_key;
  87. // merchant_public_key = executionFolder + CERT_PATH + XmlData.merchant_public_key;
  88. // appId = XmlData.appId;
  89. // serverUrl = XmlData.serverUrl;
  90. // mapiUrl = XmlData.mapiUrl;
  91. // pid = XmlData.pid;
  92. // charset = XmlData.charset;
  93. // sign_type = XmlData.sign_type;
  94. // version = XmlData.version;
  95. // }
  96. // private AliPayConfig(string currentBuId)
  97. // {
  98. // var executionFolder = AppDomain.CurrentDomain.BaseDirectory + currentBuId;
  99. // DirectoryInfo directory = new DirectoryInfo(executionFolder);
  100. // if (!directory.Exists)
  101. // {
  102. // directory.Create();
  103. // }
  104. // var cfgFilePath = executionFolder + CONFIG_PATH + CONFIG_FILE;
  105. // XmlSerializer deserializer = new XmlSerializer(typeof(AliPayConfig));
  106. // TextReader reader = new StreamReader(cfgFilePath);
  107. // object obj = deserializer.Deserialize(reader);
  108. // AliPayConfig XmlData = (AliPayConfig)obj;
  109. // reader.Close();
  110. // alipay_public_key = executionFolder + CERT_PATH + XmlData.alipay_public_key;
  111. // merchant_private_key = executionFolder + CERT_PATH + XmlData.merchant_private_key;
  112. // merchant_public_key = executionFolder + CERT_PATH + XmlData.merchant_public_key;
  113. // appId = XmlData.appId;
  114. // serverUrl = XmlData.serverUrl;
  115. // mapiUrl = XmlData.mapiUrl;
  116. // pid = XmlData.pid;
  117. // charset = XmlData.charset;
  118. // sign_type = XmlData.sign_type;
  119. // version = XmlData.version;
  120. // }
  121. // //// this method is only for test
  122. // //public AliPayConfig(string dummy)
  123. // //{ }
  124. // //// this method is only for test
  125. // //public void SerializeMyself(string targetFolder)
  126. // //{
  127. // // var filePath = targetFolder + CONFIG_FILE;
  128. // // XmlSerializer serializer = new XmlSerializer(typeof(AliPayConfig));
  129. // // using (TextWriter writer = new StreamWriter(filePath))
  130. // // {
  131. // // serializer.Serialize(writer, this);
  132. // // }
  133. // //}
  134. // //public static string getMerchantPublicKeyStr()
  135. // //{
  136. // // StreamReader sr = new StreamReader(merchant_public_key);
  137. // // string pubkey = sr.ReadToEnd();
  138. // // sr.Close();
  139. // // if (pubkey != null)
  140. // // {
  141. // // pubkey = pubkey.Replace("-----BEGIN PUBLIC KEY-----", "");
  142. // // pubkey = pubkey.Replace("-----END PUBLIC KEY-----", "");
  143. // // pubkey = pubkey.Replace("\r", "");
  144. // // pubkey = pubkey.Replace("\n", "");
  145. // // }
  146. // // return pubkey;
  147. // //}
  148. // //public static string getMerchantPriveteKeyStr()
  149. // //{
  150. // // StreamReader sr = new StreamReader(merchant_private_key);
  151. // // string pubkey = sr.ReadToEnd();
  152. // // sr.Close();
  153. // // if (pubkey != null)
  154. // // {
  155. // // pubkey = pubkey.Replace("-----BEGIN PUBLIC KEY-----", "");
  156. // // pubkey = pubkey.Replace("-----END PUBLIC KEY-----", "");
  157. // // pubkey = pubkey.Replace("\r", "");
  158. // // pubkey = pubkey.Replace("\n", "");
  159. // // }
  160. // // return pubkey;
  161. // //}
  162. //}
  163. }