feat(work): 新增外部用户临时 ID 转换接口

This commit is contained in:
Fu Diwei 2023-03-22 21:49:33 +08:00
parent e69b86a60e
commit 4d506dd01b
12 changed files with 148 additions and 18 deletions

View File

@ -21,7 +21,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
var entry = client.PlatformCertificateManager.GetEntry(strSerialNumber);
if (!entry.HasValue)
{
error = new Exception($"There is no platform certificate matched the serial number: \"{strSerialNumber}\", please make sure you have downloaded platform certificates first.");
error = new Exception($"There is no platform certificate matched the serial number: \"{strSerialNumber}\". Please make sure you have downloaded platform certificates first.");
return false;
}
@ -58,7 +58,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
var entry = client.PlatformCertificateManager.GetEntry(strSerialNumber);
if (!entry.HasValue)
{
error = new Exception($"There is no platform certificate matched the serial number: \"{strSerialNumber}\", please make sure you have downloaded platform certificates first.");
error = new Exception($"There is no platform certificate matched the serial number: \"{strSerialNumber}\". Please make sure you have downloaded platform certificates first.");
return false;
}

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
@ -186,9 +186,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
request.MerchantId = client.Credentials.MerchantId;
IFlurlRequest flurlReq = client
.CreateRequest(request, HttpMethod.Post, "transactions", "out-trade-no", request.OutTradeNumber, "close")
.SetQueryParam("sp_mchid", request.MerchantId)
.SetQueryParam("sub_mchid", request.SubMerchantId);
.CreateRequest(request, HttpMethod.Post, "transactions", "out-trade-no", request.OutTradeNumber, "close");
return await client.SendRequestWithJsonAsync<Models.CloseHKPartnerTransactionResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
@ -184,8 +184,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
request.MerchantId = client.Credentials.MerchantId;
IFlurlRequest flurlReq = client
.CreateRequest(request, HttpMethod.Post, "transactions", "out-trade-no", request.OutTradeNumber, "close")
.SetQueryParam("mchid", request.MerchantId);
.CreateRequest(request, HttpMethod.Post, "transactions", "out-trade-no", request.OutTradeNumber, "close");
return await client.SendRequestWithJsonAsync<Models.CloseHKTransactionResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}

View File

@ -1,7 +1,6 @@
using System;
using System.Linq;
using System.Reflection;
using System.Text;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
{
@ -33,7 +32,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
.OrderByDescending(e => e.ExpireTime);
if (!entries.Any())
{
throw new Exceptions.WechatTenpayEventVerificationException("Failed to encrypt request, because there is no platform certificate in the manager, please make sure you have downloaded platform certificates first.");
throw new Exceptions.WechatTenpayEventVerificationException("Failed to encrypt request, because there is no platform certificate in the manager. Please make sure you have downloaded platform certificates first.");
}
var entry = entries.First();
@ -46,7 +45,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
var entry = client.PlatformCertificateManager.GetEntry(request.WechatpayCertificateSerialNumber!);
if (!entry.HasValue)
{
throw new Exceptions.WechatTenpayEventVerificationException($"Failed to encrypt request, because there is no platform certificate matched the serial number: \"{request.WechatpayCertificateSerialNumber}\", please make sure you have downloaded platform certificates first.");
throw new Exceptions.WechatTenpayEventVerificationException($"Failed to encrypt request, because there is no platform certificate matched the serial number: \"{request.WechatpayCertificateSerialNumber}\". Please make sure you have downloaded platform certificates first.");
}
certificate = entry.Value.Certificate;
@ -108,7 +107,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
.OrderByDescending(e => e.ExpireTime);
if (!entries.Any())
{
throw new Exceptions.WechatTenpayEventVerificationException("Failed to encrypt request, because there is no platform certificate in the manager, please make sure you have downloaded platform certificates first.");
throw new Exceptions.WechatTenpayEventVerificationException("Failed to encrypt request, because there is no platform certificate in the manager. Please make sure you have downloaded platform certificates first.");
}
var entry = entries.First();
@ -121,7 +120,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
var entry = client.PlatformCertificateManager.GetEntry(request.WechatpayCertificateSerialNumber!);
if (!entry.HasValue)
{
throw new Exceptions.WechatTenpayEventVerificationException($"Failed to encrypt request, because there is no platform certificate matched the serial number: \"{request.WechatpayCertificateSerialNumber}\", please make sure you have downloaded platform certificates first.");
throw new Exceptions.WechatTenpayEventVerificationException($"Failed to encrypt request, because there is no platform certificate matched the serial number: \"{request.WechatpayCertificateSerialNumber}\". Please make sure you have downloaded platform certificates first.");
}
certificate = entry.Value.Certificate;

View File

@ -130,7 +130,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Settings
if (AlgorithmType == null)
{
throw new ArgumentException("Unrecognized certificate algorithm type, please make sure you have decrypted the certificate content first.");
throw new ArgumentException("Unrecognized certificate algorithm type. Please make sure you have decrypted the certificate content first.");
}
}

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
@ -91,5 +91,25 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
return await client.SendRequestWithJsonAsync<Models.CgibinIdConvertOpenKfIdResponse>(flurlReq, cancellationToken: cancellationToken);
}
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/idconvert/convert_tmp_external_userid 接口。</para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/98729 </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CgibinIdConvertConvertTempExternalUserIdResponse> ExecuteCgibinIdConvertConvertTempExternalUserIdAsync(this WechatWorkClient client, Models.CgibinIdConvertConvertTempExternalUserIdRequest 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, "cgi-bin", "idconvert", "convert_tmp_external_userid")
.SetQueryParam("access_token", request.AccessToken);
return await client.SendRequestWithJsonAsync<Models.CgibinIdConvertConvertTempExternalUserIdResponse>(flurlReq, cancellationToken: cancellationToken);
}
}
}

