using System; using System.Collections.Generic; using System.Net.Http; using System.Text; using System.Threading; using System.Threading.Tasks; using Flurl; using Flurl.Http; namespace SKIT.FlurlHttpClient.Wechat.Api { public static class WechatApiClientExecuteCgibinComponentExtensions { /// /// 异步调用 [POST] /cgi-bin/component/api_start_push_ticket 接口。 /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/component_verify_ticket_service.html /// /// /// /// /// public static async Task ExecuteCgibinComponentApiStartPushTicketAsync(this WechatApiClient client, Models.CgibinComponentApiStartPushTicketRequest 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; if (request.ComponentSecret == null) request.ComponentSecret = client.Credentials.AppSecret; IFlurlRequest flurlReq = client .CreateRequest(request, HttpMethod.Post, "cgi-bin", "component", "api_start_push_ticket"); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /cgi-bin/component/api_component_token 接口。 /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/component_access_token.html /// /// /// /// /// public static async Task ExecuteCgibinComponentApiComponentTokenAsync(this WechatApiClient client, Models.CgibinComponentApiComponentTokenRequest 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; if (request.ComponentSecret == null) request.ComponentSecret = client.Credentials.AppSecret; IFlurlRequest flurlReq = client .CreateRequest(request, HttpMethod.Post, "cgi-bin", "component", "api_component_token"); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /cgi-bin/component/api_create_preauthcode 接口。 /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/pre_auth_code.html /// /// /// /// /// public static async Task ExecuteCgibinComponentApiCreatePreAuthCodeAsync(this WechatApiClient client, Models.CgibinComponentApiCreatePreAuthCodeRequest 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.Post, "cgi-bin", "component", "api_create_preauthcode") .SetQueryParam("component_access_token", request.ComponentAccessToken); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /cgi-bin/component/api_query_auth 接口。 /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/authorization_info.html /// /// /// /// /// public static async Task ExecuteCgibinComponentApiQueryAuthAsync(this WechatApiClient client, Models.CgibinComponentApiQueryAuthRequest 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.Post, "cgi-bin", "component", "api_query_auth") .SetQueryParam("component_access_token", request.ComponentAccessToken); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /cgi-bin/component/api_authorizer_token 接口。 /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/api_authorizer_token.html /// /// /// /// /// public static async Task ExecuteCgibinComponentApiAuthorizerTokenAsync(this WechatApiClient client, Models.CgibinComponentApiAuthorizerTokenRequest 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.Post, "cgi-bin", "component", "api_authorizer_token") .SetQueryParam("component_access_token", request.ComponentAccessToken); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /cgi-bin/component/api_get_authorizer_info 接口。 /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/api_get_authorizer_info.html /// /// /// /// /// public static async Task ExecuteCgibinComponentApiGetAuthorizerInfoAsync(this WechatApiClient client, Models.CgibinComponentApiGetAuthorizerInfoRequest 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.Post, "cgi-bin", "component", "api_get_authorizer_info") .SetQueryParam("component_access_token", request.ComponentAccessToken); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /cgi-bin/component/api_get_authorizer_list 接口。 /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/Account_Authorization/api_get_authorizer_list.html /// /// /// /// /// public static async Task ExecuteCgibinComponentApiGetAuthorizerListAsync(this WechatApiClient client, Models.CgibinComponentApiGetAuthorizerListRequest 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.Post, "cgi-bin", "component", "api_get_authorizer_list") .SetQueryParam("component_access_token", request.ComponentAccessToken); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /cgi-bin/component/api_get_authorizer_option 接口。 /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/Account_Authorization/api_get_authorizer_option.html /// /// /// /// /// public static async Task ExecuteCgibinComponentApiGetAuthorizerOptionAsync(this WechatApiClient client, Models.CgibinComponentApiGetAuthorizerOptionRequest 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.Post, "cgi-bin", "component", "api_get_authorizer_option") .SetQueryParam("component_access_token", request.ComponentAccessToken); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /cgi-bin/component/api_set_authorizer_option 接口。 /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/Account_Authorization/api_set_authorizer_option.html /// /// /// /// /// public static async Task ExecuteCgibinComponentApiSetAuthorizerOptionAsync(this WechatApiClient client, Models.CgibinComponentApiSetAuthorizerOptionRequest 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.Post, "cgi-bin", "component", "api_set_authorizer_option") .SetQueryParam("component_access_token", request.ComponentAccessToken); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /cgi-bin/component/fastregisterweapp?action=create 接口。 /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Register_Mini_Programs/Fast_Registration_Interface_document.html /// /// /// /// /// public static async Task ExecuteCgibinComponentFastRegisterWeappCreateAsync(this WechatApiClient client, Models.CgibinComponentFastRegisterWeappCreateRequest 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", "component", "fastregisterweapp") .SetQueryParam("action", "create") .SetQueryParam("component_access_token", request.ComponentAccessToken); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /cgi-bin/component/fastregisterweapp?action=search 接口。 /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Register_Mini_Programs/Fast_Registration_Interface_document.html /// /// /// /// /// public static async Task ExecuteCgibinComponentFastRegisterWeappSearchAsync(this WechatApiClient client, Models.CgibinComponentFastRegisterWeappSearchRequest 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", "component", "fastregisterweapp") .SetQueryParam("action", "search") .SetQueryParam("component_access_token", request.ComponentAccessToken); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } } }