using 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; namespace FlexJobApi.Core { /// /// 阿里支付工具 /// public class AlipayUtils { private readonly IAopClient alipayClient; private readonly ILogger logger; private readonly IOptions options; public AlipayUtils( ILogger logger, IOptions 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, AppId = options.Value.AppId, PrivateKey = options.Value.PrivateKey, Format = options.Value.Format, Charset = options.Value.Charset, SignType = options.Value.SignType, AppCertPath = appCertPath, AlipayPublicCertPath = alipayPublicCertPath, RootCertPath = rootCertPath, AlipayPublicKey = options.Value.AlipayPublicKey, EncryptKey = options.Value.EncryptKey, }); this.logger = logger; this.options = options; } /// /// 支付宝个人协议页面签约接口 /// /// /// public AlipayUserAgreementPageSignResponse UserAgreementPageSign(AlipayUserAgreementPageSignModel model, string notifyUrl = null) { logger.LogInformation($"正在执行支付宝个人协议页面签约接口:{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; } /// /// 支付宝个人代扣协议查询接口 /// /// public AlipayUserAgreementQueryResponse UserAgreementQuery(AlipayUserAgreementQueryModel model) { logger.LogInformation($"正在执行支付宝个人代扣协议查询接口:{model.ToJson()}"); AlipayUserAgreementQueryRequest request = new AlipayUserAgreementQueryRequest(); request.SetBizModel(model); AlipayUserAgreementQueryResponse response = alipayClient.CertificateExecute(request); logger.LogInformation($"结果:{response.ToJson()}"); return response; } /// /// 支付宝个人代扣协议解约接口 /// /// public AlipayUserAgreementUnsignResponse UserAgreementUnsign(AlipayUserAgreementUnsignModel model) { logger.LogInformation($"正在执行支付宝个人代扣协议解约接口:{model.ToJson()}"); AlipayUserAgreementUnsignRequest request = new AlipayUserAgreementUnsignRequest(); request.SetBizModel(model); AlipayUserAgreementUnsignResponse response = alipayClient.CertificateExecute(request); logger.LogInformation($"结果:{response.ToJson()}"); return response; } /// /// 资金二级商户KYB代进件文件上传接口 /// /// public AlipayFundExpandindirectImageUploadResponse FundExpandindirectImageUpload(AlipayFundExpandindirectImageUploadRequest request) { logger.LogInformation("正在执行资金二级商户KYB代进件文件上传接口"); AlipayFundExpandindirectImageUploadResponse response = alipayClient.CertificateExecute(request); logger.LogInformation($"结果:{response.ToJson()}"); return response; } /// /// 资金二级商户KYB代进件 /// /// /// /// public AlipayFundExpandindirectCreateResponse FundExpandindirectCreate(AlipayFundExpandindirectCreateModel model, string notifyUrl = null) { logger.LogInformation($"正在执行资金二级商户KYB代进件:{model.ToJson()}"); AlipayFundExpandindirectCreateRequest request = new AlipayFundExpandindirectCreateRequest(); request.SetBizModel(model); if (notifyUrl.IsNotNull()) { notifyUrl = $"{options.Value.NotifyUrl}{notifyUrl}"; request.SetNotifyUrl(notifyUrl); } AlipayFundExpandindirectCreateResponse response = alipayClient.CertificateExecute(request); logger.LogInformation($"结果:{response.ToJson()}"); return response; } /// /// 资金二级商户KYB代进件单查询接口 /// /// /// public AlipayFundExpandindirectOrderQueryResponse FundExpandindirectOrderQuery(AlipayFundExpandindirectOrderQueryModel model) { logger.LogInformation($"正在执行资金二级商户KYB代进件单查询接口:{model.ToJson()}"); AlipayFundExpandindirectOrderQueryRequest request = new AlipayFundExpandindirectOrderQueryRequest(); request.SetBizModel(model); AlipayFundExpandindirectOrderQueryResponse response = alipayClient.CertificateExecute(request); logger.LogInformation($"结果:{response.ToJson()}"); return response; } /// /// 资金二级商户KYB代进件单取消接口 /// /// /// public AlipayFundExpandindirectOrderCancelResponse FundExpandindirectOrderCancel(AlipayFundExpandindirectOrderCancelModel model) { logger.LogInformation($"正在执行资金二级商户KYB代进件单取消接口:{model.ToJson()}"); AlipayFundExpandindirectOrderCancelRequest request = new AlipayFundExpandindirectOrderCancelRequest(); request.SetBizModel(model); AlipayFundExpandindirectOrderCancelResponse response = alipayClient.CertificateExecute(request); logger.LogInformation($"结果:{response.ToJson()}"); return response; } } }