mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2026-03-25 04:37:22 +08:00
优化提现中使用的微信支付功能。
This commit is contained in:
@@ -54,16 +54,17 @@ namespace CoreCms.Net.Services
|
|||||||
private readonly ICoreCmsUserServices _userServices;
|
private readonly ICoreCmsUserServices _userServices;
|
||||||
private readonly ICoreCmsUserBalanceServices _userBalanceServices;
|
private readonly ICoreCmsUserBalanceServices _userBalanceServices;
|
||||||
private readonly ICoreCmsUserWeChatInfoServices _weChatInfoServices;
|
private readonly ICoreCmsUserWeChatInfoServices _weChatInfoServices;
|
||||||
private readonly IOptions<WeChatPayOptions> _optionsAccessor;
|
|
||||||
private readonly IWeChatPayClient _v2Client;
|
private readonly IWeChatPayClient _v2Client;
|
||||||
private readonly Essensoft.Paylink.WeChatPay.V3.IWeChatPayClient _v3Client;
|
private readonly Essensoft.Paylink.WeChatPay.V3.IWeChatPayClient _v3Client;
|
||||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
|
|
||||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||||
|
private readonly IWeChatPayConfigServices _weChatPayConfigServices;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public CoreCmsUserTocashServices(IUnitOfWork unitOfWork, ICoreCmsUserTocashRepository dal,
|
public CoreCmsUserTocashServices(IUnitOfWork unitOfWork, ICoreCmsUserTocashRepository dal,
|
||||||
IServiceProvider serviceProvider, ICoreCmsUserServices userServices, ICoreCmsUserBalanceServices userBalanceServices, ICoreCmsUserWeChatInfoServices weChatInfoServices, IOptions<WeChatPayOptions> 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;
|
this._dal = dal;
|
||||||
base.BaseDal = dal;
|
base.BaseDal = dal;
|
||||||
@@ -72,11 +73,11 @@ namespace CoreCms.Net.Services
|
|||||||
_userServices = userServices;
|
_userServices = userServices;
|
||||||
_userBalanceServices = userBalanceServices;
|
_userBalanceServices = userBalanceServices;
|
||||||
_weChatInfoServices = weChatInfoServices;
|
_weChatInfoServices = weChatInfoServices;
|
||||||
_optionsAccessor = optionsAccessor;
|
|
||||||
_v2Client = v2Client;
|
_v2Client = v2Client;
|
||||||
_httpContextAccessor = httpContextAccessor;
|
_httpContextAccessor = httpContextAccessor;
|
||||||
_webHostEnvironment = webHostEnvironment;
|
_webHostEnvironment = webHostEnvironment;
|
||||||
_v3Client = v3Client;
|
_v3Client = v3Client;
|
||||||
|
_weChatPayConfigServices = weChatPayConfigServices;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -292,6 +293,26 @@ namespace CoreCms.Net.Services
|
|||||||
jm.msg = "微信用户数据获取失败";
|
jm.msg = "微信用户数据获取失败";
|
||||||
return jm;
|
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 amount = Convert.ToInt16((info.money - info.withdrawals) * 100);
|
||||||
//企业付款到零钱
|
//企业付款到零钱
|
||||||
@@ -305,7 +326,7 @@ namespace CoreCms.Net.Services
|
|||||||
Desc = "余额提现零钱",
|
Desc = "余额提现零钱",
|
||||||
SpBillCreateIp = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"
|
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)
|
if (response.ReturnCode == WeChatPayCode.Success && response.ResultCode == WeChatPayCode.Success)
|
||||||
{
|
{
|
||||||
status = (int)GlobalEnumVars.UserTocashStatus.提现成功;
|
status = (int)GlobalEnumVars.UserTocashStatus.提现成功;
|
||||||
@@ -351,6 +372,26 @@ namespace CoreCms.Net.Services
|
|||||||
jm.msg = "微信用户数据获取失败";
|
jm.msg = "微信用户数据获取失败";
|
||||||
return jm;
|
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 amount = Convert.ToInt16((info.money - info.withdrawals) * 100);
|
||||||
//企业付款到零钱
|
//企业付款到零钱
|
||||||
@@ -363,7 +404,7 @@ namespace CoreCms.Net.Services
|
|||||||
Amount = amount,
|
Amount = amount,
|
||||||
Desc = "余额提现银行卡",
|
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)
|
if (response.ReturnCode == WeChatPayCode.Success && response.ResultCode == WeChatPayCode.Success)
|
||||||
{
|
{
|
||||||
status = (int)GlobalEnumVars.UserTocashStatus.提现成功;
|
status = (int)GlobalEnumVars.UserTocashStatus.提现成功;
|
||||||
@@ -397,12 +438,32 @@ namespace CoreCms.Net.Services
|
|||||||
jm.msg = "微信用户数据获取失败";
|
jm.msg = "微信用户数据获取失败";
|
||||||
return jm;
|
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 amount = Convert.ToInt16((info.money - info.withdrawals) * 100);
|
||||||
|
|
||||||
var model = new WeChatPayTransferBatchesBodyModel
|
var model = new WeChatPayTransferBatchesBodyModel
|
||||||
{
|
{
|
||||||
AppId = _optionsAccessor.Value.AppId,
|
AppId = payOptions.AppId,
|
||||||
BatchName = info.id + "用户提现处理",
|
BatchName = info.id + "用户提现处理",
|
||||||
BatchRemark = info.id + "用户提现处理",
|
BatchRemark = info.id + "用户提现处理",
|
||||||
TotalAmount = amount,
|
TotalAmount = amount,
|
||||||
@@ -424,7 +485,7 @@ namespace CoreCms.Net.Services
|
|||||||
var request = new WeChatPayTransferBatchesRequest();
|
var request = new WeChatPayTransferBatchesRequest();
|
||||||
request.SetBodyModel(model);
|
request.SetBodyModel(model);
|
||||||
|
|
||||||
var response = await _v3Client.ExecuteAsync(request, _optionsAccessor.Value);
|
var response = await _v3Client.ExecuteAsync(request, payOptions);
|
||||||
if (response.IsError == false)
|
if (response.IsError == false)
|
||||||
{
|
{
|
||||||
status = (int)GlobalEnumVars.UserTocashStatus.提现成功;
|
status = (int)GlobalEnumVars.UserTocashStatus.提现成功;
|
||||||
|
|||||||
Reference in New Issue
Block a user