diff --git a/src/Official/EasyAbp.Abp.WeChat.Official/Services/TemplateMessage/Request/CreateTemplateRequest.cs b/src/Official/EasyAbp.Abp.WeChat.Official/Services/TemplateMessage/Request/CreateTemplateRequest.cs index 9ecab64..3157f81 100644 --- a/src/Official/EasyAbp.Abp.WeChat.Official/Services/TemplateMessage/Request/CreateTemplateRequest.cs +++ b/src/Official/EasyAbp.Abp.WeChat.Official/Services/TemplateMessage/Request/CreateTemplateRequest.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +using System.Collections.Generic; using EasyAbp.Abp.WeChat.Official.Models; using Newtonsoft.Json; @@ -10,12 +11,18 @@ namespace EasyAbp.Abp.WeChat.Official.Services.TemplateMessage.Request public class CreateTemplateRequest : OfficialCommonRequest { /// - /// 模板库中模板的编号,有 "TM**" 和 "OPENTMTM**" 等形式。 + /// 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式,对于类目模板,为纯数字ID /// [JsonPropertyName("template_id_short")] [JsonProperty("template_id_short")] public string TemplateShortId { get; protected set; } + /// + /// 选用的类目模板的关键词,按顺序传入,如果为空,或者关键词不在模板库中,会返回40246错误码 + /// + [JsonProperty("keyword_name_list")] + public List KeywordNameList { get; protected set; } + protected CreateTemplateRequest() { } @@ -23,10 +30,12 @@ protected CreateTemplateRequest() /// /// 构建一个新的 对象。 /// - /// 模板库中模板的编号,有 "TM**" 和 "OPENTMTM**" 等形式。 - public CreateTemplateRequest(string templateShortId) + /// 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式,对于类目模板,为纯数字ID + /// 选用的类目模板的关键词,按顺序传入,如果为空,或者关键词不在模板库中,会返回40246错误码 + public CreateTemplateRequest(string templateShortId, List keywordNameList) { TemplateShortId = templateShortId; + KeywordNameList = keywordNameList; } } } \ No newline at end of file diff --git a/src/Official/EasyAbp.Abp.WeChat.Official/Services/TemplateMessage/TemplateMessageWeService.cs b/src/Official/EasyAbp.Abp.WeChat.Official/Services/TemplateMessage/TemplateMessageWeService.cs index e3298b3..93baf49 100644 --- a/src/Official/EasyAbp.Abp.WeChat.Official/Services/TemplateMessage/TemplateMessageWeService.cs +++ b/src/Official/EasyAbp.Abp.WeChat.Official/Services/TemplateMessage/TemplateMessageWeService.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using EasyAbp.Abp.WeChat.Official.Models; @@ -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) { } @@ -112,13 +114,15 @@ public virtual Task GetIndustryAsync() /// /// 根据短模版 Id 创建模版。 /// - /// 模板库中模板的编号,有 "TM**" 和 "OPENTMTM**" 等形式。 - public virtual Task CreateTemplateAsync(string templateShortId) + /// 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式,对于类目模板,为纯数字ID + /// 选用的类目模板的关键词,按顺序传入,如果为空,或者关键词不在模板库中,会返回40246错误码 + public virtual Task CreateTemplateAsync(string templateShortId, + List keywordNameList) { return ApiRequester.RequestAsync( GetTemplateIdUrl, HttpMethod.Post, - new CreateTemplateRequest(templateShortId), + new CreateTemplateRequest(templateShortId, keywordNameList), Options); } diff --git a/tests/EasyAbp.Abp.WeChat.Official.Tests/Services/TemplateMessageServiceTests.cs b/tests/EasyAbp.Abp.WeChat.Official.Tests/Services/TemplateMessageServiceTests.cs index 74ea989..fddba5e 100644 --- a/tests/EasyAbp.Abp.WeChat.Official.Tests/Services/TemplateMessageServiceTests.cs +++ b/tests/EasyAbp.Abp.WeChat.Official.Tests/Services/TemplateMessageServiceTests.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Drawing; using System.Threading.Tasks; using Shouldly; @@ -57,7 +58,8 @@ public async Task Should_Create_A_Template_And_Return_TemplateId() { var templateMessageService = await WeChatServiceFactory.CreateAsync(); - var response = await templateMessageService.CreateTemplateAsync("OPENTM206482867"); + var response = await templateMessageService.CreateTemplateAsync("47123", + new List { "时间", "地点", "金额" }); response.ErrorCode.ShouldBe(0); response.TemplateId.ShouldNotBeNullOrEmpty(); @@ -78,7 +80,9 @@ public async Task Should_Delete_Template_By_Id() { var templateMessageService = await WeChatServiceFactory.CreateAsync(); - var createdTemplateResponse = await templateMessageService.CreateTemplateAsync("OPENTM206482867"); + var createdTemplateResponse = await templateMessageService.CreateTemplateAsync("47123", + new List { "时间", "地点", "金额" }); + var deletedTemplateResponse = await templateMessageService.DeleteTemplateAsync(createdTemplateResponse.TemplateId);