File tree Expand file tree Collapse file tree 3 files changed +45
-15
lines changed
main/java/me/chanjar/weixin/mp/api
test/java/me/chanjar/weixin/mp/api/impl Expand file tree Collapse file tree 3 files changed +45
-15
lines changed Original file line number Diff line number Diff line change 11package me .chanjar .weixin .mp .api ;
22
3- import java .util .List ;
4-
53import me .chanjar .weixin .common .exception .WxErrorException ;
64import me .chanjar .weixin .mp .bean .template .WxMpTemplate ;
75import me .chanjar .weixin .mp .bean .template .WxMpTemplateIndustry ;
86import me .chanjar .weixin .mp .bean .template .WxMpTemplateMessage ;
97
8+ import java .util .List ;
9+
1010/**
1111 * <pre>
1212 * 模板消息接口
@@ -68,8 +68,20 @@ public interface WxMpTemplateMsgService {
6868 * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN
6969 * 接口地址格式:https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=ACCESS_TOKEN
7070 * </pre>
71- *
71+ *
7272 * @return templateId 模板Id
7373 */
7474 List <WxMpTemplate > getAllPrivateTemplate () throws WxErrorException ;
75+
76+ /**
77+ * <pre>
78+ * 删除模板
79+ * 删除模板可在MP中完成,为方便第三方开发者,提供通过接口调用的方式来删除某帐号下的模板
80+ * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN
81+ * 接口地址格式:https://api.weixin.qq.com/cgi-bin/template/del_private_template?access_token=ACCESS_TOKEN
82+ * </pre>
83+ *
84+ * @param templateId 模板Id
85+ */
86+ boolean delPrivateTemplate (String templateId ) throws WxErrorException ;
7587}
Original file line number Diff line number Diff line change 11package me .chanjar .weixin .mp .api .impl ;
22
3- import java .util .List ;
4-
53import com .google .gson .JsonObject ;
64import com .google .gson .JsonParser ;
7-
85import me .chanjar .weixin .common .bean .result .WxError ;
96import me .chanjar .weixin .common .exception .WxErrorException ;
107import me .chanjar .weixin .mp .api .WxMpService ;
1310import me .chanjar .weixin .mp .bean .template .WxMpTemplateIndustry ;
1411import me .chanjar .weixin .mp .bean .template .WxMpTemplateMessage ;
1512
13+ import java .util .List ;
14+
1615/**
1716 * <pre>
1817 * Created by Binary Wang on 2016-10-14.
@@ -79,4 +78,18 @@ public List<WxMpTemplate> getAllPrivateTemplate() throws WxErrorException {
7978 return WxMpTemplate .fromJson (this .wxMpService .get (url , null ));
8079 }
8180
81+ @ Override
82+ public boolean delPrivateTemplate (String templateId ) throws WxErrorException {
83+ String url = API_URL_PREFIX + "/del_private_template" ;
84+ JsonObject jsonObject = new JsonObject ();
85+ jsonObject .addProperty ("template_id" , templateId );
86+ String responseContent = this .wxMpService .post (url , jsonObject .toString ());
87+ WxError error = WxError .fromJson (responseContent );
88+ if (error .getErrorCode () == 0 ) {
89+ return true ;
90+ }
91+
92+ throw new WxErrorException (error );
93+ }
94+
8295}
Original file line number Diff line number Diff line change 11package me .chanjar .weixin .mp .api .impl ;
22
3- import java .text .SimpleDateFormat ;
4- import java .util .Date ;
5- import java .util .List ;
6-
7- import org .testng .Assert ;
8- import org .testng .annotations .Guice ;
9- import org .testng .annotations .Test ;
10-
113import com .google .inject .Inject ;
12-
134import me .chanjar .weixin .common .exception .WxErrorException ;
145import me .chanjar .weixin .mp .api .ApiTestModule ;
156import me .chanjar .weixin .mp .api .WxXmlMpInMemoryConfigStorage ;
167import me .chanjar .weixin .mp .bean .template .WxMpTemplate ;
178import me .chanjar .weixin .mp .bean .template .WxMpTemplateData ;
189import me .chanjar .weixin .mp .bean .template .WxMpTemplateIndustry ;
1910import me .chanjar .weixin .mp .bean .template .WxMpTemplateMessage ;
11+ import org .testng .Assert ;
12+ import org .testng .annotations .Guice ;
13+ import org .testng .annotations .Test ;
14+
15+ import java .text .SimpleDateFormat ;
16+ import java .util .Date ;
17+ import java .util .List ;
2018
2119/**
2220 * <pre>
@@ -74,4 +72,11 @@ public void testGetAllPrivateTemplate() throws Exception {
7472 System .err .println (result );
7573 }
7674
75+ @ Test
76+ public void testDelPrivateTemplate () throws Exception {
77+ String templateId = "RPcTe7-4BkU5A2J3imC6W0b4JbjEERcJg0whOMKJKIc" ;
78+ boolean result = this .wxService .getTemplateMsgService ().delPrivateTemplate (templateId );
79+ Assert .assertTrue (result );
80+ }
81+
7782}
You can’t perform that action at this time.
0 commit comments