node-easywechat 3.7.14 → 3.7.16

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,16 @@
1
1
  # CHANGELOG
2
2
 
3
3
 
4
+ ## v3.7.16 (2026-06-09)
5
+
6
+ - Fix: 统一与补全oauth的配置参数
7
+
8
+ ## v3.7.15 (2026-06-09)
9
+
10
+ - Fix: 更新依赖包
11
+ - Fix: 修复获取企业微信代理应用jsapi签名错误的问题
12
+ - Fix: 修改企业微信网页授权的默认scope
13
+
4
14
  ## v3.7.14 (2026-06-08)
5
15
 
6
16
  - Fix: update dependencies
@@ -113,17 +113,19 @@ class Application {
113
113
  getOAuth() {
114
114
  if (!this.oauthFactory) {
115
115
  this.oauthFactory = ((app) => {
116
- return (new WeChat_1.WeChat({
116
+ return new WeChat_1.WeChat({
117
117
  client_id: app.getAccount().getAppId(),
118
118
  client_secret: app.getAccount().getSecret(),
119
119
  redirect: app.getConfig().get('oauth.redirect_url'),
120
- })).scopes(this.getConfig().get('oauth.scopes', 'snsapi_userinfo'));
120
+ });
121
121
  });
122
122
  }
123
123
  let provider = this.oauthFactory.call(null, this);
124
124
  if (!(provider instanceof WeChat_1.WeChat)) {
125
125
  throw new Error(`The factory must return a \`BaseProvider\` instance.`);
126
126
  }
127
+ provider.withRedirectUrl(this.getConfig().get('oauth.redirect_url'))
128
+ .scopes(this.getConfig().get('oauth.scopes', 'snsapi_userinfo'));
127
129
  return provider;
128
130
  }
129
131
  getTicket() {
@@ -208,16 +208,18 @@ class Application {
208
208
  }
209
209
  getOAuth() {
210
210
  let oauthFactory = ((app) => {
211
- return (new WeChat_1.WeChat({
211
+ return new WeChat_1.WeChat({
212
212
  client_id: app.getAccount().getAppId(),
213
213
  client_secret: app.getAccount().getSecret(),
214
214
  redirect: app.getConfig().get('oauth.redirect_url'),
215
- })).scopes(this.getConfig().get('oauth.scopes', 'snsapi_userinfo'));
215
+ });
216
216
  });
217
217
  let provider = oauthFactory.call(null, this);
218
218
  if (!(provider instanceof WeChat_1.WeChat)) {
219
219
  throw new Error(`The factory must return a \`WeChat\` instance.`);
220
220
  }
221
+ provider.withRedirectUrl(this.getConfig().get('oauth.redirect_url'))
222
+ .scopes(this.getConfig().get('oauth.scopes', 'snsapi_userinfo'));
221
223
  return provider;
222
224
  }
223
225
  /**
@@ -254,6 +256,7 @@ class Application {
254
256
  config.token = this.config.get('token');
255
257
  config.aes_key = this.config.get('aes_key');
256
258
  config.http = this.config.get('http', {});
259
+ config.oauth = this.config.get('oauth', {});
257
260
  config = new Config_1.default(config);
258
261
  }
259
262
  else {
@@ -261,6 +264,7 @@ class Application {
261
264
  config.set('token', this.config.get('token'));
262
265
  config.set('aes_key', this.config.get('aes_key'));
263
266
  config.set('http', this.config.get('http', {}));
267
+ config.set('oauth', this.config.get('oauth', {}));
264
268
  }
265
269
  let app = new Application_1.default(config);
266
270
  app.setAccessToken(authorizerAccessToken);
@@ -282,8 +286,9 @@ class Application {
282
286
  component_app_id: this.getAccount().getSecret(),
283
287
  component_access_token: this.getComponentAccessToken().getToken(),
284
288
  },
285
- redirect: this.config.get('oauth.redirect_url'),
286
- })).scopes(config.get('oauth.scopes', 'snsapi_userinfo'));
289
+ redirect: config.get('oauth.redirect_url'),
290
+ }))
291
+ .scopes(config.get('oauth.scopes', 'snsapi_userinfo'));
287
292
  });
288
293
  }
289
294
  /**
@@ -287,6 +287,7 @@ class Application {
287
287
  }))
288
288
  .withSuiteTicket(await this.getSuiteTicket().getTicket())
289
289
  .withSuiteAccessToken(await suiteAccessToken.getToken())
290
+ .withRedirectUrl(this.getConfig().get('oauth.redirect_url'))
290
291
  .scopes(this.getConfig().get('oauth.scopes', 'snsapi_base'));
291
292
  }
292
293
  async getCorpOAuth(corpId, suiteAccessToken = null) {
@@ -299,6 +300,7 @@ class Application {
299
300
  }))
300
301
  .withSuiteTicket(await this.getSuiteTicket().getTicket())
301
302
  .withSuiteAccessToken(await suiteAccessToken.getToken())
303
+ .withRedirectUrl(this.getConfig().get('oauth.redirect_url'))
302
304
  .scopes(this.getConfig().get('oauth.scopes', 'snsapi_base'));
303
305
  }
304
306
  /**
@@ -27,21 +27,6 @@ export interface WeixinResponse extends Record<string, any> {
27
27
  errmsg?: string,
28
28
  }
29
29
 
30
- /**
31
- * 公众号网页授权相关配置
32
- */
33
- export interface OauthConfig {
34
- /**
35
- * 网页授权权限,可选值:snsapi_userinfo、snsapi_base
36
- */
37
- scope: string;
38
-
39
- /**
40
- * 网页授权回调地址,完整URL
41
- */
42
- redirect_url: string;
43
- }
44
-
45
30
  /**
46
31
  * 文件缓存相关配置
47
32
  */
@@ -135,7 +120,17 @@ export interface OfficialAccountConfig extends BaseConfig {
135
120
  /**
136
121
  * 网页授权相关配置
137
122
  */
138
- oauth?: OauthConfig;
123
+ oauth?: {
124
+ /**
125
+ * 网页授权权限,可选值:snsapi_userinfo、snsapi_base,默认:snsapi_userinfo
126
+ */
127
+ scopes: string;
128
+
129
+ /**
130
+ * 网页授权回调地址,完整URL
131
+ */
132
+ redirect_url?: string;
133
+ };
139
134
 
140
135
  /**
141
136
  * 是否使用稳定版接口调用凭据,默认:false
@@ -237,6 +232,21 @@ export interface OpenPlatformConfig extends BaseConfig {
237
232
  * 开发平台服务端消息加解密密钥 aes_key
238
233
  */
239
234
  aes_key?: string;
235
+
236
+ /**
237
+ * 网页授权相关配置
238
+ */
239
+ oauth?: {
240
+ /**
241
+ * 网页授权权限,可选值:snsapi_userinfo、snsapi_base,默认:snsapi_userinfo
242
+ */
243
+ scopes: string;
244
+
245
+ /**
246
+ * 网页授权回调地址,完整URL
247
+ */
248
+ redirect_url?: string;
249
+ };
240
250
  }
241
251
 
242
252
  /**
@@ -248,6 +258,11 @@ export interface WorkConfig extends BaseConfig {
248
258
  */
249
259
  corp_id?: string;
250
260
 
261
+ /**
262
+ * 应用ID(AgentId)
263
+ */
264
+ agent_id?: string;
265
+
251
266
  /**
252
267
  * 企业微信 secret
253
268
  */
@@ -262,6 +277,21 @@ export interface WorkConfig extends BaseConfig {
262
277
  * 企业微信服务端消息加解密密钥 aes_key
263
278
  */
264
279
  aes_key?: string;
280
+
281
+ /**
282
+ * 网页授权相关配置
283
+ */
284
+ oauth?: {
285
+ /**
286
+ * 网页授权权限,可选值:snsapi_privateinfo、snsapi_base,默认:snsapi_base
287
+ */
288
+ scopes: string;
289
+
290
+ /**
291
+ * 网页授权回调地址,完整URL
292
+ */
293
+ redirect_url?: string;
294
+ };
265
295
  }
266
296
 
267
297
  /**
@@ -297,6 +327,21 @@ export interface OpenWorkConfig extends BaseConfig {
297
327
  * 企业微信服务端消息加解密密钥 aes_key
298
328
  */
299
329
  aes_key?: string;
330
+
331
+ /**
332
+ * 网页授权相关配置
333
+ */
334
+ oauth?: {
335
+ /**
336
+ * 网页授权权限,可选值:snsapi_privateinfo、snsapi_base,默认:snsapi_base
337
+ */
338
+ scopes: string;
339
+
340
+ /**
341
+ * 网页授权回调地址,完整URL
342
+ */
343
+ redirect_url?: string;
344
+ };
300
345
  }
301
346
 
302
347
  /**
@@ -124,9 +124,10 @@ class Application {
124
124
  if (!(provider instanceof WeWork_1.WeWork)) {
125
125
  throw new Error(`The factory must return a \`WeWork\` instance.`);
126
126
  }
127
- provider.withApiAccessToken(await this.getAccessToken().getToken());
128
- provider.scopes(this.getConfig().get('oauth.scopes', 'snsapi_userinfo'));
129
- let agent_id = parseInt(this.config.get('agent_id')) || null;
127
+ provider.withApiAccessToken(await this.getAccessToken().getToken())
128
+ .withRedirectUrl(this.getConfig().get('oauth.redirect_url'))
129
+ .scopes(this.getConfig().get('oauth.scopes', 'snsapi_base'));
130
+ let agent_id = parseInt(this.getConfig().get('agent_id')) || null;
130
131
  if (agent_id) {
131
132
  provider.setAgentId(agent_id);
132
133
  }
@@ -8,6 +8,7 @@ class Config extends Config_1.default {
8
8
  super(...arguments);
9
9
  this.requiredKeys = [
10
10
  'corp_id',
11
+ 'agent_id',
11
12
  'secret',
12
13
  'token',
13
14
  'aes_key',
@@ -74,7 +74,7 @@ class JsApiTicket extends AccessToken_1.default {
74
74
  async createAgentConfigSignature(agentId, url, nonce = null, timestamp = null) {
75
75
  nonce = nonce || (0, Utils_1.randomString)(10);
76
76
  timestamp = timestamp || (0, Utils_1.getTimestamp)();
77
- let ticket = await this.getTicket();
77
+ let ticket = await this.getAgentTicket(agentId);
78
78
  return {
79
79
  corpid: this.corpId,
80
80
  agentid: agentId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-easywechat",
3
- "version": "3.7.14",
3
+ "version": "3.7.16",
4
4
  "description": "EasyWechat SDK for Node.js (NOT OFFICIAL)",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -33,7 +33,7 @@
33
33
  "axios-retry": "^4.5.0",
34
34
  "form-data": "^4.0.5",
35
35
  "merge": "^2.1.1",
36
- "node-socialite": "^1.5.5",
36
+ "node-socialite": "^1.5.6",
37
37
  "qs": "^6.15.2",
38
38
  "raw-body": "^2.5.3",
39
39
  "xml2js": "^0.6.2"