Skip to content

Commit

Permalink
Add "获取设置的行业信息" method at template message service.
Browse files Browse the repository at this point in the history
  • Loading branch information
GameBelial committed Dec 17, 2020
1 parent 3b93fd3 commit 7513eb0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using EasyAbp.Abp.WeChat.Official.Infrastructure.Models;
using Newtonsoft.Json;

namespace EasyAbp.Abp.WeChat.Official.Services.TemplateMessage
{
/// <summary>
/// 获取消息模版对应的行业信息。
/// </summary>
public class GetIndustryResponse : OfficialCommonResponse
{
/// <summary>
/// 账号设置的主营行业。
/// </summary>
[JsonProperty("primary_industry")]
public IndustryItem PrimaryIndustry { get; set; }

/// <summary>
/// 账号设置的副营行业。
/// </summary>
[JsonProperty("secondary_industry")]
public IndustryItem SecondaryIndustry { get; set; }
}

public class IndustryItem
{
/// <summary>
/// 主行业。
/// </summary>
[JsonProperty("first_class")]
public string FirstClass { get; set; }

/// <summary>
/// 副行业。
/// </summary>
[JsonProperty("second_class")]
public string SecondClass { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class TemplateMessageService : CommonService
{
private const string SendUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?";
private const string SetIndustry = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry?";
private const string GetIndustry = "https://api.weixin.qq.com/cgi-bin/template/get_industry?";

/// <summary>
/// 请求微信公众号的 API 发送指定的模板消息。
Expand Down Expand Up @@ -61,11 +62,22 @@ public Task<SendMessageResponse> SendMessageAsync(string openId,
/// 设置行业可在微信公众平台后台完成,每月可修改行业 1 次。<br/>
/// 帐号仅可使用所属行业中相关的模板。
/// </remarks>
/// <param name="industry1">公众号模板消息所属行业编号。</param>
/// <param name="industry2">公众号模板消息所属行业编号。</param>
public Task<OfficialCommonResponse> SetIndustryAsync(string industry1, string industry2)
/// <param name="primaryIndustry">公众号模板消息所属行业编号。</param>
/// <param name="secondaryIndustry">公众号模板消息所属行业编号。</param>
public Task<OfficialCommonResponse> SetIndustryAsync(string primaryIndustry, string secondaryIndustry)
{
return WeChatOfficialApiRequester.RequestAsync<OfficialCommonResponse>(SetIndustry, HttpMethod.Post, new SetIndustryRequest(industry1, industry2));
return WeChatOfficialApiRequester.RequestAsync<OfficialCommonResponse>(SetIndustry, HttpMethod.Post, new SetIndustryRequest(primaryIndustry, secondaryIndustry));
}

/// <summary>
/// 获取设置的模版消息行业信息。
/// </summary>
/// <remarks>
/// 获取帐号设置的行业信息。可登录微信公众平台,在公众号后台中查看行业信息。
/// </remarks>
public Task<GetIndustryResponse> GetIndustryAsync()
{
return WeChatOfficialApiRequester.RequestAsync<GetIndustryResponse>(GetIndustry, HttpMethod.Get);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,17 @@ public async Task Should_Set_Industry()

response.ErrorCode.ShouldBe(0);
}

[Fact]
public async Task Should_Get_Current_Industry()
{
var response = await _templateMessageService.GetIndustryAsync();

response.ErrorCode.ShouldBe(0);
response.PrimaryIndustry.FirstClass.ShouldBe("IT科技");
response.SecondaryIndustry.FirstClass.ShouldBe("IT科技");
response.PrimaryIndustry.SecondClass.ShouldBe("互联网|电子商务");
response.SecondaryIndustry.SecondClass.ShouldBe("电子技术");
}
}
}

0 comments on commit 7513eb0

Please sign in to comment.