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

乱码 #1656

Closed
crdsoft opened this issue Nov 25, 2018 · 14 comments
Closed

乱码 #1656

crdsoft opened this issue Nov 25, 2018 · 14 comments

Comments

@crdsoft
Copy link

crdsoft commented Nov 25, 2018

async function onMessage (msg) {
console.log(msg.toString())
let msgText = msg.text()
if (msgText.indexOf("vip") > -1) {
respText = "想成为VIP?"
await msg.say(respText)
}
}

微信端收到乱码:
���ΪVIP��

怎么解决?

@crdsoft
Copy link
Author

crdsoft commented Nov 25, 2018

@lijiarui 帮忙看看呗

@lijiarui
Copy link
Member

Need More Information

I suggest you not follow the ISSUE Template, this issue doesn't have enough information about your problem.

In order to help us to find the problem out, you should provide all the detail information about the issue. Please make sure you are following the ISSUE Template, answer all the question, and the more important: provide the steps to reproduce the problem.

@crdsoft
Copy link
Author

crdsoft commented Nov 25, 2018

需要什么信息?我发你。

@lijiarui
Copy link
Member

Please follow the ISSUE Template

0. Report Issue Guide

  1. Please search in the issue first, and make sure your problem had not been reported before.
  2. If your issue is related to wechaty-puppet-padchat, please report the issue at https://github.com/lijiarui/wechaty-puppet-padchat/issues/new
  3. If your issue is related to wechaty-puppet-puppeteer, please report the issue at https://github.com/Chatie/wechaty-puppet-puppeteer/issues/new
  4. If your issue is DIRECT related to Wechaty, then please follow the below template and make sure you fill it as required in detail.

1. Expected behavior

Question: What behavior do you expect?

Answer:

2. Actual behavior

Question: What actual behavior did you experience?

Answer:

3. Steps to reproduce your problem (and fixes, if any)

This part is very important: if you can not provide any reproduce steps, then the problem will be very hard to be recognized.

Question: What're the reproducible steps for us to see your problem?

Answer:

4. Full Output Logs

Show Logs
$ WECHATY_LOG=silly node yourbot.js

Question: Paste your FULL(DO NOT ONLY PROVIDE FRAGMENTS) log messages
Answer:

@crdsoft
Copy link
Author

crdsoft commented Nov 25, 2018

  1. Expected behavior

Question: What behavior do you expect?

Answer:机器人发消息,对方收到是乱码

  1. Actual behavior

Question: What actual behavior did you experience?

Answer:第一次使用,在自己window server电脑上安装node js,安装git,然后用git安装wechaty:
https://github.com/Chatie/wechaty-getting-started,然后就开始进入wechaty目录,
修改start-bot.js文件如下:
#!/usr/bin/env node

const {
    Wechaty,
    config,
} = require('wechaty')

function onScan (qrcode, status) {
  require('qrcode-terminal').generate(qrcode, { small: true })  // show qrcode on console

  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())
  let msgText = msg.text()
  if (msgText.indexOf("vip")  > -1) {
        respText ='想成为VIP?'
        await msg.say(respText)
    }
}

const bot = new Wechaty({
    profile: config.default.DEFAULT_PROFILE,
})

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))

然后执行npm start

然后用微信登陆发消息,发送包含vip的消息
机器人就会回复,但是消息中文是乱码的
���ΪVIP��

  1. Steps to reproduce your problem (and fixes, if any)

This part is very important: if you can not provide any reproduce steps, then the problem will be very hard to be recognized.

Question: What're the reproducible steps for us to see your problem?

Answer::第一次使用,在自己window server电脑上安装node js,安装git,然后用git安装wechaty:
https://github.com/Chatie/wechaty-getting-started,然后就开始进入wechaty目录,
修改start-bot.js文件如下:
#!/usr/bin/env node

const {
    Wechaty,
    config,
} = require('wechaty')

function onScan (qrcode, status) {
  require('qrcode-terminal').generate(qrcode, { small: true })  // show qrcode on console

  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())
  let msgText = msg.text()
  if (msgText.indexOf("vip")  > -1) {
        respText ='想成为VIP?'
        await msg.say(respText)
    }
}

