参考微信官方文档-发送模板消息
接口调用请求说明
http请求方式: POST
请求地址:https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
POST数据说明
POST数据示例如下:
参数说明
注:
(1)openId:微信用户在当前公众号的唯一标识,消息接收方
(2)template_id:
(3)url和miniprogram都是非必填字段,若都不传则模板无跳转;若都传,会优先跳转至小程序。开发者可根据实际需要选择其中一种跳转方式即可。当用户的微信客户端版本不支持跳小程序时,将会跳转至url。
返回码说明
在调用模板消息接口后,会返回JSON数据包。正常时的返回JSON数据包示例:
{
“errcode”:0,
“errmsg”:“ok”,
“msgid”:200228332
}
完整的代码:
/**aa
* 学长学姐审核通过接口
*/
@ApiOperation(value = “学长学姐【学长学姐-审核-审核通过】”)
@PostMapping(value = “ushOneUser”)
@Transactional(rollbackFor = {Exception.class})
public Result pushOneUser(@RequestBody ApprovedParameter approvedParameter) {
try {
//更新学长学姐信息
Date date = new Date();
BuffSeniorApprentice buffSeniorApprentice = new BuffSeniorApprentice();
buffSeniorApprentice.setId(approvedParameter.getSeniorApprenticeId());
buffSeniorApprentice.setAuditStatus(3);
buffSeniorApprentice.setAuditTime(date);
//往学长学姐审核信息表里插入数据 BuffSeniorApprenticeExamine buffSeniorApprenticeExamine = new BuffSeniorApprenticeExamine(); buffSeniorApprenticeExamine.setSeniorApprenticeId(approvedParameter.getSeniorApprenticeId()); buffSeniorApprenticeExamine.setAuditStatus(3); buffSeniorApprenticeExamine.setAuditTime(date); buffSeniorApprenticeExamine.setCtime(date); buffSeniorApprenticeExamineService.insertSelective(buffSeniorApprenticeExamine); // TODO 审核通过发送微信模板消息 BuffSeniorApprentice buffSeniorApprentice1 = buffSeniorApprenticeService.selectByPrimaryKey(approvedParameter.getSeniorApprenticeId()); if (!ObjectUtils.isEmpty(buffSeniorApprentice1.getIsPushMessage()) && buffSeniorApprentice1.getIsPushMessage() == 1) { String openId = userWxInfoMapper.findByUid(buffSeniorApprentice1.getUid()); WxMssTemplate.WxMssVo wxMssVo=new WxMssTemplate.WxMssVo(); wxMssVo.setToUser(openId); wxMssVo.setTemplate_id(businessConfig.getApproved); wxMssVo.setUrl(businessConfig.getApprovedUrl()); Date currentTime = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss"); String dateString = formatter.format(currentTime); Map<String,WxMssTemplate.WxMssData> map = new HashMap<String,WxMssTemplate.WxMssData>(); if (buffSeniorApprentice1.getIdentity() == 0) { map.put("first", new WxMssTemplate.WxMssData("学长您好,研控平台入驻审核已通过!")); } else if (buffSeniorApprentice1.getIdentity() == 1) { map.put("first", new WxMssTemplate.WxMssData("学姐您好,研控平台入驻审核已通过!")); } else { map.put("first", new WxMssTemplate.WxMssData("老师您好,研控平台入驻审核已通过!")); } map.put("keyword1", new WxMssTemplate.WxMssData("通过审核")); map.put("keyword2", new WxMssTemplate.WxMssData(dateString)); map.put("remark", new WxMssTemplate.WxMssData("点击进入查看")); wxMssVo.setData(map); } //获取access_token String access_token=new WxMssTemplate.getAccessToken(); String url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send" + "?access_token=" + access_token; ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, wxMssVo, String.class); return ok(responseEntity.getBody()); } catch(Exception e){ return errMsg("审核异常!"); }}