using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Xml.Serialization; namespace Wechat.PayAPI { /** * 配置账号信息 */ //public sealed class WxPayConfig //{ // //=======【基本信息设置】===================================== // /* 微信公众号信息配置 // * APPID:绑定支付的APPID(必须配置) // * SUBAPPID: 子商户的APPID // * MCHID:商户号(必须配置) // * SUBMCHID:子商户号 // * KEY:商户支付密钥,参考开户邮件设置(必须配置) // * APPSECRET:公众帐号secert(仅JSAPI支付的时候需要配置) // */ // public string APPID { get; set; } // public string SUBAPPID { get; set; } // public string MCHID { get; set; } // public string SUBMCHID { get; set; } // public string KEY { get; set; } // public string APPSECRET { get; set; } // //=======【证书设置】===================================== // /* 证书文件名(仅退款、撤销订单时需要) // */ // public string SSLCERT { get; set; } // public string SSLCERT_PASSWORD { get; set; } // //=======【支付结果通知url】===================================== // /* 支付结果通知回调url,用于商户接收支付结果 // */ // public string NOTIFY_URL { get; set; } // //=======【商户系统后台机器IP】===================================== // /* 此参数可手动配置也可在程序中自动获取 // */ // public string IP { get; set; } // //=======【代理服务器设置】=================================== // /* 默认IP和端口号分别为0.0.0.0和0,此时不开启代理(如有需要才设置) // */ // public string PROXY_URL { get; set; } // //=======【上报信息配置】=================================== // /* 测速上报等级,0.关闭上报; 1.仅错误时上报; 2.全量上报 // */ // public int REPORT_LEVENL { get; set; } // //=======【日志级别】=================================== // /* 日志等级,0.不输出日志;1.只输出错误信息; 2.输出错误和正常信息; 3.输出错误信息、正常信息和调试信息 // */ // //public const int LOG_LEVENL = 0; // // the following are for singelton // private const string CONFIG_PATH = @"\WeChatPaymentProcessor\Wechat\Config\"; // private const string CONFIG_FILE = @"\WxPayConfig.xml"; // private const string CERT_PATH = @"\WeChatPaymentProcessor\Wechat\Cert\"; // private static volatile WxPayConfig instance = null; // private static volatile Dictionary instances = new Dictionary(); // private static object syncRoot = new Object(); // public static WxPayConfigs Instances(string buId) // { // if (!instances.ContainsKey(buId)) // { // //var newConfig= new WxPayConfig(buId); // string configName = "WeChatPayConfig"; // string serviceUrl = "http://127.0.0.1:8889"; // var configuration = ExtentionMethod.LoadElectronicPayConfig(serviceUrl, configName, buId); // byte[] bytes = Encoding.UTF8.GetBytes(configuration.Value); // MemoryStream stream = new MemoryStream(bytes); // XmlSerializer deserializer = new XmlSerializer(typeof(WxPayConfigs)); // TextReader reader = new StreamReader(stream); // WxPayConfigs config = (WxPayConfigs)deserializer.Deserialize(reader); // instances.Add(buId, config); // return config; // } // else // { // return instances[buId]; // } // } // // used for serilization and deserilization // private WxPayConfig() // { } // // used for singleton instance // private WxPayConfig(int dummy) // { // var executionFolder = AppDomain.CurrentDomain.BaseDirectory; // var cfgFilePath = executionFolder + CONFIG_PATH + CONFIG_FILE; // XmlSerializer deserializer = new XmlSerializer(typeof(WxPayConfig)); // TextReader reader = new StreamReader(cfgFilePath); // object obj = deserializer.Deserialize(reader); // WxPayConfig XmlData = (WxPayConfig)obj; // reader.Close(); // APPID = XmlData.APPID; // MCHID = XmlData.MCHID; // KEY = XmlData.KEY; // APPSECRET = XmlData.APPSECRET; // SSLCERT = executionFolder + CERT_PATH + XmlData.SSLCERT; // SSLCERT_PASSWORD = XmlData.SSLCERT_PASSWORD; // NOTIFY_URL = XmlData.NOTIFY_URL; // IP = XmlData.IP; // PROXY_URL = XmlData.PROXY_URL; // REPORT_LEVENL = XmlData.REPORT_LEVENL; // } // public WxPayConfig(string buId) // { // var executionFolder = AppDomain.CurrentDomain.BaseDirectory + buId; // DirectoryInfo directory = new DirectoryInfo(executionFolder); // if (!directory.Exists) // { // directory.Create(); // } // var cfgFilePath = executionFolder + CONFIG_PATH + CONFIG_FILE; // XmlSerializer deserializer = new XmlSerializer(typeof(WxPayConfig)); // TextReader reader = new StreamReader(cfgFilePath); // object obj = deserializer.Deserialize(reader); // WxPayConfig XmlData = (WxPayConfig)obj; // reader.Close(); // APPID = XmlData.APPID; // SUBAPPID = XmlData.SUBAPPID; // MCHID = XmlData.MCHID; // SUBMCHID = XmlData.SUBMCHID; // KEY = XmlData.KEY; // APPSECRET = XmlData.APPSECRET; // SSLCERT = executionFolder + CERT_PATH + XmlData.SSLCERT; // SSLCERT_PASSWORD = XmlData.SSLCERT_PASSWORD; // NOTIFY_URL = XmlData.NOTIFY_URL; // IP = XmlData.IP; // PROXY_URL = XmlData.PROXY_URL; // REPORT_LEVENL = XmlData.REPORT_LEVENL; // } //} }