node-easywechat 2.9.5 → 2.9.6
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 +4 -0
- package/README.md +4 -4
- package/dist/Core/BaseAccessToken.d.ts +3 -3
- package/dist/Core/BaseAccessToken.js +6 -3
- package/dist/Core/Types.d.ts +1 -1
- package/dist/OpenPlatform/Application.d.ts +7 -7
- package/dist/OpenPlatform/Application.js +14 -14
- package/dist/OpenPlatform/Authorizer/MiniProgram/Application.js +1 -2
- package/dist/OpenPlatform/Authorizer/OfficialAccount/Application.js +1 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -107,8 +107,8 @@ let app = EasyWechat.Factory.getInstance('OficialAccount', {
|
|
|
107
107
|
key: 'key-for-signature',
|
|
108
108
|
// 默认回调地址,也可以在下单时单独设置来覆盖它,完整URL,不带参数
|
|
109
109
|
notify_url: 'http://xxx.com/pay/notify',
|
|
110
|
-
// 证书地址,Node.js 只需要 .
|
|
111
|
-
cert_path: 'path/to/your/
|
|
110
|
+
// 证书地址,Node.js 只需要 apiclient_cert.p12 证书文件即可
|
|
111
|
+
cert_path: 'path/to/your/apiclient_cert.p12', // XXX: 绝对路径!!!!
|
|
112
112
|
}
|
|
113
113
|
```
|
|
114
114
|
|
|
@@ -143,8 +143,8 @@ let app = EasyWechat.Factory.getInstance('OficialAccount', {
|
|
|
143
143
|
key: 'key-for-signature',
|
|
144
144
|
// V3版本签名密钥
|
|
145
145
|
apiv3_key: 'apiv3_key-for-signature',
|
|
146
|
-
// 证书地址,Node.js 只需要 .
|
|
147
|
-
cert_path: 'path/to/your/
|
|
146
|
+
// 证书地址,Node.js 只需要 apiclient_cert.p12 证书文件即可
|
|
147
|
+
cert_path: 'path/to/your/apiclient_cert.p12', // XXX: 绝对路径!!!!
|
|
148
148
|
|
|
149
149
|
// 以下两项配置在获取证书接口时可为空,在调用入驻接口前请先调用获取证书接口获取以下两项配置,如果获取过证书可以直接在这里配置,也可参照本文档获取平台证书章节中示例
|
|
150
150
|
// serial_no: '获取证书接口获取到的平台证书序列号',
|
|
@@ -63,7 +63,7 @@ declare abstract class BaseAccessToken implements HttpMixin {
|
|
|
63
63
|
protected getCredentials(): Promise<object>;
|
|
64
64
|
getEndpoint(): Promise<string>;
|
|
65
65
|
getCacheKey(): Promise<string>;
|
|
66
|
-
requestToken(credentials: object): Promise<any
|
|
66
|
+
requestToken(credentials: object): Promise<Record<string, any>>;
|
|
67
67
|
/**
|
|
68
68
|
* 获取Token
|
|
69
69
|
* @param refresh 为true时表示强制刷新
|
|
@@ -77,10 +77,10 @@ declare abstract class BaseAccessToken implements HttpMixin {
|
|
|
77
77
|
protected warpAccessToken(token: Record<string, any>): AccessToken;
|
|
78
78
|
/**
|
|
79
79
|
* 设置Token
|
|
80
|
-
* @param access_token
|
|
80
|
+
* @param access_token Record<string, any>
|
|
81
81
|
* @param expires_in 有效时间,单位:秒
|
|
82
82
|
*/
|
|
83
|
-
setToken(
|
|
83
|
+
setToken(token: Record<string, any>, expires_in?: number): Promise<this>;
|
|
84
84
|
/**
|
|
85
85
|
* 刷新Token
|
|
86
86
|
*/
|
|
@@ -151,6 +151,9 @@ class BaseAccessToken {
|
|
|
151
151
|
return this.warpAccessToken(token);
|
|
152
152
|
}
|
|
153
153
|
let res = yield this.requestToken(yield this.getCredentials());
|
|
154
|
+
if (res.errcode) {
|
|
155
|
+
throw new Error(res.errmsg);
|
|
156
|
+
}
|
|
154
157
|
yield this.setToken(res, res.expires_in || 7200);
|
|
155
158
|
return this.warpAccessToken(res);
|
|
156
159
|
});
|
|
@@ -165,14 +168,14 @@ class BaseAccessToken {
|
|
|
165
168
|
}
|
|
166
169
|
/**
|
|
167
170
|
* 设置Token
|
|
168
|
-
* @param access_token
|
|
171
|
+
* @param access_token Record<string, any>
|
|
169
172
|
* @param expires_in 有效时间,单位:秒
|
|
170
173
|
*/
|
|
171
|
-
setToken(
|
|
174
|
+
setToken(token, expires_in = 7200) {
|
|
172
175
|
return __awaiter(this, void 0, void 0, function* () {
|
|
173
176
|
let cacheKey = yield this.getCacheKey();
|
|
174
177
|
let cache = this.app.getCache();
|
|
175
|
-
yield cache.set(cacheKey,
|
|
178
|
+
yield cache.set(cacheKey, token, expires_in);
|
|
176
179
|
if (!cache.has(cacheKey)) {
|
|
177
180
|
throw new Error('Failed to cache access token.');
|
|
178
181
|
}
|
package/dist/Core/Types.d.ts
CHANGED
|
@@ -52,37 +52,37 @@ export default class OpenPlatform extends BaseApplication {
|
|
|
52
52
|
* 使用授权码换取接口调用凭据和授权信息
|
|
53
53
|
* @param authCode 授权码, 会在授权成功的回调返回给第三方平台
|
|
54
54
|
*/
|
|
55
|
-
handleAuthorize(): Promise<any>;
|
|
55
|
+
handleAuthorize(...arg: any[]): Promise<any>;
|
|
56
56
|
/**
|
|
57
57
|
* 获取授权方的帐号基本信息
|
|
58
58
|
* @param appId 授权方app_id
|
|
59
59
|
*/
|
|
60
|
-
getAuthorizer(): Promise<any>;
|
|
60
|
+
getAuthorizer(...arg: any[]): Promise<any>;
|
|
61
61
|
/**
|
|
62
62
|
* 设置授权方的选项信息
|
|
63
63
|
* @param appId 授权方app_id
|
|
64
64
|
* @param name 选项名称
|
|
65
65
|
*/
|
|
66
|
-
getAuthorizerOption(): Promise<any>;
|
|
66
|
+
getAuthorizerOption(...arg: any[]): Promise<any>;
|
|
67
67
|
/**
|
|
68
68
|
* 设置授权方的选项信息
|
|
69
69
|
* @param appId 授权方app_id
|
|
70
70
|
* @param name 选项名称
|
|
71
71
|
* @param value 选项值
|
|
72
72
|
*/
|
|
73
|
-
setAuthorizerOption(): Promise<any>;
|
|
73
|
+
setAuthorizerOption(...arg: any[]): Promise<any>;
|
|
74
74
|
/**
|
|
75
75
|
* 获取已授权的授权方列表
|
|
76
76
|
* @param offset 起始位置,从0开始
|
|
77
77
|
* @param count 获取记录数,最大500
|
|
78
78
|
*/
|
|
79
|
-
getAuthorizers(): Promise<any>;
|
|
79
|
+
getAuthorizers(...arg: any[]): Promise<any>;
|
|
80
80
|
/**
|
|
81
81
|
* 获取预授权码
|
|
82
82
|
*/
|
|
83
|
-
createPreAuthorizationCode(): Promise<any>;
|
|
83
|
+
createPreAuthorizationCode(...arg: any[]): Promise<any>;
|
|
84
84
|
/**
|
|
85
85
|
* 清零调用次数
|
|
86
86
|
*/
|
|
87
|
-
clearQuota(): Promise<any>;
|
|
87
|
+
clearQuota(...arg: any[]): Promise<any>;
|
|
88
88
|
}
|
|
@@ -171,23 +171,23 @@ class OpenPlatform extends BaseApplication_1.default {
|
|
|
171
171
|
* 使用授权码换取接口调用凭据和授权信息
|
|
172
172
|
* @param authCode 授权码, 会在授权成功的回调返回给第三方平台
|
|
173
173
|
*/
|
|
174
|
-
handleAuthorize() {
|
|
175
|
-
return this.base.handleAuthorize.apply(this.base,
|
|
174
|
+
handleAuthorize(...arg) {
|
|
175
|
+
return this.base.handleAuthorize.apply(this.base, arg);
|
|
176
176
|
}
|
|
177
177
|
/**
|
|
178
178
|
* 获取授权方的帐号基本信息
|
|
179
179
|
* @param appId 授权方app_id
|
|
180
180
|
*/
|
|
181
|
-
getAuthorizer() {
|
|
182
|
-
return this.base.getAuthorizer.apply(this.base,
|
|
181
|
+
getAuthorizer(...arg) {
|
|
182
|
+
return this.base.getAuthorizer.apply(this.base, arg);
|
|
183
183
|
}
|
|
184
184
|
/**
|
|
185
185
|
* 设置授权方的选项信息
|
|
186
186
|
* @param appId 授权方app_id
|
|
187
187
|
* @param name 选项名称
|
|
188
188
|
*/
|
|
189
|
-
getAuthorizerOption() {
|
|
190
|
-
return this.base.getAuthorizerOption.apply(this.base,
|
|
189
|
+
getAuthorizerOption(...arg) {
|
|
190
|
+
return this.base.getAuthorizerOption.apply(this.base, arg);
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
193
193
|
* 设置授权方的选项信息
|
|
@@ -195,28 +195,28 @@ class OpenPlatform extends BaseApplication_1.default {
|
|
|
195
195
|
* @param name 选项名称
|
|
196
196
|
* @param value 选项值
|
|
197
197
|
*/
|
|
198
|
-
setAuthorizerOption() {
|
|
199
|
-
return this.base.setAuthorizerOption.apply(this.base,
|
|
198
|
+
setAuthorizerOption(...arg) {
|
|
199
|
+
return this.base.setAuthorizerOption.apply(this.base, arg);
|
|
200
200
|
}
|
|
201
201
|
/**
|
|
202
202
|
* 获取已授权的授权方列表
|
|
203
203
|
* @param offset 起始位置,从0开始
|
|
204
204
|
* @param count 获取记录数,最大500
|
|
205
205
|
*/
|
|
206
|
-
getAuthorizers() {
|
|
207
|
-
return this.base.getAuthorizers.apply(this.base,
|
|
206
|
+
getAuthorizers(...arg) {
|
|
207
|
+
return this.base.getAuthorizers.apply(this.base, arg);
|
|
208
208
|
}
|
|
209
209
|
/**
|
|
210
210
|
* 获取预授权码
|
|
211
211
|
*/
|
|
212
|
-
createPreAuthorizationCode() {
|
|
213
|
-
return this.base.createPreAuthorizationCode.apply(this.base,
|
|
212
|
+
createPreAuthorizationCode(...arg) {
|
|
213
|
+
return this.base.createPreAuthorizationCode.apply(this.base, arg);
|
|
214
214
|
}
|
|
215
215
|
/**
|
|
216
216
|
* 清零调用次数
|
|
217
217
|
*/
|
|
218
|
-
clearQuota() {
|
|
219
|
-
return this.base.clearQuota.apply(this.base,
|
|
218
|
+
clearQuota(...arg) {
|
|
219
|
+
return this.base.clearQuota.apply(this.base, arg);
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
222
|
exports.default = OpenPlatform;
|
|
@@ -17,10 +17,9 @@ class MiniProgram extends Application_1.default {
|
|
|
17
17
|
this.account = null;
|
|
18
18
|
this.setting = null;
|
|
19
19
|
this.tester = null;
|
|
20
|
-
this.registerProviders();
|
|
21
20
|
}
|
|
22
21
|
registerProviders() {
|
|
23
|
-
|
|
22
|
+
super.registerProviders();
|
|
24
23
|
this.offsetSet('code', function (app) {
|
|
25
24
|
return new CodeClient_1.default(app);
|
|
26
25
|
});
|
|
@@ -9,10 +9,9 @@ class OfficialAccount extends Application_1.default {
|
|
|
9
9
|
constructor(config = {}, prepends = {}, id = null) {
|
|
10
10
|
super(config, prepends, id);
|
|
11
11
|
this.mini_program = null;
|
|
12
|
-
this.registerProviders();
|
|
13
12
|
}
|
|
14
13
|
registerProviders() {
|
|
15
|
-
|
|
14
|
+
super.registerProviders();
|
|
16
15
|
this.offsetSet('mini_program', function (app) {
|
|
17
16
|
return new MiniProgramClient_1.default(app);
|
|
18
17
|
});
|