已收到二维码<some code>。如何使用此代码连接到 Whatsapp 网络? Whatsapp-web.js

问题描述 投票:0回答:3

当我运行我的代码时,控制台中会出现垃圾邮件。

Module - whatsapp-web.js

代码

const { Client } = require('whatsapp-web.js');
const client = new Client();

client.on('qr', (qr) => {
    // Generate and scan this code with your phone
    console.log('QR RECEIVED', qr);
});



client.on('message', async(msg) => {
    const mentions = await msg.getMentions();

    for (let contact of mentions) {
        console.log(`${contact.pushname} was mentioned`);
    }
});

client.initialize();

如何使用此模块连接到whatsapp网络?

控制台

QR received 
1@wCO3HYi6B1wat+cAyHe3+tlzfbjiWNxCTP30fEY16YNgmaBuknL/bBDpMNzA2SgfFPfCgQ==,yycd40PiAgEvrk961s+wiBLoMlsFb/eqVpRTN9Ec3FE=,E37yNJ5fmhoX3G/A==

类似上面的内容出现在控制台中。

javascript qr-code whatsapp
3个回答
1
投票

这应该可以解决问题

$ npm i qrcode-terminal

然后

const qrcode = require('qrcode-terminal');

const { Client } = require('whatsapp-web.js');
const client = new Client();

client.on('qr', qr => {
qrcode.generate(qr, {small: true});
});

client.on('ready', () => {
console.log('Client is ready!');
});

client.initialize();

0
投票

client.on('准备好', () => { console.log('客户端已准备好!');

登录后代码不起作用,扫描二维码后没有任何反应


-1
投票

运行代码后按照上面的答案,一些二维码图像将在您的控制台上生成。接下来,您转到您的 Whatsapp,从右上角的三个点图标下选择“链接的设备”。这里您应该扫描控制台生成的二维码图像。现在它已准备好发送和接收消息

© www.soinside.com 2019 - 2024. All rights reserved.