mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-09-18 09:44:43 +08:00
feat(wxads): 新增广告帐号模块相关 API 封装
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
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.Ads
|
||||
{
|
||||
public static class WechatAdsClientExecuteAdvertiserExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /advertiser/add 接口。</para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.AdvertiserAddResponse> ExecuteAdvertiserAddAsync(this WechatAdsClient client, Models.AdvertiserAddRequest 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(HttpMethod.Post, "advertiser", "add")
|
||||
.SetOptions(request)
|
||||
.SetQueryParam("access_token", request.AccessToken);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.AdvertiserAddResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /advertiser/update 接口。</para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.AdvertiserUpdateResponse> ExecuteAdvertiserUpdateAsync(this WechatAdsClient client, Models.AdvertiserUpdateRequest 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(HttpMethod.Post, "advertiser", "update")
|
||||
.SetOptions(request)
|
||||
.SetQueryParam("access_token", request.AccessToken);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.AdvertiserUpdateResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [GET] /advertiser/get 接口。</para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.AdvertiserGetResponse> ExecuteAdvertiserGetAsync(this WechatAdsClient client, Models.AdvertiserGetRequest 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(HttpMethod.Get, "advertiser", "get")
|
||||
.SetOptions(request)
|
||||
.SetQueryParam("access_token", request.AccessToken);
|
||||
|
||||
return await client.SendRequestAsync<Models.AdvertiserGetResponse>(flurlReq, cancellationToken: cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Ads.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /advertiser/add 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class AdvertiserAddRequest : WechatAdsRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置行业 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("system_industry_id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("system_industry_id")]
|
||||
public int IndustryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置联系人姓名。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("contact_person")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("contact_person")]
|
||||
public string ContactPerson { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置联系人电话号码。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("contact_person_telephone")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("contact_person_telephone")]
|
||||
public string ContactTeleNumber { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置经营性质类型。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("business_type")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("business_type")]
|
||||
public string? BusinessType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置经营内容。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("business_content")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("business_content")]
|
||||
public string? BusinessContent { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Ads.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /advertiser/add 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class AdvertiserAddResponse : WechatAdsResponse
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Ads.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /advertiser/get 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class AdvertiserGetRequest : WechatAdsRequest
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Ads.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /advertiser/get 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class AdvertiserGetResponse : WechatAdsResponse
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置公众号名称。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("wechat_account_name")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("wechat_account_name")]
|
||||
public string WechatAccountNickname { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置系统状态。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("system_status")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("system_status")]
|
||||
public string SystemStatus { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置行业 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("industry_id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("industry_id")]
|
||||
public int IndustryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置联系人姓名。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("contact_person")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("contact_person")]
|
||||
public string ContactPerson { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置联系人电话号码。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("contact_person_telephone")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("contact_person_telephone")]
|
||||
public string ContactTeleNumber { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置经营性质类型。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("business_type")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("business_type")]
|
||||
public string? BusinessType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置经营内容。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("business_content")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("business_content")]
|
||||
public string? BusinessContent { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置返回数据。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("data")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("data")]
|
||||
public Types.Data Data { get; set; } = default!;
|
||||
}
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Ads.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /advertiser/update 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class AdvertiserUpdateRequest : WechatAdsRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置行业 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("system_industry_id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("system_industry_id")]
|
||||
public int? IndustryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置联系人姓名。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("contact_person")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("contact_person")]
|
||||
public string? ContactPerson { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置联系人电话号码。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("contact_person_telephone")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("contact_person_telephone")]
|
||||
public string? ContactTeleNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置经营性质类型。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("business_type")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("business_type")]
|
||||
public string? BusinessType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置经营内容。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("business_content")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("business_content")]
|
||||
public string? BusinessContent { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Ads.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /advertiser/update 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class AdvertiserUpdateResponse : WechatAdsResponse
|
||||
{
|
||||
}
|
||||
}
|
@@ -10,6 +10,6 @@ namespace SKIT.FlurlHttpClient.Wechat.Ads
|
||||
/// <summary>
|
||||
/// 主域名(默认)。
|
||||
/// </summary>
|
||||
public const string DEFAULT = "https://api.weixin.qq.com";
|
||||
public const string DEFAULT = "https://api.weixin.qq.com/marketing";
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Ads.UnitTests
|
||||
{
|
||||
public class WechatAdsDeclarationTests
|
||||
{
|
||||
private static readonly Assembly _assembly = Assembly.Load("SKIT.FlurlHttpClient.Wechat.Ads");
|
||||
|
||||
[Fact(DisplayName = "验证 API 模型命名")]
|
||||
public void ApiModelsNamingTest()
|
||||
{
|
||||
TestAssertUtil.VerifyApiModelsNaming(_assembly, out var ex);
|
||||
|
||||
if (ex != null)
|
||||
throw ex;
|
||||
|
||||
Assert.Null(ex);
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "验证 API 模型定义")]
|
||||
public void ApiModelsDefinitionTest()
|
||||
{
|
||||
string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "ModelSamples");
|
||||
Assert.True(Directory.Exists(workdir));
|
||||
|
||||
TestAssertUtil.VerifyApiModelsDefinition(_assembly, workdir, out var ex);
|
||||
|
||||
if (ex != null)
|
||||
throw ex;
|
||||
|
||||
Assert.Null(ex);
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "验证 API 接口命名")]
|
||||
public void ApiExtensionsNamingTest()
|
||||
{
|
||||
TestAssertUtil.VerifyApiExtensionsNaming(_assembly, out var ex);
|
||||
|
||||
if (ex != null)
|
||||
throw ex;
|
||||
|
||||
Assert.Null(ex);
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "验证代码规范")]
|
||||
public void CodeStyleTest()
|
||||
{
|
||||
string workdir = Path.Combine(TestConfigs.ProjectSourceDirectory);
|
||||
Assert.True(Directory.Exists(workdir));
|
||||
|
||||
TestAssertUtil.VerifySourceCodeStyle(workdir, out var ex);
|
||||
|
||||
if (ex != null)
|
||||
throw ex;
|
||||
|
||||
Assert.Null(ex);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user