我正在使用whatsapp-web.js库,我希望在重新启动脚本后继续登录。目前,我必须扫描QR代码,每次我开始。我在网上发现的东西无法工作(可能是因为我很笨,但仍然如此)。作为参考,这是我试图让它使用的代码。
const { Client, LocalAuth, MessageMedia } = require('whatsapp-web.js');
const fs = require('fs');
const client = new Client({
ffmpegPath: "C:/ffmpeg/bin/ffmpeg.exe"
});
client.on('qr', async qr=> {
qrcode.generate(qr, {small: true});
});
client.on('ready', async function () {
console.log('Client is ready!');
});
提前谢谢。
发布于 2022-07-12 23:02:32
我修好了。对于任何看到这一点并有相同问题的人,这就是对我起作用的地方:将其添加到客户端:authStrategy: new LocalAuth()
,并在第一次生成qr代码之后,在进入ctrl+c之前等待几分钟。
发布于 2022-08-28 05:44:22
在最近的版本中,您必须手动实现LocalAuth
。
为此,请打开位于"./node_modules/whatssap-web.js/src/Client.js“的"Client.js”文件并实现这一行
const LocalAuth = require('./authStrategies/LocalAuth');
现在更改第68行
this.authStrategy = new NoAuth();
至
this.authStrategy = new LocalAuth();
版本1.16.4-字母0
日期: 27/08/2022
发布于 2022-10-10 21:44:08
const fs = require('fs');
const { Client, LegacySessionAuth } = require('whatsapp-web.js');
// Path where the session data will be stored
const SESSION_FILE_PATH = './session.json';
// Load the session data if it has been previously saved
let sessionData;
if(fs.existsSync(SESSION_FILE_PATH)) {
sessionData = require(SESSION_FILE_PATH);
}
// Use the saved values
const client = new Client({
authStrategy: new LegacySessionAuth({
session: sessionData
})
});
// Save session values to the file upon successful auth
client.on('authenticated', (session) => {
sessionData = session;
fs.writeFile(SESSION_FILE_PATH, JSON.stringify(session), (err) => {
if (err) {
console.error(err);
}
});
});
https://stackoverflow.com/questions/72945071
复制相似问题