提交 f37354c5 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

fix bridge to webdriver json escape error: use base64 to encode, and...

fix bridge to webdriver json escape error: use base64 to encode, and encodeURIComponent to support UTF8
上级 26ff4802
......@@ -112,6 +112,14 @@ I'll try my best to keep the api as sample as it can be.
## Events
Wechaty support the following 5 events:
1. scan
2. login
3. logout
4. message
5. error
### 1. Event: `scan`
A `scan` event will be emitted when the bot need to show you a QrCode for scaning.
......@@ -151,6 +159,9 @@ bot.on('message', message => {
```
The `message` here is a [Message](#class-message).
### 5. Event: `error`
To be support.
## Class Wechaty
Main bot class.
......@@ -344,6 +355,9 @@ Github Issue - https://github.com/zixia/wechaty/issues
### Javascript
1. [Weixinbot](https://github.com/feit/Weixinbot) Nodejs 封装网页版微信的接口,可编程控制微信消息
### Perl
1. [MojoWeixin](https://github.com/sjdy521/Mojo-Weixin] 使用Perl语言编写的微信客户端框架,基于Mojolicious,要求Perl版本5.10+,可通过插件提供基于HTTP协议的api接口供其他语言或系统调用
### Python
1. [WeixinBot](https://github.com/Urinx/WeixinBot) *Very well documented* 网页版微信API,包含终端版微信及微信机器人
1. [wxBot](https://github.com/liuwons/wxBot): Wechat Bot API
......
......@@ -106,8 +106,15 @@ class Bridge {
* Proxy Call to Wechaty in Bridge
*/
proxyWechaty(wechatyFunc, ...args) {
const argsBase64Json = new Buffer(JSON.stringify(args)).toString('base64')
const wechatyScript = `return (Wechaty && Wechaty.${wechatyFunc}.apply(undefined, JSON.parse(atob('${argsBase64Json}'))))`
const argsEncoded = new Buffer(
encodeURIComponent(
JSON.stringify(args)
)
).toString('base64')
// see: http://blog.sqrtthree.com/2015/08/29/utf8-to-b64/
const argsDecoded = `JSON.parse(decodeURIComponent(atob('${argsEncoded}')))`
const wechatyScript = `return (Wechaty && Wechaty.${wechatyFunc}.apply(undefined, ${argsDecoded}))`
log.silly('Bridge', 'proxyWechaty: ' + wechatyScript)
return this.execute(wechatyScript)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册