node-easywechat 2.6.9 → 2.7.2
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/README.md +34 -4
- package/dist/BaseService/ContentSecurity/ContentSecurityClient.d.ts +5 -3
- package/dist/BaseService/ContentSecurity/ContentSecurityClient.js +2 -2
- package/dist/BaseService/Jssdk/JssdkClient.d.ts +15 -15
- package/dist/BaseService/Jssdk/JssdkClient.js +15 -15
- package/dist/BaseService/Media/MediaClient.d.ts +22 -20
- package/dist/BaseService/Media/MediaClient.js +14 -14
- package/dist/BaseService/Url/UrlClient.d.ts +1 -1
- package/dist/Core/AES.d.ts +46 -0
- package/dist/Core/AES.js +95 -0
- package/dist/Core/BaseApplication.js +9 -5
- package/dist/Core/Encryptor.d.ts +2 -14
- package/dist/Core/Encryptor.js +9 -39
- package/dist/Core/Http/Request.js +2 -6
- package/dist/Core/Messages/Message.js +2 -16
- package/dist/Core/PKCS.d.ts +15 -0
- package/dist/Core/PKCS.js +44 -0
- package/dist/Core/RSA.d.ts +59 -0
- package/dist/Core/RSA.js +99 -0
- package/dist/Core/ServerGuard.d.ts +1 -1
- package/dist/Core/ServerGuard.js +5 -33
- package/dist/Core/Types.d.ts +29 -4
- package/dist/Core/Utils.d.ts +8 -2
- package/dist/Core/Utils.js +61 -20
- package/dist/MicroMerchant/Application.d.ts +27 -0
- package/dist/MicroMerchant/Application.js +105 -0
- package/dist/MicroMerchant/Base/MicroMerchantBase.d.ts +7 -0
- package/dist/MicroMerchant/Base/MicroMerchantBase.js +52 -0
- package/dist/MicroMerchant/Certficates/CertficatesClient.d.ts +5 -0
- package/dist/MicroMerchant/Certficates/CertficatesClient.js +52 -0
- package/dist/MicroMerchant/Core/BaseClient.d.ts +9 -0
- package/dist/MicroMerchant/Core/BaseClient.js +106 -0
- package/dist/MicroMerchant/Media/MediaClient.d.ts +6 -0
- package/dist/MicroMerchant/Media/MediaClient.js +33 -0
- package/dist/MicroMerchant/MerchantConfig/MerchantConfigClient.d.ts +8 -0
- package/dist/MicroMerchant/MerchantConfig/MerchantConfigClient.js +49 -0
- package/dist/MicroMerchant/Meterial/MeterialClient.d.ts +5 -0
- package/dist/MicroMerchant/Meterial/MeterialClient.js +30 -0
- package/dist/MicroMerchant/Withdraw/WithdrawClient.d.ts +5 -0
- package/dist/MicroMerchant/Withdraw/WithdrawClient.js +28 -0
- package/dist/MiniProgram/Encryptor.js +2 -6
- package/dist/Payment/Bill/BillClient.js +1 -1
- package/dist/Payment/Core/BaseClient.d.ts +0 -1
- package/dist/Payment/Core/BaseClient.js +2 -20
- package/dist/Payment/Notify/Handler.js +3 -11
- package/dist/Payment/Notify/Refunded.d.ts +0 -1
- package/dist/Payment/Notify/Refunded.js +1 -11
- package/dist/Payment/Transfer/TransferClient.js +4 -3
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2 -0
- package/node-easywechat.file_cache.easywechat.kernel.access_token.8a9684b45da7de42a06a70ba01a7005a.cache +1 -1
- package/node-easywechat.file_cache.easywechat.kernel.access_token.c3d06edaf326aad75d32f31348df787a.cache +1 -1
- package/package.json +9 -7
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
## EasyWechat for Node.js
|
|
3
3
|
|
|
4
|
-
[](https://app.travis-ci.com/hpyer/node-easywechat) [](https://www.npmjs.com/package/node-easywechat) [](LICENSE)
|
|
5
5
|
|
|
6
6
|
**注:2.x分支针对 EasyWechat 的 5.x版本(由于4.x与5.x的结构基本一致,就不升级大版本了)。若您需要 EasyWechat 的 3.x版本,请切换到 [1.x](https://github.com/hpyer/node-easywechat/tree/1.x) 分支。**
|
|
7
7
|
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
|
|
17
17
|
### 使用说明
|
|
18
18
|
|
|
19
|
-
绝大部分API都可以根据 [EasyWechat 的文档](https://www.easywechat.com/
|
|
19
|
+
绝大部分API都可以根据 [EasyWechat 的文档](https://www.easywechat.com/5.x/) 来使用。小部分(如获取请求相关数据、返回响应数据、支付证书等)的操作,由于语言环境的不同,会有不同处理。具体可以查看 [node-easywechat-demo](https://github.com/hpyer/node-easywechat-demo/) 以及下方的[自定义模块说明](#自定义模块模块替换使用方法) 。如果仍有疑问,请提issue,谢谢~
|
|
20
|
+
|
|
21
|
+
更多信息详见:[API文档](docs/README.md)
|
|
20
22
|
|
|
21
23
|
```js
|
|
22
24
|
// 公众号
|
|
@@ -44,6 +46,11 @@ let openPlatform = new EasyWechat.Factory.Work({
|
|
|
44
46
|
// ...
|
|
45
47
|
});
|
|
46
48
|
|
|
49
|
+
// 小微商户
|
|
50
|
+
let microMerchant = new EasyWechat.Factory.MicroMerchant({
|
|
51
|
+
// ...
|
|
52
|
+
});
|
|
53
|
+
|
|
47
54
|
// 通用方式
|
|
48
55
|
let app = EasyWechat.Factory.getInstance('OficialAccount', {
|
|
49
56
|
// ...
|
|
@@ -122,6 +129,24 @@ let app = EasyWechat.Factory.getInstance('OficialAccount', {
|
|
|
122
129
|
}
|
|
123
130
|
```
|
|
124
131
|
|
|
132
|
+
``` js
|
|
133
|
+
// 小微商户配置
|
|
134
|
+
{
|
|
135
|
+
// 商户号
|
|
136
|
+
mch_id: 'your-mch-id',
|
|
137
|
+
// 签名密钥
|
|
138
|
+
key: 'key-for-signature',
|
|
139
|
+
// V3版本签名密钥
|
|
140
|
+
apiv3_key: 'apiv3_key-for-signature',
|
|
141
|
+
// 证书地址,Node.js 只需要 .pfx 证书文件即可
|
|
142
|
+
cert_path: 'path/to/your/cert.pfx', // XXX: 绝对路径!!!!
|
|
143
|
+
|
|
144
|
+
// 以下两项配置在获取证书接口时可为空,在调用入驻接口前请先调用获取证书接口获取以下两项配置,如果获取过证书可以直接在这里配置,也可参照本文档获取平台证书章节中示例
|
|
145
|
+
// serial_no: '获取证书接口获取到的平台证书序列号',
|
|
146
|
+
// certificate: '获取证书接口获取到的证书内容'
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
125
150
|
### 模块支持情况
|
|
126
151
|
|
|
127
152
|
- [x] 公众号模块
|
|
@@ -130,7 +155,7 @@ let app = EasyWechat.Factory.getInstance('OficialAccount', {
|
|
|
130
155
|
- [x] 开放平台
|
|
131
156
|
- [x] 企业微信
|
|
132
157
|
- [ ] 企业微信开放平台
|
|
133
|
-
- [
|
|
158
|
+
- [x] 小微商户
|
|
134
159
|
- [x] 自定义
|
|
135
160
|
|
|
136
161
|
### 自定义模块(模块替换)使用方法
|
|
@@ -139,6 +164,8 @@ let app = EasyWechat.Factory.getInstance('OficialAccount', {
|
|
|
139
164
|
|
|
140
165
|
##### 日志模块(log)
|
|
141
166
|
|
|
167
|
+
> 注:自 `2.6.10` 版本起,配置项中新增了 `debug` 字段,默认为 `false`。设置为 `true` 时,程序才会打印相关日志。所以,如果你只是希望关闭日志的话,更新到 `2.6.10` 即可。
|
|
168
|
+
|
|
142
169
|
```js
|
|
143
170
|
// 创建实例
|
|
144
171
|
const Easywechat = require('node-easywechat');
|
|
@@ -147,10 +174,13 @@ let officialAccount = new Easywechat.Factory.OfficialAccount({
|
|
|
147
174
|
});
|
|
148
175
|
|
|
149
176
|
// 自定义日志处理方法
|
|
150
|
-
const myLogger = () => {
|
|
177
|
+
const myLogger = (app) => {
|
|
151
178
|
// 注意:这里返回的方法不能使用箭头函数,否则会导致获取到的 arguments 异常
|
|
152
179
|
// 若需要关闭日志,则返回空的函数即可
|
|
153
180
|
return function() {
|
|
181
|
+
// 判断是否开启了 debug
|
|
182
|
+
if (!app['config']['debug']) return true;
|
|
183
|
+
|
|
154
184
|
let args = arguments;
|
|
155
185
|
args[0] = 'myLogger: ' + args[0];
|
|
156
186
|
return console.log.apply(null, arguments);
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import BaseClient from '../../Core/BaseClient';
|
|
3
|
+
import Stream from 'stream';
|
|
2
4
|
export default class ContentSecurityClient extends BaseClient {
|
|
3
5
|
protected baseUrl: string;
|
|
4
6
|
/**
|
|
5
7
|
* 校验一段文本是否含有违法内容
|
|
6
|
-
* @param
|
|
8
|
+
* @param text 待校验文本
|
|
7
9
|
*/
|
|
8
10
|
checkText(text: string): Promise<any>;
|
|
9
11
|
/**
|
|
10
12
|
* 校验一张图片是否含有敏感信息
|
|
11
|
-
* @param
|
|
13
|
+
* @param file 文件路径或可读stream
|
|
12
14
|
*/
|
|
13
|
-
checkImage(file:
|
|
15
|
+
checkImage(file: string | Stream.Readable): Promise<any>;
|
|
14
16
|
}
|
|
@@ -20,7 +20,7 @@ class ContentSecurityClient extends BaseClient_1.default {
|
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* 校验一段文本是否含有违法内容
|
|
23
|
-
* @param
|
|
23
|
+
* @param text 待校验文本
|
|
24
24
|
*/
|
|
25
25
|
checkText(text) {
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -31,7 +31,7 @@ class ContentSecurityClient extends BaseClient_1.default {
|
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* 校验一张图片是否含有敏感信息
|
|
34
|
-
* @param
|
|
34
|
+
* @param file 文件路径或可读stream
|
|
35
35
|
*/
|
|
36
36
|
checkImage(file) {
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -10,35 +10,35 @@ export default class Client extends BaseClient {
|
|
|
10
10
|
getTicket(refresh?: boolean, type?: string): Promise<string>;
|
|
11
11
|
/**
|
|
12
12
|
* 获取JSSDK的配置
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
13
|
+
* @param jsApiList API列表
|
|
14
|
+
* @param debug 是否调试模式,默认:false
|
|
15
|
+
* @param beta 是否测试模式,默认:false
|
|
16
|
+
* @param json true时返回JSON字符串,默认:true
|
|
17
|
+
* @param openTagList 开放标签列表,默认:[]
|
|
18
|
+
* @param url 请求URL,默认:当前URL
|
|
19
19
|
*/
|
|
20
20
|
buildConfig(jsApiList: Array<string>, debug?: Boolean, beta?: Boolean, json?: Boolean, openTagList?: Array<string>, url?: string): Promise<any>;
|
|
21
21
|
/**
|
|
22
22
|
* 获取JSSDK的配置对象
|
|
23
|
-
* @param
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
23
|
+
* @param jsApiList API列表
|
|
24
|
+
* @param debug 是否调试模式,默认:false
|
|
25
|
+
* @param beta 是否测试模式,默认:false
|
|
26
|
+
* @param openTagList 开放标签列表,默认:[]
|
|
27
|
+
* @param url 请求URL,默认:当前URL
|
|
28
28
|
*/
|
|
29
29
|
getConfigArray(jsApiList: Array<string>, debug?: Boolean, beta?: Boolean, openTagList?: Array<string>, url?: string): Promise<any>;
|
|
30
30
|
/**
|
|
31
31
|
* 获取签名配置
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
34
|
-
* @param
|
|
32
|
+
* @param url 完整的URL地址
|
|
33
|
+
* @param nonce 随机字符串,默认:随机10位
|
|
34
|
+
* @param timestamp 时间戳,默认:当前时间
|
|
35
35
|
*/
|
|
36
36
|
configSignature(url?: string, nonce?: string, timestamp?: string): Promise<object>;
|
|
37
37
|
protected getTicketSignature(ticket: string, nonce: string, timestamp: string, url: string): string;
|
|
38
38
|
protected dictionaryOrderSignature(args: Array<string>): string;
|
|
39
39
|
/**
|
|
40
40
|
* 设置当前URL
|
|
41
|
-
* @param
|
|
41
|
+
* @param url 完整的URL地址
|
|
42
42
|
*/
|
|
43
43
|
setUrl(url: string): this;
|
|
44
44
|
/**
|
|
@@ -46,12 +46,12 @@ class Client extends BaseClient_1.default {
|
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* 获取JSSDK的配置
|
|
49
|
-
* @param
|
|
50
|
-
* @param
|
|
51
|
-
* @param
|
|
52
|
-
* @param
|
|
53
|
-
* @param
|
|
54
|
-
* @param
|
|
49
|
+
* @param jsApiList API列表
|
|
50
|
+
* @param debug 是否调试模式,默认:false
|
|
51
|
+
* @param beta 是否测试模式,默认:false
|
|
52
|
+
* @param json true时返回JSON字符串,默认:true
|
|
53
|
+
* @param openTagList 开放标签列表,默认:[]
|
|
54
|
+
* @param url 请求URL,默认:当前URL
|
|
55
55
|
*/
|
|
56
56
|
buildConfig(jsApiList, debug = false, beta = false, json = true, openTagList = [], url = '') {
|
|
57
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -63,20 +63,20 @@ class Client extends BaseClient_1.default {
|
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* 获取JSSDK的配置对象
|
|
66
|
-
* @param
|
|
67
|
-
* @param
|
|
68
|
-
* @param
|
|
69
|
-
* @param
|
|
70
|
-
* @param
|
|
66
|
+
* @param jsApiList API列表
|
|
67
|
+
* @param debug 是否调试模式,默认:false
|
|
68
|
+
* @param beta 是否测试模式,默认:false
|
|
69
|
+
* @param openTagList 开放标签列表,默认:[]
|
|
70
|
+
* @param url 请求URL,默认:当前URL
|
|
71
71
|
*/
|
|
72
72
|
getConfigArray(jsApiList, debug = false, beta = false, openTagList = [], url = '') {
|
|
73
73
|
return this.buildConfig(jsApiList, debug, beta, false, openTagList, url);
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
76
|
* 获取签名配置
|
|
77
|
-
* @param
|
|
78
|
-
* @param
|
|
79
|
-
* @param
|
|
77
|
+
* @param url 完整的URL地址
|
|
78
|
+
* @param nonce 随机字符串,默认:随机10位
|
|
79
|
+
* @param timestamp 时间戳,默认:当前时间
|
|
80
80
|
*/
|
|
81
81
|
configSignature(url = '', nonce = '', timestamp = '') {
|
|
82
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -106,7 +106,7 @@ class Client extends BaseClient_1.default {
|
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
108
|
* 设置当前URL
|
|
109
|
-
* @param
|
|
109
|
+
* @param url 完整的URL地址
|
|
110
110
|
*/
|
|
111
111
|
setUrl(url) {
|
|
112
112
|
this.url = url;
|
|
@@ -1,55 +1,57 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import BaseClient from '../../Core/BaseClient';
|
|
3
|
+
import Stream from 'stream';
|
|
2
4
|
export default class MediaClient extends BaseClient {
|
|
3
5
|
protected baseUrl: string;
|
|
4
6
|
protected allowTypes: Array<string>;
|
|
5
7
|
/**
|
|
6
8
|
* 上传图片到临时素材
|
|
7
|
-
* @param
|
|
9
|
+
* @param file 文件路径或可读stream
|
|
8
10
|
*/
|
|
9
|
-
uploadImage(file:
|
|
11
|
+
uploadImage(file: string | Stream.Readable): Promise<any>;
|
|
10
12
|
/**
|
|
11
13
|
* 上传视频到临时素材
|
|
12
|
-
* @param
|
|
14
|
+
* @param file 文件路径或可读stream
|
|
13
15
|
*/
|
|
14
|
-
uploadVideo(file:
|
|
16
|
+
uploadVideo(file: string | Stream.Readable): Promise<any>;
|
|
15
17
|
/**
|
|
16
18
|
* 上传语音到临时素材
|
|
17
|
-
* @param
|
|
19
|
+
* @param file 文件路径或可读stream
|
|
18
20
|
*/
|
|
19
|
-
uploadVoice(file:
|
|
21
|
+
uploadVoice(file: string | Stream.Readable): Promise<any>;
|
|
20
22
|
/**
|
|
21
23
|
* 上传缩略图到临时素材
|
|
22
|
-
* @param
|
|
24
|
+
* @param file 文件路径或可读stream
|
|
23
25
|
*/
|
|
24
|
-
uploadThumb(file:
|
|
26
|
+
uploadThumb(file: string | Stream.Readable): Promise<any>;
|
|
25
27
|
/**
|
|
26
28
|
* 上传到临时素材
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
29
|
+
* @param type 类型,可选值:image,video,voice,thumb
|
|
30
|
+
* @param file 文件路径或可读stream
|
|
29
31
|
*/
|
|
30
|
-
upload(type: string, file:
|
|
32
|
+
upload(type: string, file: string | Stream.Readable): Promise<any>;
|
|
31
33
|
/**
|
|
32
34
|
* 上传群发视频
|
|
33
|
-
* @param
|
|
34
|
-
* @param
|
|
35
|
-
* @param
|
|
35
|
+
* @param file 文件路径或可读stream
|
|
36
|
+
* @param title 标题
|
|
37
|
+
* @param description 描述
|
|
36
38
|
*/
|
|
37
|
-
uploadVideoForBroadcasting(file:
|
|
39
|
+
uploadVideoForBroadcasting(file: string | Stream.Readable, title: string, description: string): Promise<any>;
|
|
38
40
|
/**
|
|
39
41
|
* 创建群发消息
|
|
40
|
-
* @param
|
|
41
|
-
* @param
|
|
42
|
-
* @param
|
|
42
|
+
* @param media_id 上传视频得到 media_id
|
|
43
|
+
* @param title 标题
|
|
44
|
+
* @param description 描述
|
|
43
45
|
*/
|
|
44
46
|
createVideoForBroadcasting(media_id: string, title: string, description: string): Promise<any>;
|
|
45
47
|
/**
|
|
46
48
|
* 获取临时素材内容
|
|
47
|
-
* @param
|
|
49
|
+
* @param media_id 上传视频得到 media_id
|
|
48
50
|
*/
|
|
49
51
|
get(media_id: string): Promise<any>;
|
|
50
52
|
/**
|
|
51
53
|
* 获取 JSSDK 上传的高清语音
|
|
52
|
-
* @param
|
|
54
|
+
* @param media_id 上传视频得到 media_id
|
|
53
55
|
*/
|
|
54
56
|
getJssdkMedia(media_id: string): Promise<any>;
|
|
55
57
|
}
|
|
@@ -23,36 +23,36 @@ class MediaClient extends BaseClient_1.default {
|
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* 上传图片到临时素材
|
|
26
|
-
* @param
|
|
26
|
+
* @param file 文件路径或可读stream
|
|
27
27
|
*/
|
|
28
28
|
uploadImage(file) {
|
|
29
29
|
return this.upload('image', file);
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* 上传视频到临时素材
|
|
33
|
-
* @param
|
|
33
|
+
* @param file 文件路径或可读stream
|
|
34
34
|
*/
|
|
35
35
|
uploadVideo(file) {
|
|
36
36
|
return this.upload('video', file);
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* 上传语音到临时素材
|
|
40
|
-
* @param
|
|
40
|
+
* @param file 文件路径或可读stream
|
|
41
41
|
*/
|
|
42
42
|
uploadVoice(file) {
|
|
43
43
|
return this.upload('voice', file);
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
46
|
* 上传缩略图到临时素材
|
|
47
|
-
* @param
|
|
47
|
+
* @param file 文件路径或可读stream
|
|
48
48
|
*/
|
|
49
49
|
uploadThumb(file) {
|
|
50
50
|
return this.upload('thumb', file);
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* 上传到临时素材
|
|
54
|
-
* @param
|
|
55
|
-
* @param
|
|
54
|
+
* @param type 类型,可选值:image,video,voice,thumb
|
|
55
|
+
* @param file 文件路径或可读stream
|
|
56
56
|
*/
|
|
57
57
|
upload(type, file) {
|
|
58
58
|
if (!file) {
|
|
@@ -69,9 +69,9 @@ class MediaClient extends BaseClient_1.default {
|
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
71
|
* 上传群发视频
|
|
72
|
-
* @param
|
|
73
|
-
* @param
|
|
74
|
-
* @param
|
|
72
|
+
* @param file 文件路径或可读stream
|
|
73
|
+
* @param title 标题
|
|
74
|
+
* @param description 描述
|
|
75
75
|
*/
|
|
76
76
|
uploadVideoForBroadcasting(file, title, description) {
|
|
77
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -84,9 +84,9 @@ class MediaClient extends BaseClient_1.default {
|
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
86
|
* 创建群发消息
|
|
87
|
-
* @param
|
|
88
|
-
* @param
|
|
89
|
-
* @param
|
|
87
|
+
* @param media_id 上传视频得到 media_id
|
|
88
|
+
* @param title 标题
|
|
89
|
+
* @param description 描述
|
|
90
90
|
*/
|
|
91
91
|
createVideoForBroadcasting(media_id, title, description) {
|
|
92
92
|
return this.httpPostJson('media/uploadvideo', {
|
|
@@ -97,7 +97,7 @@ class MediaClient extends BaseClient_1.default {
|
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* 获取临时素材内容
|
|
100
|
-
* @param
|
|
100
|
+
* @param media_id 上传视频得到 media_id
|
|
101
101
|
*/
|
|
102
102
|
get(media_id) {
|
|
103
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -123,7 +123,7 @@ class MediaClient extends BaseClient_1.default {
|
|
|
123
123
|
}
|
|
124
124
|
/**
|
|
125
125
|
* 获取 JSSDK 上传的高清语音
|
|
126
|
-
* @param
|
|
126
|
+
* @param media_id 上传视频得到 media_id
|
|
127
127
|
*/
|
|
128
128
|
getJssdkMedia(media_id) {
|
|
129
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { CipherGCMTypes, BinaryLike, CipherKey } from 'crypto';
|
|
3
|
+
export declare class AES {
|
|
4
|
+
/**
|
|
5
|
+
* 加密
|
|
6
|
+
* @static
|
|
7
|
+
* @param plaintext 待加密文本
|
|
8
|
+
* @param key 密钥
|
|
9
|
+
* @param iv 向量
|
|
10
|
+
* @param autoPadding 自动补位,默认:null,表示不设置
|
|
11
|
+
* @param method 加密方式,默认:'aes-256-cbc'
|
|
12
|
+
*/
|
|
13
|
+
static encrypt(plaintext: BinaryLike, key: CipherKey, iv?: BinaryLike, autoPadding?: boolean, method?: string): Buffer;
|
|
14
|
+
/**
|
|
15
|
+
* 解密
|
|
16
|
+
* @static
|
|
17
|
+
* @param ciphertext 待解密文本,Base64 编码字符串
|
|
18
|
+
* @param key 密钥
|
|
19
|
+
* @param iv 向量
|
|
20
|
+
* @param autoPadding 自动补位,默认:null,表示不设置
|
|
21
|
+
* @param method 加密方式,默认:aes-256-cbc
|
|
22
|
+
*/
|
|
23
|
+
static decrypt(ciphertext: NodeJS.ArrayBufferView, key: BinaryLike, iv?: BinaryLike, autoPadding?: boolean, method?: string): Buffer;
|
|
24
|
+
}
|
|
25
|
+
export declare class AES_GCM {
|
|
26
|
+
/**
|
|
27
|
+
* GCM模式加密
|
|
28
|
+
* @static
|
|
29
|
+
* @param plaintext 待加密文本
|
|
30
|
+
* @param key 密钥
|
|
31
|
+
* @param iv 向量
|
|
32
|
+
* @param aad aad
|
|
33
|
+
* @param method 加密方式,默认:aes-256-gcm
|
|
34
|
+
*/
|
|
35
|
+
static encrypt(plaintext: BinaryLike, key: CipherKey, iv?: BinaryLike, aad?: string, method?: CipherGCMTypes): Buffer;
|
|
36
|
+
/**
|
|
37
|
+
* GCM模式解密
|
|
38
|
+
* @static
|
|
39
|
+
* @param ciphertext 待解密文本,Base64 编码字符串
|
|
40
|
+
* @param key 密钥
|
|
41
|
+
* @param iv 向量
|
|
42
|
+
* @param aad aad
|
|
43
|
+
* @param method 加密方式,默认:aes-256-gcm
|
|
44
|
+
*/
|
|
45
|
+
static decrypt(ciphertext: NodeJS.ArrayBufferView, key: BinaryLike, iv?: BinaryLike, aad?: string, method?: CipherGCMTypes): Buffer;
|
|
46
|
+
}
|
package/dist/Core/AES.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AES_GCM = exports.AES = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
class AES {
|
|
6
|
+
/**
|
|
7
|
+
* 加密
|
|
8
|
+
* @static
|
|
9
|
+
* @param plaintext 待加密文本
|
|
10
|
+
* @param key 密钥
|
|
11
|
+
* @param iv 向量
|
|
12
|
+
* @param autoPadding 自动补位,默认:null,表示不设置
|
|
13
|
+
* @param method 加密方式,默认:'aes-256-cbc'
|
|
14
|
+
*/
|
|
15
|
+
static encrypt(plaintext, key, iv = '', autoPadding = null, method = 'aes-256-cbc') {
|
|
16
|
+
let cipher = crypto_1.createCipheriv(method, key, iv);
|
|
17
|
+
if (typeof autoPadding === 'boolean') {
|
|
18
|
+
cipher.setAutoPadding(autoPadding);
|
|
19
|
+
}
|
|
20
|
+
return Buffer.concat([
|
|
21
|
+
cipher.update(plaintext),
|
|
22
|
+
cipher.final(),
|
|
23
|
+
]);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 解密
|
|
27
|
+
* @static
|
|
28
|
+
* @param ciphertext 待解密文本,Base64 编码字符串
|
|
29
|
+
* @param key 密钥
|
|
30
|
+
* @param iv 向量
|
|
31
|
+
* @param autoPadding 自动补位,默认:null,表示不设置
|
|
32
|
+
* @param method 加密方式,默认:aes-256-cbc
|
|
33
|
+
*/
|
|
34
|
+
static decrypt(ciphertext, key, iv = '', autoPadding = null, method = 'aes-256-cbc') {
|
|
35
|
+
let decipher = crypto_1.createDecipheriv(method, key, iv);
|
|
36
|
+
if (typeof autoPadding === 'boolean') {
|
|
37
|
+
decipher.setAutoPadding(autoPadding);
|
|
38
|
+
}
|
|
39
|
+
if (typeof ciphertext === 'string') {
|
|
40
|
+
ciphertext = Buffer.from(ciphertext, 'base64');
|
|
41
|
+
}
|
|
42
|
+
let deciphered = Buffer.concat([
|
|
43
|
+
decipher.update(ciphertext),
|
|
44
|
+
decipher.final(),
|
|
45
|
+
]);
|
|
46
|
+
return deciphered;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.AES = AES;
|
|
50
|
+
class AES_GCM {
|
|
51
|
+
/**
|
|
52
|
+
* GCM模式加密
|
|
53
|
+
* @static
|
|
54
|
+
* @param plaintext 待加密文本
|
|
55
|
+
* @param key 密钥
|
|
56
|
+
* @param iv 向量
|
|
57
|
+
* @param aad aad
|
|
58
|
+
* @param method 加密方式,默认:aes-256-gcm
|
|
59
|
+
*/
|
|
60
|
+
static encrypt(plaintext, key, iv = '', aad = '', method = 'aes-256-gcm') {
|
|
61
|
+
let cipher = crypto_1.createCipheriv(method, key, iv).setAAD(Buffer.from(aad));
|
|
62
|
+
return Buffer.concat([
|
|
63
|
+
cipher.update(plaintext),
|
|
64
|
+
cipher.final(),
|
|
65
|
+
cipher.getAuthTag(),
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* GCM模式解密
|
|
70
|
+
* @static
|
|
71
|
+
* @param ciphertext 待解密文本,Base64 编码字符串
|
|
72
|
+
* @param key 密钥
|
|
73
|
+
* @param iv 向量
|
|
74
|
+
* @param aad aad
|
|
75
|
+
* @param method 加密方式,默认:aes-256-gcm
|
|
76
|
+
*/
|
|
77
|
+
static decrypt(ciphertext, key, iv = '', aad = '', method = 'aes-256-gcm') {
|
|
78
|
+
let buf = null;
|
|
79
|
+
if (typeof ciphertext === 'string') {
|
|
80
|
+
buf = Buffer.from(ciphertext, 'base64');
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
buf = Buffer.from(ciphertext);
|
|
84
|
+
}
|
|
85
|
+
let tag = buf.slice(-16);
|
|
86
|
+
let payload = buf.slice(0, -16);
|
|
87
|
+
let decipher = crypto_1.createDecipheriv(method, key, iv).setAuthTag(tag).setAAD(Buffer.from(aad));
|
|
88
|
+
return Buffer.concat([
|
|
89
|
+
decipher.update(payload),
|
|
90
|
+
decipher.final(),
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.AES_GCM = AES_GCM;
|
|
95
|
+
;
|
|
@@ -68,11 +68,15 @@ class BaseApplicatioin {
|
|
|
68
68
|
this.offsetSet('config', function (app) {
|
|
69
69
|
return app.getConfig();
|
|
70
70
|
});
|
|
71
|
-
this.log
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
this.offsetSet('log', function (app) {
|
|
72
|
+
return function () {
|
|
73
|
+
if (!app['config']['debug'])
|
|
74
|
+
return true;
|
|
75
|
+
let args = arguments;
|
|
76
|
+
args[0] = 'NodeEasywechat2: ' + args[0];
|
|
77
|
+
return console.log.apply(null, arguments);
|
|
78
|
+
};
|
|
79
|
+
});
|
|
76
80
|
if (!this.request) {
|
|
77
81
|
this.request = new Request_1.default;
|
|
78
82
|
}
|
package/dist/Core/Encryptor.d.ts
CHANGED
|
@@ -7,18 +7,6 @@ export default class Encryptor {
|
|
|
7
7
|
constructor(appId: string, token: string, aesKey: string);
|
|
8
8
|
getToken(): string;
|
|
9
9
|
signature(...args: any[]): string;
|
|
10
|
-
encrypt(text:
|
|
11
|
-
decrypt(text:
|
|
12
|
-
/**
|
|
13
|
-
* 删除解密后明文的补位字符
|
|
14
|
-
* @param {Buffer} text 解密后的明文
|
|
15
|
-
* @return {Buffer}
|
|
16
|
-
*/
|
|
17
|
-
pkcs7Unpad(text: Buffer): Buffer;
|
|
18
|
-
/**
|
|
19
|
-
* 对需要加密的明文进行填充补位
|
|
20
|
-
* @param {Buffer} text 需要进行填充补位操作的明文
|
|
21
|
-
* @return {Buffer}
|
|
22
|
-
*/
|
|
23
|
-
pkcs7Pad(text: Buffer, blockSize: number): Buffer;
|
|
10
|
+
encrypt(text: string, nonce?: string, timestamp?: number): string;
|
|
11
|
+
decrypt(text: string, msgSignature: string, nonce: string, timestamp: number): string;
|
|
24
12
|
}
|