wechaty/wechaty-puppet-padchat

login failed and got -106 status

Closed this issue · 5 comments

after scan the login qrcode, login failed and got Error: PadchatRpc, WXQRCodeLogin, unknown status: -106

11:20:10 INFO Wechaty <Puppet#0<PuppetPadchat>()/PuppetPadchat#0> start() v0.21.10 is starting...
11:20:10 WARN PuppetPadchatManager startCheckScan() unknown WXCheckQRCodeStatus: -2
http://weixin.qq.com/x/wcLtEnZ0CaO4xD6bvHUU
[0] https://api.qrserver.com/v1/create-qr-code/?data=http%3A%2F%2Fweixin.qq.com%2Fx%2FwcLtEnZ0CaO4xD6bvHUU
Scan QR Code above to log in:
http://weixin.qq.com/x/wcLtEnZ0CaO4xD6bvHUU
[1] https://api.qrserver.com/v1/create-qr-code/?data=http%3A%2F%2Fweixin.qq.com%2Fx%2FwcLtEnZ0CaO4xD6bvHUU
Scan QR Code above to log in:
http://weixin.qq.com/x/wcLtEnZ0CaO4xD6bvHUU
[2] https://api.qrserver.com/v1/create-qr-code/?data=http%3A%2F%2Fweixin.qq.com%2Fx%2FwcLtEnZ0CaO4xD6bvHUU
Scan QR Code above to log in:
(node:27) UnhandledPromiseRejectionWarning: Error: PadchatRpc, WXQRCodeLogin, unknown status: -106
    at PadchatManager.<anonymous> (/bot/node_modules/wechaty-puppet-padchat/src/padchat-rpc.ts:1051:11)
    at Generator.next (<anonymous>)
    at fulfilled (/bot/node_modules/wechaty-puppet-padchat/dist/src/padchat-rpc.js:4:58)
(node:27) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:27) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

This may refer to wechat new security check p, but Padchat is solving this issue now

这个问题什么时候可以解决呢?

@kis87988 I clone the "wechaty-getting-started", and change the initial code of Wechaty to use padchat. I install the “puppet-padchat-patch” with "npm install". Then i run "npm start". When I scan the qrcode first time, I got the Infos below in the console. However when I scan the new qrcode, there is nothing in the console while my phone shows that ipad wechat has logined.

Or what should I do in padchatPatch.on('finish',function(){}).

the version of My wechaty-puppet-padchat is v0.17.15, Wechaty is v0.22.4.

 INFO PadchatPatch start() with token: myToken, name: test, wxid: -106
[undefined] https://api.qrserver.com/v1/create-qr-code/?data=http%3A%2F%2Fweixin.qq.com%2Fx%2FYZKr7op0DA0LPG1VSXq3
Scan QR Code above to log in:

There are my codes:

const { Wechaty } = require('wechaty')
const { PadchatPatch } = require('puppet-padchat-patch')

const TOKEN = 'myToken'; // the token I applied
const initialName = 'test';

const puppet = 'wechaty-puppet-padchat'
const puppetOptions = {
    token: TOKEN
}

const bot = new Wechaty({
    initialName,
    puppet,
    puppetOptions,
});
bot.on('scan',    onScan)
bot.on('login',   onLogin)
bot.on('logout',  onLogout)
bot.on('message', onMessage)
bot.start()
.then(() => console.log('Starter Bot Started.'))
.catch(e => console.error(e))

function onScan (qrcode, status) {
  const qrcodeImageUrl = [
    'https://api.qrserver.com/v1/create-qr-code/?data=',
    encodeURIComponent(qrcode),
  ].join('')
  console.log(qrcodeImageUrl)
}

function onLogin (user) {
  console.log(`${user} login`)
}

function onLogout(user) {
  console.log(`${user} logout`)
}

async function onMessage (msg) {
  console.log(msg.toString())
}

/**
 * Hook the -106 failure status here, try to get auth data from separate server
 */
process.on('unhandledRejection', (error) => {
    const { message } = error
    if (message && message.indexOf('unknown status: -106') !== -1) {
        const wxid = message.split(' ').slice(-1)[0]
        const padchatPatch = new PadchatPatch(TOKEN, initialName, wxid)
        padchatPatch
            .on('scan', (qrcode, status) => {
                // You need to let the user scan the qrcode again here
                // generate(qrcode, { small: true })
                const qrcodeImageUrl = [
                    'https://api.qrserver.com/v1/create-qr-code/?data=',
                    encodeURIComponent(qrcode),
                ].join('')
                console.log(`[${status}] ${qrcodeImageUrl}\nScan QR Code above to log in: `)
            })
            .on('finish', async () => {
                // restart your application here
                bot.start()
            })
            .start()
        return
    }
})

This issue has been fixed, please update the latest code and have a try.