node-easywechat 3.3.1 → 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
@@ -1,6 +1,12 @@
1
1
  # CHANGELOG
2
2
 
3
3
 
4
+ ## v3.3.2 (2023-03-30)
5
+
6
+ - Feat: 新增生成授权页地址的方法
7
+
8
+ - Fix: 修复获取第三方授权令牌异常的问题
9
+
4
10
  ## v3.3.1 (2023-03-27)
5
11
 
6
12
  - Fix: 调整3.x分支为npm的latest标签
@@ -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<import("../Types/global").WeixinResponse>;
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<any>;
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
- let authorizerAccessToken = response['authorizer_access_token'];
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-easywechat",
3
- "version": "3.3.1",
3
+ "version": "3.3.2",
4
4
  "description": "EasyWechat SDK for Node.js (NOT OFFICIAL)",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {