zoukankan      html  css  js  c++  java
  • node.js结合wechaty实现微信机器人[基础篇]


    此处展示为最基础的示例版本

    安装

    // 链接转化二维码控制台输出
    cnpm i qrcode-terminal -D
    
    // wechaty核心包
    cnpm i wechaty -D
    
    // ipad协议包 按个人不同的token切换不同协议
    cnpm i wechaty-puppet-padlocal -D
    
    
    const { Wechaty } = require("wechaty");
    const { PuppetPadlocal } = require("wechaty-puppet-padlocal");
    const  QrcodeTerminal  = require("qrcode-terminal");
    const bot = new Wechaty({
      puppet: new PuppetPadlocal({
        token: "puppet_padlocal_token",  // 填写自己的token
      }),
    });
    
    bot
      // 扫码登录
      .on("scan", (qrcode, status) => {
        console.log(`Scan QR Code to login: ${status}
    https://api.qrserver.com/v1/create-qr-code/?data=${encodeURIComponent(qrcode)}`);
        QrcodeTerminal.generate(qrcode);
      })
      // 登录监听
      .on("login", (user) => {
        console.log(user, "logined");
      })
      // 退出监听
      .on("logout", (user) => {
        console.log(user, "logout");
      })
      // 消息监听
      .on("message", (message) => {
        console.log(message);
      })
      .start();
    
    
    愿以往所学皆有所获
  • 相关阅读:
    172. Factorial Trailing Zeroes
    96. Unique Binary Search Trees
    95. Unique Binary Search Trees II
    91. Decode Ways
    LeetCode 328 奇偶链表
    LeetCode 72 编辑距离
    LeetCode 226 翻转二叉树
    LeetCode 79单词搜索
    LeetCode 198 打家劫舍
    LeetCode 504 七进制数
  • 原文地址:https://www.cnblogs.com/Azune/p/14653819.html
Copyright © 2011-2022 走看看