mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 22:33:26 +08:00
87 lines
3.7 KiB
C#
87 lines
3.7 KiB
C#
/***********************************************************************
|
|
* Project: CoreCms
|
|
* ProjectName: 核心内容管理系统
|
|
* Web: https://www.corecms.net
|
|
* Author: 大灰灰
|
|
* Email: jianweie@163.com
|
|
* CreateTime: 2021/1/31 21:45:10
|
|
* 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
|
|
{
|
|
/// <summary>
|
|
/// 支付宝支付 接口实现
|
|
/// </summary>
|
|
public class AliPayServices : BaseServices<CoreCmsSetting>, IAliPayServices
|
|
{
|
|
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 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;
|
|
}
|
|
|
|
}
|
|
} |