node-easywechat 3.3.0 → 3.3.2
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
CHANGED
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
### 安装
|
|
16
16
|
|
|
17
|
-
`npm install -S node-easywechat
|
|
17
|
+
`npm install -S node-easywechat`
|
|
18
18
|
|
|
19
19
|
**注:3.x 版本需要 Node.js 15.6.0 及以上版本**
|
|
20
20
|
|
|
@@ -301,5 +301,5 @@ app.setRequest(request);
|
|
|
301
301
|
- [x] 小程序
|
|
302
302
|
- [x] 开放平台
|
|
303
303
|
- [x] 企业微信
|
|
304
|
-
- [
|
|
305
|
-
- [
|
|
304
|
+
- [x] 企业微信开放平台
|
|
305
|
+
- [x] 自定义
|
|
@@ -78,7 +78,33 @@ declare class Application implements ApplicationInterface {
|
|
|
78
78
|
* @see https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/pre_auth_code.html
|
|
79
79
|
* @returns
|
|
80
80
|
*/
|
|
81
|
-
createPreAuthorizationCode(): Promise<
|
|
81
|
+
createPreAuthorizationCode(): Promise<{
|
|
82
|
+
/**
|
|
83
|
+
* 错误代码
|
|
84
|
+
*/
|
|
85
|
+
errcode?: string;
|
|
86
|
+
/**
|
|
87
|
+
* 错误信息
|
|
88
|
+
*/
|
|
89
|
+
errmsg?: string;
|
|
90
|
+
/**
|
|
91
|
+
* 预授权码
|
|
92
|
+
*/
|
|
93
|
+
pre_auth_code?: string;
|
|
94
|
+
/**
|
|
95
|
+
* 有效期,单位:秒
|
|
96
|
+
*/
|
|
97
|
+
expires_in?: number;
|
|
98
|
+
}>;
|
|
99
|
+
/**
|
|
100
|
+
* 生成授权页地址
|
|
101
|
+
* @param callbackUrl 授权后的回调地址
|
|
102
|
+
* @param optional 预授权码,不传
|
|
103
|
+
* @returns
|
|
104
|
+
*/
|
|
105
|
+
createPreAuthorizationUrl(callbackUrl: string, optional?: string | {
|
|
106
|
+
pre_auth_code: string;
|
|
107
|
+
}): Promise<string>;
|
|
82
108
|
getOAuth(): ProviderInterface;
|
|
83
109
|
/**
|
|
84
110
|
* 根据刷新令牌获取公众号实例
|
|
@@ -139,7 +165,7 @@ declare class Application implements ApplicationInterface {
|
|
|
139
165
|
* @param refreshToken
|
|
140
166
|
* @returns
|
|
141
167
|
*/
|
|
142
|
-
getAuthorizerAccessToken(appId: string, refreshToken: string): Promise<
|
|
168
|
+
getAuthorizerAccessToken(appId: string, refreshToken: string): Promise<string>;
|
|
143
169
|
createClient(): AccessTokenAwareClient;
|
|
144
170
|
/**
|
|
145
171
|
* 获取请求默认配置
|
|
@@ -187,6 +187,31 @@ class Application {
|
|
|
187
187
|
return response;
|
|
188
188
|
});
|
|
189
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* 生成授权页地址
|
|
192
|
+
* @param callbackUrl 授权后的回调地址
|
|
193
|
+
* @param optional 预授权码,不传
|
|
194
|
+
* @returns
|
|
195
|
+
*/
|
|
196
|
+
createPreAuthorizationUrl(callbackUrl, optional) {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
198
|
+
if (typeof optional === 'string') {
|
|
199
|
+
optional = {
|
|
200
|
+
pre_auth_code: optional,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
else if (!optional || !optional['pre_auth_code']) {
|
|
204
|
+
optional = {
|
|
205
|
+
pre_auth_code: (yield this.createPreAuthorizationCode()).pre_auth_code,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
let queries = (0, merge_1.default)({
|
|
209
|
+
component_appid: this.getAccount().getAppId(),
|
|
210
|
+
redirect_uri: callbackUrl,
|
|
211
|
+
}, optional);
|
|
212
|
+
return `https://mp.weixin.qq.com/cgi-bin/componentloginpage?${(0, Utils_1.buildQueryString)(queries)}`;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
190
215
|
getOAuth() {
|
|
191
216
|
let oauthFactory = ((app) => {
|
|
192
217
|
return (new WeChat_1.default({
|
|
@@ -329,7 +354,7 @@ class Application {
|
|
|
329
354
|
let authorizerAccessToken = yield cache.get(cacheKey);
|
|
330
355
|
if (!authorizerAccessToken) {
|
|
331
356
|
let response = yield this.refreshAuthorizerToken(appId, refreshToken);
|
|
332
|
-
|
|
357
|
+
authorizerAccessToken = response['authorizer_access_token'];
|
|
333
358
|
yield cache.set(cacheKey, authorizerAccessToken, ((_a = parseInt(response['expires_in'])) !== null && _a !== void 0 ? _a : 7200) - 500);
|
|
334
359
|
}
|
|
335
360
|
return authorizerAccessToken;
|