mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 17:53:25 +08:00
优化支付宝支付状态查询处理
This commit is contained in:
@@ -19,6 +19,7 @@ using NLog;
|
|||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using CoreCms.Net.Utility.Extensions;
|
using CoreCms.Net.Utility.Extensions;
|
||||||
|
using CoreCms.Net.Utility.Helper;
|
||||||
using Essensoft.Paylink.Alipay;
|
using Essensoft.Paylink.Alipay;
|
||||||
using Essensoft.Paylink.Alipay.Domain;
|
using Essensoft.Paylink.Alipay.Domain;
|
||||||
using Essensoft.Paylink.Alipay.Request;
|
using Essensoft.Paylink.Alipay.Request;
|
||||||
@@ -66,7 +67,7 @@ namespace CoreCms.Net.Services
|
|||||||
{
|
{
|
||||||
var jObj = (JObject)JsonConvert.DeserializeObject(entity.parameters);
|
var jObj = (JObject)JsonConvert.DeserializeObject(entity.parameters);
|
||||||
if (jObj != null && jObj.TryGetValue("trade_type", out var value))
|
if (jObj != null && jObj.TryGetValue("trade_type", out var value))
|
||||||
tradeType = GetTradeType(value.ObjectToString());
|
tradeType = PayHelper.GetAliPayPayTradeType(value.ObjectToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -217,25 +218,6 @@ namespace CoreCms.Net.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static string GetTradeType(string tradeType)
|
|
||||||
{
|
|
||||||
if (tradeType != GlobalEnumVars.AliPayPayTradeType.JSAPI.ToString() &&
|
|
||||||
tradeType != GlobalEnumVars.AliPayPayTradeType.JSAPI_PC.ToString() &&
|
|
||||||
tradeType != GlobalEnumVars.AliPayPayTradeType.ScanQRCodes.ToString() &&
|
|
||||||
tradeType != GlobalEnumVars.AliPayPayTradeType.APP.ToString() &&
|
|
||||||
tradeType != GlobalEnumVars.AliPayPayTradeType.MWEB.ToString()
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return GlobalEnumVars.AliPayPayTradeType.JSAPI_PC.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
//if (tradeType == GlobalEnumVars.AliPayPayTradeType.JSAPI_PC.ToString())
|
|
||||||
//{
|
|
||||||
// return GlobalEnumVars.AliPayPayTradeType.JSAPI_PC.ToString();
|
|
||||||
//}
|
|
||||||
return tradeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,5 +30,26 @@ namespace CoreCms.Net.Utility.Helper
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取支付宝支付类型
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tradeType"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string GetAliPayPayTradeType(string tradeType)
|
||||||
|
{
|
||||||
|
if (tradeType != GlobalEnumVars.AliPayPayTradeType.JSAPI.ToString() &&
|
||||||
|
tradeType != GlobalEnumVars.AliPayPayTradeType.JSAPI_PC.ToString() &&
|
||||||
|
tradeType != GlobalEnumVars.AliPayPayTradeType.ScanQRCodes.ToString() &&
|
||||||
|
tradeType != GlobalEnumVars.AliPayPayTradeType.APP.ToString() &&
|
||||||
|
tradeType != GlobalEnumVars.AliPayPayTradeType.MWEB.ToString()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return GlobalEnumVars.AliPayPayTradeType.JSAPI_PC.ToString();
|
||||||
|
}
|
||||||
|
return tradeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ using Newtonsoft.Json;
|
|||||||
using NPOI.HSSF.UserModel;
|
using NPOI.HSSF.UserModel;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using CoreCms.Net.Services;
|
using CoreCms.Net.Services;
|
||||||
|
using Essensoft.Paylink.Alipay;
|
||||||
|
using Essensoft.Paylink.Alipay.Domain;
|
||||||
|
using Essensoft.Paylink.Alipay.Request;
|
||||||
|
|
||||||
namespace CoreCms.Net.Web.Admin.Controllers
|
namespace CoreCms.Net.Web.Admin.Controllers
|
||||||
{
|
{
|
||||||
@@ -51,25 +54,26 @@ namespace CoreCms.Net.Web.Admin.Controllers
|
|||||||
{
|
{
|
||||||
private readonly ICoreCmsBillPaymentsServices _coreCmsBillPaymentsServices;
|
private readonly ICoreCmsBillPaymentsServices _coreCmsBillPaymentsServices;
|
||||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||||
private readonly IWeChatPayClient _client;
|
private readonly IWeChatPayClient _clientWeCaht;
|
||||||
|
private readonly IAlipayClient _clientAlipay;
|
||||||
|
|
||||||
|
|
||||||
private readonly IWeChatPayConfigServices _weChatPayConfigServices;
|
private readonly IWeChatPayConfigServices _weChatPayConfigServices;
|
||||||
|
private readonly IAlipayConfigServices _alipayConfigServices;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="webHostEnvironment"></param>
|
|
||||||
/// <param name="coreCmsBillPaymentsServices"></param>
|
|
||||||
/// <param name="client"></param>
|
|
||||||
/// <param name="weChatPayConfigServices"></param>
|
|
||||||
public CoreCmsBillPaymentsController(IWebHostEnvironment webHostEnvironment
|
public CoreCmsBillPaymentsController(IWebHostEnvironment webHostEnvironment
|
||||||
, ICoreCmsBillPaymentsServices coreCmsBillPaymentsServices, IWeChatPayClient client, IWeChatPayConfigServices weChatPayConfigServices)
|
, ICoreCmsBillPaymentsServices coreCmsBillPaymentsServices, IWeChatPayClient client, IWeChatPayConfigServices weChatPayConfigServices, IAlipayConfigServices alipayConfigServices, IAlipayClient clientAlipay)
|
||||||
{
|
{
|
||||||
_webHostEnvironment = webHostEnvironment;
|
_webHostEnvironment = webHostEnvironment;
|
||||||
_coreCmsBillPaymentsServices = coreCmsBillPaymentsServices;
|
_coreCmsBillPaymentsServices = coreCmsBillPaymentsServices;
|
||||||
_client = client;
|
_clientWeCaht = client;
|
||||||
_weChatPayConfigServices = weChatPayConfigServices;
|
_weChatPayConfigServices = weChatPayConfigServices;
|
||||||
|
_alipayConfigServices = alipayConfigServices;
|
||||||
|
_clientAlipay = clientAlipay;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 获取列表============================================================
|
#region 获取列表============================================================
|
||||||
@@ -563,7 +567,7 @@ namespace CoreCms.Net.Web.Admin.Controllers
|
|||||||
//商户订单号
|
//商户订单号
|
||||||
OutTradeNo = model.paymentId
|
OutTradeNo = model.paymentId
|
||||||
};
|
};
|
||||||
var response = await _client.ExecuteAsync(request, payOptions);
|
var response = await _clientWeCaht.ExecuteAsync(request, payOptions);
|
||||||
|
|
||||||
if (response is { ReturnCode: WeChatPayCode.Success, ResultCode: WeChatPayCode.Success, TradeState: WeChatPayCode.Success })
|
if (response is { ReturnCode: WeChatPayCode.Success, ResultCode: WeChatPayCode.Success, TradeState: WeChatPayCode.Success })
|
||||||
{
|
{
|
||||||
@@ -575,22 +579,79 @@ namespace CoreCms.Net.Web.Admin.Controllers
|
|||||||
|
|
||||||
jm.code = 0;
|
jm.code = 0;
|
||||||
jm.msg = "刷新成功";
|
jm.msg = "刷新成功";
|
||||||
jm.data = response;
|
//jm.data = response;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jm.code = 1;
|
jm.code = 1;
|
||||||
jm.data = response;
|
//jm.data = response;
|
||||||
jm.msg = response.TradeState == "NOTPAY" ? response.TradeStateDesc : response.ErrCodeDes;
|
jm.msg = response.TradeState == "NOTPAY" ? response.TradeStateDesc : response.ErrCodeDes;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (model.paymentCode == GlobalEnumVars.PaymentsTypes.alipay.ToString())
|
else if (model.paymentCode == GlobalEnumVars.PaymentsTypes.alipay.ToString())
|
||||||
{
|
{
|
||||||
|
var tradeType = GlobalEnumVars.AliPayPayTradeType.ScanQRCodes.ToString();
|
||||||
|
if (!string.IsNullOrEmpty(model.parameters))
|
||||||
|
{
|
||||||
|
var jObj = (JObject)JsonConvert.DeserializeObject(model.parameters);
|
||||||
|
if (jObj != null && jObj.TryGetValue("trade_type", out var value))
|
||||||
|
tradeType = PayHelper.GetAliPayPayTradeType(value.ObjectToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
var config = await _alipayConfigServices.QueryByClauseAsync(p => p.isDefault == true && p.isEnable == true && p.appType == tradeType);
|
||||||
|
if (config == null)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
};
|
||||||
|
|
||||||
|
var request = new AlipayTradeQueryModel
|
||||||
|
{
|
||||||
|
OutTradeNo = model.paymentId,
|
||||||
|
//TradeNo = viewMode.TradeNo
|
||||||
|
};
|
||||||
|
|
||||||
|
var req = new AlipayTradeQueryRequest();
|
||||||
|
req.SetBizModel(request);
|
||||||
|
|
||||||
|
var response = await _clientAlipay.ExecuteAsync(req, payOptions);
|
||||||
|
|
||||||
|
if (response is { Code: "10000", IsError: false })
|
||||||
|
{
|
||||||
|
var money = Convert.ToDecimal(response.PayAmount);
|
||||||
|
await _coreCmsBillPaymentsServices.ToUpdate(response.OutTradeNo,
|
||||||
|
(int)GlobalEnumVars.BillPaymentsStatus.Payed,
|
||||||
|
GlobalEnumVars.PaymentsTypes.wechatpay.ToString(), money, response.Code,
|
||||||
|
response.TradeNo);
|
||||||
|
|
||||||
|
jm.code = 0;
|
||||||
|
jm.msg = "刷新成功";
|
||||||
|
//jm.data = response;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
jm.code = 1;
|
||||||
|
//jm.data = response;
|
||||||
|
jm.msg = !string.IsNullOrEmpty(response.SubMsg) ? response.SubMsg : response.Msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
jm.otherData = response;
|
||||||
|
|
||||||
|
return jm;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1300,14 +1300,10 @@
|
|||||||
支付单表
|
支付单表
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:CoreCms.Net.Web.Admin.Controllers.CoreCmsBillPaymentsController.#ctor(Microsoft.AspNetCore.Hosting.IWebHostEnvironment,CoreCms.Net.IServices.ICoreCmsBillPaymentsServices,Essensoft.Paylink.WeChatPay.V2.IWeChatPayClient,CoreCms.Net.IServices.IWeChatPayConfigServices)">
|
<member name="M:CoreCms.Net.Web.Admin.Controllers.CoreCmsBillPaymentsController.#ctor(Microsoft.AspNetCore.Hosting.IWebHostEnvironment,CoreCms.Net.IServices.ICoreCmsBillPaymentsServices,Essensoft.Paylink.WeChatPay.V2.IWeChatPayClient,CoreCms.Net.IServices.IWeChatPayConfigServices,CoreCms.Net.IServices.IAlipayConfigServices,Essensoft.Paylink.Alipay.IAlipayClient)">
|
||||||
<summary>
|
<summary>
|
||||||
构造函数
|
构造函数
|
||||||
</summary>
|
</summary>
|
||||||
<param name="webHostEnvironment"></param>
|
|
||||||
<param name="coreCmsBillPaymentsServices"></param>
|
|
||||||
<param name="client"></param>
|
|
||||||
<param name="weChatPayConfigServices"></param>
|
|
||||||
</member>
|
</member>
|
||||||
<member name="M:CoreCms.Net.Web.Admin.Controllers.CoreCmsBillPaymentsController.GetPageList">
|
<member name="M:CoreCms.Net.Web.Admin.Controllers.CoreCmsBillPaymentsController.GetPageList">
|
||||||
<summary>
|
<summary>
|
||||||
|
|||||||
@@ -6,21 +6,12 @@
|
|||||||
</colgroup>
|
</colgroup>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<label for="id">序列</label>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{{ d.params.data.model.id || '' }}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<label for="appId">支付宝开放平台AppId</label>
|
<label for="appId">支付宝开放平台AppId</label>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ d.params.data.model.appId || '' }}
|
{{ d.params.data.appId || '' }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@@ -29,7 +20,7 @@
|
|||||||
<label for="publicKey">支付宝公钥</label>
|
<label for="publicKey">支付宝公钥</label>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ d.params.data.model.publicKey || '' }}
|
{{ d.params.data.publicKey || '' }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@@ -38,7 +29,7 @@
|
|||||||
<label for="privateKey">应用私钥</label>
|
<label for="privateKey">应用私钥</label>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ d.params.data.model.privateKey || '' }}
|
{{ d.params.data.privateKey || '' }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@@ -47,7 +38,7 @@
|
|||||||
<label for="serverUrl">服务网关地址</label>
|
<label for="serverUrl">服务网关地址</label>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ d.params.data.model.serverUrl || '' }}
|
{{ d.params.data.serverUrl || '' }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@@ -56,7 +47,7 @@
|
|||||||
<label for="signType">签名类型</label>
|
<label for="signType">签名类型</label>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ d.params.data.model.signType || '' }}
|
{{ d.params.data.signType || '' }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@@ -65,7 +56,7 @@
|
|||||||
<label for="appPublicCert">应用公钥证书</label>
|
<label for="appPublicCert">应用公钥证书</label>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ d.params.data.model.appPublicCert || '' }}
|
{{ d.params.data.appPublicCert || '' }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@@ -74,7 +65,7 @@
|
|||||||
<label for="alipayPublicCert">支付宝公钥证书</label>
|
<label for="alipayPublicCert">支付宝公钥证书</label>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ d.params.data.model.alipayPublicCert || '' }}
|
{{ d.params.data.alipayPublicCert || '' }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@@ -83,7 +74,7 @@
|
|||||||
<label for="alipayRootCert">支付宝根证书</label>
|
<label for="alipayRootCert">支付宝根证书</label>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ d.params.data.model.alipayRootCert || '' }}
|
{{ d.params.data.alipayRootCert || '' }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@@ -92,7 +83,7 @@
|
|||||||
<label for="appType">应用类型</label>
|
<label for="appType">应用类型</label>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ d.params.data.model.appType || '' }}
|
{{ d.params.data.appType || '' }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@@ -101,7 +92,7 @@
|
|||||||
<label for="notifyUrl">支付宝支付回调通知</label>
|
<label for="notifyUrl">支付宝支付回调通知</label>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ d.params.data.model.notifyUrl || '' }}
|
{{ d.params.data.notifyUrl || '' }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@@ -110,7 +101,7 @@
|
|||||||
<label for="refundUrl">支付宝退款回调</label>
|
<label for="refundUrl">支付宝退款回调</label>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ d.params.data.model.refundUrl || '' }}
|
{{ d.params.data.refundUrl || '' }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@@ -119,7 +110,7 @@
|
|||||||
<label for="jumpUrl">支付跳转地址</label>
|
<label for="jumpUrl">支付跳转地址</label>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ d.params.data.model.jumpUrl || '' }}
|
{{ d.params.data.jumpUrl || '' }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@@ -128,7 +119,7 @@
|
|||||||
<label for="isEnable">是否启用</label>
|
<label for="isEnable">是否启用</label>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input type="checkbox" disabled name="isEnable" value="{{d.params.data.model.isEnable}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="isEnable" {{ d.params.data.model.isEnable ? 'checked' : '' }}>
|
<input type="checkbox" disabled name="isEnable" value="{{d.params.data.isEnable}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="isEnable" {{ d.params.data.isEnable ? 'checked' : '' }}>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@@ -137,7 +128,7 @@
|
|||||||
<label for="isDefault">当前多端默认</label>
|
<label for="isDefault">当前多端默认</label>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input type="checkbox" disabled name="isDefault" value="{{d.params.data.model.isDefault}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="isDefault" {{ d.params.data.model.isDefault ? 'checked' : '' }}>
|
<input type="checkbox" disabled name="isDefault" value="{{d.params.data.isDefault}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="isDefault" {{ d.params.data.isDefault ? 'checked' : '' }}>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user