【新增】增加支付宝支付功能,方便APP调用。

This commit is contained in:
大灰灰
2022-09-15 00:35:15 +08:00
parent 0f922e1f32
commit a3630fecc0
12 changed files with 197 additions and 27 deletions

View File

@@ -413,10 +413,7 @@ namespace CoreCms.Net.Configuration
/// 微信自定义交易组件-同步创建售后单
/// </summary>
public const string TransactionComponentAfterSaleCreateSync = "TransactionComponentAfterSaleCreateSyncQueue";
//用户相关
@@ -428,6 +425,10 @@ namespace CoreCms.Net.Configuration
//发送微信模板消息
public const string MessageSendWxMessageTemplet = "MessageSendWxMessageTempletQueue";
/// <summary>
/// 支付宝支付成功后推送到接口进行数据处理
/// </summary>
public const string AliPayNotice = "AliPayNoticeQueue";
}

View File

@@ -46,6 +46,7 @@ namespace CoreCms.Net.Core.Config
typeof(SendWxTemplateMessageSubscribe),
typeof(AfterSalesReviewSubscribe),
typeof(AfterSalesReviewForPointSubscribe),
typeof(AliPayNoticeSubscribe),
};
//显示日志
m.ShowLog = false;

View File

@@ -8,6 +8,7 @@
* Description: 暂无
***********************************************************************/
using System.Threading.Tasks;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.UI;
@@ -23,6 +24,6 @@ namespace CoreCms.Net.IServices
/// </summary>
/// <param name="entity">实体数据</param>
/// <returns></returns>
WebApiCallBack PubPay(CoreCmsBillPayments entity);
Task<WebApiCallBack> PubPay(CoreCmsBillPayments entity);
}
}

View File

@@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Essensoft.Paylink.Alipay" Version="4.0.12" />
<PackageReference Include="Essensoft.Paylink.WeChatPay" Version="4.0.12" />
<PackageReference Include="InitQ" Version="1.0.0.12" />
<PackageReference Include="Qc.YilianyunSdk" Version="1.0.7" />

View File

@@ -0,0 +1,76 @@
/***********************************************************************
* Project: CoreCms
* ProjectName: 核心内容管理系统
* Web: https://www.corecms.net
* Author: 大灰灰
* Email: jianweie@163.com
* CreateTime: 2022/1/31 21:45:10
* Description: 暂无
***********************************************************************/
using System;
using System.Threading.Tasks;
using CoreCms.Net.Configuration;
using CoreCms.Net.IServices;
using CoreCms.Net.Loging;
using Essensoft.Paylink.Alipay;
using Essensoft.Paylink.Alipay.Notify;
using InitQ.Abstractions;
using InitQ.Attributes;
using Newtonsoft.Json;
namespace CoreCms.Net.RedisMQ.Subscribe
{
/// <summary>
/// 支付宝支付成功后推送到接口进行数据处理
/// </summary>
public class AliPayNoticeSubscribe : IRedisSubscribe
{
private readonly ICoreCmsBillPaymentsServices _billPaymentsServices;
public AliPayNoticeSubscribe(ICoreCmsBillPaymentsServices billPaymentsServices)
{
_billPaymentsServices = billPaymentsServices;
}
/// <summary>
/// 支付宝支付成功后推送到接口进行数据处理
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
[Subscribe(RedisMessageQueueKey.AliPayNotice)]
private async Task AliPayNotice(string msg)
{
try
{
var notify = JsonConvert.DeserializeObject<AlipayTradeAppPayNotify>(msg);
if (notify is { TradeStatus: AlipayTradeStatus.Success })
{
if (notify.TradeStatus == AlipayTradeStatus.Success)
{
var money = decimal.Parse(notify.TotalAmount);
await _billPaymentsServices.ToUpdate(notify.OutTradeNo,
(int)GlobalEnumVars.BillPaymentsStatus.Payed,
GlobalEnumVars.PaymentsTypes.alipay.ToString(), money, notify.TradeStatus,notify.TradeNo);
}
else
{
var money = decimal.Parse(notify.TotalAmount);
var message = notify.TradeStatus;
await _billPaymentsServices.ToUpdate(notify.OutTradeNo,
(int)GlobalEnumVars.BillPaymentsStatus.Other,
GlobalEnumVars.PaymentsTypes.alipay.ToString(), money, message, notify.TradeNo);
}
}
NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "支付宝支付成功后推送到接口进行数据处理", msg);
}
catch (Exception ex)
{
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "支付宝支付成功后推送到接口进行数据处理", msg, ex);
throw;
}
await Task.CompletedTask;
}
}
}

View File

@@ -479,7 +479,7 @@ namespace CoreCms.Net.Services
//支付宝支付
else if (paymentCode == GlobalEnumVars.PaymentsTypes.alipay.ToString())
{
jm = aliPayServices.PubPay(billPayments);
jm = await aliPayServices.PubPay(billPayments);
}
//余额支付

View File

@@ -6,6 +6,7 @@
<ItemGroup>
<PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.13.0" />
<PackageReference Include="Essensoft.Paylink.Alipay" Version="4.0.12" />
<PackageReference Include="Essensoft.Paylink.WeChatPay" Version="4.0.12" />
<PackageReference Include="Flurl.Http" Version="3.2.4" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />

