mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2026-02-12 02:36:21 +08:00
93 lines
4.7 KiB
C#
93 lines
4.7 KiB
C#
using System;
|
|
using System.Net.Http;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Flurl.Http;
|
|
|
|
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
|
|
{
|
|
public static class WechatTenpayClientExecuteHKMerchantsExtensions
|
|
{
|
|
/// <summary>
|
|
/// <para>异步调用 [POST] /merchants 接口。</para>
|
|
/// <para>
|
|
/// REF: <br/>
|
|
/// <![CDATA[ https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/Onborading_Sub_Merchant/chapter3_1.shtml ]]>
|
|
/// </para>
|
|
/// <para><i>(请注意此接口专为境外支付设计,调用时需在构造 <see cref="WechatTenpayClient" /> 时指定单独的 <see cref="WechatTenpayClientOptions.Endpoint"/>。)</i></para>
|
|
/// </summary>
|
|
/// <param name="client"></param>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public static async Task<Models.AddHKSubMerchantResponse> ExecuteAddHKSubMerchantAsync(this WechatTenpayClient client, Models.AddHKSubMerchantRequest request, CancellationToken cancellationToken = default)
|
|
{
|
|
if (client is null) throw new ArgumentNullException(nameof(client));
|
|
if (request is null) throw new ArgumentNullException(nameof(request));
|
|
|
|
if (request.MerchantId is null)
|
|
request.MerchantId = client.Credentials.MerchantId;
|
|
|
|
IFlurlRequest flurlReq = client
|
|
.CreateFlurlRequest(request, HttpMethod.Post, "merchants")
|
|
.WithHeader("Idempotency-Key", request.IdempotencyKey);
|
|
|
|
return await client.SendFlurlRequestAsJsonAsync<Models.AddHKSubMerchantResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>异步调用 [GET] /merchants/{sub_mchid} 接口。</para>
|
|
/// <para>
|
|
/// REF: <br/>
|
|
/// <![CDATA[ https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/Onborading%20Sub%20Merchant/chapter3_2.shtml ]]>
|
|
/// </para>
|
|
/// <para><i>(请注意此接口专为境外支付设计,调用时需在构造 <see cref="WechatTenpayClient" /> 时指定单独的 <see cref="WechatTenpayClientOptions.Endpoint"/>。)</i></para>
|
|
/// </summary>
|
|
/// <param name="client"></param>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public static async Task<Models.GetHKSubMerchantResponse> ExecuteGetHKSubMerchantAsync(this WechatTenpayClient client, Models.GetHKSubMerchantRequest request, CancellationToken cancellationToken = default)
|
|
{
|
|
if (client is null) throw new ArgumentNullException(nameof(client));
|
|
if (request is null) throw new ArgumentNullException(nameof(request));
|
|
|
|
if (request.MerchantId is null)
|
|
request.MerchantId = client.Credentials.MerchantId;
|
|
|
|
IFlurlRequest flurlReq = client
|
|
.CreateFlurlRequest(request, HttpMethod.Get, "merchants", request.SubMerchantId)
|
|
.SetQueryParam("sp_mchid", request.MerchantId)
|
|
.SetQueryParam("sp_appid", request.AppId);
|
|
|
|
return await client.SendFlurlRequestAsJsonAsync<Models.GetHKSubMerchantResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>异步调用 [PUT] /merchants 接口。</para>
|
|
/// <para>
|
|
/// REF: <br/>
|
|
/// <![CDATA[ https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/Onborading_Sub_Merchant/chapter3_3.shtml ]]>
|
|
/// </para>
|
|
/// <para><i>(请注意此接口专为境外支付设计,调用时需在构造 <see cref="WechatTenpayClient" /> 时指定单独的 <see cref="WechatTenpayClientOptions.Endpoint"/>。)</i></para>
|
|
/// </summary>
|
|
/// <param name="client"></param>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public static async Task<Models.ModifyHKSubMerchantResponse> ExecuteModifyHKSubMerchantAsync(this WechatTenpayClient client, Models.ModifyHKSubMerchantRequest request, CancellationToken cancellationToken = default)
|
|
{
|
|
if (client is null) throw new ArgumentNullException(nameof(client));
|
|
if (request is null) throw new ArgumentNullException(nameof(request));
|
|
|
|
if (request.MerchantId is null)
|
|
request.MerchantId = client.Credentials.MerchantId;
|
|
|
|
IFlurlRequest flurlReq = client
|
|
.CreateFlurlRequest(request, HttpMethod.Put, "merchants");
|
|
|
|
return await client.SendFlurlRequestAsJsonAsync<Models.ModifyHKSubMerchantResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
|
}
|
|
}
|
|
}
|