const bot = new Wechaty({
    profile: config.default.DEFAULT_PROFILE,
})

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))

然后执行npm start

然后用微信登陆发消息,发送包含vip的消息
机器人就会回复,但是消息中文是乱码的
���ΪVIP��

  1. Full Output Logs

@crdsoft
Copy link
Author

crdsoft commented Nov 25, 2018

@lijiarui 美女

@lijiarui
Copy link
Member

Please paste the full log info, thanks :)

@crdsoft
Copy link
Author

crdsoft commented Nov 25, 2018

Your environment has been set up for using Node.js 11.2.0 (x64) and npm.

C:\Users\Administrator>cd wechaty

C:\Users\Administrator\wechaty>npm start

> wechaty-getting-started@0.1.0 start C:\Users\Administrator\wechaty
> node examples/starter-bot.js

19:44:53 INFO Wechaty <default> start() v0.22.4 is starting...
Starter Bot Started.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█ ▄▄▄▄▄ █▄▀ ▀  █▄ ▀█▄▄█ ▄▄▄▄▄ █
█ █   █ █   █▀ █ ▀▀ ▄▀█ █   █ █
█ █▄▄▄█ █▄█▀ ▄ █▄ ▀▀ ██ █▄▄▄█ █
█▄▄▄▄▄▄▄█▄█ █ █ ▀▄▀▄▀▄█▄▄▄▄▄▄▄█
█▄  ▄█▀▄▀ █ ▄ ▀▄██▄ ▀█ ▀▀ ▄▄█ █
█▄█▀▀█▀▄▀▄  ▄▄ ██▄█▀█ ▄▄█▀█▄▄▀█
█▄███ ▄▄▀▀▄▄▀ █ ▀█▄█ █▄▀██▄ ▀▀█
█▀█▄█▀▄▄█▀▀▀ █▄▀▀▀▄▄▄▄ ▀  █▄ ▄█
█▄▀ ███▄▄▄▀ █▄▄ ▀▄▀▄▄  █ ▄ ▀ ██
█▄██ ▀▀▄ ▄▀ ▀██▄ ▄▀▀█▀▀▀▄▀█ ███
██▄██▄▄▄▄▀▀███▀▀█  ▀▀ ▄▄▄   ▀▀█
█ ▄▄▄▄▄ ███▄▀▀▀▀▀▄█ ▄ █▄█  █▄██
█ █   █ █▀ █ █▀▀▀▀▄█▀  ▄  ▀▄▄ █
█ █▄▄▄█ █  ██ ▀▄█▀█ ▄ ██▄▀▀▄▀▄█
█▄▄▄▄▄▄▄█▄▄█▄███▄███▄▄▄██▄██▄██

https://api.qrserver.com/v1/create-qr-code/?data=https%3A%2F%2Flogin.weixin.qq.com%2Fl%2Focu-2wN8nA%3D%3D
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█ ▄▄▄▄▄ █▄▀ ▀  █▄ ▀█▄▄█ ▄▄▄▄▄ █
█ █   █ █   █▀ █ ▀▀ ▄▀█ █   █ █
█ █▄▄▄█ █▄█▀ ▄ █▄ ▀▀ ██ █▄▄▄█ █
█▄▄▄▄▄▄▄█▄█ █ █ ▀▄▀▄▀▄█▄▄▄▄▄▄▄█
█▄  ▄█▀▄▀ █ ▄ ▀▄██▄ ▀█ ▀▀ ▄▄█ █
█▄█▀▀█▀▄▀▄  ▄▄ ██▄█▀█ ▄▄█▀█▄▄▀█
█▄███ ▄▄▀▀▄▄▀ █ ▀█▄█ █▄▀██▄ ▀▀█
█▀█▄█▀▄▄█▀▀▀ █▄▀▀▀▄▄▄▄ ▀  █▄ ▄█
█▄▀ ███▄▄▄▀ █▄▄ ▀▄▀▄▄  █ ▄ ▀ ██
█▄██ ▀▀▄ ▄▀ ▀██▄ ▄▀▀█▀▀▀▄▀█ ███
██▄██▄▄▄▄▀▀███▀▀█  ▀▀ ▄▄▄   ▀▀█
█ ▄▄▄▄▄ ███▄▀▀▀▀▀▄█ ▄ █▄█  █▄██
█ █   █ █▀ █ █▀▀▀▀▄█▀  ▄  ▀▄▄ █
█ █▄▄▄█ █  ██ ▀▄█▀█ ▄ ██▄▀▀▄▀▄█
█▄▄▄▄▄▄▄█▄▄█▄███▄███▄▄▄██▄██▄██

