当前位置:网站首页>Automatic reply of wechat official account development message
Automatic reply of wechat official account development message
2022-07-25 16:36:00 【youhebuke225】
List of articles
Please refer to Click on
- Because we need to reply to different types of messages , Here we are
wechatUnder the folder , Create a new onereply.js, It is specially used for automatic reply of messages reply.jsExpose a function , This function takes a parametermessage, Is the message we need to send , Function returns the corresponding template , And send it to wechat server
Code
Code
const template = require('./template');
module.exports = async message => {
// Definition options
let options = {
toUserName: message.FromUserName,
fromUserName: message.ToUserName,
createTime: Date.now(),
msgType: 'text'
}
// Set the specific content of the reply to the user message
let content = '';
// Determine the type and content of messages sent by users , Decide what message to return to the user
if (message.MsgType === 'text') {
if (message.Content === '1') {
content = ' prosperous , Tonight to eat chicken '
} else if (message.Content === '2') {
content = ' Land in a box '
} else if (message.Content === '3') {
// Reply to text message
content = [
{
title: 'Nodejs Development ',
description: ' WeChat official account development ',
picUrl: 'https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=1841004364,244945169&fm=58&bpow=121&bpoh=75',
url: 'http://nodejs.cn/'
}, {
title: 'web front end ',
description: ' Here's the latest 、 The strongest technology ',
picUrl: 'https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=1981851186,10620031&fm=58&s=6183FE1ECDA569015C69A554030010F3&bpow=121&bpoh=75',
url: 'http://www.atguigu.com/'
}];
options.msgType = 'news'
} else if (message.Content.match(' Love ')) {
// Fuzzy matching , As long as it contains love
content = ' I love you! ~'
} else {
content = ' What are you talking about , I cannot understand '
}
} else if (message.MsgType === 'image') {
content = ' Your picture address is :' + message.PicUrl
} else if (message.MsgType === 'voice') {
content = ' Speech recognition results :' + message.Recognition
} else if (message.MsgType === 'video') {
content = ' Received the video message '
} else if (message.MsgType === 'shortvideo') {
content = ' Received a small video message '
} else if (message.MsgType === 'location') {
content = ' latitude :' + message.Location_X + ' longitude :' + message.Location_Y + ' Zoom size :' + message.Scale + ' details :' + message.Label
} else if (message.MsgType === 'link') {
content = ' title :' + message.Title + ' describe :' + message.Description + ' website :' + message.Url
} else if (message.MsgType === 'event') {
if (message.Event === 'subscribe') {
// Users subscribe to events
content = ' Welcome to subscribe ~';
if (message.EventKey) {
// Scan subscription events with QR code parameters
content = ' Welcome to scan QR code '
}
} else if (message.Event === 'SCAN') {
// Have followed official account , Enter the official account with parameter QR code in the scanning zone
content = ' Have followed official account , Enter the official account with parameter QR code in the scanning zone '
} else if (message.Event === 'unsubscribe') {
// User unfocused
console.log(' Ruthless clearance ~')
} else if (message.Event === 'LOCATION') {
// When the user is in a session , Report the geographic location information once
content = ' latitude :' + message.Latitude + ' longitude :' + message.Longitude + ' precision :' + message.Precision
} else if (message.Event === 'CLICK') {
content = ' Click on the menu ~~~'
} else if (message.Event === 'VIEW') {
// User click menu , Jump to other links
console.log(' User click menu , Jump to other links ')
}
}
// Add the final reply message content to options in
options.content = content;
// Will eventually xml Data is returned
return template(options)
}
The interpretation of the code
- Here we use the imported template
template, Click on
- Defined
optionsVariable , This variable is the common content of all kinds of reply messages - Different content , use if Judgment statement to judge
- It's a function , Different templates will be returned according to different types of messages
Message template of the event
- Because it triggers Message template of event reply It is similar to the message template of automatic reply , I wrote it together
Use recovery function
So this is using
reply.jsExposed functions
Let's punch in auth.js This file , Delete unwanted structure , Write the following code
user_data = formatMsg(user_data)
// Use reply.js
const replyMessage = await reply(user_data)
console.log(replyMessage)
// Send the message structure to the wechat server
res.send(replyMessage)
This is the time , Let's test it again , You will find , succeed 
边栏推荐
- 终极套娃 2.0 | 云原生交付的封装
- Which led display manufacturer is better
- IAAs infrastructure cloud cloud network
- SAP Fiori 的附件处理(Attachment handling)
- 链游开发现成版 链游系统开发详细原理 链游源码交付
- MySQL pessimistic lock
- 【图像隐藏】基于混合 DWT-HD-SVD 的数字图像水印方法技术附matlab代码
- Quickly deploy mqtt clusters on AWS using terraform
- The annualized interest rate of treasury bonds is too low. Is there a financial product with a higher annualized interest rate than the reverse repurchase of treasury bonds?
- Sum arrays with recursion
猜你喜欢

论文笔记:Highly accurate protein structure prediction with AlphaFold (AlphaFold 2 & appendix)

MyBaits

Who moved my memory and revealed the secret of 90% reduction in oom crash

Win11动态磁贴没了?Win11中恢复动态磁贴的方法

柏睿数据加入阿里云PolarDB开源数据库社区

fastadmin tp 安装使用百度富文本编辑器UEditor

Paper notes: highly accurate protein structure prediction with alphafold (alphafold 2 & appendix)

2D semantic segmentation -- deeplabv3plus reproduction
![[image denoising] image denoising based on bicube interpolation and sparse representation matlab source code](/img/39/716c62d6ca533a7e84704b2c55d072.png)
[image denoising] image denoising based on bicube interpolation and sparse representation matlab source code

微信公众号开发之消息的自动回复
随机推荐
What is chain game system development? How to make chain game system development
Permission management - role assignment menu
7. Dependency injection
国债年化利率太低了,有比国债逆回购年化利率还要高的理财产品吗?
How to build an enterprise level OLAP data engine for massive data and high real-time requirements?
百度富文本编辑器UEditor单张图片上传跨域
Talk about how to use redis to realize distributed locks?
激荡20年,芯片产能从零起步到反超美国,中国制造的又一大成就
Test framework unittest skip test
Rebudget汇报PPT
复旦大学EMBA同学同行专题:始终将消费者的价值放在最重要的位置
MySQL pessimistic lock
进程之间的通信(管道详解)
Understanding service governance in distributed development
doGet与doPost
0x80131500打不开微软商店的解决办法
C Music
首页门户分类查询
Leetcode:6127. Number of high-quality number pairs [bit operation finding rules + the sum of two numbers is greater than or equal to K + dichotomy]
免费的低代码开发平台有哪些?