View File

@@ -8,10 +8,21 @@
* Description: 暂无
***********************************************************************/
using CoreCms.Net.Configuration;
using CoreCms.Net.IRepository;
using CoreCms.Net.IServices;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.UI;
using Newtonsoft.Json;
using System.Threading.Tasks;
using NLog;
using System;
using Essensoft.Paylink.Alipay;
using Essensoft.Paylink.Alipay.Domain;
using Essensoft.Paylink.Alipay.Request;
using Microsoft.Extensions.DependencyInjection;
using Essensoft.Paylink.WeChatPay;
using Microsoft.Extensions.Options;
namespace CoreCms.Net.Services
{
@@ -20,20 +31,57 @@ namespace CoreCms.Net.Services
/// </summary>
public class AliPayServices : BaseServices<CoreCmsSetting>, IAliPayServices
{
public AliPayServices(IWeChatPayRepository dal)
private readonly IAlipayClient _client;
private readonly IServiceProvider _serviceProvider;
private readonly IOptions<AlipayOptions> _optionsAccessor;
public AliPayServices(IWeChatPayRepository dal, IServiceProvider serviceProvider, IAlipayClient client, IOptions<AlipayOptions> optionsAccessor)
{
_serviceProvider = serviceProvider;
_client = client;
_optionsAccessor = optionsAccessor;
BaseDal = dal;
}
/// <summary>
/// 发起支付
/// 发起支付宝支付
/// </summary>
/// <param name="entity">实体数据</param>
/// <returns></returns>
public WebApiCallBack PubPay(CoreCmsBillPayments entity)
public async Task<WebApiCallBack> PubPay(CoreCmsBillPayments entity)
{
var jm = new WebApiCallBack();
using var container = _serviceProvider.CreateScope();
var billPaymentsServices = container.ServiceProvider.GetService<ICoreCmsBillPaymentsServices>();
var payment = await billPaymentsServices.QueryByClauseAsync(p => p.paymentId == entity.paymentId);
var allPayUrl = AppSettingsConstVars.PayCallBackAlipayUrl;
var allPayReturnUrl = AppSettingsConstVars.PayCallBackAlipayUrl;
if (string.IsNullOrEmpty(allPayUrl))
{
jm.msg = "未获取到配置的回调地址";
return jm;
}
var model = new AlipayTradeAppPayModel
{
OutTradeNo = entity.paymentId,
Subject = entity.payTitle.Length > 40 ? entity.payTitle[..40] : entity.payTitle,
ProductCode = entity.paymentCode,
TotalAmount = entity.money.ToString(),
Body = entity.payTitle.Length > 40 ? entity.payTitle[..40] : entity.payTitle
};
var req = new AlipayTradeAppPayRequest();
req.SetBizModel(model);
req.SetNotifyUrl(allPayUrl);
Loging.NLogUtil.WriteAll(LogLevel.Trace, Loging.LogType.Order, "支付宝支付拼接APP入参", JsonConvert.SerializeObject(model));
var response = await _client.SdkExecuteAsync(req, _optionsAccessor.Value);
Loging.NLogUtil.WriteAll(LogLevel.Trace, Loging.LogType.Order, "支付宝支付返回数据", JsonConvert.SerializeObject(response));
jm.data = response.Body;
response.TradeNo = entity.paymentId;
jm.otherData = response;
jm.status = true;
return jm;
}
}
}

View File

@@ -139,18 +139,21 @@
switch (code) {
case 'alipay':
/**
* 支付宝支付需要模拟GET提交数据
*/
* 支付宝支付需要模拟GET提交数据
*/
console.log("支付宝支付入参app", data)
_this.$u.api.pay(data).then(res => {
//console.log("支付宝支付返回参数app", res)
//console.log("支付宝app支付get提交数据", res.data)
if (res.status) {
uni.requestPayment({
provider: "alipay",
orderInfo: res.data.data,
orderInfo: res.data,
success: function (data) {
_this.$refs.uToast.show({
message: '支付成功', type: 'success', complete: function () {
_this.redirectHandler(res.data.paymentId)
console.log("支付id", res.otherData.tradeNo)
_this.redirectHandler(res.otherData.tradeNo)
}
})
}
@@ -162,7 +165,7 @@
})
break
case 'wechatpay':
// 微信app支付
_this.$u.api.pay(data).then(res => {
if (res.status) {

View File

@@ -224,7 +224,7 @@
//微信退款回调
"WeChatRefundUrl": "https://api.pro.coreshop.cn/Notify/WeChatPay/Refund",
//支付宝支付回调
"AlipayUrl": "",
"AlipayUrl": "https://api.pro.coreshop.cn/Notify/AliPay/Unifiedorder",
//支付宝退款回调
"AlipayRefundUrl": ""
},

View File

@@ -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
}
}

View File

@@ -224,7 +224,7 @@
//微信退款回调
"WeChatRefundUrl": "https://api.pro.coreshop.cn/Notify/WeChatPay/Refund",
//支付宝支付回调
"AlipayUrl": "",
"AlipayUrl": "https://api.pro.coreshop.cn/Notify/AliPay/Unifiedorder",
//支付宝退款回调
"AlipayRefundUrl": ""
},