mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2026-02-14 03:56:22 +08:00
47 lines
2.4 KiB
C#
47 lines
2.4 KiB
C#
using System;
|
|
using System.Net.Http;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Flurl.Http;
|
|
|
|
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
|
|
{
|
|
using SKIT.FlurlHttpClient.Primitives;
|
|
|
|
public static class WechatTenpayClientExecuteMarketingBankExtensions
|
|
{
|
|
/// <summary>
|
|
/// <para>异步调用 [POST] /marketing/bank/packages/{package_id}/tasks 接口。</para>
|
|
/// <para>
|
|
/// REF: <br/>
|
|
/// <![CDATA[ https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_8_1.shtml ]]> <br/>
|
|
/// <![CDATA[ https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter9_8_1.shtml ]]>
|
|
/// </para>
|
|
/// </summary>
|
|
/// <param name="client"></param>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public static async Task<Models.UploadMarketingBankPackagesTasksResponse> ExecuteUploadMarketingBankPackagesTasksAsync(this WechatTenpayClient client, Models.UploadMarketingBankPackagesTasksRequest request, CancellationToken cancellationToken = default)
|
|
{
|
|
if (client is null) throw new ArgumentNullException(nameof(client));
|
|
if (request is null) throw new ArgumentNullException(nameof(request));
|
|
|
|
if (request.FileName is null)
|
|
request.FileName = Guid.NewGuid().ToString("N").ToLower() + ".txt";
|
|
|
|
if (request.FileHash is null)
|
|
request.FileHash = EncodedString.ToHexString(Utilities.SHA256Utility.Hash(request.FileBytes ?? Array.Empty<byte>())).Value!.ToLower();
|
|
|
|
if (request.FileContentType is null)
|
|
request.FileContentType = Utilities.FileNameToContentTypeMapper.GetContentTypeForImage(request.FileName!) ?? "text/plain";
|
|
|
|
IFlurlRequest flurlReq = client
|
|
.CreateFlurlRequest(request, HttpMethod.Post, "marketing", "bank", "packages", request.PackageId, "tasks");
|
|
|
|
using var httpContent = Utilities.FileHttpContentBuilder.Build(fileName: request.FileName, fileBytes: request.FileBytes!, fileContentType: request.FileContentType, fileMetaJson: client.JsonSerializer.Serialize(request));
|
|
return await client.SendFlurlRequestAsync<Models.UploadMarketingBankPackagesTasksResponse>(flurlReq, httpContent: httpContent, cancellationToken: cancellationToken).ConfigureAwait(false);
|
|
}
|
|
}
|
|
}
|