构建回调请求处理。

This commit is contained in:
jianweie code
2023-04-26 00:23:55 +08:00
parent 2bfbf7d139
commit 04a8b30413

View File

@@ -34,21 +34,26 @@ namespace CoreCms.Net.Web.WebApi.Controllers.PayNotify
private readonly ICoreCmsBillPaymentsServices _billPaymentsServices;
private readonly ICoreCmsBillRefundServices _billRefundServices;
private readonly IWeChatPayNotifyClient _client;
private readonly IOptions<WeChatPayOptions> _optionsAccessor;
//private readonly IOptions<WeChatPayOptions> _optionsAccessor;
private readonly IRedisOperationRepository _redisOperationRepository;
private readonly IWeChatPayConfigServices _weChatPayConfigServices;
/// <summary>
/// 构造函数
/// </summary>
public WeChatPayController(
IWeChatPayNotifyClient client
, IOptions<WeChatPayOptions> optionsAccessor
, ICoreCmsBillPaymentsServices billPaymentsServices, ICoreCmsBillRefundServices billRefundServices, IRedisOperationRepository redisOperationRepository)
//, IOptions<WeChatPayOptions> optionsAccessor
, ICoreCmsBillPaymentsServices billPaymentsServices, ICoreCmsBillRefundServices billRefundServices, IRedisOperationRepository redisOperationRepository, IWeChatPayConfigServices weChatPayConfigServices)
{
_client = client;
_optionsAccessor = optionsAccessor;
//_optionsAccessor = optionsAccessor;
_billPaymentsServices = billPaymentsServices;
_billRefundServices = billRefundServices;
_redisOperationRepository = redisOperationRepository;
_weChatPayConfigServices = weChatPayConfigServices;
}
/// <summary>
@@ -59,7 +64,23 @@ namespace CoreCms.Net.Web.WebApi.Controllers.PayNotify
{
try
{
var notify = await _client.ExecuteAsync<WeChatPayUnifiedOrderNotify>(Request, _optionsAccessor.Value);
var config = await _weChatPayConfigServices.QueryByClauseAsync(p => p.isDefault == true && p.isEnable == true);
//构建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 notify = await _client.ExecuteAsync<WeChatPayUnifiedOrderNotify>(Request, payOptions);
if (notify.ReturnCode == WeChatPayCode.Success)
{
await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.WeChatPayNotice,
@@ -84,7 +105,24 @@ namespace CoreCms.Net.Web.WebApi.Controllers.PayNotify
{
try
{
var notify = await _client.ExecuteAsync<WeChatPayRefundNotify>(Request, _optionsAccessor.Value);
var config = await _weChatPayConfigServices.QueryByClauseAsync(p => p.isDefault == true && p.isEnable == true);
//构建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 notify = await _client.ExecuteAsync<WeChatPayRefundNotify>(Request, payOptions);
NLogUtil.WriteAll(LogLevel.Trace, LogType.Refund, "微信退款结果通知", JsonConvert.SerializeObject(notify));
if (notify.ReturnCode == WeChatPayCode.Success)