chatrbot / wechaty-puppet-simplepad

Another implementation of Wechaty-Puppet
Apache License 2.0
33 stars 6 forks source link

在qrCode中输出的长度太长,导致生成的二维码错误,无法扫描登录 #6

Closed chenbb0128 closed 2 years ago

chenbb0128 commented 2 years ago

create bot

const bot = new Wechaty({
  puppet: new PuppetSimplePad({
    token: config.token
  }),
  name: config.robot_name
})

bot.on('scan', onScan)

// onScan 方法
const onScan = function (qrCode, status) {
  console.log(status)
  console.log(qrCode)
  if (status === ScanStatus.Waiting || status === ScanStatus.Timeout) {
    QrTerminal.generate(qrCode, { small: true });
    const qrCodeImageUrl = ['https://wechaty.js.org/qrcode/', encodeURIComponent(qrCode)].join('');
    log.info('StarterBot', 'onScan: %s(%s) - %s', ScanStatus[status], status, qrCodeImageUrl);
  } else {
    log.info('StarterBot', 'onScan: %s(%s)', ScanStatus[status], status);
  }
}

在qrCode中输出的长度太长,导致生成的二维码错误,无法扫描登录

(node:21216) UnhandledPromiseRejectionWarning: Error: code length overflow. (519444>23648)
    at Function.QRCode.createData (D:\work\html\wechat-robot\node_modules\qrcode-terminal\vendor\QRCode\index.js:363:9)
    at QRCode.makeImpl (D:\work\html\wechat-robot\node_modules\qrcode-terminal\vendor\QRCode\index.js:106:28)
    at QRCode.getBestMaskPattern (D:\work\html\wechat-robot\node_modules\qrcode-terminal\vendor\QRCode\index.js:140:9)
    at QRCode.make (D:\work\html\wechat-robot\node_modules\qrcode-terminal\vendor\QRCode\index.js:77:29)
    at Object.generate (D:\work\html\wechat-robot\node_modules\qrcode-terminal\lib\main.js:35:16)
    at Wechaty.onScan (D:\work\html\wechat-robot\src\listeners\onScan.js:8:16)
    at Wechaty.emit (events.js:315:20)
    at Wechaty.EventEmitter.emit (domain.js:482:12)
    at PuppetSimplePad.<anonymous> (D:\work\html\wechat-robot\node_modules\wechaty\dist\src\wechaty.js:416:30)
    at PuppetSimplePad.emit (events.js:315:20)
    at PuppetSimplePad.EventEmitter.emit (domain.js:482:12)
    at D:\work\html\wechat-robot\node_modules\wechaty-puppet-simplepad\dist\puppet-simplepad.js:76:18
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:21216) 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(). To t
erminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(

version

"wechaty-puppet-simplepad": "^0.2.1",
"wechaty": "^0.62.3",
node  v12.18.2
chatrbot commented 2 years ago

这边的QrCode机制和其他Puppet的有所不同,从服务端返回的是原始图片的完整二进制,如果需要在终端输出,需要做一次"转化"

const fileBox = FileBox.fromBase64(qrcode,'qrcode')
const qrCodeValue = await fileBox.toQRCode()
QrcodeTerminal.generate(qrCodeValue, { small: true })

详细可以参考demo/bot.ts