@@ -8,7 +8,7 @@ | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Essensoft.Paylink.WeChatPay" Version="4.1.3" /> | |||
<PackageReference Include="Essensoft.Paylink.WeChatPay" Version="4.1.2" /> | |||
<PackageReference Include="NPOI" Version="2.6.2" /> | |||
</ItemGroup> | |||
@@ -1,15 +0,0 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.WeighOrder.Dtos | |||
{ | |||
public class PayWeighOrderDto | |||
{ | |||
public string OrderId { get; set; } | |||
public string OpenId { get; set; } | |||
} | |||
} |
@@ -1,4 +1,6 @@ | |||
using System; | |||
using BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.WeighOrderPay.Dtos; | |||
using Essensoft.Paylink.WeChatPay.V2; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
@@ -8,5 +10,7 @@ namespace BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Servi | |||
{ | |||
public interface IWeighOrderService | |||
{ | |||
} | |||
} |
@@ -1,63 +1,29 @@ | |||
//using BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.CheckService.Services; | |||
//using BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.WeighOrder.Dtos; | |||
//using BPA.KitChen.GroupMealOrder.Core.Entity; | |||
//using Essensoft.Paylink.WeChatPay.V2; | |||
//using Essensoft.Paylink.WeChatPay.V2.Request; | |||
//using Furion.DependencyInjection; | |||
//using Microsoft.AspNetCore.Mvc; | |||
//using System; | |||
//using System.Collections.Generic; | |||
//using System.Linq; | |||
//using System.Text; | |||
//using System.Threading.Tasks; | |||
//namespace BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.WeighOrder.Service | |||
//{ | |||
// public class WeighOrderService : IWeighOrderService, ITransient | |||
// { | |||
// private readonly IWeChatPayClient _client; | |||
// public WeighOrderService(IWeChatPayClient client) | |||
// { | |||
// _client=client; | |||
// } | |||
// //public async Task<bool> PayOrder(PayWeighOrderDto inputDto) | |||
// //{ | |||
// // var order=SqlSugar.SqlSugarDb.Db.Queryable< BPA_WeighOrder >() | |||
// // .ClearFilter() | |||
// // .FirstAsync(x=>x.Id==inputDto.OrderId); | |||
// // var request = new WeChatPayUnifiedOrderRequest | |||
// // { | |||
// // Body = "", | |||
// // OutTradeNo = viewModel.OutTradeNo, | |||
// // TotalFee = viewModel.TotalFee, | |||
// // SpBillCreateIp = viewModel.SpBillCreateIp, | |||
// // NotifyUrl = viewModel.NotifyUrl, | |||
// // TradeType = viewModel.TradeType, | |||
// // OpenId = viewModel.OpenId | |||
// // }; | |||
// // var response = await _client.ExecuteAsync(request, _optionsAccessor.Value); | |||
// // if (response.ReturnCode == WeChatPayCode.Success && response.ResultCode == WeChatPayCode.Success) | |||
// // { | |||
// // var req = new WeChatPayMiniProgramSdkRequest | |||
// // { | |||
// // Package = "prepay_id=" + response.PrepayId | |||
// // }; | |||
// // var parameter = await _client.ExecuteAsync(req, _optionsAccessor.Value); | |||
// // // 将参数(parameter)给 小程序前端 让他调起支付API(https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=7_7&index=5) | |||
// // ViewData["parameter"] = JsonSerializer.Serialize(parameter); | |||
// // ViewData["response"] = response.Body; | |||
// // return View(); | |||
// // } | |||
// // ViewData["response"] = response.Body; | |||
// // return View(); | |||
// //} | |||
// } | |||
//} | |||
using BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.CheckService.Services; | |||
using BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.WeighOrderPay.Dtos; | |||
using BPA.KitChen.GroupMealOrder.Core.Entity; | |||
using Essensoft.Paylink.WeChatPay; | |||
using Essensoft.Paylink.WeChatPay.V2; | |||
using Essensoft.Paylink.WeChatPay.V2.Request; | |||
using Furion.DependencyInjection; | |||
using Furion.FriendlyException; | |||
using Microsoft.AspNetCore.Mvc; | |||
using Microsoft.Extensions.Options; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Net; | |||
using System.Net.NetworkInformation; | |||
using System.Net.Sockets; | |||
using System.Text; | |||
using System.Text.Json; | |||
using System.Text.RegularExpressions; | |||
using System.Threading.Tasks; | |||
namespace BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.WeighOrder.Service | |||
{ | |||
public class WeighOrderService : IWeighOrderService, ITransient | |||
{ | |||
} | |||
} |
@@ -2,9 +2,11 @@ | |||
using BPA.KitChen.GroupMealOrder.Application.BaseDto; | |||
using BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.WeighOrder.Dtos; | |||
using BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.WeighOrderPay.Dtos; | |||
using BPA.KitChen.GroupMealOrder.Application.Service.WeighOrder.Dtos; | |||
using BPA.KitChen.GroupMealOrder.Application.Service.WeighOrder.Service; | |||
using BPA.KitChen.GroupMealOrder.Core; | |||
using Essensoft.Paylink.WeChatPay.V2; | |||
using Furion.DynamicApiController; | |||
using Microsoft.AspNetCore.Authorization; | |||
using Microsoft.AspNetCore.Mvc; | |||
@@ -16,9 +18,11 @@ namespace BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Servi | |||
public class WeighOrderServices: IDynamicApiController | |||
{ | |||
private readonly IWeighOrderService _weighOrderService; | |||
public WeighOrderServices(IWeighOrderService weighOrderService) | |||
private readonly Service.IWeighOrderService _externalPlatformweighOrderService; | |||
public WeighOrderServices(IWeighOrderService weighOrderService, Service.IWeighOrderService externalPlatformweighOrderService) | |||
{ | |||
_weighOrderService = weighOrderService; | |||
_externalPlatformweighOrderService= externalPlatformweighOrderService; | |||
} | |||
/// <summary> | |||
@@ -110,5 +114,7 @@ namespace BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Servi | |||
{ | |||
return await _weighOrderService.GetWeighOrderByOpenId(inputDto); | |||
} | |||
} | |||
} |
@@ -0,0 +1,31 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.WeighOrderPay.Dtos | |||
{ | |||
public class PayWeighOrderDto | |||
{ | |||
public string OrderId { get; set; } | |||
public string OpenId { get; set; } | |||
} | |||
public class WeChatPayResponseDto | |||
{ | |||
public string parameter { get; set; } | |||
public string response { get; set; } | |||
} | |||
public class ContentResultDto | |||
{ | |||
public string Content { get; set; } | |||
public string ContentType { get; set; } | |||
public int? StatusCode { get; set; } | |||
} | |||
} |
@@ -0,0 +1,22 @@ | |||
using BPA.KitChen.GroupMealOrder.Core.Entity; | |||
using Essensoft.Paylink.WeChatPay.V2.Notify; | |||
using Essensoft.Paylink.WeChatPay.V2; | |||
using Essensoft.Paylink.WeChatPay; | |||
using Furion; | |||
using Microsoft.AspNetCore.Mvc; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.WeighOrderPay.Service | |||
{ | |||
public interface IWeighOrderPayNotify | |||
{ | |||
/// <summary> | |||
/// 统一下单支付结果通知 | |||
/// </summary> | |||
Task<IActionResult> Unifiedorder(); | |||
} | |||
} |
@@ -0,0 +1,19 @@ | |||
using BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.WeighOrderPay.Dtos; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.WeighOrderPay.Service | |||
{ | |||
public interface IWeighOrderPayService | |||
{ | |||
/// <summary> | |||
/// 订单支付 | |||
/// </summary> | |||
/// <param name="inputDto"></param> | |||
/// <returns></returns> | |||
Task<WeChatPayResponseDto> PayOrder(PayWeighOrderDto inputDto); | |||
} | |||
} |
@@ -0,0 +1,95 @@ | |||
using Essensoft.Paylink.WeChatPay.V2.Notify; | |||
using Essensoft.Paylink.WeChatPay.V2; | |||
using Essensoft.Paylink.WeChatPay; | |||
using Furion.DependencyInjection; | |||
using Microsoft.AspNetCore.Mvc; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using Microsoft.Extensions.Options; | |||
using Org.BouncyCastle.Asn1.Ocsp; | |||
using Furion; | |||
using BPA.KitChen.GroupMealOrder.Core.Entity; | |||
namespace BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.WeighOrderPay.Service | |||
{ | |||
public class WeighOrderPayNotify: IWeighOrderPayNotify, ITransient | |||
{ | |||
private readonly IWeChatPayNotifyClient _client; | |||
private readonly IOptions<WeChatPayOptions> _optionsAccessor; | |||
public WeighOrderPayNotify( IWeChatPayNotifyClient client, | |||
IOptions<WeChatPayOptions> optionsAccessor) | |||
{ | |||
_client = client; | |||
_optionsAccessor = optionsAccessor; | |||
} | |||
/// <summary> | |||
/// 统一下单支付结果通知 | |||
/// </summary> | |||
public async Task<IActionResult> Unifiedorder() | |||
{ | |||
try | |||
{ | |||
var data= App.HttpContext.Request; | |||
var notify = await _client.ExecuteAsync<WeChatPayUnifiedOrderNotify>(data, _optionsAccessor.Value); | |||
//查询订单 | |||
var order = await SqlSugar.SqlSugarDb.Db.Queryable<BPA_WeighOrder>() | |||
.ClearFilter() | |||
.FirstAsync(x => x.Id == notify.OutTradeNo); | |||
if (order == null) | |||
{ | |||
return WeChatPayNotifyResult.Failure; | |||
} | |||
if (notify.ReturnCode == WeChatPayCode.Success) | |||
{ | |||
order.States = 1; | |||
order.PayStates = 1; | |||
await SqlSugar.SqlSugarDb.Db.Updateable(order).ExecuteCommandAsync(); | |||
return WeChatPayNotifyResult.Success; | |||
} | |||
return WeChatPayNotifyResult.Failure; | |||
} | |||
catch (WeChatPayException ex) | |||
{ | |||
return WeChatPayNotifyResult.Failure; | |||
} | |||
} | |||
/// <summary> | |||
/// 退款结果通知 | |||
/// </summary> | |||
public async Task<IActionResult> Refund() | |||
{ | |||
try | |||
{ | |||
var data = App.HttpContext.Request; | |||
var notify = await _client.ExecuteAsync<WeChatPayRefundNotify>(data, _optionsAccessor.Value); | |||
if (notify.ReturnCode == WeChatPayCode.Success) | |||
{ | |||
if (notify.RefundStatus == WeChatPayRefundStatus.Success) | |||
{ | |||
return WeChatPayNotifyResult.Success; | |||
} | |||
} | |||
return WeChatPayNotifyResult.Failure; | |||
} | |||
catch (WeChatPayException ex) | |||
{ | |||
return WeChatPayNotifyResult.Failure; | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,84 @@ | |||
using BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.WeighOrderPay.Dtos; | |||
using BPA.KitChen.GroupMealOrder.Core.Entity; | |||
using Essensoft.Paylink.WeChatPay.V2; | |||
using Essensoft.Paylink.WeChatPay; | |||
using Furion.DependencyInjection; | |||
using Furion.FriendlyException; | |||
using Microsoft.Extensions.Options; | |||
using System.Net; | |||
using Essensoft.Paylink.WeChatPay.V2.Request; | |||
using System.Text.Json; | |||
using Furion; | |||
namespace BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.WeighOrderPay.Service | |||
{ | |||
public class WeighOrderPayService : IWeighOrderPayService, ITransient | |||
{ | |||
private readonly IWeChatPayClient _client; | |||
private readonly IOptions<WeChatPayOptions> _optionsAccessor; | |||
public WeighOrderPayService(IWeChatPayClient client, IOptions<WeChatPayOptions> optionsAccessor) | |||
{ | |||
_client = client; | |||
_optionsAccessor = optionsAccessor; | |||
} | |||
/// <summary> | |||
/// 订单支付 | |||
/// </summary> | |||
/// <param name="inputDto"></param> | |||
/// <returns></returns> | |||
public async Task<WeChatPayResponseDto> PayOrder(PayWeighOrderDto inputDto) | |||
{ | |||
var result = new WeChatPayResponseDto(); | |||
var order = await SqlSugar.SqlSugarDb.Db.Queryable<BPA_WeighOrder>() | |||
.ClearFilter() | |||
.FirstAsync(x => x.Id == inputDto.OrderId); | |||
if (order == null) | |||
{ | |||
throw Oops.Oh("订单不存在"); | |||
} | |||
if (order.PayStates == 1) | |||
{ | |||
throw Oops.Oh("订单已支付"); | |||
} | |||
IPHostEntry ipHost = Dns.GetHostEntry(Dns.GetHostName());//Dns.GetHostEntry方法没有过时,但是获取的是v4和v6的所有ip地址 | |||
IPAddress ipAddress = ipHost.AddressList.Where(x => x.AddressFamily.ToString() == "InterNetwork").FirstOrDefault();//InterNetwork是v4的IP,但是依然是多个 | |||
var request = new WeChatPayUnifiedOrderRequest | |||
{ | |||
Body = order.Id, | |||
OutTradeNo = order.Id, | |||
TotalFee = Convert.ToInt32(order.TotalAmount * 100), | |||
SpBillCreateIp = ipAddress.ToString(), | |||
NotifyUrl = App.Configuration["DomainName"] +"api/ExternalPlatform/WeighOrder/Unifiedorder", | |||
TradeType = "JSAPI", | |||
OpenId = inputDto.OpenId | |||
}; | |||
var response = await _client.ExecuteAsync(request, _optionsAccessor.Value); | |||
if (response.ReturnCode == WeChatPayCode.Success && response.ResultCode == WeChatPayCode.Success) | |||
{ | |||
var req = new WeChatPayMiniProgramSdkRequest | |||
{ | |||
Package = "prepay_id=" + response.PrepayId | |||
}; | |||
var parameter = await _client.ExecuteAsync(req, _optionsAccessor.Value); | |||
// 将参数(parameter)给 小程序前端 让他调起支付API(https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=7_7&index=5) | |||
result.parameter = JsonSerializer.Serialize(parameter); | |||
result.response = response.Body; | |||
return result; | |||
} | |||
result.response = response.Body; | |||
return result; | |||
} | |||
} | |||
} |
@@ -0,0 +1,51 @@ | |||
using BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.WeighOrderPay.Dtos; | |||
using BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.WeighOrderPay.Service; | |||
using BPA.KitChen.GroupMealOrder.Core.Entity; | |||
using Essensoft.Paylink.WeChatPay.V2.Notify; | |||
using Essensoft.Paylink.WeChatPay.V2; | |||
using Essensoft.Paylink.WeChatPay; | |||
using Furion; | |||
using Furion.DynamicApiController; | |||
using Microsoft.AspNetCore.Mvc; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.WeighOrderPay | |||
{ | |||
public class WeighOrderPayServices: IDynamicApiController | |||
{ | |||
private readonly Service.IWeighOrderPayNotify _weighOrderPayNotify; | |||
private readonly Service.IWeighOrderPayService _weighOrderPayService; | |||
public WeighOrderPayServices(IWeighOrderPayService weighOrderPayService, | |||
Service.IWeighOrderPayNotify weighOrderPayNotify) | |||
{ | |||
_weighOrderPayService = weighOrderPayService; | |||
_weighOrderPayNotify= weighOrderPayNotify; | |||
} | |||
/// <summary> | |||
/// 订单支付 | |||
/// </summary> | |||
/// <param name="inputDto"></param> | |||
/// <returns></returns> | |||
[HttpPost("/api/ExternalPlatform/WeighOrder/PayOrder")] | |||
public async Task<WeChatPayResponseDto> PayOrder(PayWeighOrderDto inputDto) | |||
{ | |||
return await _weighOrderPayService.PayOrder(inputDto); | |||
} | |||
/// <summary> | |||
/// 统一下单支付结果通知 | |||
/// </summary> | |||
[HttpPost("/api/ExternalPlatform/WeighOrder/Unifiedorder")] | |||
public async Task<IActionResult> Unifiedorder() | |||
{ | |||
return await _weighOrderPayNotify.Unifiedorder(); | |||
} | |||
} | |||
} |
@@ -8,7 +8,6 @@ | |||
<ItemGroup> | |||
<PackageReference Include="EasyNetQ" Version="7.8.0" /> | |||
<PackageReference Include="Essensoft.Paylink.WeChatPay" Version="4.1.3" /> | |||
<PackageReference Include="Furion" Version="4.9.1.20" /> | |||
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.1.20" /> | |||
<PackageReference Include="SqlSugarCore" Version="5.1.4.134" /> | |||
@@ -1,5 +1,15 @@ | |||
using BPA.KitChen.GroupMealOrder.Handlers; | |||
using BPA.KitChen.GroupMealOrder.SqlSugar; | |||
using Essensoft.Paylink.WeChatPay; | |||
using Essensoft.Paylink.WeChatPay; | |||
using Furion; | |||
using Microsoft.AspNetCore.Builder; | |||
using Microsoft.AspNetCore.Hosting; | |||
using Microsoft.Extensions.Configuration; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using Microsoft.Extensions.Hosting; | |||
var builder = WebApplication.CreateBuilder(args).Inject(); | |||
@@ -13,6 +23,15 @@ builder.Services.AddUnifyResult(); | |||
builder.Services.AddControllers().AddInject(); | |||
builder.Services.AddSqlsugarSetup(); | |||
builder.Services.AddMvcFilter<RequestAuditFiltercs>(); | |||
// Ìí¼ÓPaylinkÒÀÀµ×¢Èë | |||
builder.Services.AddWeChatPay(); | |||
IConfigurationRoot config = new ConfigurationBuilder() | |||
.AddJsonFile("appsettings.json") | |||
.AddEnvironmentVariables() | |||
.Build(); | |||
builder.Services.Configure<WeChatPayOptions>(config.GetSection("WeChatPay")); | |||
var app = builder.Build(); | |||
@@ -8,7 +8,36 @@ | |||
"SAAS_Manage": "http://10.2.1.26:21995/saasbase/", | |||
"GroupMealBaseUrl": "http://localhost:5001/", | |||
"GroupMealUrl": "http://localhost:5002/", | |||
"DomainName": "https://bpa.black-pa.com:21995/order/", | |||
"DBConnectionStr": "server=10.2.1.21;Port=3306;Database=bpa_kitchen_groupmealorder;Uid=root;Pwd=cygadmin;", | |||
"DBConnectionLogStr": "server=10.2.1.21;Port=3306;Database=bpa_kitchen_groupmeallog;Uid=root;Pwd=cygadmin;", | |||
"AllowedHosts": "*" | |||
"AllowedHosts": "*", | |||
// 微信支付 | |||
// 更多配置,请查看WeChatPayOptions类 | |||
"WeChatPay": { | |||
// 应用号 | |||
// 如:微信公众平台AppId、微信开放平台AppId、微信小程序AppId、企业微信CorpId等 | |||
"AppId": "2021003145639786", | |||
// 商户号 | |||
// 为微信支付商户平台的商户号 | |||
"MchId": "", | |||
// 商户API密钥 | |||
// 为微信支付商户平台的API密钥,请注意不是APIv3密钥 | |||
"APIKey": "", | |||
// 商户APIv3密钥 | |||
// 为微信支付商户平台的APIv3密钥,请注意不是API密钥,v3接口必填 | |||
"APIv3Key": "", | |||
// 商户API证书 | |||
// 使用V2退款、付款等接口时必填 | |||
// 使用V3接口时必填 | |||
// 可为证书文件路径 / 证书文件的base64字符串 | |||
"Certificate": "", | |||
// 商户API私钥 | |||
// 当配置了P12格式证书时,已包含私钥,不必再单独配置API私钥。 | |||
// PEM格式证书,需要单独配置。 | |||
"APIPrivateKey": "", | |||
// RSA公钥 | |||
// 目前仅调用"企业付款到银行卡API [V2]"时使用,执行本示例中的"获取RSA加密公钥API [V2]"即可获取。 | |||
"RsaPublicKey": "" | |||
} | |||
} |