//using System.Linq; using System; using System.Collections.Generic; using System.IO; using System.Reflection; using System.Web; using System.Xml.Serialization; /// /// Summary description for Config /// namespace WayneCloud.PaymentProcessors.Alipay.FromSDK { //public sealed class AliPayConfig //{ // public string alipay_public_key { get; set; } // //这里要配置没有经过PKCS8转换的原始私钥 // public string merchant_private_key { get; set; } // public string merchant_public_key { get; set; } // public string appId { get; set; } // public string serverUrl { get; set; } // public string mapiUrl { get; set; } // public string pid { get; set; } // public string charset { get; set; } // public string sign_type { get; set; } // public string version { get; set; } // private const string CONFIG_PATH = @"\AliPaymentProcessor\Alipay\Config\"; // private const string CONFIG_FILE = @"\AliPayConfig.xml"; // private const string CERT_PATH = @"\AliPaymentProcessor\Alipay\Pems\"; // private static volatile AliPayConfig instance = null; // private static volatile Dictionary instances = new Dictionary(); // private static object syncRoot = new Object(); // //public static AliPayConfig Instance // //{ // // get // // { // // if (instance == null) // // { // // lock (syncRoot) // // { // // if (instance == null) // // instance = new AliPayConfig(0); // // } // // } // // return instance; // // } // //} // public static AliPayConfig Instances(string buId) // { // if (string.IsNullOrEmpty(buId)) // { // if (instance == null) // { // lock (syncRoot) // { // if (instance == null) // instance = new AliPayConfig(0); // } // } // return instance; // } // if (!instances.ContainsKey(buId)) // { // var newConfig = new AliPayConfig(buId); // instances.Add(buId, newConfig); // return newConfig; // } // else // { // return instances[buId]; // } // } // // used for serilization and deserilization // private AliPayConfig() // { } // // used for singleton instance // private AliPayConfig(int dummy) // { // var executionFolder = AppDomain.CurrentDomain.BaseDirectory; // var cfgFilePath = executionFolder + CONFIG_PATH + CONFIG_FILE; // XmlSerializer deserializer = new XmlSerializer(typeof(AliPayConfig)); // TextReader reader = new StreamReader(cfgFilePath); // object obj = deserializer.Deserialize(reader); // AliPayConfig XmlData = (AliPayConfig)obj; // reader.Close(); // alipay_public_key = executionFolder + CERT_PATH + XmlData.alipay_public_key; // merchant_private_key = executionFolder + CERT_PATH + XmlData.merchant_private_key; // merchant_public_key = executionFolder + CERT_PATH + XmlData.merchant_public_key; // appId = XmlData.appId; // serverUrl = XmlData.serverUrl; // mapiUrl = XmlData.mapiUrl; // pid = XmlData.pid; // charset = XmlData.charset; // sign_type = XmlData.sign_type; // version = XmlData.version; // } // private AliPayConfig(string currentBuId) // { // var executionFolder = AppDomain.CurrentDomain.BaseDirectory + currentBuId; // DirectoryInfo directory = new DirectoryInfo(executionFolder); // if (!directory.Exists) // { // directory.Create(); // } // var cfgFilePath = executionFolder + CONFIG_PATH + CONFIG_FILE; // XmlSerializer deserializer = new XmlSerializer(typeof(AliPayConfig)); // TextReader reader = new StreamReader(cfgFilePath); // object obj = deserializer.Deserialize(reader); // AliPayConfig XmlData = (AliPayConfig)obj; // reader.Close(); // alipay_public_key = executionFolder + CERT_PATH + XmlData.alipay_public_key; // merchant_private_key = executionFolder + CERT_PATH + XmlData.merchant_private_key; // merchant_public_key = executionFolder + CERT_PATH + XmlData.merchant_public_key; // appId = XmlData.appId; // serverUrl = XmlData.serverUrl; // mapiUrl = XmlData.mapiUrl; // pid = XmlData.pid; // charset = XmlData.charset; // sign_type = XmlData.sign_type; // version = XmlData.version; // } // //// this method is only for test // //public AliPayConfig(string dummy) // //{ } // //// this method is only for test // //public void SerializeMyself(string targetFolder) // //{ // // var filePath = targetFolder + CONFIG_FILE; // // XmlSerializer serializer = new XmlSerializer(typeof(AliPayConfig)); // // using (TextWriter writer = new StreamWriter(filePath)) // // { // // serializer.Serialize(writer, this); // // } // //} // //public static string getMerchantPublicKeyStr() // //{ // // StreamReader sr = new StreamReader(merchant_public_key); // // string pubkey = sr.ReadToEnd(); // // sr.Close(); // // if (pubkey != null) // // { // // pubkey = pubkey.Replace("-----BEGIN PUBLIC KEY-----", ""); // // pubkey = pubkey.Replace("-----END PUBLIC KEY-----", ""); // // pubkey = pubkey.Replace("\r", ""); // // pubkey = pubkey.Replace("\n", ""); // // } // // return pubkey; // //} // //public static string getMerchantPriveteKeyStr() // //{ // // StreamReader sr = new StreamReader(merchant_private_key); // // string pubkey = sr.ReadToEnd(); // // sr.Close(); // // if (pubkey != null) // // { // // pubkey = pubkey.Replace("-----BEGIN PUBLIC KEY-----", ""); // // pubkey = pubkey.Replace("-----END PUBLIC KEY-----", ""); // // pubkey = pubkey.Replace("\r", ""); // // pubkey = pubkey.Replace("\n", ""); // // } // // return pubkey; // //} //} }