# 本節知識點
- 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)老師拉你進學習群。