node-easywechat 2.8.0 → 2.9.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.
Files changed (142) hide show
  1. package/README.md +51 -4
  2. package/dist/BaseService/Jssdk/JssdkClient.js +5 -5
  3. package/dist/BaseService/Media/MediaClient.js +1 -1
  4. package/dist/Core/AES.d.ts +1 -1
  5. package/dist/Core/AES.js +4 -4
  6. package/dist/Core/BaseAccessToken.js +2 -2
  7. package/dist/Core/BaseApplication.js +4 -4
  8. package/dist/Core/BaseClient.js +2 -2
  9. package/dist/Core/Cache/FileCache.js +3 -3
  10. package/dist/Core/Encryptor.js +3 -3
  11. package/dist/Core/Http/Request.js +13 -13
  12. package/dist/Core/Http/StreamResponse.js +1 -1
  13. package/dist/Core/Messages/Media.js +2 -2
  14. package/dist/Core/Messages/Message.js +7 -7
  15. package/dist/Core/Mixins/HttpMixin.js +4 -4
  16. package/dist/Core/ServerGuard.d.ts +2 -2
  17. package/dist/Core/ServerGuard.js +5 -5
  18. package/dist/Core/Types.d.ts +34 -4
  19. package/dist/Core/Utils.js +18 -18
  20. package/dist/MicroMerchant/Application.js +1 -1
  21. package/dist/MicroMerchant/Base/MicroMerchantBase.js +6 -6
  22. package/dist/MicroMerchant/Certficates/CertficatesClient.js +1 -1
  23. package/dist/MicroMerchant/Core/BaseClient.js +8 -8
  24. package/dist/MicroMerchant/Media/MediaClient.js +1 -1
  25. package/dist/MicroMerchant/MerchantConfig/MerchantConfigClient.js +1 -1
  26. package/dist/MicroMerchant/Meterial/MeterialClient.js +4 -4
  27. package/dist/MicroMerchant/Withdraw/WithdrawClient.js +2 -2
  28. package/dist/MiniProgram/ActivityMessage/ActivityMessageClient.js +3 -3
  29. package/dist/MiniProgram/AppCode/AppCodeClient.js +2 -2
  30. package/dist/MiniProgram/Application.d.ts +16 -0
  31. package/dist/MiniProgram/Application.js +40 -0
  32. package/dist/MiniProgram/Base/MiniProgramBase.js +1 -1
  33. package/dist/MiniProgram/NearbyPoi/NearbyPoiClient.js +3 -3
  34. package/dist/MiniProgram/OpenData/OpenDataClient.js +2 -2
  35. package/dist/MiniProgram/RealtimeLog/RealtimeLogClient.js +1 -1
  36. package/dist/MiniProgram/Shop/AccoutClient.d.ts +25 -0
  37. package/dist/MiniProgram/Shop/AccoutClient.js +42 -0
  38. package/dist/MiniProgram/Shop/AftersaleClient.d.ts +22 -0
  39. package/dist/MiniProgram/Shop/AftersaleClient.js +35 -0
  40. package/dist/MiniProgram/Shop/BasicClient.d.ts +39 -0
  41. package/dist/MiniProgram/Shop/BasicClient.js +69 -0
  42. package/dist/MiniProgram/Shop/DeliveryClient.d.ts +20 -0
  43. package/dist/MiniProgram/Shop/DeliveryClient.js +32 -0
  44. package/dist/MiniProgram/Shop/OrderClient.d.ts +32 -0
  45. package/dist/MiniProgram/Shop/OrderClient.js +51 -0
  46. package/dist/MiniProgram/Shop/RegisterClient.d.ts +25 -0
  47. package/dist/MiniProgram/Shop/RegisterClient.js +43 -0
  48. package/dist/MiniProgram/Shop/SpuClient.d.ts +67 -0
  49. package/dist/MiniProgram/Shop/SpuClient.js +92 -0
  50. package/dist/MiniProgram/ShortLink/ShortLinkClient.d.ts +11 -0
  51. package/dist/MiniProgram/ShortLink/ShortLinkClient.js +23 -0
  52. package/dist/MiniProgram/SubscribeMessage/SubscribeMessageClient.js +5 -5
  53. package/dist/MiniProgram/UniformMessage/UniformMessageClient.js +3 -3
  54. package/dist/MiniProgram/UrlLink/UrlLinkClient.d.ts +6 -1
  55. package/dist/MiniProgram/UrlLink/UrlLinkClient.js +7 -2
  56. package/dist/OfficialAccount/Base/OfficialAccountBase.js +2 -2
  57. package/dist/OfficialAccount/Broadcasting/BroadcastingClient.js +2 -2
  58. package/dist/OfficialAccount/Broadcasting/MessageBuilder.js +1 -1
  59. package/dist/OfficialAccount/Card/Client.js +1 -1
  60. package/dist/OfficialAccount/Card/JssdkClient.js +2 -2
  61. package/dist/OfficialAccount/Card/MemberCardClient.js +1 -1
  62. package/dist/OfficialAccount/CustomerService/CustomerServiceClient.js +2 -2
  63. package/dist/OfficialAccount/CustomerService/Messenger.js +1 -1
  64. package/dist/OfficialAccount/DataCube/DataCubeClient.js +1 -1
  65. package/dist/OfficialAccount/Material/MaterialClient.js +2 -2
  66. package/dist/OfficialAccount/OCR/OCRClient.js +1 -1
  67. package/dist/OfficialAccount/Semantic/SemanticClient.js +1 -1
  68. package/dist/OfficialAccount/SubscribeMessage/SubscribeMessageClient.js +4 -4
  69. package/dist/OfficialAccount/TemplateMessage/TemplateMessageClient.js +4 -4
  70. package/dist/OpenPlatform/Application.js +8 -8
  71. package/dist/OpenPlatform/Authorizer/Auth/AccessToken.js +1 -1
  72. package/dist/OpenPlatform/Authorizer/OfficialAccount/Account/Client.js +1 -1
  73. package/dist/OpenWork/Application.d.ts +37 -0
  74. package/dist/OpenWork/Application.js +128 -0
  75. package/dist/OpenWork/Auth/ProviderAccessToken.d.ts +8 -0
  76. package/dist/OpenWork/Auth/ProviderAccessToken.js +33 -0
  77. package/dist/OpenWork/Auth/SuiteAccessToken.d.ts +8 -0
  78. package/dist/OpenWork/Auth/SuiteAccessToken.js +34 -0
  79. package/dist/OpenWork/Auth/SuiteTicket.d.ts +8 -0
  80. package/dist/OpenWork/Auth/SuiteTicket.js +40 -0
  81. package/dist/OpenWork/Corp/CorpClient.d.ts +72 -0
  82. package/dist/OpenWork/Corp/CorpClient.js +150 -0
  83. package/dist/OpenWork/MiniProgram/MiniProgramClient.d.ts +5 -0
  84. package/dist/OpenWork/MiniProgram/MiniProgramClient.js +18 -0
  85. package/dist/OpenWork/Provider/ProviderClient.d.ts +81 -0
  86. package/dist/OpenWork/Provider/ProviderClient.js +172 -0
  87. package/dist/OpenWork/Server/OpenWorkGuard.d.ts +13 -0
  88. package/dist/OpenWork/Server/OpenWorkGuard.js +51 -0
  89. package/dist/OpenWork/Work/Application.d.ts +5 -0
  90. package/dist/OpenWork/Work/Application.js +22 -0
  91. package/dist/OpenWork/Work/Auth/AccessToken.d.ts +12 -0
  92. package/dist/OpenWork/Work/Auth/AccessToken.js +44 -0
  93. package/dist/Payment/Application.js +4 -4
  94. package/dist/Payment/Bill/BillClient.js +2 -2
  95. package/dist/Payment/Core/BaseClient.js +8 -8
  96. package/dist/Payment/Jssdk/JssdkClient.js +14 -14
  97. package/dist/Payment/Merchant/MerchantClient.js +1 -1
  98. package/dist/Payment/Notify/Handler.js +5 -5
  99. package/dist/Payment/Notify/Refunded.js +1 -1
  100. package/dist/Payment/Notify/Scanned.js +2 -2
  101. package/dist/Payment/Order/OrderClient.js +1 -1
  102. package/dist/Payment/Redpack/RedpackClient.js +5 -5
  103. package/dist/Payment/Refund/RefundClient.js +3 -3
  104. package/dist/Payment/Sandbox/SandboxClient.js +1 -1
  105. package/dist/Payment/Transfer/TransferClient.js +1 -1
  106. package/dist/Work/Agent/AgentClient.js +1 -1
  107. package/dist/Work/Agent/WorkbenchClient.d.ts +24 -0
  108. package/dist/Work/Agent/WorkbenchClient.js +39 -0
  109. package/dist/Work/Application.d.ts +8 -0
  110. package/dist/Work/Application.js +20 -0
  111. package/dist/Work/Calendar/CalendarClient.js +1 -1
  112. package/dist/Work/Chat/ChatClient.js +1 -1
  113. package/dist/Work/CorpGroup/CorpGroupClient.d.ts +34 -0
  114. package/dist/Work/CorpGroup/CorpGroupClient.js +42 -0
  115. package/dist/Work/Department/DepartmentClient.js +1 -1
  116. package/dist/Work/ExternalContact/Client.d.ts +56 -0
  117. package/dist/Work/ExternalContact/Client.js +88 -0
  118. package/dist/Work/ExternalContact/ContactWayClient.d.ts +37 -0
  119. package/dist/Work/ExternalContact/ContactWayClient.js +51 -2
  120. package/dist/Work/ExternalContact/MessageClient.js +4 -4
  121. package/dist/Work/ExternalContact/MessageTemplateClient.js +3 -3
  122. package/dist/Work/ExternalContact/MomentClient.d.ts +56 -3
  123. package/dist/Work/ExternalContact/MomentClient.js +62 -3
  124. package/dist/Work/ExternalContact/StatisticsClient.d.ts +24 -0
  125. package/dist/Work/ExternalContact/StatisticsClient.js +35 -0
  126. package/dist/Work/Jssdk/JssdkClient.js +3 -3
  127. package/dist/Work/Kf/KfAccountClient.d.ts +41 -0
  128. package/dist/Work/Kf/KfAccountClient.js +71 -0
  129. package/dist/Work/Kf/KfMessageClient.d.ts +44 -0
  130. package/dist/Work/Kf/KfMessageClient.js +73 -0
  131. package/dist/Work/Kf/KfServicerClient.d.ts +26 -0
  132. package/dist/Work/Kf/KfServicerClient.js +47 -0
  133. package/dist/Work/Media/MediaClient.js +1 -1
  134. package/dist/Work/Message/Messenger.js +2 -2
  135. package/dist/Work/Schedule/ScheduleClient.js +1 -1
  136. package/dist/Work/Server/Guard.d.ts +1 -1
  137. package/dist/Work/User/UserClient.js +3 -3
  138. package/dist/index.d.ts +8 -2
  139. package/dist/index.js +9 -7
  140. package/node-easywechat.file_cache.easywechat.kernel.access_token.8a9684b45da7de42a06a70ba01a7005a.cache +1 -1
  141. package/node-easywechat.file_cache.easywechat.kernel.access_token.c3d06edaf326aad75d32f31348df787a.cache +1 -1
  142. package/package.json +11 -11