View File

@ -17,7 +17,7 @@
public string ExternalUserId { get; set; } = default!;
/// <summary>
/// 获取或设置临时部联系人账号 ID。
/// 获取或设置临时部联系人账号 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("pending_id")]
[System.Text.Json.Serialization.JsonPropertyName("pending_id")]

View File

@ -0,0 +1,31 @@
using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/idconvert/convert_tmp_external_userid 接口的请求。</para>
/// </summary>
public class CgibinIdConvertConvertTempExternalUserIdRequest : WechatWorkRequest
{
/// <summary>
/// 获取或设置业务类型。
/// </summary>
[Newtonsoft.Json.JsonProperty("business_type")]
[System.Text.Json.Serialization.JsonPropertyName("business_type")]
public int BusinessType { get; set; }
/// <summary>
/// 获取或设置目标用户类型。
/// </summary>
[Newtonsoft.Json.JsonProperty("user_type")]
[System.Text.Json.Serialization.JsonPropertyName("user_type")]
public int UserType { get; set; }
/// <summary>
/// 获取或设置外部联系人临时 ID 列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("tmp_external_userid_list")]
[System.Text.Json.Serialization.JsonPropertyName("tmp_external_userid_list")]
public IList<string> TempExternalUserIdList { get; set; } = new List<string>();
}
}

View File

@ -0,0 +1,56 @@
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/idconvert/convert_tmp_external_userid 接口的响应。</para>
/// </summary>
public class CgibinIdConvertConvertTempExternalUserIdResponse : WechatWorkResponse
{
public static class Types
{
public class Result
{
/// <summary>
/// 获取或设置外部联系人临时 ID ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("tmp_external_userid")]
[System.Text.Json.Serialization.JsonPropertyName("tmp_external_userid")]
public string TempExternalUserId { get; set; } = default!;
/// <summary>
/// 获取或设置外部联系人账号 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("external_userid")]
[System.Text.Json.Serialization.JsonPropertyName("external_userid")]
public string? ExternalUserId { get; set; }
/// <summary>
/// 获取或设置企业 CorpId。
/// </summary>
[Newtonsoft.Json.JsonProperty("corpid")]
[System.Text.Json.Serialization.JsonPropertyName("corpid")]
public string? CorpId { get; set; }
/// <summary>
/// 获取或设置成员账号 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("userid")]
[System.Text.Json.Serialization.JsonPropertyName("userid")]
public string? UserId { get; set; }
}
}
/// <summary>
/// 获取或设置转换结果列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("results")]
[System.Text.Json.Serialization.JsonPropertyName("results")]
public Types.Result[] ResultList { get; set; } = default!;
/// <summary>
/// 获取或设置无效的外部联系人临时 ID 列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("invalid_tmp_external_userid_list")]
[System.Text.Json.Serialization.JsonPropertyName("invalid_tmp_external_userid_list")]
public string[]? InvalidTempExternalUserIdList { get; set; }
}
}

View File

@ -13,7 +13,7 @@
public string? ExternalUserId { get; set; }
/// <summary>
/// 获取或设置临时部联系人账号 ID。
/// 获取或设置临时部联系人账号 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("pending_id")]
[System.Text.Json.Serialization.JsonPropertyName("pending_id")]

View File

@ -0,0 +1,9 @@
{
"business_type": 1,
"user_type": 1,
"tmp_external_userid_list": [
"ouXXX1",
"ouXXX2",
"ouXXX3"
]
}

View File

@ -0,0 +1,18 @@
{
"errcode": 0,
"errmsg": "ok",
"results": [
{
"tmp_external_userid": "ouXXX1",
"external_userid": "EXTERNAL_USER_ID"
},
{
"tmp_external_userid": "ouXXX2",
"corpid": "CORPID",
"userid": "USERID"
}
],
"invalid_tmp_external_userid_list": [
"ouXXX3"
]
}