diff --git a/CoreCms.Net.Services/Pay/WeChatPayServices.cs b/CoreCms.Net.Services/Pay/WeChatPayServices.cs
index 3d4029fb..59f080a0 100644
--- a/CoreCms.Net.Services/Pay/WeChatPayServices.cs
+++ b/CoreCms.Net.Services/Pay/WeChatPayServices.cs
@@ -18,6 +18,7 @@ using CoreCms.Net.Loging;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.Utility.Extensions;
+using CoreCms.Net.Utility.Helper;
using CoreCms.Net.WeChat.Service.HttpClients;
using Essensoft.Paylink.WeChatPay;
using Essensoft.Paylink.WeChatPay.V2;
@@ -123,7 +124,7 @@ namespace CoreCms.Net.Services
{
var jObj = (JObject)JsonConvert.DeserializeObject(entity.parameters);
if (jObj != null && jObj.TryGetValue("trade_type", out var value))
- tradeType = GetTradeType(value.ObjectToString());
+ tradeType = PayHelper.GetWeiChatPayTradeType(value.ObjectToString());
}
@@ -294,7 +295,7 @@ namespace CoreCms.Net.Services
{
var jObj = (JObject)JsonConvert.DeserializeObject(paymentInfo.parameters);
if (jObj != null && jObj.TryGetValue("trade_type", out var value))
- tradeType = GetTradeType(value.ObjectToString());
+ tradeType = PayHelper.GetWeiChatPayTradeType(value.ObjectToString());
}
var config = await _weChatPayConfigServices.QueryByClauseAsync(p =>
@@ -352,18 +353,5 @@ namespace CoreCms.Net.Services
return jm;
}
- private static string GetTradeType(string tradeType)
- {
- if (tradeType != GlobalEnumVars.WeiChatPayTradeType.JSAPI.ToString() &&
- tradeType != GlobalEnumVars.WeiChatPayTradeType.JSAPI_OFFICIAL.ToString() &&
- tradeType != GlobalEnumVars.WeiChatPayTradeType.NATIVE.ToString() &&
- tradeType != GlobalEnumVars.WeiChatPayTradeType.APP.ToString() &&
- tradeType != GlobalEnumVars.WeiChatPayTradeType.MWEB.ToString()
- )
- return "JSAPI";
- if (tradeType == GlobalEnumVars.WeiChatPayTradeType.JSAPI_OFFICIAL.ToString())
- return "JSAPI";
- return tradeType;
- }
}
}
\ No newline at end of file
diff --git a/CoreCms.Net.Uni-App/CoreShop/pages/payment/components/coreshop-paymentsByWx.vue b/CoreCms.Net.Uni-App/CoreShop/pages/payment/components/coreshop-paymentsByWx.vue
index 812d7e33..7a7b6ab7 100644
--- a/CoreCms.Net.Uni-App/CoreShop/pages/payment/components/coreshop-paymentsByWx.vue
+++ b/CoreCms.Net.Uni-App/CoreShop/pages/payment/components/coreshop-paymentsByWx.vue
@@ -134,7 +134,7 @@
payment_code: code,
payment_type: this.type,
params: {
- //trade_type: 'NATIVE',
+ trade_type: 'JSAPI',
}
}
data.ids = (this.type == this.$globalConstVars.paymentType.common || this.type == this.$globalConstVars.paymentType.pinTuan || this.type == this.$globalConstVars.paymentType.group || this.type == this.$globalConstVars.paymentType.seckill || this.type == this.$globalConstVars.paymentType.bargain || this.type == this.$globalConstVars.paymentType.giveaway || this.type == this.$globalConstVars.paymentType.solitaire || this.type == this.$globalConstVars.paymentType.transactionComponent || this.type == this.$globalConstVars.paymentType.serviceOrder) ? this.orderId : this.uid
diff --git a/CoreCms.Net.Utility/Helper/PayHelper.cs b/CoreCms.Net.Utility/Helper/PayHelper.cs
new file mode 100644
index 00000000..4c45a2d8
--- /dev/null
+++ b/CoreCms.Net.Utility/Helper/PayHelper.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using CoreCms.Net.Configuration;
+
+namespace CoreCms.Net.Utility.Helper
+{
+ public static class PayHelper
+ {
+
+ ///
+ /// 获取微信支付类型
+ ///
+ ///
+ ///
+ public static string GetWeiChatPayTradeType(string tradeType)
+ {
+ if (tradeType != GlobalEnumVars.WeiChatPayTradeType.JSAPI.ToString() &&
+ tradeType != GlobalEnumVars.WeiChatPayTradeType.JSAPI_OFFICIAL.ToString() &&
+ tradeType != GlobalEnumVars.WeiChatPayTradeType.NATIVE.ToString() &&
+ tradeType != GlobalEnumVars.WeiChatPayTradeType.APP.ToString() &&
+ tradeType != GlobalEnumVars.WeiChatPayTradeType.MWEB.ToString()
+ )
+ return GlobalEnumVars.WeiChatPayTradeType.JSAPI.ToString();
+ if (tradeType == GlobalEnumVars.WeiChatPayTradeType.JSAPI_OFFICIAL.ToString())
+ return GlobalEnumVars.WeiChatPayTradeType.JSAPI.ToString();
+ return tradeType;
+ }
+
+
+ }
+}
diff --git a/CoreCms.Net.Web.Admin/Controllers/Financial/CoreCmsBillPaymentsController.cs b/CoreCms.Net.Web.Admin/Controllers/Financial/CoreCmsBillPaymentsController.cs
index ab350947..50dc429c 100644
--- a/CoreCms.Net.Web.Admin/Controllers/Financial/CoreCmsBillPaymentsController.cs
+++ b/CoreCms.Net.Web.Admin/Controllers/Financial/CoreCmsBillPaymentsController.cs
@@ -31,8 +31,11 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
+using Newtonsoft.Json.Linq;
+using Newtonsoft.Json;
using NPOI.HSSF.UserModel;
using SqlSugar;
+using CoreCms.Net.Services;
namespace CoreCms.Net.Web.Admin.Controllers
{
@@ -49,7 +52,8 @@ namespace CoreCms.Net.Web.Admin.Controllers
private readonly ICoreCmsBillPaymentsServices _coreCmsBillPaymentsServices;
private readonly IWebHostEnvironment _webHostEnvironment;
private readonly IWeChatPayClient _client;
- private readonly IOptions _optionsAccessor;
+
+ private readonly IWeChatPayConfigServices _weChatPayConfigServices;
///
@@ -58,14 +62,14 @@ namespace CoreCms.Net.Web.Admin.Controllers
///
///
///
- ///
+ ///
public CoreCmsBillPaymentsController(IWebHostEnvironment webHostEnvironment
- , ICoreCmsBillPaymentsServices coreCmsBillPaymentsServices, IWeChatPayClient client, IOptions optionsAccessor)
+ , ICoreCmsBillPaymentsServices coreCmsBillPaymentsServices, IWeChatPayClient client, IWeChatPayConfigServices weChatPayConfigServices)
{
_webHostEnvironment = webHostEnvironment;
_coreCmsBillPaymentsServices = coreCmsBillPaymentsServices;
_client = client;
- _optionsAccessor = optionsAccessor;
+ _weChatPayConfigServices = weChatPayConfigServices;
}
#region 获取列表============================================================
@@ -508,9 +512,9 @@ namespace CoreCms.Net.Web.Admin.Controllers
jm.msg = "不存在此信息";
return jm;
}
- if (model.paymentCode != GlobalEnumVars.PaymentsTypes.wechatpay.ToString())
+ if (model.paymentCode != GlobalEnumVars.PaymentsTypes.wechatpay.ToString() && model.paymentCode != GlobalEnumVars.PaymentsTypes.alipay.ToString())
{
- jm.msg = "此更新暂时仅支持微信支付查询";
+ jm.msg = "此更新暂时仅支持微信支付及支付宝支付查询";
return jm;
}
@@ -521,32 +525,79 @@ namespace CoreCms.Net.Web.Admin.Controllers
}
- var request = new WeChatPayOrderQueryRequest
+ if (model.paymentCode == GlobalEnumVars.PaymentsTypes.wechatpay.ToString())
{
- //微信订单号
- //TransactionId = model.TransactionId,
- //商户订单号
- OutTradeNo = model.paymentId
- };
- var response = await _client.ExecuteAsync(request, _optionsAccessor.Value);
+ var tradeType = GlobalEnumVars.WeiChatPayTradeType.JSAPI.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.GetWeiChatPayTradeType(value.ObjectToString());
+ }
- if (response is { ReturnCode: WeChatPayCode.Success, ResultCode: WeChatPayCode.Success, TradeState: WeChatPayCode.Success })
+ var config = await _weChatPayConfigServices.QueryByClauseAsync(p => p.isDefault == true && p.isEnable == true && p.appType == tradeType);
+
+ if (config == null)
+ {
+ 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 WeChatPayOrderQueryRequest
+ {
+ //微信订单号
+ //TransactionId = model.TransactionId,
+ //商户订单号
+ OutTradeNo = model.paymentId
+ };
+ var response = await _client.ExecuteAsync(request, payOptions);
+
+ if (response is { ReturnCode: WeChatPayCode.Success, ResultCode: WeChatPayCode.Success, TradeState: WeChatPayCode.Success })
+ {
+ var money = Math.Round((decimal)response.TotalFee / 100, 2);
+ await _coreCmsBillPaymentsServices.ToUpdate(response.OutTradeNo,
+ (int)GlobalEnumVars.BillPaymentsStatus.Payed,
+ GlobalEnumVars.PaymentsTypes.wechatpay.ToString(), money, response.ResultCode,
+ response.TransactionId);
+
+ jm.code = 0;
+ jm.msg = "刷新成功";
+ jm.data = response;
+ }
+ else
+ {
+ jm.code = 1;
+ jm.data = response;
+ jm.msg = response.TradeState == "NOTPAY" ? response.TradeStateDesc : response.ErrCodeDes;
+ }
+
+ }
+ else if (model.paymentCode == GlobalEnumVars.PaymentsTypes.alipay.ToString())
{
- var money = Math.Round((decimal)response.TotalFee / 100, 2);
- await _coreCmsBillPaymentsServices.ToUpdate(response.OutTradeNo,
- (int)GlobalEnumVars.BillPaymentsStatus.Payed,
- GlobalEnumVars.PaymentsTypes.wechatpay.ToString(), money, response.ResultCode,
- response.TransactionId);
- jm.code = 0;
- jm.msg = "刷新成功";
- jm.data = response;
+
+
+
+
}
else
{
- jm.code = 1;
- jm.msg = response.TradeStateDesc;
+ jm.msg = "错误类型的支付方式";
}
+
return jm;
}
diff --git a/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.xml b/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.xml
index 8c29e789..c1280488 100644
--- a/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.xml
+++ b/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.xml
@@ -1300,14 +1300,14 @@
支付单表
-
+
构造函数
-
+
diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/financial/billpayments/index.html b/CoreCms.Net.Web.Admin/wwwroot/views/financial/billpayments/index.html
index a27dde80..a05f32cc 100644
--- a/CoreCms.Net.Web.Admin/wwwroot/views/financial/billpayments/index.html
+++ b/CoreCms.Net.Web.Admin/wwwroot/views/financial/billpayments/index.html
@@ -69,7 +69,7 @@
@@ -224,6 +224,7 @@
//执行刷新操作
function doRefresh(obj) {
coreHelper.Post("Api/CoreCmsBillPayments/doRefresh", { id: obj.data.paymentId }, function (e) {
+ table.reloadData('LAY-app-CoreCmsBillPayments-tableBox');
layer.msg(e.msg);
});
}