修改支付回调
This commit is contained in:
parent
565c5e0e26
commit
f2b6187c82
|
|
@ -29,6 +29,17 @@ namespace CloudGaming.PayApi.Controllers
|
|||
[ApiController]
|
||||
public class PayController(ILogger<PayController> logger, IHttpContextAccessor httpContextAccessor, IServiceProvider serviceProvider) : ControllerBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{tenant?}/{pay?}/{orderId?}/{sign?}")]
|
||||
public async Task<string> Get(string? tenant, string? pay, string? orderId, string? sign)
|
||||
{
|
||||
return await PayCallback(logger, httpContextAccessor, serviceProvider, tenant, pay, orderId, sign);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 支付中心回调
|
||||
/// </summary>
|
||||
|
|
@ -39,6 +50,12 @@ namespace CloudGaming.PayApi.Controllers
|
|||
/// <returns></returns>
|
||||
[HttpPost("{tenant?}/{pay?}/{orderId?}/{sign?}")]
|
||||
public async Task<string> Post(string? tenant, string? pay, string? orderId, string? sign)
|
||||
{
|
||||
return await PayCallback(logger, httpContextAccessor, serviceProvider, tenant, pay, orderId, sign);
|
||||
|
||||
}
|
||||
|
||||
private static async Task<string> PayCallback(ILogger<PayController> logger, IHttpContextAccessor httpContextAccessor, IServiceProvider serviceProvider, string? tenant, string? pay, string? orderId, string? sign)
|
||||
{
|
||||
var context = httpContextAccessor.HttpContext;
|
||||
context.Request.EnableBuffering(); // Enable buffering to allow the body to be read multiple times
|
||||
|
|
@ -129,8 +146,7 @@ namespace CloudGaming.PayApi.Controllers
|
|||
var userDiamond = await dao.DaoUser.Context.T_User_Currency.Where(it => it.UserId == user.Id && it.CurrencyType == (int)UserCurrencyType.钻石).FirstOrDefaultAsync();
|
||||
//刷新钻石缓存
|
||||
await AccountExtend.RefreshUserInfo(user.Id, redis, (int)(userDiamond?.CurrencyMoney ?? 0), intentOrder.Price > 0 ? true : false);
|
||||
|
||||
return $"success";
|
||||
return "success";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace CloudGaming.Code.Aliyun;
|
|||
/// <param name="userId"></param>
|
||||
public class AlipayPayment(AppConfig appConfig, int userId) : IPayment
|
||||
{
|
||||
public Task<(string orderId, string order)> CreateOrder(int productId, string productName, decimal price, params object[] args)
|
||||
public Task<(string orderId, string order, string payNotifyUrl)> CreateOrder(int productId, string productName, decimal price, params object[] args)
|
||||
{
|
||||
if (string.IsNullOrEmpty(productName))
|
||||
{
|
||||
|
|
@ -58,7 +58,7 @@ public class AlipayPayment(AppConfig appConfig, int userId) : IPayment
|
|||
}
|
||||
//.PreCreate("Apple iPhone11 128G", "2234567234890", "5799.00");
|
||||
var zfbOrderId = response.Body;
|
||||
return Task.FromResult((orderId, zfbOrderId));
|
||||
return Task.FromResult((orderId, zfbOrderId, notifyUrl));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -19,5 +19,5 @@ public interface IPayment
|
|||
/// <param name="price">价格</param>
|
||||
/// <param name="args">其它参数</param>
|
||||
/// <returns></returns>
|
||||
Task<(string orderId, string order)> CreateOrder(int productId, string productName, decimal price, params object[] args);
|
||||
Task<(string orderId, string order,string payNotifyUrl)> CreateOrder(int productId, string productName, decimal price, params object[] args);
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ public class OrderBLL : CloudGamingBase
|
|||
{
|
||||
price = (decimal)0.01;
|
||||
}
|
||||
(var orderId, var order) = await payment.CreateOrder(product.Id, product.ProductName, price, product, ip);
|
||||
(var orderId, var order, var payNotifyUrl) = await payment.CreateOrder(product.Id, product.ProductName, price, product, ip);
|
||||
var t = product.ToIntentOrder(paymentMethod, orderId);
|
||||
t.UserId = _UserId;
|
||||
await Dao.DaoUser.Context.AddAsync(t);
|
||||
|
|
@ -81,6 +81,7 @@ public class OrderBLL : CloudGamingBase
|
|||
Payment = order
|
||||
};
|
||||
RedisCache.KeyDelete(redisLock);
|
||||
HttpContextAccessor.HttpContext.Response.Headers.Add("PayNotifyUrl", payNotifyUrl);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ public static class OrderExtend
|
|||
|
||||
if (productReward != null && productReward.Count > 0)
|
||||
{
|
||||
|
||||
List<string> tips = new List<string>();
|
||||
//List<T_User_Currency> user_Currencies = new List<T_User_Currency>();
|
||||
foreach (var reward in productReward)
|
||||
|
|
@ -44,7 +45,7 @@ public static class OrderExtend
|
|||
var money = reward.Money;
|
||||
var currency = (UserCurrencyType)reward.CurrencyType;
|
||||
var userCurrency = new T_User_Currency();
|
||||
await user.ConsumeMoneyNoWork(currency, money, dao, userCurrency, orderId);
|
||||
await user.ConsumeMoneyNoWork(currency, money, dao, userCurrency, orderId, $"购买{product.ProductName}");
|
||||
tips.Add($"获得{currency}*{money}");
|
||||
if (product.IsFirstCharge && chargeMoneyCount == 0 && reward.FirstChargeMoney > 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace CloudGaming.Code.WeChat;
|
|||
/// </summary>
|
||||
public class WeChatPayment(WechatTenpayClient client, WeChatConfig weChatConfig, AppConfig appConfig, int userId) : IPayment
|
||||
{
|
||||
public async Task<(string orderId, string order)> CreateOrder(int productId, string productName, decimal price, params object[] args)
|
||||
public async Task<(string orderId, string order, string payNotifyUrl)> CreateOrder(int productId, string productName, decimal price, params object[] args)
|
||||
{
|
||||
//var orderId = GenerateTimestampIdWithOffset();
|
||||
var orderId = PaymentExtend.GenerateCustomString("WX", userId, productId, "001");
|
||||
|
|
@ -46,7 +46,7 @@ public class WeChatPayment(WechatTenpayClient client, WeChatConfig weChatConfig,
|
|||
{
|
||||
var paramMap = client.GenerateParametersForAppPayRequest(request.AppId, response.PrepayId);
|
||||
//Console.WriteLine("PrepayId:" + response.PrepayId);
|
||||
return new(orderId, JsonConvert.SerializeObject(paramMap));
|
||||
return new(orderId, JsonConvert.SerializeObject(paramMap), notifyUrl);
|
||||
}
|
||||
throw new Exception("微信下单失败");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user