@@ -19,7 +19,7 @@ class MemberCardClient extends Client_1.default {
19
19
  * @param settings 会员卡激活时的选项
20
20
  */
21
21
  setActivationForm(cardId, settings) {
22
- let params = Utils_1.merge({
22
+ let params = (0, Utils_1.merge)({
23
23
  card_id: cardId,
24
24
  }, settings);
25
25
  return this.httpPostJson('card/membercard/activateuserform/set', params);
@@ -68,8 +68,8 @@ class CustomerServiceClient extends BaseClient_1.default {
68
68
  }
69
69
  messages(startTime, endTime, msgId = 1, number = 10000) {
70
70
  return this.httpPostJson('customservice/msgrecord/getmsglist', {
71
- starttime: Utils_1.getTimestamp(startTime),
72
- endtime: Utils_1.getTimestamp(endTime),
71
+ starttime: (0, Utils_1.getTimestamp)(startTime),
72
+ endtime: (0, Utils_1.getTimestamp)(endTime),
73
73
  msgid: msgId,
74
74
  number: number,
75
75
  });
@@ -8,7 +8,7 @@ class Messenger {
8
8
  this.client = client;
9
9
  }
10
10
  message(message) {
11
- if (Utils_1.isString(message)) {
11
+ if ((0, Utils_1.isString)(message)) {
12
12
  message = new Messages_1.Text(message);
13
13
  }
14
14
  this._message = message;
@@ -193,7 +193,7 @@ class DataCubeClient extends BaseClient_1.default {
193
193
  return this.query('datacube/getcardmembercarddetail', from, to, ext);
194
194
  }
195
195
  query(api, from, to, ext = {}) {
196
- let params = Utils_1.merge({
196
+ let params = (0, Utils_1.merge)({
197
197
  begin_date: from,
198
198
  end_date: to,
199
199
  }, ext);
@@ -70,10 +70,10 @@ class MaterialClient extends BaseClient_1.default {
70
70
  if (!file) {
71
71
  throw new Error(`File does not exist, or the file is unreadable: '${file}'`);
72
72
  }
73
- if (Utils_1.isString(file)) {
73
+ if ((0, Utils_1.isString)(file)) {
74
74
  file = fs_1.default.createReadStream(file);
75
75
  }
76
- if (!Utils_1.inArray(type, this.allowTypes)) {
76
+ if (!(0, Utils_1.inArray)(type, this.allowTypes)) {
77
77
  throw new Error(`Unsupported media type: '${type}'`);
78
78
  }
79
79
  let formData = new form_data_1.default();
@@ -19,7 +19,7 @@ class OCRClient extends BaseClient_1.default {
19
19
  * @param type
20
20
  */
21
21
  idCard(img_url, type = 'photo') {
22
- if (!Utils_1.inArray(type, this.allowTypes, true)) {
22
+ if (!(0, Utils_1.inArray)(type, this.allowTypes, true)) {
23
23
  throw new Error(`Unsupported type: '${type}'`);
24
24
  }
25
25
  return this.httpPost('cv/ocr/idcard', {
@@ -13,7 +13,7 @@ class SemanticClient extends BaseClient_1.default {
13
13
  * @param optional 其它参数。属性:latitude,纬度,与城市二选一;longitude,经度,与城市二选一;city,城市,与经纬度二选一;region,区域名称,在城市存在的情况下可省;uid,用户唯一id(非开发者id);
14
14
  */
15
15
  query(keyword, categories, optional = {}) {
16
- let params = Utils_1.merge({
16
+ let params = (0, Utils_1.merge)({
17
17
  query: keyword,
18
18
  category: categories,
19
19
  appid: this.app.config.app_id,
@@ -82,9 +82,9 @@ class SubscribeMessageClient extends BaseClient_1.default {
82
82
  return this.httpPostJson(this.API_SEND, params);
83
83
  }
84
84
  formatMessage(data) {
85
- let params = Utils_1.merge(Utils_1.merge({}, this.message), data);
85
+ let params = (0, Utils_1.merge)((0, Utils_1.merge)({}, this.message), data);
86
86
  for (let key in params) {
87
- if (Utils_1.inArray(key, this.required) && !params[key]) {
87
+ if ((0, Utils_1.inArray)(key, this.required) && !params[key]) {
88
88
  throw new Error(`Attribute "${key}" can not be empty!`);
89
89
  }
90
90
  }
@@ -95,12 +95,12 @@ class SubscribeMessageClient extends BaseClient_1.default {
95
95
  let formatted = {}, value;
96
96
  for (let key in data) {
97
97
  value = {};
98
- if (Utils_1.isArray(data[key]) && data[key].length == 2) {
98
+ if ((0, Utils_1.isArray)(data[key]) && data[key].length == 2) {
99
99
  value = {
100
100
  value: data[key][0],
101
101
  };
102
102
  }
103
- else if (Utils_1.isObject(data[key]) && data[key]['value']) {
103
+ else if ((0, Utils_1.isObject)(data[key]) && data[key]['value']) {
104
104
  value = data[key];
105
105
  }
106
106
  else {
@@ -79,9 +79,9 @@ class Client extends BaseClient_1.default {
79
79
  return this.httpPostJson('cgi-bin/message/template/subscribe', params);
80
80
  }
81
81
  formatMessage(data) {
82
- let params = Utils_1.merge(Utils_1.merge({}, this.message), data);
82
+ let params = (0, Utils_1.merge)((0, Utils_1.merge)({}, this.message), data);
83
83
  for (let key in params) {
84
- if (Utils_1.inArray(key, this.required) && !params[key]) {
84
+ if ((0, Utils_1.inArray)(key, this.required) && !params[key]) {
85
85
  throw new Error(`Attribute "${key}" can not be empty!`);
86
86
  }
87
87
  }
@@ -92,13 +92,13 @@ class Client extends BaseClient_1.default {
92
92
  let formatted = {}, value;
93
93
  for (let key in data) {
94
94
  value = {};
95
- if (Utils_1.isArray(data[key]) && data[key].length == 2) {
95
+ if ((0, Utils_1.isArray)(data[key]) && data[key].length == 2) {
96
96
  value = {
97
97
  value: data[key][0],
98
98
  color: data[key][1],
99
99
  };
100
100
  }
101
- else if (Utils_1.isObject(data[key]) && data[key]['value']) {
101
+ else if ((0, Utils_1.isObject)(data[key]) && data[key]['value']) {
102
102
  value = data[key];
103
103
  }
104
104
  else {
@@ -70,7 +70,7 @@ class OpenPlatform extends BaseApplication_1.default {
70
70
  */
71
71
  getPreAuthorizationUrl(callbackUrl, optional = {}) {
72
72
  return __awaiter(this, void 0, void 0, function* () {
73
- if (Utils_1.isString(optional)) {
73
+ if ((0, Utils_1.isString)(optional)) {
74
74
  optional = {
75
75
  pre_auth_code: optional,
76
76
  };
@@ -78,7 +78,7 @@ class OpenPlatform extends BaseApplication_1.default {
78
78
  else {
79
79
  optional['pre_auth_code'] = (yield this.createPreAuthorizationCode())['pre_auth_code'];
80
80
  }
81
- return 'https://mp.weixin.qq.com/cgi-bin/componentloginpage?' + Utils_1.buildQueryString(Utils_1.merge(Utils_1.merge({}, optional), {
81
+ return 'https://mp.weixin.qq.com/cgi-bin/componentloginpage?' + (0, Utils_1.buildQueryString)((0, Utils_1.merge)((0, Utils_1.merge)({}, optional), {
82
82
  component_appid: this.config['app_id'],
83
83
  redirect_uri: callbackUrl,
84
84
  }));
@@ -91,15 +91,15 @@ class OpenPlatform extends BaseApplication_1.default {
91
91
  */
92
92
  getMobilePreAuthorizationUrl(callbackUrl, optional = {}) {
93
93
  return __awaiter(this, void 0, void 0, function* () {
94
- if (Utils_1.isString(optional)) {
94
+ if ((0, Utils_1.isString)(optional)) {
95
95
  optional = {
96
96
  pre_auth_code: optional,
97
97
  };
98
98
  }
99
99
  else {
100
- optional['pre_auth_code'] = yield this.createPreAuthorizationCode()['pre_auth_code'];
100
+ optional['pre_auth_code'] = (yield this.createPreAuthorizationCode())['pre_auth_code'];
101
101
  }
102
- return 'https://mp.weixin.qq.com/safe/bindcomponent?' + Utils_1.buildQueryString(Utils_1.merge(optional, {
102
+ return 'https://mp.weixin.qq.com/safe/bindcomponent?' + (0, Utils_1.buildQueryString)((0, Utils_1.merge)((0, Utils_1.merge)({}, optional), {
103
103
  component_appid: this.config['app_id'],
104
104
  redirect_uri: callbackUrl,
105
105
  action: 'bindcomponent',
@@ -108,7 +108,7 @@ class OpenPlatform extends BaseApplication_1.default {
108
108
  });
109
109
  }
110
110
  getAuthorizerConfig(appId, refreshToken = null) {
111
- return Utils_1.merge(Utils_1.merge({}, this.config), {
111
+ return (0, Utils_1.merge)((0, Utils_1.merge)({}, this.config), {
112
112
  component_app_id: this.config['app_id'],
113
113
  app_id: appId,
114
114
  refresh_token: refreshToken,
@@ -139,7 +139,7 @@ class OpenPlatform extends BaseApplication_1.default {
139
139
  */
140
140
  officialAccount(appId, refreshToken = null, accessToken = null) {
141
141
  let that = this;
142
- let services = Utils_1.merge(Utils_1.merge({}, this.getReplaceServices(accessToken)), {
142
+ let services = (0, Utils_1.merge)((0, Utils_1.merge)({}, this.getReplaceServices(accessToken)), {
143
143
  encryptor: this.encryptor,
144
144
  account: function (app) {
145
145
  return new Client_1.default(app, that);
@@ -159,7 +159,7 @@ class OpenPlatform extends BaseApplication_1.default {
159
159
  */
160
160
  miniProgram(appId, refreshToken = null, accessToken = null) {
161
161
  let that = this;
162
- let services = Utils_1.merge(Utils_1.merge({}, this.getReplaceServices(accessToken)), {
162
+ let services = (0, Utils_1.merge)((0, Utils_1.merge)({}, this.getReplaceServices(accessToken)), {
163
163
  auth: function (app) {
164
164
  return new Client_2.default(app, that);
165
165
  },
@@ -34,7 +34,7 @@ class AccessToken extends BaseAccessToken_1.default {
34
34
  }
35
35
  getEndpoint() {
36
36
  return __awaiter(this, void 0, void 0, function* () {
37
- return 'cgi-bin/component/api_authorizer_token?' + Utils_1.buildQueryString({
37
+ return 'cgi-bin/component/api_authorizer_token?' + (0, Utils_1.buildQueryString)({
38
38
  component_access_token: (yield this.component.access_token.getToken())['component_access_token'],
39
39
  });
40
40
  });
@@ -23,7 +23,7 @@ class Client extends Client_1.default {
23
23
  appid: this.app.config.app_id,
24
24
  redirect_uri: callbackUrl,
25
25
  };
26
- return 'https://mp.weixin.qq.com/cgi-bin/fastregisterauth?' + Utils_1.buildQueryString(query);
26
+ return 'https://mp.weixin.qq.com/cgi-bin/fastregisterauth?' + (0, Utils_1.buildQueryString)(query);
27
27
  }
28
28
  /**
29
29
  * 第三方平台调用快速注册 API 完成注册
@@ -0,0 +1,37 @@
1
+ import BaseApplication from '../Core/BaseApplication';
2
+ import MiniProgram from '../Work/MiniProgram/Application';
3
+ import Work from './Work/Application';
4
+ import ProviderAccessToken from './Auth/ProviderAccessToken';
5
+ import SuiteAccessToken from './Auth/SuiteAccessToken';
6
+ import SuiteTicket from './Auth/SuiteTicket';
7
+ import CorpClient from './Corp/CorpClient';
8
+ import MiniProgramClient from './MiniProgram/MiniProgramClient';
9
+ import ProviderClient from './Provider/ProviderClient';
10
+ import Encryptor from '../Core/Encryptor';
11
+ import OpenWorkGuard from './Server/OpenWorkGuard';
12
+ import { EasyWechatConfig } from '../Core/Types';
13
+ export default class OpenWork extends BaseApplication {
14
+ protected defaultConfig: EasyWechatConfig;
15
+ provider_access_token: ProviderAccessToken;
16
+ suite_access_token: SuiteAccessToken;
17
+ suite_ticket: SuiteTicket;
18
+ corp: CorpClient;
19
+ mini_program: MiniProgramClient;
20
+ provider: ProviderClient;
21
+ encryptor_corp: Encryptor;
22
+ encryptor: Encryptor;
23
+ server: OpenWorkGuard;
24
+ constructor(config?: EasyWechatConfig, prepends?: Object, id?: String);
25
+ registerProviders(): void;
26
+ /**
27
+ * 代理小程序实现业务,返回SDK实例
28
+ */
29
+ miniProgram(): MiniProgram;
30
+ /**
31
+ * 代理企业微信实现业务,返回SDK实例
32
+ * @param authCorpId 企业 corp_id
33
+ * @param permanentCode 企业永久授权码
34
+ * @returns
35
+ */
36
+ work(authCorpId: string, permanentCode: string): Work;
37
+ }
@@ -0,0 +1,128 @@
1
+ 'use strict';
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const BaseApplication_1 = __importDefault(require("../Core/BaseApplication"));
16
+ const Application_1 = __importDefault(require("../Work/MiniProgram/Application"));
17
+ const Application_2 = __importDefault(require("./Work/Application"));
18
+ const ProviderAccessToken_1 = __importDefault(require("./Auth/ProviderAccessToken"));
19
+ const SuiteAccessToken_1 = __importDefault(require("./Auth/SuiteAccessToken"));
20
+ const SuiteTicket_1 = __importDefault(require("./Auth/SuiteTicket"));
21
+ const CorpClient_1 = __importDefault(require("./Corp/CorpClient"));
22
+ const MiniProgramClient_1 = __importDefault(require("./MiniProgram/MiniProgramClient"));
23
+ const ProviderClient_1 = __importDefault(require("./Provider/ProviderClient"));
24
+ const Encryptor_1 = __importDefault(require("../Core/Encryptor"));
25
+ const OpenWorkGuard_1 = __importDefault(require("./Server/OpenWorkGuard"));
26
+ const FinallResult_1 = __importDefault(require("../Core/Decorators/FinallResult"));
27
+ class OpenWork extends BaseApplication_1.default {
28
+ constructor(config = {}, prepends = {}, id = null) {
29
+ super(config, prepends, id);
30
+ this.defaultConfig = {
31
+ // 必要配置
32
+ app_id: '',
33
+ key: '',
34
+ http: {
35
+ baseURL: 'https://qyapi.weixin.qq.com/',
36
+ },
37
+ };
38
+ this.provider_access_token = null;
39
+ this.suite_access_token = null;
40
+ this.suite_ticket = null;
41
+ this.corp = null;
42
+ this.mini_program = null;
43
+ this.provider = null;
44
+ this.encryptor_corp = null;
45
+ this.encryptor = null;
46
+ this.server = null;
47
+ this.registerProviders();
48
+ }
49
+ registerProviders() {
50
+ super.registerCommonProviders();
51
+ if (!this.provider_access_token) {
52
+ this.offsetSet('provider_access_token', function (app) {
53
+ return new ProviderAccessToken_1.default(app);
54
+ });
55
+ }
56
+ this.offsetSet('suite_ticket', function (app) {
57
+ return new SuiteTicket_1.default(app);
58
+ });
59
+ if (!this.suite_access_token) {
60
+ this.offsetSet('suite_access_token', function (app) {
61
+ return new SuiteAccessToken_1.default(app);
62
+ });
63
+ }
64
+ if (!this.corp) {
65
+ this.offsetSet('corp', function (app) {
66
+ return new CorpClient_1.default(app);
67
+ });
68
+ }
69
+ if (!this.mini_program) {
70
+ this.offsetSet('mini_program', function (app) {
71
+ return new MiniProgramClient_1.default(app);
72
+ });
73
+ }
74
+ if (!this.provider) {
75
+ this.offsetSet('provider', function (app) {
76
+ return new ProviderClient_1.default(app);
77
+ });
78
+ }
79
+ if (!this.encryptor_corp) {
80
+ this.offsetSet('encryptor_corp', function (app) {
81
+ return new Encryptor_1.default(app.config['corp_id'], app.config['token'], app.config['aes_key']);
82
+ });
83
+ }
84
+ if (!this.encryptor) {
85
+ this.offsetSet('encryptor', function (app) {
86
+ return new Encryptor_1.default(app.config['suite_id'], app.config['token'], app.config['aes_key']);
87
+ });
88
+ }
89
+ if (!this.server) {
90
+ this.offsetSet('server', function (app) {
91
+ let guard = new OpenWorkGuard_1.default(app);
92
+ guard.push(function (payload) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ let decrypted = yield this.app.request.get('echostr');
95
+ if (decrypted) {
96
+ let str = this.app.encryptor_corp.decrypt(decrypted, this.app.request.get('msg_signature'), this.app.request.get('nonce'), this.app.request.get('timestamp'));
97
+ return new FinallResult_1.default(str);
98
+ }
99
+ // 缓存SuiteTicket
100
+ if (typeof payload['SuiteTicket'] != 'undefined') {
101
+ yield this.app.suite_ticket.setTicket(payload['SuiteTicket']);
102
+ return new FinallResult_1.default('success');
103
+ }
104
+ return null;
105
+ });
106
+ });
107
+ return guard;
108
+ });
109
+ }
110
+ }
111
+ /**
112
+ * 代理小程序实现业务,返回SDK实例
113
+ */
114
+ miniProgram() {
115
+ return new Application_1.default(this.getConfig());
116
+ }
117
+ /**
118
+ * 代理企业微信实现业务,返回SDK实例
119
+ * @param authCorpId 企业 corp_id
120
+ * @param permanentCode 企业永久授权码
121
+ * @returns
122
+ */
123
+ work(authCorpId, permanentCode) {
124
+ return new Application_2.default(authCorpId, permanentCode, this);
125
+ }
126
+ }
127
+ exports.default = OpenWork;
128
+ ;
@@ -0,0 +1,8 @@
1
+ import BaseAccessToken from '../../Core/BaseAccessToken';
2
+ export default class ProviderAccessToken extends BaseAccessToken {
3
+ protected requestMethod: string;
4
+ protected tokenKey: string;
5
+ protected endpointToGetToken: string;
6
+ protected cachePrefix: string;
7
+ protected getCredentials(): Promise<object>;
8
+ }
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const BaseAccessToken_1 = __importDefault(require("../../Core/BaseAccessToken"));
16
+ class ProviderAccessToken extends BaseAccessToken_1.default {
17
+ constructor() {
18
+ super(...arguments);
19
+ this.requestMethod = 'POST';
20
+ this.tokenKey = 'provider_access_token';
21
+ this.endpointToGetToken = 'cgi-bin/service/get_provider_token';
22
+ this.cachePrefix = 'easywechat.kernel.provider_access_token.';
23
+ }
24
+ getCredentials() {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ return {
27
+ corpid: this.app.config.corp_id,
28
+ provider_secret: this.app.config.secret,
29
+ };
30
+ });
31
+ }
32
+ }
33
+ exports.default = ProviderAccessToken;
@@ -0,0 +1,8 @@
1
+ import BaseAccessToken from '../../Core/BaseAccessToken';
2
+ export default class SuiteAccessToken extends BaseAccessToken {
3
+ protected requestMethod: string;
4
+ protected tokenKey: string;
5
+ protected endpointToGetToken: string;
6
+ protected cachePrefix: string;
7
+ protected getCredentials(): Promise<object>;
8
+ }
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const BaseAccessToken_1 = __importDefault(require("../../Core/BaseAccessToken"));
16
+ class SuiteAccessToken extends BaseAccessToken_1.default {
17
+ constructor() {
18
+ super(...arguments);
19
+ this.requestMethod = 'POST';
20
+ this.tokenKey = 'suite_access_token';
21
+ this.endpointToGetToken = 'cgi-bin/service/get_suite_token';
22
+ this.cachePrefix = 'easywechat.kernel.suite_access_token.';
23
+ }
24
+ getCredentials() {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ return {
27
+ suite_id: this.app.config.suite_id,
28
+ suite_secret: this.app.config.suite_secret,
29
+ suite_ticket: yield this.app['suite_ticket'].getTicket(),
30
+ };
31
+ });
32
+ }
33
+ }
34
+ exports.default = SuiteAccessToken;
@@ -0,0 +1,8 @@
1
+ import BaseApplication from '../../Core/BaseApplication';
2
+ export default class SuiteTicket {
3
+ protected app: BaseApplication;
4
+ constructor(app: BaseApplication);
5
+ setTicket(ticket: string): Promise<this>;
6
+ getTicket(): Promise<string>;
7
+ protected getCacheKey(): string;
8
+ }
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ class SuiteTicket {
13
+ constructor(app) {
14
+ this.app = null;
15
+ this.app = app;
16
+ }
17
+ setTicket(ticket) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ let cacher = this.app.getCache();
20
+ yield cacher.set(this.getCacheKey(), ticket, 3600);
21
+ if (!(yield cacher.has(this.getCacheKey()))) {
22
+ throw new Error('Failed to cache suite ticket.');
23
+ }
24
+ return this;
25
+ });
26
+ }
27
+ getTicket() {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ let cached = yield this.app.getCache().get(this.getCacheKey());
30
+ if (cached) {
31
+ return cached;
32
+ }
33
+ throw new Error('Credential "suite_ticket" does not exist in cache.');
34
+ });
35
+ }
36
+ getCacheKey() {
37
+ return 'easywechat.open_work.suite_ticket.' + this.app.config.suite_id;
38
+ }
39
+ }
40
+ exports.default = SuiteTicket;
@@ -0,0 +1,72 @@
1
+ import BaseClient from '../../Core/BaseClient';
2
+ export default class CorpClient extends BaseClient {
3
+ constructor(app: any);
4
+ /**
5
+ * 企业授权应用
6
+ * @see https://developer.work.weixin.qq.com/document/path/90597
7
+ * @param preAuthCode
8
+ * @param redirectUri
9
+ * @param state
10
+ * @returns
11
+ */
12
+ getPreAuthorizationUrl(preAuthCode?: string, redirectUri?: string, state?: string): Promise<string>;
13
+ /**
14
+ * 获取预授权码
15
+ * @returns
16
+ */
17
+ getPreAuthCode(): Promise<any>;
18
+ /**
19
+ * 设置授权配置
20
+ * @see https://developer.work.weixin.qq.com/document/path/90602
21
+ * @param preAuthCode
22
+ * @param sessionInfo
23
+ * @returns
24
+ */
25
+ setSession(preAuthCode: string, sessionInfo: object): Promise<any>;
26
+ /**
27
+ * 获取企业永久授权码
28
+ * @see https://developer.work.weixin.qq.com/document/path/90603
29
+ * @param authCode
30
+ * @returns
31
+ */
32
+ getPermanentByCode(authCode: string): Promise<any>;
33
+ /**
34
+ * 获取企业授权信息
35
+ * @see https://developer.work.weixin.qq.com/document/path/90604
36
+ * @param authCorpId
37
+ * @param permanentCode
38
+ * @returns
39
+ */
40
+ getAuthorization(authCorpId: string, permanentCode: string): Promise<any>;
41
+ /**
42
+ * 获取应用的管理员列表
43
+ * @see https://developer.work.weixin.qq.com/document/path/90606
44
+ * @param authCorpId
45
+ * @param agentId
46
+ * @returns
47
+ */
48
+ getManagers(authCorpId: string, agentId: string): Promise<any>;
49
+ /**
50
+ * 构造第三方应用oauth2链接
51
+ * @see https://developer.work.weixin.qq.com/document/path/91120
52
+ * @param redirectUri
53
+ * @param scope
54
+ * @param state
55
+ * @returns
56
+ */
57
+ getOAuthRedirectUrl(redirectUri?: string, scope?: string, state?: string): string;
58
+ /**
59
+ * 获取访问用户身份
60
+ * @see https://developer.work.weixin.qq.com/document/path/91121
61
+ * @param code
62
+ * @returns
63
+ */
64
+ getUserByCode(code: string): Promise<any>;
65
+ /**
66
+ * 获取访问用户敏感信息
67
+ * @see https://developer.work.weixin.qq.com/document/path/91122
68
+ * @param userTicket
69
+ * @returns
70
+ */
71
+ getUserByTicket(userTicket: string): Promise<any>;
72
+ }