diff --git a/New_College.Common/Helper/WeChatPayHelper.cs b/New_College.Common/Helper/WeChatPayHelper.cs index 44b3420..4107b20 100644 --- a/New_College.Common/Helper/WeChatPayHelper.cs +++ b/New_College.Common/Helper/WeChatPayHelper.cs @@ -1,6 +1,7 @@ using Essensoft.AspNetCore.Payment.WeChatPay; -using Essensoft.AspNetCore.Payment.WeChatPay.Request; -using Essensoft.AspNetCore.Payment.WeChatPay.Response; +using Essensoft.AspNetCore.Payment.WeChatPay.V2; +using Essensoft.AspNetCore.Payment.WeChatPay.V2.Request; +using Essensoft.AspNetCore.Payment.WeChatPay.V2.Response; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; diff --git a/New_College.Common/Helper/WeChatPayOrderQuery.cs b/New_College.Common/Helper/WeChatPayOrderQuery.cs index f85c5f7..368a2f9 100644 --- a/New_College.Common/Helper/WeChatPayOrderQuery.cs +++ b/New_College.Common/Helper/WeChatPayOrderQuery.cs @@ -38,6 +38,15 @@ namespace New_College.Common.Helper } + public class WeChatPayTransactionsNativeQuery + { + public int? Total { get; set; } + public string Description { get; set; } + public string NotifyUrl { get; set; } + public string OutTradeNo { get; set; } + } + + public class ProductPayRequest { /// diff --git a/New_College.Common/Helper/WeChatPayV3Helper.cs b/New_College.Common/Helper/WeChatPayV3Helper.cs new file mode 100644 index 0000000..eb27fda --- /dev/null +++ b/New_College.Common/Helper/WeChatPayV3Helper.cs @@ -0,0 +1,44 @@ +using Essensoft.AspNetCore.Payment.WeChatPay; +using Essensoft.AspNetCore.Payment.WeChatPay.V3; +using Essensoft.AspNetCore.Payment.WeChatPay.V3.Domain; +using Essensoft.AspNetCore.Payment.WeChatPay.V3.Request; +using Microsoft.Extensions.Options; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; + + +namespace New_College.Common.Helper +{ + public class WeChatPayV3 + { + /// + /// 扫码支付-Native下单API + /// + /// + /// + /// + /// + public static async Task QrCodePay(IWeChatPayClient _client, + IOptions _optionsAccessor, WeChatPayTransactionsNativeQuery viewModel) + { + var model = new WeChatPayTransactionsNativeBodyModel + { + AppId = _optionsAccessor.Value.AppId, + MchId = _optionsAccessor.Value.MchId, + Amount = new Essensoft.AspNetCore.Payment.WeChatPay.V3.Domain.Amount { Total = viewModel.Total, Currency = "CNY" }, + Description = viewModel.Description, + NotifyUrl = viewModel.NotifyUrl, + OutTradeNo = viewModel.OutTradeNo, + }; + var request = new WeChatPayTransactionsNativeRequest(); + request.SetBodyModel(model); + return await _client.ExecuteAsync(request, _optionsAccessor.Value); + } + + + + } +} diff --git a/New_College.Common/New_College.Common.csproj b/New_College.Common/New_College.Common.csproj index e6037b9..aeef837 100644 --- a/New_College.Common/New_College.Common.csproj +++ b/New_College.Common/New_College.Common.csproj @@ -13,9 +13,9 @@ - - - + + + diff --git a/New_College.IServices/IWeiChatPayServicesV3.cs b/New_College.IServices/IWeiChatPayServicesV3.cs new file mode 100644 index 0000000..8a02dfb --- /dev/null +++ b/New_College.IServices/IWeiChatPayServicesV3.cs @@ -0,0 +1,16 @@ +using New_College.Common.Helper; +using New_College.IServices.BASE; +using New_College.Model.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace New_College.IServices +{ + public interface IWeiChatPayServicesV3 : IBaseServices + { + Task QrCodePay(WeChatPayTransactionsNativeQuery viewModel); + } +} diff --git a/New_College.Model/ViewModels/Query/OrderQuery.cs b/New_College.Model/ViewModels/Query/OrderQuery.cs index 3cb5783..544d9f4 100644 --- a/New_College.Model/ViewModels/Query/OrderQuery.cs +++ b/New_College.Model/ViewModels/Query/OrderQuery.cs @@ -25,4 +25,9 @@ namespace New_College.Model.ViewModels public int StudentId { get; set; } } + + + + + } diff --git a/New_College.Services/V_OrderInfoServices.cs b/New_College.Services/V_OrderInfoServices.cs index 920ce57..cb458d3 100644 --- a/New_College.Services/V_OrderInfoServices.cs +++ b/New_College.Services/V_OrderInfoServices.cs @@ -16,7 +16,6 @@ using New_College.Common.Helper; using Microsoft.Extensions.Options; using Essensoft.AspNetCore.Payment.WeChatPay; using Essensoft.AspNetCore.Payment.Alipay; -using Essensoft.AspNetCore.Payment.WeChatPay.Notify; using Microsoft.Extensions.Logging; using Essensoft.AspNetCore.Payment.Alipay.Domain; using Essensoft.AspNetCore.Payment.Alipay.Request; @@ -24,9 +23,11 @@ using System.Collections.Generic; using LinqKit; using System.Collections.Specialized; using Org.BouncyCastle.Asn1.Ocsp; -using Essensoft.AspNetCore.Payment.WeChatPay.Response; -using Essensoft.AspNetCore.Payment.WeChatPay.Request; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using NPOI.SS.Formula.Functions; +using Essensoft.AspNetCore.Payment.WeChatPay.V2.Request; +using Essensoft.AspNetCore.Payment.WeChatPay.V2; namespace New_College.Services { @@ -44,6 +45,7 @@ namespace New_College.Services private readonly IV_VipCardTypeRepository v_VipCardTypeRepository; private readonly ILogger logger; + private readonly IWeiChatPayServicesV3 _weiChatPayServicesV3; public int Nums = 10; public V_OrderInfoServices(IWeChatPayClient client, IOptions optionsAccessor @@ -53,7 +55,7 @@ namespace New_College.Services , IV_CustomerInfoRepository IV_CustomerInfoRepository , IV_VipCardInfoRepository IV_VipCardInfoRepository , IV_VipCardTypeRepository IV_VipCardTypeRepository - , ILogger loggers + , ILogger loggers, IWeiChatPayServicesV3 weiChatPayServicesV3 ) { _client = client; @@ -67,6 +69,17 @@ namespace New_College.Services v_VipCardTypeRepository = IV_VipCardTypeRepository; logger = loggers; base.BaseDal = dal; + _weiChatPayServicesV3 = weiChatPayServicesV3; + } + + + /// + /// 扫码支付-Native下单API + /// + /// + public async Task QrCodePay(WeChatPayTransactionsNativeQuery viewModel) + { + return await _weiChatPayServicesV3.QrCodePay(viewModel); } /// @@ -287,7 +300,7 @@ namespace New_College.Services //viewModel.NotifyUrl = string.Format("{0}/api/front/HFivePay/WeChartOrderConfirm?out_trade_no={1}", PayInfoQuery.ApiUrl, out_trade_no); viewModel.SpBillCreateIp = PayInfoQuery.CreateIp; viewModel.OutTradeNo = out_trade_no; - viewModel.TotalFee = Convert.ToInt32(query.Money*100); + viewModel.TotalFee = Convert.ToInt32(query.Money * 100); viewModel.Body = "六纬志愿VIP"; viewModel.TradeType = "MWEB"; diff --git a/New_College.Services/WeiChatPayServicesV3.cs b/New_College.Services/WeiChatPayServicesV3.cs new file mode 100644 index 0000000..950b7f7 --- /dev/null +++ b/New_College.Services/WeiChatPayServicesV3.cs @@ -0,0 +1,83 @@ + +using New_College.IServices; +using New_College.Model.Models; +using New_College.Services.BASE; +using New_College.IRepository.Base; +using New_College.IRepository.UnitOfWork; +using New_College.Model.ViewModels; +using System.Threading.Tasks; +using New_College.Common; +using New_College.IRepository; +using System.Linq; +using YIJIYI.Core.Common.Helper; +using System; +using New_College.Model; +using New_College.Common.Helper; +using Microsoft.Extensions.Options; +using Essensoft.AspNetCore.Payment.WeChatPay; +using Essensoft.AspNetCore.Payment.Alipay; +using Microsoft.Extensions.Logging; +using Essensoft.AspNetCore.Payment.Alipay.Domain; +using Essensoft.AspNetCore.Payment.Alipay.Request; +using System.Collections.Generic; +using LinqKit; +using System.Collections.Specialized; +using Org.BouncyCastle.Asn1.Ocsp; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using NPOI.SS.Formula.Functions; +using Essensoft.AspNetCore.Payment.WeChatPay.V3; + +namespace New_College.Services +{ + public class WeiChatPayServicesV3 : BaseServices, IWeiChatPayServicesV3 + { + private readonly IWeChatPayClient _client; + private readonly IOptions _optionsAccessor; + private readonly IAlipayClient alipayClient; + private readonly IOptions alipayoptions; + + private readonly IBaseRepository _dal; + private readonly IUnitOfWork _unitOfWork; + private readonly IV_CustomerInfoRepository v_CustomerInfoRepository; + private readonly IV_VipCardInfoRepository v_VipCardInfoRepository; + private readonly IV_VipCardTypeRepository v_VipCardTypeRepository; + + private readonly ILogger logger; + + public int Nums = 10; + public WeiChatPayServicesV3(IWeChatPayClient client, IOptions optionsAccessor + , IAlipayClient IAlipayClient, IOptions alipayopt + , IBaseRepository dal + , IUnitOfWork IUnitOfWork + , IV_CustomerInfoRepository IV_CustomerInfoRepository + , IV_VipCardInfoRepository IV_VipCardInfoRepository + , IV_VipCardTypeRepository IV_VipCardTypeRepository + , ILogger loggers + ) + { + _client = client; + _optionsAccessor = optionsAccessor; + alipayClient = IAlipayClient; + alipayoptions = alipayopt; + this._dal = dal; + _unitOfWork = IUnitOfWork; + v_CustomerInfoRepository = IV_CustomerInfoRepository; + v_VipCardInfoRepository = IV_VipCardInfoRepository; + v_VipCardTypeRepository = IV_VipCardTypeRepository; + logger = loggers; + base.BaseDal = dal; + } + + + /// + /// PC端扫描支付生成URL + /// + /// + /// + public async Task QrCodePay(WeChatPayTransactionsNativeQuery viewModel) + { + return await WeChatPayV3.QrCodePay(_client, _optionsAccessor, viewModel); + } + } +} \ No newline at end of file