微服务中消息推送模块,一般消息推送分为微信模板消息、阿里云短信、APP消息推送,APP消息推送选择个推,本文主要介绍微信消息模板
- 引入maven(具体版本具体引入)
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-mp</artifactId>
<version>3.3.0</version>
</dependency>
- yml配置文件配置微信账号基本信息
#微信参数设置
wx:
msg:
#参数配置
appid: wx1cXXXXad983
secret: 4269XXXX9e3df3c6af03833
AESKey: JykXXXX4+=@
- 创建模板实体类
WxTemplate.java
/**
* 实体类
*
* @author myn
* @since 2021-10-12
*/
@Data
@TableName("message_wx_template")
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "WxTemplate对象", description = "WxTemplate对象")
public class WxTemplate extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@ApiModelProperty(value = "主键")
private Long id;
/**
* 模板id
*/
@ApiModelProperty(value = "模板id")
private String tid;
/**
* 关键字列表,最多支持5个,最少2个
*/
@ApiModelProperty(value = "关键字列表,最多支持5个,最少2个")
private String kidList;
/**
* 服务场景描述,15个字以内
*/
@ApiModelProperty(value = "服务场景描述,15个字以内")
private String sceneDesc;
/**
* 审核结果。0--未通过,1--通过
*/
@ApiModelProperty(value = "审核结果。0--未通过,1--通过")
private String reviewStatus;
/**
* 生成的模板id
*/
@ApiModelProperty(value = "生成的模板id")
private String templateId;
/**
* 模板类型。0--一次性订阅,1--永久性推送
*/
@ApiModelProperty(value = "模板类型。0--一次性订阅,1--永久性推送")
private String type;
/**
* 模板标题
*/
@ApiModelProperty(value = "模板标题")
private String title;
/**
* 模板类目id
*/
@ApiModelProperty(value = "模板类目id")
private Integer categoryId;
/**
* 模板类目名称
*/
@ApiModelProperty(value = "模板类目名称")
private String categoryName;
/**
* 租户标识
*/
@ApiModelProperty(value = "租户标识")
private String tenant;
/**
* 排序
*/
@ApiModelProperty(value = "排序")
private Integer sort;
}
WxTemplateData.java
/**
* 实体类
*
* @author myn
* @since 2021-10-13
*/
@Data
@TableName("message_wx_template_data")
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "WxTemplateData对象", description = "WxTemplateData对象")
public class WxTemplateData extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* id
*/
@ApiModelProperty(value = "id")
private Long id;
/**
* 生成的模板id,如TbZwosLXXXXXXfTP27E
*/
@ApiModelProperty(value = "生成的模板id,如TbZwosLXXXXXXfTP27E")
private String templateId;
/**
* 模板id,如“2269”
*/
@ApiModelProperty(value = "模板id,如“2269”")
private String tid;
/**
* 用户ID
*/
@ApiModelProperty(value = "用户ID")
private String openId;
/**
* 跳转页面
*/
@ApiModelProperty(value = "跳转页面")
private String page;
/**
* 跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
*/
@ApiModelProperty(value = "跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版")
private String miniprogramState;
/**
* 进入小程序查看”的语言类型,支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为zh_CN
返回值
*/
@ApiModelProperty(value = "进入小程序查看”的语言类型,支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为zh_CN 返回值")
private String lang;
/**
* 关键字id,如 1
*/
@ApiModelProperty(value = "关键字id,如 1 ")
private String kid1;
/**
* 关键字名称,如“商品名称”
*/
@ApiModelProperty(value = "关键字名称,如“商品名称”")
private String kidName1;
/**
* 关键字的key。如”thing1“,微信后台获取
*/
@ApiModelProperty(value = "关键字的key。如”thing1“,微信后台获取")
private String kidDataKey1;
/**
* 关键字发送的内容
*/
@ApiModelProperty(value = "关键字发送的内容")
private String kidData1;
/**
* 关键字id,如 1
*/
@ApiModelProperty(value = "关键字id,如 1 ")
private String kid2;
/**
* 关键字名称,如“商品名称”
*/
@ApiModelProperty(value = "关键字名称,如“商品名称”")
private String kidName2;
/**
* 关键字的key。如”thing1“,微信后台获取
*/
@ApiModelProperty(value = "关键字的key。如”thing1“,微信后台获取")
private String kidDataKey2;
/**
* 关键字发送的内容
*/
@ApiModelProperty(value = "关键字发送的内容")
private String kidData2;
/**
* 关键字id,如 1
*/
@ApiModelProperty(value = "关键字id,如 1 ")
private String kid3;
/**
* 关键字名称,如“商品名称”
*/
@ApiModelProperty(value = "关键字名称,如“商品名称”")
private String kidName3;
/**
* 关键字的key。如”thing1“,微信后台获取
*/
@ApiModelProperty(value = "关键字的key。如”thing1“,微信后台获取")
private String kidDataKey3;
/**
* 关键字发送的内容
*/
@ApiModelProperty(value = "关键字发送的内容")
private String kidData3;
/**
* 关键字id,如 1
*/
@ApiModelProperty(value = "关键字id,如 1 ")
private String kid4;
/**
* 关键字名称,如“商品名称”
*/
@ApiModelProperty(value = "关键字名称,如“商品名称”")
private String kidName4;
/**
* 关键字的key。如”thing1“,微信后台获取
*/
@ApiModelProperty(value = "关键字的key。如”thing1“,微信后台获取")
private String kidDataKey4;
/**
* 关键字发送的内容
*/
@ApiModelProperty(value = "关键字发送的内容")
private String kidData4;
/**
* 关键字id,如 1
*/
@ApiModelProperty(value = "关键字id,如 1 ")
private String kid5;
/**
* 关键字名称,如“商品名称”
*/
@ApiModelProperty(value = "关键字名称,如“商品名称”")
private String kidName5;
/**
* 关键字的key。如”thing1“,微信后台获取
*/
@ApiModelProperty(value = "关键字的key。如”thing1“,微信后台获取")
private String kidDataKey5;
/**
* 关键字发送的内容
*/
@ApiModelProperty(value = "关键字发送的内容")
private String kidData5;
/**
* 租户标识
*/
@ApiModelProperty(value = "租户标识")
private String tenant;
}
- service实现类,主要实现微信模板的增删改查
/**
* 服务实现类
*
* @author myn
* @since 2021-10-12
*/
@Service
public class WxTemplateServiceImpl extends BaseServiceImpl<WxTemplateMapper, WxTemplate> implements IWxTemplateService {
@Autowired
private PlatformTransactionManager platformTransactionManager;
@Autowired
private TransactionDefinition transactionDefinition;
@Override
public IPage<WxTemplateVO> selectWxTemplatePage(IPage<WxTemplateVO> page, WxTemplateVO wxTemplate) {
return page.setRecords(baseMapper.selectWxTemplatePage(page, wxTemplate));
}
@Override
public JSONObject addWxTemplate(WxTemplate wxTemplate) {
String accessToken = GetAccessToken.getAccessToken();
String tid = wxTemplate.getTid();
char[] kidList = wxTemplate.getKidList().toCharArray();
String sceneDesc = wxTemplate.getSceneDesc();
String url = "https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token="
+ accessToken;
wxTemplate.setReviewStatus("0");
Map<String, String> map = new HashMap<>();
map.put("tid", tid);
map.put("kidList", Arrays.toString(kidList));
map.put("sceneDesc", sceneDesc);
//租户标识
wxTemplate.setTenant("");
JSONObject object = null;
R<Object> resp = R.status(this.save(wxTemplate));
if (resp.getCode() == 200) {
String result = HttpUtil.sendPost(url, map);
object = JSON.parseObject(result);
if (object.get("errcode") == "0") {
String tempid = object.get("priTmplId").toString();
wxTemplate.setTemplateId(tempid);
wxTemplate.setReviewStatus("1");
R.status(this.updateById(wxTemplate));
} else {
return object;
}
} else {
return JSONObject.parseObject(String.valueOf(resp));
}
return object;
}
@Override
public JSONObject delWxTemplate(String id, String templateId) {
String accessToken = GetAccessToken.getAccessToken();
TransactionStatus transaction = platformTransactionManager.getTransaction(transactionDefinition);
String url = "https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate?access_token="
+ accessToken;
JSONObject object = null;
Map<String, String> map = new HashMap<>();
map.put("priTmplId", templateId);
try {
R<Object> resp = R.status(this.deleteLogic(Func.toLongList(id)));
if (resp.getCode() == 200) {
String result = HttpUtil.sendPost(url, map);
object = JSON.parseObject(result);
if (object.get("errcode") == "0") {
platformTransactionManager.commit(transaction);
return object;
} else {
return object;
}
} else {
return JSONObject.parseObject(String.valueOf(resp));
}
} catch (Exception e) {
platformTransactionManager.rollback(transaction);
e.printStackTrace();
}
assert object != null;
return object;
}
@Override
public JSONObject getCategory() {
String accessToken = GetAccessToken.getAccessToken();
String url = "https://api.weixin.qq.com/wxaapi/newtmpl/getcategory?access_token="
+ accessToken;
String result = HttpUtil.sendGet(url);
return JSON.parseObject(result);
}
@Override
public JSONObject getPubTemplateKeyWordsById(String tid) {
String accessToken = GetAccessToken.getAccessToken();
String url = "https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatekeywords?access_token="
+ accessToken
+ "&tid="
+ tid;
String result = HttpUtil.sendGet(url);
return JSON.parseObject(result);
}
@Override
public JSONObject getPubTemplateTitleList(String ids, int start, int limit) {
String accessToken = GetAccessToken.getAccessToken();
String url = "https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatetitles?access_token="
+ accessToken
+ "&ids="
+ ids
+ "&start="
+ start
+ "&limit="
+ limit;
String result = HttpUtil.sendGet(url);
return JSON.parseObject(result);
}
@Override
public JSONObject getTemplateList() {
String accessToken = GetAccessToken.getAccessToken();
String url = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token="
+ accessToken;
String result = HttpUtil.sendGet(url);
return JSON.parseObject(result);
}
@Override
public Map<String,String> getTemplateId(){
JSONArray js = (JSONArray) getTemplateList().get("data");
Map<String,String> map = new HashMap<>();
for (int i=0;i<js.size();i++){
map.put(js.getJSONObject(i).get("priTmplId").toString(),js.getJSONObject(i).get("title").toString());
}
return map;
}
}
微信消息的服务实现类
/**
* 服务实现类
*
* @author myn
* @since 2021-10-13
*/
@Service
public class WxTemplateDataServiceImpl extends BaseServiceImpl<WxTemplateDataMapper, WxTemplateData> implements IWxTemplateDataService {
@Autowired
private IWxAcceptsingleService wxAcceptsingleService;
private WxMaMsgService msgService;
public WxTemplateDataServiceImpl() {
}
Log log = LogFactory.get();
@Override
public IPage<WxTemplateDataVO> selectWxTemplateDataPage(IPage<WxTemplateDataVO> page, WxTemplateDataVO wxTemplateData) {
return page.setRecords(baseMapper.selectWxTemplateDataPage(page, wxTemplateData));
}
/**
* 获取需要填写的关键字列表
*
* @param templateId
* @return 关键字的键值对
* @author huan
*/
@Override
public Map<String, String> getDataList(String templateId) {
WxTemplateData wxTemplateData = baseMapper.selectWxTemplateDataParam(templateId);
Map<String, String> map = new HashMap<>();
map.put(wxTemplateData.getKidName1(), wxTemplateData.getKidDataKey1());
map.put(wxTemplateData.getKidName2(), wxTemplateData.getKidDataKey2());
map.put(wxTemplateData.getKidName3(), wxTemplateData.getKidDataKey3());
map.put(wxTemplateData.getKidName4(), wxTemplateData.getKidDataKey4());
map.put(wxTemplateData.getKidName5(), wxTemplateData.getKidDataKey5());
//去掉空的KEY和Value,返回有数值的map
MapRemoveNullUtil.removeNullEntry(map);
System.out.println(map);
return map;
}
/**
* 发送消息
*
* @param wxTemplateData
* @return 返回信息的String
* @throws Exception
* @author huan
*/
@Override
public String sendMsg(WxTemplateData wxTemplateData) throws Exception {
Map<String, String> map = new HashMap<>();
map.put(wxTemplateData.getKidDataKey1(), wxTemplateData.getKidData1());
map.put(wxTemplateData.getKidDataKey2(), wxTemplateData.getKidData2());
map.put(wxTemplateData.getKidDataKey3(), wxTemplateData.getKidData3());
map.put(wxTemplateData.getKidDataKey4(), wxTemplateData.getKidData4());
map.put(wxTemplateData.getKidDataKey5(), wxTemplateData.getKidData5());
//去掉空的键值对
MapRemoveNullUtil.removeNullEntry(map);
List<Map<String, String>> data = new ArrayList<>();
data.add(map);
//根据,分割传进来的多个openid
String[] templateId = wxTemplateData.getTemplateId().split(",");
net.sf.json.JSONObject jsonResult = new JSONObject();
//foreach发送
for (String id : templateId) {
Template template = new Template();
template.setTemplate_id(id);
template.setTouser(wxTemplateData.getOpenId());
template.setPage(wxTemplateData.getPage());
List<TemplateParam> paras = new ArrayList<>(data.size());
//转换成{things:{value:"things"}}形式
for (Map<String, String> m : data) {
for (String k : m.keySet()) {
paras.add(new TemplateParam(k, m.get(k)));
}
}
template.setTemplateParamList(paras);
//拼接链接
String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=ACCESS_TOKEN";
requestUrl = requestUrl.replace("ACCESS_TOKEN", GetAccessToken.getAccessToken());
log.info("链接地址:{}", template.toJSON());
//获取返回信息
jsonResult = CommonUtil.httpsRequest(requestUrl, "POST", template.toJSON());
log.info("返回消息:{}", jsonResult);
int errorCode = jsonResult.getInt("errcode");
String errorMessage = jsonResult.getString("errmsg");
if (errorCode == 0) {
//发送成功
log.info("给{}发送的消息成功,返回消息:{}", id, jsonResult.toString());
//记录存库
WxAcceptsingle wxAcceptsingle = new WxAcceptsingle();
wxAcceptsingle.setData(data.toString());
wxAcceptsingle.setLang(WxMaConstants.MiniprogramLang.ZH_CN);
wxAcceptsingle.setMiniprogramState(WxMaConstants.MiniprogramState.FORMAL);
wxAcceptsingle.setAccessToken(GetAccessToken.getAccessToken());
wxAcceptsingle.setPage(wxTemplateData.getPage());
wxAcceptsingle.setSendStatus("1");
wxAcceptsingle.setTouser(wxTemplateData.getOpenId());
wxAcceptsingle.setTenant(AESUtils.aesEncode(WxAppConfig.getAesKey(), WxAppConfig.getAppId()));
R.status(this.wxAcceptsingleService.save(wxAcceptsingle));
} else {
//发送失败,不进行终止,日志记录后继续发送下一个
log.warn("订阅消息发送失败" + errorCode + "," + errorMessage);
}
}
return jsonResult.toString();
}
/**
* 利用租户字段进行增删改查测试
* 查询测试
*
* @return
*/
@Override
public List<WxTemplateData> selectList() {
QueryWrapper<WxTemplateData> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("tenant", AESUtils.aesEncode(WxAppConfig.getAesKey(), WxAppConfig.getAppId()));
String a = AESUtils.aesEncode(WxAppConfig.getAesKey(), WxAppConfig.getAppId());
System.out.println(a);
return baseMapper.selectList(queryWrapper);
}
/**
* 利用租户字段进行增删改查测试
* 删除测试
* @author huan
* @return 1为删除成功,0为删除失败
*/
@Override
public int deleteByEntity(String id) {
QueryWrapper<WxTemplateData> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("tenant", AESUtils.aesEncode(WxAppConfig.getAesKey(), WxAppConfig.getAppId()))
.eq("id", id);
String a = AESUtils.aesEncode(WxAppConfig.getAesKey(), WxAppConfig.getAppId());
System.out.println(a);
return baseMapper.delete(queryWrapper);
}
}
- 控制器
这个就很简单了,中间建立接口实现调用
WxTemplateController.java
/**
* 控制器
*
* @author myn
* @since 2021-10-12
*/
@RestController
@AllArgsConstructor
@RequestMapping("/wxtemplate")
@Api(value = "", tags = "接口")
public class WxTemplateController extends BladeController {
private IWxTemplateService wxTemplateService;
/**
* 详情
*/
@GetMapping("/detail")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "详情", notes = "传入wxTemplate")
public R<WxTemplateVO> detail(WxTemplate wxTemplate) {
WxTemplate detail = wxTemplateService.getOne(Condition.getQueryWrapper(wxTemplate));
return R.data(WxTemplateWrapper.build().entityVO(detail));
}
/**
* 分页
*/
@GetMapping("/list")
@ApiOperationSupport(order = 2)
@ApiOperation(value = "分页", notes = "传入wxTemplate")
public R<IPage<WxTemplateVO>> list(WxTemplate wxTemplate, Query query) {
IPage<WxTemplate> pages = wxTemplateService.page(Condition.getPage(query), Condition.getQueryWrapper(wxTemplate));
return R.data(WxTemplateWrapper.build().pageVO(pages));
}
/**
* 自定义分页
*/
@GetMapping("/page")
@ApiOperationSupport(order = 3)
@ApiOperation(value = "分页", notes = "传入wxTemplate")
public R<IPage<WxTemplateVO>> page(WxTemplateVO wxTemplate, Query query) {
IPage<WxTemplateVO> pages = wxTemplateService.selectWxTemplatePage(Condition.getPage(query), wxTemplate);
return R.data(pages);
}
/**
* 新增
*/
@PostMapping("/save")
@ApiOperationSupport(order = 4)
@ApiOperation(value = "新增", notes = "传入wxTemplate")
public R save(@Valid @RequestBody WxTemplate wxTemplate) {
return R.status(wxTemplateService.save(wxTemplate));
}
/**
* 修改
*/
@PostMapping("/update")
@ApiOperationSupport(order = 5)
@ApiOperation(value = "修改", notes = "传入wxTemplate")
public R update(@Valid @RequestBody WxTemplate wxTemplate) {
return R.status(wxTemplateService.updateById(wxTemplate));
}
/**
* 新增或修改
*/
@PostMapping("/submit")
@ApiOperationSupport(order = 6)
@ApiOperation(value = "新增或修改", notes = "传入wxTemplate")
public R submit(@Valid @RequestBody WxTemplate wxTemplate) {
return R.status(wxTemplateService.saveOrUpdate(wxTemplate));
}
/**
* 删除
*/
@PostMapping("/remove")
@ApiOperationSupport(order = 7)
@ApiOperation(value = "逻辑删除", notes = "传入ids")
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
return R.status(wxTemplateService.deleteLogic(Func.toLongList(ids)));
}
/**
* 添加模板
*
* @return
*/
@PostMapping("/addTem")
@ApiOperationSupport(order = 8)
@ApiOperation(value = "添加", notes = "传入wxTemplate")
public JSONObject addTem(@Valid @RequestBody WxTemplate wxTemplate) {
return wxTemplateService.addWxTemplate(wxTemplate);
}
/**
* 删除模板
*
* @return
*/
@PostMapping("/removeTem")
@ApiOperationSupport(order = 9)
@ApiOperation(value = "逻辑删除", notes = "传入id和模板id")
public JSONObject removeTem(@ApiParam(value = "主键集合", required = true) @RequestParam String id, @RequestParam String templateId) {
return wxTemplateService.delWxTemplate(id, templateId);
}
/**
* 获取小程序账号的类目
*
* @return
*/
@GetMapping("/getCategory")
@ApiOperationSupport(order = 10)
@ApiOperation(value = "查询类目")
public JSONObject getCategory() {
return wxTemplateService.getCategory();
}
/**
* 获取模板标题下的关键词列表
*
* @return
*/
@GetMapping("/getPubTemplateKeyWordsById")
@ApiOperationSupport(order = 11)
@ApiOperation(value = "获取模板标题下的关键词列表")
public JSONObject getPubTemplateKeyWordsById(@ApiParam(value = "关键词id", required = true) @RequestParam String tid) {
return wxTemplateService.getPubTemplateKeyWordsById(tid);
}
/**
* 获取帐号所属类目下的公共模板标题
*
* @return
*/
@GetMapping("/getPubTemplateTitleList")
@ApiOperationSupport(order = 12)
@ApiOperation(value = "获取帐号所属类目下的公共模板标题")
public JSONObject getPubTemplateTitleList(@ApiParam(value = "关键词集合", required = true) @RequestParam String ids, @RequestParam int start, @RequestParam int limit) {
return wxTemplateService.getPubTemplateTitleList(ids, start, limit);
}
/**
* 获取当前帐号下的个人模板列表
*
* @return
*/
@GetMapping("/getTemplateList")
@ApiOperationSupport(order = 13)
@ApiOperation(value = "获取帐号所属类目下的公共模板标题")
public JSONObject getTemplateList() {
return wxTemplateService.getTemplateList();
}
/**
* 获取当前帐号下的个人模板列表
*
* @return
*/
@GetMapping("/getTemplateListIdAndName")
@ApiOperationSupport(order = 14)
@ApiOperation(value = "获取帐号所属类目下的公共模板标题和ID")
public Map<String, String> getTemplateListIdAndName() {
return wxTemplateService.getTemplateId();
}
}
WxTemplateDataController.java
/**
* 控制器
*
* @author myn
* @since 2021-10-13
*/
@RestController
@AllArgsConstructor
@RequestMapping("/wxtemplatedata")
@Api(value = "", tags = "接口")
public class WxTemplateDataController extends BladeController {
private IWxTemplateDataService wxTemplateDataService;
/**
* 详情
*/
@GetMapping("/detail")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "详情", notes = "传入wxTemplateData")
public R<WxTemplateDataVO> detail(WxTemplateData wxTemplateData) {
WxTemplateData detail = wxTemplateDataService.getOne(Condition.getQueryWrapper(wxTemplateData));
return R.data(WxTemplateDataWrapper.build().entityVO(detail));
}
/**
* 分页
*/
@GetMapping("/list")
@ApiOperationSupport(order = 2)
@ApiOperation(value = "分页", notes = "传入wxTemplateData")
public R<IPage<WxTemplateDataVO>> list(WxTemplateData wxTemplateData, Query query) {
QueryWrapper<WxTemplateData> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("tenant", AESUtils.aesEncode(WxAppConfig.getAesKey(), WxAppConfig.getAppId()));
String a=AESUtils.aesEncode(WxAppConfig.getAesKey(), WxAppConfig.getAppId());
System.out.println(a);
IPage<WxTemplateData> pages = wxTemplateDataService.page(Condition.getPage(query), queryWrapper);
return R.data(WxTemplateDataWrapper.build().pageVO(pages));
}
/**
* 自定义分页
*/
@GetMapping("/page")
@ApiOperationSupport(order = 3)
@ApiOperation(value = "分页", notes = "传入wxTemplateData")
public R<IPage<WxTemplateDataVO>> page(WxTemplateDataVO wxTemplateData, Query query) {
IPage<WxTemplateDataVO> pages = wxTemplateDataService.selectWxTemplateDataPage(Condition.getPage(query), wxTemplateData);
return R.data(pages);
}
/**
* 新增
*/
@PostMapping("/save")
@ApiOperationSupport(order = 4)
@ApiOperation(value = "新增", notes = "传入wxTemplateData")
public R save(@Valid @RequestBody WxTemplateData wxTemplateData) {
return R.status(wxTemplateDataService.save(wxTemplateData));
}
/**
* 修改
*/
@PostMapping("/update")
@ApiOperationSupport(order = 5)
@ApiOperation(value = "修改", notes = "传入wxTemplateData")
public R update(@Valid @RequestBody WxTemplateData wxTemplateData) {
return R.status(wxTemplateDataService.updateById(wxTemplateData));
}
/**
* 新增或修改
*/
@PostMapping("/submit")
@ApiOperationSupport(order = 6)
@ApiOperation(value = "新增或修改", notes = "传入wxTemplateData")
public R submit(@Valid @RequestBody WxTemplateData wxTemplateData) {
return R.status(wxTemplateDataService.saveOrUpdate(wxTemplateData));
}
/**
* 删除
*/
@PostMapping("/remove")
@ApiOperationSupport(order = 7)
@ApiOperation(value = "逻辑删除", notes = "传入ids")
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
return R.status(wxTemplateDataService.deleteLogic(Func.toLongList(ids)));
}
/**
* 发送
*/
@PostMapping("/send")
@ApiOperationSupport(order = 8)
@ApiOperation(value = "发送", notes = "传入实体类")
public String send(@Valid @RequestBody WxTemplateData wxTemplateData) throws Exception {
return wxTemplateDataService.sendMsg(wxTemplateData);
}
/**
* 获取需要填写的关键字名称
* @return
*/
@GetMapping("/getKeyWords")
@ApiOperationSupport(order = 9)
@ApiOperation(value = "获取需要填写的关键字名称", notes = "传入模板id")
public Map<String, String> getKeyWords(@ApiParam(value = "模板id", required = true) @RequestParam String templateId) throws Exception {
return wxTemplateDataService.getDataList(templateId);
}
/**
* 租户测试
* @return
*/
@GetMapping("/getList")
@ApiOperationSupport(order = 10)
@ApiOperation(value = "租户测试")
public List<WxTemplateData> getList(){
return wxTemplateDataService.selectList();
}
/**
* 租户删除测试
* @return
*/
@GetMapping("/deleteByEntity")
@ApiOperationSupport(order = 10)
@ApiOperation(value = "租户测试")
public int deleteByEntity(String id){
return wxTemplateDataService.deleteByEntity(id);
}
}
微信模板的建立可以在微信公众后台手工创建,比调用API简单。