添加删除模板的接口方法实现 for issue #63

This commit is contained in:
Binary Wang
2016-10-18 18:29:43 +08:00
parent 550bbe3d1b
commit acc129111a
3 changed files with 45 additions and 15 deletions

View File

@@ -1,12 +1,12 @@
package me.chanjar.weixin.mp.api;
import java.util.List;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import java.util.List;
/**
* <pre>
* 模板消息接口
@@ -68,8 +68,20 @@ public interface WxMpTemplateMsgService {
* 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN
* 接口地址格式https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=ACCESS_TOKEN
* </pre>
*
*
* @return templateId 模板Id
*/
List<WxMpTemplate> getAllPrivateTemplate() throws WxErrorException;
/**
* <pre>
* 删除模板
* 删除模板可在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/del_private_template?access_token=ACCESS_TOKEN
* </pre>
*
* @param templateId 模板Id
*/
boolean delPrivateTemplate(String templateId) throws WxErrorException;
}

View File

@@ -1,10 +1,7 @@
package me.chanjar.weixin.mp.api.impl;
import java.util.List;
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;
@@ -13,6 +10,8 @@ import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import java.util.List;
/**
* <pre>
* Created by Binary Wang on 2016-10-14.
@@ -79,4 +78,18 @@ public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService {
return WxMpTemplate.fromJson(this.wxMpService.get(url, null));
}
@Override
public boolean delPrivateTemplate(String templateId) throws WxErrorException {
String url = API_URL_PREFIX + "/del_private_template";
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("template_id", templateId);
String responseContent = this.wxMpService.post(url, jsonObject.toString());
WxError error = WxError.fromJson(responseContent);
if (error.getErrorCode() == 0) {
return true;
}
throw new WxErrorException(error);
}
}