mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-07-16 07:59:44 +08:00
feat(wxapi): 新增代公众号发起网页授权相关接口
This commit is contained in:
parent
21c7e1d6e3
commit
7764fe2144
@ -151,13 +151,67 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Get, "sns", "component", "jscode2session")
|
||||
.SetQueryParam("grant_type", request.GrantType)
|
||||
.SetQueryParam("js_code", request.JsCode)
|
||||
.SetQueryParam("appid", request.AppId)
|
||||
.SetQueryParam("component_appid", request.ComponentAppId)
|
||||
.SetQueryParam("component_access_token", request.ComponentAccessToken)
|
||||
.SetQueryParam("js_code", request.JsCode);
|
||||
.SetQueryParam("component_access_token", request.ComponentAccessToken);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.SnsComponentJsCode2SessionResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [GET] /sns/oauth2/component/access_token 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/Official_Accounts/official_account_website_authorization.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.SnsOAuth2ComponentAccessTokenResponse> ExecuteSnsOAuth2ComponentAccessTokenAsync(this WechatApiClient client, Models.SnsOAuth2ComponentAccessTokenRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (client is null) throw new ArgumentNullException(nameof(client));
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (request.ComponentAppId == null)
|
||||
request.ComponentAppId = client.Credentials.AppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Get, "sns", "oauth2", "component", "access_token")
|
||||
.SetQueryParam("grant_type", request.GrantType)
|
||||
.SetQueryParam("code", request.Code)
|
||||
.SetQueryParam("appid", request.AppId)
|
||||
.SetQueryParam("component_appid", request.ComponentAppId)
|
||||
.SetQueryParam("component_access_token", request.ComponentAccessToken);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.SnsOAuth2ComponentAccessTokenResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [GET] /sns/oauth2/component/refresh_token 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/Official_Accounts/official_account_website_authorization.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.SnsOAuth2ComponentRefreshTokenResponse> ExecuteSnsOAuth2ComponentRefreshTokenAsync(this WechatApiClient client, Models.SnsOAuth2ComponentRefreshTokenRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (client is null) throw new ArgumentNullException(nameof(client));
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (request.ComponentAppId == null)
|
||||
request.ComponentAppId = client.Credentials.AppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Get, "sns", "oauth2", "component", "refresh_token")
|
||||
.SetQueryParam("grant_type", request.GrantType)
|
||||
.SetQueryParam("refresh_token", request.RefreshToken)
|
||||
.SetQueryParam("appid", request.AppId)
|
||||
.SetQueryParam("component_appid", request.ComponentAppId)
|
||||
.SetQueryParam("component_access_token", request.ComponentAccessToken);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.SnsOAuth2ComponentRefreshTokenResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /sns/component/jscode2session 接口的请求。</para>
|
||||
|
@ -0,0 +1,29 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /sns/oauth2/component/access_token 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class SnsOAuth2ComponentAccessTokenRequest : SnsOAuth2AccessTokenRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置微信 AppId。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string AppId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置第三方平台 AppId。如果不指定将使用构造 <see cref="WechatApiClient"/> 时的 <see cref="WechatApiClientOptions.AppId"/> 参数。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string? ComponentAppId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置第三方平台 AccessToken。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string ComponentAccessToken { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /sns/oauth2/component/access_token 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class SnsOAuth2ComponentAccessTokenResponse : SnsOAuth2AccessTokenResponse
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /sns/oauth2/component/refresh_token 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class SnsOAuth2ComponentRefreshTokenRequest : SnsOAuth2RefreshTokenRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置微信 AppId。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string AppId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置第三方平台 AppId。如果不指定将使用构造 <see cref="WechatApiClient"/> 时的 <see cref="WechatApiClientOptions.AppId"/> 参数。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string? ComponentAppId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置第三方平台 AccessToken。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string ComponentAccessToken { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /sns/oauth2/component/refresh_token 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class SnsOAuth2ComponentRefreshTokenResponse : SnsOAuth2RefreshTokenResponse
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user