node-easywechat 2.7.2 → 2.8.3
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/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 +11 -11
- 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.js +5 -5
- 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 +20 -0
- package/dist/MiniProgram/Application.js +50 -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/PhoneNumber/PhoneNumberClient.d.ts +10 -0
- package/dist/MiniProgram/PhoneNumber/PhoneNumberClient.js +20 -0
- 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/Union/UnionClient.d.ts +3 -0
- package/dist/MiniProgram/Union/UnionClient.js +9 -0
- package/dist/MiniProgram/UrlLink/UrlLinkClient.d.ts +9 -0
- package/dist/MiniProgram/UrlLink/UrlLinkClient.js +17 -0
- 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 +7 -7
- package/dist/OpenPlatform/Authorizer/Auth/AccessToken.js +1 -1
- package/dist/OpenPlatform/Authorizer/OfficialAccount/Account/Client.js +1 -1
- 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.d.ts +12 -0
- package/dist/Payment/Jssdk/JssdkClient.js +41 -9
- 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 +202 -3
- package/dist/Work/ExternalContact/Client.js +244 -6
- package/dist/Work/ExternalContact/ContactWayClient.d.ts +37 -0
- package/dist/Work/ExternalContact/ContactWayClient.js +51 -2
- package/dist/Work/ExternalContact/MessageClient.d.ts +45 -0
- package/dist/Work/ExternalContact/MessageClient.js +90 -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/User/UserClient.js +3 -3
- package/dist/index.js +1 -1
- 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
|
@@ -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
|
}
|
|
@@ -132,7 +132,7 @@ 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
138
|
return this._post && this._post[key] ? this._post[key] : null;
|
|
@@ -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);
|
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/Utils.js
CHANGED
|
@@ -19,24 +19,24 @@ const xml2js_1 = __importDefault(require("xml2js"));
|
|
|
19
19
|
const stream_1 = __importDefault(require("stream"));
|
|
20
20
|
const fs_1 = __importDefault(require("fs"));
|
|
21
21
|
const merge = (target, source) => {
|
|
22
|
-
if (exports.isObject(source)) {
|
|
22
|
+
if ((0, exports.isObject)(source)) {
|
|
23
23
|
if (source.constructor !== Object) {
|
|
24
24
|
target = source;
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
|
-
if (!target || !exports.isObject(target)) {
|
|
27
|
+
if (!target || !(0, exports.isObject)(target)) {
|
|
28
28
|
target = {};
|
|
29
29
|
}
|
|
30
30
|
Object.keys(source).map((k) => {
|
|
31
31
|
if (!target[k]) {
|
|
32
32
|
target[k] = null;
|
|
33
33
|
}
|
|
34
|
-
target[k] = exports.merge(target[k], source[k]);
|
|
34
|
+
target[k] = (0, exports.merge)(target[k], source[k]);
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
else if (exports.isArray(source)) {
|
|
39
|
-
if (!target || !exports.isArray(target)) {
|
|
38
|
+
else if ((0, exports.isArray)(source)) {
|
|
39
|
+
if (!target || !(0, exports.isArray)(target)) {
|
|
40
40
|
target = [];
|
|
41
41
|
}
|
|
42
42
|
target = target.concat(target, source);
|
|
@@ -62,7 +62,7 @@ exports.createHmac = createHmac;
|
|
|
62
62
|
const md5File = function (path) {
|
|
63
63
|
return new Promise((reslove, reject) => {
|
|
64
64
|
let stream;
|
|
65
|
-
if (exports.isString(path)) {
|
|
65
|
+
if ((0, exports.isString)(path)) {
|
|
66
66
|
stream = fs_1.default.createReadStream(path);
|
|
67
67
|
}
|
|
68
68
|
else {
|
|
@@ -83,7 +83,7 @@ exports.md5File = md5File;
|
|
|
83
83
|
const getTimestamp = function (datetime = null) {
|
|
84
84
|
let time;
|
|
85
85
|
try {
|
|
86
|
-
time = (exports.isString(datetime) ? new Date(datetime) : new Date).getTime();
|
|
86
|
+
time = ((0, exports.isString)(datetime) ? new Date(datetime) : new Date).getTime();
|
|
87
87
|
}
|
|
88
88
|
catch (e) {
|
|
89
89
|
return 0;
|
|
@@ -127,12 +127,12 @@ const makeSignature = function (params, key = '', type = 'md5') {
|
|
|
127
127
|
switch (type) {
|
|
128
128
|
case 'sha1':
|
|
129
129
|
case 'md5':
|
|
130
|
-
sign = exports.createHash(paramsString, type);
|
|
130
|
+
sign = (0, exports.createHash)(paramsString, type);
|
|
131
131
|
break;
|
|
132
132
|
case 'hmac-sha256':
|
|
133
133
|
case 'hmac_sha256':
|
|
134
134
|
type = type.replace(/^hmac[\-|_]/i, '');
|
|
135
|
-
sign = exports.createHmac(paramsString, key, type);
|
|
135
|
+
sign = (0, exports.createHmac)(paramsString, key, type);
|
|
136
136
|
break;
|
|
137
137
|
}
|
|
138
138
|
return (sign + '').toUpperCase();
|
|
@@ -171,13 +171,13 @@ const isIpv6 = function (ip) {
|
|
|
171
171
|
};
|
|
172
172
|
exports.isIpv6 = isIpv6;
|
|
173
173
|
const isIp = function (ip) {
|
|
174
|
-
return exports.isIpv4(ip) || exports.isIpv6(ip);
|
|
174
|
+
return (0, exports.isIpv4)(ip) || (0, exports.isIpv6)(ip);
|
|
175
175
|
};
|
|
176
176
|
exports.isIp = isIp;
|
|
177
177
|
const inArray = function (data, arr, strict = false) {
|
|
178
|
-
if (!exports.isArray(arr))
|
|
178
|
+
if (!(0, exports.isArray)(arr))
|
|
179
179
|
return strict ? data === arr : data == arr;
|
|
180
|
-
if (exports.isFunction(arr.findIndex)) {
|
|
180
|
+
if ((0, exports.isFunction)(arr.findIndex)) {
|
|
181
181
|
return arr.findIndex((o) => { return strict ? o === data : o == data; }) > -1;
|
|
182
182
|
}
|
|
183
183
|
else {
|
|
@@ -216,12 +216,12 @@ const strLcwords = function (str) {
|
|
|
216
216
|
exports.strLcwords = strLcwords;
|
|
217
217
|
// 驼峰(首字母大写),'hello word' => 'HelloWorld'
|
|
218
218
|
const strStudly = function (value) {
|
|
219
|
-
return exports.strUcwords(value.replace(/[\-|\_]/gi, ' ')).replace(/\s/gi, '');
|
|
219
|
+
return (0, exports.strUcwords)(value.replace(/[\-|\_]/gi, ' ')).replace(/\s/gi, '');
|
|
220
220
|
};
|
|
221
221
|
exports.strStudly = strStudly;
|
|
222
222
|
// 驼峰(首字母小写),'hello word' => 'helloWorld'
|
|
223
223
|
const strCamel = function (value) {
|
|
224
|
-
return exports.strLcwords(exports.strStudly(value));
|
|
224
|
+
return (0, exports.strLcwords)((0, exports.strStudly)(value));
|
|
225
225
|
};
|
|
226
226
|
exports.strCamel = strCamel;
|
|
227
227
|
// 如果只有一个同名、同级节点,则不当作数组
|
|
@@ -229,16 +229,16 @@ const singleItem = function (obj) {
|
|
|
229
229
|
if (typeof obj == 'object') {
|
|
230
230
|
if (typeof obj.length != 'undefined') {
|
|
231
231
|
if (obj.length == 1) {
|
|
232
|
-
return exports.singleItem(obj[0]);
|
|
232
|
+
return (0, exports.singleItem)(obj[0]);
|
|
233
233
|
}
|
|
234
234
|
for (let i = 0; i < obj.length; i++) {
|
|
235
|
-
obj[i] = exports.singleItem(obj[i]);
|
|
235
|
+
obj[i] = (0, exports.singleItem)(obj[i]);
|
|
236
236
|
}
|
|
237
237
|
return obj;
|
|
238
238
|
}
|
|
239
239
|
else {
|
|
240
240
|
for (let k in obj) {
|
|
241
|
-
obj[k] = exports.singleItem(obj[k]);
|
|
241
|
+
obj[k] = (0, exports.singleItem)(obj[k]);
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
}
|
|
@@ -248,7 +248,7 @@ exports.singleItem = singleItem;
|
|
|
248
248
|
const parseXml = function (xml) {
|
|
249
249
|
return __awaiter(this, void 0, void 0, function* () {
|
|
250
250
|
let res = yield xml2js_1.default.parseStringPromise(xml);
|
|
251
|
-
res = exports.singleItem(res);
|
|
251
|
+
res = (0, exports.singleItem)(res);
|
|
252
252
|
if (res['xml'])
|
|
253
253
|
res = res['xml'];
|
|
254
254
|
return res;
|
|
@@ -82,7 +82,7 @@ class MicroMerchant extends BaseApplication_1.default {
|
|
|
82
82
|
delete data['sign'];
|
|
83
83
|
let signType = sign.length > 32 ? 'HMAC-SHA256' : 'MD5';
|
|
84
84
|
let secretKey = this.getKey();
|
|
85
|
-
if (Utils_1.makeSignature(data, secretKey, signType) === sign) {
|
|
85
|
+
if ((0, Utils_1.makeSignature)(data, secretKey, signType) === sign) {
|
|
86
86
|
return true;
|
|
87
87
|
}
|
|
88
88
|
throw new Error('return value signature verification error');
|
|
@@ -7,11 +7,11 @@ const Utils_1 = require("../../Core/Utils");
|
|
|
7
7
|
const BaseClient_1 = __importDefault(require("../Core/BaseClient"));
|
|
8
8
|
class MicroMerchantBase extends BaseClient_1.default {
|
|
9
9
|
submitApplication(params) {
|
|
10
|
-
let newParams = this.processParams(Utils_1.merge(Utils_1.merge({}, params), {
|
|
10
|
+
let newParams = this.processParams((0, Utils_1.merge)((0, Utils_1.merge)({}, params), {
|
|
11
11
|
version: '3.0',
|
|
12
12
|
cert_sn: '',
|
|
13
13
|
sign_type: 'HMAC-SHA256',
|
|
14
|
-
nonce_str: Utils_1.randomString(18),
|
|
14
|
+
nonce_str: (0, Utils_1.randomString)(18),
|
|
15
15
|
}));
|
|
16
16
|
return this.safeRequest('applyment/micro/submit', newParams);
|
|
17
17
|
}
|
|
@@ -19,7 +19,7 @@ class MicroMerchantBase extends BaseClient_1.default {
|
|
|
19
19
|
let params = {
|
|
20
20
|
version: '1.0',
|
|
21
21
|
sign_type: 'HMAC-SHA256',
|
|
22
|
-
nonce_str: Utils_1.randomString(18),
|
|
22
|
+
nonce_str: (0, Utils_1.randomString)(18),
|
|
23
23
|
};
|
|
24
24
|
if (applymentId) {
|
|
25
25
|
params['applyment_id'] = applymentId;
|
|
@@ -30,12 +30,12 @@ class MicroMerchantBase extends BaseClient_1.default {
|
|
|
30
30
|
return this.safeRequest('applyment/micro/getstate', params);
|
|
31
31
|
}
|
|
32
32
|
upgrade(params) {
|
|
33
|
-
let newParams = this.processParams(Utils_1.merge(Utils_1.merge({}, params), {
|
|
33
|
+
let newParams = this.processParams((0, Utils_1.merge)((0, Utils_1.merge)({}, params), {
|
|
34
34
|
sub_mch_id: params['sub_mch_id'] || this.app.config.sub_mch_id,
|
|
35
35
|
version: '1.0',
|
|
36
36
|
cert_sn: '',
|
|
37
37
|
sign_type: 'HMAC-SHA256',
|
|
38
|
-
nonce_str: Utils_1.randomString(18),
|
|
38
|
+
nonce_str: (0, Utils_1.randomString)(18),
|
|
39
39
|
}));
|
|
40
40
|
return this.safeRequest('applyment/micro/submitupgrade', newParams);
|
|
41
41
|
}
|
|
@@ -44,7 +44,7 @@ class MicroMerchantBase extends BaseClient_1.default {
|
|
|
44
44
|
sub_mch_id: subMchId || this.app.config.sub_mch_id,
|
|
45
45
|
version: '1.0',
|
|
46
46
|
sign_type: 'HMAC-SHA256',
|
|
47
|
-
nonce_str: Utils_1.randomString(18),
|
|
47
|
+
nonce_str: (0, Utils_1.randomString)(18),
|
|
48
48
|
};
|
|
49
49
|
return this.safeRequest('applyment/micro/getupgradestate', params);
|
|
50
50
|
}
|
|
@@ -20,7 +20,7 @@ class CertficatesClient extends BaseClient_1.default {
|
|
|
20
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
21
|
let params = {
|
|
22
22
|
sign_type: 'HMAC-SHA256',
|
|
23
|
-
nonce_str: Utils_1.randomString(18),
|
|
23
|
+
nonce_str: (0, Utils_1.randomString)(18),
|
|
24
24
|
};
|
|
25
25
|
if (returnRaw) {
|
|
26
26
|
return yield this.requestRaw('risk/getcertficates', params);
|