https://api.qrserver.com/v1/create-qr-code/?data=https%3A%2F%2Flogin.weixin.qq.com%2Fl%2Focu-2wN8nA%3D%3D
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█ ▄▄▄▄▄ █▄▀ ▀  █▄ ▀█▄▄█ ▄▄▄▄▄ █
█ █   █ █   █▀ █ ▀▀ ▄▀█ █   █ █
█ █▄▄▄█ █▄█▀ ▄ █▄ ▀▀ ██ █▄▄▄█ █
█▄▄▄▄▄▄▄█▄█ █ █ ▀▄▀▄▀▄█▄▄▄▄▄▄▄█
█▄  ▄█▀▄▀ █ ▄ ▀▄██▄ ▀█ ▀▀ ▄▄█ █
█▄█▀▀█▀▄▀▄  ▄▄ ██▄█▀█ ▄▄█▀█▄▄▀█
█▄███ ▄▄▀▀▄▄▀ █ ▀█▄█ █▄▀██▄ ▀▀█
█▀█▄█▀▄▄█▀▀▀ █▄▀▀▀▄▄▄▄ ▀  █▄ ▄█
█▄▀ ███▄▄▄▀ █▄▄ ▀▄▀▄▄  █ ▄ ▀ ██
█▄██ ▀▀▄ ▄▀ ▀██▄ ▄▀▀█▀▀▀▄▀█ ███
██▄██▄▄▄▄▀▀███▀▀█  ▀▀ ▄▄▄   ▀▀█
█ ▄▄▄▄▄ ███▄▀▀▀▀▀▄█ ▄ █▄█  █▄██
█ █   █ █▀ █ █▀▀▀▀▄█▀  ▄  ▀▄▄ █
█ █▄▄▄█ █  ██ ▀▄█▀█ ▄ ██▄▀▀▄▀▄█
█▄▄▄▄▄▄▄█▄▄█▄███▄███▄▄▄██▄██▄██

https://api.qrserver.com/v1/create-qr-code/?data=https%3A%2F%2Flogin.weixin.qq.com%2Fl%2Focu-2wN8nA%3D%3D
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█ ▄▄▄▄▄ █▄▀ ▀  █▄ ▀█▄▄█ ▄▄▄▄▄ █
█ █   █ █   █▀ █ ▀▀ ▄▀█ █   █ █
█ █▄▄▄█ █▄█▀ ▄ █▄ ▀▀ ██ █▄▄▄█ █
█▄▄▄▄▄▄▄█▄█ █ █ ▀▄▀▄▀▄█▄▄▄▄▄▄▄█
█▄  ▄█▀▄▀ █ ▄ ▀▄██▄ ▀█ ▀▀ ▄▄█ █
█▄█▀▀█▀▄▀▄  ▄▄ ██▄█▀█ ▄▄█▀█▄▄▀█
█▄███ ▄▄▀▀▄▄▀ █ ▀█▄█ █▄▀██▄ ▀▀█
█▀█▄█▀▄▄█▀▀▀ █▄▀▀▀▄▄▄▄ ▀  █▄ ▄█
█▄▀ ███▄▄▄▀ █▄▄ ▀▄▀▄▄  █ ▄ ▀ ██
█▄██ ▀▀▄ ▄▀ ▀██▄ ▄▀▀█▀▀▀▄▀█ ███
██▄██▄▄▄▄▀▀███▀▀█  ▀▀ ▄▄▄   ▀▀█
█ ▄▄▄▄▄ ███▄▀▀▀▀▀▄█ ▄ █▄█  █▄██
█ █   █ █▀ █ █▀▀▀▀▄█▀  ▄  ▀▄▄ █
█ █▄▄▄█ █  ██ ▀▄█▀█ ▄ ██▄▀▀▄▀▄█
█▄▄▄▄▄▄▄█▄▄█▄███▄███▄▄▄██▄██▄██

