mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-02-18 22:26:22 +08:00
添加获得模板ID的接口方法实现 for issue #63
This commit is contained in:
@@ -46,4 +46,15 @@ public interface WxMpTemplateMsgService {
|
||||
*/
|
||||
String sendTemplateMsg(WxMpTemplateMessage templateMessage) 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**”等形式
|
||||
* @return templateId 模板Id
|
||||
*/
|
||||
String addTemplate(String shortTemplateId) throws WxErrorException;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
@@ -55,4 +56,18 @@ public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService {
|
||||
return WxMpIndustry.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addTemplate(String shortTemplateId) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/api_add_template";
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("template_id_short", shortTemplateId);
|
||||
String responseContent = this.wxMpService.post(url, jsonObject.toString());
|
||||
final JsonObject result = JSON_PARSER.parse(responseContent).getAsJsonObject();
|
||||
if (result.get("errcode").getAsInt() == 0) {
|
||||
return result.get("template_id").getAsString();
|
||||
}
|
||||
|
||||
throw new WxErrorException(WxError.fromJson(responseContent));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user