node-easywechat 3.5.12 → 3.5.13
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 +6 -0
- package/dist/Core/Http/Minxins/MessageMixin.js +1 -2
- package/dist/OpenPlatform/Message.d.ts +3 -1
- package/dist/OpenPlatform/Server.d.ts +6 -0
- package/dist/OpenPlatform/Server.js +12 -0
- package/dist/Pay/Contracts/MerchantInterface.d.ts +7 -2
- package/dist/Pay/Contracts/MerchantInterface.js +7 -2
- package/dist/Pay/Merchant.d.ts +1 -0
- package/dist/Pay/Merchant.js +8 -0
- package/dist/Pay/Server.js +4 -0
- package/dist/Pay/Utils.d.ts +13 -1
- package/dist/Pay/Utils.js +39 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -16,10 +16,12 @@ interface Message {
|
|
|
16
16
|
* - unauthorized:取消授权
|
|
17
17
|
* - updateauthorized:更新授权
|
|
18
18
|
* - component_verify_ticket:验证票据
|
|
19
|
+
* - notify_third_fasteregister:快速注册企业小程序审核事件
|
|
19
20
|
* @see [授权变更通知推送](https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/authorize_event.html)
|
|
20
21
|
* @see [验证票据](https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/component_verify_ticket.html)
|
|
22
|
+
* @see [快速注册企业小程序审核事件](https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Register_Mini_Programs/Fast_Registration_Interface_document.html#三、注册审核事件推送)
|
|
21
23
|
*/
|
|
22
|
-
InfoType?: 'authorized' | 'unauthorized' | 'updateauthorized' | 'component_verify_ticket';
|
|
24
|
+
InfoType?: 'authorized' | 'unauthorized' | 'updateauthorized' | 'component_verify_ticket' | 'notify_third_fasteregister' | string;
|
|
23
25
|
/**
|
|
24
26
|
* 公众号或小程序的 appid
|
|
25
27
|
*/
|
|
@@ -44,6 +44,12 @@ declare class Server extends ServerInterface {
|
|
|
44
44
|
* @returns
|
|
45
45
|
*/
|
|
46
46
|
handleVerifyTicketRefreshed(handler: ServerHandlerClosure<Message>): this;
|
|
47
|
+
/**
|
|
48
|
+
* 处理快速注册企业小程序审核通知
|
|
49
|
+
* @param handler
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
handleThirdFastRegister(handler: ServerHandlerClosure<Message>): this;
|
|
47
53
|
protected decryptRequestMessage(): ServerHandlerClosure<Message>;
|
|
48
54
|
/**
|
|
49
55
|
* 获取来自微信服务器的推送消息
|
|
@@ -102,6 +102,18 @@ class Server extends ServerInterface_1.default {
|
|
|
102
102
|
});
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* 处理快速注册企业小程序审核通知
|
|
107
|
+
* @param handler
|
|
108
|
+
* @returns
|
|
109
|
+
*/
|
|
110
|
+
handleThirdFastRegister(handler) {
|
|
111
|
+
return this.with(function (message, next) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
return message.InfoType === 'notify_third_fasteregister' ? handler(message, next) : next(message);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
105
117
|
decryptRequestMessage() {
|
|
106
118
|
let query = this.request.getQueryParams();
|
|
107
119
|
return (message, next) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -35,13 +35,18 @@ declare abstract class MerchantInterface {
|
|
|
35
35
|
*/
|
|
36
36
|
setPlatformCertKey(key: string): this;
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
38
|
+
* 根据证书序列号获取平台证书
|
|
39
39
|
* @param serial
|
|
40
40
|
* @returns
|
|
41
41
|
*/
|
|
42
42
|
getPlatformCert(serial: string): Promise<PublicKey>;
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
44
|
+
* 获取所有平台证书
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
getPlatformCerts(): Promise<Record<string, PublicKey>>;
|
|
48
|
+
/**
|
|
49
|
+
* 从缓存或者接口获取平台证书
|
|
45
50
|
* @param force 是否强制刷新缓存,默认:false
|
|
46
51
|
*/
|
|
47
52
|
loadPlatformCerts(force?: boolean): Promise<void>;
|
|
@@ -34,13 +34,18 @@ class MerchantInterface {
|
|
|
34
34
|
*/
|
|
35
35
|
setPlatformCertKey(key) { return this; }
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* 根据证书序列号获取平台证书
|
|
38
38
|
* @param serial
|
|
39
39
|
* @returns
|
|
40
40
|
*/
|
|
41
41
|
getPlatformCert(serial) { return null; }
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* 获取所有平台证书
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
getPlatformCerts() { return null; }
|
|
47
|
+
/**
|
|
48
|
+
* 从缓存或者接口获取平台证书
|
|
44
49
|
* @param force 是否强制刷新缓存,默认:false
|
|
45
50
|
*/
|
|
46
51
|
loadPlatformCerts(force = false) { return; }
|
package/dist/Pay/Merchant.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ declare class Merchant implements MerchantInterface {
|
|
|
24
24
|
getV2SecretKey(): string;
|
|
25
25
|
getCertificate(): PublicKey;
|
|
26
26
|
getPlatformCert(serial: string): Promise<PublicKey>;
|
|
27
|
+
getPlatformCerts(): Promise<Record<string, PublicKey>>;
|
|
27
28
|
setPlatformCerts(certs: Record<string, PublicKey | string>): void;
|
|
28
29
|
getPlatformCertKey(): string;
|
|
29
30
|
setPlatformCertKey(key: string): this;
|
package/dist/Pay/Merchant.js
CHANGED
|
@@ -76,6 +76,14 @@ class Merchant {
|
|
|
76
76
|
return (_a = this.platformCerts[serial]) !== null && _a !== void 0 ? _a : null;
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
|
+
getPlatformCerts() {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
if (!this.platformCerts || Object.keys(this.platformCerts).length === 0) {
|
|
82
|
+
yield this.loadPlatformCerts();
|
|
83
|
+
}
|
|
84
|
+
return this.platformCerts;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
79
87
|
setPlatformCerts(certs) {
|
|
80
88
|
let newCerts = {};
|
|
81
89
|
for (let key of Object.keys(certs)) {
|
package/dist/Pay/Server.js
CHANGED
|
@@ -125,6 +125,10 @@ class Server extends ServerInterface_1.default {
|
|
|
125
125
|
*/
|
|
126
126
|
handlePaid(handler) {
|
|
127
127
|
this.with((message, next) => __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
let isV2Message = message.getOriginalContents().startsWith('<xml');
|
|
129
|
+
if (isV2Message) {
|
|
130
|
+
return handler(message, next);
|
|
131
|
+
}
|
|
128
132
|
return message.getEventType() === 'TRANSACTION.SUCCESS' && message.trade_state === 'SUCCESS'
|
|
129
133
|
? handler(message, next) : next(message);
|
|
130
134
|
}));
|
package/dist/Pay/Utils.d.ts
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { PublicKey } from '../Core/Support/PublicKey';
|
|
2
3
|
import { PayAppConfig, PayBridgeConfig, PaySdkConfig } from '../Types/global';
|
|
3
4
|
import MerchantInterface from './Contracts/MerchantInterface';
|
|
4
5
|
declare class Utils {
|
|
5
6
|
protected merchant: MerchantInterface;
|
|
7
|
+
protected platformCert: PublicKey;
|
|
6
8
|
constructor(merchant: MerchantInterface);
|
|
9
|
+
/**
|
|
10
|
+
* 设置加密所用的平台证书
|
|
11
|
+
* @param platformCert
|
|
12
|
+
*/
|
|
13
|
+
setPlatformCert(platformCert: PublicKey): this;
|
|
14
|
+
/**
|
|
15
|
+
* 获取加密所用的平台证书
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
getPlatformCert(): Promise<PublicKey>;
|
|
7
19
|
/**
|
|
8
20
|
* 加密字符串
|
|
9
21
|
* @param plaintext 原文
|
|
10
22
|
* @param encoding 密文的编码格式,默认:base64
|
|
11
23
|
* @param hashType 哈希算法,默认:sha256
|
|
12
24
|
*/
|
|
13
|
-
encrypt(plaintext: string, encoding?: BufferEncoding, hashType?: string): string
|
|
25
|
+
encrypt(plaintext: string, encoding?: BufferEncoding, hashType?: string): Promise<string>;
|
|
14
26
|
/**
|
|
15
27
|
* 解密字符串
|
|
16
28
|
* @param ciphertext 密文
|
package/dist/Pay/Utils.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
@@ -8,6 +17,30 @@ class Utils {
|
|
|
8
17
|
constructor(merchant) {
|
|
9
18
|
this.merchant = merchant;
|
|
10
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* 设置加密所用的平台证书
|
|
22
|
+
* @param platformCert
|
|
23
|
+
*/
|
|
24
|
+
setPlatformCert(platformCert) {
|
|
25
|
+
this.platformCert = platformCert;
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 获取加密所用的平台证书
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
getPlatformCert() {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
if (!this.platformCert) {
|
|
35
|
+
let certs = yield this.merchant.getPlatformCerts();
|
|
36
|
+
if (!certs || Object.keys(certs).length === 0) {
|
|
37
|
+
throw new Error('Fail to get platform certs');
|
|
38
|
+
}
|
|
39
|
+
this.platformCert = certs[Object.keys(certs)[0]];
|
|
40
|
+
}
|
|
41
|
+
return this.platformCert;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
11
44
|
/**
|
|
12
45
|
* 加密字符串
|
|
13
46
|
* @param plaintext 原文
|
|
@@ -15,9 +48,12 @@ class Utils {
|
|
|
15
48
|
* @param hashType 哈希算法,默认:sha256
|
|
16
49
|
*/
|
|
17
50
|
encrypt(plaintext, encoding = 'base64', hashType = 'sha256') {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
let rsa = new RSA_1.default;
|
|
53
|
+
let cert = yield this.getPlatformCert();
|
|
54
|
+
rsa.setPublicKey(cert.toString());
|
|
55
|
+
return rsa.encrypt(plaintext, encoding, hashType);
|
|
56
|
+
});
|
|
21
57
|
}
|
|
22
58
|
/**
|
|
23
59
|
* 解密字符串
|