wechat-offiaccount 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG +7 -1
- package/README.md +14 -0
- package/bin/run +3 -3
- package/nodejs/index.d.ts +6 -0
- package/nodejs/index.js +4 -31
- package/nodejs/libs/JsApiSignature.js +12 -15
- package/nodejs/libs/getAccessToken.js +1 -1
- package/nodejs/libs/getJsapiTicket.js +1 -1
- package/nodejs/server.js +43 -0
- package/nodejs/utils/log.js +14 -0
- package/nodejs/utils/network.js +27 -0
- package/nodejs/utils/options.js +49 -0
- package/nodejs/utils/remote.js +21 -0
- package/package.json +2 -3
package/CHANGELOG
CHANGED
package/README.md
CHANGED
|
@@ -132,6 +132,20 @@ module.exports = config
|
|
|
132
132
|
|
|
133
133
|
然后需要启动后部署到外网可以访问的服务器上,最后就可以作为微信公众号后台服务器使用,然后进行各种测试学习了。
|
|
134
134
|
|
|
135
|
+
### 调试服务器API接口
|
|
136
|
+
|
|
137
|
+
> v0.3.0 新增
|
|
138
|
+
|
|
139
|
+
为了更好的提供服务,对部分可能需要二次开发的接口(开发服务器)进行了封装,比如:
|
|
140
|
+
|
|
141
|
+
一、微信sdk验证签名接口
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
const { JsApiSignature } = require("wechat-offiaccount/nodejs/index")
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
具体使用参考 [./nodejs/server.js](./nodejs/server.js)
|
|
148
|
+
|
|
135
149
|
## 版权
|
|
136
150
|
|
|
137
151
|
MIT License
|
package/bin/run
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
5
|
process.title = 'offiaccount-cli'
|
|
6
|
-
const { log } = require('
|
|
6
|
+
const { log } = require('../nodejs/utils/log')
|
|
7
7
|
const path = require('path')
|
|
8
8
|
|
|
9
9
|
const jsonfile = require('../package.json')
|
|
10
10
|
|
|
11
11
|
// 命令行传递的参数
|
|
12
|
-
const parsed = require("
|
|
12
|
+
const parsed = require("../nodejs/utils/options")({
|
|
13
13
|
"-c": "--config"
|
|
14
14
|
}, process.argv)
|
|
15
15
|
|
|
@@ -19,7 +19,7 @@ if (parsed.config && parsed.config.length > 0) {
|
|
|
19
19
|
let configFile = require(path.join(process.cwd(), parsed.config[0]))
|
|
20
20
|
|
|
21
21
|
// 启动
|
|
22
|
-
require('../nodejs/
|
|
22
|
+
require('../nodejs/server')(configFile)
|
|
23
23
|
|
|
24
24
|
} else {
|
|
25
25
|
log(`
|
package/nodejs/index.js
CHANGED
|
@@ -1,32 +1,5 @@
|
|
|
1
|
-
const express = require('express')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
const auth = require('./libs/auth')
|
|
4
|
-
const JsApiSignature = require('./libs/JsApiSignature')
|
|
5
|
-
const { log, error, network } = require('devby')
|
|
6
|
-
const jsonfile = require('../package.json')
|
|
7
1
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
app.use(express.static(path.resolve(__dirname, '../')))
|
|
13
|
-
|
|
14
|
-
// 获取微信签名
|
|
15
|
-
app.get("/JsApiSignature", JsApiSignature(config))
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 我们这里使用测试号,通过”接口配置信息“来验证
|
|
19
|
-
* https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index
|
|
20
|
-
*/
|
|
21
|
-
app.use(auth(config))
|
|
22
|
-
|
|
23
|
-
app.listen(config.port, () => {
|
|
24
|
-
|
|
25
|
-
let ipv4 = network().IPv4[0]?.address || '127.0.0.1'
|
|
26
|
-
|
|
27
|
-
log(`${jsonfile.name}@v${jsonfile.version}
|
|
28
|
-
微信公众号辅助调试服务器启动成功
|
|
29
|
-
`)
|
|
30
|
-
error(`访问 http://${ipv4}:${config.port}`)
|
|
31
|
-
})
|
|
32
|
-
}
|
|
2
|
+
/**
|
|
3
|
+
* 微信sdk验证签名
|
|
4
|
+
*/
|
|
5
|
+
exports.JsApiSignature = require('./libs/JsApiSignature')
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
const sha1 = require('sha1')
|
|
2
2
|
|
|
3
|
-
module.exports = (config) => {
|
|
4
|
-
|
|
3
|
+
module.exports = (url, config) => {
|
|
4
|
+
const { appID } = config
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* 生成js-sdk的签名
|
|
8
|
+
* 1、组合参与签名的四个参数:jsapi_ticket(临时票据)、noncestr(随机字符串)、timestamp(时间戳)、url(当前服务器地址)
|
|
9
|
+
* 2、将其进行字典序排序,以‘&’拼接在一起
|
|
10
|
+
* 3、进行sha1加密,最终生成signature
|
|
11
|
+
*/
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
* 生成js-sdk的签名
|
|
11
|
-
* 1、组合参与签名的四个参数:jsapi_ticket(临时票据)、noncestr(随机字符串)、timestamp(时间戳)、url(当前服务器地址)
|
|
12
|
-
* 2、将其进行字典序排序,以‘&’拼接在一起
|
|
13
|
-
* 3、进行sha1加密,最终生成signature
|
|
14
|
-
*/
|
|
13
|
+
return new Promise()((resolve, reject) => {
|
|
15
14
|
|
|
16
15
|
require('./getJsapiTicket')(config).then(jsapi_ticket => {
|
|
17
16
|
|
|
@@ -32,16 +31,14 @@ module.exports = (config) => {
|
|
|
32
31
|
// sha1加密
|
|
33
32
|
const sha1Str = sha1(str)
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
res.send(JSON.stringify({
|
|
34
|
+
resolve({
|
|
37
35
|
appId: appID,
|
|
38
36
|
timestamp,
|
|
39
37
|
nonceStr: noncestr,
|
|
40
38
|
signature: sha1Str
|
|
41
|
-
})
|
|
42
|
-
|
|
39
|
+
})
|
|
43
40
|
})
|
|
44
41
|
|
|
45
|
-
}
|
|
42
|
+
})
|
|
46
43
|
|
|
47
44
|
}
|
package/nodejs/server.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const express = require('express')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const auth = require('./libs/auth')
|
|
4
|
+
const JsApiSignature = require('./libs/JsApiSignature')
|
|
5
|
+
const { log, error } = require('./utils/log')
|
|
6
|
+
const network = require('./utils/network')
|
|
7
|
+
const jsonfile = require('../package.json')
|
|
8
|
+
|
|
9
|
+
module.exports = (config) => {
|
|
10
|
+
const app = express()
|
|
11
|
+
|
|
12
|
+
// 静态资源
|
|
13
|
+
app.use(express.static(path.resolve(__dirname, '../')))
|
|
14
|
+
|
|
15
|
+
// 获取微信签名
|
|
16
|
+
app.get("/JsApiSignature", function (req, res) {
|
|
17
|
+
const { url } = req.query
|
|
18
|
+
|
|
19
|
+
JsApiSignature(url, config).then(data => {
|
|
20
|
+
|
|
21
|
+
res.setHeader('Access-Control-Allow-Origin', '*')
|
|
22
|
+
res.send(JSON.stringify(data))
|
|
23
|
+
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 我们这里使用测试号,通过”接口配置信息“来验证
|
|
30
|
+
* https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index
|
|
31
|
+
*/
|
|
32
|
+
app.use(auth(config))
|
|
33
|
+
|
|
34
|
+
app.listen(config.port, () => {
|
|
35
|
+
|
|
36
|
+
let ipv4 = network().IPv4[0]?.address || '127.0.0.1'
|
|
37
|
+
|
|
38
|
+
log(`${jsonfile.name}@v${jsonfile.version}
|
|
39
|
+
微信公众号辅助调试服务器启动成功
|
|
40
|
+
`)
|
|
41
|
+
error(`访问 http://${ipv4}:${config.port}`)
|
|
42
|
+
})
|
|
43
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// 日志
|
|
2
|
+
exports.log = function (txt) {
|
|
3
|
+
console.log("\x1B[34m" + txt + "\x1B[39m");
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
// 警告
|
|
7
|
+
exports.warn = function (txt) {
|
|
8
|
+
console.log("\x1B[33m" + txt + "\x1B[39m");
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// 错误
|
|
12
|
+
exports.error = function (txt) {
|
|
13
|
+
console.log("\x1B[35m" + txt + "\x1B[39m");
|
|
14
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module.exports = function () {
|
|
2
|
+
|
|
3
|
+
let infomation = {
|
|
4
|
+
IPv4: [],
|
|
5
|
+
IPv6: []
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
let networks = require('os').networkInterfaces()
|
|
9
|
+
for (let typeName in networks) {
|
|
10
|
+
let network = networks[typeName]
|
|
11
|
+
for (let index = 0; index < network.length; index++) {
|
|
12
|
+
if (network[index].family == 'IPv4' && network[index].address != '127.0.0.1') {
|
|
13
|
+
infomation.IPv4.push({
|
|
14
|
+
address: network[index].address,
|
|
15
|
+
mac: network[index].mac
|
|
16
|
+
});
|
|
17
|
+
} else if (network[index].family == 'IPv6' && network[index].address != '::1') {
|
|
18
|
+
infomation.IPv6.push({
|
|
19
|
+
address: network[index].address,
|
|
20
|
+
mac: network[index].mac
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return infomation;
|
|
27
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* 命令行参数解析
|
|
4
|
+
*
|
|
5
|
+
* @param {JSON} config 命令参数缩小到全写的映射
|
|
6
|
+
* @param {Array} argv 需要判断类型的值
|
|
7
|
+
*
|
|
8
|
+
* @returns {JSON} 返回整理后的参数
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
module.exports = function (config, argv) {
|
|
12
|
+
|
|
13
|
+
let resultConfig = {
|
|
14
|
+
__terminal__: []
|
|
15
|
+
}, flag = null;
|
|
16
|
+
for (let i = 2; i < argv.length; i++) {
|
|
17
|
+
|
|
18
|
+
// 如果是新的配置
|
|
19
|
+
if (/^--[0-9a-zA-Z]+$/.test(argv[i]) || /^-[0-9a-zA-Z]$/.test(argv[i])) {
|
|
20
|
+
let key = argv[i];
|
|
21
|
+
|
|
22
|
+
// 如果是缩写,需要映射
|
|
23
|
+
if (key.length == 2) {
|
|
24
|
+
key = config[key];
|
|
25
|
+
|
|
26
|
+
// 如果是错误缩写
|
|
27
|
+
if (!key) {
|
|
28
|
+
flag = null;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
flag = key.replace(/^--/, "");
|
|
34
|
+
resultConfig[flag] = [];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 如果是普通的参数
|
|
38
|
+
else if (flag != null) {
|
|
39
|
+
resultConfig[flag].push(argv[i]);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
else {
|
|
43
|
+
resultConfig.__terminal__.push(argv[i]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return resultConfig;
|
|
49
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const https = require('https');
|
|
2
|
+
const http = require('http');
|
|
3
|
+
|
|
4
|
+
exports.get = function (url, options = {}) {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
|
|
7
|
+
let handler = /^https/.test(url) ? https : http;
|
|
8
|
+
|
|
9
|
+
handler.get(url, res => {
|
|
10
|
+
res.on('data', (data) => {
|
|
11
|
+
if (options.json) {
|
|
12
|
+
resolve(JSON.parse(data.toString('utf8')));
|
|
13
|
+
} else {
|
|
14
|
+
resolve(data);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}).on('error', (e) => {
|
|
18
|
+
reject(e);
|
|
19
|
+
});
|
|
20
|
+
})
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wechat-offiaccount",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "微信公众号辅助调试服务器 + 微信官方js-sdk,支持typescript开发",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -29,11 +29,10 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/oi-contrib/WeChat-offiaccount",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"devby": "^0.4.6",
|
|
33
32
|
"express": "^4.18.2",
|
|
34
33
|
"sha1": "^1.1.1"
|
|
35
34
|
},
|
|
36
35
|
"devDependencies": {
|
|
37
|
-
"zdebug.js": "^0.
|
|
36
|
+
"zdebug.js": "^0.3.0"
|
|
38
37
|
}
|
|
39
38
|
}
|