node-easywechat 2.9.5 → 2.9.6

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,10 @@
1
1
  # CHANGELOG
2
2
 
3
3
 
4
+ ## v2.9.6 (2022-04-25)
5
+
6
+ - Docs: 更新企业微信支付证书说明
7
+
4
8
  ## v2.9.5 (2022-04-23)
5
9
 
6
10
  - Fix: 修复企业微信获取注册定制化URL接口未自动获取到注册码的问题
package/README.md CHANGED
@@ -107,8 +107,8 @@ let app = EasyWechat.Factory.getInstance('OficialAccount', {
107
107
  key: 'key-for-signature',
108
108
  // 默认回调地址,也可以在下单时单独设置来覆盖它,完整URL,不带参数
109
109
  notify_url: 'http://xxx.com/pay/notify',
110
- // 证书地址,Node.js 只需要 .pfx 证书文件即可
111
- cert_path: 'path/to/your/cert.pfx', // XXX: 绝对路径!!!!
110
+ // 证书地址,Node.js 只需要 apiclient_cert.p12 证书文件即可
111
+ cert_path: 'path/to/your/apiclient_cert.p12', // XXX: 绝对路径!!!!
112
112
  }
113
113
  ```
114
114
 
@@ -143,8 +143,8 @@ let app = EasyWechat.Factory.getInstance('OficialAccount', {
143
143
  key: 'key-for-signature',
144
144
  // V3版本签名密钥
145
145
  apiv3_key: 'apiv3_key-for-signature',
146
- // 证书地址,Node.js 只需要 .pfx 证书文件即可
147
- cert_path: 'path/to/your/cert.pfx', // XXX: 绝对路径!!!!
146
+ // 证书地址,Node.js 只需要 apiclient_cert.p12 证书文件即可
147
+ cert_path: 'path/to/your/apiclient_cert.p12', // XXX: 绝对路径!!!!
148
148
 
149
149
  // 以下两项配置在获取证书接口时可为空,在调用入驻接口前请先调用获取证书接口获取以下两项配置,如果获取过证书可以直接在这里配置,也可参照本文档获取平台证书章节中示例
150
150
  // serial_no: '获取证书接口获取到的平台证书序列号',
@@ -63,7 +63,7 @@ declare abstract class BaseAccessToken implements HttpMixin {
63
63
  protected getCredentials(): Promise<object>;
64
64
  getEndpoint(): Promise<string>;
65
65
  getCacheKey(): Promise<string>;
66
- requestToken(credentials: object): Promise<any>;
66
+ requestToken(credentials: object): Promise<Record<string, any>>;
67
67
  /**
68
68
  * 获取Token
69
69
  * @param refresh 为true时表示强制刷新
@@ -77,10 +77,10 @@ declare abstract class BaseAccessToken implements HttpMixin {
77
77
  protected warpAccessToken(token: Record<string, any>): AccessToken;
78
78
  /**
79
79
  * 设置Token
80
- * @param access_token AccessToken
80
+ * @param access_token Record<string, any>
81
81
  * @param expires_in 有效时间,单位:秒
82
82
  */
83
- setToken(access_token: string, expires_in?: number): Promise<this>;
83
+ setToken(token: Record<string, any>, expires_in?: number): Promise<this>;
84
84
  /**
85
85
  * 刷新Token
86
86
  */
@@ -151,6 +151,9 @@ class BaseAccessToken {
151
151
  return this.warpAccessToken(token);
152
152
  }
153
153
  let res = yield this.requestToken(yield this.getCredentials());
154
+ if (res.errcode) {
155
+ throw new Error(res.errmsg);
156
+ }
154
157
  yield this.setToken(res, res.expires_in || 7200);
155
158
  return this.warpAccessToken(res);
156
159
  });
@@ -165,14 +168,14 @@ class BaseAccessToken {
165
168
  }
166
169
  /**
167
170
  * 设置Token
168
- * @param access_token AccessToken
171
+ * @param access_token Record<string, any>
169
172
  * @param expires_in 有效时间,单位:秒
170
173
  */
171
- setToken(access_token, expires_in = 7200) {
174
+ setToken(token, expires_in = 7200) {
172
175
  return __awaiter(this, void 0, void 0, function* () {
173
176
  let cacheKey = yield this.getCacheKey();
174
177
  let cache = this.app.getCache();
175
- yield cache.set(cacheKey, access_token, expires_in);
178
+ yield cache.set(cacheKey, token, expires_in);
176
179
  if (!cache.has(cacheKey)) {
177
180
  throw new Error('Failed to cache access token.');
178
181
  }
@@ -98,7 +98,7 @@ export declare interface EasyWechatConfig {
98
98
  */
99
99
  sub_mch_id?: string;
100
100
  /**
101
- * pfx 证书路径(敏感接口(如退款、发送红包等)需要)
101
+ * apiclient_cert.p12 证书文件路径(敏感接口(如退款、发送红包等)需要)
102
102
  * @scope Payment | MicroMerchant
103
103
  */
104
104
  cert_path?: string;
@@ -52,37 +52,37 @@ export default class OpenPlatform extends BaseApplication {
52
52
  * 使用授权码换取接口调用凭据和授权信息
53
53
  * @param authCode 授权码, 会在授权成功的回调返回给第三方平台
54
54
  */
55
- handleAuthorize(): Promise<any>;
55
+ handleAuthorize(...arg: any[]): Promise<any>;
56
56
  /**
57
57
  * 获取授权方的帐号基本信息
58
58
  * @param appId 授权方app_id
59
59
  */
60
- getAuthorizer(): Promise<any>;
60
+ getAuthorizer(...arg: any[]): Promise<any>;
61
61
  /**
62
62
  * 设置授权方的选项信息
63
63
  * @param appId 授权方app_id
64
64
  * @param name 选项名称
65
65
  */
66
- getAuthorizerOption(): Promise<any>;
66
+ getAuthorizerOption(...arg: any[]): Promise<any>;
67
67
  /**
68
68
  * 设置授权方的选项信息
69
69
  * @param appId 授权方app_id
70
70
  * @param name 选项名称
71
71
  * @param value 选项值
72
72
  */
73
- setAuthorizerOption(): Promise<any>;
73
+ setAuthorizerOption(...arg: any[]): Promise<any>;
74
74
  /**
75
75
  * 获取已授权的授权方列表
76
76
  * @param offset 起始位置,从0开始
77
77
  * @param count 获取记录数,最大500
78
78
  */
79
- getAuthorizers(): Promise<any>;
79
+ getAuthorizers(...arg: any[]): Promise<any>;
80
80
  /**
81
81
  * 获取预授权码
82
82
  */
83
- createPreAuthorizationCode(): Promise<any>;
83
+ createPreAuthorizationCode(...arg: any[]): Promise<any>;
84
84
  /**
85
85
  * 清零调用次数
86
86
  */
87
- clearQuota(): Promise<any>;
87
+ clearQuota(...arg: any[]): Promise<any>;
88
88
  }
@@ -171,23 +171,23 @@ class OpenPlatform extends BaseApplication_1.default {
171
171
  * 使用授权码换取接口调用凭据和授权信息
172
172
  * @param authCode 授权码, 会在授权成功的回调返回给第三方平台
173
173
  */
174
- handleAuthorize() {
175
- return this.base.handleAuthorize.apply(this.base, arguments);
174
+ handleAuthorize(...arg) {
175
+ return this.base.handleAuthorize.apply(this.base, arg);
176
176
  }
177
177
  /**
178
178
  * 获取授权方的帐号基本信息
179
179
  * @param appId 授权方app_id
180
180
  */
181
- getAuthorizer() {
182
- return this.base.getAuthorizer.apply(this.base, arguments);
181
+ getAuthorizer(...arg) {
182
+ return this.base.getAuthorizer.apply(this.base, arg);
183
183
  }
184
184
  /**
185
185
  * 设置授权方的选项信息
186
186
  * @param appId 授权方app_id
187
187
  * @param name 选项名称
188
188
  */
189
- getAuthorizerOption() {
190
- return this.base.getAuthorizerOption.apply(this.base, arguments);
189
+ getAuthorizerOption(...arg) {
190
+ return this.base.getAuthorizerOption.apply(this.base, arg);
191
191
  }
192
192
  /**
193
193
  * 设置授权方的选项信息
@@ -195,28 +195,28 @@ class OpenPlatform extends BaseApplication_1.default {
195
195
  * @param name 选项名称
196
196
  * @param value 选项值
197
197
  */
198
- setAuthorizerOption() {
199
- return this.base.setAuthorizerOption.apply(this.base, arguments);
198
+ setAuthorizerOption(...arg) {
199
+ return this.base.setAuthorizerOption.apply(this.base, arg);
200
200
  }
201
201
  /**
202
202
  * 获取已授权的授权方列表
203
203
  * @param offset 起始位置,从0开始
204
204
  * @param count 获取记录数,最大500
205
205
  */
206
- getAuthorizers() {
207
- return this.base.getAuthorizers.apply(this.base, arguments);
206
+ getAuthorizers(...arg) {
207
+ return this.base.getAuthorizers.apply(this.base, arg);
208
208
  }
209
209
  /**
210
210
  * 获取预授权码
211
211
  */
212
- createPreAuthorizationCode() {
213
- return this.base.createPreAuthorizationCode.apply(this.base, arguments);
212
+ createPreAuthorizationCode(...arg) {
213
+ return this.base.createPreAuthorizationCode.apply(this.base, arg);
214
214
  }
215
215
  /**
216
216
  * 清零调用次数
217
217
  */
218
- clearQuota() {
219
- return this.base.clearQuota.apply(this.base, arguments);
218
+ clearQuota(...arg) {
219
+ return this.base.clearQuota.apply(this.base, arg);
220
220
  }
221
221
  }
222
222
  exports.default = OpenPlatform;
@@ -17,10 +17,9 @@ class MiniProgram extends Application_1.default {
17
17
  this.account = null;
18
18
  this.setting = null;
19
19
  this.tester = null;
20
- this.registerProviders();
21
20
  }
22
21
  registerProviders() {
23
- this.registerCommonProviders();
22
+ super.registerProviders();
24
23
  this.offsetSet('code', function (app) {
25
24
  return new CodeClient_1.default(app);
26
25
  });
@@ -9,10 +9,9 @@ class OfficialAccount extends Application_1.default {
9
9
  constructor(config = {}, prepends = {}, id = null) {
10
10
  super(config, prepends, id);
11
11
  this.mini_program = null;
12
- this.registerProviders();
13
12
  }
14
13
  registerProviders() {
15
- this.registerCommonProviders();
14
+ super.registerProviders();
16
15
  this.offsetSet('mini_program', function (app) {
17
16
  return new MiniProgramClient_1.default(app);
18
17
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-easywechat",
3
- "version": "2.9.5",
3
+ "version": "2.9.6",
4
4
  "description": "EasyWechat SDK for Node.js (NOT OFFICIAL)",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {