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

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

10 人参与  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://m.zhangshiyu.com/post/45046.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

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

最新文章

  • 相国独子的丫鬟砸坏我的玉佩后,我当场拒婚阅读_玉佩陈郡谢氏全新_小说后续在线阅读_无删减免费完结_
  • 手术时,我看着病人惨死最新试读_淼淼陆知衍姜颜全本完结_小说后续在线阅读_无删减免费完结_
  • 男友霸道给我开黑卡,转头却骂我是捞女最新章节_肖年顾客黑卡热文_小说后续在线阅读_无删减免费完结_
  • 他在回忆尽头全集_贺南舟许清梨叶絮完结txt_小说后续在线阅读_无删减免费完结_
  • 旅游结婚那天未婚夫另娶女秘书,我让他们一无所有连载_老公迎宾超长版_小说后续在线阅读_无删减免费完结_
  • 完结文异界修仙我的直播间能打赏核弹列表_完结文异界修仙我的直播间能打赏核弹(江流年沈红菱)
  • 全书浏览陪弟弟混骑行圈,离婚你哭什么?(韩星河柳千雪)_陪弟弟混骑行圈,离婚你哭什么?(韩星河柳千雪)全书结局
  • 老公出轨我助攻虐心反转_秦绍卿卿阿溪后续加长_小说后续在线阅读_无删减免费完结_
  • 替老婆坐牢出狱那天,我被送去斗兽场精校文本_许言沈宇郑子番茄热门_小说后续在线阅读_无删减免费完结_
  • 沐巍澜温溪:结局+番外(爱如一刹花火)电子书畅享阅读无广告
  • 傅凌川林柚续集(傅凌川林柚)章节前文+全书阅读(替嫁燃婚:小祖宗嘴硬腰软)最新连载
  • 资助生把导盲犬做成火锅后,我家杀疯了!列表_资助生把导盲犬做成火锅后,我家杀疯了!(陈米雪波波)

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

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