| | |
| | | using Aliyun.OSS; |
| | | 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; |
| | |
| | | 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, |
| | |
| | | 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, |
| | | }); |
| | | this.logger = logger; |
| | | this.options = options; |
| | | } |
| | | |
| | | public void UserAgreementPageSign(AlipayUserAgreementPageSignModel model) |
| | | /// <summary> |
| | | /// 支付宝个人协议页面签约接口 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <param name="notifyUrl"></param> |
| | | public AlipayUserAgreementPageSignResponse UserAgreementPageSign(AlipayUserAgreementPageSignModel model, string notifyUrl = null) |
| | | { |
| | | // 初始化SDK |
| | | // 构造请求参数以调用接口 |
| | | logger.LogInformation($"正在执行支付宝个人协议页面签约接口:{model.ToJson()}"); |
| | | 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(); |
| | | if (notifyUrl.IsNotNull()) |
| | | { |
| | | notifyUrl = $"{options.Value.NotifyUrl}{notifyUrl}"; |
| | | request.SetNotifyUrl(notifyUrl); |
| | | } |
| | | AlipayUserAgreementPageSignResponse response = alipayClient.pageExecute(request, null, "GET"); |
| | | string pageRedirectionData = response.Body; |
| | | Console.WriteLine(pageRedirectionData); |
| | | |
| | | if (!response.IsError) |
| | | { |
| | | Console.WriteLine("调用成功"); |
| | | } |
| | | else |
| | | { |
| | | Console.WriteLine("调用失败"); |
| | | } |
| | | logger.LogInformation($"结果:{response.ToJson()}"); |
| | | return response; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 支付宝个人代扣协议查询接口 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | 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; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 支付宝个人代扣协议解约接口 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | 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; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 单笔转账接口 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | public AlipayFundTransUniTransferResponse FundTransUniTransfer(AlipayFundTransUniTransferModel model) |
| | | { |
| | | logger.LogInformation($"正在执行单笔转账接口:{model.ToJson()}"); |
| | | AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest(); |
| | | request.SetBizModel(model); |
| | | AlipayFundTransUniTransferResponse response = alipayClient.CertificateExecute(request); |
| | | logger.LogInformation($"结果:{response.ToJson()}"); |
| | | return response; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 资金二级商户KYB代进件文件上传接口 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public AlipayFundExpandindirectImageUploadResponse FundExpandindirectImageUpload(AlipayFundExpandindirectImageUploadRequest request) |
| | | { |
| | | logger.LogInformation("正在执行资金二级商户KYB代进件文件上传接口"); |
| | | AlipayFundExpandindirectImageUploadResponse response = alipayClient.CertificateExecute(request); |
| | | logger.LogInformation($"结果:{response.ToJson()}"); |
| | | return response; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 资金二级商户KYB代进件 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <param name="notifyUrl"></param> |
| | | /// <returns></returns> |
| | | 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.Execute(request); |
| | | AlipayFundExpandindirectCreateResponse response = alipayClient.CertificateExecute(request); |
| | | logger.LogInformation($"结果:{response.ToJson()}"); |
| | | return response; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 资金二级商户KYB代进件单查询接口 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | 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; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 资金二级商户KYB代进件单取消接口 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | 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; |
| | | } |
| | | } |