Просмотр исходного кода

[微信第三方开放平台][新增]:小程序消息模板管理

release_toaliyun_real
Stormeye Wu 7 лет назад
Родитель
Сommit
7415b2a70d
1 измененных файлов: 115 добавлений и 0 удалений
  1. +115
    -0
      mallinkAdmin/src/main/java/com/iformall/controller/WechatWeappMsgTemplateController.java

+ 115
- 0
mallinkAdmin/src/main/java/com/iformall/controller/WechatWeappMsgTemplateController.java Просмотреть файл

@@ -0,0 +1,115 @@
package com.iformall.controller;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateAddResult;
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateLibraryGetResult;
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateLibraryListResult;
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateListResult;
import com.iformall.common.Result;
import com.iformall.common.ResultData;
import com.iformall.service.wechat.WxOpenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.common.error.WxErrorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* Stormeye Wu
*/
@RestController
@RequestMapping("/weappDraftTemplate")
@Api(description = "微信第三方开发平台-小程序草稿/模板管理")
public class WechatWeappMsgTemplateController {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private WxOpenService openService;

@ApiOperation("获取小程序模板库标题列表")
@GetMapping("getTmpLibList")
@ApiImplicitParams({
@ApiImplicitParam(name = "appId", value = "appId", dataType = "String", paramType = "query", required = true),
@ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
@ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
public ResultData getTmpLibList(String appId, Integer pageNum, Integer pageSize) {
try {
WxMaService maService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId);
WxMaTemplateLibraryListResult ret = maService.getTemplateService().findTemplateLibraryList(pageNum, pageSize);
return new ResultData(ret);
} catch (WxErrorException e) {
logger.error(e.getMessage());
return new ResultData(Result.ERROR, e.getMessage());
}
}

@ApiOperation("获取模板库某个模板标题下关键词库")
@GetMapping("getTemplateLibraryKeywordList")
@ApiImplicitParams({
@ApiImplicitParam(name = "appId", value = "appId", dataType = "String", paramType = "query", required = true),
@ApiImplicitParam(name = "id", value = "页数", dataType = "String", paramType = "query", required = true)})
public ResultData findTemplateLibraryKeywordList(String appId, String id) {
try {
WxMaService maService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId);
WxMaTemplateLibraryGetResult ret = maService.getTemplateService().findTemplateLibraryKeywordList(id);
return new ResultData(ret);
} catch (WxErrorException e) {
logger.error(e.getMessage());
return new ResultData(Result.ERROR, e.getMessage());
}

}

@ApiOperation("组合模板并添加至帐号下的个人模板库")
@PostMapping("addTemplate")
public ResultData addTemplate(
@RequestParam(value = "appId") String appId,
@RequestParam(value = "id") String id,
@RequestParam(value = "keywordIdList")List<Integer> keywordIdList) {
try {
WxMaService maService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId);
WxMaTemplateAddResult ret = maService.getTemplateService().addTemplate(id, keywordIdList);
return new ResultData(ret);
} catch (WxErrorException e) {
logger.error(e.getMessage());
return new ResultData(Result.ERROR, e.getMessage());
}

}

@ApiOperation("获取帐号下已存在的模板列表")
@GetMapping("getTemplateList")
@ApiImplicitParams({
@ApiImplicitParam(name = "appId", value = "appId", dataType = "String", paramType = "query", required = true),
@ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
@ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
public ResultData findTemplateList(String appId, Integer pageNum, Integer pageSize) {
try {
WxMaService maService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId);
WxMaTemplateListResult ret = maService.getTemplateService().findTemplateList(pageNum, pageSize);
return new ResultData(ret);
} catch (WxErrorException e) {
logger.error(e.getMessage());
return new ResultData(Result.ERROR, e.getMessage());
}

}

@ApiOperation("删除帐号下的某个模板")
@PostMapping("delTemplate")
public ResultData delTemplate(@RequestParam(value = "appId") String appId, @RequestParam(value = "templateId") String templateId) {
try {
WxMaService maService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId);
maService.getTemplateService().delTemplate(templateId);
return new ResultData();
} catch (WxErrorException e) {
logger.error(e.getMessage());
return new ResultData(Result.ERROR, e.getMessage());
}
}
}

Загрузка…
Отмена
Сохранить