mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-12-29 01:44:42 +08:00
feat(wxapi): 新增第三方平台小程序用户隐私保护指引相关接口
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Flurl;
|
||||
using Flurl.Http;
|
||||
|
||||
@@ -323,5 +323,80 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.CgibinComponentModifyWxaJumpDomainResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /cgi-bin/component/setprivacysetting 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/privacy_config/set_privacy_setting.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.CgibinComponentSetPrivacySettingResponse> ExecuteCgibinComponentSetPrivacySettingAsync(this WechatApiClient client, Models.CgibinComponentSetPrivacySettingRequest 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", "setprivacysetting")
|
||||
.SetQueryParam("access_token", request.AccessToken);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.CgibinComponentSetPrivacySettingResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /cgi-bin/component/getprivacysetting 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/privacy_config/get_privacy_setting.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.CgibinComponentGetPrivacySettingResponse> ExecuteCgibinComponentGetPrivacySettingAsync(this WechatApiClient client, Models.CgibinComponentGetPrivacySettingRequest 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", "getprivacysetting")
|
||||
.SetQueryParam("access_token", request.AccessToken);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.CgibinComponentGetPrivacySettingResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /cgi-bin/component/uploadprivacyextfile 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/privacy_config/upload_privacy_exfile.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.CgibinComponentUploadPrivacyExtraFileResponse> ExecuteCgibinComponentUploadPrivacyExtraFileAsync(this WechatApiClient client, Models.CgibinComponentUploadPrivacyExtraFileRequest 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() + ".txt";
|
||||
|
||||
if (request.FileContentType == null)
|
||||
request.FileContentType = "text/plain";
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "cgi-bin", "component", "uploadprivacyextfile")
|
||||
.SetQueryParam("access_token", request.AccessToken);
|
||||
|
||||
string boundary = "--BOUNDARY--" + DateTimeOffset.Now.Ticks.ToString("x");
|
||||
using var fileContent = new ByteArrayContent(request.FileBytes ?? new byte[0]);
|
||||
using var httpContent = new MultipartFormDataContent(boundary);
|
||||
httpContent.Add(fileContent, "\"file\"", $"\"{HttpUtility.UrlEncode(request.FileName)}\"");
|
||||
httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data; boundary=" + boundary);
|
||||
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse(request.FileContentType);
|
||||
fileContent.Headers.ContentLength = request.FileBytes?.Length;
|
||||
|
||||
return await client.SendRequestAsync<Models.CgibinComponentUploadPrivacyExtraFileResponse>(flurlReq, httpContent: httpContent, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,9 +117,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
request.FileName = Guid.NewGuid().ToString("N").ToLower() + ".png";
|
||||
|
||||
if (request.FileContentType == null)
|
||||
{
|
||||
request.FileContentType = Utilities.FileNameToContentTypeMapper.GetContentTypeForImage(request.FileName!) ?? "image/png";
|
||||
}
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "cgi-bin", "media", "uploadimg")
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /cgi-bin/component/getprivacysetting 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class CgibinComponentGetPrivacySettingRequest : WechatApiRequest
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class OwnerSetting
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置信息收集方的邮箱地址。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("contact_email")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("contact_email")]
|
||||
public string? ContactEmail { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置信息收集方的电话号码。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("contact_phone")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("contact_phone")]
|
||||
public string? ContactPhoneNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置信息收集方的 QQ 号。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("contact_qq")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("contact_qq")]
|
||||
public string? ContactQQ { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置信息收集方的微信号。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("contact_weixin")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("contact_weixin")]
|
||||
public string? ContactWexin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户隐私保护指引文件的 MediaId。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("ext_file_media_id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("ext_file_media_id")]
|
||||
public string? ExtraFileMediaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置通知方式。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("notice_method")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("notice_method")]
|
||||
public string? NoticeMethod { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置存储期限时间字符串。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("store_expire_timestamp")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("store_expire_timestamp")]
|
||||
public string? StoreExpireTimeString { get; set; }
|
||||
}
|
||||
|
||||
public class PrivacySetting
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置隐私项目标识。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("privacy_key")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("privacy_key")]
|
||||
public string PrivacyKey { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置收集该信息的用途。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("privacy_text")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("privacy_text")]
|
||||
public string PrivacyText { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户隐私保护指引的版本。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("privacy_ver")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("privacy_ver")]
|
||||
public int? PrivacyVersion { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /cgi-bin/component/getprivacysetting 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class CgibinComponentGetPrivacySettingResponse : WechatApiResponse
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class OwnerSetting : CgibinComponentGetPrivacySettingRequest.Types.OwnerSetting
|
||||
{
|
||||
}
|
||||
|
||||
public class PrivacySetting : CgibinComponentGetPrivacySettingRequest.Types.PrivacySetting
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置用户信息类型的中文名称。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("privacy_label")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("privacy_label")]
|
||||
public string PrivacyLabel { get; set; } = default!;
|
||||
}
|
||||
|
||||
public class PrivacyDescriptionList
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置用户信息类型对应的中英文描述列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("privacy_desc_list")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("privacy_desc_list")]
|
||||
public PrivacyDescriptionItem[] Items { get; set; } = default!;
|
||||
}
|
||||
|
||||
public class PrivacyDescriptionItem
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置用户信息类型的英文名称。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("privacy_key")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("privacy_key")]
|
||||
public string PrivacyKey { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户信息类型的中文描述。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("privacy_desc")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("privacy_desc")]
|
||||
public string PrivacyDescription { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置代码是否存在。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("code_exist")]
|
||||
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.NumericalBooleanConverter))]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("code_exist")]
|
||||
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.NumericalBooleanConverter))]
|
||||
public bool IsCodeExisted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置收集方信息配置。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("owner_setting")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("owner_setting")]
|
||||
public Types.OwnerSetting? OwnerSetting { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置要收集的用户信息列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("privacy_list")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("privacy_list")]
|
||||
public string[]? PrivacyKeyList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置要收集的用户信息配置列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("setting_list")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("setting_list")]
|
||||
public Types.PrivacySetting[]? PrivacySettingList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户信息类型对应的中英文描述信息。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("privacy_desc")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("privacy_desc")]
|
||||
public Types.PrivacyDescriptionList? PrivacyDescriptionList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置更新时间戳。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("update_time")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("update_time")]
|
||||
public long? UpdateTimestamp { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /cgi-bin/component/setprivacysetting 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class CgibinComponentSetPrivacySettingRequest : WechatApiRequest
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class OwnerSetting
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置信息收集方的邮箱地址。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("contact_email")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("contact_email")]
|
||||
public string? ContactEmail { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置信息收集方的电话号码。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("contact_phone")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("contact_phone")]
|
||||
public string? ContactPhoneNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置信息收集方的 QQ 号。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("contact_qq")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("contact_qq")]
|
||||
public string? ContactQQ { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置信息收集方的微信号。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("contact_weixin")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("contact_weixin")]
|
||||
public string? ContactWexin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户隐私保护指引文件的 MediaId。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("ext_file_media_id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("ext_file_media_id")]
|
||||
public string? ExtraFileMediaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置通知方式。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("notice_method")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("notice_method")]
|
||||
public string? NoticeMethod { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置存储期限时间字符串。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("store_expire_timestamp")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("store_expire_timestamp")]
|
||||
public string? StoreExpireTimeString { get; set; }
|
||||
}
|
||||
|
||||
public class PrivacySetting
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置用户信息类型的英文名称。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("privacy_key")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("privacy_key")]
|
||||
public string PrivacyKey { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置收集该信息的用途。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("privacy_text")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("privacy_text")]
|
||||
public string PrivacyText { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户隐私保护指引的版本。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("privacy_ver")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("privacy_ver")]
|
||||
public int? PrivacyVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置收集方信息配置。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("owner_setting")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("owner_setting")]
|
||||
public Types.OwnerSetting OwnerSetting { get; set; } = new Types.OwnerSetting();
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置要收集的用户信息配置列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("setting_list")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("setting_list")]
|
||||
public IList<Types.PrivacySetting>? PrivacySettingList { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /cgi-bin/component/setprivacysetting 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class CgibinComponentSetPrivacySettingResponse : WechatApiResponse
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /cgi-bin/component/uploadprivacyextfile 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class CgibinComponentUploadPrivacyExtraFileRequest : WechatApiRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置图片文件字节数组。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public byte[] FileBytes { get; set; } = new byte[0];
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置图片文件名。如果不指定将由系统自动生成。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string? FileName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置图片文件 Conent-Type。如果不指定将由系统自动生成。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string? FileContentType { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /cgi-bin/component/uploadprivacyextfile 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class CgibinComponentUploadPrivacyExtraFileResponse : WechatApiResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置用户隐私保护指引文件的 MediaId。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("ext_file_media_id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("ext_file_media_id")]
|
||||
public string ExtraFileMediaId { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user