mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-12-29 18:04:42 +08:00
feat(tenpayv2): 新增境外子商户进件相关接口
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Flurl.Http;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV2
|
||||
{
|
||||
public static class WechatTenpayClientExecuteMerchantInstitutionSubExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /secapi/mch/addInstitutionsub 接口。</para>
|
||||
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/sub_merchant_entry/chapter3_1.shtml </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.AddSubMerchantInstitutionResponse> ExecuteAddSubMerchantInstitutionAsync(this WechatTenpayClient client, Models.AddSubMerchantInstitutionRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (client is null) throw new ArgumentNullException(nameof(client));
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "secapi", "mch", "addInstitutionsub");
|
||||
|
||||
return await client.SendRequestWithXmlAsync<Models.AddSubMerchantInstitutionResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /secapi/mch/queryInstitutionsub 接口。</para>
|
||||
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/sub_merchant_entry/chapter3_2.shtml </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.GetSubMerchantInstitutionResponse> ExecuteGetSubMerchantInstitutionAsync(this WechatTenpayClient client, Models.GetSubMerchantInstitutionRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (client is null) throw new ArgumentNullException(nameof(client));
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "secapi", "mch", "queryInstitutionsub");
|
||||
|
||||
return await client.SendRequestWithXmlAsync<Models.GetSubMerchantInstitutionResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /secapi/mch/modifyInstitutionsub 接口。</para>
|
||||
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/sub_merchant_entry/chapter3_3.shtml </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.ModifySubMerchantInstitutionResponse> ExecuteModifySubMerchantInstitutionAsync(this WechatTenpayClient client, Models.ModifySubMerchantInstitutionRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (client is null) throw new ArgumentNullException(nameof(client));
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "secapi", "mch", "modifyInstitutionsub");
|
||||
|
||||
return await client.SendRequestWithXmlAsync<Models.ModifySubMerchantInstitutionResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Flurl.Http;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV2
|
||||
{
|
||||
public static class WechatTenpayClientExecuteMerchantMediaExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /secapi/mch/uploadmedia 接口。</para>
|
||||
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/tool/chapter3_1.shtml </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.UploadMerchantMediaResponse> ExecuteUploadMerchantMediaAsync(this WechatTenpayClient client, Models.UploadMerchantMediaRequest 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 == null)
|
||||
request.FileName = Guid.NewGuid().ToString("N").ToLower() + ".jpg";
|
||||
|
||||
if (request.FileHash == null)
|
||||
request.FileHash = Utilities.MD5Utility.Hash(request.FileBytes).ToLower();
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "secapi", "mch", "uploadmedia");
|
||||
|
||||
string boundary = "--BOUNDARY--" + DateTimeOffset.Now.Ticks.ToString("x");
|
||||
string sign = Utilities.RequestSigner.Sign(new Dictionary<string, string?>() { { "mch_id", client.Credentials.MerchantId }, { "media_hash", request.FileHash } }, client.Credentials.MerchantSecret, Constants.SignTypes.MD5);
|
||||
using var fileContent = new ByteArrayContent(request.FileBytes);
|
||||
using var httpContent = new MultipartFormDataContent(boundary);
|
||||
httpContent.Add(fileContent, "\"media\"", $"\"{HttpUtility.UrlEncode(request.FileName)}\"");
|
||||
httpContent.Add(new StringContent(client.Credentials.MerchantId, Encoding.UTF8), $"\"mch_id\"");
|
||||
httpContent.Add(new StringContent(request.FileHash, Encoding.UTF8), $"\"media_hash\"");
|
||||
httpContent.Add(new StringContent(sign, Encoding.UTF8), $"\"sign\"");
|
||||
httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data; boundary=" + boundary);
|
||||
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("image/jpeg");
|
||||
|
||||
return await client.SendRequestAsync<Models.UploadMerchantMediaResponse>(flurlReq, httpContent: httpContent, cancellationToken: cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user