当前位置:首页 » 《随便一记》 » 正文

java实现微信公众号消息推送

4 人参与  2022年09月23日 11:06  分类 : 《随便一记》  评论

点击全文阅读


参考微信官方文档-发送模板消息

接口调用请求说明
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("审核异常!");    }}

点击全文阅读


本文链接:http://zhangshiyu.com/post/45046.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新文章

  • 完结文问越芙宁结局番外列表_完结文问越芙宁结局番外(沈问越苏芙宁)
  • 侯府断亲?重生嫡女惨虐全家!小说(沈清陆曜)+前传(侯府断亲?重生嫡女惨虐全家!)阅读
  • 热文推荐慕晚安陆晏霆霆爷家的小妖精又撩又飒小说大结局(霆爷家的小妖精又撩又飒)书荒必看列表
  • 岁月杳杳人不归高质量好文(裴烬野),岁月杳杳人不归高质量好文
  • 高分_等不到鬓雪相拥小说(容临渊云朝朝)(等不到鬓雪相拥)全本完整阅读
  • 等不到鬓雪相拥后续在线列表_等不到鬓雪相拥后续在线(云朝朝容临渊)
  • 完结文铁马冰河入梦来完结文列表_完结文铁马冰河入梦来完结文(陆知栩褚明策)
  • 睁眼大婚日,我踹了渣夫抱紧金大腿(云筝厉无恙)全书浏览_睁眼大婚日,我踹了渣夫抱紧金大腿全书浏览
  • (乱世伽黎)顾承煊余芊芊乱世伽黎后续一口气无广告全书章节表
  • 全书浏览重生后联姻丈夫爱上KTV小妹我死遁了后续免费(姜满裴聿琛温舒柠)_重生后联姻丈夫爱上KTV小妹我死遁了后续免费(姜满裴聿琛温舒柠)全书结局
  • 重生后联姻丈夫爱上KTV小妹我死遁了后续免费姜满裴聿琛温舒柠完本_重生后联姻丈夫爱上KTV小妹我死遁了后续免费(姜满裴聿琛温舒柠)
  • 高考前,我拒绝再为全班求护身符免费阅读_林薇薇年年大反击_小说后续在线阅读_无删减免费完结_

    关于我们 | 我要投稿 | 免责申明

    Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1