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<string, RSACryptoServiceProvider> mGetMerchantPrivateKeyFunc;
|
|
|
|
ConcurrentDictionary<string, RSACryptoServiceProvider> mMerchantPrivateKeys = new ConcurrentDictionary<string, RSACryptoServiceProvider>();
|
|
|
|
public static void Init(Func<string, RSACryptoServiceProvider> getMerchantPrivateKey, Func<X509Certificate> getPublicKeyFunc, string logPath)
|
|
{
|
|
mGetMerchantPrivateKeyFunc = getMerchantPrivateKey;
|
|
mGetABCPublicKeyFunc = getPublicKeyFunc;
|
|
mLogPath = logPath;
|
|
}
|
|
|
|
static string mLogPath;
|
|
|
|
internal static string mMerchantID;
|
|
|
|
/// <summary>
|
|
/// 开启日志
|
|
/// </summary>
|
|
public bool EnableLog
|
|
{
|
|
get
|
|
{
|
|
return !string.IsNullOrEmpty(mLogPath);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 日志目录
|
|
/// </summary>
|
|
public string LogPath
|
|
{
|
|
get
|
|
{
|
|
return mLogPath;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 商户编号
|
|
/// </summary>
|
|
public string MerchanID
|
|
{
|
|
get
|
|
{
|
|
return mMerchantID;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 商户私钥
|
|
/// </summary>
|
|
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<X509Certificate> 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;
|
|
}
|
|
}
|
|
}
|
|
}
|