https://api.qrserver.com/v1/create-qr-code/?data=https%3A%2F%2Flogin.weixin.qq.com%2Fl%2Focu-2wN8nA%3D%3D
Contact<义鉑> login
Message#Text(🗣Contact<公安信息化>👤Contact<义鉑>)<你好>
Message#Text(🗣Contact<公安信息化>👤Contact<义鉑>)<vip>
Message#Text(🗣Contact<义鉑>👤Contact<公安信息化>)<���ΪVIP��<br>��ô�������룿>
Message#Text(🗣Contact<公安信息化>👤Contact<义鉑>)<请先关注微信公众号:执法信息化。完成关注的请告诉我:"已经关注",谢谢!>
Message#Text(🗣Contact<公安信息化>👤Contact<义鉑>)<&lt;?xml version="1.0"?&gt;<br/>&lt;msg bigheadimgurl="http://wx.qlogo>

@lijiarui
Copy link
Member

lijiarui commented Nov 25, 2018

Could you add console.log(respText) as the following showed and have a try?

async function onMessage (msg) {
  console.log(msg.toString())
  let msgText = msg.text()
  if (msgText.indexOf("vip")  > -1) {
        respText ='想成为VIP?'
+       console.log(respText)
        await msg.say(respText)
    }
}

@crdsoft
Copy link
Author

crdsoft commented Nov 25, 2018

改成上面代码,结果运行出错了

Contact<义鉑> login
Message#Text(🗣Contact<公安信息化>👤Contact<义鉑>)<vip>
(node:16956) UnhandledPromiseRejectionWarning: ReferenceError: respText is not defined
    at Wechaty.onMessage (C:\Users\Administrator\wechaty\examples\starter-bot.js:32:20)
    at Wechaty.on.args (C:\Users\Administrator\wechaty\node_modules\wechaty\dist\src\wechaty.js:383:26)
    at Wechaty.emit (events.js:182:13)
    at Wechaty.EventEmitter.emit (domain.js:441:20)
    at Wechaty.emit (C:\Users\Administrator\wechaty\node_modules\wechaty\dist\src\wechaty.js:179:22)
    at Wechaty.<anonymous> (C:\Users\Administrator\wechaty\node_modules\wechaty\dist\src\wechaty.js:477:30)
    at Generator.next (<anonymous>)
    at fulfilled (C:\Users\Administrator\wechaty\node_modules\wechaty\dist\src\wechaty.js:4:58)
    at process.internalTickCallback (internal/process/next_tick.js:77:7)
(node:16956) 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:16956) [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.

@crdsoft
Copy link
Author

crdsoft commented Nov 25, 2018

就是改成这样也是两行错误编码

async function onMessage (msg) {
  console.log(msg.toString())
 let msgText = msg.text()
  if (msgText.indexOf("vip")  > -1) {
      let  respText ='想成为VIP?'
        console.log(respText)
        await msg.say(respText)
        await msg.say('甚至将他的')
    }
}

运行结果:

Contact<义鉑> login
Message#Text(🗣Contact<公安信息化>👤Contact<义鉑>)<vip>
���ΪVIP��
Message#Text(🗣Contact<义鉑>👤Contact<公安信息化>)<���ΪVIP��>
Message#Text(🗣Contact<义鉑>👤Contact<公安信息化>)<����������>

@lijiarui
Copy link
Member

Could you just try the following code:

const a = '中文'
console.log(a)

If this still has a strange code, I guess this is not related to wechaty, it is related to your code editor.

@windmemory
Copy link
Member

Or related to windows encoding.

@crdsoft
Copy link
Author

crdsoft commented Nov 25, 2018

解决了,谢谢美女和大神。果然是编辑器问题,我直接使用记事本的原因。

@crdsoft crdsoft closed this as completed Nov 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants