当前位置:网站首页>[project training] wechat official account template message push
[project training] wechat official account template message push
2022-06-12 01:15:00 【par_ ser】
First , You need to get a template first
If it is not the test number , Then you need to apply ; If it is a test number , Simply add a test template on the test number management page .

Introduce dependencies
To simplify development , We introduce a third-party wechat development kit
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-mp</artifactId>
<version>3.3.0</version>
</dependency>Code
Put the parameters in application In profile
@Value("${wx.appid}")
private String appid;
@Value("${wx.secret}")
private String secret;
@Value("${wx.templateId}")
private String templateId; public void pushMessage(AlarmParamsDTO alarmParamsDTO) {
//1, To configure
WxMpInMemoryConfigStorage wxStorage = new WxMpInMemoryConfigStorage();
wxStorage.setAppId(appid);
wxStorage.setSecret(secret);
WxMpService wxMpService = new WxMpServiceImpl();
wxMpService.setWxMpConfigStorage(wxStorage);
List<WxMpTemplateData> wxMpTemplateData = Arrays.asList(
new WxMpTemplateData("first",alarmParamsDTO.getFirst(),"#000000"),
new WxMpTemplateData("keyword1",alarmParamsDTO.getKeyword1(),"#0000FF"),
new WxMpTemplateData("keyword2",alarmParamsDTO.getKeyword2(),"#0000FF"),
new WxMpTemplateData("keyword3",alarmParamsDTO.getKeyword3(),"#0000FF"),
new WxMpTemplateData("keyword4",alarmParamsDTO.getKeyword4(),"#0000FF"),
new WxMpTemplateData("keyword5",alarmParamsDTO.getKeyword5(),"#0000FF"),
new WxMpTemplateData("remark",alarmParamsDTO.getRemark(),"#00FF00")
);
//2, Push message
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
.toUser(alarmParamsDTO.getOpenId())
.templateId(templateId)
.data(wxMpTemplateData)
.build();
try {
wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
} catch (Exception e) {
System.out.println(" Push failed :" + e.getMessage());
}
}边栏推荐
- Defect detection, introduction to Halcon case.
- A summary of the interface automation test problems most easily encountered
- In the field of enabling finance, the transformation of state secrets makes security compliance more solid
- jmeter 性能测试用 csv,这个坑有些扯蛋
- C language bit operation - learning 26
- 语义向量检索入门教程
- LabVIEW Arduino electronic weighing system (project Part-1)
- Recursive and non recursive transformation
- Verification code is the natural enemy of automation? Let's see how Ali P7 solved it
- Streaming data warehouse storage: requirements and architecture
猜你喜欢

Kill session? This cross domain authentication solution is really elegant

VM tools fail in VMware? Install VM tools using Ali image source

中创专利|中国5G标准必要专利达1.8万项,尊重知识产权,共建知识产权强国

How to guarantee industrial control safety: system reinforcement

Crawler case 05 - parsing websites using XPath

Building circuits on glass

Codemirror 2 - highlight only (no editor) - codemirror 2 - highlight only (no editor)

Recurrent+Transformer 视频恢复领域的‘德艺双馨’

Argodb 3.2 of star ring technology was officially released to comprehensively upgrade ease of use, performance and security

Zhongchuang patents | China has 18000 necessary patents for 5g standards, respects intellectual property rights and jointly builds a strong intellectual property country
随机推荐
一文get,最容易碰上的接口自动化测试问题汇总
Weekly CTF 第一周:神奇的磁带
出门带着小溪
Recurrent+Transformer 视频恢复领域的‘德艺双馨’
Vscode - the problem of saving a file and automatically formatting the single quotation mark 'into a double quotation mark'
手写MapReduce程序详细操作步骤
网狐游戏服务器-房间配置向导-组件属性与基本配置赋值
flowable 工作流
MATLAB basic application 02 wind stock data introduction and use case:
Streaming data warehouse storage: requirements and architecture
About MySQL password modification failure
我在某大厂做软件测试工程师的《一天完整工作流程》
市场监管总局、国家网信办:开展数据安全管理认证工作
C language pointer and array - learning 23
The CSV used for JMeter performance test is bullshit
Industry competition analysis and investment scale research report of global and Chinese micro potato industry 2022-2028
Nat. Comm. | 超算+AI: 为天然产物生物合成路线规划提供导航
Lambda中间操作limit
Defect detection, introduction to Halcon case.
Esp8266wifi development board collects temperature and humidity data and uploads them to the Internet of things platform