node-easywechat 2.8.0 → 2.9.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/README.md +51 -4
- package/dist/BaseService/Jssdk/JssdkClient.js +5 -5
- package/dist/BaseService/Media/MediaClient.js +1 -1
- package/dist/Core/AES.d.ts +1 -1
- package/dist/Core/AES.js +4 -4
- package/dist/Core/BaseAccessToken.js +2 -2
- package/dist/Core/BaseApplication.js +4 -4
- package/dist/Core/BaseClient.js +2 -2
- package/dist/Core/Cache/FileCache.js +3 -3
- package/dist/Core/Encryptor.js +3 -3
- package/dist/Core/Http/Request.js +13 -13
- package/dist/Core/Http/StreamResponse.js +1 -1
- package/dist/Core/Messages/Media.js +2 -2
- package/dist/Core/Messages/Message.js +7 -7
- package/dist/Core/Mixins/HttpMixin.js +4 -4
- package/dist/Core/ServerGuard.d.ts +2 -2
- package/dist/Core/ServerGuard.js +5 -5
- package/dist/Core/Types.d.ts +34 -4
- package/dist/Core/Utils.js +18 -18
- package/dist/MicroMerchant/Application.js +1 -1
- package/dist/MicroMerchant/Base/MicroMerchantBase.js +6 -6
- package/dist/MicroMerchant/Certficates/CertficatesClient.js +1 -1
- package/dist/MicroMerchant/Core/BaseClient.js +8 -8
- package/dist/MicroMerchant/Media/MediaClient.js +1 -1
- package/dist/MicroMerchant/MerchantConfig/MerchantConfigClient.js +1 -1
- package/dist/MicroMerchant/Meterial/MeterialClient.js +4 -4
- package/dist/MicroMerchant/Withdraw/WithdrawClient.js +2 -2
- package/dist/MiniProgram/ActivityMessage/ActivityMessageClient.js +3 -3
- package/dist/MiniProgram/AppCode/AppCodeClient.js +2 -2
- package/dist/MiniProgram/Application.d.ts +16 -0
- package/dist/MiniProgram/Application.js +40 -0
- package/dist/MiniProgram/Base/MiniProgramBase.js +1 -1
- package/dist/MiniProgram/NearbyPoi/NearbyPoiClient.js +3 -3
- package/dist/MiniProgram/OpenData/OpenDataClient.js +2 -2
- package/dist/MiniProgram/RealtimeLog/RealtimeLogClient.js +1 -1
- package/dist/MiniProgram/Shop/AccoutClient.d.ts +25 -0
- package/dist/MiniProgram/Shop/AccoutClient.js +42 -0
- package/dist/MiniProgram/Shop/AftersaleClient.d.ts +22 -0
- package/dist/MiniProgram/Shop/AftersaleClient.js +35 -0
- package/dist/MiniProgram/Shop/BasicClient.d.ts +39 -0
- package/dist/MiniProgram/Shop/BasicClient.js +69 -0
- package/dist/MiniProgram/Shop/DeliveryClient.d.ts +20 -0
- package/dist/MiniProgram/Shop/DeliveryClient.js +32 -0
- package/dist/MiniProgram/Shop/OrderClient.d.ts +32 -0
- package/dist/MiniProgram/Shop/OrderClient.js +51 -0
- package/dist/MiniProgram/Shop/RegisterClient.d.ts +25 -0
- package/dist/MiniProgram/Shop/RegisterClient.js +43 -0
- package/dist/MiniProgram/Shop/SpuClient.d.ts +67 -0
- package/dist/MiniProgram/Shop/SpuClient.js +92 -0
- package/dist/MiniProgram/ShortLink/ShortLinkClient.d.ts +11 -0
- package/dist/MiniProgram/ShortLink/ShortLinkClient.js +23 -0
- package/dist/MiniProgram/SubscribeMessage/SubscribeMessageClient.js +5 -5
- package/dist/MiniProgram/UniformMessage/UniformMessageClient.js +3 -3
- package/dist/MiniProgram/UrlLink/UrlLinkClient.d.ts +6 -1
- package/dist/MiniProgram/UrlLink/UrlLinkClient.js +7 -2
- package/dist/OfficialAccount/Base/OfficialAccountBase.js +2 -2
- package/dist/OfficialAccount/Broadcasting/BroadcastingClient.js +2 -2
- package/dist/OfficialAccount/Broadcasting/MessageBuilder.js +1 -1
- package/dist/OfficialAccount/Card/Client.js +1 -1
- package/dist/OfficialAccount/Card/JssdkClient.js +2 -2
- package/dist/OfficialAccount/Card/MemberCardClient.js +1 -1
- package/dist/OfficialAccount/CustomerService/CustomerServiceClient.js +2 -2
- package/dist/OfficialAccount/CustomerService/Messenger.js +1 -1
- package/dist/OfficialAccount/DataCube/DataCubeClient.js +1 -1
- package/dist/OfficialAccount/Material/MaterialClient.js +2 -2
- package/dist/OfficialAccount/OCR/OCRClient.js +1 -1
- package/dist/OfficialAccount/Semantic/SemanticClient.js +1 -1
- package/dist/OfficialAccount/SubscribeMessage/SubscribeMessageClient.js +4 -4
- package/dist/OfficialAccount/TemplateMessage/TemplateMessageClient.js +4 -4
- package/dist/OpenPlatform/Application.js +8 -8
- package/dist/OpenPlatform/Authorizer/Auth/AccessToken.js +1 -1
- package/dist/OpenPlatform/Authorizer/OfficialAccount/Account/Client.js +1 -1
- package/dist/OpenWork/Application.d.ts +37 -0
- package/dist/OpenWork/Application.js +128 -0
- package/dist/OpenWork/Auth/ProviderAccessToken.d.ts +8 -0
- package/dist/OpenWork/Auth/ProviderAccessToken.js +33 -0
- package/dist/OpenWork/Auth/SuiteAccessToken.d.ts +8 -0
- package/dist/OpenWork/Auth/SuiteAccessToken.js +34 -0
- package/dist/OpenWork/Auth/SuiteTicket.d.ts +8 -0
- package/dist/OpenWork/Auth/SuiteTicket.js +40 -0
- package/dist/OpenWork/Corp/CorpClient.d.ts +72 -0
- package/dist/OpenWork/Corp/CorpClient.js +150 -0
- package/dist/OpenWork/MiniProgram/MiniProgramClient.d.ts +5 -0
- package/dist/OpenWork/MiniProgram/MiniProgramClient.js +18 -0
- package/dist/OpenWork/Provider/ProviderClient.d.ts +81 -0
- package/dist/OpenWork/Provider/ProviderClient.js +172 -0
- package/dist/OpenWork/Server/OpenWorkGuard.d.ts +13 -0
- package/dist/OpenWork/Server/OpenWorkGuard.js +51 -0
- package/dist/OpenWork/Work/Application.d.ts +5 -0
- package/dist/OpenWork/Work/Application.js +22 -0
- package/dist/OpenWork/Work/Auth/AccessToken.d.ts +12 -0
- package/dist/OpenWork/Work/Auth/AccessToken.js +44 -0
- package/dist/Payment/Application.js +4 -4
- package/dist/Payment/Bill/BillClient.js +2 -2
- package/dist/Payment/Core/BaseClient.js +8 -8
- package/dist/Payment/Jssdk/JssdkClient.js +14 -14
- package/dist/Payment/Merchant/MerchantClient.js +1 -1
- package/dist/Payment/Notify/Handler.js +5 -5
- package/dist/Payment/Notify/Refunded.js +1 -1
- package/dist/Payment/Notify/Scanned.js +2 -2
- package/dist/Payment/Order/OrderClient.js +1 -1
- package/dist/Payment/Redpack/RedpackClient.js +5 -5
- package/dist/Payment/Refund/RefundClient.js +3 -3
- package/dist/Payment/Sandbox/SandboxClient.js +1 -1
- package/dist/Payment/Transfer/TransferClient.js +1 -1
- package/dist/Work/Agent/AgentClient.js +1 -1
- package/dist/Work/Agent/WorkbenchClient.d.ts +24 -0
- package/dist/Work/Agent/WorkbenchClient.js +39 -0
- package/dist/Work/Application.d.ts +8 -0
- package/dist/Work/Application.js +20 -0
- package/dist/Work/Calendar/CalendarClient.js +1 -1
- package/dist/Work/Chat/ChatClient.js +1 -1
- package/dist/Work/CorpGroup/CorpGroupClient.d.ts +34 -0
- package/dist/Work/CorpGroup/CorpGroupClient.js +42 -0
- package/dist/Work/Department/DepartmentClient.js +1 -1
- package/dist/Work/ExternalContact/Client.d.ts +56 -0
- package/dist/Work/ExternalContact/Client.js +88 -0
- package/dist/Work/ExternalContact/ContactWayClient.d.ts +37 -0
- package/dist/Work/ExternalContact/ContactWayClient.js +51 -2
- package/dist/Work/ExternalContact/MessageClient.js +4 -4
- package/dist/Work/ExternalContact/MessageTemplateClient.js +3 -3
- package/dist/Work/ExternalContact/MomentClient.d.ts +56 -3
- package/dist/Work/ExternalContact/MomentClient.js +62 -3
- package/dist/Work/ExternalContact/StatisticsClient.d.ts +24 -0
- package/dist/Work/ExternalContact/StatisticsClient.js +35 -0
- package/dist/Work/Jssdk/JssdkClient.js +3 -3
- package/dist/Work/Kf/KfAccountClient.d.ts +41 -0
- package/dist/Work/Kf/KfAccountClient.js +71 -0
- package/dist/Work/Kf/KfMessageClient.d.ts +44 -0
- package/dist/Work/Kf/KfMessageClient.js +73 -0
- package/dist/Work/Kf/KfServicerClient.d.ts +26 -0
- package/dist/Work/Kf/KfServicerClient.js +47 -0
- package/dist/Work/Media/MediaClient.js +1 -1
- package/dist/Work/Message/Messenger.js +2 -2
- package/dist/Work/Schedule/ScheduleClient.js +1 -1
- package/dist/Work/Server/Guard.d.ts +1 -1
- package/dist/Work/User/UserClient.js +3 -3
- package/dist/index.d.ts +8 -2
- package/dist/index.js +9 -7
- 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 +11 -11
package/README.md
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
[](https://app.travis-ci.com/hpyer/node-easywechat) [](https://www.npmjs.com/package/node-easywechat) [](LICENSE)
|
|
5
5
|
|
|
6
|
-
**注:2.x分支针对 EasyWechat 的 5.x版本(由于4.x与5.x的结构基本一致,就不升级大版本了)
|
|
6
|
+
**注:2.x分支针对 EasyWechat 的 5.x版本(由于4.x与5.x的结构基本一致,就不升级大版本了)。**
|
|
7
7
|
|
|
8
|
-
[
|
|
8
|
+
~~若您需要 EasyWechat 的 3.x版本,请切换到 [1.x](https://github.com/hpyer/node-easywechat/tree/1.x) 分支。~~ **1.0版本已废弃**
|
|
9
|
+
|
|
10
|
+
[EasyWechat](https://github.com/w7corp/easywechat) 是一个由 `安正超` 大神用 PHP 开发的开源的微信非官方 SDK(现由微擎团队团队维护)。其功能强大,使用方便,个人一直很喜欢,所以近日将其在 Node.js 上实现。本人会尽量还原其配置项以及接口的调用方式,但毕竟语言环境不同,具体的实现方式会有些许差别,还请各位开发者见谅。
|
|
9
11
|
|
|
10
12
|
> 注:虽然也使用了 EasyWechat 这个名称,但是和 `安正超` 大神没有任何关系,请各位开发者不要因使用本包产生的疑惑而去打扰大神,如有疑问请在本项目中提 issue,谢谢~
|
|
11
13
|
|
|
@@ -36,7 +38,7 @@ let payment = new EasyWechat.Factory.Payment({
|
|
|
36
38
|
// ...
|
|
37
39
|
});
|
|
38
40
|
|
|
39
|
-
//
|
|
41
|
+
// 开放平台
|
|
40
42
|
let openPlatform = new EasyWechat.Factory.OpenPlatform({
|
|
41
43
|
// ...
|
|
42
44
|
});
|
|
@@ -51,6 +53,11 @@ let microMerchant = new EasyWechat.Factory.MicroMerchant({
|
|
|
51
53
|
// ...
|
|
52
54
|
});
|
|
53
55
|
|
|
56
|
+
// 企业微信开放平台
|
|
57
|
+
let openWork = new EasyWechat.Factory.OpenWork({
|
|
58
|
+
// ...
|
|
59
|
+
});
|
|
60
|
+
|
|
54
61
|
// 通用方式
|
|
55
62
|
let app = EasyWechat.Factory.getInstance('OficialAccount', {
|
|
56
63
|
// ...
|
|
@@ -147,6 +154,46 @@ let app = EasyWechat.Factory.getInstance('OficialAccount', {
|
|
|
147
154
|
}
|
|
148
155
|
```
|
|
149
156
|
|
|
157
|
+
``` js
|
|
158
|
+
// 开放平台
|
|
159
|
+
{
|
|
160
|
+
// 开放平台APPID
|
|
161
|
+
app_id: 'your-app-id',
|
|
162
|
+
// 开放平台Secret
|
|
163
|
+
secret: 'your-secret',
|
|
164
|
+
// 开放平台Token
|
|
165
|
+
token: 'your-token',
|
|
166
|
+
// 开放平台AES KEY
|
|
167
|
+
aes_key: 'your-aes_key',
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
``` js
|
|
172
|
+
// 企业微信开放平台
|
|
173
|
+
{
|
|
174
|
+
// 服务商的corpid
|
|
175
|
+
corp_id: 'your-corp_id',
|
|
176
|
+
// 服务商的secret
|
|
177
|
+
secret: 'your-secret',
|
|
178
|
+
// 应用id
|
|
179
|
+
suite_id: 'your-suite_id',
|
|
180
|
+
// 应用secret
|
|
181
|
+
suite_secret: 'your-suite_secret',
|
|
182
|
+
// 应用Token
|
|
183
|
+
token: 'your-token',
|
|
184
|
+
// 应用AESKey
|
|
185
|
+
aes_key: 'your-aes_key',
|
|
186
|
+
// 注册定制化模板ID
|
|
187
|
+
reg_template_id: 'your-tpl_id',
|
|
188
|
+
// 安装应用的回调url(可选)
|
|
189
|
+
redirect_uri_install: 'your-uri_install',
|
|
190
|
+
// 单点登录回调url(可选)
|
|
191
|
+
redirect_uri_single: 'your-uri_single',
|
|
192
|
+
// 网页授权第三方回调url(可选)
|
|
193
|
+
redirect_uri_oauth: 'your-uri_oauth',
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
150
197
|
### 模块支持情况
|
|
151
198
|
|
|
152
199
|
- [x] 公众号模块
|
|
@@ -154,7 +201,7 @@ let app = EasyWechat.Factory.getInstance('OficialAccount', {
|
|
|
154
201
|
- [x] 小程序
|
|
155
202
|
- [x] 开放平台
|
|
156
203
|
- [x] 企业微信
|
|
157
|
-
- [
|
|
204
|
+
- [x] 企业微信开放平台
|
|
158
205
|
- [x] 小微商户
|
|
159
206
|
- [x] 自定义
|
|
160
207
|
|
|
@@ -55,7 +55,7 @@ class Client extends BaseClient_1.default {
|
|
|
55
55
|
*/
|
|
56
56
|
buildConfig(jsApiList, debug = false, beta = false, json = true, openTagList = [], url = '') {
|
|
57
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
let config = Utils_1.merge({
|
|
58
|
+
let config = (0, Utils_1.merge)({
|
|
59
59
|
jsApiList, debug, beta, openTagList
|
|
60
60
|
}, yield this.configSignature(url));
|
|
61
61
|
return json ? JSON.stringify(config) : config;
|
|
@@ -81,8 +81,8 @@ class Client extends BaseClient_1.default {
|
|
|
81
81
|
configSignature(url = '', nonce = '', timestamp = '') {
|
|
82
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
83
|
url = url || this.getUrl();
|
|
84
|
-
nonce = nonce || Utils_1.randomString(10);
|
|
85
|
-
timestamp = timestamp || Utils_1.getTimestamp() + '';
|
|
84
|
+
nonce = nonce || (0, Utils_1.randomString)(10);
|
|
85
|
+
timestamp = timestamp || (0, Utils_1.getTimestamp)() + '';
|
|
86
86
|
let ticket = yield this.getTicket();
|
|
87
87
|
return {
|
|
88
88
|
appId: this.getAppId(),
|
|
@@ -94,7 +94,7 @@ class Client extends BaseClient_1.default {
|
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
getTicketSignature(ticket, nonce, timestamp, url) {
|
|
97
|
-
return Utils_1.createHash(`jsapi_ticket=${ticket}&noncestr=${nonce}×tamp=${timestamp}&url=${url}`, 'sha1');
|
|
97
|
+
return (0, Utils_1.createHash)(`jsapi_ticket=${ticket}&noncestr=${nonce}×tamp=${timestamp}&url=${url}`, 'sha1');
|
|
98
98
|
}
|
|
99
99
|
dictionaryOrderSignature(args) {
|
|
100
100
|
let params = [];
|
|
@@ -102,7 +102,7 @@ class Client extends BaseClient_1.default {
|
|
|
102
102
|
params.push(args[i]);
|
|
103
103
|
}
|
|
104
104
|
params.sort();
|
|
105
|
-
return Utils_1.createHash(params.join(''), 'sha1');
|
|
105
|
+
return (0, Utils_1.createHash)(params.join(''), 'sha1');
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
108
|
* 设置当前URL
|
|
@@ -58,7 +58,7 @@ class MediaClient extends BaseClient_1.default {
|
|
|
58
58
|
if (!file) {
|
|
59
59
|
throw new Error(`File does not exist, or the file is unreadable: '${file}'`);
|
|
60
60
|
}
|
|
61
|
-
if (!Utils_1.inArray(type, this.allowTypes)) {
|
|
61
|
+
if (!(0, Utils_1.inArray)(type, this.allowTypes)) {
|
|
62
62
|
throw new Error(`Unsupported media type: '${type}'`);
|
|
63
63
|
}
|
|
64
64
|
return this.httpUpload('media/upload', {
|
package/dist/Core/AES.d.ts
CHANGED
|
@@ -42,5 +42,5 @@ export declare class AES_GCM {
|
|
|
42
42
|
* @param aad aad
|
|
43
43
|
* @param method 加密方式,默认:aes-256-gcm
|
|
44
44
|
*/
|
|
45
|
-
static decrypt(ciphertext:
|
|
45
|
+
static decrypt(ciphertext: WithImplicitCoercion<ArrayBuffer | SharedArrayBuffer>, key: BinaryLike, iv?: BinaryLike, aad?: string, method?: CipherGCMTypes): Buffer;
|
|
46
46
|
}
|
package/dist/Core/AES.js
CHANGED
|
@@ -13,7 +13,7 @@ class AES {
|
|
|
13
13
|
* @param method 加密方式,默认:'aes-256-cbc'
|
|
14
14
|
*/
|
|
15
15
|
static encrypt(plaintext, key, iv = '', autoPadding = null, method = 'aes-256-cbc') {
|
|
16
|
-
let cipher = crypto_1.createCipheriv(method, key, iv);
|
|
16
|
+
let cipher = (0, crypto_1.createCipheriv)(method, key, iv);
|
|
17
17
|
if (typeof autoPadding === 'boolean') {
|
|
18
18
|
cipher.setAutoPadding(autoPadding);
|
|
19
19
|
}
|
|
@@ -32,7 +32,7 @@ class AES {
|
|
|
32
32
|
* @param method 加密方式,默认:aes-256-cbc
|
|
33
33
|
*/
|
|
34
34
|
static decrypt(ciphertext, key, iv = '', autoPadding = null, method = 'aes-256-cbc') {
|
|
35
|
-
let decipher = crypto_1.createDecipheriv(method, key, iv);
|
|
35
|
+
let decipher = (0, crypto_1.createDecipheriv)(method, key, iv);
|
|
36
36
|
if (typeof autoPadding === 'boolean') {
|
|
37
37
|
decipher.setAutoPadding(autoPadding);
|
|
38
38
|
}
|
|
@@ -58,7 +58,7 @@ class AES_GCM {
|
|
|
58
58
|
* @param method 加密方式,默认:aes-256-gcm
|
|
59
59
|
*/
|
|
60
60
|
static encrypt(plaintext, key, iv = '', aad = '', method = 'aes-256-gcm') {
|
|
61
|
-
let cipher = crypto_1.createCipheriv(method, key, iv).setAAD(Buffer.from(aad));
|
|
61
|
+
let cipher = (0, crypto_1.createCipheriv)(method, key, iv).setAAD(Buffer.from(aad));
|
|
62
62
|
return Buffer.concat([
|
|
63
63
|
cipher.update(plaintext),
|
|
64
64
|
cipher.final(),
|
|
@@ -84,7 +84,7 @@ class AES_GCM {
|
|
|
84
84
|
}
|
|
85
85
|
let tag = buf.slice(-16);
|
|
86
86
|
let payload = buf.slice(0, -16);
|
|
87
|
-
let decipher = crypto_1.createDecipheriv(method, key, iv).setAuthTag(tag).setAAD(Buffer.from(aad));
|
|
87
|
+
let decipher = (0, crypto_1.createDecipheriv)(method, key, iv).setAuthTag(tag).setAAD(Buffer.from(aad));
|
|
88
88
|
return Buffer.concat([
|
|
89
89
|
decipher.update(payload),
|
|
90
90
|
decipher.final(),
|
|
@@ -112,7 +112,7 @@ class BaseAccessToken {
|
|
|
112
112
|
}
|
|
113
113
|
getCacheKey() {
|
|
114
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
-
return 'easywechat.kernel.access_token.' + Utils_1.createHash(JSON.stringify(yield this.getCredentials()), 'md5');
|
|
115
|
+
return 'easywechat.kernel.access_token.' + (0, Utils_1.createHash)(JSON.stringify(yield this.getCredentials()), 'md5');
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
requestToken(credentials) {
|
|
@@ -202,5 +202,5 @@ class BaseAccessToken {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
;
|
|
205
|
-
Utils_1.applyMixins(BaseAccessToken, [HttpMixin_1.default]);
|
|
205
|
+
(0, Utils_1.applyMixins)(BaseAccessToken, [HttpMixin_1.default]);
|
|
206
206
|
exports.default = BaseAccessToken;
|
|
@@ -34,7 +34,7 @@ class BaseApplicatioin {
|
|
|
34
34
|
if (new.target === BaseApplicatioin) {
|
|
35
35
|
throw new Error('Can not create instance via BaseApplicatioin.');
|
|
36
36
|
}
|
|
37
|
-
if (Utils_1.isObject(prepends)) {
|
|
37
|
+
if ((0, Utils_1.isObject)(prepends)) {
|
|
38
38
|
for (let key in prepends) {
|
|
39
39
|
this.offsetSet(key, prepends[key]);
|
|
40
40
|
}
|
|
@@ -44,7 +44,7 @@ class BaseApplicatioin {
|
|
|
44
44
|
}
|
|
45
45
|
getId() {
|
|
46
46
|
if (!this.id) {
|
|
47
|
-
this.id = Utils_1.createHash(JSON.stringify(this.userConfig), 'md5');
|
|
47
|
+
this.id = (0, Utils_1.createHash)(JSON.stringify(this.userConfig), 'md5');
|
|
48
48
|
}
|
|
49
49
|
return this.id;
|
|
50
50
|
}
|
|
@@ -59,7 +59,7 @@ class BaseApplicatioin {
|
|
|
59
59
|
baseURL: 'https://api.weixin.qq.com/',
|
|
60
60
|
},
|
|
61
61
|
};
|
|
62
|
-
return Utils_1.merge(Utils_1.merge(base, this.defaultConfig), this.userConfig);
|
|
62
|
+
return (0, Utils_1.merge)((0, Utils_1.merge)(base, this.defaultConfig), this.userConfig);
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* 注册通用模块
|
|
@@ -113,7 +113,7 @@ class BaseApplicatioin {
|
|
|
113
113
|
* @param value 自定义服务模块的实例,可以传入一个闭包,闭包会接收一个指向Application的参数
|
|
114
114
|
*/
|
|
115
115
|
offsetSet(id, value) {
|
|
116
|
-
if (Utils_1.isFunction(value)) {
|
|
116
|
+
if ((0, Utils_1.isFunction)(value)) {
|
|
117
117
|
value = value(this);
|
|
118
118
|
}
|
|
119
119
|
this[id] = value;
|
package/dist/Core/BaseClient.js
CHANGED
|
@@ -50,7 +50,7 @@ class BaseClient {
|
|
|
50
50
|
httpUpload(url, files = {}, form = {}, query = {}) {
|
|
51
51
|
let formData = new form_data_1.default;
|
|
52
52
|
for (let name in files) {
|
|
53
|
-
if (Utils_1.isString(files[name])) {
|
|
53
|
+
if ((0, Utils_1.isString)(files[name])) {
|
|
54
54
|
formData.append(name, fs_1.default.createReadStream(files[name]));
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
@@ -105,5 +105,5 @@ class BaseClient {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
;
|
|
108
|
-
Utils_1.applyMixins(BaseClient, [HttpMixin_1.default]);
|
|
108
|
+
(0, Utils_1.applyMixins)(BaseClient, [HttpMixin_1.default]);
|
|
109
109
|
exports.default = BaseClient;
|
|
@@ -24,7 +24,7 @@ class FileCache {
|
|
|
24
24
|
ext: '.cache'
|
|
25
25
|
};
|
|
26
26
|
if (options && typeof options == 'object') {
|
|
27
|
-
this.options = Utils_1.merge({
|
|
27
|
+
this.options = (0, Utils_1.merge)({
|
|
28
28
|
path: './',
|
|
29
29
|
dirMode: 0o777,
|
|
30
30
|
fileMode: 0o666,
|
|
@@ -52,7 +52,7 @@ class FileCache {
|
|
|
52
52
|
encoding: 'utf-8',
|
|
53
53
|
flag: 'r'
|
|
54
54
|
}));
|
|
55
|
-
if (dataItem.lifeTime > 0 && dataItem.lifeTime < Utils_1.getTimestamp()) {
|
|
55
|
+
if (dataItem.lifeTime > 0 && dataItem.lifeTime < (0, Utils_1.getTimestamp)()) {
|
|
56
56
|
throw new Error('Cache expired.');
|
|
57
57
|
}
|
|
58
58
|
return dataItem.data;
|
|
@@ -89,7 +89,7 @@ class FileCache {
|
|
|
89
89
|
try {
|
|
90
90
|
let dataItem = {
|
|
91
91
|
data,
|
|
92
|
-
lifeTime: lifeTime > 0 ? lifeTime + Utils_1.getTimestamp() : 0
|
|
92
|
+
lifeTime: lifeTime > 0 ? lifeTime + (0, Utils_1.getTimestamp)() : 0
|
|
93
93
|
};
|
|
94
94
|
fs_1.default.writeFileSync(file, JSON.stringify(dataItem), {
|
|
95
95
|
mode: this.options.fileMode,
|
package/dist/Core/Encryptor.js
CHANGED
|
@@ -22,7 +22,7 @@ class Encryptor {
|
|
|
22
22
|
}
|
|
23
23
|
signature(...args) {
|
|
24
24
|
args.sort();
|
|
25
|
-
return Utils_1.createHash(args.join(''), 'sha1');
|
|
25
|
+
return (0, Utils_1.createHash)(args.join(''), 'sha1');
|
|
26
26
|
}
|
|
27
27
|
encrypt(text, nonce = null, timestamp = null) {
|
|
28
28
|
let encrypted = '';
|
|
@@ -41,14 +41,14 @@ class Encryptor {
|
|
|
41
41
|
if (!nonce)
|
|
42
42
|
nonce = this.appId.slice(0, 10);
|
|
43
43
|
if (!timestamp)
|
|
44
|
-
timestamp = Utils_1.getTimestamp();
|
|
44
|
+
timestamp = (0, Utils_1.getTimestamp)();
|
|
45
45
|
let response = {
|
|
46
46
|
Encrypt: encrypted,
|
|
47
47
|
MsgSignature: this.signature(this.token, timestamp, nonce, encrypted),
|
|
48
48
|
TimeStamp: timestamp,
|
|
49
49
|
Nonce: nonce,
|
|
50
50
|
};
|
|
51
|
-
return Utils_1.buildXml(response);
|
|
51
|
+
return (0, Utils_1.buildXml)(response);
|
|
52
52
|
}
|
|
53
53
|
decrypt(text, msgSignature, nonce, timestamp) {
|
|
54
54
|
let signature = this.signature(this.token, nonce, timestamp, text);
|
|
@@ -36,7 +36,7 @@ class Request {
|
|
|
36
36
|
if (Buffer.isBuffer(content)) {
|
|
37
37
|
this._content = content;
|
|
38
38
|
}
|
|
39
|
-
else if (Utils_1.isObject(content)) {
|
|
39
|
+
else if ((0, Utils_1.isObject)(content)) {
|
|
40
40
|
this._post = content;
|
|
41
41
|
this._content = Buffer.from(JSON.stringify(content));
|
|
42
42
|
this._contentType = 'application/json';
|
|
@@ -48,13 +48,13 @@ class Request {
|
|
|
48
48
|
}
|
|
49
49
|
catch (e) {
|
|
50
50
|
if (content.substr(0, 1) === '<') {
|
|
51
|
-
Utils_1.parseXml(content).then(res => {
|
|
51
|
+
(0, Utils_1.parseXml)(content).then(res => {
|
|
52
52
|
this._post = res;
|
|
53
53
|
this._contentType = 'text/xml';
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
|
-
this._post = Utils_1.parseQueryString(content);
|
|
57
|
+
this._post = (0, Utils_1.parseQueryString)(content);
|
|
58
58
|
this._contentType = 'application/x-www-form-urlencoded';
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -63,7 +63,7 @@ class Request {
|
|
|
63
63
|
}
|
|
64
64
|
this._get = url_1.default.parse(req.url, true).query || {};
|
|
65
65
|
// 提取请求ip
|
|
66
|
-
if (Utils_1.isIp(this._headers['x-client-ip'])) {
|
|
66
|
+
if ((0, Utils_1.isIp)(this._headers['x-client-ip'])) {
|
|
67
67
|
this._ip = this._headers['x-client-ip'];
|
|
68
68
|
}
|
|
69
69
|
else if (this._headers['x-forwarded-for']) {
|
|
@@ -79,22 +79,22 @@ class Request {
|
|
|
79
79
|
ip = tmp[0];
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
if (Utils_1.isIp(ip)) {
|
|
82
|
+
if ((0, Utils_1.isIp)(ip)) {
|
|
83
83
|
break;
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
this._ip = ip;
|
|
87
87
|
}
|
|
88
|
-
else if (Utils_1.isIp(this._headers['x-real-ip'])) {
|
|
88
|
+
else if ((0, Utils_1.isIp)(this._headers['x-real-ip'])) {
|
|
89
89
|
this._ip = this._headers['x-real-ip'];
|
|
90
90
|
}
|
|
91
|
-
else if (Utils_1.isIp(this._headers['x-forwarded'])) {
|
|
91
|
+
else if ((0, Utils_1.isIp)(this._headers['x-forwarded'])) {
|
|
92
92
|
this._ip = this._headers['x-forwarded'];
|
|
93
93
|
}
|
|
94
|
-
else if (Utils_1.isIp(this._headers['forwarded-for'])) {
|
|
94
|
+
else if ((0, Utils_1.isIp)(this._headers['forwarded-for'])) {
|
|
95
95
|
this._ip = this._headers['forwarded-for'];
|
|
96
96
|
}
|
|
97
|
-
else if (Utils_1.isIp(this._headers['client-ip'])) {
|
|
97
|
+
else if ((0, Utils_1.isIp)(this._headers['client-ip'])) {
|
|
98
98
|
this._ip = this._headers['client-ip'];
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -110,7 +110,7 @@ class Request {
|
|
|
110
110
|
get(key) {
|
|
111
111
|
if (!this.isValid)
|
|
112
112
|
throw new Error('Please set request first. app.rebind(\'request\', new EasyWechat.Request(ctx.req));');
|
|
113
|
-
if (this._get[key])
|
|
113
|
+
if (this._get[key] != undefined)
|
|
114
114
|
return this._get[key];
|
|
115
115
|
return this.post(key);
|
|
116
116
|
}
|
|
@@ -132,10 +132,10 @@ class Request {
|
|
|
132
132
|
catch (e) { }
|
|
133
133
|
}
|
|
134
134
|
else if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
|
|
135
|
-
this._post = Utils_1.parseQueryString(this._content.toString());
|
|
135
|
+
this._post = (0, Utils_1.parseQueryString)(this._content.toString());
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
return this._post && this._post[key] ? this._post[key] : null;
|
|
138
|
+
return this._post && this._post[key] != undefined ? this._post[key] : null;
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
141
|
getAllGet() {
|
|
@@ -155,7 +155,7 @@ class Request {
|
|
|
155
155
|
if (this._method !== 'POST')
|
|
156
156
|
return null;
|
|
157
157
|
if (!this._content) {
|
|
158
|
-
this._content = yield raw_body_1.default(this._req);
|
|
158
|
+
this._content = yield (0, raw_body_1.default)(this._req);
|
|
159
159
|
}
|
|
160
160
|
return this._content;
|
|
161
161
|
});
|
|
@@ -24,7 +24,7 @@ class StreamResponse extends Response_1.default {
|
|
|
24
24
|
throw new Error('Invalid media response content.');
|
|
25
25
|
}
|
|
26
26
|
if (!filename) {
|
|
27
|
-
filename = Utils_1.createHash(content, 'md5');
|
|
27
|
+
filename = (0, Utils_1.createHash)(content, 'md5');
|
|
28
28
|
}
|
|
29
29
|
fs_1.default.writeFileSync(`${directory}/${filename}`, buffer);
|
|
30
30
|
return filename;
|
|
@@ -5,7 +5,7 @@ const Message_1 = require("./Message");
|
|
|
5
5
|
const Utils_1 = require("../Utils");
|
|
6
6
|
class Media extends Message_1.Message {
|
|
7
7
|
constructor(mediaId, type = '', attributes = {}) {
|
|
8
|
-
super(Utils_1.merge({ media_id: mediaId }, attributes));
|
|
8
|
+
super((0, Utils_1.merge)({ media_id: mediaId }, attributes));
|
|
9
9
|
this.properties = [
|
|
10
10
|
'media_id',
|
|
11
11
|
];
|
|
@@ -21,7 +21,7 @@ class Media extends Message_1.Message {
|
|
|
21
21
|
}
|
|
22
22
|
toXmlArray() {
|
|
23
23
|
return {
|
|
24
|
-
[Utils_1.strStudly(this.getType())]: {
|
|
24
|
+
[(0, Utils_1.strStudly)(this.getType())]: {
|
|
25
25
|
MediaId: this.get('media_id'),
|
|
26
26
|
}
|
|
27
27
|
};
|
|
@@ -17,11 +17,11 @@ class Message {
|
|
|
17
17
|
this.type = type;
|
|
18
18
|
}
|
|
19
19
|
transformToXml(appends = {}, returnAsObject = false) {
|
|
20
|
-
let data = Utils_1.merge(Utils_1.merge({ MsgType: this.getType() }, this.toXmlArray()), appends);
|
|
20
|
+
let data = (0, Utils_1.merge)((0, Utils_1.merge)({ MsgType: this.getType() }, this.toXmlArray()), appends);
|
|
21
21
|
if (returnAsObject) {
|
|
22
22
|
return data;
|
|
23
23
|
}
|
|
24
|
-
return Utils_1.buildXml(data);
|
|
24
|
+
return (0, Utils_1.buildXml)(data);
|
|
25
25
|
}
|
|
26
26
|
toXmlArray() {
|
|
27
27
|
throw new Error(`Class "${this.constructor.name}" cannot support transform to XML message.`);
|
|
@@ -34,10 +34,10 @@ class Message {
|
|
|
34
34
|
return this.propertiesToObject({}, this.jsonAliases);
|
|
35
35
|
}
|
|
36
36
|
let messageType = this.getType();
|
|
37
|
-
let data = Utils_1.merge({
|
|
37
|
+
let data = (0, Utils_1.merge)({
|
|
38
38
|
msgtype: messageType
|
|
39
39
|
}, appends);
|
|
40
|
-
data[messageType] = Utils_1.merge(data[messageType] || {}, this.propertiesToObject({}, this.jsonAliases));
|
|
40
|
+
data[messageType] = (0, Utils_1.merge)(data[messageType] || {}, this.propertiesToObject({}, this.jsonAliases));
|
|
41
41
|
return data;
|
|
42
42
|
}
|
|
43
43
|
propertiesToObject(data, aliases = null) {
|
|
@@ -78,7 +78,7 @@ class Message {
|
|
|
78
78
|
return false;
|
|
79
79
|
}
|
|
80
80
|
merge(attributes) {
|
|
81
|
-
this.attributes = Utils_1.merge(Utils_1.merge({}, this.attributes), attributes);
|
|
81
|
+
this.attributes = (0, Utils_1.merge)((0, Utils_1.merge)({}, this.attributes), attributes);
|
|
82
82
|
return this;
|
|
83
83
|
}
|
|
84
84
|
only(keys) {
|
|
@@ -97,10 +97,10 @@ class Message {
|
|
|
97
97
|
return this.attributes;
|
|
98
98
|
}
|
|
99
99
|
getRequired() {
|
|
100
|
-
return this.required && Utils_1.isArray(this.required) ? this.required : [];
|
|
100
|
+
return this.required && (0, Utils_1.isArray)(this.required) ? this.required : [];
|
|
101
101
|
}
|
|
102
102
|
isRequired(attribute) {
|
|
103
|
-
return Utils_1.inArray(attribute, this.getRequired(), true);
|
|
103
|
+
return (0, Utils_1.inArray)(attribute, this.getRequired(), true);
|
|
104
104
|
}
|
|
105
105
|
checkRequiredAttributes() {
|
|
106
106
|
this.getRequired().forEach(attribute => {
|
|
@@ -19,7 +19,7 @@ const form_data_1 = __importDefault(require("form-data"));
|
|
|
19
19
|
class HttpMixin {
|
|
20
20
|
doRequest(payload) {
|
|
21
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
let opts = Utils_1.merge({}, payload || {});
|
|
22
|
+
let opts = (0, Utils_1.merge)({}, payload || {});
|
|
23
23
|
if (typeof opts.baseURL == 'undefined' && this['baseUrl']) {
|
|
24
24
|
opts.baseURL = this['baseUrl'];
|
|
25
25
|
}
|
|
@@ -33,14 +33,14 @@ class HttpMixin {
|
|
|
33
33
|
opts.responseType = 'json';
|
|
34
34
|
}
|
|
35
35
|
if (this['app'] && this['app'] instanceof BaseApplication_1.default) {
|
|
36
|
-
opts = Utils_1.merge(Utils_1.merge({}, this['app'].config.http || {}), opts);
|
|
36
|
+
opts = (0, Utils_1.merge)((0, Utils_1.merge)({}, this['app'].config.http || {}), opts);
|
|
37
37
|
}
|
|
38
38
|
if (opts.data && opts.data instanceof form_data_1.default) {
|
|
39
|
-
opts.headers = Utils_1.merge(opts.headers || {}, opts.data.getHeaders());
|
|
39
|
+
opts.headers = (0, Utils_1.merge)(opts.headers || {}, opts.data.getHeaders());
|
|
40
40
|
opts.headers['Content-Length'] = yield new Promise((resolve, reject) => {
|
|
41
41
|
opts.data.getLength((err, length) => {
|
|
42
42
|
if (err) {
|
|
43
|
-
resolve(0);
|
|
43
|
+
resolve('0');
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
46
|
resolve(length);
|
|
@@ -35,8 +35,8 @@ export default class ServerGuard {
|
|
|
35
35
|
* 处理消息
|
|
36
36
|
*/
|
|
37
37
|
serve(): Promise<Response>;
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
validate(): Promise<this>;
|
|
39
|
+
forceValidate(): this;
|
|
40
40
|
protected resolve(): Promise<Response>;
|
|
41
41
|
protected shouldReturnRawResponse(): Promise<boolean>;
|
|
42
42
|
protected buildResponse(to: string, from: string, message: any): Promise<string>;
|
package/dist/Core/ServerGuard.js
CHANGED
|
@@ -166,10 +166,10 @@ class ServerGuard {
|
|
|
166
166
|
if (message instanceof Messages_1.Raw) {
|
|
167
167
|
return message.get('content', ServerGuard.SUCCESS_EMPTY_RESPONSE);
|
|
168
168
|
}
|
|
169
|
-
if (Utils_1.isString(message) || Utils_1.isNumber(message)) {
|
|
169
|
+
if ((0, Utils_1.isString)(message) || (0, Utils_1.isNumber)(message)) {
|
|
170
170
|
message = new Messages_1.Text(message + '');
|
|
171
171
|
}
|
|
172
|
-
if (Utils_1.isArray(message) && message[0] instanceof Messages_1.NewsItem) {
|
|
172
|
+
if ((0, Utils_1.isArray)(message) && message[0] instanceof Messages_1.NewsItem) {
|
|
173
173
|
message = new Messages_1.News(message);
|
|
174
174
|
}
|
|
175
175
|
if (message instanceof Messages_1.NewsItem) {
|
|
@@ -186,7 +186,7 @@ class ServerGuard {
|
|
|
186
186
|
let prepends = {
|
|
187
187
|
ToUserName: to,
|
|
188
188
|
FromUserName: from,
|
|
189
|
-
CreateTime: Utils_1.getTimestamp(),
|
|
189
|
+
CreateTime: (0, Utils_1.getTimestamp)(),
|
|
190
190
|
MsgType: message.getType(),
|
|
191
191
|
};
|
|
192
192
|
let res = message.transformToXml(prepends);
|
|
@@ -209,7 +209,7 @@ class ServerGuard {
|
|
|
209
209
|
}
|
|
210
210
|
signature(params) {
|
|
211
211
|
params.sort();
|
|
212
|
-
return Utils_1.createHash(params.join(''), 'sha1');
|
|
212
|
+
return (0, Utils_1.createHash)(params.join(''), 'sha1');
|
|
213
213
|
}
|
|
214
214
|
handleRequest() {
|
|
215
215
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -247,7 +247,7 @@ class ServerGuard {
|
|
|
247
247
|
return {};
|
|
248
248
|
}
|
|
249
249
|
else if (0 === content.indexOf('<')) {
|
|
250
|
-
content = yield Utils_1.parseXml(content);
|
|
250
|
+
content = yield (0, Utils_1.parseXml)(content);
|
|
251
251
|
}
|
|
252
252
|
else {
|
|
253
253
|
// Handle JSON format.
|
package/dist/Core/Types.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ export declare interface EasyWechatConfig {
|
|
|
49
49
|
app_id?: string;
|
|
50
50
|
/**
|
|
51
51
|
* 应用 secret
|
|
52
|
-
* @scope BaseService | OfficialAccount | MiniProgram | Work
|
|
52
|
+
* @scope BaseService | OfficialAccount | MiniProgram | Work | OpenWork
|
|
53
53
|
*/
|
|
54
54
|
secret?: string;
|
|
55
55
|
/**
|
|
@@ -64,12 +64,12 @@ export declare interface EasyWechatConfig {
|
|
|
64
64
|
file_cache?: EasyWechatConfigCacheFile;
|
|
65
65
|
/**
|
|
66
66
|
* 服务端接口验证 token
|
|
67
|
-
* @scope OfficialAccount | MiniProgram | OpenPlatform
|
|
67
|
+
* @scope OfficialAccount | MiniProgram | OpenPlatform | OpenWork
|
|
68
68
|
*/
|
|
69
69
|
token?: string;
|
|
70
70
|
/**
|
|
71
71
|
* 服务端消息加解密密钥 aes_key
|
|
72
|
-
* @scope OfficialAccount | MiniProgram | OpenPlatform
|
|
72
|
+
* @scope OfficialAccount | MiniProgram | OpenPlatform | OpenWork
|
|
73
73
|
*/
|
|
74
74
|
aes_key?: string;
|
|
75
75
|
/**
|
|
@@ -154,7 +154,7 @@ export declare interface EasyWechatConfig {
|
|
|
154
154
|
device_type?: string;
|
|
155
155
|
/**
|
|
156
156
|
* 企业id
|
|
157
|
-
* @scope Work
|
|
157
|
+
* @scope Work | OpenWork
|
|
158
158
|
*/
|
|
159
159
|
corp_id?: string;
|
|
160
160
|
/**
|
|
@@ -162,6 +162,36 @@ export declare interface EasyWechatConfig {
|
|
|
162
162
|
* @scope Work
|
|
163
163
|
*/
|
|
164
164
|
agent_id?: string;
|
|
165
|
+
/**
|
|
166
|
+
* 应用id
|
|
167
|
+
* @scope OpenWork
|
|
168
|
+
*/
|
|
169
|
+
suite_id?: string;
|
|
170
|
+
/**
|
|
171
|
+
* 应用secret
|
|
172
|
+
* @scope OpenWork
|
|
173
|
+
*/
|
|
174
|
+
suite_secret?: string;
|
|
175
|
+
/**
|
|
176
|
+
* 注册定制化模板ID
|
|
177
|
+
* @scope OpenWork
|
|
178
|
+
*/
|
|
179
|
+
reg_template_id?: string;
|
|
180
|
+
/**
|
|
181
|
+
* 安装应用的回调url(可选)
|
|
182
|
+
* @scope OpenWork
|
|
183
|
+
*/
|
|
184
|
+
redirect_uri_install?: string;
|
|
185
|
+
/**
|
|
186
|
+
* 单点登录回调url(可选)
|
|
187
|
+
* @scope OpenWork
|
|
188
|
+
*/
|
|
189
|
+
redirect_uri_single?: string;
|
|
190
|
+
/**
|
|
191
|
+
* 网页授权第三方回调url(可选)
|
|
192
|
+
* @scope OpenWork
|
|
193
|
+
*/
|
|
194
|
+
redirect_uri_oauth?: string;
|
|
165
195
|
}
|
|
166
196
|
/**
|
|
167
197
|
* 服务端通知处理回调函数
|