💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 本节知识点 - 1,springboot创建小程序推送后台 - 2,微信小程序开发的学习 - 3,获取推送需要的formid - 4,实现微信小程序推送功能 # 课程中用到的网址和文件 - 1,小程序学习视频:[https://edu.csdn.net/course/detail/9531](https://edu.csdn.net/course/detail/9531) - 2,小程序云开发获取用户openid: [https://edu.csdn.net/course/play/9604/204529](https://edu.csdn.net/course/play/9604/204529) - 3,微信小程序官方推送文档: [https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/template-message.html](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/template-message.html) # 配套笔记 - 5行代码实现微信小程序模版消息推送 (含推送后台和小程序源码) [https://www.jianshu.com/p/35da86f309d4](https://www.jianshu.com/p/35da86f309d4) # 视频地址 在线视频:[https://edu.csdn.net/course/detail/23750](https://edu.csdn.net/course/detail/23750) 网盘视频:加老师微信索要视频资源。 最好跟着老师的教程敲代码,如果实在敲不出来,再加老师微信索要源码。 # 推送验证 http://localhost:8080/push?openid=o3DoL0WEdzcJ20AVJg1crP96gbjM&formid=00869c94008b43379e52658997d887e9 注意:这里一定要替换成你自己的openid,和formid。否则没法推送成功的 # 核心代码 - 1 三方类库 ``` <!--微信小程序模版推送--> <dependency> <groupId>com.github.binarywang</groupId> <artifactId>weixin-java-miniapp</artifactId> <version>3.4.0</version> </dependency> ``` - 2 推送的核心类 ``` /** * Created by qcl on 2019-05-20 * 微信:2501902696 * desc: 微信小程序模版推送实现 */ @RestController public class PushController { @GetMapping("/push") public String push(@RequestParam String openid, @RequestParam String formid) { //1,配置小程序信息 WxMaInMemoryConfig wxConfig = new WxMaInMemoryConfig(); wxConfig.setAppid("wx7c54942dfc87f4d8");//小程序appid wxConfig.setSecret("5873a729c365b65ab42bb5fc82d2ed49");//小程序AppSecret WxMaService wxMaService = new WxMaServiceImpl(); wxMaService.setWxMaConfig(wxConfig); //2,设置模版信息(keyword1:类型,keyword2:内容) List<WxMaTemplateData> templateDataList = new ArrayList<>(2); WxMaTemplateData data1 = new WxMaTemplateData("keyword1", "获取老师微信"); WxMaTemplateData data2 = new WxMaTemplateData("keyword2", "2501902696"); templateDataList.add(data1); templateDataList.add(data2); //3,设置推送消息 WxMaTemplateMessage templateMessage = WxMaTemplateMessage.builder() .toUser(openid)//要推送的用户openid .formId(formid)//收集到的formid .templateId("eDZCu__qIz64Xx19dAoKg0Taf5AAoDmhUHprF6CAd4A")//推送的模版id(在小程序后台设置) .data(templateDataList)//模版信息 .page("pages/index/index")//要跳转到小程序那个页面 .build(); //4,发起推送 try { wxMaService.getMsgService().sendTemplateMsg(templateMessage); } catch (WxErrorException e) { System.out.println("推送失败:" + e.getMessage()); return e.getMessage(); } return "推送成功"; } } ``` - 3,小程序获取formid的核心布局 ``` <form class="form_item" bindsubmit='gorRunnerLobby' report-submit='true' data-type="1"> <button class="button" form-type='submit'> 获取formid </button> </form> ``` - 4,小程序获取formid的核心js代码 ``` //获取用户的formid,用于模版消息推送 gorRunnerLobby(event) { console.log("formid: " + event.detail.formId); this.setData({ formid: event.detail.formId }) }, ``` # 老师微信 2501902696(备注小程序) # 学习群 学习群请加老师微信2501902696(备注java)老师拉你进学习群。