using ESSupport.Common; using ESSupport.Pos; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; namespace PBlibPay { [Guid("8D08F30F-8D55-4D4E-9FFA-CE5DDF007E1F")] public interface IESTPay { [DispId(1)] string Createpay(string ticketCode, string ticketPrice, string userPayCode, string payType, string payDesc); } [Guid("58A76A9E-D154-4411-88AF-8BEBA8D6A2EC"), ClassInterface(ClassInterfaceType.None), ComSourceInterfaces(typeof(IESTPay))] public class ESTPay : IESTPay { public ESTPay() { GetMobilePayOperators(PosConfigInit.ServerIP); } public string Createpay(string ticketCode, string ticketPrice, string userPayCode, string payType, string payDesc) { if (string.IsNullOrWhiteSpace(payType)) { payType = "ALIPAY"; } if (string.IsNullOrWhiteSpace(payDesc)) { payDesc = "服务区商品"; } Enum.TryParse(PosConfigInit.MobilePayOperators, out libESPay.PayUtils.MobilePayOperators mobilePayOperators); libESPay.PayUtils.MobilePayConfig.PayMerchant payMerchant = new libESPay.PayUtils.MobilePayConfig.PayMerchant() { MerchantAPPID = PosControl.MobilePayMerchantList[mobilePayOperators].AppID, MerchantCode = PosControl.MobilePayMerchantList[mobilePayOperators].Busi_id, MerchantKey = PosControl.MobilePayMerchantList[mobilePayOperators].Key, MerchantPosCode = PosControl.MobilePayMerchantList[mobilePayOperators].PosCode, MerchantShopCode = PosControl.MobilePayMerchantList[mobilePayOperators].ShopCode, MobilePayOperatorURL = PosControl.MobilePayMerchantList[mobilePayOperators].ApiURL, MobilePayProxyURL = PosControl.MobilePayMerchantList[mobilePayOperators].Proxy }; return libESPay.ESPayService.ESTScanPay(mobilePayOperators, payMerchant, userPayCode, ticketCode, ticketPrice, payDesc, true); } /// /// 获取主备用通道对应的移动支付服务商,并初始化交易参数 /// /// 支付通道服务器IP地址 private void GetMobilePayOperators(string paySeviceIP) { try { //移动支付代理转发地址 string mobilePayProxyURL = $"http://{paySeviceIP}:17080/DataTransferService/Service.asmx"; //初始化移动支付交易参数列表属性 if (PosControl.MobilePayMerchantList == null) { PosControl.MobilePayMerchantList = new ConcurrentDictionary(); } //读取当前门店全部移动支付交易参数配置信息 List mpcm_PayConfig = ESSupport.DataStorage.DataFunction.QueryMobilePayConfig(PosConfigInit.ServerpartCode, PosConfigInit.ShopCode); if (mpcm_PayConfig != null && mpcm_PayConfig.Count > 0) { for (int i = 0; i < mpcm_PayConfig.Count; i++) { //解析移动支付服务商交易信息 if (Enum.TryParse(mpcm_PayConfig[i].MobilePayOperator.ToString("F0"), out libESPay.PayUtils.MobilePayOperators _MobilePayOperators)) { //生成移动支付交易参数对象 PayMerchant payMerchant = new PayMerchant { AppID = mpcm_PayConfig[i].MerchantAPPID, Busi_id = mpcm_PayConfig[i].MerchantCode, Key = mpcm_PayConfig[i].MerchantKey, PosCode = mpcm_PayConfig[i].MerchantPosCode, ShopCode = mpcm_PayConfig[i].MerchantShopCode, ApiURL = mpcm_PayConfig[i].MobilePayOperatorURL, Proxy = mobilePayProxyURL }; //添加交易参数到列表 PosControl.MobilePayMerchantList.AddOrUpdate(_MobilePayOperators, payMerchant, (operators, merchant) => payMerchant); } } } } catch (Exception) { } } } }