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

Refactoring PadChat with JsonRpcPeer

上级 2d2848ac
#!/usr/bin/env ts-node
/**
* Author: Huan LI <zixia@zixia.net>
* https://github.com/zixia
* License: Apache-2.0
*/
import { minor } from 'semver'
const version: string = require('../package.json').version
......
#!/usr/bin/env bash
#
# Author: Huan LI <zixia@zixia.net>
# https://github.com/zixia
# License: Apache-2.0
#
[ -z "$1" ] && {
echo
......
此差异已折叠。
此差异已折叠。
......@@ -32,6 +32,7 @@ export interface WXGetQRCodeType {
}
export enum WXCheckQRCodeStatus {
Unknown = -1,
WaitScan = 0,
WaitConfirm = 1,
Confirmed = 2,
......@@ -45,7 +46,7 @@ export interface WXCheckQRCodePayload {
head_url ?: string, // http://wx.qlogo.cn/mmhead/ver_1/NkOvv1rTx3Dsqpicnhe0j7cVOR3psEAVfuhFLbmoAcwaob4eENNZlp3KIEsMgibfH4kRjDicFFXN3qdP6SGRXbo7GBs8YpN52icxSeBUX8xkZBA/0,
nick_name ?: string, // 苏轼,
password ?: string,
status : number, // 2 = success
status : WXCheckQRCodeStatus, // 2 = success
user_name ?: string, // wxid_zj2cahpwzgie12
}
......
......@@ -21,7 +21,7 @@
// import * as fs from 'fs'
// import * as cuid from 'cuid'
import * as LRU from 'lru-cache'
import LRU from 'lru-cache'
import {
FileBox,
......@@ -115,7 +115,6 @@ export class PuppetPadchat extends Puppet {
memory : this.options.memory,
token : WECHATY_PUPPET_PADCHAT_TOKEN,
endpoint: WECHATY_PUPPET_PADCHAT_ENDPOINT,
autoData : {},
// profile: profile, // should be profile in the future
})
}
......
......@@ -8,6 +8,8 @@
* [Master the JavaScript Interview: What is a Pure Function?](https://medium.com/javascript-scene/master-the-javascript-interview-what-is-a-pure-function-d1c076bec976)
*
*/
import jsQR from 'jsqr'
import Jimp from 'jimp'
import {
ContactPayload,
......@@ -267,6 +269,39 @@ export class PadchatPureFunctionHelper {
// }
}
public static async imageBase64ToQrCode(base64: string): Promise<string> {
const imageBuffer = Buffer.from(base64, 'base64')
const future = new Promise<string>((resolve, reject) => {
Jimp.read(imageBuffer, (err, image) => {
if (err) {
return reject(err)
}
const qrCodeImageArray = new Uint8ClampedArray(image.bitmap.data.buffer)
const qrCodeResult = jsQR(
qrCodeImageArray,
image.bitmap.width,
image.bitmap.height,
)
if (qrCodeResult) {
return resolve(qrCodeResult.data)
} else {
return reject(new Error('WXGetQRCode() qrCode decode fail'))
}
})
})
try {
const qrCode = await future
return qrCode
} catch (e) {
throw new Error('no qrcode in image: ' + e.message)
}
}
}
export default PadchatPureFunctionHelper
......@@ -17,12 +17,12 @@
* limitations under the License.
*
*/
import * as fs from 'fs'
import * as path from 'path'
import fs from 'fs'
import path from 'path'
// tslint:disable:no-shadowed-variable
import * as test from 'blue-tape'
import * as sinon from 'sinon'
import test from 'blue-tape'
import sinon from 'sinon'
import {
Cookie,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册