教你做一个美团外卖领券微信机器人

参考文章:
1、wx机器人运行在Linux服务器上?消息自动回复,Docker一键部署。详细安装使用。
2、wechatbot-webhook
拉取镜像
sudo docker pull dannicool/docker-wechatbot-webhook

运行镜像, 注意修改自定义token以及http://localhost:8080/receive_msg接收消息的接口
sudo docker run -d \
–name wxBotWebhook \
-p 3001:3001 \
-e LOGIN_API_TOKEN=”techshrimp” \
-e RECVD_MSG_API=”http://localhost:8080/receive_msg” \
dannicool/docker-wechatbot-webhook

处理接收消息的node

import express from 'express';
import multer from 'multer';
import axios from 'axios';
import cors from 'cors';

const app = express();
const port = '修改成自己的端口号';

// 设置 multer 处理 multipart/form-data
const storage = multer.memoryStorage();
const upload = multer({ storage: storage });

// 用于解析 application/json 和 application/x-www-form-urlencoded
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

app.post('/receive_msg', upload.any(), (req, res) => {
    // 获取 form-data 中的字段
    const type = req.body.type;
    const content = req.body.content;
    const source = req.body.source;
    const isMentioned = req.body.isMentioned;
    const isMsgFromSelf = req.body.isMsgFromSelf;

    // console.log('Type:', type);
    // console.log('Content:', content);
    // console.log('Source:', source);
    // console.log(source.to);
    // 使用JSON.parse()方法将字符串转换为JSON对象


    // console.log('Is Mentioned:', isMentioned);
    // console.log('Is Msg From Self:', isMsgFromSelf);

    // 如果有文件,获取文件信息
    // const files = req.files;
    // if (files && files.length > 0) {
    //     files.forEach(file => {
    //         console.log('File fieldname:', file.fieldname);
    //         console.log('File originalname:', file.originalname);
    //         console.log('File mimetype:', file.mimetype);
    //     });
    // }

    res.status(200).json({ message: 'Data received successfully' });
});

app.listen(port, () => {
    console.log(`Server is running on port ${port}`);
});

 

© 版权声明
THE END
喜欢就支持一下吧
点赞16赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容