mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 17:23:26 +08:00
【升级】升级paylink支付组件。
【优化】优化商家付款到零钱组件。
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.13.0" />
|
||||
<PackageReference Include="Essensoft.Paylink.Alipay" Version="4.0.14" />
|
||||
<PackageReference Include="Essensoft.Paylink.WeChatPay" Version="4.0.14" />
|
||||
<PackageReference Include="Essensoft.Paylink.Alipay" Version="4.1.0" />
|
||||
<PackageReference Include="Essensoft.Paylink.WeChatPay" Version="4.1.0" />
|
||||
<PackageReference Include="Flurl.Http" Version="3.2.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
|
||||
|
||||
@@ -29,16 +29,16 @@ using CoreCms.Net.WeChat.Service.HttpClients;
|
||||
using Essensoft.Paylink.WeChatPay;
|
||||
using Essensoft.Paylink.WeChatPay.V2;
|
||||
using Essensoft.Paylink.WeChatPay.V2.Request;
|
||||
using Essensoft.Paylink.WeChatPay.V3.Domain;
|
||||
using Essensoft.Paylink.WeChatPay.V3.Request;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using SKIT.FlurlHttpClient.Wechat.TenpayV3.Settings;
|
||||
using SKIT.FlurlHttpClient.Wechat.TenpayV3;
|
||||
using SKIT.FlurlHttpClient.Wechat.TenpayV3.Models;
|
||||
using SqlSugar;
|
||||
using Yitter.IdGenerator;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
||||
|
||||
namespace CoreCms.Net.Services
|
||||
@@ -55,13 +55,15 @@ namespace CoreCms.Net.Services
|
||||
private readonly ICoreCmsUserBalanceServices _userBalanceServices;
|
||||
private readonly ICoreCmsUserWeChatInfoServices _weChatInfoServices;
|
||||
private readonly IOptions<WeChatPayOptions> _optionsAccessor;
|
||||
private readonly IWeChatPayClient _client;
|
||||
private readonly IWeChatPayClient _v2Client;
|
||||
private readonly Essensoft.Paylink.WeChatPay.V3.IWeChatPayClient _v3Client;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||
|
||||
|
||||
public CoreCmsUserTocashServices(IUnitOfWork unitOfWork, ICoreCmsUserTocashRepository dal,
|
||||
IServiceProvider serviceProvider, ICoreCmsUserServices userServices, ICoreCmsUserBalanceServices userBalanceServices, ICoreCmsUserWeChatInfoServices weChatInfoServices, IOptions<WeChatPayOptions> optionsAccessor, IWeChatPayClient client, IHttpContextAccessor httpContextAccessor)
|
||||
IServiceProvider serviceProvider, ICoreCmsUserServices userServices, ICoreCmsUserBalanceServices userBalanceServices, ICoreCmsUserWeChatInfoServices weChatInfoServices, IOptions<WeChatPayOptions> optionsAccessor, IWeChatPayClient v2Client, IHttpContextAccessor httpContextAccessor, IWebHostEnvironment webHostEnvironment, Essensoft.Paylink.WeChatPay.V3.IWeChatPayClient v3Client)
|
||||
{
|
||||
this._dal = dal;
|
||||
base.BaseDal = dal;
|
||||
@@ -71,8 +73,10 @@ namespace CoreCms.Net.Services
|
||||
_userBalanceServices = userBalanceServices;
|
||||
_weChatInfoServices = weChatInfoServices;
|
||||
_optionsAccessor = optionsAccessor;
|
||||
_client = client;
|
||||
_v2Client = v2Client;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_webHostEnvironment = webHostEnvironment;
|
||||
_v3Client = v3Client;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -301,7 +305,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 _client.ExecuteAsync(request, _optionsAccessor.Value);
|
||||
var response = await _v2Client.ExecuteAsync(request, _optionsAccessor.Value);
|
||||
if (response.ReturnCode == WeChatPayCode.Success && response.ResultCode == WeChatPayCode.Success)
|
||||
{
|
||||
status = (int)GlobalEnumVars.UserTocashStatus.提现成功;
|
||||
@@ -359,7 +363,7 @@ namespace CoreCms.Net.Services
|
||||
Amount = amount,
|
||||
Desc = "余额提现银行卡",
|
||||
};
|
||||
var response = await _client.ExecuteAsync(request, _optionsAccessor.Value);
|
||||
var response = await _v2Client.ExecuteAsync(request, _optionsAccessor.Value);
|
||||
if (response.ReturnCode == WeChatPayCode.Success && response.ResultCode == WeChatPayCode.Success)
|
||||
{
|
||||
status = (int)GlobalEnumVars.UserTocashStatus.提现成功;
|
||||
@@ -396,41 +400,32 @@ namespace CoreCms.Net.Services
|
||||
//按分计算
|
||||
var amount = Convert.ToInt16((info.money - info.withdrawals) * 100);
|
||||
|
||||
var palpay = _optionsAccessor.Value;
|
||||
|
||||
var manager = new InMemoryCertificateManager();
|
||||
var options = new WechatTenpayClientOptions()
|
||||
var model = new WeChatPayTransferBatchesBodyModel
|
||||
{
|
||||
MerchantId = palpay.MchId,
|
||||
MerchantV3Secret = palpay.APIv3Key,
|
||||
MerchantCertificateSerialNumber = "微信商户证书序列号",
|
||||
MerchantCertificatePrivateKey = "-----BEGIN PRIVATE KEY-----微信商户证书私钥,即 `apiclient_key.pem` 文件内容-----END PRIVATE KEY-----",
|
||||
PlatformCertificateManager = manager // 证书管理器的具体用法请参阅下文的高级技巧与加密、验签有关的章节
|
||||
AppId = _optionsAccessor.Value.AppId,
|
||||
BatchName = info.id + "用户提现处理",
|
||||
BatchRemark = info.id + "用户提现处理",
|
||||
TotalAmount = amount,
|
||||
TotalNum = 1,
|
||||
OutBatchNo = "ut" + info.createTime.ToString("yyyyMMddHHmmss"),
|
||||
TransferDetailList = new List<TransferDetail>()
|
||||
{
|
||||
new()
|
||||
{
|
||||
OutDetailNo = "ut" + info.id,
|
||||
TransferAmount = amount,
|
||||
TransferRemark = "用户提现处理",
|
||||
OpenId = weChatUserInfo.openid,
|
||||
UserName = info.accountName
|
||||
}
|
||||
}
|
||||
};
|
||||
var client = new WechatTenpayClient(options);
|
||||
|
||||
var request = new CreateTransferBatchRequest();
|
||||
request.AppId = palpay.AppId;
|
||||
request.OutBatchNumber = "ut" + info.createTime.ToString("yyyyMMddHHmmss");
|
||||
request.BatchName = info.id + "用户提现处理";
|
||||
request.BatchRemark = info.id + "用户提现处理";
|
||||
request.TotalAmount = amount;
|
||||
request.TotalNumber = 1;
|
||||
request.TransferDetailList = new List<CreateTransferBatchRequest.Types.TransferDetail>();
|
||||
//转账明细列表
|
||||
var t = new CreateTransferBatchRequest.Types.TransferDetail
|
||||
{
|
||||
OutDetailNumber = "ut" + info.id,
|
||||
TransferAmount = amount,
|
||||
TransferRemark = "用户提现处理",
|
||||
OpenId = weChatUserInfo.openid,
|
||||
UserName = info.accountName
|
||||
};
|
||||
request.TransferDetailList.Add(t);
|
||||
var request = new WeChatPayTransferBatchesRequest();
|
||||
request.SetBodyModel(model);
|
||||
|
||||
var response = await client.ExecuteCreateTransferBatchAsync(request);
|
||||
|
||||
if (response.IsSuccessful())
|
||||
var response = await _v3Client.ExecuteAsync(request, _optionsAccessor.Value);
|
||||
if (response.IsError == false)
|
||||
{
|
||||
status = (int)GlobalEnumVars.UserTocashStatus.提现成功;
|
||||
var message = JsonConvert.SerializeObject(response);
|
||||
|
||||
Reference in New Issue
Block a user