node-easywechat 3.3.6 → 3.5.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.
- package/CHANGELOG.md +8 -0
- package/README.md +20 -2
- package/dist/Core/Config.d.ts +2 -2
- package/dist/Core/Contracts/ConfigInterface.d.ts +1 -1
- package/dist/Core/Support/Utils.d.ts +1 -1
- package/dist/MiniApp/Application.js +1 -1
- package/dist/MiniApp/Decryptor.d.ts +1 -1
- package/dist/MiniApp/Utils.d.ts +1 -1
- package/dist/OfficialAccount/AccessToken.d.ts +11 -1
- package/dist/OfficialAccount/AccessToken.js +31 -1
- package/dist/OfficialAccount/Application.js +1 -1
- package/dist/OpenPlatform/Application.d.ts +2 -2
- package/dist/Types/global.d.ts +44 -44
- package/dist/Types/shim-axios.d.ts +31 -0
- package/dist/index.d.ts +95 -1
- package/dist/index.js +145 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -67,6 +67,20 @@ let app = new OpenWork({
|
|
|
67
67
|
// 配置项
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
+
// ----- 定义配置项(v3.5.0+) -----
|
|
71
|
+
|
|
72
|
+
// 这种方式设置配置项时可获得编辑器的代码提示(如:VS Code)
|
|
73
|
+
|
|
74
|
+
// 公众号配置
|
|
75
|
+
const config = defineOfficialAccountConfig({
|
|
76
|
+
// 配置项
|
|
77
|
+
});
|
|
78
|
+
// 小程序: defineMiniAppConfig()
|
|
79
|
+
// 支付: definePayConfig()
|
|
80
|
+
// 开放平台: defineOpenPlatformConfig()
|
|
81
|
+
// 企业微信: defineWorkConfig()
|
|
82
|
+
// 企业微信开放平台: defineOpenWorkConfig()
|
|
83
|
+
|
|
70
84
|
// ----- 以下为通用的 api 调用方法 -----
|
|
71
85
|
|
|
72
86
|
// 获取 api 调用客户端
|
|
@@ -127,7 +141,9 @@ let data = response.toObject();
|
|
|
127
141
|
scope: 'snsapi_userinfo',
|
|
128
142
|
// 网页授权回调地址,完整的URL
|
|
129
143
|
redirect: 'http://node-easywechat.hpyer.cn/wxlogin/callback'
|
|
130
|
-
}
|
|
144
|
+
},
|
|
145
|
+
// 是否使用稳定版接口调用凭据,默认:false
|
|
146
|
+
use_stable_access_token: false
|
|
131
147
|
}
|
|
132
148
|
```
|
|
133
149
|
|
|
@@ -141,7 +157,9 @@ let data = response.toObject();
|
|
|
141
157
|
// 小程序的 token
|
|
142
158
|
token: '',
|
|
143
159
|
// EncodingAESKey
|
|
144
|
-
aes_key: ''
|
|
160
|
+
aes_key: '',
|
|
161
|
+
// 是否使用稳定版接口调用凭据,默认:false
|
|
162
|
+
use_stable_access_token: false
|
|
145
163
|
}
|
|
146
164
|
```
|
|
147
165
|
|
package/dist/Core/Config.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ declare class Config extends ConfigInterface {
|
|
|
13
13
|
* 获取所有配置项
|
|
14
14
|
* @returns
|
|
15
15
|
*/
|
|
16
|
-
all():
|
|
16
|
+
all(): Record<string, any>;
|
|
17
17
|
/**
|
|
18
18
|
* 判断配置项是否存在
|
|
19
19
|
* @param key
|
|
@@ -38,7 +38,7 @@ declare class Config extends ConfigInterface {
|
|
|
38
38
|
* @param keys 键名列表 或者 {键名:默认值} 格式的对象
|
|
39
39
|
* @returns
|
|
40
40
|
*/
|
|
41
|
-
getMany(keys: string[] | Record<string, any>):
|
|
41
|
+
getMany(keys: string[] | Record<string, any>): Record<string, any>;
|
|
42
42
|
/**
|
|
43
43
|
* 判断配置项是否存在
|
|
44
44
|
* @param key
|
|
@@ -11,7 +11,7 @@ export declare const getTimestamp: (datetime?: string) => number;
|
|
|
11
11
|
export declare const buildQueryString: (data: Record<string, any>, options?: Record<string, any>) => string;
|
|
12
12
|
export declare const parseQueryString: (data: string, options?: Record<string, any>) => Record<string, any>;
|
|
13
13
|
export declare const randomString: (len?: number) => string;
|
|
14
|
-
export declare const makeSignature: (params:
|
|
14
|
+
export declare const makeSignature: (params: Record<string, any>, key?: string, type?: string) => string;
|
|
15
15
|
export declare const isString: (data: any) => boolean;
|
|
16
16
|
export declare const isArray: (data: any) => boolean;
|
|
17
17
|
export declare const isNumber: (data: any) => boolean;
|
|
@@ -90,7 +90,7 @@ class Application {
|
|
|
90
90
|
}
|
|
91
91
|
getAccessToken() {
|
|
92
92
|
if (!this.accessToken) {
|
|
93
|
-
this.accessToken = new AccessToken_1.default(this.getAccount().getAppId(), this.getAccount().getSecret(), null, this.getCache(), this.getHttpClient());
|
|
93
|
+
this.accessToken = new AccessToken_1.default(this.getAccount().getAppId(), this.getAccount().getSecret(), null, this.getCache(), this.getHttpClient(), this.config.get('use_stable_access_token', false));
|
|
94
94
|
}
|
|
95
95
|
return this.accessToken;
|
|
96
96
|
}
|
package/dist/MiniApp/Utils.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ declare class AccessToken implements RefreshableAccessTokenInterface {
|
|
|
7
7
|
protected key: string;
|
|
8
8
|
protected cache: CacheInterface;
|
|
9
9
|
protected httpClient: HttpClientInterface;
|
|
10
|
-
|
|
10
|
+
protected stable: boolean;
|
|
11
|
+
constructor(appId: string, secret: string, key?: string, cache?: CacheInterface, httpClient?: HttpClientInterface, stable?: boolean);
|
|
11
12
|
/**
|
|
12
13
|
* 获取access_token的缓存名称
|
|
13
14
|
* @returns
|
|
@@ -22,5 +23,14 @@ declare class AccessToken implements RefreshableAccessTokenInterface {
|
|
|
22
23
|
getToken(): Promise<string>;
|
|
23
24
|
toQuery(): Promise<Record<string, any>>;
|
|
24
25
|
refresh(): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* 获取稳定版接口调用凭据
|
|
28
|
+
* @param forceRefresh 是否强制刷新,默认:false
|
|
29
|
+
*/
|
|
30
|
+
getStableAccessToken(forceRefresh?: boolean): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* 获取接口调用凭据
|
|
33
|
+
*/
|
|
34
|
+
getAccessToken(): Promise<string>;
|
|
25
35
|
}
|
|
26
36
|
export = AccessToken;
|
|
@@ -13,12 +13,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
const HttpClient_1 = __importDefault(require("../Core/HttpClient/HttpClient"));
|
|
15
15
|
class AccessToken {
|
|
16
|
-
constructor(appId, secret, key = null, cache = null, httpClient = null) {
|
|
16
|
+
constructor(appId, secret, key = null, cache = null, httpClient = null, stable = false) {
|
|
17
17
|
this.appId = appId;
|
|
18
18
|
this.secret = secret;
|
|
19
19
|
this.key = key;
|
|
20
20
|
this.cache = cache;
|
|
21
21
|
this.httpClient = httpClient;
|
|
22
|
+
this.stable = stable;
|
|
22
23
|
if (!this.httpClient) {
|
|
23
24
|
this.httpClient = HttpClient_1.default.create({
|
|
24
25
|
baseURL: 'https://api.weixin.qq.com/',
|
|
@@ -64,6 +65,35 @@ class AccessToken {
|
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
67
|
refresh() {
|
|
68
|
+
return this.stable ? this.getStableAccessToken() : this.getAccessToken();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 获取稳定版接口调用凭据
|
|
72
|
+
* @param forceRefresh 是否强制刷新,默认:false
|
|
73
|
+
*/
|
|
74
|
+
getStableAccessToken(forceRefresh = false) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
let response = (yield this.httpClient.request('post', 'cgi-bin/stable_token', {
|
|
77
|
+
json: {
|
|
78
|
+
grant_type: 'client_credential',
|
|
79
|
+
appid: this.appId,
|
|
80
|
+
secret: this.secret,
|
|
81
|
+
force_refresh: forceRefresh,
|
|
82
|
+
}
|
|
83
|
+
})).toObject();
|
|
84
|
+
if (!response['access_token']) {
|
|
85
|
+
throw new Error('Failed to get stable access_token: ' + JSON.stringify(response));
|
|
86
|
+
}
|
|
87
|
+
if (this.cache) {
|
|
88
|
+
yield this.cache.set(this.getKey(), response['access_token'], parseInt(response['expires_in']));
|
|
89
|
+
}
|
|
90
|
+
return response['access_token'];
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 获取接口调用凭据
|
|
95
|
+
*/
|
|
96
|
+
getAccessToken() {
|
|
67
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
98
|
let response = (yield this.httpClient.request('get', 'cgi-bin/token', {
|
|
69
99
|
params: {
|
|
@@ -90,7 +90,7 @@ class Application {
|
|
|
90
90
|
}
|
|
91
91
|
getAccessToken() {
|
|
92
92
|
if (!this.accessToken) {
|
|
93
|
-
this.accessToken = new AccessToken_1.default(this.getAccount().getAppId(), this.getAccount().getSecret(), null, this.getCache(), this.getHttpClient());
|
|
93
|
+
this.accessToken = new AccessToken_1.default(this.getAccount().getAppId(), this.getAccount().getSecret(), null, this.getCache(), this.getHttpClient(), this.config.get('use_stable_access_token', false));
|
|
94
94
|
}
|
|
95
95
|
return this.accessToken;
|
|
96
96
|
}
|
|
@@ -9,7 +9,7 @@ import HttpClientMixin from '../Core/Mixins/HttpClientMixin';
|
|
|
9
9
|
import ServerRequestMixin from '../Core/Mixins/ServerRequestMixin';
|
|
10
10
|
import OfficialAccountApplication from '../OfficialAccount/Application';
|
|
11
11
|
import MiniAppApplication from '../MiniApp/Application';
|
|
12
|
-
import { OfficialAccountConfig, OfficialAccountOAuthFactory, MiniAppConfig } from '../Types/global';
|
|
12
|
+
import { OpenPlatformConfig, OfficialAccountConfig, OfficialAccountOAuthFactory, MiniAppConfig } from '../Types/global';
|
|
13
13
|
import AccountInterface from './Contracts/AccountInterface';
|
|
14
14
|
import ApplicationInterface from './Contracts/ApplicationInterface';
|
|
15
15
|
import Server from './Server';
|
|
@@ -21,7 +21,7 @@ import AuthorizerAccessToken from './AuthorizerAccessToken';
|
|
|
21
21
|
* 开放平台应用
|
|
22
22
|
*/
|
|
23
23
|
declare class Application implements ApplicationInterface {
|
|
24
|
-
constructor(config: ConfigInterface |
|
|
24
|
+
constructor(config: ConfigInterface | OpenPlatformConfig);
|
|
25
25
|
protected account: AccountInterface;
|
|
26
26
|
protected encryptor: Encryptor;
|
|
27
27
|
protected server: Server;
|
package/dist/Types/global.d.ts
CHANGED
|
@@ -3,30 +3,18 @@ import ProviderInterface from 'node-socialite/dist/Core/ProviderInterface';
|
|
|
3
3
|
import OfficialAccountApplicationInterface from '../OfficialAccount/Contracts/ApplicationInterface';
|
|
4
4
|
import WorkApplicationInterface from '../Work/Contracts/ApplicationInterface';
|
|
5
5
|
import Message from '../Core/Message';
|
|
6
|
+
import OfficialAccountMessage from '../OfficialAccount/Message';
|
|
7
|
+
import PayMessage from '../Pay/Message';
|
|
8
|
+
import WorkMessage from '../Work/Message';
|
|
9
|
+
import OpenPlatformMessage from '../OpenPlatform/Message';
|
|
10
|
+
import OpenWorkMessage from '../OpenWork/Message';
|
|
6
11
|
import HttpClientResponseInterface from '../Core/HttpClient/Contracts/HttpClientResponseInterface';
|
|
7
12
|
import { PublicKey } from "../Core/Support/PublicKey";
|
|
8
13
|
|
|
9
|
-
declare module 'axios' {
|
|
10
|
-
export interface AxiosRequestConfig {
|
|
11
|
-
/**
|
|
12
|
-
* 要发送的xml数据,会自动解析并赋值到data属性,同时设置content-type=text/xml
|
|
13
|
-
*/
|
|
14
|
-
xml?: string | Record<string, any>;
|
|
15
|
-
/**
|
|
16
|
-
* 要发送的json数据,会自动解析并赋值到data属性,同时设置content-type=application/json
|
|
17
|
-
*/
|
|
18
|
-
json?: string | Record<string, any>;
|
|
19
|
-
/**
|
|
20
|
-
* 要发送的FormData数据,会自动解析并赋值到data属性,同时设置根据内容提取headers
|
|
21
|
-
*/
|
|
22
|
-
formData?: Record<string, any>;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
14
|
/**
|
|
27
15
|
* 微信接口响应数据格式
|
|
28
16
|
*/
|
|
29
|
-
export
|
|
17
|
+
export interface WeixinResponse extends Record<string, any> {
|
|
30
18
|
/**
|
|
31
19
|
* 错误代码
|
|
32
20
|
*/
|
|
@@ -41,7 +29,7 @@ export declare interface WeixinResponse extends Record<string, any> {
|
|
|
41
29
|
/**
|
|
42
30
|
* 公众号网页授权相关配置
|
|
43
31
|
*/
|
|
44
|
-
export
|
|
32
|
+
export interface OauthConfig {
|
|
45
33
|
/**
|
|
46
34
|
* 网页授权权限,可选值:snsapi_userinfo、snsapi_base
|
|
47
35
|
*/
|
|
@@ -56,7 +44,7 @@ export declare interface OauthConfig {
|
|
|
56
44
|
/**
|
|
57
45
|
* 文件缓存相关配置
|
|
58
46
|
*/
|
|
59
|
-
export
|
|
47
|
+
export interface CacheFileConfig {
|
|
60
48
|
/**
|
|
61
49
|
* 缓存文件保存路径,默认:./
|
|
62
50
|
*/
|
|
@@ -78,7 +66,7 @@ export declare interface CacheFileConfig {
|
|
|
78
66
|
/**
|
|
79
67
|
* 网络请求配置
|
|
80
68
|
*/
|
|
81
|
-
export
|
|
69
|
+
export interface HttpConfig extends AxiosRequestConfig {
|
|
82
70
|
/**
|
|
83
71
|
* 是否抛出异常
|
|
84
72
|
*/
|
|
@@ -107,7 +95,7 @@ export declare interface HttpConfig extends AxiosRequestConfig {
|
|
|
107
95
|
/**
|
|
108
96
|
* 基础配置
|
|
109
97
|
*/
|
|
110
|
-
export
|
|
98
|
+
export interface BaseConfig {
|
|
111
99
|
/**
|
|
112
100
|
* 网络请求相关配置
|
|
113
101
|
*/
|
|
@@ -122,7 +110,7 @@ export declare interface BaseConfig {
|
|
|
122
110
|
/**
|
|
123
111
|
* 公众号配置
|
|
124
112
|
*/
|
|
125
|
-
export
|
|
113
|
+
export interface OfficialAccountConfig extends BaseConfig {
|
|
126
114
|
/**
|
|
127
115
|
* 公众号 app_id
|
|
128
116
|
*/
|
|
@@ -147,12 +135,18 @@ export declare interface OfficialAccountConfig extends BaseConfig {
|
|
|
147
135
|
* 网页授权相关配置
|
|
148
136
|
*/
|
|
149
137
|
oauth?: OauthConfig;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 是否使用稳定版接口调用凭据,默认:false
|
|
141
|
+
* @see https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/getStableAccessToken.html
|
|
142
|
+
*/
|
|
143
|
+
use_stable_access_token?: boolean;
|
|
150
144
|
}
|
|
151
145
|
|
|
152
146
|
/**
|
|
153
147
|
* 小程序配置
|
|
154
148
|
*/
|
|
155
|
-
export
|
|
149
|
+
export interface MiniAppConfig extends BaseConfig {
|
|
156
150
|
/**
|
|
157
151
|
* 小程序 app_id
|
|
158
152
|
*/
|
|
@@ -172,12 +166,18 @@ export declare interface MiniAppConfig extends BaseConfig {
|
|
|
172
166
|
* 服务端消息加解密密钥 aes_key
|
|
173
167
|
*/
|
|
174
168
|
aes_key?: string;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 是否使用稳定版接口调用凭据,默认:false
|
|
172
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/mp-access-token/getStableAccessToken.html
|
|
173
|
+
*/
|
|
174
|
+
use_stable_access_token?: boolean;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
/**
|
|
178
178
|
* 微信支付配置
|
|
179
179
|
*/
|
|
180
|
-
export
|
|
180
|
+
export interface PayConfig extends BaseConfig {
|
|
181
181
|
/**
|
|
182
182
|
* 商户号
|
|
183
183
|
*/
|
|
@@ -216,7 +216,7 @@ export declare interface PayConfig extends BaseConfig {
|
|
|
216
216
|
/**
|
|
217
217
|
* 开发平台配置
|
|
218
218
|
*/
|
|
219
|
-
export
|
|
219
|
+
export interface OpenPlatformConfig extends BaseConfig {
|
|
220
220
|
/**
|
|
221
221
|
* 开发平台 app_id
|
|
222
222
|
*/
|
|
@@ -241,7 +241,7 @@ export declare interface OpenPlatformConfig extends BaseConfig {
|
|
|
241
241
|
/**
|
|
242
242
|
* 企业微信配置
|
|
243
243
|
*/
|
|
244
|
-
export
|
|
244
|
+
export interface WorkConfig extends BaseConfig {
|
|
245
245
|
/**
|
|
246
246
|
* 企业微信 corp_id
|
|
247
247
|
*/
|
|
@@ -266,7 +266,7 @@ export declare interface WorkConfig extends BaseConfig {
|
|
|
266
266
|
/**
|
|
267
267
|
* 企业微信开放平台配置
|
|
268
268
|
*/
|
|
269
|
-
export
|
|
269
|
+
export interface OpenWorkConfig extends BaseConfig {
|
|
270
270
|
/**
|
|
271
271
|
* 企业微信 corp_id
|
|
272
272
|
*/
|
|
@@ -303,19 +303,19 @@ export declare interface OpenWorkConfig extends BaseConfig {
|
|
|
303
303
|
* @param app 公众号应用实例
|
|
304
304
|
* @returns OAuth服务供应商实例
|
|
305
305
|
*/
|
|
306
|
-
export
|
|
306
|
+
export type OfficialAccountOAuthFactory = (app: OfficialAccountApplicationInterface) => ProviderInterface;
|
|
307
307
|
|
|
308
308
|
/**
|
|
309
309
|
* 企业微信OAuth工厂方法
|
|
310
310
|
* @param app 企业微信应用实例
|
|
311
311
|
* @returns OAuth服务供应商实例
|
|
312
312
|
*/
|
|
313
|
-
export
|
|
313
|
+
export type WorkOAuthFactory = (app: WorkApplicationInterface) => ProviderInterface;
|
|
314
314
|
|
|
315
315
|
/**
|
|
316
316
|
* 服务端通知处理项
|
|
317
317
|
*/
|
|
318
|
-
export
|
|
318
|
+
export interface ServerHandlerItem {
|
|
319
319
|
hash: string;
|
|
320
320
|
handler: ServerHandlerClosure;
|
|
321
321
|
};
|
|
@@ -323,44 +323,44 @@ export declare interface ServerHandlerItem {
|
|
|
323
323
|
/**
|
|
324
324
|
* 服务端普通消息类型
|
|
325
325
|
*/
|
|
326
|
-
export
|
|
326
|
+
export type ServerMessageType = 'text' | 'image' | 'voice' | 'video' | 'shortvideo' | 'location';
|
|
327
327
|
|
|
328
328
|
/**
|
|
329
329
|
* 服务端事件消息类型
|
|
330
330
|
*/
|
|
331
|
-
export
|
|
331
|
+
export type ServerEventType = 'subscribe' | 'unsubscribe' | 'SCAN' | 'LOCATION' | 'CLICK' | 'VIEW';
|
|
332
332
|
|
|
333
333
|
/**
|
|
334
334
|
* 服务端消息处理器
|
|
335
335
|
* @param message 微信信息
|
|
336
336
|
* @param next 下一个消息处理器
|
|
337
337
|
*/
|
|
338
|
-
export
|
|
338
|
+
export type ServerHandlerClosure<T = Message> = (message: T extends OfficialAccountMessage | PayMessage | WorkMessage | OpenPlatformMessage | OpenWorkMessage ? T : Message, next?: ServerHandler<T>) => any;
|
|
339
339
|
|
|
340
340
|
/**
|
|
341
341
|
* HttpClient错误判定回调
|
|
342
342
|
* @param response 响应对象
|
|
343
343
|
*/
|
|
344
|
-
export
|
|
344
|
+
export type HttpClientFailureJudgeClosure = (response: HttpClientResponseInterface) => boolean;
|
|
345
345
|
|
|
346
346
|
/**
|
|
347
347
|
* Payment通知错误处理
|
|
348
348
|
* @param error 错误信息
|
|
349
349
|
*/
|
|
350
|
-
export
|
|
350
|
+
export type PaymentFailHandler = (error: string) => void;
|
|
351
351
|
|
|
352
352
|
/**
|
|
353
353
|
* Payment业务错误处理
|
|
354
354
|
* @param error 错误信息
|
|
355
355
|
*/
|
|
356
|
-
export
|
|
356
|
+
export type PaymentAlertHandler = (error: string) => void;
|
|
357
357
|
|
|
358
358
|
/**
|
|
359
359
|
* Payment支付结果处理回调函数
|
|
360
360
|
* @param message 微信通知信息
|
|
361
361
|
* @param fail 通知错误处理函数
|
|
362
362
|
*/
|
|
363
|
-
export
|
|
363
|
+
export type PaymentPaidHandler = (message: PayMessage, fail: PaymentFailHandler) => void;
|
|
364
364
|
|
|
365
365
|
/**
|
|
366
366
|
* Payment退款结果处理回调函数
|
|
@@ -368,7 +368,7 @@ export declare type PaymentPaidHandler = (message: Message, fail: PaymentFailHan
|
|
|
368
368
|
* @param reqInfo 微信通知信息中 req_info 解密后的信息
|
|
369
369
|
* @param fail 通知错误处理函数
|
|
370
370
|
*/
|
|
371
|
-
export
|
|
371
|
+
export type PaymentRefundedHandler = (message: PayMessage, reqInfo: Record<string, any>, fail: PaymentFailHandler) => void;
|
|
372
372
|
|
|
373
373
|
/**
|
|
374
374
|
* Payment扫码支付结果处理回调函数
|
|
@@ -376,7 +376,7 @@ export declare type PaymentRefundedHandler = (message: Message, reqInfo: object,
|
|
|
376
376
|
* @param fail 通知错误处理函数
|
|
377
377
|
* @param alert 业务错误处理函数
|
|
378
378
|
*/
|
|
379
|
-
export
|
|
379
|
+
export type PaymentScannedHandler = (message: PayMessage, fail: PaymentFailHandler, alert: PaymentAlertHandler) => void;
|
|
380
380
|
|
|
381
381
|
/**
|
|
382
382
|
* 日志处理方法
|
|
@@ -385,12 +385,12 @@ export declare type PaymentScannedHandler = (message: Message, fail: PaymentFail
|
|
|
385
385
|
* @param usedTime 请求耗时,单位ms,仅在 type 为 after 时返回
|
|
386
386
|
* @param response 响应对象,仅在 type 为 after 时返回
|
|
387
387
|
*/
|
|
388
|
-
export
|
|
388
|
+
export type LogHandler = (type: 'before' | 'after', options: AxiosRequestConfig, usedTime?: number, response?: AxiosResponse) => void | Promise<void>;
|
|
389
389
|
|
|
390
390
|
/**
|
|
391
391
|
* 支付参数 JsBridge
|
|
392
392
|
*/
|
|
393
|
-
export
|
|
393
|
+
export interface PayBridgeConfig {
|
|
394
394
|
/**
|
|
395
395
|
* 应用id
|
|
396
396
|
*/
|
|
@@ -420,7 +420,7 @@ export declare interface PayBridgeConfig {
|
|
|
420
420
|
/**
|
|
421
421
|
* 支付参数 JsSdk
|
|
422
422
|
*/
|
|
423
|
-
export
|
|
423
|
+
export interface PaySdkConfig {
|
|
424
424
|
/**
|
|
425
425
|
* 应用id
|
|
426
426
|
*/
|
|
@@ -450,7 +450,7 @@ export declare interface PaySdkConfig {
|
|
|
450
450
|
/**
|
|
451
451
|
* 支付参数 App
|
|
452
452
|
*/
|
|
453
|
-
export
|
|
453
|
+
export interface PayAppConfig {
|
|
454
454
|
/**
|
|
455
455
|
* 应用id
|
|
456
456
|
*/
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
|
|
4
|
+
declare module 'axios' {
|
|
5
|
+
|
|
6
|
+
interface AxiosInstance {
|
|
7
|
+
<T = Recordable, R = ApiResponse<T>>(config: AxiosRequestConfig): Promise<R>;
|
|
8
|
+
request<T = Recordable, R = ApiResponse<T>>(config: AxiosRequestConfig): Promise<R>;
|
|
9
|
+
get<T = Recordable, R = ApiResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
|
|
10
|
+
delete<T = Recordable, R = ApiResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
|
|
11
|
+
head<T = Recordable, R = ApiResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
|
|
12
|
+
post<T = Recordable, R = ApiResponse<T>>(url: string, data?: Recordable, config?: AxiosRequestConfig): Promise<R>;
|
|
13
|
+
put<T = Recordable, R = ApiResponse<T>>(url: string, data?: Recordable, config?: AxiosRequestConfig): Promise<R>;
|
|
14
|
+
patch<T = Recordable, R = ApiResponse<T>>(url: string, data?: Recordable, config?: AxiosRequestConfig): Promise<R>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface AxiosRequestConfig {
|
|
18
|
+
/**
|
|
19
|
+
* 要发送的xml数据,会自动解析并赋值到data属性,同时设置content-type=text/xml
|
|
20
|
+
*/
|
|
21
|
+
xml?: string | Recordable;
|
|
22
|
+
/**
|
|
23
|
+
* 要发送的json数据,会自动解析并赋值到data属性,同时设置content-type=application/json
|
|
24
|
+
*/
|
|
25
|
+
json?: string | Recordable;
|
|
26
|
+
/**
|
|
27
|
+
* 要发送的FormData数据,会自动解析并赋值到data属性,同时设置根据内容提取headers
|
|
28
|
+
*/
|
|
29
|
+
formData?: Recordable;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OfficialAccountConfig, MiniAppConfig, LogHandler, ServerEventType, ServerHandlerClosure, PayConfig, OpenPlatformConfig, WorkConfig, OpenWorkConfig } from './Types/global';
|
|
1
|
+
import { OfficialAccountConfig, MiniAppConfig, LogHandler, ServerEventType, ServerHandlerClosure, PayConfig, OpenPlatformConfig, WorkConfig, OpenWorkConfig, HttpClientFailureJudgeClosure, PaymentFailHandler, PaymentAlertHandler, PaymentPaidHandler, PaymentRefundedHandler, PaymentScannedHandler } from './Types/global';
|
|
2
2
|
import OfficialAccount from './OfficialAccount/Application';
|
|
3
3
|
import MiniApp from './MiniApp/Application';
|
|
4
4
|
import Pay from './Pay/Application';
|
|
@@ -8,6 +8,10 @@ import OpenWork from './OpenWork/Application';
|
|
|
8
8
|
import CacheInterface from './Core/Contracts/CacheInterface';
|
|
9
9
|
import ServerRequest from './Core/Http/ServerRequest';
|
|
10
10
|
import FormData from 'form-data';
|
|
11
|
+
import OfficialAccountMessage from './OfficialAccount/Message';
|
|
12
|
+
import WorkMessage from './Work/Message';
|
|
13
|
+
import OpenPlatformMessage from './OpenPlatform/Message';
|
|
14
|
+
import OpenWorkMessage from './OpenWork/Message';
|
|
11
15
|
export { OfficialAccount, OfficialAccountConfig, MiniApp, MiniAppConfig, Pay, PayConfig, OpenPlatform, OpenPlatformConfig, Work, WorkConfig, OpenWork, OpenWorkConfig, CacheInterface, ServerRequest, LogHandler, ServerEventType, ServerHandlerClosure,
|
|
12
16
|
/**
|
|
13
17
|
* 表单对象
|
|
@@ -15,3 +19,93 @@ export { OfficialAccount, OfficialAccountConfig, MiniApp, MiniAppConfig, Pay, Pa
|
|
|
15
19
|
* @see https://github.com/form-data/form-data#readme
|
|
16
20
|
*/
|
|
17
21
|
FormData, };
|
|
22
|
+
/**
|
|
23
|
+
* 定义公众号配置
|
|
24
|
+
* @param config
|
|
25
|
+
*/
|
|
26
|
+
export declare function defineOfficialAccountConfig(config: OfficialAccountConfig): OfficialAccountConfig;
|
|
27
|
+
/**
|
|
28
|
+
* 定义小程序配置
|
|
29
|
+
* @param config
|
|
30
|
+
*/
|
|
31
|
+
export declare function defineMiniAppConfig(config: MiniAppConfig): MiniAppConfig;
|
|
32
|
+
/**
|
|
33
|
+
* 定义支付配置
|
|
34
|
+
* @param config
|
|
35
|
+
*/
|
|
36
|
+
export declare function definePayConfig(config: PayConfig): PayConfig;
|
|
37
|
+
/**
|
|
38
|
+
* 定义开放平台配置
|
|
39
|
+
* @param config
|
|
40
|
+
*/
|
|
41
|
+
export declare function defineOpenPlatformConfig(config: OpenPlatformConfig): OpenPlatformConfig;
|
|
42
|
+
/**
|
|
43
|
+
* 定义企业微信配置
|
|
44
|
+
* @param config
|
|
45
|
+
*/
|
|
46
|
+
export declare function defineWorkConfig(config: WorkConfig): WorkConfig;
|
|
47
|
+
/**
|
|
48
|
+
* 定义企业微信开放平台配置
|
|
49
|
+
* @param config
|
|
50
|
+
*/
|
|
51
|
+
export declare function defineOpenWorkConfig(config: OpenWorkConfig): OpenWorkConfig;
|
|
52
|
+
/**
|
|
53
|
+
* 定义日志处理函数
|
|
54
|
+
* @param func
|
|
55
|
+
*/
|
|
56
|
+
export declare function defineLogHandler(func: LogHandler): LogHandler;
|
|
57
|
+
/**
|
|
58
|
+
* 定义公众号服务端消息处理函数
|
|
59
|
+
* @param func
|
|
60
|
+
*/
|
|
61
|
+
export declare function defineOfficeAccountServerHandler(func: ServerHandlerClosure<OfficialAccountMessage>): ServerHandlerClosure<OfficialAccountMessage>;
|
|
62
|
+
/**
|
|
63
|
+
* 定义小程序服务端消息处理函数
|
|
64
|
+
* @param func
|
|
65
|
+
*/
|
|
66
|
+
export declare function defineMiniAppServerHandler(func: ServerHandlerClosure<OfficialAccountMessage>): ServerHandlerClosure<OfficialAccountMessage>;
|
|
67
|
+
/**
|
|
68
|
+
* 定义企业微信服务端消息处理函数
|
|
69
|
+
* @param func
|
|
70
|
+
*/
|
|
71
|
+
export declare function defineWorkServerHandler(func: ServerHandlerClosure<WorkMessage>): ServerHandlerClosure<WorkMessage>;
|
|
72
|
+
/**
|
|
73
|
+
* 定义开放平台服务端消息处理函数
|
|
74
|
+
* @param func
|
|
75
|
+
*/
|
|
76
|
+
export declare function defineOpenPlatformServerHandler(func: ServerHandlerClosure<OpenPlatformMessage>): ServerHandlerClosure<OpenPlatformMessage>;
|
|
77
|
+
/**
|
|
78
|
+
* 定义企业微信开放平台服务端消息处理函数
|
|
79
|
+
* @param func
|
|
80
|
+
*/
|
|
81
|
+
export declare function defineOpenWorkServerHandler(func: ServerHandlerClosure<OpenWorkMessage>): ServerHandlerClosure<OpenWorkMessage>;
|
|
82
|
+
/**
|
|
83
|
+
* 定义HttpClient错误判定回调
|
|
84
|
+
* @param func
|
|
85
|
+
*/
|
|
86
|
+
export declare function defineHttpClientFailureJudgeClosure(func: HttpClientFailureJudgeClosure): HttpClientFailureJudgeClosure;
|
|
87
|
+
/**
|
|
88
|
+
* 定义支付通知错误处理函数
|
|
89
|
+
* @param func
|
|
90
|
+
*/
|
|
91
|
+
export declare function definePaymentFailHandler(func: PaymentFailHandler): PaymentFailHandler;
|
|
92
|
+
/**
|
|
93
|
+
* 定义支付业务错误处理函数
|
|
94
|
+
* @param func
|
|
95
|
+
*/
|
|
96
|
+
export declare function definePaymentAlertHandler(func: PaymentAlertHandler): PaymentAlertHandler;
|
|
97
|
+
/**
|
|
98
|
+
* 定义支付结果处理回调函数
|
|
99
|
+
* @param func
|
|
100
|
+
*/
|
|
101
|
+
export declare function definePaymentPaidHandler(func: PaymentPaidHandler): PaymentPaidHandler;
|
|
102
|
+
/**
|
|
103
|
+
* 定义退款结果处理回调函数
|
|
104
|
+
* @param func
|
|
105
|
+
*/
|
|
106
|
+
export declare function definePaymentRefundedHandler(func: PaymentRefundedHandler): PaymentRefundedHandler;
|
|
107
|
+
/**
|
|
108
|
+
* 定义扫码支付结果处理回调函数
|
|
109
|
+
* @param func
|
|
110
|
+
*/
|
|
111
|
+
export declare function definePaymentScannedHandler(func: PaymentScannedHandler): PaymentScannedHandler;
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.FormData = exports.ServerRequest = exports.CacheInterface = exports.OpenWork = exports.Work = exports.OpenPlatform = exports.Pay = exports.MiniApp = exports.OfficialAccount = void 0;
|
|
6
|
+
exports.definePaymentScannedHandler = exports.definePaymentRefundedHandler = exports.definePaymentPaidHandler = exports.definePaymentAlertHandler = exports.definePaymentFailHandler = exports.defineHttpClientFailureJudgeClosure = exports.defineOpenWorkServerHandler = exports.defineOpenPlatformServerHandler = exports.defineWorkServerHandler = exports.defineMiniAppServerHandler = exports.defineOfficeAccountServerHandler = exports.defineLogHandler = exports.defineOpenWorkConfig = exports.defineWorkConfig = exports.defineOpenPlatformConfig = exports.definePayConfig = exports.defineMiniAppConfig = exports.defineOfficialAccountConfig = exports.FormData = exports.ServerRequest = exports.CacheInterface = exports.OpenWork = exports.Work = exports.OpenPlatform = exports.Pay = exports.MiniApp = exports.OfficialAccount = void 0;
|
|
7
7
|
const Application_1 = __importDefault(require("./OfficialAccount/Application"));
|
|
8
8
|
exports.OfficialAccount = Application_1.default;
|
|
9
9
|
const Application_2 = __importDefault(require("./MiniApp/Application"));
|
|
@@ -22,3 +22,147 @@ const ServerRequest_1 = __importDefault(require("./Core/Http/ServerRequest"));
|
|
|
22
22
|
exports.ServerRequest = ServerRequest_1.default;
|
|
23
23
|
const form_data_1 = __importDefault(require("form-data"));
|
|
24
24
|
exports.FormData = form_data_1.default;
|
|
25
|
+
/**
|
|
26
|
+
* 定义公众号配置
|
|
27
|
+
* @param config
|
|
28
|
+
*/
|
|
29
|
+
function defineOfficialAccountConfig(config) {
|
|
30
|
+
return config;
|
|
31
|
+
}
|
|
32
|
+
exports.defineOfficialAccountConfig = defineOfficialAccountConfig;
|
|
33
|
+
/**
|
|
34
|
+
* 定义小程序配置
|
|
35
|
+
* @param config
|
|
36
|
+
*/
|
|
37
|
+
function defineMiniAppConfig(config) {
|
|
38
|
+
return config;
|
|
39
|
+
}
|
|
40
|
+
exports.defineMiniAppConfig = defineMiniAppConfig;
|
|
41
|
+
/**
|
|
42
|
+
* 定义支付配置
|
|
43
|
+
* @param config
|
|
44
|
+
*/
|
|
45
|
+
function definePayConfig(config) {
|
|
46
|
+
return config;
|
|
47
|
+
}
|
|
48
|
+
exports.definePayConfig = definePayConfig;
|
|
49
|
+
/**
|
|
50
|
+
* 定义开放平台配置
|
|
51
|
+
* @param config
|
|
52
|
+
*/
|
|
53
|
+
function defineOpenPlatformConfig(config) {
|
|
54
|
+
return config;
|
|
55
|
+
}
|
|
56
|
+
exports.defineOpenPlatformConfig = defineOpenPlatformConfig;
|
|
57
|
+
/**
|
|
58
|
+
* 定义企业微信配置
|
|
59
|
+
* @param config
|
|
60
|
+
*/
|
|
61
|
+
function defineWorkConfig(config) {
|
|
62
|
+
return config;
|
|
63
|
+
}
|
|
64
|
+
exports.defineWorkConfig = defineWorkConfig;
|
|
65
|
+
/**
|
|
66
|
+
* 定义企业微信开放平台配置
|
|
67
|
+
* @param config
|
|
68
|
+
*/
|
|
69
|
+
function defineOpenWorkConfig(config) {
|
|
70
|
+
return config;
|
|
71
|
+
}
|
|
72
|
+
exports.defineOpenWorkConfig = defineOpenWorkConfig;
|
|
73
|
+
/**
|
|
74
|
+
* 定义日志处理函数
|
|
75
|
+
* @param func
|
|
76
|
+
*/
|
|
77
|
+
function defineLogHandler(func) {
|
|
78
|
+
return func;
|
|
79
|
+
}
|
|
80
|
+
exports.defineLogHandler = defineLogHandler;
|
|
81
|
+
/**
|
|
82
|
+
* 定义公众号服务端消息处理函数
|
|
83
|
+
* @param func
|
|
84
|
+
*/
|
|
85
|
+
function defineOfficeAccountServerHandler(func) {
|
|
86
|
+
return func;
|
|
87
|
+
}
|
|
88
|
+
exports.defineOfficeAccountServerHandler = defineOfficeAccountServerHandler;
|
|
89
|
+
/**
|
|
90
|
+
* 定义小程序服务端消息处理函数
|
|
91
|
+
* @param func
|
|
92
|
+
*/
|
|
93
|
+
function defineMiniAppServerHandler(func) {
|
|
94
|
+
return func;
|
|
95
|
+
}
|
|
96
|
+
exports.defineMiniAppServerHandler = defineMiniAppServerHandler;
|
|
97
|
+
/**
|
|
98
|
+
* 定义企业微信服务端消息处理函数
|
|
99
|
+
* @param func
|
|
100
|
+
*/
|
|
101
|
+
function defineWorkServerHandler(func) {
|
|
102
|
+
return func;
|
|
103
|
+
}
|
|
104
|
+
exports.defineWorkServerHandler = defineWorkServerHandler;
|
|
105
|
+
/**
|
|
106
|
+
* 定义开放平台服务端消息处理函数
|
|
107
|
+
* @param func
|
|
108
|
+
*/
|
|
109
|
+
function defineOpenPlatformServerHandler(func) {
|
|
110
|
+
return func;
|
|
111
|
+
}
|
|
112
|
+
exports.defineOpenPlatformServerHandler = defineOpenPlatformServerHandler;
|
|
113
|
+
/**
|
|
114
|
+
* 定义企业微信开放平台服务端消息处理函数
|
|
115
|
+
* @param func
|
|
116
|
+
*/
|
|
117
|
+
function defineOpenWorkServerHandler(func) {
|
|
118
|
+
return func;
|
|
119
|
+
}
|
|
120
|
+
exports.defineOpenWorkServerHandler = defineOpenWorkServerHandler;
|
|
121
|
+
/**
|
|
122
|
+
* 定义HttpClient错误判定回调
|
|
123
|
+
* @param func
|
|
124
|
+
*/
|
|
125
|
+
function defineHttpClientFailureJudgeClosure(func) {
|
|
126
|
+
return func;
|
|
127
|
+
}
|
|
128
|
+
exports.defineHttpClientFailureJudgeClosure = defineHttpClientFailureJudgeClosure;
|
|
129
|
+
/**
|
|
130
|
+
* 定义支付通知错误处理函数
|
|
131
|
+
* @param func
|
|
132
|
+
*/
|
|
133
|
+
function definePaymentFailHandler(func) {
|
|
134
|
+
return func;
|
|
135
|
+
}
|
|
136
|
+
exports.definePaymentFailHandler = definePaymentFailHandler;
|
|
137
|
+
/**
|
|
138
|
+
* 定义支付业务错误处理函数
|
|
139
|
+
* @param func
|
|
140
|
+
*/
|
|
141
|
+
function definePaymentAlertHandler(func) {
|
|
142
|
+
return func;
|
|
143
|
+
}
|
|
144
|
+
exports.definePaymentAlertHandler = definePaymentAlertHandler;
|
|
145
|
+
/**
|
|
146
|
+
* 定义支付结果处理回调函数
|
|
147
|
+
* @param func
|
|
148
|
+
*/
|
|
149
|
+
function definePaymentPaidHandler(func) {
|
|
150
|
+
return func;
|
|
151
|
+
}
|
|
152
|
+
exports.definePaymentPaidHandler = definePaymentPaidHandler;
|
|
153
|
+
/**
|
|
154
|
+
* 定义退款结果处理回调函数
|
|
155
|
+
* @param func
|
|
156
|
+
*/
|
|
157
|
+
function definePaymentRefundedHandler(func) {
|
|
158
|
+
return func;
|
|
159
|
+
}
|
|
160
|
+
exports.definePaymentRefundedHandler = definePaymentRefundedHandler;
|
|
161
|
+
/**
|
|
162
|
+
* 定义扫码支付结果处理回调函数
|
|
163
|
+
* @param func
|
|
164
|
+
*/
|
|
165
|
+
function definePaymentScannedHandler(func) {
|
|
166
|
+
return func;
|
|
167
|
+
}
|
|
168
|
+
exports.definePaymentScannedHandler = definePaymentScannedHandler;
|