mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 19:03:27 +08:00
制作微信支付和支付宝支付后台管理及业务处理
This commit is contained in:
@@ -37,14 +37,15 @@ namespace CoreCms.Net.Services
|
||||
{
|
||||
private readonly IAlipayClient _client;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IOptions<AlipayOptions> _optionsAccessor;
|
||||
private readonly IAlipayConfigServices _alipayConfigServices;
|
||||
|
||||
|
||||
public AliPayServices(IWeChatPayRepository dal, IServiceProvider serviceProvider, IAlipayClient client, IOptions<AlipayOptions> optionsAccessor)
|
||||
|
||||
public AliPayServices(IWeChatPayRepository dal, IServiceProvider serviceProvider, IAlipayClient client, IAlipayConfigServices alipayConfigServices)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_client = client;
|
||||
_optionsAccessor = optionsAccessor;
|
||||
_alipayConfigServices = alipayConfigServices;
|
||||
BaseDal = dal;
|
||||
}
|
||||
|
||||
@@ -58,24 +59,46 @@ namespace CoreCms.Net.Services
|
||||
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.PayCallBackAlipayRefundUrl;
|
||||
if (string.IsNullOrEmpty(allPayUrl))
|
||||
{
|
||||
jm.msg = "未获取到配置的回调地址";
|
||||
return jm;
|
||||
}
|
||||
|
||||
//var payment = await billPaymentsServices.QueryByClauseAsync(p => p.paymentId == entity.paymentId);
|
||||
|
||||
var tradeType = GlobalEnumVars.AliPayPayTradeType.ScanQRCodes.ToString();
|
||||
if (!string.IsNullOrEmpty(entity.parameters))
|
||||
{
|
||||
var jobj = (JObject)JsonConvert.DeserializeObject(entity.parameters);
|
||||
if (jobj != null && jobj.ContainsKey("trade_type"))
|
||||
tradeType = GetTradeType(jobj["trade_type"].ObjectToString());
|
||||
var jObj = (JObject)JsonConvert.DeserializeObject(entity.parameters);
|
||||
if (jObj != null && jObj.TryGetValue("trade_type", out var value))
|
||||
tradeType = GetTradeType(value.ObjectToString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
var config = await _alipayConfigServices.QueryByClauseAsync(p =>
|
||||
p.isDefault == true && p.isEnable == true && p.appType == tradeType);
|
||||
if (config == null)
|
||||
{
|
||||
jm.msg = "支付配置信息获取失败";
|
||||
return jm;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(config.notifyUrl))
|
||||
{
|
||||
jm.msg = "未获取到配置的通知地址";
|
||||
return jm;
|
||||
}
|
||||
|
||||
//构建linkPay请求配置实体
|
||||
var payOptions = new AlipayOptions
|
||||
{
|
||||
AppId = config.appId,
|
||||
AlipayPublicKey = config.publicKey,
|
||||
AppPrivateKey = config.privateKey,
|
||||
ServerUrl = config.serverUrl,
|
||||
SignType = config.signType,
|
||||
AppPublicCert = config.appPublicCert,
|
||||
AlipayPublicCert = config.alipayPublicCert,
|
||||
AlipayRootCert = config.alipayRootCert
|
||||
};
|
||||
|
||||
|
||||
//扫码支付
|
||||
if (tradeType == GlobalEnumVars.AliPayPayTradeType.ScanQRCodes.ToString())
|
||||
{
|
||||
@@ -89,11 +112,11 @@ namespace CoreCms.Net.Services
|
||||
};
|
||||
var req = new AlipayTradePrecreateRequest();
|
||||
req.SetBizModel(model);
|
||||
req.SetNotifyUrl(allPayUrl);
|
||||
req.SetReturnUrl(allPayReturnUrl);
|
||||
req.SetNotifyUrl(config.notifyUrl);
|
||||
//req.SetReturnUrl("https://pc.pro.demo.corecms.cn/order/payment/result");
|
||||
|
||||
Loging.NLogUtil.WriteAll(LogLevel.Trace, Loging.LogType.Order, "支付宝ScanQRCodes支付拼接APP入参", JsonConvert.SerializeObject(model));
|
||||
var response = await _client.ExecuteAsync(req, _optionsAccessor.Value);
|
||||
var response = await _client.ExecuteAsync(req, payOptions);
|
||||
Loging.NLogUtil.WriteAll(LogLevel.Trace, Loging.LogType.Order, "支付宝ScanQRCodes支付返回数据", JsonConvert.SerializeObject(response));
|
||||
|
||||
|
||||
@@ -116,12 +139,11 @@ namespace CoreCms.Net.Services
|
||||
};
|
||||
var req = new AlipayTradePagePayRequest();
|
||||
req.SetBizModel(model);
|
||||
req.SetNotifyUrl(allPayUrl);
|
||||
req.SetReturnUrl(allPayReturnUrl);
|
||||
|
||||
req.SetNotifyUrl(config.notifyUrl);
|
||||
req.SetReturnUrl(config.jumpUrl);
|
||||
|
||||
Loging.NLogUtil.WriteAll(LogLevel.Trace, Loging.LogType.Order, "支付宝JSAPI_PC支付拼接APP入参", JsonConvert.SerializeObject(model));
|
||||
var response = await _client.PageExecuteAsync(req, _optionsAccessor.Value);
|
||||
var response = await _client.PageExecuteAsync(req, payOptions);
|
||||
Loging.NLogUtil.WriteAll(LogLevel.Trace, Loging.LogType.Order, "支付宝JSAPI_PC支付返回数据", JsonConvert.SerializeObject(response));
|
||||
|
||||
|
||||
@@ -144,12 +166,11 @@ namespace CoreCms.Net.Services
|
||||
};
|
||||
var req = new AlipayTradeAppPayRequest();
|
||||
req.SetBizModel(model);
|
||||
req.SetNotifyUrl(allPayUrl);
|
||||
req.SetReturnUrl(allPayReturnUrl);
|
||||
|
||||
req.SetNotifyUrl(config.notifyUrl);
|
||||
//req.SetReturnUrl(config.jumpUrl);
|
||||
|
||||
Loging.NLogUtil.WriteAll(LogLevel.Trace, Loging.LogType.Order, "支付宝APP支付拼接APP入参", JsonConvert.SerializeObject(model));
|
||||
var response = await _client.SdkExecuteAsync(req, _optionsAccessor.Value);
|
||||
var response = await _client.SdkExecuteAsync(req, payOptions);
|
||||
Loging.NLogUtil.WriteAll(LogLevel.Trace, Loging.LogType.Order, "支付宝APP支付返回数据", JsonConvert.SerializeObject(response));
|
||||
|
||||
|
||||
@@ -172,12 +193,11 @@ namespace CoreCms.Net.Services
|
||||
};
|
||||
var req = new AlipayTradeWapPayRequest();
|
||||
req.SetBizModel(model);
|
||||
req.SetNotifyUrl(allPayUrl);
|
||||
req.SetReturnUrl(allPayReturnUrl);
|
||||
|
||||
req.SetNotifyUrl(config.notifyUrl);
|
||||
req.SetReturnUrl(config.jumpUrl);
|
||||
|
||||
Loging.NLogUtil.WriteAll(LogLevel.Trace, Loging.LogType.Order, "支付宝MWEB支付拼接APP入参", JsonConvert.SerializeObject(model));
|
||||
var response = await _client.PageExecuteAsync(req, _optionsAccessor.Value);
|
||||
var response = await _client.PageExecuteAsync(req, payOptions);
|
||||
Loging.NLogUtil.WriteAll(LogLevel.Trace, Loging.LogType.Order, "支付宝MWEB支付返回数据", JsonConvert.SerializeObject(response));
|
||||
|
||||
|
||||
|
||||
129
CoreCms.Net.Services/Pay/AlipayConfigServices.cs
Normal file
129
CoreCms.Net.Services/Pay/AlipayConfigServices.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2023/4/20 23:33:03
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IRepository;
|
||||
using CoreCms.Net.IRepository.UnitOfWork;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.ViewModels.Basics;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using SqlSugar;
|
||||
|
||||
|
||||
namespace CoreCms.Net.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// 支付宝支付配置 接口实现
|
||||
/// </summary>
|
||||
public class AlipayConfigServices : BaseServices<CoreCmsAlipayConfig>, IAlipayConfigServices
|
||||
{
|
||||
private readonly IAlipayConfigRepository _dal;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public AlipayConfigServices(IUnitOfWork unitOfWork, IAlipayConfigRepository dal)
|
||||
{
|
||||
this._dal = dal;
|
||||
base.BaseDal = dal;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
#region 实现重写增删改查操作==========================================================
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步插入方法
|
||||
/// </summary>
|
||||
/// <param name="entity">实体数据</param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> InsertAsync(CoreCmsAlipayConfig entity)
|
||||
{
|
||||
return await _dal.InsertAsync(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步更新方法方法
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> UpdateAsync(CoreCmsAlipayConfig entity)
|
||||
{
|
||||
return await _dal.UpdateAsync(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步更新方法方法
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> UpdateAsync(List<CoreCmsAlipayConfig> entity)
|
||||
{
|
||||
return await _dal.UpdateAsync(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写删除指定ID的数据
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> DeleteByIdAsync(object id)
|
||||
{
|
||||
return await _dal.DeleteByIdAsync(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写删除指定ID集合的数据(批量删除)
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> DeleteByIdsAsync(int[] ids)
|
||||
{
|
||||
return await _dal.DeleteByIdsAsync(ids);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取缓存的所有数据==========================================================
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存的所有数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<CoreCmsAlipayConfig>> GetCaChe()
|
||||
{
|
||||
return await _dal.GetCaChe();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 重写根据条件查询分页数据
|
||||
/// <summary>
|
||||
/// 重写根据条件查询分页数据
|
||||
/// </summary>
|
||||
/// <param name="predicate">判断集合</param>
|
||||
/// <param name="orderByType">排序方式</param>
|
||||
/// <param name="pageIndex">当前页面索引</param>
|
||||
/// <param name="pageSize">分布大小</param>
|
||||
/// <param name="orderByExpression"></param>
|
||||
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
|
||||
/// <returns></returns>
|
||||
public async Task<IPageList<CoreCmsAlipayConfig>> QueryPageAsync(Expression<Func<CoreCmsAlipayConfig, bool>> predicate,
|
||||
Expression<Func<CoreCmsAlipayConfig, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
|
||||
int pageSize = 20, bool blUseNoLock = false)
|
||||
{
|
||||
return await _dal.QueryPageAsync(predicate, orderByExpression, orderByType, pageIndex, pageSize, blUseNoLock);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
129
CoreCms.Net.Services/Pay/WeChatPayConfigServices.cs
Normal file
129
CoreCms.Net.Services/Pay/WeChatPayConfigServices.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2023/4/20 23:42:07
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IRepository;
|
||||
using CoreCms.Net.IRepository.UnitOfWork;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.ViewModels.Basics;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using SqlSugar;
|
||||
|
||||
|
||||
namespace CoreCms.Net.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// 微信支付配置 接口实现
|
||||
/// </summary>
|
||||
public class WeChatPayConfigServices : BaseServices<CoreCmsWeChatPayConfig>, IWeChatPayConfigServices
|
||||
{
|
||||
private readonly IWeChatPayConfigRepository _dal;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public WeChatPayConfigServices(IUnitOfWork unitOfWork, IWeChatPayConfigRepository dal)
|
||||
{
|
||||
this._dal = dal;
|
||||
base.BaseDal = dal;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
#region 实现重写增删改查操作==========================================================
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步插入方法
|
||||
/// </summary>
|
||||
/// <param name="entity">实体数据</param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> InsertAsync(CoreCmsWeChatPayConfig entity)
|
||||
{
|
||||
return await _dal.InsertAsync(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步更新方法方法
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> UpdateAsync(CoreCmsWeChatPayConfig entity)
|
||||
{
|
||||
return await _dal.UpdateAsync(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步更新方法方法
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> UpdateAsync(List<CoreCmsWeChatPayConfig> entity)
|
||||
{
|
||||
return await _dal.UpdateAsync(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写删除指定ID的数据
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> DeleteByIdAsync(object id)
|
||||
{
|
||||
return await _dal.DeleteByIdAsync(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写删除指定ID集合的数据(批量删除)
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> DeleteByIdsAsync(int[] ids)
|
||||
{
|
||||
return await _dal.DeleteByIdsAsync(ids);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取缓存的所有数据==========================================================
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存的所有数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<CoreCmsWeChatPayConfig>> GetCaChe()
|
||||
{
|
||||
return await _dal.GetCaChe();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 重写根据条件查询分页数据
|
||||
/// <summary>
|
||||
/// 重写根据条件查询分页数据
|
||||
/// </summary>
|
||||
/// <param name="predicate">判断集合</param>
|
||||
/// <param name="orderByType">排序方式</param>
|
||||
/// <param name="pageIndex">当前页面索引</param>
|
||||
/// <param name="pageSize">分布大小</param>
|
||||
/// <param name="orderByExpression"></param>
|
||||
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
|
||||
/// <returns></returns>
|
||||
public async Task<IPageList<CoreCmsWeChatPayConfig>> QueryPageAsync(Expression<Func<CoreCmsWeChatPayConfig, bool>> predicate,
|
||||
Expression<Func<CoreCmsWeChatPayConfig, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
|
||||
int pageSize = 20, bool blUseNoLock = false)
|
||||
{
|
||||
return await _dal.QueryPageAsync(predicate, orderByExpression, orderByType, pageIndex, pageSize, blUseNoLock);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@
|
||||
***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Auth.HttpContextUser;
|
||||
using CoreCms.Net.Caching.AccressToken;
|
||||
@@ -20,12 +19,10 @@ using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using CoreCms.Net.WeChat.Service.HttpClients;
|
||||
using Essensoft.Paylink.Alipay.Domain;
|
||||
using Essensoft.Paylink.WeChatPay;
|
||||
using Essensoft.Paylink.WeChatPay.V2;
|
||||
using Essensoft.Paylink.WeChatPay.V2.Request;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using QRCoder;
|
||||
@@ -40,12 +37,11 @@ namespace CoreCms.Net.Services
|
||||
public class WeChatPayServices : BaseServices<CoreCmsSetting>, IWeChatPayServices
|
||||
{
|
||||
private readonly IWeChatPayClient _client;
|
||||
private readonly IOptions<WeChatPayOptions> _optionsAccessor;
|
||||
private readonly IHttpContextUser _user;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly WeChat.Service.HttpClients.IWeChatApiHttpClientFactory _weChatApiHttpClientFactory;
|
||||
|
||||
private readonly IWeChatApiHttpClientFactory _weChatApiHttpClientFactory;
|
||||
|
||||
private readonly IWeChatPayConfigServices _weChatPayConfigServices;
|
||||
|
||||
private readonly ICoreCmsUserServices _userServices;
|
||||
private readonly ICoreCmsUserWeChatInfoServices _userWeChatInfoServices;
|
||||
@@ -53,18 +49,17 @@ namespace CoreCms.Net.Services
|
||||
|
||||
public WeChatPayServices(IHttpContextUser user
|
||||
, IWeChatPayClient client
|
||||
, IOptions<WeChatPayOptions> optionsAccessor
|
||||
, ICoreCmsUserServices userServices
|
||||
, ICoreCmsUserWeChatInfoServices userWeChatInfoServices, IServiceProvider serviceProvider, IWeChatApiHttpClientFactory weChatApiHttpClientFactory)
|
||||
, ICoreCmsUserWeChatInfoServices userWeChatInfoServices, IServiceProvider serviceProvider, IWeChatApiHttpClientFactory weChatApiHttpClientFactory, IWeChatPayConfigServices weChatPayConfigServices)
|
||||
{
|
||||
|
||||
_client = client;
|
||||
_optionsAccessor = optionsAccessor;
|
||||
_user = user;
|
||||
_userServices = userServices;
|
||||
_userWeChatInfoServices = userWeChatInfoServices;
|
||||
_serviceProvider = serviceProvider;
|
||||
_weChatApiHttpClientFactory = weChatApiHttpClientFactory;
|
||||
_weChatPayConfigServices = weChatPayConfigServices;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -92,12 +87,13 @@ namespace CoreCms.Net.Services
|
||||
var accessToken = WeChatCacheAccessTokenHelper.GetWxOpenAccessToken();
|
||||
var client = _weChatApiHttpClientFactory.CreateWxOpenClient();
|
||||
|
||||
var getPaymentParameters = new ShopOrderGetPaymentParametersRequest();
|
||||
|
||||
getPaymentParameters.AccessToken = accessToken;
|
||||
getPaymentParameters.OpenId = order.openid;
|
||||
getPaymentParameters.OrderId = order.orderId;
|
||||
getPaymentParameters.OutOrderId = order.outOrderId;
|
||||
var getPaymentParameters = new ShopOrderGetPaymentParametersRequest
|
||||
{
|
||||
AccessToken = accessToken,
|
||||
OpenId = order.openid,
|
||||
OrderId = order.orderId,
|
||||
OutOrderId = order.outOrderId
|
||||
};
|
||||
|
||||
var shopOrderGetPayment = await client.ExecuteShopOrderGetPaymentParametersAsync(getPaymentParameters);
|
||||
if (shopOrderGetPayment.IsSuccessful())
|
||||
@@ -121,20 +117,42 @@ namespace CoreCms.Net.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
var weChatPayUrl = AppSettingsConstVars.PayCallBackWeChatPayUrl;
|
||||
if (string.IsNullOrEmpty(weChatPayUrl))
|
||||
|
||||
var tradeType = GlobalEnumVars.WeiChatPayTradeType.JSAPI.ToString();
|
||||
if (!string.IsNullOrEmpty(entity.parameters))
|
||||
{
|
||||
var jObj = (JObject)JsonConvert.DeserializeObject(entity.parameters);
|
||||
if (jObj != null && jObj.TryGetValue("trade_type", out var value))
|
||||
tradeType = GetTradeType(value.ObjectToString());
|
||||
}
|
||||
|
||||
|
||||
var config = await _weChatPayConfigServices.QueryByClauseAsync(p =>
|
||||
p.isDefault == true && p.isEnable == true && p.appType == tradeType);
|
||||
if (config == null)
|
||||
{
|
||||
jm.msg = "支付配置信息获取失败";
|
||||
return jm;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(config.notifyUrl))
|
||||
{
|
||||
jm.msg = "未获取到配置的通知地址";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var tradeType = GlobalEnumVars.WeiChatPayTradeType.JSAPI.ToString();
|
||||
if (!string.IsNullOrEmpty(entity.parameters))
|
||||
//构建linkPay请求配置实体
|
||||
var payOptions = new WeChatPayOptions
|
||||
{
|
||||
var jobj = (JObject)JsonConvert.DeserializeObject(entity.parameters);
|
||||
if (jobj != null && jobj.ContainsKey("trade_type"))
|
||||
tradeType = GetTradeType(jobj["trade_type"].ObjectToString());
|
||||
}
|
||||
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 openId = string.Empty;
|
||||
if (tradeType == GlobalEnumVars.WeiChatPayTradeType.JSAPI.ToString())
|
||||
@@ -168,14 +186,14 @@ namespace CoreCms.Net.Services
|
||||
OutTradeNo = entity.paymentId,
|
||||
TotalFee = Convert.ToInt32(entity.money * 100),
|
||||
SpBillCreateIp = entity.ip,
|
||||
NotifyUrl = weChatPayUrl,
|
||||
NotifyUrl = config.notifyUrl,
|
||||
TradeType = tradeType,
|
||||
//OpenId = openId
|
||||
};
|
||||
|
||||
if (tradeType == GlobalEnumVars.WeiChatPayTradeType.JSAPI.ToString())
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_optionsAccessor.Value.SubMchId))
|
||||
if (!string.IsNullOrEmpty(payOptions.SubMchId))
|
||||
{
|
||||
orderRequest.SubOpenId = openId;
|
||||
}
|
||||
@@ -185,7 +203,7 @@ namespace CoreCms.Net.Services
|
||||
}
|
||||
}
|
||||
|
||||
var response = await _client.ExecuteAsync(orderRequest, _optionsAccessor.Value);
|
||||
var response = await _client.ExecuteAsync(orderRequest, payOptions);
|
||||
if (response.ReturnCode == WeChatPayCode.Success && response.ResultCode == WeChatPayCode.Success)
|
||||
{
|
||||
//App微信支付
|
||||
@@ -195,7 +213,7 @@ namespace CoreCms.Net.Services
|
||||
{
|
||||
PrepayId = response.PrepayId
|
||||
};
|
||||
var parameter = await _client.ExecuteAsync(reqApp, _optionsAccessor.Value);
|
||||
var parameter = await _client.ExecuteAsync(reqApp, payOptions);
|
||||
parameter.Add("paymentId", entity.paymentId);
|
||||
jm.status = true;
|
||||
jm.msg = "创建微信APP支付环境成功";
|
||||
@@ -210,7 +228,7 @@ namespace CoreCms.Net.Services
|
||||
{
|
||||
Package = "prepay_id=" + response.PrepayId
|
||||
};
|
||||
var parameter = await _client.ExecuteAsync(req, _optionsAccessor.Value);
|
||||
var parameter = await _client.ExecuteAsync(req, payOptions);
|
||||
parameter.Add("paymentId", entity.paymentId);
|
||||
jm.status = true;
|
||||
jm.msg = "创建JSAPI支付环境成功";
|
||||
@@ -268,13 +286,42 @@ namespace CoreCms.Net.Services
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var weChatRefundUrl = AppSettingsConstVars.PayCallBackWeChatRefundUrl;
|
||||
if (string.IsNullOrEmpty(weChatRefundUrl))
|
||||
var tradeType = GlobalEnumVars.WeiChatPayTradeType.JSAPI.ToString();
|
||||
if (!string.IsNullOrEmpty(paymentInfo.parameters))
|
||||
{
|
||||
jm.msg = "未获取到配置的通知地址";
|
||||
var jObj = (JObject)JsonConvert.DeserializeObject(paymentInfo.parameters);
|
||||
if (jObj != null && jObj.TryGetValue("trade_type", out var value))
|
||||
tradeType = GetTradeType(value.ObjectToString());
|
||||
}
|
||||
|
||||
var config = await _weChatPayConfigServices.QueryByClauseAsync(p =>
|
||||
p.isDefault == true && p.isEnable == true && p.appType == tradeType);
|
||||
if (config == null)
|
||||
{
|
||||
jm.msg = "支付配置信息获取失败";
|
||||
return jm;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(config.refundUrl))
|
||||
{
|
||||
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 request = new WeChatPayRefundRequest
|
||||
{
|
||||
OutRefundNo = refundInfo.refundId,
|
||||
@@ -282,9 +329,9 @@ namespace CoreCms.Net.Services
|
||||
OutTradeNo = paymentInfo.paymentId,
|
||||
TotalFee = Convert.ToInt32(paymentInfo.money * 100),
|
||||
RefundFee = Convert.ToInt32(refundInfo.money * 100),
|
||||
NotifyUrl = weChatRefundUrl
|
||||
NotifyUrl = config.refundUrl
|
||||
};
|
||||
var response = await _client.ExecuteAsync(request, _optionsAccessor.Value);
|
||||
var response = await _client.ExecuteAsync(request, payOptions);
|
||||
|
||||
if (response.ReturnCode == WeChatPayCode.Success && response.ResultCode == WeChatPayCode.Success)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user