From 6b655d3fc91d7cb76962493c6540bf63f6dce49b Mon Sep 17 00:00:00 2001 From: jianweie Date: Wed, 26 Apr 2023 14:17:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8F=90=E7=8E=B0=E4=B8=AD?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../User/CoreCmsUserTocashServices.cs | 75 +++++++++++++++++-- 1 file changed, 68 insertions(+), 7 deletions(-) diff --git a/CoreCms.Net.Services/User/CoreCmsUserTocashServices.cs b/CoreCms.Net.Services/User/CoreCmsUserTocashServices.cs index 93b3d722..510b7e51 100644 --- a/CoreCms.Net.Services/User/CoreCmsUserTocashServices.cs +++ b/CoreCms.Net.Services/User/CoreCmsUserTocashServices.cs @@ -54,16 +54,17 @@ namespace CoreCms.Net.Services private readonly ICoreCmsUserServices _userServices; private readonly ICoreCmsUserBalanceServices _userBalanceServices; private readonly ICoreCmsUserWeChatInfoServices _weChatInfoServices; - private readonly IOptions _optionsAccessor; private readonly IWeChatPayClient _v2Client; private readonly Essensoft.Paylink.WeChatPay.V3.IWeChatPayClient _v3Client; private readonly IHttpContextAccessor _httpContextAccessor; private readonly IWebHostEnvironment _webHostEnvironment; + private readonly IWeChatPayConfigServices _weChatPayConfigServices; + public CoreCmsUserTocashServices(IUnitOfWork unitOfWork, ICoreCmsUserTocashRepository dal, - IServiceProvider serviceProvider, ICoreCmsUserServices userServices, ICoreCmsUserBalanceServices userBalanceServices, ICoreCmsUserWeChatInfoServices weChatInfoServices, IOptions optionsAccessor, IWeChatPayClient v2Client, IHttpContextAccessor httpContextAccessor, IWebHostEnvironment webHostEnvironment, Essensoft.Paylink.WeChatPay.V3.IWeChatPayClient v3Client) + IServiceProvider serviceProvider, ICoreCmsUserServices userServices, ICoreCmsUserBalanceServices userBalanceServices, ICoreCmsUserWeChatInfoServices weChatInfoServices, IWeChatPayClient v2Client, IHttpContextAccessor httpContextAccessor, IWebHostEnvironment webHostEnvironment, Essensoft.Paylink.WeChatPay.V3.IWeChatPayClient v3Client, IWeChatPayConfigServices weChatPayConfigServices) { this._dal = dal; base.BaseDal = dal; @@ -72,11 +73,11 @@ namespace CoreCms.Net.Services _userServices = userServices; _userBalanceServices = userBalanceServices; _weChatInfoServices = weChatInfoServices; - _optionsAccessor = optionsAccessor; _v2Client = v2Client; _httpContextAccessor = httpContextAccessor; _webHostEnvironment = webHostEnvironment; _v3Client = v3Client; + _weChatPayConfigServices = weChatPayConfigServices; } /// @@ -292,6 +293,26 @@ namespace CoreCms.Net.Services jm.msg = "微信用户数据获取失败"; return jm; } + + var config = await _weChatPayConfigServices.QueryByClauseAsync(p => p.isDefault == true && p.isEnable == true); + if (config == null) + { + jm.msg = "支付配置信息获取失败"; + return jm; + } + //构建linkPay请求配置实体 + var payOptions = new WeChatPayOptions + { + AppId = config.appId, + MchId = config.mchId, + APIKey = config.apiKey, + APIv3Key = config.apiV3Key, + Certificate = config.certificate, + RsaPublicKey = config.rsaPublicKey, + SubAppId = config.subAppId, + SubMchId = config.subMchId + }; + //按分计算 var amount = Convert.ToInt16((info.money - info.withdrawals) * 100); //企业付款到零钱 @@ -305,7 +326,7 @@ namespace CoreCms.Net.Services Desc = "余额提现零钱", SpBillCreateIp = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1" }; - var response = await _v2Client.ExecuteAsync(request, _optionsAccessor.Value); + var response = await _v2Client.ExecuteAsync(request, payOptions); if (response.ReturnCode == WeChatPayCode.Success && response.ResultCode == WeChatPayCode.Success) { status = (int)GlobalEnumVars.UserTocashStatus.提现成功; @@ -351,6 +372,26 @@ namespace CoreCms.Net.Services jm.msg = "微信用户数据获取失败"; return jm; } + + var config = await _weChatPayConfigServices.QueryByClauseAsync(p => p.isDefault == true && p.isEnable == true); + if (config == null) + { + jm.msg = "支付配置信息获取失败"; + return jm; + } + //构建linkPay请求配置实体 + var payOptions = new WeChatPayOptions + { + AppId = config.appId, + MchId = config.mchId, + APIKey = config.apiKey, + APIv3Key = config.apiV3Key, + Certificate = config.certificate, + RsaPublicKey = config.rsaPublicKey, + SubAppId = config.subAppId, + SubMchId = config.subMchId + }; + //按分计算 var amount = Convert.ToInt16((info.money - info.withdrawals) * 100); //企业付款到零钱 @@ -363,7 +404,7 @@ namespace CoreCms.Net.Services Amount = amount, Desc = "余额提现银行卡", }; - var response = await _v2Client.ExecuteAsync(request, _optionsAccessor.Value); + var response = await _v2Client.ExecuteAsync(request, payOptions); if (response.ReturnCode == WeChatPayCode.Success && response.ResultCode == WeChatPayCode.Success) { status = (int)GlobalEnumVars.UserTocashStatus.提现成功; @@ -397,12 +438,32 @@ namespace CoreCms.Net.Services jm.msg = "微信用户数据获取失败"; return jm; } + + var config = await _weChatPayConfigServices.QueryByClauseAsync(p => p.isDefault == true && p.isEnable == true); + if (config == null) + { + jm.msg = "支付配置信息获取失败"; + return jm; + } + //构建linkPay请求配置实体 + var payOptions = new WeChatPayOptions + { + AppId = config.appId, + MchId = config.mchId, + APIKey = config.apiKey, + APIv3Key = config.apiV3Key, + Certificate = config.certificate, + RsaPublicKey = config.rsaPublicKey, + SubAppId = config.subAppId, + SubMchId = config.subMchId + }; + //按分计算 var amount = Convert.ToInt16((info.money - info.withdrawals) * 100); var model = new WeChatPayTransferBatchesBodyModel { - AppId = _optionsAccessor.Value.AppId, + AppId = payOptions.AppId, BatchName = info.id + "用户提现处理", BatchRemark = info.id + "用户提现处理", TotalAmount = amount, @@ -424,7 +485,7 @@ namespace CoreCms.Net.Services var request = new WeChatPayTransferBatchesRequest(); request.SetBodyModel(model); - var response = await _v3Client.ExecuteAsync(request, _optionsAccessor.Value); + var response = await _v3Client.ExecuteAsync(request, payOptions); if (response.IsError == false) { status = (int)GlobalEnumVars.UserTocashStatus.提现成功;