企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 本节知识点 - 1,注册微信公号测试账号 - 2,获取测试账号的用户openid - 3,接入微信推送sdk - 4,实现微信推送 # 课程中用到的网址和文件 - 1,微信官方注册测试账号:[https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login](https://links.jianshu.com/go?to=https%3A%2F%2Fmp.weixin.qq.com%2Fdebug%2Fcgi-bin%2Fsandbox%3Ft%3Dsandbox%2Flogin) # 配套笔记 [5行代码实现微信模版消息推送](https://www.jianshu.com/p/bc5f80818934) # 视频地址 在线视频:[https://edu.csdn.net/course/detail/23750](https://edu.csdn.net/course/detail/23750) 网盘视频:加老师微信索要视频资源。 最好跟着老师的教程敲代码,如果实在敲不出来,再加老师微信索要源码。 # 核心代码 - 1 三方类库 ``` <!--微信模版消息推送三方sdk--> <dependency> <groupId>com.github.binarywang</groupId> <artifactId>weixin-java-mp</artifactId> <version>3.3.0</version> </dependency> ``` - 2 推送的核心类 ``` public String push() { //1,配置 WxMpInMemoryConfigStorage wxStorage = new WxMpInMemoryConfigStorage(); wxStorage.setAppId("wx77bb69292323a000");//appid wxStorage.setSecret("29bd368145806115ad6820133e62806e");//appsecret WxMpService wxMpService = new WxMpServiceImpl(); wxMpService.setWxMpConfigStorage(wxStorage); //2,推送消息 WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder() .toUser("o5kho6DgC7SDry8zCmXuvHJGvrgI")//要推送的用户openid .templateId("Tpln-Eue2obJ0B-8JNkgkiRJaDMPgVeIgGxna982xrg")//模版id .url("https://30paotui.com/")//点击模版消息要访问的网址 .build(); //3,发起推送 try { String msg = wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage); System.out.println("推送成功:" + msg); return "推送成功:" + msg; } catch (Exception e) { System.out.println("推送失败:" + e.getMessage()); e.printStackTrace(); } return "推送失败"; } ``` # 老师微信 2501902696(备注小程序) # 学习群 学习群请加老师微信2501902696(备注java)老师拉你进学习群。