sunpengfei
2025-09-02 2dfe3b8df9d01bb810224115522ba90da9b31f21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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.FriendlyException;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace FlexJobApi.Core
{
    /// <summary>
    /// 阿里支付工具
    /// </summary>
    public class AlipayUtils
    {
        private readonly IAopClient alipayClient;
        private readonly ILogger<AlipayUtils> logger;
 
        public AlipayUtils(
            ILogger<AlipayUtils> logger,
            IOptions<AlipayOptions> options)
        {
            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 = options.Value.AppCertPath,
                AlipayPublicCertPath = options.Value.AlipayPublicCertPath,
                RootCertContent = options.Value.RootCertContent,
                AlipayPublicKey = options.Value.AlipayPublicKey,
                EncryptKey = options.Value.EncryptKey,
            });
            this.logger = logger;
        }
 
        public void UserAgreementPageSign(AlipayUserAgreementPageSignModel model)
        {
            // 初始化SDK
            // 构造请求参数以调用接口
            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("调用失败");
            }
        }
 
        /// <summary>
        /// 资金二级商户KYB代进件文件上传接口
        /// </summary>
        /// <returns></returns>
        public AlipayFundExpandindirectImageUploadResponse FundExpandindirectImageUpload(AlipayFundExpandindirectImageUploadRequest request)
        {
            logger.LogInformation("正在执行资金二级商户KYB代进件文件上传接口");
            AlipayFundExpandindirectImageUploadResponse response = alipayClient.Execute(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())
            {
                request.SetNotifyUrl(notifyUrl);
            }
            AlipayFundExpandindirectCreateResponse response = alipayClient.Execute(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.Execute(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.Execute(request);
            logger.LogInformation($"结果:{response.ToJson()}");
            return response;
        }
    }
}