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

类目模板库关键字入参 #3078

Merged
merged 1 commit into from
Jul 13, 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
Expand Up @@ -66,6 +66,21 @@ public interface WxMpTemplateMsgService {
*/
String addTemplate(String shortTemplateId) throws WxErrorException;

/**
* <pre>
* 获得模板ID
* 从类目模板库选择模板到帐号后台,获得模板ID的过程可在MP中完成
* 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN
* 接口地址格式:https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=ACCESS_TOKEN
* </pre>
*
* @param shortTemplateId 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式,对于类目模板,为纯数字ID
* @param keywordNameList 选用的类目模板的关键词,按顺序传入,如果为空,或者关键词不在模板库中,会返回40246错误码
* @return templateId 模板Id
* @throws WxErrorException .
*/
String addTemplate(String shortTemplateId, List<String> keywordNameList) throws WxErrorException;

/**
* <pre>
* 获取模板列表
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.chanjar.weixin.mp.api.impl;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
Expand Down Expand Up @@ -68,6 +69,21 @@ public String addTemplate(String shortTemplateId) throws WxErrorException {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
}

@Override
public String addTemplate(String shortTemplateId, List<String> keywordNameList) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
Gson gson = new Gson();
jsonObject.addProperty("template_id_short", shortTemplateId);
jsonObject.addProperty("keyword_name_list",gson.toJson(keywordNameList));
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<WxMpTemplate> getAllPrivateTemplate() throws WxErrorException {
return WxMpTemplate.fromJson(this.wxMpService.get(TEMPLATE_GET_ALL_PRIVATE_TEMPLATE, null));
Expand Down