@yunzhanghu/sdk-nodejs 1.0.1 → 1.0.3
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 +22 -7
- package/example/apiUserSign.js +54 -12
- package/example/authentication.js +112 -25
- package/example/bizlicXjjH5.js +27 -7
- package/example/bizlicXjjH5Api.js +41 -10
- package/example/conf/config.js +4 -2
- package/example/dataService.js +84 -8
- package/example/h5UserSign.js +53 -10
- package/example/invoice.js +90 -14
- package/example/notify.js +0 -1
- package/example/payment.js +148 -26
- package/example/tax.js +25 -3
- package/example/uploadusersign.js +60 -0
- package/package.json +50 -45
- package/src/common/client.ts +26 -7
- package/src/common/exception/yzhSDKHttpException.ts +3 -0
- package/src/common/http/index.ts +20 -9
- package/src/common/utils/index.ts +2 -0
- package/src/services/apiusersign/index.ts +2 -0
- package/src/services/authentication/index.ts +2 -18
- package/src/services/bizlicxjjh5/index.ts +2 -32
- package/src/services/bizlicxjjh5api/index.ts +2 -32
- package/src/services/dataservice/index.ts +4 -2
- package/src/services/h5usersign/index.ts +2 -14
- package/src/services/index.ts +3 -2
- package/src/services/invoice/index.ts +2 -38
- package/src/services/payment/index.ts +27 -67
- package/src/services/tax/index.ts +2 -0
- package/src/services/uploadusersign/index.ts +88 -0
- package/tdsformat.js +22 -0
- package/tsconfig.json +2 -1
- package/yzh/common/client.d.ts +7 -4
- package/yzh/common/client.js +12 -6
- 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 +88 -14
- package/yzh/services/payment/index.js +24 -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
package/example/payment.js
CHANGED
|
@@ -1,115 +1,186 @@
|
|
|
1
1
|
const yzhAPI = require("../yzh/index.js")
|
|
2
2
|
const config = require("./conf/config.js")
|
|
3
|
+
|
|
3
4
|
// 实时支付
|
|
4
5
|
const payment = new yzhAPI.PaymentClient(config)
|
|
5
6
|
|
|
6
7
|
// 银行卡实时支付
|
|
7
8
|
payment
|
|
8
9
|
.CreateBankpayOrder({
|
|
10
|
+
// request-id:请求 ID,请求的唯一标识
|
|
11
|
+
// 建议平台企业自定义 request-id,并记录在日志中,便于问题发现及排查
|
|
12
|
+
// 如平台企业未自定义 request-id,将使用 SDK 中的 random 方法自动生成。注意:random 方法生成的 request-id 不能保证全局唯一,推荐自定义
|
|
13
|
+
request_id: "requestIdExample123456789",
|
|
9
14
|
order_id: "nodetest123",
|
|
10
15
|
dealer_id: config.dealer_id,
|
|
11
16
|
broker_id: config.broker_id,
|
|
12
17
|
real_name: "张三",
|
|
13
|
-
card_no: "
|
|
14
|
-
id_card: "
|
|
18
|
+
card_no: "8888888888888888888",
|
|
19
|
+
id_card: "110121202202222222",
|
|
15
20
|
pay: "0.01",
|
|
16
21
|
pay_remark: "test",
|
|
17
|
-
notify_url: "https://
|
|
22
|
+
notify_url: "https://www.example.com",
|
|
18
23
|
project_id: "",
|
|
19
24
|
})
|
|
20
25
|
.then((data) => {
|
|
21
|
-
|
|
26
|
+
if (data.code === "0000") {
|
|
27
|
+
// 操作成功
|
|
28
|
+
console.log("操作成功 ", data.data)
|
|
29
|
+
} else {
|
|
30
|
+
// 失败返回
|
|
31
|
+
console.log("失败返回 ", "code:" + data.code + " message:" + data.message + " request_id:" + data.request_id)
|
|
32
|
+
}
|
|
22
33
|
})
|
|
23
34
|
.catch((err) => {
|
|
35
|
+
// 发生异常
|
|
24
36
|
console.log(err.toString())
|
|
25
37
|
})
|
|
26
38
|
|
|
27
39
|
// 支付宝实时支付
|
|
28
40
|
payment
|
|
29
41
|
.CreateAlipayOrder({
|
|
42
|
+
// request-id:请求 ID,请求的唯一标识
|
|
43
|
+
// 建议平台企业自定义 request-id,并记录在日志中,便于问题发现及排查
|
|
44
|
+
// 如平台企业未自定义 request-id,将使用 SDK 中的 random 方法自动生成。注意:random 方法生成的 request-id 不能保证全局唯一,推荐自定义
|
|
45
|
+
request_id: "requestIdExample123456789",
|
|
30
46
|
order_id: "nodetest123",
|
|
31
47
|
dealer_id: config.dealer_id,
|
|
32
48
|
broker_id: config.broker_id,
|
|
33
49
|
real_name: "张三",
|
|
34
|
-
card_no: "
|
|
35
|
-
id_card: "
|
|
50
|
+
card_no: "username@example.com",
|
|
51
|
+
id_card: "110121202202222222",
|
|
36
52
|
pay: "0.01",
|
|
37
53
|
check_name: "Check",
|
|
38
54
|
pay_remark: "test",
|
|
39
|
-
notify_url: "https://
|
|
55
|
+
notify_url: "https://www.example.com",
|
|
40
56
|
project_id: "",
|
|
41
57
|
})
|
|
42
58
|
.then((data) => {
|
|
43
|
-
|
|
59
|
+
if (data.code === "0000") {
|
|
60
|
+
// 操作成功
|
|
61
|
+
console.log("操作成功 ", data.data)
|
|
62
|
+
} else {
|
|
63
|
+
// 失败返回
|
|
64
|
+
console.log("失败返回 ", "code:" + data.code + " message:" + data.message + " request_id:" + data.request_id)
|
|
65
|
+
}
|
|
44
66
|
})
|
|
45
67
|
.catch((err) => {
|
|
68
|
+
// 发生异常
|
|
46
69
|
console.log(err.toString())
|
|
47
70
|
})
|
|
48
71
|
|
|
49
72
|
// 微信实时支付
|
|
50
73
|
payment
|
|
51
74
|
.CreateWxpayOrder({
|
|
75
|
+
// request-id:请求 ID,请求的唯一标识
|
|
76
|
+
// 建议平台企业自定义 request-id,并记录在日志中,便于问题发现及排查
|
|
77
|
+
// 如平台企业未自定义 request-id,将使用 SDK 中的 random 方法自动生成。注意:random 方法生成的 request-id 不能保证全局唯一,推荐自定义
|
|
78
|
+
request_id: "requestIdExample123456789",
|
|
52
79
|
order_id: "nodetest1234",
|
|
53
80
|
dealer_id: config.dealer_id,
|
|
54
81
|
broker_id: config.broker_id,
|
|
55
82
|
real_name: "张三",
|
|
56
|
-
openid: "
|
|
57
|
-
id_card: "
|
|
83
|
+
openid: "wx11111111111",
|
|
84
|
+
id_card: "110121202202222222",
|
|
58
85
|
pay: "0.3",
|
|
59
86
|
wx_app_id: "",
|
|
60
87
|
pay_remark: "test",
|
|
61
|
-
notify_url: "https://
|
|
88
|
+
notify_url: "https://www.example.com",
|
|
62
89
|
project_id: "",
|
|
63
90
|
})
|
|
64
91
|
.then((data) => {
|
|
65
|
-
|
|
92
|
+
if (data.code === "0000") {
|
|
93
|
+
// 操作成功
|
|
94
|
+
console.log("操作成功 ", data.data)
|
|
95
|
+
} else {
|
|
96
|
+
// 失败返回
|
|
97
|
+
console.log("失败返回 ", "code:" + data.code + " message:" + data.message + " request_id:" + data.request_id)
|
|
98
|
+
}
|
|
66
99
|
})
|
|
67
100
|
.catch((err) => {
|
|
101
|
+
// 发生异常
|
|
68
102
|
console.log(err.toString())
|
|
69
103
|
})
|
|
70
104
|
|
|
71
105
|
// 查询单笔订单信息
|
|
72
106
|
payment
|
|
73
107
|
.GetOrder({
|
|
74
|
-
|
|
108
|
+
// request-id:请求 ID,请求的唯一标识
|
|
109
|
+
// 建议平台企业自定义 request-id,并记录在日志中,便于问题发现及排查
|
|
110
|
+
// 如平台企业未自定义 request-id,将使用 SDK 中的 random 方法自动生成。注意:random 方法生成的 request-id 不能保证全局唯一,推荐自定义
|
|
111
|
+
request_id: "requestIdExample123456789",
|
|
112
|
+
order_id: "nodetest123",
|
|
75
113
|
channel: "支付宝",
|
|
76
114
|
data_type: "",
|
|
77
115
|
})
|
|
78
116
|
.then((data) => {
|
|
79
|
-
|
|
117
|
+
if (data.code === "0000") {
|
|
118
|
+
// 操作成功
|
|
119
|
+
console.log("操作成功 ", data.data)
|
|
120
|
+
} else {
|
|
121
|
+
// 失败返回
|
|
122
|
+
console.log("失败返回 ", "code:" + data.code + " message:" + data.message + " request_id:" + data.request_id)
|
|
123
|
+
}
|
|
80
124
|
})
|
|
81
125
|
.catch((err) => {
|
|
126
|
+
// 发生异常
|
|
82
127
|
console.log(err.toString())
|
|
83
128
|
})
|
|
84
129
|
|
|
85
130
|
// 查询平台企业余额
|
|
86
131
|
payment
|
|
87
132
|
.ListAccount({
|
|
133
|
+
// request-id:请求 ID,请求的唯一标识
|
|
134
|
+
// 建议平台企业自定义 request-id,并记录在日志中,便于问题发现及排查
|
|
135
|
+
// 如平台企业未自定义 request-id,将使用 SDK 中的 random 方法自动生成。注意:random 方法生成的 request-id 不能保证全局唯一,推荐自定义
|
|
136
|
+
request_id: "requestIdExample123456789",
|
|
88
137
|
dealer_id: config.dealer_id,
|
|
89
138
|
})
|
|
90
139
|
.then((data) => {
|
|
91
|
-
|
|
140
|
+
if (data.code === "0000") {
|
|
141
|
+
// 操作成功
|
|
142
|
+
console.log("操作成功 ", data.data)
|
|
143
|
+
} else {
|
|
144
|
+
// 失败返回
|
|
145
|
+
console.log("失败返回 ", "code:" + data.code + " message:" + data.message + " request_id:" + data.request_id)
|
|
146
|
+
}
|
|
92
147
|
})
|
|
93
148
|
.catch((err) => {
|
|
149
|
+
// 发生异常
|
|
94
150
|
console.log(err.toString())
|
|
95
151
|
})
|
|
96
152
|
|
|
97
153
|
// 查询电子回单
|
|
98
154
|
payment
|
|
99
155
|
.GetEleReceiptFile({
|
|
156
|
+
// request-id:请求 ID,请求的唯一标识
|
|
157
|
+
// 建议平台企业自定义 request-id,并记录在日志中,便于问题发现及排查
|
|
158
|
+
// 如平台企业未自定义 request-id,将使用 SDK 中的 random 方法自动生成。注意:random 方法生成的 request-id 不能保证全局唯一,推荐自定义
|
|
159
|
+
request_id: "requestIdExample123456789",
|
|
100
160
|
order_id: "120530112204453",
|
|
101
161
|
ref: "",
|
|
102
162
|
})
|
|
103
163
|
.then((data) => {
|
|
104
|
-
|
|
164
|
+
if (data.code === "0000") {
|
|
165
|
+
// 操作成功
|
|
166
|
+
console.log("操作成功 ", data.data)
|
|
167
|
+
} else {
|
|
168
|
+
// 失败返回
|
|
169
|
+
console.log("失败返回 ", "code:" + data.code + " message:" + data.message + " request_id:" + data.request_id)
|
|
170
|
+
}
|
|
105
171
|
})
|
|
106
172
|
.catch((err) => {
|
|
173
|
+
// 发生异常
|
|
107
174
|
console.log(err.toString())
|
|
108
175
|
})
|
|
109
176
|
|
|
110
177
|
// 取消待支付订单
|
|
111
178
|
payment
|
|
112
179
|
.CancelOrder({
|
|
180
|
+
// request-id:请求 ID,请求的唯一标识
|
|
181
|
+
// 建议平台企业自定义 request-id,并记录在日志中,便于问题发现及排查
|
|
182
|
+
// 如平台企业未自定义 request-id,将使用 SDK 中的 random 方法自动生成。注意:random 方法生成的 request-id 不能保证全局唯一,推荐自定义
|
|
183
|
+
request_id: "requestIdExample123456789",
|
|
113
184
|
dealer_id: config.dealer_id,
|
|
114
185
|
order_id: "2222",
|
|
115
186
|
})
|
|
@@ -123,19 +194,34 @@ payment
|
|
|
123
194
|
// 查询平台企业汇款信息
|
|
124
195
|
payment
|
|
125
196
|
.GetDealerVARechargeAccount({
|
|
197
|
+
// request-id:请求 ID,请求的唯一标识
|
|
198
|
+
// 建议平台企业自定义 request-id,并记录在日志中,便于问题发现及排查
|
|
199
|
+
// 如平台企业未自定义 request-id,将使用 SDK 中的 random 方法自动生成。注意:random 方法生成的 request-id 不能保证全局唯一,推荐自定义
|
|
200
|
+
request_id: "requestIdExample123456789",
|
|
126
201
|
dealer_id: config.dealer_id,
|
|
127
202
|
broker_id: config.broker_id,
|
|
128
203
|
})
|
|
129
204
|
.then((data) => {
|
|
130
|
-
|
|
205
|
+
if (data.code === "0000") {
|
|
206
|
+
// 操作成功
|
|
207
|
+
console.log("操作成功 ", data.data)
|
|
208
|
+
} else {
|
|
209
|
+
// 失败返回
|
|
210
|
+
console.log("失败返回 ", "code:" + data.code + " message:" + data.message + " request_id:" + data.request_id)
|
|
211
|
+
}
|
|
131
212
|
})
|
|
132
213
|
.catch((err) => {
|
|
214
|
+
// 发生异常
|
|
133
215
|
console.log(err.toString())
|
|
134
216
|
})
|
|
135
217
|
|
|
136
218
|
// 批次下单
|
|
137
219
|
payment
|
|
138
220
|
.CreateBatchOrder({
|
|
221
|
+
// request-id:请求 ID,请求的唯一标识
|
|
222
|
+
// 建议平台企业自定义 request-id,并记录在日志中,便于问题发现及排查
|
|
223
|
+
// 如平台企业未自定义 request-id,将使用 SDK 中的 random 方法自动生成。注意:random 方法生成的 request-id 不能保证全局唯一,推荐自定义
|
|
224
|
+
request_id: "requestIdExample123456789",
|
|
139
225
|
batch_id: "batchtest123456",
|
|
140
226
|
dealer_id: config.dealer_id,
|
|
141
227
|
broker_id: config.broker_id,
|
|
@@ -146,20 +232,20 @@ payment
|
|
|
146
232
|
{
|
|
147
233
|
order_id: "2013011801111",
|
|
148
234
|
real_name: "张三",
|
|
149
|
-
card_no: "
|
|
150
|
-
id_card: "
|
|
235
|
+
card_no: "username1@example.com",
|
|
236
|
+
id_card: "110121202202222221",
|
|
151
237
|
pay: "0.01",
|
|
152
238
|
pay_remark: "测试订单1",
|
|
153
|
-
notify_url: "https://
|
|
239
|
+
notify_url: "https://www.example.com",
|
|
154
240
|
},
|
|
155
241
|
{
|
|
156
242
|
order_id: "2013011802111",
|
|
157
243
|
real_name: "李四",
|
|
158
|
-
card_no: "
|
|
159
|
-
id_card: "
|
|
244
|
+
card_no: "username2@example.com",
|
|
245
|
+
id_card: "110121202202222222",
|
|
160
246
|
pay: "0.01",
|
|
161
|
-
pay_remark: "测试订单
|
|
162
|
-
notify_url: "https://
|
|
247
|
+
pay_remark: "测试订单2",
|
|
248
|
+
notify_url: "https://www.example.com",
|
|
163
249
|
},
|
|
164
250
|
],
|
|
165
251
|
})
|
|
@@ -173,14 +259,50 @@ payment
|
|
|
173
259
|
// 批次确认
|
|
174
260
|
payment
|
|
175
261
|
.ConfirmBatchOrder({
|
|
176
|
-
|
|
262
|
+
// request-id:请求 ID,请求的唯一标识
|
|
263
|
+
// 建议平台企业自定义 request-id,并记录在日志中,便于问题发现及排查
|
|
264
|
+
// 如平台企业未自定义 request-id,将使用 SDK 中的 random 方法自动生成。注意:random 方法生成的 request-id 不能保证全局唯一,推荐自定义
|
|
265
|
+
request_id: "requestIdExample123456789",
|
|
266
|
+
batch_id: "batchtest123456",
|
|
177
267
|
dealer_id: config.dealer_id,
|
|
178
268
|
broker_id: config.broker_id,
|
|
179
269
|
channel: "支付宝",
|
|
180
270
|
})
|
|
181
271
|
.then((data) => {
|
|
182
|
-
|
|
272
|
+
if (data.code === "0000") {
|
|
273
|
+
// 操作成功
|
|
274
|
+
console.log("操作成功 ", data.data)
|
|
275
|
+
} else {
|
|
276
|
+
// 失败返回
|
|
277
|
+
console.log("失败返回 ", "code:" + data.code + " message:" + data.message + " request_id:" + data.request_id)
|
|
278
|
+
}
|
|
279
|
+
})
|
|
280
|
+
.catch((err) => {
|
|
281
|
+
// 发生异常
|
|
282
|
+
console.log(err.toString())
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
// 批次撤销
|
|
286
|
+
payment
|
|
287
|
+
.CancelBatchOrder({
|
|
288
|
+
// request-id:请求 ID,请求的唯一标识
|
|
289
|
+
// 建议平台企业自定义 request-id,并记录在日志中,便于问题发现及排查
|
|
290
|
+
// 如平台企业未自定义 request-id,将使用 SDK 中的 random 方法自动生成。注意:random 方法生成的 request-id 不能保证全局唯一,推荐自定义
|
|
291
|
+
request_id: "requestIdExample123456789",
|
|
292
|
+
batch_id: "batchtest123456",
|
|
293
|
+
dealer_id: config.dealer_id,
|
|
294
|
+
broker_id: config.broker_id,
|
|
295
|
+
})
|
|
296
|
+
.then((data) => {
|
|
297
|
+
if (data.code === "0000") {
|
|
298
|
+
// 操作成功
|
|
299
|
+
console.log("操作成功 ", data.data)
|
|
300
|
+
} else {
|
|
301
|
+
// 失败返回
|
|
302
|
+
console.log("失败返回 ", "code:" + data.code + " message:" + data.message + " request_id:" + data.request_id)
|
|
303
|
+
}
|
|
183
304
|
})
|
|
184
305
|
.catch((err) => {
|
|
306
|
+
// 发生异常
|
|
185
307
|
console.log(err.toString())
|
|
186
308
|
})
|
package/example/tax.js
CHANGED
|
@@ -7,28 +7,50 @@ const tax = new yzhAPI.TaxClient(config)
|
|
|
7
7
|
// 下载个人所得税扣缴明细表
|
|
8
8
|
tax
|
|
9
9
|
.GetTaxFile({
|
|
10
|
+
// request-id:请求 ID,请求的唯一标识
|
|
11
|
+
// 建议平台企业自定义 request-id,并记录在日志中,便于问题发现及排查
|
|
12
|
+
// 如平台企业未自定义 request-id,将使用 SDK 中的 random 方法自动生成。注意:random 方法生成的 request-id 不能保证全局唯一,推荐自定义
|
|
13
|
+
request_id: "requestIdExample123456789",
|
|
10
14
|
dealer_id: config.dealer_id,
|
|
11
15
|
ent_id: "accumulus_tj",
|
|
12
16
|
year_month: "2022-10",
|
|
13
17
|
})
|
|
14
18
|
.then((data) => {
|
|
15
|
-
|
|
19
|
+
if (data.code === "0000") {
|
|
20
|
+
// 操作成功
|
|
21
|
+
console.log("操作成功 ", data.data)
|
|
22
|
+
} else {
|
|
23
|
+
// 失败返回
|
|
24
|
+
console.log("失败返回 ", "code:" + data.code + " message:" + data.message + " request_id:" + data.request_id)
|
|
25
|
+
}
|
|
16
26
|
})
|
|
17
27
|
.catch((err) => {
|
|
28
|
+
// 发生异常
|
|
18
29
|
console.log(err.toString())
|
|
19
30
|
})
|
|
20
31
|
|
|
21
32
|
// 查询纳税人是否为跨集团用户
|
|
22
33
|
tax
|
|
23
34
|
.GetUserCross({
|
|
35
|
+
// request-id:请求 ID,请求的唯一标识
|
|
36
|
+
// 建议平台企业自定义 request-id,并记录在日志中,便于问题发现及排查
|
|
37
|
+
// 如平台企业未自定义 request-id,将使用 SDK 中的 random 方法自动生成。注意:random 方法生成的 request-id 不能保证全局唯一,推荐自定义
|
|
38
|
+
request_id: "requestIdExample123456789",
|
|
24
39
|
dealer_id: config.dealer_id,
|
|
25
40
|
ent_id: "accumulus_tj",
|
|
26
|
-
id_card: "
|
|
41
|
+
id_card: "110121202202222222",
|
|
27
42
|
year: "2022",
|
|
28
43
|
})
|
|
29
44
|
.then((data) => {
|
|
30
|
-
|
|
45
|
+
if (data.code === "0000") {
|
|
46
|
+
// 操作成功
|
|
47
|
+
console.log("操作成功 ", data.data)
|
|
48
|
+
} else {
|
|
49
|
+
// 失败返回
|
|
50
|
+
console.log("失败返回 ", "code:" + data.code + " message:" + data.message + " request_id:" + data.request_id)
|
|
51
|
+
}
|
|
31
52
|
})
|
|
32
53
|
.catch((err) => {
|
|
54
|
+
// 发生异常
|
|
33
55
|
console.log(err.toString())
|
|
34
56
|
})
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const yzhAPI = require("../yzh/index.js")
|
|
2
|
+
const config = require("./conf/config.js")
|
|
3
|
+
|
|
4
|
+
// 签约信息上传
|
|
5
|
+
const uploaduserSign = new yzhAPI.UploadUserSignServiceClient(config)
|
|
6
|
+
|
|
7
|
+
// 用户签约信息上传
|
|
8
|
+
uploaduserSign
|
|
9
|
+
.UploadUserSign({
|
|
10
|
+
// request-id:请求 ID,请求的唯一标识
|
|
11
|
+
// 建议平台企业自定义 request-id,并记录在日志中,便于问题发现及排查
|
|
12
|
+
// 如平台企业未自定义 request-id,将使用 SDK 中的 random 方法自动生成。注意:random 方法生成的 request-id 不能保证全局唯一,推荐自定义
|
|
13
|
+
request_id: "requestIdExample123456789",
|
|
14
|
+
dealer_id: config.dealer_id,
|
|
15
|
+
broker_id: config.broker_id,
|
|
16
|
+
real_name: "张三",
|
|
17
|
+
id_card: "110121202202222222",
|
|
18
|
+
phone: "188****8888",
|
|
19
|
+
is_abroad: false,
|
|
20
|
+
notify_url: "https://www.example.com",
|
|
21
|
+
})
|
|
22
|
+
.then((data) => {
|
|
23
|
+
if (data.code === "0000") {
|
|
24
|
+
// 操作成功
|
|
25
|
+
console.log("操作成功 ", data.data)
|
|
26
|
+
} else {
|
|
27
|
+
// 失败返回
|
|
28
|
+
console.log("失败返回 ", "code:" + data.code + " message:" + data.message + " request_id:" + data.request_id)
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
.catch((err) => {
|
|
32
|
+
// 发生异常
|
|
33
|
+
console.log(err.toString())
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
// 获取用户签约状态
|
|
37
|
+
uploaduserSign
|
|
38
|
+
.GetUploadUserSignStatus({
|
|
39
|
+
// request-id:请求 ID,请求的唯一标识
|
|
40
|
+
// 建议平台企业自定义 request-id,并记录在日志中,便于问题发现及排查
|
|
41
|
+
// 如平台企业未自定义 request-id,将使用 SDK 中的 random 方法自动生成。注意:random 方法生成的 request-id 不能保证全局唯一,推荐自定义
|
|
42
|
+
request_id: "requestIdExample123456789",
|
|
43
|
+
dealer_id: config.dealer_id,
|
|
44
|
+
broker_id: config.broker_id,
|
|
45
|
+
real_name: "张三",
|
|
46
|
+
id_card: "110121202202222222",
|
|
47
|
+
})
|
|
48
|
+
.then((data) => {
|
|
49
|
+
if (data.code === "0000") {
|
|
50
|
+
// 操作成功
|
|
51
|
+
console.log("操作成功 ", data.data)
|
|
52
|
+
} else {
|
|
53
|
+
// 失败返回
|
|
54
|
+
console.log("失败返回 ", "code:" + data.code + " message:" + data.message + " request_id:" + data.request_id)
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
.catch((err) => {
|
|
58
|
+
// 发生异常
|
|
59
|
+
console.log(err.toString())
|
|
60
|
+
})
|
package/package.json
CHANGED
|
@@ -1,47 +1,52 @@
|
|
|
1
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
|
-
|
|
2
|
+
"name": "@yunzhanghu/sdk-nodejs",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "云账户 SDK for Node.js",
|
|
5
|
+
"main": "yzh/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"build": "tsc && node tdsformat.js && npm run format:dts",
|
|
9
|
+
"prettier": "prettier --config prettier.config.js --write 'src/**/*.{ts,js}'",
|
|
10
|
+
"lint:tsc": "tsc -p tsconfig.json --noEmit",
|
|
11
|
+
"lint:es": "eslint --ext .js,ts --cache src",
|
|
12
|
+
"format:dts": "prettier --write yzh/services/**/*.d.ts yzh/services/**/*.js",
|
|
13
|
+
"prepare": "husky install"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/YunzhanghuOpen/sdk-nodejs"
|
|
18
|
+
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=12"
|
|
21
|
+
},
|
|
22
|
+
"author": "yunzhanghuapi",
|
|
23
|
+
"license": "Apache-2.0",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/crypto-js": "^4.1.1",
|
|
26
|
+
"@types/json-bigint": "^1.0.2",
|
|
27
|
+
"@types/node": "^18.11.18",
|
|
28
|
+
"@types/urlencode": "^1.1.2",
|
|
29
|
+
"@types/vfile-message": "^2.0.0",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^5.50.0",
|
|
31
|
+
"@typescript-eslint/parser": "^5.50.0",
|
|
32
|
+
"@yzh-devkit/eslint-config-lint": "^3.0.6",
|
|
33
|
+
"eslint": "^8.33.0",
|
|
34
|
+
"husky": "^8.0.3",
|
|
35
|
+
"lint-staged": "^13.1.0",
|
|
36
|
+
"prettier": "^2.8.3",
|
|
37
|
+
"typescript": "^4.9.4"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"axios": "^1.2.1",
|
|
41
|
+
"crypto-js": "^4.1.1",
|
|
42
|
+
"json-bigint": "^1.0.0",
|
|
43
|
+
"tslib": "^2.4.1",
|
|
44
|
+
"urlencode": "^1.1.0"
|
|
45
|
+
},
|
|
46
|
+
"lint-staged": {
|
|
47
|
+
"*.{js,ts}": [
|
|
48
|
+
"eslint --fix --ext .js,ts --cache src",
|
|
49
|
+
"git add"
|
|
50
|
+
]
|
|
51
|
+
}
|
|
47
52
|
}
|
package/src/common/client.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
2
2
|
import * as crypto from "crypto"
|
|
3
|
+
|
|
4
|
+
import getInstance from "../common/http"
|
|
3
5
|
import YZHSDKHttpException from "./exception/yzhSDKHttpException"
|
|
6
|
+
|
|
4
7
|
const clearEncoding = "utf8"
|
|
5
8
|
const cipherEncoding = "base64"
|
|
6
9
|
|
|
@@ -10,14 +13,23 @@ type ResponseData = any
|
|
|
10
13
|
|
|
11
14
|
export class YZHClient {
|
|
12
15
|
public dealer_id: string
|
|
16
|
+
|
|
13
17
|
public broker_id: string
|
|
18
|
+
|
|
14
19
|
public app_key: string
|
|
20
|
+
|
|
15
21
|
public des3_key: string
|
|
22
|
+
|
|
16
23
|
public private_key: string
|
|
24
|
+
|
|
17
25
|
public yzh_public_key: string
|
|
26
|
+
|
|
18
27
|
public sign_type: "rsa" | "sha256"
|
|
28
|
+
|
|
19
29
|
public base_url?: string
|
|
20
30
|
|
|
31
|
+
public timeout?: number
|
|
32
|
+
|
|
21
33
|
/**
|
|
22
34
|
* 构造函数参数
|
|
23
35
|
* @param {string} dealer_id 平台企业 ID
|
|
@@ -26,8 +38,9 @@ export class YZHClient {
|
|
|
26
38
|
* @param {string} des3_key 3DES Key
|
|
27
39
|
* @param {string} private_key 平台企业私钥
|
|
28
40
|
* @param {string} yzh_public_key 云账户公钥
|
|
29
|
-
* @param {string} sign_type
|
|
41
|
+
* @param {string} sign_type 签名算法,支持 RSA、HMAC,枚举分别为 rsa、sha256
|
|
30
42
|
* @param {string} base_url 可选,默认为 https://api-service.yunzhanghu.com/
|
|
43
|
+
* @param {number} timeout 请求超时时间。可选,默认30*1000ms。0为永不超时。
|
|
31
44
|
*/
|
|
32
45
|
constructor(conf: {
|
|
33
46
|
dealer_id: string
|
|
@@ -38,6 +51,7 @@ export class YZHClient {
|
|
|
38
51
|
yzh_public_key: string
|
|
39
52
|
sign_type: "rsa" | "sha256"
|
|
40
53
|
base_url?: string
|
|
54
|
+
timeout?: number
|
|
41
55
|
}) {
|
|
42
56
|
const { dealer_id, broker_id, app_key, des3_key, private_key, yzh_public_key, sign_type } =
|
|
43
57
|
conf || {}
|
|
@@ -59,6 +73,7 @@ export class YZHClient {
|
|
|
59
73
|
this.yzh_public_key = conf.yzh_public_key
|
|
60
74
|
this.sign_type = conf.sign_type
|
|
61
75
|
this.base_url = conf?.base_url
|
|
76
|
+
this.timeout = conf?.timeout
|
|
62
77
|
} else {
|
|
63
78
|
throw new YZHSDKHttpException(
|
|
64
79
|
`实例初始化失败,请检查以下配置是否缺失:\ndealer_id、broker_id、app_key、des3_key、private_key、yzh_public_key、sign_type`
|
|
@@ -76,9 +91,11 @@ export class YZHClient {
|
|
|
76
91
|
request_id: request_id ?? this.mess(),
|
|
77
92
|
dealer_id: this.dealer_id,
|
|
78
93
|
base_url: this.base_url,
|
|
94
|
+
timeout: this.timeout,
|
|
79
95
|
})
|
|
96
|
+
|
|
80
97
|
// 返回请求实例
|
|
81
|
-
const baseInstanceConf = { method
|
|
98
|
+
const baseInstanceConf = { method, url: action }
|
|
82
99
|
let instanceConf
|
|
83
100
|
if (method === "get") {
|
|
84
101
|
instanceConf = { ...baseInstanceConf, params: encryptParams }
|
|
@@ -144,7 +161,7 @@ export class YZHClient {
|
|
|
144
161
|
}
|
|
145
162
|
|
|
146
163
|
/**
|
|
147
|
-
* 生成签名(RSA
|
|
164
|
+
* 生成签名(RSA 签名算法)
|
|
148
165
|
* @param {string} data 经过加密后的具体数据
|
|
149
166
|
* @param {string} mess 自定义随机字符串,用于签名
|
|
150
167
|
* @param {string} timestamp 时间戳,精确到秒
|
|
@@ -163,7 +180,7 @@ export class YZHClient {
|
|
|
163
180
|
}
|
|
164
181
|
|
|
165
182
|
/**
|
|
166
|
-
* 生成签名(
|
|
183
|
+
* 生成签名(HMAC 签名算法)
|
|
167
184
|
* @param {string} data 经过加密后的具体数据
|
|
168
185
|
* @param {string} mess 自定义随机字符串,用于签名
|
|
169
186
|
* @param {string} timestamp 时间戳,精确到秒
|
|
@@ -185,7 +202,7 @@ export class YZHClient {
|
|
|
185
202
|
* @param {string} data 经过加密后的具体数据
|
|
186
203
|
* @param {string} mess 自定义随机字符串,用于签名
|
|
187
204
|
* @param {string} timestamp 时间戳,精确到秒
|
|
188
|
-
* @param {string} sign_type
|
|
205
|
+
* @param {string} sign_type 签名算法,支持 RSA、HMAC,枚举分别为 rsa、sha256
|
|
189
206
|
* @returns {string} 签名内容
|
|
190
207
|
*/
|
|
191
208
|
private sign = (data: string, mess: string, timestamp: string) => {
|
|
@@ -198,7 +215,7 @@ export class YZHClient {
|
|
|
198
215
|
return this.signHmacSHA256(data, mess, timestamp)
|
|
199
216
|
}
|
|
200
217
|
default:
|
|
201
|
-
throw new YZHSDKHttpException(`sign_type类型不存在`)
|
|
218
|
+
throw new YZHSDKHttpException(`sign_type 类型不存在`)
|
|
202
219
|
}
|
|
203
220
|
} catch (err) {
|
|
204
221
|
throw new YZHSDKHttpException(`${err}`)
|
|
@@ -206,6 +223,7 @@ export class YZHClient {
|
|
|
206
223
|
}
|
|
207
224
|
|
|
208
225
|
// 自定义随机字符串
|
|
226
|
+
// eslint-disable-next-line class-methods-use-this
|
|
209
227
|
private mess = () => {
|
|
210
228
|
const buf = crypto.randomBytes(16)
|
|
211
229
|
const token = buf.toString("hex")
|
|
@@ -233,6 +251,7 @@ export class YZHClient {
|
|
|
233
251
|
}
|
|
234
252
|
|
|
235
253
|
// 返回处理结果
|
|
254
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
236
255
|
private async parseResponse(result: ResponseData, encryption?: boolean) {
|
|
237
256
|
if (result.status !== 200) {
|
|
238
257
|
const yzhError = new YZHSDKHttpException(result.statusText)
|