|
|
@ -14,11 +14,17 @@ using Senparc.CO2NET.Extensions;
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Senparc.Weixin.TenPay.V3;
|
|
|
|
using Senparc.Weixin.TenPay.V3;
|
|
|
|
using Senparc.Weixin.TenPay;
|
|
|
|
using Senparc.Weixin.TenPay;
|
|
|
|
|
|
|
|
using Furion.DependencyInjection;
|
|
|
|
|
|
|
|
using Furion.DynamicApiController;
|
|
|
|
|
|
|
|
|
|
|
|
namespace GDZZ.Application.Service.WXPay
|
|
|
|
namespace GDZZ.Application.Service.WXPay
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class WXPayService:IWXPayService
|
|
|
|
[ApiDescriptionSettings("Application", Name = "WXPay", Order = 1)]
|
|
|
|
|
|
|
|
public class WXPayService: IWXPayService, IDynamicApiController, ITransient
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly string TenPayKey = Config.SenparcWeixinSetting.TenPayV3_Key; //与微信小程序后台的AppId设置保持一致,区分大小写。
|
|
|
|
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<BaseUser> Baseuser; // wx用户仓储
|
|
|
|
private readonly SqlSugarRepository<BaseUser> Baseuser; // wx用户仓储
|
|
|
|
private readonly SqlSugarRepository<SysUser> _sysUserRep; // 用户表仓储
|
|
|
|
private readonly SqlSugarRepository<SysUser> _sysUserRep; // 用户表仓储
|
|
|
|
private readonly SqlSugarRepository<SysTenant> _sysTenantRep; //租户仓储
|
|
|
|
private readonly SqlSugarRepository<SysTenant> _sysTenantRep; //租户仓储
|
|
|
@ -86,7 +92,7 @@ namespace GDZZ.Application.Service.WXPay
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
[HttpGet]
|
|
|
|
[AllowAnonymous]
|
|
|
|
[AllowAnonymous]
|
|
|
|
[Route("api/v1/wxpay/{productId}")]
|
|
|
|
[Route("api/v1/wxpay")]
|
|
|
|
public async Task<dynamic> WxPay(AuthUserInput authUserInput)
|
|
|
|
public async Task<dynamic> WxPay(AuthUserInput authUserInput)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var recharge = await this.rechargeRep.InsertReturnEntityAsync(new MiniRecharge()
|
|
|
|
var recharge = await this.rechargeRep.InsertReturnEntityAsync(new MiniRecharge()
|
|
|
@ -115,7 +121,7 @@ namespace GDZZ.Application.Service.WXPay
|
|
|
|
(int)authUserInput.Money * 100,
|
|
|
|
(int)authUserInput.Money * 100,
|
|
|
|
"127.0.0.1",
|
|
|
|
"127.0.0.1",
|
|
|
|
Config.SenparcWeixinSetting.TenPayV3_WxOpenTenpayNotify, TenPayV3Type.JSAPI, authUserInput.OpenID.ToString(),
|
|
|
|
Config.SenparcWeixinSetting.TenPayV3_WxOpenTenpayNotify, TenPayV3Type.JSAPI, authUserInput.OpenID.ToString(),
|
|
|
|
Config.SenparcWeixinSetting.TenPayV3_Key, nonceStr, null, null, null, null, payTake.Id.ToString());
|
|
|
|
Config.SenparcWeixinSetting.TenPayV3_Key, nonceStr, null, null, null, null, payTake.OrderId.ToString());
|
|
|
|
UnifiedorderResult result = await TenPayV3.UnifiedorderAsync(xmlDataInfo); //调用统一订单接口
|
|
|
|
UnifiedorderResult result = await TenPayV3.UnifiedorderAsync(xmlDataInfo); //调用统一订单接口
|
|
|
|
string packageStr = "prepay_id=" + result.prepay_id;
|
|
|
|
string packageStr = "prepay_id=" + result.prepay_id;
|
|
|
|
|
|
|
|
|
|
|
@ -145,34 +151,25 @@ namespace GDZZ.Application.Service.WXPay
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.LogError("NotifyUrl");
|
|
|
|
|
|
|
|
ResponseHandler resHandler = new ResponseHandler(_httpContextAccessor.HttpContext);
|
|
|
|
ResponseHandler resHandler = new ResponseHandler(_httpContextAccessor.HttpContext);
|
|
|
|
string returnCode = resHandler.GetParameter("return_code");
|
|
|
|
string returnCode = resHandler.GetParameter("return_code");
|
|
|
|
resHandler.SetKey(TenPayKey);
|
|
|
|
resHandler.SetKey(TenPayKey);
|
|
|
|
if (resHandler.IsTenpaySign() && returnCode.ToUpper() == "SUCCESS")
|
|
|
|
if (resHandler.IsTenpaySign() && returnCode.ToUpper() == "SUCCESS")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//attach
|
|
|
|
//attach
|
|
|
|
string paymentId = resHandler.GetParameter("attach");
|
|
|
|
var paymentId =long.Parse(resHandler.GetParameter("attach"));
|
|
|
|
//业务处理
|
|
|
|
//业务处理
|
|
|
|
PaymentRecordEntity paymentRecord = await _paymentRecordRepository.GetAsync(paymentId.ToLong());
|
|
|
|
var paytake = await this.payTakeRep.Where(x => x.OrderId == paymentId).SingleAsync();
|
|
|
|
if (paymentRecord.IsNotNull())
|
|
|
|
if (paytake.IsNullOrZero())
|
|
|
|
{
|
|
|
|
|
|
|
|
paymentRecord.PayStatus = (int)PayStatusEnum.Paying;
|
|
|
|
|
|
|
|
await _paymentRecordRepository.UpdateAsync(paymentRecord);
|
|
|
|
|
|
|
|
//order
|
|
|
|
|
|
|
|
OrderEntity order = await _orderRepository.GetAsync(paymentRecord.OrderId);
|
|
|
|
|
|
|
|
if (order.IsNotNull())
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
order.OrderStatus = (int)OrderStatusEnum.Paying;
|
|
|
|
paytake.PayStatus =(int)PayStatusEnum.Paying;
|
|
|
|
await _orderRepository.UpdateAsync(order);
|
|
|
|
this.payTakeRep.Update(paytake);
|
|
|
|
//积分操作
|
|
|
|
|
|
|
|
OrderDetailEntity orderDetail = await _orderDetailRepository.Select.Where(x => x.OrderId == order.Id)
|
|
|
|
|
|
|
|
.ToOneAsync();
|
|
|
|
|
|
|
|
//ProductInfoEntity productInfo = await _productInfoRepository.GetAsync(orderDetail.ProductId);
|
|
|
|
|
|
|
|
RechargeIntroEntity entity = await _rechargeIntroRepository.GetAsync(orderDetail.ProductId);
|
|
|
|
|
|
|
|
await _currencyService.AddCurrencyByCharge(order.UserId, order.Id,
|
|
|
|
|
|
|
|
entity.AllValue);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var recharge = await this.rechargeRep.Where(x=>x.Id == paymentId).SingleAsync();
|
|
|
|
|
|
|
|
if(recharge.IsNullOrZero())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
recharge.Status = (int)RechargeEnum.Finish;
|
|
|
|
|
|
|
|
this.rechargeRep.Update(recharge);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -184,7 +181,7 @@ namespace GDZZ.Application.Service.WXPay
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.LogError(ex, ex.Message);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string xml = "<xml>"
|
|
|
|
string xml = "<xml>"
|
|
|
|
+ "<return_code>FAIL</return_code>"
|
|
|
|
+ "<return_code>FAIL</return_code>"
|
|
|
|