node-easywechat 3.3.6 → 3.4.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/CHANGELOG.md +4 -0
- package/README.md +6 -2
- package/dist/MiniApp/Application.js +1 -1
- package/dist/OfficialAccount/AccessToken.d.ts +11 -1
- package/dist/OfficialAccount/AccessToken.js +31 -1
- package/dist/OfficialAccount/Application.js +1 -1
- package/dist/Types/global.d.ts +12 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -127,7 +127,9 @@ let data = response.toObject();
|
|
|
127
127
|
scope: 'snsapi_userinfo',
|
|
128
128
|
// 网页授权回调地址,完整的URL
|
|
129
129
|
redirect: 'http://node-easywechat.hpyer.cn/wxlogin/callback'
|
|
130
|
-
}
|
|
130
|
+
},
|
|
131
|
+
// 是否使用稳定版接口调用凭据,默认:false
|
|
132
|
+
use_stable_access_token: false
|
|
131
133
|
}
|
|
132
134
|
```
|
|
133
135
|
|
|
@@ -141,7 +143,9 @@ let data = response.toObject();
|
|
|
141
143
|
// 小程序的 token
|
|
142
144
|
token: '',
|
|
143
145
|
// EncodingAESKey
|
|
144
|
-
aes_key: ''
|
|
146
|
+
aes_key: '',
|
|
147
|
+
// 是否使用稳定版接口调用凭据,默认:false
|
|
148
|
+
use_stable_access_token: false
|
|
145
149
|
}
|
|
146
150
|
```
|
|
147
151
|
|
|
@@ -90,7 +90,7 @@ class Application {
|
|
|
90
90
|
}
|
|
91
91
|
getAccessToken() {
|
|
92
92
|
if (!this.accessToken) {
|
|
93
|
-
this.accessToken = new AccessToken_1.default(this.getAccount().getAppId(), this.getAccount().getSecret(), null, this.getCache(), this.getHttpClient());
|
|
93
|
+
this.accessToken = new AccessToken_1.default(this.getAccount().getAppId(), this.getAccount().getSecret(), null, this.getCache(), this.getHttpClient(), this.config.get('use_stable_access_token', false));
|
|
94
94
|
}
|
|
95
95
|
return this.accessToken;
|
|
96
96
|
}
|
|
@@ -7,7 +7,8 @@ declare class AccessToken implements RefreshableAccessTokenInterface {
|
|
|
7
7
|
protected key: string;
|
|
8
8
|
protected cache: CacheInterface;
|
|
9
9
|
protected httpClient: HttpClientInterface;
|
|
10
|
-
|
|
10
|
+
protected stable: boolean;
|
|
11
|
+
constructor(appId: string, secret: string, key?: string, cache?: CacheInterface, httpClient?: HttpClientInterface, stable?: boolean);
|
|
11
12
|
/**
|
|
12
13
|
* 获取access_token的缓存名称
|
|
13
14
|
* @returns
|
|
@@ -22,5 +23,14 @@ declare class AccessToken implements RefreshableAccessTokenInterface {
|
|
|
22
23
|
getToken(): Promise<string>;
|
|
23
24
|
toQuery(): Promise<Record<string, any>>;
|
|
24
25
|
refresh(): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* 获取稳定版接口调用凭据
|
|
28
|
+
* @param forceRefresh 是否强制刷新,默认:false
|
|
29
|
+
*/
|
|
30
|
+
getStableAccessToken(forceRefresh?: boolean): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* 获取接口调用凭据
|
|
33
|
+
*/
|
|
34
|
+
getAccessToken(): Promise<string>;
|
|
25
35
|
}
|
|
26
36
|
export = AccessToken;
|
|
@@ -13,12 +13,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
const HttpClient_1 = __importDefault(require("../Core/HttpClient/HttpClient"));
|
|
15
15
|
class AccessToken {
|
|
16
|
-
constructor(appId, secret, key = null, cache = null, httpClient = null) {
|
|
16
|
+
constructor(appId, secret, key = null, cache = null, httpClient = null, stable = false) {
|
|
17
17
|
this.appId = appId;
|
|
18
18
|
this.secret = secret;
|
|
19
19
|
this.key = key;
|
|
20
20
|
this.cache = cache;
|
|
21
21
|
this.httpClient = httpClient;
|
|
22
|
+
this.stable = stable;
|
|
22
23
|
if (!this.httpClient) {
|
|
23
24
|
this.httpClient = HttpClient_1.default.create({
|
|
24
25
|
baseURL: 'https://api.weixin.qq.com/',
|
|
@@ -64,6 +65,35 @@ class AccessToken {
|
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
67
|
refresh() {
|
|
68
|
+
return this.stable ? this.getStableAccessToken() : this.getAccessToken();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 获取稳定版接口调用凭据
|
|
72
|
+
* @param forceRefresh 是否强制刷新,默认:false
|
|
73
|
+
*/
|
|
74
|
+
getStableAccessToken(forceRefresh = false) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
let response = (yield this.httpClient.request('post', 'cgi-bin/stable_token', {
|
|
77
|
+
json: {
|
|
78
|
+
grant_type: 'client_credential',
|
|
79
|
+
appid: this.appId,
|
|
80
|
+
secret: this.secret,
|
|
81
|
+
force_refresh: forceRefresh,
|
|
82
|
+
}
|
|
83
|
+
})).toObject();
|
|
84
|
+
if (!response['access_token']) {
|
|
85
|
+
throw new Error('Failed to get stable access_token: ' + JSON.stringify(response));
|
|
86
|
+
}
|
|
87
|
+
if (this.cache) {
|
|
88
|
+
yield this.cache.set(this.getKey(), response['access_token'], parseInt(response['expires_in']));
|
|
89
|
+
}
|
|
90
|
+
return response['access_token'];
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 获取接口调用凭据
|
|
95
|
+
*/
|
|
96
|
+
getAccessToken() {
|
|
67
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
98
|
let response = (yield this.httpClient.request('get', 'cgi-bin/token', {
|
|
69
99
|
params: {
|
|
@@ -90,7 +90,7 @@ class Application {
|
|
|
90
90
|
}
|
|
91
91
|
getAccessToken() {
|
|
92
92
|
if (!this.accessToken) {
|
|
93
|
-
this.accessToken = new AccessToken_1.default(this.getAccount().getAppId(), this.getAccount().getSecret(), null, this.getCache(), this.getHttpClient());
|
|
93
|
+
this.accessToken = new AccessToken_1.default(this.getAccount().getAppId(), this.getAccount().getSecret(), null, this.getCache(), this.getHttpClient(), this.config.get('use_stable_access_token', false));
|
|
94
94
|
}
|
|
95
95
|
return this.accessToken;
|
|
96
96
|
}
|
package/dist/Types/global.d.ts
CHANGED
|
@@ -147,6 +147,12 @@ export declare interface OfficialAccountConfig extends BaseConfig {
|
|
|
147
147
|
* 网页授权相关配置
|
|
148
148
|
*/
|
|
149
149
|
oauth?: OauthConfig;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* 是否使用稳定版接口调用凭据,默认:false
|
|
153
|
+
* @see https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/getStableAccessToken.html
|
|
154
|
+
*/
|
|
155
|
+
use_stable_access_token?: boolean;
|
|
150
156
|
}
|
|
151
157
|
|
|
152
158
|
/**
|
|
@@ -172,6 +178,12 @@ export declare interface MiniAppConfig extends BaseConfig {
|
|
|
172
178
|
* 服务端消息加解密密钥 aes_key
|
|
173
179
|
*/
|
|
174
180
|
aes_key?: string;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* 是否使用稳定版接口调用凭据,默认:false
|
|
184
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/mp-access-token/getStableAccessToken.html
|
|
185
|
+
*/
|
|
186
|
+
use_stable_access_token?: boolean;
|
|
175
187
|
}
|
|
176
188
|
|
|
177
189
|
/**
|