Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support new official account template message API #96

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using System.Collections.Generic;
using EasyAbp.Abp.WeChat.Official.Models;
using Newtonsoft.Json;

Expand All @@ -10,23 +11,31 @@ namespace EasyAbp.Abp.WeChat.Official.Services.TemplateMessage.Request
public class CreateTemplateRequest : OfficialCommonRequest
{
/// <summary>
/// 模板库中模板的编号,有 "TM**" 和 "OPENTMTM**" 等形式
/// 模板库中模板的编号,有TM**”和“OPENTMTM**等形式,对于类目模板,为纯数字ID
/// </summary>
[JsonPropertyName("template_id_short")]
[JsonProperty("template_id_short")]
public string TemplateShortId { get; protected set; }

/// <summary>
/// 选用的类目模板的关键词,按顺序传入,如果为空,或者关键词不在模板库中,会返回40246错误码
/// </summary>
[JsonProperty("keyword_name_list")]
public List<string> KeywordNameList { get; protected set; }

protected CreateTemplateRequest()
{
}

/// <summary>
/// 构建一个新的 <see cref="CreateTemplateRequest"/> 对象。
/// </summary>
/// <param name="templateShortId">模板库中模板的编号,有 "TM**" 和 "OPENTMTM**" 等形式。</param>
public CreateTemplateRequest(string templateShortId)
/// <param name="templateShortId">模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式,对于类目模板,为纯数字ID</param>
/// <param name="keywordNameList">选用的类目模板的关键词,按顺序传入,如果为空,或者关键词不在模板库中,会返回40246错误码</param>
public CreateTemplateRequest(string templateShortId, List<string> keywordNameList)
{
TemplateShortId = templateShortId;
KeywordNameList = keywordNameList;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using EasyAbp.Abp.WeChat.Official.Models;
Expand Down Expand Up @@ -25,7 +26,8 @@ public class TemplateMessageWeService : OfficialAbpWeChatServiceBase
private const string DeletePrivateTemplateUrl =
"https://api.weixin.qq.com/cgi-bin/template/del_private_template?";

public TemplateMessageWeService(AbpWeChatOfficialOptions options, IAbpLazyServiceProvider lazyServiceProvider) : base(options, lazyServiceProvider)
public TemplateMessageWeService(AbpWeChatOfficialOptions options, IAbpLazyServiceProvider lazyServiceProvider) :
base(options, lazyServiceProvider)
{
}

Expand Down Expand Up @@ -112,13 +114,15 @@ public virtual Task<GetIndustryResponse> GetIndustryAsync()
/// <summary>
/// 根据短模版 Id 创建模版。
/// </summary>
/// <param name="templateShortId">模板库中模板的编号,有 "TM**" 和 "OPENTMTM**" 等形式。</param>
public virtual Task<CreateTemplateResponse> CreateTemplateAsync(string templateShortId)
/// <param name="templateShortId">模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式,对于类目模板,为纯数字ID</param>
/// <param name="keywordNameList">选用的类目模板的关键词,按顺序传入,如果为空,或者关键词不在模板库中,会返回40246错误码</param>
public virtual Task<CreateTemplateResponse> CreateTemplateAsync(string templateShortId,
List<string> keywordNameList)
{
return ApiRequester.RequestAsync<CreateTemplateResponse>(
GetTemplateIdUrl,
HttpMethod.Post,
new CreateTemplateRequest(templateShortId),
new CreateTemplateRequest(templateShortId, keywordNameList),
Options);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Drawing;
using System.Threading.Tasks;
using Shouldly;
Expand Down Expand Up @@ -57,7 +58,8 @@ public async Task Should_Create_A_Template_And_Return_TemplateId()
{
var templateMessageService = await WeChatServiceFactory.CreateAsync<TemplateMessageWeService>();

var response = await templateMessageService.CreateTemplateAsync("OPENTM206482867");
var response = await templateMessageService.CreateTemplateAsync("47123",
new List<string> { "时间", "地点", "金额" });

response.ErrorCode.ShouldBe(0);
response.TemplateId.ShouldNotBeNullOrEmpty();
Expand All @@ -78,7 +80,9 @@ public async Task Should_Delete_Template_By_Id()
{
var templateMessageService = await WeChatServiceFactory.CreateAsync<TemplateMessageWeService>();

var createdTemplateResponse = await templateMessageService.CreateTemplateAsync("OPENTM206482867");
var createdTemplateResponse = await templateMessageService.CreateTemplateAsync("47123",
new List<string> { "时间", "地点", "金额" });

var deletedTemplateResponse =
await templateMessageService.DeleteTemplateAsync(createdTemplateResponse.TemplateId);

Expand Down