123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- //using System.Linq;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Reflection;
- using System.Web;
- using System.Xml.Serialization;
- /// <summary>
- /// Summary description for Config
- /// </summary>
- 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<string, AliPayConfig> instances = new Dictionary<string, AliPayConfig>();
- // 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;
- // //}
- //}
- }
|