Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]WorkPro: 验证码实例代码跑不通,还是获取不到验证码,没法登陆 #351

Closed
ahujack opened this issue Jan 8, 2024 · 3 comments
Assignees
Labels
workpro Wechaty Puppet Service WorkPro

Comments

@ahujack
Copy link

ahujack commented Jan 8, 2024

下面这个实例代码有两个问题:
1、getQrcodeKey这个方法找不到,应该怎么import
2、我这个verifyCode怎么获取?如果我扫码获取到了,我需要关掉再重新启动,那个时候的验证码已经换了啊。

bot.on('scan', (qrcode, status, data) => {
console.log(============================================================ qrcode : ${qrcode}, status: ${status}, data: ${data} ============================================================)
if (status === ScanStatus.Waiting) {
store.qrcodeKey= getQrcodeKey(qrcode) || ''
QrcodeTerminal.generate(qrcode, {
small: true
})
}
}).on('verify-code', async (id: string, message: string, scene: types.VerifyCodeScene, status: types.VerifyCodeStatus) => {
// 需要注意的是,验证码事件不是完全即时的,可能有最多10秒的延迟。
// 这与底层轮询二维码状态的时间间隔有关。
if (status === types.VerifyCodeStatus.WAITING && scene === types.VerifyCodeScene.LOGIN && id === store.qrcodeKey) {
console.log(receive verify-code event, id: ${id}, message: ${message}, scene: ${types.VerifyCodeScene[scene]} status: ${types.VerifyCodeStatus[status]})
const verifyCode = '084356' // 通过一些途径输入验证码
try {
await bot.enterVerifyCode(id, verifyCode) // 如果没抛错,则说明输入成功,会推送登录事件
return
} catch (e) {
console.log((e as Error).message)
// 如果抛错,请根据 message 处理,目前发现可以输错3次,超过3次错误需要重新扫码。
// 错误关键词: 验证码错误输入错误,请重新输入
// 错误关键词:验证码错误次数超过阈值,请重新扫码'
// 目前不会推送 EXPIRED 事件,需要根据错误内容判断
}
}
}).on('login', user => {
console.log(============================================ user: ${JSON.stringify(user)}, friend: ${user.friend()}, ${user.coworker()} ============================================)
}).on('message', message => {
console.log(new message received: ${JSON.stringify(message)})
}).on('error', err => {
console.log(err)
}).on('room-announce', (...args) => {
console.log(room announce: ${JSON.stringify(args)})
}).on('contact-alias', (...args) => {
console.log(contact alias: ${JSON.stringify(args)})
}).on('tag', (...args) => {
console.log(tag: ${JSON.stringify(args)})
})

@ahujack ahujack added the workpro Wechaty Puppet Service WorkPro label Jan 8, 2024
@ahujack ahujack changed the title [BUG]WorkPro: [BUG]WorkPro: 验证码实例代码跑不通,还是获取不到验证码,没法登陆 Jan 8, 2024
@su-chang
Copy link
Member

su-chang commented Jan 8, 2024

@ahujack 参考 #267

@ahujack
Copy link
Author

ahujack commented Jan 9, 2024

@ahujack 参考 #267

就是参考的这个示例,不行

@su-chang
Copy link
Member

su-chang commented Jan 9, 2024

@ahujack
需要自行通过实现将手机端获取到验证码,通过api等形式传递给你的服务,并且通过监听 'verify-code' 事件,将获取到的验证码调用 enterVerifyCode 方法传递。

@hcfw007 hcfw007 closed this as completed Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
workpro Wechaty Puppet Service WorkPro
Projects
None yet
Development

No branches or pull requests

3 participants