From 582011fe0778b89312a3a9f886a24d687530aad4 Mon Sep 17 00:00:00 2001 From: sunpengfei <i@angelzzz.com> Date: 星期二, 02 九月 2025 14:45:47 +0800 Subject: [PATCH] feat:开发 --- FlexJobApi.Core/Utils/AlipayUtils/AlipayUtils.cs | 126 +++++++++++++++++++++++++++--------------- 1 files changed, 81 insertions(+), 45 deletions(-) diff --git a/FlexJobApi.Core/Utils/AlipayUtils/AlipayUtils.cs b/FlexJobApi.Core/Utils/AlipayUtils/AlipayUtils.cs index 8fe6911..f363e67 100644 --- a/FlexJobApi.Core/Utils/AlipayUtils/AlipayUtils.cs +++ b/FlexJobApi.Core/Utils/AlipayUtils/AlipayUtils.cs @@ -1,13 +1,18 @@ -锘縰sing Aliyun.OSS; +锘縰sing Aliyun.Acs.Core.Logging; +using Aliyun.OSS; using Aop.Api; using Aop.Api.Domain; using Aop.Api.Request; using Aop.Api.Response; using Aop.Api.Util; +using Furion; using Furion.FriendlyException; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -20,9 +25,16 @@ public class AlipayUtils { private readonly IAopClient alipayClient; + private readonly ILogger<AlipayUtils> logger; + private readonly IOptions<AlipayOptions> options; - public AlipayUtils(IOptions<AlipayOptions> options) + public AlipayUtils( + ILogger<AlipayUtils> logger, + IOptions<AlipayOptions> options) { + var appCertPath = Path.Combine(App.WebHostEnvironment.ContentRootPath, options.Value.AppCertPath); + var alipayPublicCertPath = Path.Combine(App.WebHostEnvironment.ContentRootPath, options.Value.AlipayPublicCertPath); + var rootCertPath = Path.Combine(App.WebHostEnvironment.ContentRootPath, options.Value.RootCertPath); alipayClient = new DefaultAopClient(new AlipayConfig { ServerUrl = options.Value.ServerUrl, @@ -31,53 +43,73 @@ Format = options.Value.Format, Charset = options.Value.Charset, SignType = options.Value.SignType, - AppCertPath = options.Value.AppCertPath, - AlipayPublicCertPath = options.Value.AlipayPublicCertPath, - RootCertContent = options.Value.RootCertContent, + AppCertPath = appCertPath, + AlipayPublicCertPath = alipayPublicCertPath, + RootCertPath = rootCertPath, AlipayPublicKey = options.Value.AlipayPublicKey, EncryptKey = options.Value.EncryptKey, }); - } - - public void UserAgreementPageSign(AlipayUserAgreementPageSignModel model) - { - // 鍒濆鍖朣DK - // 鏋勯�犺姹傚弬鏁颁互璋冪敤鎺ュ彛 - AlipayUserAgreementPageSignRequest request = new AlipayUserAgreementPageSignRequest(); - model.PersonalProductCode = "FUND_SAFT_SIGN_WITHHOLDING_P"; - model.SignScene = "INDUSTRY|SATF_ACC"; - model.ThirdPartyType = "PARTNER"; - model.AccessParams = new AccessParams - { - Channel = "" - }; - // 璁剧疆绛剧害鏈夋晥鏃堕棿闄愬埗 - model.EffectTime = 300; - - request.SetBizModel(model); - //request.SetNotifyUrl(); - AlipayUserAgreementPageSignResponse response = alipayClient.pageExecute(request, null, "GET"); - string pageRedirectionData = response.Body; - Console.WriteLine(pageRedirectionData); - - if (!response.IsError) - { - Console.WriteLine("璋冪敤鎴愬姛"); - } - else - { - Console.WriteLine("璋冪敤澶辫触"); - } + this.logger = logger; + this.options = options; } /// <summary> - /// 璧勯噾浜岀骇鍟嗘埛KYB浠h繘浠� + /// 鏀粯瀹濅釜浜哄崗璁〉闈㈢绾︽帴鍙� + /// </summary> + /// <param name="model"></param> + /// <param name="notifyUrl"></param> + public AlipayUserAgreementPageSignResponse UserAgreementPageSign(AlipayUserAgreementPageSignModel model, string notifyUrl = null) + { + logger.LogInformation($"姝e湪鎵ц鏀粯瀹濅釜浜哄崗璁〉闈㈢绾︽帴鍙o細{model.ToJson()}"); + AlipayUserAgreementPageSignRequest request = new AlipayUserAgreementPageSignRequest(); + request.SetBizModel(model); + if (notifyUrl.IsNotNull()) + { + notifyUrl = $"{options.Value.NotifyUrl}{notifyUrl}"; + request.SetNotifyUrl(notifyUrl); + } + AlipayUserAgreementPageSignResponse response = alipayClient.pageExecute(request, null, "GET"); + logger.LogInformation($"缁撴灉锛歿response.ToJson()}"); + return response; + } + + /// <summary> + /// 鏀粯瀹濅釜浜轰唬鎵e崗璁煡璇㈡帴鍙� + /// </summary> + /// <param name="model"></param> + public AlipayUserAgreementQueryResponse UserAgreementQuery(AlipayUserAgreementQueryModel model) + { + logger.LogInformation($"姝e湪鎵ц鏀粯瀹濅釜浜轰唬鎵e崗璁煡璇㈡帴鍙o細{model.ToJson()}"); + AlipayUserAgreementQueryRequest request = new AlipayUserAgreementQueryRequest(); + request.SetBizModel(model); + AlipayUserAgreementQueryResponse response = alipayClient.CertificateExecute(request); + logger.LogInformation($"缁撴灉锛歿response.ToJson()}"); + return response; + } + + /// <summary> + /// 鏀粯瀹濅釜浜轰唬鎵e崗璁В绾︽帴鍙� + /// </summary> + /// <param name="model"></param> + public AlipayUserAgreementUnsignResponse UserAgreementUnsign(AlipayUserAgreementUnsignModel model) + { + logger.LogInformation($"姝e湪鎵ц鏀粯瀹濅釜浜轰唬鎵e崗璁В绾︽帴鍙o細{model.ToJson()}"); + AlipayUserAgreementUnsignRequest request = new AlipayUserAgreementUnsignRequest(); + request.SetBizModel(model); + AlipayUserAgreementUnsignResponse response = alipayClient.CertificateExecute(request); + logger.LogInformation($"缁撴灉锛歿response.ToJson()}"); + return response; + } + + /// <summary> + /// 璧勯噾浜岀骇鍟嗘埛KYB浠h繘浠舵枃浠朵笂浼犳帴鍙� /// </summary> /// <returns></returns> public AlipayFundExpandindirectImageUploadResponse FundExpandindirectImageUpload(AlipayFundExpandindirectImageUploadRequest request) { - AlipayFundExpandindirectImageUploadResponse response = alipayClient.Execute(request); - if (response.IsError) throw Oops.Oh(EnumErrorCodeType.s510, response.Msg); + logger.LogInformation("姝e湪鎵ц璧勯噾浜岀骇鍟嗘埛KYB浠h繘浠舵枃浠朵笂浼犳帴鍙�"); + AlipayFundExpandindirectImageUploadResponse response = alipayClient.CertificateExecute(request); + logger.LogInformation($"缁撴灉锛歿response.ToJson()}"); return response; } @@ -89,14 +121,16 @@ /// <returns></returns> public AlipayFundExpandindirectCreateResponse FundExpandindirectCreate(AlipayFundExpandindirectCreateModel model, string notifyUrl = null) { + logger.LogInformation($"姝e湪鎵ц璧勯噾浜岀骇鍟嗘埛KYB浠h繘浠讹細{model.ToJson()}"); AlipayFundExpandindirectCreateRequest request = new AlipayFundExpandindirectCreateRequest(); request.SetBizModel(model); if (notifyUrl.IsNotNull()) { + notifyUrl = $"{options.Value.NotifyUrl}{notifyUrl}"; request.SetNotifyUrl(notifyUrl); } - AlipayFundExpandindirectCreateResponse response = alipayClient.Execute(request); - if (response.IsError) throw Oops.Oh(EnumErrorCodeType.s510, response.Msg); + AlipayFundExpandindirectCreateResponse response = alipayClient.CertificateExecute(request); + logger.LogInformation($"缁撴灉锛歿response.ToJson()}"); return response; } @@ -107,10 +141,11 @@ /// <returns></returns> public AlipayFundExpandindirectOrderQueryResponse FundExpandindirectOrderQuery(AlipayFundExpandindirectOrderQueryModel model) { + logger.LogInformation($"姝e湪鎵ц璧勯噾浜岀骇鍟嗘埛KYB浠h繘浠跺崟鏌ヨ鎺ュ彛锛歿model.ToJson()}"); AlipayFundExpandindirectOrderQueryRequest request = new AlipayFundExpandindirectOrderQueryRequest(); request.SetBizModel(model); - AlipayFundExpandindirectOrderQueryResponse response = alipayClient.Execute(request); - if (response.IsError) throw Oops.Oh(EnumErrorCodeType.s510, response.Msg); + AlipayFundExpandindirectOrderQueryResponse response = alipayClient.CertificateExecute(request); + logger.LogInformation($"缁撴灉锛歿response.ToJson()}"); return response; } @@ -122,10 +157,11 @@ /// <returns></returns> public AlipayFundExpandindirectOrderCancelResponse FundExpandindirectOrderCancel(AlipayFundExpandindirectOrderCancelModel model) { + logger.LogInformation($"姝e湪鎵ц璧勯噾浜岀骇鍟嗘埛KYB浠h繘浠跺崟鍙栨秷鎺ュ彛锛歿model.ToJson()}"); AlipayFundExpandindirectOrderCancelRequest request = new AlipayFundExpandindirectOrderCancelRequest(); request.SetBizModel(model); - AlipayFundExpandindirectOrderCancelResponse response = alipayClient.Execute(request); - if (response.IsError) throw Oops.Oh(EnumErrorCodeType.s510, response.Msg); + AlipayFundExpandindirectOrderCancelResponse response = alipayClient.CertificateExecute(request); + logger.LogInformation($"缁撴灉锛歿response.ToJson()}"); return response; } } -- Gitblit v1.9.1