node-easywechat 3.7.4 → 3.7.5

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.7.5 (2024-11-16)
5
+
6
+ - Feat: 企业微信开放平台模块,新增生成授权页地址、获取企业永久授权码两个方法
7
+
8
+ - Fix: 更新说明文档
9
+
4
10
  ## v3.7.4 (2024-08-14)
5
11
 
6
12
  - Fix: 更新依赖包
package/README.md CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  ### 使用说明
22
22
 
23
- 绝大部分API都可以根据 [EasyWeChat 的文档](https://www.easywechat.com/5.x/) 来使用。小部分(如获取请求相关数据、返回响应数据、支付证书等)的操作,由于语言环境的不同,会有不同处理。具体可以查看 [node-easywechat-demo](https://github.com/hpyer/node-easywechat-demo/) 以及下方的[自定义模块说明](#自定义模块模块替换使用方法) 。如果仍有疑问,请提issue,谢谢~
23
+ 请参考 [文档](https://hpyer.github.io/node-easywechat/) 来使用。如有需要可以查看 [示例代码](https://github.com/hpyer/node-easywechat-demo/)。如果仍有疑问,请提issue,谢谢~
24
24
 
25
25
  从 `3.x` 起 SDK 中不再内置具体业务的接口,仅封装底层基础部分,如认证、授权和 API 客户端。至于为什么不再封装业务接口,可以查看 [EasyWeChat 给出说明](https://easywechat.com/6.x/introduction.html#不再封装业务接口)。
26
26
 
@@ -96,6 +96,23 @@ declare class Application implements ApplicationInterface {
96
96
  * @returns
97
97
  */
98
98
  createPreAuthorizationCode(suiteAccessToken?: SuiteAccessToken): Promise<import("../Types/global").WeixinResponse>;
99
+ /**
100
+ * 生成授权页地址
101
+ * @see https://developer.work.weixin.qq.com/document/path/90597#从服务商网站发起
102
+ * @param callbackUrl 授权后的回调地址
103
+ * @param pre_auth_code 预授权码,不传则系统自动调用 createPreAuthorizationCode 获取
104
+ * @param state
105
+ * @returns
106
+ */
107
+ createPreAuthorizationUrl(callbackUrl: string, pre_auth_code?: string, state?: string): Promise<string>;
108
+ /**
109
+ * 获取企业永久授权码
110
+ * @see https://developer.work.weixin.qq.com/document/path/90603
111
+ * @param authCode 临时授权码
112
+ * @param suiteAccessToken
113
+ * @returns
114
+ */
115
+ getPermanentCode(authCode: string, suiteAccessToken?: SuiteAccessToken): Promise<import("../Types/global").WeixinResponse>;
99
116
  /**
100
117
  * 获取企业授权令牌
101
118
  * @param corpId
@@ -211,6 +211,49 @@ class Application {
211
211
  }
212
212
  return response;
213
213
  }
214
+ /**
215
+ * 生成授权页地址
216
+ * @see https://developer.work.weixin.qq.com/document/path/90597#从服务商网站发起
217
+ * @param callbackUrl 授权后的回调地址
218
+ * @param pre_auth_code 预授权码,不传则系统自动调用 createPreAuthorizationCode 获取
219
+ * @param state
220
+ * @returns
221
+ */
222
+ async createPreAuthorizationUrl(callbackUrl, pre_auth_code, state) {
223
+ let optional = {
224
+ pre_auth_code,
225
+ state,
226
+ };
227
+ if (!optional['pre_auth_code']) {
228
+ optional.pre_auth_code = (await this.createPreAuthorizationCode()).pre_auth_code;
229
+ }
230
+ let queries = (0, merge_1.default)({
231
+ suite_id: this.getAccount().getSuiteId(),
232
+ redirect_uri: callbackUrl,
233
+ }, optional);
234
+ return `https://open.work.weixin.qq.com/3rdapp/install?${(0, Utils_1.buildQueryString)(queries)}`;
235
+ }
236
+ /**
237
+ * 获取企业永久授权码
238
+ * @see https://developer.work.weixin.qq.com/document/path/90603
239
+ * @param authCode 临时授权码
240
+ * @param suiteAccessToken
241
+ * @returns
242
+ */
243
+ async getPermanentCode(authCode, suiteAccessToken = null) {
244
+ if (!suiteAccessToken)
245
+ suiteAccessToken = this.getSuiteAccessToken();
246
+ let response = (await this.getClient().request('post', '/cgi-bin/service/get_permanent_code', {
247
+ params: {
248
+ auth_code: authCode,
249
+ suite_access_token: await suiteAccessToken.getToken(),
250
+ }
251
+ })).toObject();
252
+ if (!response['permanent_code']) {
253
+ throw new Error('Failed to get permanent_code: ' + JSON.stringify(response));
254
+ }
255
+ return response;
256
+ }
214
257
  /**
215
258
  * 获取企业授权令牌
216
259
  * @param corpId
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-easywechat",
3
- "version": "3.7.4",
3
+ "version": "3.7.5",
4
4
  "description": "EasyWechat SDK for Node.js (NOT OFFICIAL)",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {