mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2026-02-05 16:09:49 +08:00
【新增】增加支付宝支付功能,方便APP调用。
This commit is contained in:
@@ -7,38 +7,76 @@
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using CoreCms.Net.Caching.AutoMate.RedisCache;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.Loging;
|
||||
using Essensoft.Paylink.Alipay;
|
||||
using Essensoft.Paylink.Alipay.Notify;
|
||||
using Essensoft.Paylink.Alipay.Utility;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers.PayNotify
|
||||
{
|
||||
/// <summary>
|
||||
/// 支付宝异步通知
|
||||
/// 支付宝异步通知
|
||||
/// </summary>
|
||||
[Route("Notify/[controller]/[action]")]
|
||||
public class AliPayController : ControllerBase
|
||||
{
|
||||
private readonly IAlipayNotifyClient _client;
|
||||
private readonly IOptions<AlipayOptions> _optionsAccessor;
|
||||
private readonly IRedisOperationRepository _redisOperationRepository;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="optionsAccessor"></param>
|
||||
public AliPayController(IAlipayNotifyClient client, IOptions<AlipayOptions> optionsAccessor)
|
||||
/// <param name="redisOperationRepository"></param>
|
||||
public AliPayController(IAlipayNotifyClient client, IOptions<AlipayOptions> optionsAccessor, IRedisOperationRepository redisOperationRepository)
|
||||
{
|
||||
_client = client;
|
||||
_optionsAccessor = optionsAccessor;
|
||||
_redisOperationRepository = redisOperationRepository;
|
||||
}
|
||||
#region 支付宝统一回调接口
|
||||
/// <summary>
|
||||
/// APP支付统一下单支付结果通知
|
||||
/// https://api.pro.coreshop.cn/Notify/AliPay/Unifiedorder
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Unifiedorder()
|
||||
{
|
||||
NLogUtil.WriteAll(LogLevel.Trace, LogType.Order, "支付宝支付回调开始", "支付宝回调开始数据标记");
|
||||
try
|
||||
{
|
||||
var notify = await _client.ExecuteAsync<AlipayTradeAppPayNotify>(Request, _optionsAccessor.Value);
|
||||
NLogUtil.WriteAll(LogLevel.Trace, LogType.Order, "支付宝支付回调支付宝返回的参数", JsonConvert.SerializeObject(notify));
|
||||
if (notify.TradeStatus == AlipayTradeStatus.Success)
|
||||
{
|
||||
NLogUtil.WriteAll(LogLevel.Trace, LogType.Order, "支付宝支付回调开始处理订单业务,队列名称:", RedisMessageQueueKey.AliPayNotice);
|
||||
await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.AliPayNotice, JsonConvert.SerializeObject(notify));
|
||||
return AlipayNotifyResult.Success;
|
||||
}
|
||||
NLogUtil.WriteAll(LogLevel.Trace, LogType.Order, "支付宝支付成功回调", JsonConvert.SerializeObject(notify));
|
||||
return NoContent();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NLogUtil.WriteAll(LogLevel.Trace, LogType.Order, "支付宝支付成功回调", "统一下单支付结果通知", ex);
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 其他
|
||||
/// <summary>
|
||||
/// 应用网关
|
||||
/// </summary>
|
||||
@@ -57,7 +95,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers.PayNotify
|
||||
var options = _optionsAccessor.Value;
|
||||
|
||||
// 获取参数
|
||||
var parameters =await _client.GetParametersAsync(Request);
|
||||
var parameters = await _client.GetParametersAsync(Request);
|
||||
var sign = parameters["sign"];
|
||||
parameters.Remove("sign");
|
||||
|
||||
@@ -146,17 +184,18 @@ namespace CoreCms.Net.Web.WebApi.Controllers.PayNotify
|
||||
{
|
||||
try
|
||||
{
|
||||
var notify = await _client.CertificateExecuteAsync<AlipayTradePrecreateNotify>(Request, _optionsAccessor.Value);
|
||||
var notify = await _client.ExecuteAsync<AlipayTradeAppPayNotify>(Request, _optionsAccessor.Value);
|
||||
if (notify.TradeStatus == AlipayTradeStatus.Success)
|
||||
{
|
||||
Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
|
||||
|
||||
await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.AliPayNotice, JsonConvert.SerializeObject(notify));
|
||||
return AlipayNotifyResult.Success;
|
||||
}
|
||||
NLogUtil.WriteAll(LogLevel.Trace, LogType.Order, "支付宝支付成功回调", JsonConvert.SerializeObject(notify));
|
||||
return NoContent();
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
NLogUtil.WriteAll(LogLevel.Trace, LogType.Order, "支付宝支付成功回调", "统一下单支付结果通知", ex);
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
@@ -183,7 +222,6 @@ namespace CoreCms.Net.Web.WebApi.Controllers.PayNotify
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 电脑网站支付异步通知
|
||||
/// </summary>
|
||||
@@ -278,6 +316,6 @@ namespace CoreCms.Net.Web.WebApi.Controllers.PayNotify
|
||||
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user