@@ -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 | |||
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(); | |||
boolean hasDraftList = response.has("draft_list"); | |||
if (hasDraftList) { | |||
@@ -380,7 +381,8 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService { | |||
@Override | |||
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(); | |||
boolean hasTemplateList = response.has("template_list"); | |||
if (hasTemplateList) { | |||
@@ -394,16 +396,19 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService { | |||
@Override | |||
public void addToTemplate(long draftId) throws WxErrorException { | |||
String uri = ADD_TO_TEMPLATE_URL + "?component_appid=" + getWxOpenConfigStorage().getComponentAppId(); | |||
JsonObject param = new JsonObject(); | |||
param.addProperty("draft_id", draftId); | |||
post(ADD_TO_TEMPLATE_URL, param.toString(), "access_token"); | |||
post(uri, param.toString(), "component_access_token"); | |||
} | |||
@Override | |||
public void deleteTemplate(long templateId) throws WxErrorException { | |||
String uri = DELETE_TEMPLATE_URL + "?component_appid=" + getWxOpenConfigStorage().getComponentAppId(); | |||
JsonObject param = new JsonObject(); | |||
param.addProperty("template_id", templateId); | |||
post(DELETE_TEMPLATE_URL, param.toString(), "access_token"); | |||
post(uri, param.toString(), "access_token"); | |||
} | |||
@Override | |||
@@ -2,6 +2,7 @@ package com.iformall.controller; | |||
import com.iformall.common.Result; | |||
import com.iformall.common.ResultData; | |||
import com.iformall.service.toutiao.FmTtOpenService; | |||
import com.iformall.service.wechat.FmOpenService; | |||
import io.swagger.annotations.Api; | |||
import me.chanjar.weixin.common.error.WxErrorException; | |||
@@ -23,13 +24,13 @@ public class WechatWeappDraftTemplateController { | |||
private final Logger logger = LoggerFactory.getLogger(getClass()); | |||
@Autowired | |||
private FmOpenService openService; | |||
private FmTtOpenService openService; | |||
@GetMapping("/tempDraftList") | |||
public ResultData getTempDraftList() { | |||
try { | |||
List<WxOpenMaCodeTemplate> list = openService.getWxOpenComponentService().getTemplateDraftList(); | |||
List<WxOpenMaCodeTemplate> list = openService.getTtOpenComponentService().getTemplateDraftList(); | |||
return new ResultData(list); | |||
} catch (WxErrorException e) { | |||
logger.error(e.getMessage()); | |||
@@ -41,7 +42,7 @@ public class WechatWeappDraftTemplateController { | |||
@GetMapping("/tempList") | |||
public ResultData getTempList() { | |||
try { | |||
List<WxOpenMaCodeTemplate> list = openService.getWxOpenComponentService().getTemplateList(); | |||
List<WxOpenMaCodeTemplate> list = openService.getTtOpenComponentService().getTemplateList(); | |||
return new ResultData(list); | |||
} catch (WxErrorException e) { | |||
logger.error(e.getMessage()); | |||
@@ -55,7 +56,7 @@ public class WechatWeappDraftTemplateController { | |||
return new ResultData(Result.ERROR, "draftId is null"); | |||
} | |||
try { | |||
openService.getWxOpenComponentService().addToTemplate(template.getDraftId()); | |||
openService.getTtOpenComponentService().addToTemplate(template.getDraftId()); | |||
return new ResultData(); | |||
} catch (WxErrorException e) { | |||
logger.error(e.getMessage()); | |||
@@ -69,7 +70,7 @@ public class WechatWeappDraftTemplateController { | |||
return new ResultData(Result.ERROR, "templateId is null"); | |||
} | |||
try { | |||
openService.getWxOpenComponentService().deleteTemplate(template.getTemplateId()); | |||
openService.getTtOpenComponentService().deleteTemplate(template.getTemplateId()); | |||
return new ResultData(); | |||
} catch (WxErrorException e) { | |||
logger.error(e.getMessage()); | |||