/
Base.ts
102 lines (95 loc) · 2.02 KB
/
Base.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* 基础返回数据
*/
export interface BaseReturn {
/**
* 返回状态码
* @description SUCCESS/FAIL 此字段是通信标识,非交易标识,交易是否成功需要查看trade_state来判断
* @example SUCCESS
* @typedef String(16)
*/
return_code: string;
/**
* 返回信息
* @description 当return_code为FAIL时返回信息为错误原因 ,例如 签名失败 参数格式校验错误
* @example OK
* @typedef String(128)
*/
return_msg?: string;
}
export interface SuccessReturn extends BaseReturn {
/**
* 业务结果
* @description success/fail
* @example success
* @typedef string(16)
*/
result_code: "SUCCESS";
}
/**
* 业务逻辑成功返回数据
*/
export type SuccessT<T> = T & SuccessReturn;
export interface FailReturn extends BaseReturn {
/**
* 业务结果
* @description success/fail
* @example success
* @typedef string(16)
*/
result_code: "FAIL";
/**
* 错误代码
* @description 详细参见错误列表
* @example systemerror
* @typedef string(32)
*/
err_code?: string;
/**
* 错误代码描述
* @description 错误返回的信息描述
* @example 系统错误
* @typedef string(128)
*/
err_code_des?: string;
}
/**
* 业务逻辑失败返回数据
*/
export type FailT<T> = T & FailReturn;
/**
* 支付类构造函数选项
*/
export interface ConstructorOptions {
appId: string;
mchId: string;
key: string;
pfx: Buffer;
}
export const enum SignType {
MD5 = "MD5",
"HMAC-SHA256" = "HMAC-SHA256"
}
/**
* 额外请求参数,支付实例自带或自动生成,不需要随 options 传递
*/
export interface FetchOptions {
appid: string;
mch_id: string;
key: string;
nonce_str: string;
url: string;
pfx?: Buffer;
/**
* appid 键名映射, 比如有些接口使用 app_id, wxappid
*/
mapAppId?: string;
/**
* mch_id 键名映射
*/
mapMchId?: string;
/**
* 固定值,将会直接合并到请求体中
*/
consts?: { [k: string]: any };
}