@yunzhanghu/sdk-nodejs 1.0.2 → 1.0.4
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/.editorconfig +8 -0
- package/.eslintrc.js +16 -0
- package/.prettierrc.js +3 -0
- package/README.md +23 -6
- package/example/apiUserSign.js +66 -12
- package/example/authentication.js +136 -25
- package/example/bizlicXjjH5.js +33 -7
- package/example/bizlicXjjH5Api.js +50 -10
- package/example/conf/config.js +2 -0
- package/example/dataService.js +105 -8
- package/example/h5UserSign.js +65 -10
- package/example/invoice.js +111 -14
- package/example/notify.js +0 -1
- package/example/payment.js +208 -26
- package/example/tax.js +31 -3
- package/example/uploadusersign.js +66 -0
- package/package.json +50 -45
- package/src/common/client.ts +364 -355
- package/src/common/exception/yzhSDKHttpException.ts +29 -26
- package/src/common/http/index.ts +62 -53
- package/src/common/utils/index.ts +16 -14
- package/src/index.ts +1 -1
- package/src/services/apiusersign/index.ts +107 -105
- package/src/services/authentication/index.ts +162 -196
- package/src/services/bizlicxjjh5/index.ts +77 -107
- package/src/services/bizlicxjjh5api/index.ts +108 -156
- package/src/services/dataservice/index.ts +246 -268
- package/src/services/h5usersign/index.ts +93 -105
- package/src/services/index.ts +11 -10
- package/src/services/invoice/index.ts +184 -244
- package/src/services/payment/index.ts +501 -435
- package/src/services/tax/index.ts +53 -51
- package/src/services/uploadusersign/index.ts +88 -0
- package/src/typings.d.ts +1 -1
- package/tdsformat.js +22 -0
- package/tsconfig.json +2 -1
- package/yzh/common/client.d.ts +3 -0
- package/yzh/common/client.js +9 -3
- package/yzh/common/http/index.d.ts +1 -0
- package/yzh/common/http/index.js +18 -8
- package/yzh/common/utils/index.d.ts +1 -0
- package/yzh/common/utils/index.js +1 -0
- package/yzh/services/apiusersign/index.d.ts +34 -7
- package/yzh/services/apiusersign/index.js +9 -8
- package/yzh/services/authentication/index.d.ts +57 -19
- package/yzh/services/authentication/index.js +12 -11
- package/yzh/services/bizlicxjjh5/index.d.ts +16 -4
- package/yzh/services/bizlicxjjh5/index.js +6 -5
- package/yzh/services/bizlicxjjh5api/index.d.ts +22 -5
- package/yzh/services/bizlicxjjh5api/index.js +7 -6
- package/yzh/services/dataservice/index.d.ts +52 -11
- package/yzh/services/dataservice/index.js +23 -10
- package/yzh/services/h5usersign/index.d.ts +28 -6
- package/yzh/services/h5usersign/index.js +8 -7
- package/yzh/services/index.d.ts +3 -2
- package/yzh/services/index.js +7 -5
- package/yzh/services/invoice/index.d.ts +51 -12
- package/yzh/services/invoice/index.js +11 -10
- package/yzh/services/payment/index.d.ts +194 -18
- package/yzh/services/payment/index.js +28 -13
- package/yzh/services/tax/index.d.ts +17 -4
- package/yzh/services/tax/index.js +6 -5
- package/yzh/services/uploadusersign/index.d.ts +78 -0
- package/yzh/services/uploadusersign/index.js +19 -0
- package/.eslintrc.json +0 -19
- package/prettier.config.js +0 -32
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
export default class YZHSDKHttpException extends Error {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// HTTP 状态码
|
|
5
|
-
httpCode?: number
|
|
6
|
-
// 接口返回状态码
|
|
7
|
-
code?: string
|
|
2
|
+
// 请求 ID
|
|
3
|
+
request_id: string;
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
this.request_id = request_id || ""
|
|
12
|
-
}
|
|
5
|
+
// HTTP 状态码
|
|
6
|
+
httpCode?: number;
|
|
13
7
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
8
|
+
// 接口返回状态码
|
|
9
|
+
code?: string;
|
|
17
10
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
constructor(error: string, request_id = '') {
|
|
12
|
+
super(error);
|
|
13
|
+
this.request_id = request_id || '';
|
|
14
|
+
}
|
|
21
15
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
16
|
+
getMessage(): string {
|
|
17
|
+
return this.message;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getRequestId(): string {
|
|
21
|
+
return this.request_id;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
toString(): string {
|
|
25
|
+
return `[yzh_sdk_exception] ${
|
|
26
|
+
this.code && `code:${this.code}`
|
|
27
|
+
} requestId:${this.getRequestId()} message:${this.getMessage()}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
toLocaleString(): string {
|
|
31
|
+
return `[yzh_sdk_exception] ${
|
|
32
|
+
this.code && `code:${this.code}`
|
|
33
|
+
} requestId:${this.getRequestId()} message:${this.getMessage()}`;
|
|
34
|
+
}
|
|
32
35
|
}
|
package/src/common/http/index.ts
CHANGED
|
@@ -1,57 +1,66 @@
|
|
|
1
|
-
import axios from
|
|
2
|
-
import * as urlencode from
|
|
3
|
-
|
|
4
|
-
import * as
|
|
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
|
-
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import * as urlencode from 'urlencode';
|
|
3
|
+
|
|
4
|
+
import * as pkg from '../../../package.json';
|
|
5
|
+
|
|
6
|
+
const JsonBigString = require('json-bigint')({ storeAsString: true });
|
|
7
|
+
|
|
8
|
+
const BASE_URL = 'https://api-service.yunzhanghu.com/';
|
|
9
|
+
|
|
10
|
+
const getInstance = (config: { request_id?: string; dealer_id?: string; base_url?: string; timeout?: number } = {}) => {
|
|
11
|
+
const instance = axios.create({
|
|
12
|
+
baseURL: config.base_url || BASE_URL,
|
|
13
|
+
headers: {
|
|
14
|
+
'request-id': config?.request_id,
|
|
15
|
+
'dealer-id': config?.dealer_id,
|
|
16
|
+
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
|
17
|
+
'User-Agent': `yunzhanghu-sdk-nodejs/${pkg.version}/${process.version}`,
|
|
18
|
+
},
|
|
19
|
+
timeout: config.timeout ?? 30 * 1000,
|
|
20
|
+
transformResponse: [
|
|
21
|
+
function toJson(data) {
|
|
22
|
+
try {
|
|
23
|
+
return JsonBigString.parse(data);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
// data 返回的内容不是合法的json字符串时会报错,此时直接返回原 data 数据
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// 拦截器
|
|
33
|
+
instance.interceptors.request.use(config => {
|
|
34
|
+
// URL Encode
|
|
35
|
+
if (config.method === 'get') {
|
|
36
|
+
const { params: urlData } = config;
|
|
37
|
+
const { data, sign, ...resData } = urlData;
|
|
38
|
+
// eslint-disable-next-line no-param-reassign
|
|
39
|
+
config.data = {
|
|
40
|
+
data: urlencode(data),
|
|
41
|
+
sign: urlencode(sign),
|
|
42
|
+
...resData,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return config;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
instance.interceptors.response.use(response => {
|
|
49
|
+
const { data } = response;
|
|
50
|
+
if (data) {
|
|
51
|
+
const { request_id, requestID, ...resResponse } = data;
|
|
52
|
+
if (request_id || requestID) {
|
|
53
|
+
response.data = {
|
|
54
|
+
...resResponse,
|
|
55
|
+
request_id: request_id || requestID,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
47
58
|
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
59
|
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
return response;
|
|
61
|
+
});
|
|
53
62
|
|
|
54
|
-
|
|
55
|
-
}
|
|
63
|
+
return instance;
|
|
64
|
+
};
|
|
56
65
|
|
|
57
|
-
export default getInstance
|
|
66
|
+
export default getInstance;
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import YZHclient from
|
|
1
|
+
import YZHclient from '../client';
|
|
2
2
|
|
|
3
3
|
export class Util extends YZHclient {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
// eslint-disable-next-line no-useless-constructor
|
|
5
|
+
constructor(conf: {
|
|
6
|
+
dealer_id: string;
|
|
7
|
+
broker_id: string;
|
|
8
|
+
app_key: string;
|
|
9
|
+
des3_key: string;
|
|
10
|
+
private_key: string;
|
|
11
|
+
yzh_public_key: string;
|
|
12
|
+
sign_type: 'rsa' | 'sha256';
|
|
13
|
+
base_url?: string;
|
|
14
|
+
timeout?: number;
|
|
15
|
+
}) {
|
|
16
|
+
super(conf);
|
|
17
|
+
}
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
export default Util
|
|
20
|
+
export default Util;
|
package/src/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './services';
|
|
@@ -1,148 +1,150 @@
|
|
|
1
|
-
import YZHclient from
|
|
1
|
+
import YZHclient from '../../common/client';
|
|
2
2
|
|
|
3
3
|
/** ApiUseSignContractRequest 获取协议预览 URL 请求 */
|
|
4
4
|
interface ApiUseSignContractRequest {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
/** 平台企业 ID */
|
|
6
|
+
dealer_id: string;
|
|
7
|
+
/** 综合服务主体 ID */
|
|
8
|
+
broker_id: string;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/** ApiUseSignContractResponse 获取协议预览 URL 返回 */
|
|
12
12
|
interface ApiUseSignContractResponse {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
/** 预览跳转 URL */
|
|
14
|
+
url: string;
|
|
15
|
+
/** 协议名称 */
|
|
16
|
+
title: string;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/** ApiUserSignContractRequest 获取协议预览 URL 请求 V2 */
|
|
20
20
|
interface ApiUserSignContractRequest {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
/** 平台企业 ID */
|
|
22
|
+
dealer_id: string;
|
|
23
|
+
/** 综合服务主体 ID */
|
|
24
|
+
broker_id: string;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/** ApiUserSignContractResponse 获取协议预览 URL 返回 V2 */
|
|
28
28
|
interface ApiUserSignContractResponse {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
/** 预览跳转 URL */
|
|
30
|
+
url: string;
|
|
31
|
+
/** 协议名称 */
|
|
32
|
+
title: string;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/** ApiUserSignRequest 用户签约请求 */
|
|
36
36
|
interface ApiUserSignRequest {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
/** 综合服务主体 ID */
|
|
38
|
+
broker_id: string;
|
|
39
|
+
/** 平台企业 ID */
|
|
40
|
+
dealer_id: string;
|
|
41
|
+
/** 姓名 */
|
|
42
|
+
real_name: string;
|
|
43
|
+
/** 证件号码 */
|
|
44
|
+
id_card: string;
|
|
45
|
+
/** 证件类型 idcard:身份证 passport:护照 mtphkm:港澳居民来往内地通行证 mtpt:台湾居民往来大陆通行证 rphkm:中华人民共和国港澳居民居住证 rpt:中华人民共和国台湾居民居住证 fpr:外国人永久居留身份证 ffwp:中华人民共和国外国人就业许可证书 */
|
|
46
|
+
card_type: string;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/** ApiUserSignResponse 用户签约返回 */
|
|
50
50
|
interface ApiUserSignResponse {
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
/** 是否签约成功 */
|
|
52
|
+
status: string;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/** GetApiUserSignStatusRequest 获取用户签约状态请求 */
|
|
56
56
|
interface GetApiUserSignStatusRequest {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
/** 平台企业 ID */
|
|
58
|
+
dealer_id: string;
|
|
59
|
+
/** 综合服务主体 ID */
|
|
60
|
+
broker_id: string;
|
|
61
|
+
/** 姓名 */
|
|
62
|
+
real_name: string;
|
|
63
|
+
/** 证件号码 */
|
|
64
|
+
id_card: string;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/** GetApiUserSignStatusResponse 获取用户签约状态返回 */
|
|
68
68
|
interface GetApiUserSignStatusResponse {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
/** 签约时间 */
|
|
70
|
+
signed_at: string;
|
|
71
|
+
/** 用户签约状态 */
|
|
72
|
+
status: string;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/** ApiUserSignReleaseRequest 用户解约(测试账号专用接口)请求 */
|
|
76
76
|
interface ApiUserSignReleaseRequest {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
/** 综合服务主体 ID */
|
|
78
|
+
broker_id: string;
|
|
79
|
+
/** 平台企业 ID */
|
|
80
|
+
dealer_id: string;
|
|
81
|
+
/** 姓名 */
|
|
82
|
+
real_name: string;
|
|
83
|
+
/** 证件号码 */
|
|
84
|
+
id_card: string;
|
|
85
|
+
/** 证件类型 idcard:身份证 passport:护照 mtphkm:港澳居民来往内地通行证 mtpt:台湾居民往来大陆通行证 rphkm:中华人民共和国港澳居民居住证 rpt:中华人民共和国台湾居民居住证 fpr:外国人永久居留身份证 ffwp:中华人民共和国外国人就业许可证书 */
|
|
86
|
+
card_type: string;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/** ApiUserSignReleaseResponse 用户解约(测试账号专用接口)返回 */
|
|
90
90
|
interface ApiUserSignReleaseResponse {
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
/** 是否解约成功 */
|
|
92
|
+
status: string;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
export class ApiUserSignServiceClient extends YZHclient {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
96
|
+
// eslint-disable-next-line no-useless-constructor
|
|
97
|
+
constructor(conf: {
|
|
98
|
+
dealer_id: string;
|
|
99
|
+
broker_id: string;
|
|
100
|
+
app_key: string;
|
|
101
|
+
des3_key: string;
|
|
102
|
+
private_key: string;
|
|
103
|
+
yzh_public_key: string;
|
|
104
|
+
sign_type: 'rsa' | 'sha256';
|
|
105
|
+
base_url?: string;
|
|
106
|
+
timeout?: number;
|
|
107
|
+
}) {
|
|
108
|
+
super(conf);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ApiUseSignContract 获取协议预览 URL
|
|
112
|
+
async ApiUseSignContract(
|
|
113
|
+
req: ApiUseSignContractRequest,
|
|
114
|
+
cb?: (error: null | string, rep: ApiUseSignContractResponse) => void
|
|
115
|
+
): Promise<ApiUseSignContractResponse> {
|
|
116
|
+
return this.request('get', '/api/sign/v1/user/contract', req, { encryption: false }, cb);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ApiUserSignContract 获取协议预览 URL V2
|
|
120
|
+
async ApiUserSignContract(
|
|
121
|
+
req: ApiUserSignContractRequest,
|
|
122
|
+
cb?: (error: null | string, rep: ApiUserSignContractResponse) => void
|
|
123
|
+
): Promise<ApiUserSignContractResponse> {
|
|
124
|
+
return this.request('get', '/api/sign/v1/user/contract', req, { encryption: false }, cb);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ApiUserSign 用户签约
|
|
128
|
+
async ApiUserSign(
|
|
129
|
+
req: ApiUserSignRequest,
|
|
130
|
+
cb?: (error: null | string, rep: ApiUserSignResponse) => void
|
|
131
|
+
): Promise<ApiUserSignResponse> {
|
|
132
|
+
return this.request('post', '/api/sign/v1/user/sign', req, { encryption: false }, cb);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// GetApiUserSignStatus 获取用户签约状态
|
|
136
|
+
async GetApiUserSignStatus(
|
|
137
|
+
req: GetApiUserSignStatusRequest,
|
|
138
|
+
cb?: (error: null | string, rep: GetApiUserSignStatusResponse) => void
|
|
139
|
+
): Promise<GetApiUserSignStatusResponse> {
|
|
140
|
+
return this.request('get', '/api/sign/v1/user/status', req, { encryption: false }, cb);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// ApiUserSignRelease 用户解约(测试账号专用接口)
|
|
144
|
+
async ApiUserSignRelease(
|
|
145
|
+
req: ApiUserSignReleaseRequest,
|
|
146
|
+
cb?: (error: null | string, rep: ApiUserSignReleaseResponse) => void
|
|
147
|
+
): Promise<ApiUserSignReleaseResponse> {
|
|
148
|
+
return this.request('post', '/api/sign/v1/user/release', req, { encryption: false }, cb);
|
|
149
|
+
}
|
|
148
150
|
}
|