提交代码
This commit is contained in:
parent
9f298b5f00
commit
b35f7d83fb
|
|
@ -89,7 +89,7 @@ namespace HuanMeng.MiaoYu.Code.Order
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RedisCache.KeyDelete(redisLock);
|
||||
RedisCache.KeyDelete(redisLock);
|
||||
throw new Exception("创建订单失败");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -132,6 +132,20 @@ namespace HuanMeng.MiaoYu.Code.Payment
|
|||
|
||||
var _weChatConfig = miaoYuBase.AppConfig.Payment.WeChatConfig ?? weChatConfig;
|
||||
var _wxClient = miaoYuBase.AppConfig.Payment.WxClient ?? wxClient;
|
||||
if (payment == "xcx")
|
||||
{
|
||||
if (miaoYuBase._UserId == 0)
|
||||
{
|
||||
throw new Exception("请先登录");
|
||||
}
|
||||
var userAccount = miaoYuBase.Dao.daoDbMiaoYu.context.T_User_MiniProgram_Account.FirstOrDefault(it => it.UserId == miaoYuBase._UserId);
|
||||
if (userAccount == null)
|
||||
{
|
||||
throw new Exception("未找到人员数据,请先登录");
|
||||
}
|
||||
|
||||
return new WeChatMiniProgram(_wxClient, _weChatConfig, miaoYuBase.TenantInfo, miaoYuBase._UserId, userAccount.OpenId);
|
||||
}
|
||||
return new WeChatPayment(_wxClient, _weChatConfig, miaoYuBase.TenantInfo, miaoYuBase._UserId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
using HuanMeng.DotNetCore.MultiTenant.Contract;
|
||||
using HuanMeng.MiaoYu.Code.Payment.Contract;
|
||||
using Newtonsoft.Json;
|
||||
using SKIT.FlurlHttpClient.Wechat.TenpayV3.Models;
|
||||
using SKIT.FlurlHttpClient.Wechat.TenpayV3;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HuanMeng.MiaoYu.Code.Payment.WeChat
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="weChatConfig"></param>
|
||||
/// <param name="tenantInfo"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="openId"></param>
|
||||
public class WeChatMiniProgram(WechatTenpayClient client, WeChatConfig weChatConfig, ITenantInfo tenantInfo, int userId, string openId) : IPayment
|
||||
{
|
||||
public async Task<(string orderId, string order)> CreateOrder(int productId, string productName, decimal price, params object[] args)
|
||||
{
|
||||
//var orderId = GenerateTimestampIdWithOffset();
|
||||
var orderId = PaymentExtend.GenerateCustomString("WMP", userId, productId, "002");
|
||||
//var client = new WechatTenpayClient(wechatTenpayClientOptions);
|
||||
/* 以 JSAPI 统一下单接口为例 */
|
||||
string sign = $"{tenantInfo.Identifier}{orderId}{userId}";
|
||||
sign = MD5Encryption.ComputeMD5Hash(sign);
|
||||
var notifyUrl = weChatConfig.NotifyUrl.Replace("${pay}", "wx").Replace("${orderId}", orderId).Replace("${tenant}", tenantInfo.Identifier).Replace("${sign}", sign);
|
||||
|
||||
var request1 = new CreatePayTransactionAppRequest()
|
||||
{
|
||||
OutTradeNumber = orderId,
|
||||
AppId = weChatConfig.AppId,
|
||||
Description = productName,
|
||||
ExpireTime = DateTimeOffset.Now.AddMinutes(20),
|
||||
NotifyUrl = notifyUrl,
|
||||
Amount = new CreatePayTransactionJsapiRequest.Types.Amount()
|
||||
{
|
||||
Total = (int)(price * 100)
|
||||
},
|
||||
};
|
||||
|
||||
/* 以 JSAPI 统一下单接口为例 */
|
||||
var request = new CreatePayTransactionJsapiRequest()
|
||||
{
|
||||
|
||||
OutTradeNumber = orderId,
|
||||
AppId = weChatConfig.AppId,
|
||||
Description = productName,
|
||||
ExpireTime = DateTimeOffset.Now.AddMinutes(20),
|
||||
NotifyUrl = notifyUrl,
|
||||
Amount = new CreatePayTransactionJsapiRequest.Types.Amount()
|
||||
{
|
||||
Total = (int)(price * 100)
|
||||
},
|
||||
Payer = new CreatePayTransactionJsapiRequest.Types.Payer()
|
||||
{
|
||||
OpenId = openId
|
||||
}
|
||||
};
|
||||
var response = await client.ExecuteCreatePayTransactionJsapiAsync(request);
|
||||
if (response.IsSuccessful())
|
||||
{
|
||||
var paramMap = client.GenerateParametersForAppPayRequest(request.AppId, response.PrepayId);
|
||||
//Console.WriteLine("PrepayId:" + response.PrepayId);
|
||||
return new(orderId, JsonConvert.SerializeObject(paramMap));
|
||||
}
|
||||
throw new Exception("微信下单失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ using System.Security.Cryptography;
|
|||
namespace HuanMeng.MiaoYu.Code.Payment.WeChat
|
||||
{
|
||||
/// <summary>
|
||||
/// 微信支付
|
||||
/// 微信支付
|
||||
/// </summary>
|
||||
public class WeChatPayment(WechatTenpayClient client, WeChatConfig weChatConfig, ITenantInfo tenantInfo, int userId) : IPayment
|
||||
{
|
||||
|
|
@ -35,6 +35,7 @@ namespace HuanMeng.MiaoYu.Code.Payment.WeChat
|
|||
Total = (int)(price * 100)
|
||||
},
|
||||
};
|
||||
|
||||
var response = await client.ExecuteCreatePayTransactionAppAsync(request);
|
||||
if (response.IsSuccessful())
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user