node-easywechat 3.6.3 → 3.7.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.md +7 -0
- package/README.md +25 -0
- package/dist/Channel/AccessToken.d.ts +8 -0
- package/dist/Channel/AccessToken.js +15 -0
- package/dist/Channel/Account.d.ts +4 -0
- package/dist/Channel/Account.js +8 -0
- package/dist/Channel/Application.d.ts +60 -0
- package/dist/Channel/Application.js +125 -0
- package/dist/Channel/Contracts/AccountInterface.d.ts +23 -0
- package/dist/Channel/Contracts/AccountInterface.js +25 -0
- package/dist/Channel/Contracts/ApplicationInterface.d.ts +62 -0
- package/dist/Channel/Contracts/ApplicationInterface.js +55 -0
- package/dist/Channel/Message.d.ts +542 -0
- package/dist/Channel/Message.js +9 -0
- package/dist/Channel/Server.d.ts +91 -0
- package/dist/Channel/Server.js +16 -0
- package/dist/Core/Contracts/ServerInterface.d.ts +3 -3
- package/dist/Core/Contracts/ServerInterface.js +3 -3
- package/dist/Core/Mixins/{DecryptXmlMessageMixin.d.ts → DecryptMessageMixin.d.ts} +2 -2
- package/dist/Core/Mixins/{DecryptXmlMessageMixin.js → DecryptMessageMixin.js} +11 -4
- package/dist/Core/Mixins/HandlersMixin.d.ts +8 -8
- package/dist/Core/Mixins/HandlersMixin.js +8 -8
- package/dist/Core/Mixins/{ResponseXmlMessageMixin.d.ts → ResponseMessageMixin.d.ts} +4 -3
- package/dist/Core/Mixins/{ResponseXmlMessageMixin.js → ResponseMessageMixin.js} +16 -5
- package/dist/OfficialAccount/Server.d.ts +24 -0
- package/dist/OfficialAccount/Server.js +4 -1
- package/dist/Types/global.d.ts +31 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.js +19 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -67,6 +67,13 @@ let app = new OpenWork({
|
|
|
67
67
|
// 配置项
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
+
// 视频号
|
|
71
|
+
const { Channel } = require('node-easywechat');
|
|
72
|
+
// 实例化应用
|
|
73
|
+
let app = new Channel({
|
|
74
|
+
// 配置项
|
|
75
|
+
});
|
|
76
|
+
|
|
70
77
|
// ----- 定义配置项(v3.5.0+) -----
|
|
71
78
|
|
|
72
79
|
// 这种方式可以让你在需要单独设置配置项时,也能获得编辑器的代码提示
|
|
@@ -80,6 +87,7 @@ const config = defineOfficialAccountConfig({
|
|
|
80
87
|
// 开放平台: defineOpenPlatformConfig()
|
|
81
88
|
// 企业微信: defineWorkConfig()
|
|
82
89
|
// 企业微信开放平台: defineOpenWorkConfig()
|
|
90
|
+
// 视频号: defineChannelConfig()
|
|
83
91
|
|
|
84
92
|
// ----- 以下为通用的 api 调用方法 -----
|
|
85
93
|
|
|
@@ -229,6 +237,22 @@ let data = response.toObject();
|
|
|
229
237
|
}
|
|
230
238
|
```
|
|
231
239
|
|
|
240
|
+
``` js
|
|
241
|
+
// 视频号配置
|
|
242
|
+
{
|
|
243
|
+
// 视频号的 app key
|
|
244
|
+
app_id: '',
|
|
245
|
+
// 视频号的 app secret
|
|
246
|
+
secret: '',
|
|
247
|
+
// 视频号的 token
|
|
248
|
+
token: '',
|
|
249
|
+
// EncodingAESKey
|
|
250
|
+
aes_key: '',
|
|
251
|
+
// 是否使用稳定版接口调用凭据,默认:false
|
|
252
|
+
use_stable_access_token: false
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
232
256
|
### 自定义模块(模块替换)使用方法
|
|
233
257
|
|
|
234
258
|
#### 日志模块
|
|
@@ -345,4 +369,5 @@ app.setRequest(request);
|
|
|
345
369
|
- [x] 开放平台
|
|
346
370
|
- [x] 企业微信
|
|
347
371
|
- [x] 企业微信开放平台
|
|
372
|
+
- [x] 视频号
|
|
348
373
|
- [x] 自定义
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const AccessToken_1 = __importDefault(require("../OfficialAccount/AccessToken"));
|
|
6
|
+
class AccessToken extends AccessToken_1.default {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
/**
|
|
10
|
+
* 缓存前缀
|
|
11
|
+
*/
|
|
12
|
+
this.CACHE_KEY_PREFIX = 'channel';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
module.exports = AccessToken;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const Account_1 = __importDefault(require("../OfficialAccount/Account"));
|
|
6
|
+
class Account extends Account_1.default {
|
|
7
|
+
}
|
|
8
|
+
module.exports = Account;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import ConfigInterface from '../Core/Contracts/ConfigInterface';
|
|
2
|
+
import Encryptor from '../Core/Encryptor';
|
|
3
|
+
import AccessTokenAwareClient from '../Core/HttpClient/AccessTokenAwareClient';
|
|
4
|
+
import CacheMixin from '../Core/Mixins/CacheMixin';
|
|
5
|
+
import ClientMixin from '../Core/Mixins/ClientMixin';
|
|
6
|
+
import ConfigMixin from '../Core/Mixins/ConfigMixin';
|
|
7
|
+
import HttpClientMixin from '../Core/Mixins/HttpClientMixin';
|
|
8
|
+
import ServerRequestMixin from '../Core/Mixins/ServerRequestMixin';
|
|
9
|
+
import { ChannelConfig } from '../Types/global';
|
|
10
|
+
import AccountInterface from './Contracts/AccountInterface';
|
|
11
|
+
import ApplicationInterface from './Contracts/ApplicationInterface';
|
|
12
|
+
import Server from './Server';
|
|
13
|
+
import AccessTokenInterface from '../Core/Contracts/AccessTokenInterface';
|
|
14
|
+
/**
|
|
15
|
+
* 视频号应用
|
|
16
|
+
*/
|
|
17
|
+
declare class Application implements ApplicationInterface {
|
|
18
|
+
constructor(config: ConfigInterface | ChannelConfig);
|
|
19
|
+
protected account: AccountInterface;
|
|
20
|
+
protected encryptor: Encryptor;
|
|
21
|
+
protected server: Server;
|
|
22
|
+
protected accessToken: AccessTokenInterface;
|
|
23
|
+
getAccount(): AccountInterface;
|
|
24
|
+
/**
|
|
25
|
+
* 设置当前账户实例
|
|
26
|
+
* @param account
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
setAccount(account: AccountInterface): this;
|
|
30
|
+
getEncryptor(): Encryptor;
|
|
31
|
+
/**
|
|
32
|
+
* 设置加密机实例
|
|
33
|
+
* @param encryptor
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
setEncryptor(encryptor: Encryptor): this;
|
|
37
|
+
getServer(): Server;
|
|
38
|
+
/**
|
|
39
|
+
* 设置服务端实例
|
|
40
|
+
* @param server
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
setServer(server: Server): this;
|
|
44
|
+
getAccessToken(): AccessTokenInterface;
|
|
45
|
+
/**
|
|
46
|
+
* 设置AccessToken实例
|
|
47
|
+
* @param accessToken
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
setAccessToken(accessToken: AccessTokenInterface): this;
|
|
51
|
+
createClient(): AccessTokenAwareClient;
|
|
52
|
+
/**
|
|
53
|
+
* 获取请求默认配置
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
protected getHttpClientDefaultOptions(): Record<string, any>;
|
|
57
|
+
}
|
|
58
|
+
interface Application extends ConfigMixin, CacheMixin, ClientMixin, ServerRequestMixin, HttpClientMixin {
|
|
59
|
+
}
|
|
60
|
+
export = Application;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const merge_1 = __importDefault(require("merge"));
|
|
6
|
+
const ConfigInterface_1 = __importDefault(require("../Core/Contracts/ConfigInterface"));
|
|
7
|
+
const Encryptor_1 = __importDefault(require("../Core/Encryptor"));
|
|
8
|
+
const AccessTokenAwareClient_1 = __importDefault(require("../Core/HttpClient/AccessTokenAwareClient"));
|
|
9
|
+
const CacheMixin_1 = __importDefault(require("../Core/Mixins/CacheMixin"));
|
|
10
|
+
const ClientMixin_1 = __importDefault(require("../Core/Mixins/ClientMixin"));
|
|
11
|
+
const ConfigMixin_1 = __importDefault(require("../Core/Mixins/ConfigMixin"));
|
|
12
|
+
const HttpClientMixin_1 = __importDefault(require("../Core/Mixins/HttpClientMixin"));
|
|
13
|
+
const ServerRequestMixin_1 = __importDefault(require("../Core/Mixins/ServerRequestMixin"));
|
|
14
|
+
const Utils_1 = require("../Core/Support/Utils");
|
|
15
|
+
const AccessToken_1 = __importDefault(require("./AccessToken"));
|
|
16
|
+
const Account_1 = __importDefault(require("./Account"));
|
|
17
|
+
const Server_1 = __importDefault(require("./Server"));
|
|
18
|
+
const Config_1 = __importDefault(require("../OfficialAccount/Config"));
|
|
19
|
+
/**
|
|
20
|
+
* 视频号应用
|
|
21
|
+
*/
|
|
22
|
+
class Application {
|
|
23
|
+
constructor(config) {
|
|
24
|
+
this.account = null;
|
|
25
|
+
this.encryptor = null;
|
|
26
|
+
this.server = null;
|
|
27
|
+
this.accessToken = null;
|
|
28
|
+
if (config instanceof ConfigInterface_1.default) {
|
|
29
|
+
this.setConfig(config);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
this.setConfig(new Config_1.default(config));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
getAccount() {
|
|
36
|
+
if (!this.account) {
|
|
37
|
+
this.account = new Account_1.default(this.config.get('app_id'), this.config.get('secret'), this.config.get('token'), this.config.get('aes_key'));
|
|
38
|
+
}
|
|
39
|
+
return this.account;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 设置当前账户实例
|
|
43
|
+
* @param account
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
setAccount(account) {
|
|
47
|
+
this.account = account;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
getEncryptor() {
|
|
51
|
+
if (!this.encryptor) {
|
|
52
|
+
let token = this.getAccount().getToken();
|
|
53
|
+
let aesKey = this.getAccount().getAesKey();
|
|
54
|
+
if (!token || !aesKey) {
|
|
55
|
+
throw new Error('token or aes_key cannot be empty.');
|
|
56
|
+
}
|
|
57
|
+
this.encryptor = new Encryptor_1.default(this.getAccount().getAppId(), token, aesKey, this.getAccount().getAppId());
|
|
58
|
+
}
|
|
59
|
+
return this.encryptor;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 设置加密机实例
|
|
63
|
+
* @param encryptor
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
setEncryptor(encryptor) {
|
|
67
|
+
this.encryptor = encryptor;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
getServer() {
|
|
71
|
+
if (!this.server) {
|
|
72
|
+
let token = this.getAccount().getToken();
|
|
73
|
+
let aesKey = this.getAccount().getAesKey();
|
|
74
|
+
if (!token || !aesKey) {
|
|
75
|
+
throw new Error('token or aes_key cannot be empty.');
|
|
76
|
+
}
|
|
77
|
+
this.server = new Server_1.default(this.getRequest(), this.getAccount().getAesKey() ? this.getEncryptor() : null);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
this.server.setRequest(this.getRequest());
|
|
81
|
+
}
|
|
82
|
+
return this.server;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 设置服务端实例
|
|
86
|
+
* @param server
|
|
87
|
+
* @returns
|
|
88
|
+
*/
|
|
89
|
+
setServer(server) {
|
|
90
|
+
this.server = server;
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
getAccessToken() {
|
|
94
|
+
if (!this.accessToken) {
|
|
95
|
+
this.accessToken = new AccessToken_1.default(this.getAccount().getAppId(), this.getAccount().getSecret(), null, this.getCache(), this.getHttpClient(), this.config.get('use_stable_access_token', false));
|
|
96
|
+
}
|
|
97
|
+
return this.accessToken;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 设置AccessToken实例
|
|
101
|
+
* @param accessToken
|
|
102
|
+
* @returns
|
|
103
|
+
*/
|
|
104
|
+
setAccessToken(accessToken) {
|
|
105
|
+
this.accessToken = accessToken;
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
createClient() {
|
|
109
|
+
return (new AccessTokenAwareClient_1.default(this.getHttpClient(), this.getAccessToken(), (response) => { var _a; return ((_a = response.toObject()['errcode']) !== null && _a !== void 0 ? _a : 0) || (response.toObject()['error'] !== null && response.toObject()['error'] !== undefined); }, this.getConfig().get('http.throw', true)))
|
|
110
|
+
.setPresets(this.getConfig().all());
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 获取请求默认配置
|
|
114
|
+
* @returns
|
|
115
|
+
*/
|
|
116
|
+
getHttpClientDefaultOptions() {
|
|
117
|
+
return (0, merge_1.default)(true, {
|
|
118
|
+
baseURL: 'https://api.weixin.qq.com/',
|
|
119
|
+
}, this.getConfig().get('http'));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
;
|
|
123
|
+
;
|
|
124
|
+
(0, Utils_1.applyMixins)(Application, [ConfigMixin_1.default, CacheMixin_1.default, ClientMixin_1.default, ServerRequestMixin_1.default, HttpClientMixin_1.default]);
|
|
125
|
+
module.exports = Application;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare abstract class AccountInterface {
|
|
2
|
+
/**
|
|
3
|
+
* 获取appid
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
getAppId(): string;
|
|
7
|
+
/**
|
|
8
|
+
* 获取secret
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
getSecret(): string;
|
|
12
|
+
/**
|
|
13
|
+
* 获取token
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
getToken(): string;
|
|
17
|
+
/**
|
|
18
|
+
* 获取aesKey
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
getAesKey(): string;
|
|
22
|
+
}
|
|
23
|
+
export = AccountInterface;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
class AccountInterface {
|
|
3
|
+
/**
|
|
4
|
+
* 获取appid
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
getAppId() { return null; }
|
|
8
|
+
/**
|
|
9
|
+
* 获取secret
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
getSecret() { return null; }
|
|
13
|
+
/**
|
|
14
|
+
* 获取token
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
getToken() { return null; }
|
|
18
|
+
/**
|
|
19
|
+
* 获取aesKey
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
getAesKey() { return null; }
|
|
23
|
+
}
|
|
24
|
+
;
|
|
25
|
+
module.exports = AccountInterface;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import CacheInterface from "../../Core/Contracts/CacheInterface";
|
|
2
|
+
import ConfigInterface from "../../Core/Contracts/ConfigInterface";
|
|
3
|
+
import AccessTokenAwareClient from "../../Core/HttpClient/AccessTokenAwareClient";
|
|
4
|
+
import HttpClientInterface from "../../Core/HttpClient/Contracts/HttpClientInterface";
|
|
5
|
+
import ServerInterface from "../../Core/Contracts/ServerInterface";
|
|
6
|
+
import ServerRequestInterface from "../../Core/Http/Contracts/ServerRequestInterface";
|
|
7
|
+
import Encryptor from "../../Core/Encryptor";
|
|
8
|
+
import AccountInterface from "./AccountInterface";
|
|
9
|
+
import AccessTokenInterface from "../../Core/Contracts/AccessTokenInterface";
|
|
10
|
+
declare abstract class ApplicationInterface {
|
|
11
|
+
/**
|
|
12
|
+
* 获取当前账户实例
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
getAccount(): AccountInterface;
|
|
16
|
+
/**
|
|
17
|
+
* 获取加密机实例
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
getEncryptor(): Encryptor;
|
|
21
|
+
/**
|
|
22
|
+
* 获取服务端实例
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
getServer(): ServerInterface;
|
|
26
|
+
/**
|
|
27
|
+
* 获取当前请求实例
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
getRequest(): ServerRequestInterface;
|
|
31
|
+
/**
|
|
32
|
+
* 获取客户端实例
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
getClient(): AccessTokenAwareClient;
|
|
36
|
+
/**
|
|
37
|
+
* 创建客户端实例
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
createClient(): AccessTokenAwareClient;
|
|
41
|
+
/**
|
|
42
|
+
* 获取网络请求客户端实例
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
getHttpClient(): HttpClientInterface;
|
|
46
|
+
/**
|
|
47
|
+
* 获取配置信息实例
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
getConfig(): ConfigInterface;
|
|
51
|
+
/**
|
|
52
|
+
* 获取AccessToken实例
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
getAccessToken(): AccessTokenInterface;
|
|
56
|
+
/**
|
|
57
|
+
* 获取缓存实例
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
getCache(): CacheInterface;
|
|
61
|
+
}
|
|
62
|
+
export = ApplicationInterface;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
class ApplicationInterface {
|
|
3
|
+
/**
|
|
4
|
+
* 获取当前账户实例
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
getAccount() { return null; }
|
|
8
|
+
/**
|
|
9
|
+
* 获取加密机实例
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
getEncryptor() { return null; }
|
|
13
|
+
/**
|
|
14
|
+
* 获取服务端实例
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
getServer() { return null; }
|
|
18
|
+
/**
|
|
19
|
+
* 获取当前请求实例
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
getRequest() { return null; }
|
|
23
|
+
/**
|
|
24
|
+
* 获取客户端实例
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
getClient() { return null; }
|
|
28
|
+
/**
|
|
29
|
+
* 创建客户端实例
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
createClient() { return null; }
|
|
33
|
+
/**
|
|
34
|
+
* 获取网络请求客户端实例
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
getHttpClient() { return null; }
|
|
38
|
+
/**
|
|
39
|
+
* 获取配置信息实例
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
getConfig() { return null; }
|
|
43
|
+
/**
|
|
44
|
+
* 获取AccessToken实例
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
getAccessToken() { return null; }
|
|
48
|
+
/**
|
|
49
|
+
* 获取缓存实例
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
getCache() { return null; }
|
|
53
|
+
}
|
|
54
|
+
;
|
|
55
|
+
module.exports = ApplicationInterface;
|