|
| 1 | +using System; |
| 2 | +using System.Net.Http; |
| 3 | +using System.Threading; |
| 4 | +using System.Threading.Tasks; |
| 5 | +using Flurl.Http; |
| 6 | + |
| 7 | +namespace SKIT.FlurlHttpClient.Wechat.TenpayV3 |
| 8 | +{ |
| 9 | + using SKIT.FlurlHttpClient.Primitives; |
| 10 | + |
| 11 | + public static class WechatTenpayClientExecuteMerchantManageExtensions |
| 12 | + { |
| 13 | + /// <summary> |
| 14 | + /// <para>异步调用 [GET] /mch-manage/mch-manage-records/sub-mchid/{sub_mchid} 接口。</para> |
| 15 | + /// <para> |
| 16 | + /// REF: <br/> |
| 17 | + /// <![CDATA[ https://pay.weixin.qq.com/doc/v3/partner/4014940381 ]]> |
| 18 | + /// </para> |
| 19 | + /// </summary> |
| 20 | + /// <param name="client"></param> |
| 21 | + /// <param name="request"></param> |
| 22 | + /// <param name="cancellationToken"></param> |
| 23 | + /// <returns></returns> |
| 24 | + public static async Task<Models.QueryMerchantManageRecordsResponse> ExecuteQueryMerchantManageRecordsAsync(this WechatTenpayClient client, Models.QueryMerchantManageRecordsRequest request, CancellationToken cancellationToken = default) |
| 25 | + { |
| 26 | + if (client is null) throw new ArgumentNullException(nameof(client)); |
| 27 | + if (request is null) throw new ArgumentNullException(nameof(request)); |
| 28 | + |
| 29 | + IFlurlRequest flurlReq = client |
| 30 | + .CreateFlurlRequest(request, HttpMethod.Get, "mch-manage", "mch-manage-records", "sub-mchid", request.SubMerchantId) |
| 31 | + .SetQueryParam("manage_record_type", request.ManageRecordType) |
| 32 | + .SetQueryParam("manage_record_state", request.ManageRecordState) |
| 33 | + .SetQueryParam("limit", request.Limit) |
| 34 | + .SetQueryParam("offset", request.Offset); |
| 35 | + |
| 36 | + return await client.SendFlurlRequestAsJsonAsync<Models.QueryMerchantManageRecordsResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false); |
| 37 | + } |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// <para>异步调用 [GET] /mch-manage/mch-manage-records/{manage_record_id} 接口。</para> |
| 41 | + /// <para> |
| 42 | + /// REF: <br/> |
| 43 | + /// <![CDATA[ https://pay.weixin.qq.com/doc/v3/partner/4014940383 ]]> |
| 44 | + /// </para> |
| 45 | + /// </summary> |
| 46 | + /// <param name="client"></param> |
| 47 | + /// <param name="request"></param> |
| 48 | + /// <param name="cancellationToken"></param> |
| 49 | + /// <returns></returns> |
| 50 | + public static async Task<Models.GetMerchantManageRecordResponse> ExecuteGetMerchantManageRecordAsync(this WechatTenpayClient client, Models.GetMerchantManageRecordRequest request, CancellationToken cancellationToken = default) |
| 51 | + { |
| 52 | + if (client is null) throw new ArgumentNullException(nameof(client)); |
| 53 | + if (request is null) throw new ArgumentNullException(nameof(request)); |
| 54 | + |
| 55 | + IFlurlRequest flurlReq = client |
| 56 | + .CreateFlurlRequest(request, HttpMethod.Get, "mch-manage", "mch-manage-records", request.ManageRecordId) |
| 57 | + .SetQueryParam("sub_mchid", request.SubMerchantId); |
| 58 | + |
| 59 | + return await client.SendFlurlRequestAsJsonAsync<Models.GetMerchantManageRecordResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false); |
| 60 | + } |
| 61 | + |
| 62 | + /// <summary> |
| 63 | + /// <para>异步调用 [POST] /mch-manage/mch-manage-records/{manage_record_id}/mch-manage-submissions 接口。</para> |
| 64 | + /// <para> |
| 65 | + /// REF: <br/> |
| 66 | + /// <![CDATA[ https://pay.weixin.qq.com/doc/v3/partner/4014940417 ]]> |
| 67 | + /// </para> |
| 68 | + /// </summary> |
| 69 | + /// <param name="client"></param> |
| 70 | + /// <param name="request"></param> |
| 71 | + /// <param name="cancellationToken"></param> |
| 72 | + /// <returns></returns> |
| 73 | + public static async Task<Models.CreateMerchantManageRecordSubmissionResponse> ExecuteCreateMerchantManageRecordSubmissionAsync(this WechatTenpayClient client, Models.CreateMerchantManageRecordSubmissionRequest request, CancellationToken cancellationToken = default) |
| 74 | + { |
| 75 | + if (client is null) throw new ArgumentNullException(nameof(client)); |
| 76 | + if (request is null) throw new ArgumentNullException(nameof(request)); |
| 77 | + |
| 78 | + IFlurlRequest flurlReq = client |
| 79 | + .CreateFlurlRequest(request, HttpMethod.Post, "mch-manage", "mch-manage-records", request.ManageRecordId, "mch-manage-submissions"); |
| 80 | + |
| 81 | + return await client.SendFlurlRequestAsJsonAsync<Models.CreateMerchantManageRecordSubmissionResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false); |
| 82 | + } |
| 83 | + |
| 84 | + /// <summary> |
| 85 | + /// <para>异步调用 [POST] /mch-manage/submission-files/sub-mchid/{sub_mchid}/upload 接口。</para> |
| 86 | + /// <para> |
| 87 | + /// REF: <br/> |
| 88 | + /// <![CDATA[ https://pay.weixin.qq.com/doc/v3/partner/4014940425 ]]> |
| 89 | + /// </para> |
| 90 | + /// </summary> |
| 91 | + /// <param name="client"></param> |
| 92 | + /// <param name="request"></param> |
| 93 | + /// <param name="cancellationToken"></param> |
| 94 | + /// <returns></returns> |
| 95 | + public static async Task<Models.UploadMerchantManageSubmissionFileResponse> ExecuteUploadMerchantManageSubmissionFileAsync(this WechatTenpayClient client, Models.UploadMerchantManageSubmissionFileRequest request, CancellationToken cancellationToken = default) |
| 96 | + { |
| 97 | + if (client is null) throw new ArgumentNullException(nameof(client)); |
| 98 | + if (request is null) throw new ArgumentNullException(nameof(request)); |
| 99 | + |
| 100 | + if (request.FileName is null) |
| 101 | + request.FileName = Guid.NewGuid().ToString("N").ToLower(); |
| 102 | + |
| 103 | + if (request.FileHash is null) |
| 104 | + request.FileHash = EncodedString.ToHexString(Utilities.SHA256Utility.Hash(request.FileBytes)).Value!.ToLower(); |
| 105 | + |
| 106 | + if (request.FileContentType is null) |
| 107 | + request.FileContentType = MimeTypes.GetMimeMapping(request.FileName!); |
| 108 | + |
| 109 | + IFlurlRequest flurlReq = client |
| 110 | + .CreateFlurlRequest(request, HttpMethod.Post, "mch-manage", "submission-files", "sub-mchid", request.SubMerchantId, "upload"); |
| 111 | + |
| 112 | + using var httpContent = Utilities.HttpContentBuilder.BuildWithFile(fileName: request.FileName, fileBytes: request.FileBytes, fileContentType: request.FileContentType, fileMetaJson: client.JsonSerializer.Serialize(request), formDataName: "submission_file"); |
| 113 | + httpContent.Add(new StringContent(request.ItemId), "item_id"); |
| 114 | + return await client.SendFlurlRequestAsync<Models.UploadMerchantManageSubmissionFileResponse>(flurlReq, httpContent: httpContent, cancellationToken: cancellationToken).ConfigureAwait(false); |
| 115 | + } |
| 116 | + } |
| 117 | +} |
0 commit comments