|
|
@@ -0,0 +1,57 @@
|
|
|
+package com.mrxu.framework.common.weixin.api;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.mrxu.framework.common.weixin.base.WxHttp;
|
|
|
+import com.mrxu.framework.common.weixin.base.WxResult;
|
|
|
+import com.mrxu.framework.common.weixin.bean.TemplateDraftList;
|
|
|
+import com.mrxu.framework.common.weixin.bean.TemplateList;
|
|
|
+
|
|
|
+// 小程序发布模板相关api
|
|
|
+// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/code_template/gettemplatedraftlist.html
|
|
|
+public class ComponentTemplateApi {
|
|
|
+
|
|
|
+ // 获取代码草稿列表
|
|
|
+ private static String get_draft = "https://api.weixin.qq.com/wxa/gettemplatedraftlist?access_token=";
|
|
|
+ // 将草稿添加到代码模板库
|
|
|
+ private static String addtotemplate = "https://api.weixin.qq.com/wxa/addtotemplate?access_token=";
|
|
|
+ // 获取代码模板列表
|
|
|
+ private static String gettemplatelist = "https://api.weixin.qq.com/wxa/gettemplatelist?access_token=";
|
|
|
+ // 删除指定代码模板
|
|
|
+ private static String deletetemplate = "https://api.weixin.qq.com/wxa/deletetemplate?access_token=";
|
|
|
+
|
|
|
+ // 第一步 获取代码草稿列表
|
|
|
+ // https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/code_template/gettemplatedraftlist.html
|
|
|
+ public static TemplateDraftList getComponentToken(String componentAccessToken) {
|
|
|
+ TemplateDraftList rs = WxHttp.get(TemplateDraftList.class,get_draft+componentAccessToken,null);
|
|
|
+ return rs;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 第二步 将草稿添加到代码模板库
|
|
|
+ // https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/code_template/gettemplatelist.html
|
|
|
+ public static WxResult addToTemplate(String componentAccessToken, String draftId) {
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("draft_id", draftId);
|
|
|
+ // 默认值是0,对应普通模板;可选1,对应标准模板库,关于标准模板库和普通模板库的区别可以查看小程序模板库介绍
|
|
|
+ json.put("template_type", 0);
|
|
|
+ WxResult rs = WxHttp.post(WxResult.class,addtotemplate+componentAccessToken,json);
|
|
|
+ return rs;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 第三步 获取代码模板列表
|
|
|
+ // https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/code_template/gettemplatedraftlist.html
|
|
|
+ public static TemplateList getTemplateList(String componentAccessToken) {
|
|
|
+ TemplateList rs = WxHttp.get(TemplateList.class,gettemplatelist+componentAccessToken,null);
|
|
|
+ return rs;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除指定代码模板
|
|
|
+ // 因为代码模板库的模板数量是有上限的,当达到上限或者有某个模板不再需要时,可以调用本接口删除指定的代码模板。使用过程中如遇到问题,可在开放平台服务商专区发帖交流。
|
|
|
+ // https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/code_template/deletetemplate.html
|
|
|
+ public static WxResult deleteTemplate(String componentAccessToken, String templateId) {
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("template_id", templateId);
|
|
|
+ WxResult rs = WxHttp.post(WxResult.class,deletetemplate+componentAccessToken,json);
|
|
|
+ return rs;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|