From f468653ac4fd746cd8000e929b1592d047b93a0e Mon Sep 17 00:00:00 2001 From: allovine Date: Mon, 17 Jul 2023 23:19:59 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E4=BF=AE=E5=A4=8D=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/impl/WxMpTemplateMsgServiceImpl.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImpl.java index 33b303328..dd4ae5b72 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImpl.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.api.impl; import com.google.gson.Gson; +import com.google.gson.JsonArray; import com.google.gson.JsonObject; import lombok.RequiredArgsConstructor; import me.chanjar.weixin.common.api.WxConsts; @@ -77,6 +78,24 @@ public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService { throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP)); } + @Override + public String addTemplate(String shortTemplateId, List keywordNameList) throws WxErrorException { + JsonObject jsonObject = new JsonObject(); + JsonArray jsonArray = new JsonArray(); + for(String val: keywordNameList) { + jsonArray.add(val); + } + jsonObject.addProperty("template_id_short", shortTemplateId); + jsonObject.add("keyword_name_list",jsonArray); + String responseContent = this.wxMpService.post(TEMPLATE_API_ADD_TEMPLATE, jsonObject.toString()); + final JsonObject result = GsonParser.parse(responseContent); + if (result.get(WxConsts.ERR_CODE).getAsInt() == 0) { + return result.get("template_id").getAsString(); + } + + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP)); + } + @Override public List getAllPrivateTemplate() throws WxErrorException { return WxMpTemplate.fromJson(this.wxMpService.get(TEMPLATE_GET_ALL_PRIVATE_TEMPLATE, null));