using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Collections.Concurrent; namespace Bwp.ABCClient2.Core { public class ABCClientConfig { static Func mGetMerchantPrivateKeyFunc; ConcurrentDictionary mMerchantPrivateKeys = new ConcurrentDictionary(); public static void Init(Func getMerchantPrivateKey, Func getPublicKeyFunc, string logPath) { mGetMerchantPrivateKeyFunc = getMerchantPrivateKey; mGetABCPublicKeyFunc = getPublicKeyFunc; mLogPath = logPath; } static string mLogPath; internal static string mMerchantID; /// /// 开启日志 /// public bool EnableLog { get { return !string.IsNullOrEmpty(mLogPath); } } /// /// 日志目录 /// public string LogPath { get { return mLogPath; } } /// /// 商户编号 /// public string MerchanID { get { return mMerchantID; } } /// /// 商户私钥 /// public RSACryptoServiceProvider MerchanPrivateKey { get { if (string.IsNullOrEmpty(MerchanID)) { throw new Exception("没有配置当前的商户"); } RSACryptoServiceProvider key; if (mMerchantPrivateKeys.TryGetValue(MerchanID, out key)) { return key; } else { key = mGetMerchantPrivateKeyFunc(MerchanID); if (key == null) { throw new Exception(string.Format("系统中没有配置商户{0}的私钥", MerchanID)); } mMerchantPrivateKeys.TryAdd(MerchanID, key); return key; } } } static Func mGetABCPublicKeyFunc; public X509Certificate ABCPublicKey { get { var mABCPublicKey = mGetABCPublicKeyFunc(); if (mABCPublicKey == null) { throw new Exception("系统中没有配置农业银行的公钥"); } return mABCPublicKey; } } internal static string mTrustPayConnectMethod = "https"; public string TrustPayConnectMethod { get { return mTrustPayConnectMethod; } } internal static string mTrustPayServerName = "www.95599.cn"; public string TrustPayServerName { get { return mTrustPayServerName; } } internal static int mTrustPayServerPort = 443; public int TrustPayServerPort { get { return mTrustPayServerPort; } } internal static string mTrustPayTrxURL; public string TrustPayTrxURL { get { return mTrustPayTrxURL; } } } }