mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-09-20 02:29:40 +08:00
feat(work): 新增获取访问用户身份或敏感信息接口
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Flurl;
|
||||
using Flurl.Http;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
{
|
||||
public static class WechatWorkClientExecuteCgibinAuthExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>异步调用 [GET] /cgi-bin/auth/getuserinfo 接口。</para>
|
||||
/// <para>REF: https://developer.work.weixin.qq.com/document/path/91023 </para>
|
||||
/// <para>REF: https://developer.work.weixin.qq.com/document/path/91437 </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.CgibinAuthGetUserInfoResponse> ExecuteCgibinAuthGetUserInfoAsync(this WechatWorkClient client, Models.CgibinAuthGetUserInfoRequest 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.Get, "cgi-bin", "auth", "getuserinfo")
|
||||
.SetQueryParam("access_token", request.AccessToken)
|
||||
.SetQueryParam("code", request.Code);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.CgibinAuthGetUserInfoResponse>(flurlReq, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /cgi-bin/auth/getuserdetail 接口。</para>
|
||||
/// <para>REF: https://developer.work.weixin.qq.com/document/path/95833 </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.CgibinAuthGetUserDetailResponse> ExecuteCgibinAuthGetUserDetailAsync(this WechatWorkClient client, Models.CgibinAuthGetUserDetailRequest 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", "auth", "getuserdetail")
|
||||
.SetQueryParam("access_token", request.AccessToken);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.CgibinAuthGetUserDetailResponse>(flurlReq, cancellationToken: cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using Flurl;
|
||||
using static SKIT.FlurlHttpClient.Wechat.Work.Models.CgibinSchoolAgentGetAllowScopeResponse.Types;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
{
|
||||
@@ -77,6 +78,22 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
/// <param name="state"></param>
|
||||
/// <returns></returns>
|
||||
public static string GenerateParameterizedUrlForConnectOAuth2Authorize(this WechatWorkClient client, string redirectUrl, string scope, string? state = null)
|
||||
{
|
||||
return GenerateParameterizedUrlForConnectOAuth2Authorize(client, agentId: client.Credentials.AgentId.GetValueOrDefault(), redirectUrl: redirectUrl, scope: scope, state: state);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>生成企业号网页授权 URL。</para>
|
||||
/// <para>REF: https://developer.work.weixin.qq.com/document/path/91022 </para>
|
||||
/// <para>REF: https://developer.work.weixin.qq.com/document/path/91120 </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="agentId"></param>
|
||||
/// <param name="redirectUrl"></param>
|
||||
/// <param name="scope"></param>
|
||||
/// <param name="state"></param>
|
||||
/// <returns></returns>
|
||||
public static string GenerateParameterizedUrlForConnectOAuth2Authorize(this WechatWorkClient client, int agentId, string redirectUrl, string scope, string? state = null)
|
||||
{
|
||||
return new Url("https://open.weixin.qq.com")
|
||||
.AppendPathSegments("connect", "oauth2", "authorize")
|
||||
@@ -85,6 +102,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
.SetQueryParam("response_type", "code")
|
||||
.SetQueryParam("scope", scope)
|
||||
.SetQueryParam("state", state)
|
||||
.SetQueryParam("agentid", agentId)
|
||||
.SetFragment("wechat_redirect")
|
||||
.ToString();
|
||||
}
|
||||
@@ -101,11 +119,28 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
/// <param name="userType"></param>
|
||||
/// <returns></returns>
|
||||
public static string GenerateParameterizedUrlForSSOQrcodeConnectAuthorize(this WechatWorkClient client, string redirectUrl, string? state = null, string? language = null, string? userType = null)
|
||||
{
|
||||
return GenerateParameterizedUrlForSSOQrcodeConnectAuthorize(client, agentId: client.Credentials.AgentId.GetValueOrDefault(), redirectUrl: redirectUrl, state: state, language: language, userType: userType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>生成企业号扫码授权 URL。</para>
|
||||
/// <para>REF: https://developer.work.weixin.qq.com/document/path/91019 </para>
|
||||
/// <para>REF: https://developer.work.weixin.qq.com/document/path/91124 </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="agentId"></param>
|
||||
/// <param name="redirectUrl"></param>
|
||||
/// <param name="state"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="userType"></param>
|
||||
/// <returns></returns>
|
||||
public static string GenerateParameterizedUrlForSSOQrcodeConnectAuthorize(this WechatWorkClient client, int agentId, string redirectUrl, string? state = null, string? language = null, string? userType = null)
|
||||
{
|
||||
return new Url("https://open.work.weixin.qq.com")
|
||||
.AppendPathSegments("wwopen", "sso", "qrConnect")
|
||||
.SetQueryParam("appid", client.Credentials.CorpId)
|
||||
.SetQueryParam("agentid", client.Credentials.AgentId)
|
||||
.SetQueryParam("agentid", agentId)
|
||||
.SetQueryParam("redirect_uri", redirectUrl)
|
||||
.SetQueryParam("state", state)
|
||||
.SetQueryParam("lang", language)
|
||||
|
@@ -0,0 +1,15 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /cgi-bin/auth/getuserdetail 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class CgibinAuthGetUserDetailRequest : WechatWorkRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置成员票据。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("user_ticket")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("user_ticket")]
|
||||
public string UserTicket { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /cgi-bin/auth/getuserdetail 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class CgibinAuthGetUserDetailResponse : WechatWorkResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置成员 UserId。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("userid")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("userid")]
|
||||
public string UserId { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置性别。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("gender")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("gender")]
|
||||
[System.Text.Json.Serialization.JsonNumberHandling(System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString)]
|
||||
public int Gender { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置头像 URL。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("avatar")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("avatar")]
|
||||
public string? AvatarUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置员工个人二维码 URL。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("qr_code")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("qr_code")]
|
||||
public string? QrcodeUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置手机号码。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("mobile")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("mobile")]
|
||||
public string? MobileNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置邮箱地址。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("email")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("email")]
|
||||
public string? Email { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置企业邮箱地址。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("biz_mail")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("biz_mail")]
|
||||
public string? BusinessEmail { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置地址。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("address")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("address")]
|
||||
public string? Address { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /cgi-bin/auth/getuserinfo 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class CgibinAuthGetUserInfoRequest : WechatWorkRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置成员授权码。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string Code { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /cgi-bin/auth/getuserinfo 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class CgibinAuthGetUserInfoResponse : WechatWorkResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置成员 UserId。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("userid")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("userid")]
|
||||
public string? UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置成员票据。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("user_ticket")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("user_ticket")]
|
||||
public string? UserTicket { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置非企业成员的标识。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("openid")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("openid")]
|
||||
public string? OpenId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置外部联系人 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("external_userid")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("external_userid")]
|
||||
public string? ExternalUserId { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"errcode": 0,
|
||||
"errmsg": "ok",
|
||||
"userid": "lisi",
|
||||
"gender": "1",
|
||||
"avatar": "http://shp.qpic.cn/bizmp/xxxxxxxxxxx/0",
|
||||
"qr_code": "https://open.work.weixin.qq.com/wwopen/userQRCode?vcode=vcfc13b01dfs78e981c",
|
||||
"mobile": "13800000000",
|
||||
"email": "zhangsan@gzdev.com",
|
||||
"biz_mail": "zhangsan@qyycs2.wecom.work",
|
||||
"address": "广州市海珠区新港中路"
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"errcode": 0,
|
||||
"errmsg": "ok",
|
||||
"userid": "USERID",
|
||||
"user_ticket": "USER_TICKET",
|
||||
"openid": "OPENID",
|
||||
"external_userid": "EXTERNAL_USERID"
|
||||
}
|
Reference in New Issue
Block a user