From 210eeb923f17fa37a47b32e269be152bc20fe2c7 Mon Sep 17 00:00:00 2001 From: real-zony Date: Sun, 7 Jan 2024 20:52:51 +0800 Subject: [PATCH] feat: Added a new JS API signature method. (V3) --- .../WeChatPayClientRequestHandlingService.cs | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Pay/EasyAbp.Abp.WeChat.Pay/RequestHandling/WeChatPayClientRequestHandlingService.cs b/src/Pay/EasyAbp.Abp.WeChat.Pay/RequestHandling/WeChatPayClientRequestHandlingService.cs index 22476a1..980f925 100644 --- a/src/Pay/EasyAbp.Abp.WeChat.Pay/RequestHandling/WeChatPayClientRequestHandlingService.cs +++ b/src/Pay/EasyAbp.Abp.WeChat.Pay/RequestHandling/WeChatPayClientRequestHandlingService.cs @@ -1,25 +1,23 @@ -using System.Security.Cryptography; +using System.Text; using System.Threading.Tasks; using EasyAbp.Abp.WeChat.Common.Extensions; -using EasyAbp.Abp.WeChat.Common.Infrastructure; -using EasyAbp.Abp.WeChat.Common.Infrastructure.Signature; using EasyAbp.Abp.WeChat.Pay.Options; using EasyAbp.Abp.WeChat.Pay.RequestHandling.Dtos; +using EasyAbp.Abp.WeChat.Pay.Security; using Volo.Abp.DependencyInjection; namespace EasyAbp.Abp.WeChat.Pay.RequestHandling; public class WeChatPayClientRequestHandlingService : IWeChatPayClientRequestHandlingService, ITransientDependency { + private readonly ICertificatesManager _certificatesManager; private readonly IAbpWeChatPayOptionsProvider _optionsProvider; - private readonly ISignatureGenerator _signatureGenerator; - public WeChatPayClientRequestHandlingService( - IAbpWeChatPayOptionsProvider optionsProvider, - ISignatureGenerator signatureGenerator) + public WeChatPayClientRequestHandlingService(ICertificatesManager certificatesManager, + IAbpWeChatPayOptionsProvider optionsProvider) { + _certificatesManager = certificatesManager; _optionsProvider = optionsProvider; - _signatureGenerator = signatureGenerator; } public virtual async Task GetJsSdkWeChatPayParametersAsync( @@ -32,20 +30,18 @@ public virtual async Task GetJsSdkWeChatPayPa var options = await _optionsProvider.GetAsync(input.MchId); + const string signType = "RSA"; var nonceStr = RandomStringHelper.GetRandomString(); var timeStamp = DateTimeHelper.GetNowTimeStamp(); var package = $"prepay_id={input.PrepayId}"; - const string signType = "MD5"; - - var @params = new WeChatParameters(); - @params.AddParameter("appId", input.AppId); - @params.AddParameter("nonceStr", nonceStr); - @params.AddParameter("timeStamp", timeStamp); - @params.AddParameter("package", package); - @params.AddParameter("signType", signType); - - var paySign = _signatureGenerator.Generate(@params, MD5.Create(), options.ApiV3Key); + var waitSignString = new StringBuilder(); + waitSignString.Append(input.AppId).Append('\n') + .Append(timeStamp).Append('\n') + .Append(nonceStr).Append('\n') + .Append("prepay_id=").Append(input.PrepayId).Append('\n'); + var certificate = await _certificatesManager.GetCertificateAsync(options.MchId); + var paySign = _certificatesManager.GetSignature(waitSignString.ToString(), certificate); return new GetJsSdkWeChatPayParametersResult(nonceStr, timeStamp, package, signType, paySign); }