| @@ -146,13 +146,13 @@ public interface TtOpenComponentService { | |||||
| /** | /** | ||||
| * 代小程序实现业务. | * 代小程序实现业务. | ||||
| * 小程序代码模版库管理:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1506504150_nMMh6&token=&lang=zh_CN | |||||
| * access_token 为 component_access_token | |||||
| * 小程序代码模版库管理: | |||||
| * component_access_token | |||||
| */ | */ | ||||
| String GET_TEMPLATE_DRAFT_LIST_URL = "https://api.weixin.qq.com/wxa/gettemplatedraftlist"; | |||||
| String GET_TEMPLATE_LIST_URL = "https://api.weixin.qq.com/wxa/gettemplatelist"; | |||||
| String ADD_TO_TEMPLATE_URL = "https://api.weixin.qq.com/wxa/addtotemplate"; | |||||
| String DELETE_TEMPLATE_URL = "https://api.weixin.qq.com/wxa/deletetemplate"; | |||||
| String GET_TEMPLATE_DRAFT_LIST_URL = "https://open.microapp.bytedance.com/openapi/v1/tp/template/get_draft_list"; | |||||
| String GET_TEMPLATE_LIST_URL = "https://open.microapp.bytedance.com/openapi/v1/tp/template/get_tpl_list"; | |||||
| String ADD_TO_TEMPLATE_URL = "https://open.microapp.bytedance.com/openapi/v1/tp/template/add_tpl"; | |||||
| String DELETE_TEMPLATE_URL = "https://open.microapp.bytedance.com/openapi/v1/tp/template/del_tpl"; | |||||
| /** | /** | ||||
| * 获取草稿箱内的所有临时代码草稿. | * 获取草稿箱内的所有临时代码草稿. | ||||
| @@ -366,7 +366,8 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService { | |||||
| @Override | @Override | ||||
| public List<WxOpenMaCodeTemplate> getTemplateDraftList() throws WxErrorException { | public List<WxOpenMaCodeTemplate> getTemplateDraftList() throws WxErrorException { | ||||
| String responseContent = get(GET_TEMPLATE_DRAFT_LIST_URL, "access_token"); | |||||
| String uri = GET_TEMPLATE_DRAFT_LIST_URL + "?component_appid=" + getWxOpenConfigStorage().getComponentAppId(); | |||||
| String responseContent = get(uri, "component_access_token"); | |||||
| JsonObject response = JSON_PARSER.parse(StringUtils.defaultString(responseContent, "{}")).getAsJsonObject(); | JsonObject response = JSON_PARSER.parse(StringUtils.defaultString(responseContent, "{}")).getAsJsonObject(); | ||||
| boolean hasDraftList = response.has("draft_list"); | boolean hasDraftList = response.has("draft_list"); | ||||
| if (hasDraftList) { | if (hasDraftList) { | ||||
| @@ -380,7 +381,8 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService { | |||||
| @Override | @Override | ||||
| public List<WxOpenMaCodeTemplate> getTemplateList() throws WxErrorException { | public List<WxOpenMaCodeTemplate> getTemplateList() throws WxErrorException { | ||||
| String responseContent = get(GET_TEMPLATE_LIST_URL, "access_token"); | |||||
| String uri = GET_TEMPLATE_LIST_URL + "?component_appid=" + getWxOpenConfigStorage().getComponentAppId(); | |||||
| String responseContent = get(GET_TEMPLATE_LIST_URL, "component_access_token"); | |||||
| JsonObject response = JSON_PARSER.parse(StringUtils.defaultString(responseContent, "{}")).getAsJsonObject(); | JsonObject response = JSON_PARSER.parse(StringUtils.defaultString(responseContent, "{}")).getAsJsonObject(); | ||||
| boolean hasTemplateList = response.has("template_list"); | boolean hasTemplateList = response.has("template_list"); | ||||
| if (hasTemplateList) { | if (hasTemplateList) { | ||||
| @@ -394,16 +396,19 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService { | |||||
| @Override | @Override | ||||
| public void addToTemplate(long draftId) throws WxErrorException { | public void addToTemplate(long draftId) throws WxErrorException { | ||||
| String uri = ADD_TO_TEMPLATE_URL + "?component_appid=" + getWxOpenConfigStorage().getComponentAppId(); | |||||
| JsonObject param = new JsonObject(); | JsonObject param = new JsonObject(); | ||||
| param.addProperty("draft_id", draftId); | param.addProperty("draft_id", draftId); | ||||
| post(ADD_TO_TEMPLATE_URL, param.toString(), "access_token"); | |||||
| post(uri, param.toString(), "component_access_token"); | |||||
| } | } | ||||
| @Override | @Override | ||||
| public void deleteTemplate(long templateId) throws WxErrorException { | public void deleteTemplate(long templateId) throws WxErrorException { | ||||
| String uri = DELETE_TEMPLATE_URL + "?component_appid=" + getWxOpenConfigStorage().getComponentAppId(); | |||||
| JsonObject param = new JsonObject(); | JsonObject param = new JsonObject(); | ||||
| param.addProperty("template_id", templateId); | param.addProperty("template_id", templateId); | ||||
| post(DELETE_TEMPLATE_URL, param.toString(), "access_token"); | |||||
| post(uri, param.toString(), "access_token"); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -2,6 +2,7 @@ package com.iformall.controller; | |||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.service.toutiao.FmTtOpenService; | |||||
| import com.iformall.service.wechat.FmOpenService; | import com.iformall.service.wechat.FmOpenService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| @@ -23,13 +24,13 @@ public class WechatWeappDraftTemplateController { | |||||
| private final Logger logger = LoggerFactory.getLogger(getClass()); | private final Logger logger = LoggerFactory.getLogger(getClass()); | ||||
| @Autowired | @Autowired | ||||
| private FmOpenService openService; | |||||
| private FmTtOpenService openService; | |||||
| @GetMapping("/tempDraftList") | @GetMapping("/tempDraftList") | ||||
| public ResultData getTempDraftList() { | public ResultData getTempDraftList() { | ||||
| try { | try { | ||||
| List<WxOpenMaCodeTemplate> list = openService.getWxOpenComponentService().getTemplateDraftList(); | |||||
| List<WxOpenMaCodeTemplate> list = openService.getTtOpenComponentService().getTemplateDraftList(); | |||||
| return new ResultData(list); | return new ResultData(list); | ||||
| } catch (WxErrorException e) { | } catch (WxErrorException e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -41,7 +42,7 @@ public class WechatWeappDraftTemplateController { | |||||
| @GetMapping("/tempList") | @GetMapping("/tempList") | ||||
| public ResultData getTempList() { | public ResultData getTempList() { | ||||
| try { | try { | ||||
| List<WxOpenMaCodeTemplate> list = openService.getWxOpenComponentService().getTemplateList(); | |||||
| List<WxOpenMaCodeTemplate> list = openService.getTtOpenComponentService().getTemplateList(); | |||||
| return new ResultData(list); | return new ResultData(list); | ||||
| } catch (WxErrorException e) { | } catch (WxErrorException e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -55,7 +56,7 @@ public class WechatWeappDraftTemplateController { | |||||
| return new ResultData(Result.ERROR, "draftId is null"); | return new ResultData(Result.ERROR, "draftId is null"); | ||||
| } | } | ||||
| try { | try { | ||||
| openService.getWxOpenComponentService().addToTemplate(template.getDraftId()); | |||||
| openService.getTtOpenComponentService().addToTemplate(template.getDraftId()); | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } catch (WxErrorException e) { | } catch (WxErrorException e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -69,7 +70,7 @@ public class WechatWeappDraftTemplateController { | |||||
| return new ResultData(Result.ERROR, "templateId is null"); | return new ResultData(Result.ERROR, "templateId is null"); | ||||
| } | } | ||||
| try { | try { | ||||
| openService.getWxOpenComponentService().deleteTemplate(template.getTemplateId()); | |||||
| openService.getTtOpenComponentService().deleteTemplate(template.getTemplateId()); | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } catch (WxErrorException e) { | } catch (WxErrorException e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||