@yunzhanghu/sdk-nodejs 1.0.4 → 1.0.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/.eslintignore +2 -1
- package/README.md +2 -2
- package/example/apiUserSign.js +3 -3
- package/example/authentication.js +11 -11
- package/example/bizlicXjjH5.js +1 -1
- package/example/bizlicXjjH5Api.js +2 -2
- package/example/custom.js +53 -0
- package/example/h5UserSign.js +3 -3
- package/example/payment.js +10 -10
- package/example/tax.js +1 -1
- package/example/uploadusersign.js +2 -2
- package/package.json +1 -3
- package/src/common/client.ts +2 -2
- package/src/services/custom/index.ts +36 -0
- package/src/services/index.ts +1 -0
- package/yzh/common/client.d.ts +3 -3
- package/yzh/common/client.js +24 -31
- package/yzh/common/exception/yzhSDKHttpException.js +2 -2
- package/yzh/common/http/index.js +9 -9
- package/yzh/common/utils/index.d.ts +2 -2
- package/yzh/index.d.ts +1 -1
- package/yzh/services/custom/index.d.ts +28 -0
- package/yzh/services/custom/index.js +23 -0
- package/yzh/services/index.d.ts +12 -11
- package/yzh/services/index.js +3 -1
package/.eslintignore
CHANGED
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
使用云账户 SDK for Node.js 前,您需先获取 dealer_id、broker_id、3DES Key、App Key、云账户公钥。
|
|
16
16
|
获取方式:使用开户邮件中的账号登录【[云账户综合服务平台](https://service.yunzhanghu.com)】,选择“业务中心 > 业务管理 > 对接信息”,查看并获取以上配置信息。
|
|
17
|
-

|
|
18
18
|
|
|
19
19
|
### 2、生成密钥
|
|
20
20
|
|
|
@@ -39,7 +39,7 @@ OpenSSL-> rsa -in private_key.pem -pubout -out pubkey.pem
|
|
|
39
39
|
### 3、配置密钥
|
|
40
40
|
|
|
41
41
|
登录【[云账户综合服务平台](https://service.yunzhanghu.com)】,选择“业务中心 > 业务管理 > 对接信息”,单击页面右上角的“编辑”,配置平台企业公钥。
|
|
42
|
-

|
|
43
43
|
|
|
44
44
|
## 安装云账户 SDK for Node.js
|
|
45
45
|
|
package/example/apiUserSign.js
CHANGED
|
@@ -44,7 +44,7 @@ apiusersign
|
|
|
44
44
|
dealer_id: config.dealer_id,
|
|
45
45
|
broker_id: config.broker_id,
|
|
46
46
|
real_name: "张三",
|
|
47
|
-
id_card: "
|
|
47
|
+
id_card: "11010519491231002X",
|
|
48
48
|
user_id: "userId00001",
|
|
49
49
|
card_type: "idcard",
|
|
50
50
|
})
|
|
@@ -75,7 +75,7 @@ apiusersign
|
|
|
75
75
|
dealer_id: config.dealer_id,
|
|
76
76
|
broker_id: config.broker_id,
|
|
77
77
|
real_name: " 张三",
|
|
78
|
-
id_card: "
|
|
78
|
+
id_card: "11010519491231002X",
|
|
79
79
|
user_id: "userId00001",
|
|
80
80
|
})
|
|
81
81
|
.then((data) => {
|
|
@@ -105,7 +105,7 @@ apiusersign
|
|
|
105
105
|
dealer_id: this.dealer_id,
|
|
106
106
|
broker_id: this.broker_id,
|
|
107
107
|
real_name: "张三",
|
|
108
|
-
id_card: "
|
|
108
|
+
id_card: "11010519491231002X",
|
|
109
109
|
user_id: "userId00001",
|
|
110
110
|
card_type: "idcard",
|
|
111
111
|
})
|
|
@@ -17,8 +17,8 @@ authentication
|
|
|
17
17
|
*/
|
|
18
18
|
request_id: "requestIdExample123456789",
|
|
19
19
|
real_name: "张三",
|
|
20
|
-
card_no: "
|
|
21
|
-
id_card: "
|
|
20
|
+
card_no: "6228888888888888888",
|
|
21
|
+
id_card: "11010519491231002X",
|
|
22
22
|
mobile: "188****8888",
|
|
23
23
|
})
|
|
24
24
|
.then((data) => {
|
|
@@ -46,8 +46,8 @@ authentication
|
|
|
46
46
|
*/
|
|
47
47
|
request_id: "requestIdExample123456789",
|
|
48
48
|
real_name: "张三",
|
|
49
|
-
card_no: "
|
|
50
|
-
id_card: "
|
|
49
|
+
card_no: "6228888888888888888",
|
|
50
|
+
id_card: "11010519491231002X",
|
|
51
51
|
mobile: "188****8888",
|
|
52
52
|
ref: "MTY3NDA0Mzc4NTg1MTY4NjUzNy0xMDYuMTIwLjQwLjU4",
|
|
53
53
|
captcha: "502373",
|
|
@@ -77,8 +77,8 @@ authentication
|
|
|
77
77
|
*/
|
|
78
78
|
request_id: "requestIdExample123456789",
|
|
79
79
|
real_name: "张三",
|
|
80
|
-
card_no: "
|
|
81
|
-
id_card: "
|
|
80
|
+
card_no: "6228888888888888888",
|
|
81
|
+
id_card: "11010519491231002X",
|
|
82
82
|
mobile: "188****8888",
|
|
83
83
|
})
|
|
84
84
|
.then((data) => {
|
|
@@ -106,8 +106,8 @@ authentication
|
|
|
106
106
|
*/
|
|
107
107
|
request_id: "requestIdExample123456789",
|
|
108
108
|
real_name: "张三",
|
|
109
|
-
card_no: "
|
|
110
|
-
id_card: "
|
|
109
|
+
card_no: "6228888888888888888",
|
|
110
|
+
id_card: "11010519491231002X",
|
|
111
111
|
})
|
|
112
112
|
.then((data) => {
|
|
113
113
|
if (data.code === "0000") {
|
|
@@ -134,7 +134,7 @@ authentication
|
|
|
134
134
|
*/
|
|
135
135
|
request_id: "requestIdExample123456789",
|
|
136
136
|
real_name: "张三",
|
|
137
|
-
id_card: "
|
|
137
|
+
id_card: "11010519491231002X",
|
|
138
138
|
})
|
|
139
139
|
.then((data) => {
|
|
140
140
|
if (data.code === "0000") {
|
|
@@ -160,7 +160,7 @@ authentication
|
|
|
160
160
|
* 如未自定义 request-id,将使用 SDK 中的 UUID 方法自动生成。注意:UUID 方法生成的 request-id 不能保证全局唯一,推荐自定义 request-id
|
|
161
161
|
*/
|
|
162
162
|
request_id: "requestIdExample123456789",
|
|
163
|
-
card_no: "
|
|
163
|
+
card_no: "6228888888888888888",
|
|
164
164
|
bank_name: "招商银行",
|
|
165
165
|
})
|
|
166
166
|
.then((data) => {
|
|
@@ -235,7 +235,7 @@ authentication
|
|
|
235
235
|
* 如未自定义 request-id,将使用 SDK 中的 UUID 方法自动生成。注意:UUID 方法生成的 request-id 不能保证全局唯一,推荐自定义 request-id
|
|
236
236
|
*/
|
|
237
237
|
request_id: "requestIdExample123456789",
|
|
238
|
-
id_card: "
|
|
238
|
+
id_card: "11010519491231002X",
|
|
239
239
|
real_name: "测试",
|
|
240
240
|
})
|
|
241
241
|
.then((data) => {
|
package/example/bizlicXjjH5.js
CHANGED
|
@@ -22,7 +22,7 @@ bizlicxjjh5api
|
|
|
22
22
|
dealer_user_id: "test000",
|
|
23
23
|
phone_no: "188****8888",
|
|
24
24
|
real_name: "张三",
|
|
25
|
-
id_card: "
|
|
25
|
+
id_card: "11010519491231002X",
|
|
26
26
|
id_card_address: "",
|
|
27
27
|
id_card_agency: "",
|
|
28
28
|
id_card_nation: "20",
|
|
@@ -91,7 +91,7 @@ bizlicxjjh5api
|
|
|
91
91
|
open_id: "",
|
|
92
92
|
dealer_user_id: "test000",
|
|
93
93
|
real_name: "张三",
|
|
94
|
-
id_card: "
|
|
94
|
+
id_card: "11010519491231002X",
|
|
95
95
|
})
|
|
96
96
|
.then((data) => {
|
|
97
97
|
if (data.code === "0000") {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const yzhAPI = require('../yzh/index.js');
|
|
2
|
+
const config = require('./conf/config.js');
|
|
3
|
+
|
|
4
|
+
// 通用请求函数
|
|
5
|
+
const customClient = new yzhAPI.CustomClient(config);
|
|
6
|
+
|
|
7
|
+
// 接口参数
|
|
8
|
+
const req = {
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} request-id:请求 ID,请求的唯一标识
|
|
11
|
+
* 建议平台企业自定义 request-id,并记录在日志中,便于问题发现及排查
|
|
12
|
+
* 如未自定义 request-id,将使用 SDK 中的 random 方法自动生成。注意:random 方法生成的 request-id 不能保证全局唯一,推荐自定义 request-id
|
|
13
|
+
*/
|
|
14
|
+
request_id: 'requestIdExample123456789',
|
|
15
|
+
order_id: '202009010016562012987',
|
|
16
|
+
dealer_id: config.dealer_id,
|
|
17
|
+
broker_id: config.broker_id,
|
|
18
|
+
real_name: '张三',
|
|
19
|
+
card_no: '6228888888888888888',
|
|
20
|
+
id_card: '11010519491231002X',
|
|
21
|
+
pay: '100.00',
|
|
22
|
+
pay_remark: '',
|
|
23
|
+
notify_url: 'https://www.example.com',
|
|
24
|
+
};
|
|
25
|
+
// 接口请求地址
|
|
26
|
+
const url = '/api/payment/v1/order-bankpay';
|
|
27
|
+
|
|
28
|
+
// 接口请求方式
|
|
29
|
+
const method = 'post';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 通用请求函数
|
|
33
|
+
* 适用于 SDK 暂未支持的接口
|
|
34
|
+
* 以“银行卡实时支付”接口为例
|
|
35
|
+
*/
|
|
36
|
+
customClient
|
|
37
|
+
.doRequest(req, url, method)
|
|
38
|
+
.then(data => {
|
|
39
|
+
if (data.code === '0000') {
|
|
40
|
+
// 操作成功
|
|
41
|
+
console.log('操作成功,', data.data);
|
|
42
|
+
} else {
|
|
43
|
+
// 失败返回
|
|
44
|
+
console.log(
|
|
45
|
+
'失败返回,',
|
|
46
|
+
'code:' + data.code + ' message:' + data.message + ' request_id:' + data.request_id
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
.catch(err => {
|
|
51
|
+
// 发生异常
|
|
52
|
+
console.log(err.toString());
|
|
53
|
+
});
|
package/example/h5UserSign.js
CHANGED
|
@@ -17,7 +17,7 @@ h5usersign
|
|
|
17
17
|
dealer_id: config.dealer_id,
|
|
18
18
|
broker_id: config.broker_id,
|
|
19
19
|
real_name: "张三",
|
|
20
|
-
id_card: "
|
|
20
|
+
id_card: "11010519491231002X",
|
|
21
21
|
certificate_type: 0,
|
|
22
22
|
})
|
|
23
23
|
.then((data) => {
|
|
@@ -76,7 +76,7 @@ h5usersign
|
|
|
76
76
|
dealer_id: config.dealer_id,
|
|
77
77
|
broker_id: config.broker_id,
|
|
78
78
|
real_name: "张三",
|
|
79
|
-
id_card: "
|
|
79
|
+
id_card: "11010519491231002X",
|
|
80
80
|
})
|
|
81
81
|
.then((data) => {
|
|
82
82
|
if (data.code === "0000") {
|
|
@@ -105,7 +105,7 @@ h5usersign
|
|
|
105
105
|
dealer_id: config.dealer_id,
|
|
106
106
|
broker_id: config.broker_id,
|
|
107
107
|
real_name: "张三",
|
|
108
|
-
id_card: "
|
|
108
|
+
id_card: "11010519491231002X",
|
|
109
109
|
certificate_type: 0,
|
|
110
110
|
})
|
|
111
111
|
.then((data) => {
|
package/example/payment.js
CHANGED
|
@@ -18,8 +18,8 @@ payment
|
|
|
18
18
|
dealer_id: config.dealer_id,
|
|
19
19
|
broker_id: config.broker_id,
|
|
20
20
|
real_name: "张三",
|
|
21
|
-
card_no: "
|
|
22
|
-
id_card: "
|
|
21
|
+
card_no: "6228888888888888888",
|
|
22
|
+
id_card: "11010519491231002X",
|
|
23
23
|
pay: "0.01",
|
|
24
24
|
pay_remark: "test",
|
|
25
25
|
notify_url: "https://www.example.com",
|
|
@@ -53,8 +53,8 @@ payment
|
|
|
53
53
|
dealer_id: config.dealer_id,
|
|
54
54
|
broker_id: config.broker_id,
|
|
55
55
|
real_name: "张三",
|
|
56
|
-
card_no: "
|
|
57
|
-
id_card: "
|
|
56
|
+
card_no: "188****8888",
|
|
57
|
+
id_card: "11010519491231002X",
|
|
58
58
|
pay: "0.01",
|
|
59
59
|
check_name: "Check",
|
|
60
60
|
pay_remark: "test",
|
|
@@ -89,8 +89,8 @@ payment
|
|
|
89
89
|
dealer_id: config.dealer_id,
|
|
90
90
|
broker_id: config.broker_id,
|
|
91
91
|
real_name: "张三",
|
|
92
|
-
openid: "
|
|
93
|
-
id_card: "
|
|
92
|
+
openid: "o4GgauInH_RCEdvrrNGrntXDuXXX",
|
|
93
|
+
id_card: "11010519491231002X",
|
|
94
94
|
pay: "0.3",
|
|
95
95
|
wx_app_id: "",
|
|
96
96
|
pay_remark: "test",
|
|
@@ -259,8 +259,8 @@ payment
|
|
|
259
259
|
{
|
|
260
260
|
order_id: "2013011801111",
|
|
261
261
|
real_name: "张三",
|
|
262
|
-
card_no: "
|
|
263
|
-
id_card: "
|
|
262
|
+
card_no: "188****8888",
|
|
263
|
+
id_card: "440524188001010014",
|
|
264
264
|
pay: "0.01",
|
|
265
265
|
pay_remark: "测试订单1",
|
|
266
266
|
notify_url: "https://www.example.com",
|
|
@@ -268,8 +268,8 @@ payment
|
|
|
268
268
|
{
|
|
269
269
|
order_id: "2013011802111",
|
|
270
270
|
real_name: "李四",
|
|
271
|
-
card_no: "
|
|
272
|
-
id_card: "
|
|
271
|
+
card_no: "188****8888",
|
|
272
|
+
id_card: "11010519491231002X",
|
|
273
273
|
pay: "0.01",
|
|
274
274
|
pay_remark: "测试订单2",
|
|
275
275
|
notify_url: "https://www.example.com",
|
package/example/tax.js
CHANGED
|
@@ -17,7 +17,7 @@ uploaduserSign
|
|
|
17
17
|
dealer_id: config.dealer_id,
|
|
18
18
|
broker_id: config.broker_id,
|
|
19
19
|
real_name: "张三",
|
|
20
|
-
id_card: "
|
|
20
|
+
id_card: "11010519491231002X",
|
|
21
21
|
phone: "188****8888",
|
|
22
22
|
is_abroad: false,
|
|
23
23
|
notify_url: "https://www.example.com",
|
|
@@ -49,7 +49,7 @@ uploaduserSign
|
|
|
49
49
|
dealer_id: config.dealer_id,
|
|
50
50
|
broker_id: config.broker_id,
|
|
51
51
|
real_name: "张三",
|
|
52
|
-
id_card: "
|
|
52
|
+
id_card: "11010519491231002X",
|
|
53
53
|
})
|
|
54
54
|
.then((data) => {
|
|
55
55
|
if (data.code === "0000") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yunzhanghu/sdk-nodejs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "云账户 SDK for Node.js",
|
|
5
5
|
"main": "yzh/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -27,8 +27,6 @@
|
|
|
27
27
|
"@types/node": "^18.11.18",
|
|
28
28
|
"@types/urlencode": "^1.1.2",
|
|
29
29
|
"@types/vfile-message": "^2.0.0",
|
|
30
|
-
"@typescript-eslint/eslint-plugin": "^5.50.0",
|
|
31
|
-
"@typescript-eslint/parser": "^5.50.0",
|
|
32
30
|
"@yzh-devkit/eslint-config-lint": "^3.0.6",
|
|
33
31
|
"eslint": "^8.33.0",
|
|
34
32
|
"husky": "^8.0.3",
|
package/src/common/client.ts
CHANGED
|
@@ -72,7 +72,7 @@ export class YZHClient {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// 基础请求:进行请求实例生成 Header,动态设置、请求体包装等偏底层操作
|
|
75
|
-
private
|
|
75
|
+
private doBaseRequest(method: string, action: string, req: any): Promise<ResponseData> {
|
|
76
76
|
const { request_id, ...resReq } = req;
|
|
77
77
|
// 请求参数加密
|
|
78
78
|
const encryptParams = this.generatorRequestParams(resReq);
|
|
@@ -108,7 +108,7 @@ export class YZHClient {
|
|
|
108
108
|
options = {} as any;
|
|
109
109
|
}
|
|
110
110
|
try {
|
|
111
|
-
const result = await this.
|
|
111
|
+
const result = await this.doBaseRequest(method, action, req ?? {});
|
|
112
112
|
// 错误码处理 > 验签 > 解密
|
|
113
113
|
const responseData = await this.parseResponse(result, options?.encryption);
|
|
114
114
|
cb && cb(null, responseData);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import YZHClient from '../../common/client';
|
|
2
|
+
|
|
3
|
+
export class CustomClient extends YZHClient {
|
|
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
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 通用请求函数
|
|
21
|
+
* @param req 请求参数
|
|
22
|
+
* @param url 请求地址
|
|
23
|
+
* @param method 请求方式 'post' | 'get'
|
|
24
|
+
* @param cb
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
public async doRequest<CustomRequest, CustomResponse>(
|
|
28
|
+
req: CustomRequest,
|
|
29
|
+
url: string,
|
|
30
|
+
method: string,
|
|
31
|
+
cb?: (error: null | string, rep: CustomResponse) => void
|
|
32
|
+
): Promise<CustomResponse> {
|
|
33
|
+
const lower_method = method.toLowerCase();
|
|
34
|
+
return this.request(lower_method, url, req, { encryption: false }, cb);
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/services/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { ApiUserSignServiceClient } from './apiusersign';
|
|
|
3
3
|
export { AuthenticationClient } from './authentication';
|
|
4
4
|
export { BizlicXjjH5ServiceClient } from './bizlicxjjh5';
|
|
5
5
|
export { BizlicXjjH5APIServiceClient } from './bizlicxjjh5api';
|
|
6
|
+
export { CustomClient } from './custom';
|
|
6
7
|
export { DataServiceClient } from './dataservice';
|
|
7
8
|
export { H5UserSignServiceClient } from './h5usersign';
|
|
8
9
|
export { InvoiceClient } from './invoice';
|
package/yzh/common/client.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare class YZHClient {
|
|
|
7
7
|
des3_key: string;
|
|
8
8
|
private_key: string;
|
|
9
9
|
yzh_public_key: string;
|
|
10
|
-
sign_type:
|
|
10
|
+
sign_type: 'rsa' | 'sha256';
|
|
11
11
|
base_url?: string;
|
|
12
12
|
timeout?: number;
|
|
13
13
|
/**
|
|
@@ -29,11 +29,11 @@ export declare class YZHClient {
|
|
|
29
29
|
des3_key: string;
|
|
30
30
|
private_key: string;
|
|
31
31
|
yzh_public_key: string;
|
|
32
|
-
sign_type:
|
|
32
|
+
sign_type: 'rsa' | 'sha256';
|
|
33
33
|
base_url?: string;
|
|
34
34
|
timeout?: number;
|
|
35
35
|
});
|
|
36
|
-
private
|
|
36
|
+
private doBaseRequest;
|
|
37
37
|
request(method: string, action: string, req?: any, options?: {
|
|
38
38
|
encryption: boolean;
|
|
39
39
|
}, cb?: ResponseCallback): Promise<ResponseData>;
|
package/yzh/common/client.js
CHANGED
|
@@ -5,8 +5,8 @@ exports.YZHClient = void 0;
|
|
|
5
5
|
const crypto = require("crypto");
|
|
6
6
|
const http_1 = require("../common/http");
|
|
7
7
|
const yzhSDKHttpException_1 = require("./exception/yzhSDKHttpException");
|
|
8
|
-
const clearEncoding =
|
|
9
|
-
const cipherEncoding =
|
|
8
|
+
const clearEncoding = 'utf8';
|
|
9
|
+
const cipherEncoding = 'base64';
|
|
10
10
|
class YZHClient {
|
|
11
11
|
/**
|
|
12
12
|
* 构造函数参数
|
|
@@ -31,7 +31,7 @@ class YZHClient {
|
|
|
31
31
|
this.signRSASHA256 = (data, mess, timestamp) => {
|
|
32
32
|
try {
|
|
33
33
|
const plaintext = `data=${data}&mess=${mess}×tamp=${timestamp}&key=${this.app_key}`;
|
|
34
|
-
const sign = crypto.createSign(
|
|
34
|
+
const sign = crypto.createSign('RSA-SHA256');
|
|
35
35
|
sign.update(plaintext);
|
|
36
36
|
sign.end();
|
|
37
37
|
return sign.sign(this.private_key, cipherEncoding);
|
|
@@ -50,9 +50,9 @@ class YZHClient {
|
|
|
50
50
|
this.signHmacSHA256 = (data, mess, timestamp) => {
|
|
51
51
|
try {
|
|
52
52
|
const plaintext = `data=${data}&mess=${mess}×tamp=${timestamp}&key=${this.app_key}`;
|
|
53
|
-
const hmac = crypto.createHmac(
|
|
53
|
+
const hmac = crypto.createHmac('sha256', this.app_key);
|
|
54
54
|
hmac.update(plaintext);
|
|
55
|
-
return hmac.digest(
|
|
55
|
+
return hmac.digest('hex');
|
|
56
56
|
}
|
|
57
57
|
catch (err) {
|
|
58
58
|
throw new yzhSDKHttpException_1.default(`${err}`);
|
|
@@ -69,10 +69,10 @@ class YZHClient {
|
|
|
69
69
|
this.sign = (data, mess, timestamp) => {
|
|
70
70
|
try {
|
|
71
71
|
switch (this.sign_type) {
|
|
72
|
-
case
|
|
72
|
+
case 'rsa': {
|
|
73
73
|
return this.signRSASHA256(data, mess, timestamp);
|
|
74
74
|
}
|
|
75
|
-
case
|
|
75
|
+
case 'sha256': {
|
|
76
76
|
return this.signHmacSHA256(data, mess, timestamp);
|
|
77
77
|
}
|
|
78
78
|
default:
|
|
@@ -87,7 +87,7 @@ class YZHClient {
|
|
|
87
87
|
// eslint-disable-next-line class-methods-use-this
|
|
88
88
|
this.mess = () => {
|
|
89
89
|
const buf = crypto.randomBytes(16);
|
|
90
|
-
const token = buf.toString(
|
|
90
|
+
const token = buf.toString('hex');
|
|
91
91
|
return token.toString();
|
|
92
92
|
};
|
|
93
93
|
/**
|
|
@@ -99,11 +99,11 @@ class YZHClient {
|
|
|
99
99
|
try {
|
|
100
100
|
const iv = this.des3_key.slice(0, 8);
|
|
101
101
|
const cipherChunks = [];
|
|
102
|
-
const cipher = crypto.createCipheriv(
|
|
102
|
+
const cipher = crypto.createCipheriv('des-ede3-cbc', this.des3_key, iv);
|
|
103
103
|
cipher.setAutoPadding(true);
|
|
104
104
|
cipherChunks.push(cipher.update(plaintext, clearEncoding, cipherEncoding));
|
|
105
105
|
cipherChunks.push(cipher.final(cipherEncoding));
|
|
106
|
-
return cipherChunks.join(
|
|
106
|
+
return cipherChunks.join('');
|
|
107
107
|
}
|
|
108
108
|
catch (err) {
|
|
109
109
|
throw new yzhSDKHttpException_1.default(`${err}`);
|
|
@@ -118,11 +118,11 @@ class YZHClient {
|
|
|
118
118
|
try {
|
|
119
119
|
const iv = this.des3_key.slice(0, 8);
|
|
120
120
|
const cipherChunks = [];
|
|
121
|
-
const decipher = crypto.createDecipheriv(
|
|
121
|
+
const decipher = crypto.createDecipheriv('des-ede3-cbc', this.des3_key, iv);
|
|
122
122
|
decipher.setAutoPadding(true);
|
|
123
123
|
cipherChunks.push(decipher.update(ciphertext, cipherEncoding, clearEncoding));
|
|
124
124
|
cipherChunks.push(decipher.final(clearEncoding));
|
|
125
|
-
return JSON.parse(cipherChunks.join(
|
|
125
|
+
return JSON.parse(cipherChunks.join(''));
|
|
126
126
|
}
|
|
127
127
|
catch (err) {
|
|
128
128
|
throw new yzhSDKHttpException_1.default(`${err}`);
|
|
@@ -139,7 +139,7 @@ class YZHClient {
|
|
|
139
139
|
this.verifyRSASHA256 = (data, mess, timestamp, sign) => {
|
|
140
140
|
try {
|
|
141
141
|
const plaintext = `data=${data}&mess=${mess}×tamp=${timestamp}&key=${this.app_key}`;
|
|
142
|
-
const verify = crypto.createVerify(
|
|
142
|
+
const verify = crypto.createVerify('RSA-SHA256');
|
|
143
143
|
verify.update(plaintext);
|
|
144
144
|
return verify.verify(this.yzh_public_key, sign, cipherEncoding);
|
|
145
145
|
}
|
|
@@ -150,9 +150,9 @@ class YZHClient {
|
|
|
150
150
|
this.verifyHmacSHA256 = (data, mess, timestamp, sign) => {
|
|
151
151
|
try {
|
|
152
152
|
const plaintext = `data=${data}&mess=${mess}×tamp=${timestamp}&key=${this.app_key}`;
|
|
153
|
-
const hmac = crypto.createHmac(
|
|
153
|
+
const hmac = crypto.createHmac('sha256', this.app_key);
|
|
154
154
|
hmac.update(plaintext);
|
|
155
|
-
return hmac.digest(
|
|
155
|
+
return hmac.digest('hex') === sign;
|
|
156
156
|
}
|
|
157
157
|
catch (err) {
|
|
158
158
|
throw new yzhSDKHttpException_1.default(`${err}`);
|
|
@@ -165,12 +165,12 @@ class YZHClient {
|
|
|
165
165
|
*/
|
|
166
166
|
this.filePassWordDecryption = (ciphertextbase64) => {
|
|
167
167
|
try {
|
|
168
|
-
const buff = Buffer.from(ciphertextbase64,
|
|
168
|
+
const buff = Buffer.from(ciphertextbase64, 'base64');
|
|
169
169
|
const decrypted = crypto.privateDecrypt({
|
|
170
170
|
key: this.private_key,
|
|
171
171
|
padding: crypto.constants.RSA_PKCS1_PADDING,
|
|
172
172
|
}, buff);
|
|
173
|
-
return decrypted.toString(
|
|
173
|
+
return decrypted.toString('utf8');
|
|
174
174
|
}
|
|
175
175
|
catch (err) {
|
|
176
176
|
throw new yzhSDKHttpException_1.default(`${err}`);
|
|
@@ -181,7 +181,7 @@ class YZHClient {
|
|
|
181
181
|
* @param responseData 回调返回对象
|
|
182
182
|
* @returns
|
|
183
183
|
*/
|
|
184
|
-
this.notifyDecoder =
|
|
184
|
+
this.notifyDecoder = responseData => {
|
|
185
185
|
const notifyDecoderResult = (data, mess, timestamp, sign) => {
|
|
186
186
|
const verifyMap = {
|
|
187
187
|
rsa: this.verifyRSASHA256,
|
|
@@ -202,17 +202,10 @@ class YZHClient {
|
|
|
202
202
|
if (data && mess && timestamp && sign) {
|
|
203
203
|
return notifyDecoderResult(data, mess, timestamp, sign);
|
|
204
204
|
}
|
|
205
|
-
return { result: false, plaintext:
|
|
205
|
+
return { result: false, plaintext: '' };
|
|
206
206
|
};
|
|
207
207
|
const { dealer_id, broker_id, app_key, des3_key, private_key, yzh_public_key, sign_type } = conf || {};
|
|
208
|
-
if (conf &&
|
|
209
|
-
dealer_id &&
|
|
210
|
-
broker_id &&
|
|
211
|
-
app_key &&
|
|
212
|
-
des3_key &&
|
|
213
|
-
private_key &&
|
|
214
|
-
yzh_public_key &&
|
|
215
|
-
sign_type) {
|
|
208
|
+
if (conf && dealer_id && broker_id && app_key && des3_key && private_key && yzh_public_key && sign_type) {
|
|
216
209
|
this.dealer_id = conf.dealer_id;
|
|
217
210
|
this.broker_id = conf.broker_id;
|
|
218
211
|
this.app_key = conf.app_key;
|
|
@@ -228,7 +221,7 @@ class YZHClient {
|
|
|
228
221
|
}
|
|
229
222
|
}
|
|
230
223
|
// 基础请求:进行请求实例生成 Header,动态设置、请求体包装等偏底层操作
|
|
231
|
-
|
|
224
|
+
doBaseRequest(method, action, req) {
|
|
232
225
|
const { request_id, ...resReq } = req;
|
|
233
226
|
// 请求参数加密
|
|
234
227
|
const encryptParams = this.generatorRequestParams(resReq);
|
|
@@ -242,7 +235,7 @@ class YZHClient {
|
|
|
242
235
|
// 返回请求实例
|
|
243
236
|
const baseInstanceConf = { method, url: action };
|
|
244
237
|
let instanceConf;
|
|
245
|
-
if (method ===
|
|
238
|
+
if (method === 'get') {
|
|
246
239
|
instanceConf = { ...baseInstanceConf, params: encryptParams };
|
|
247
240
|
}
|
|
248
241
|
else {
|
|
@@ -252,12 +245,12 @@ class YZHClient {
|
|
|
252
245
|
}
|
|
253
246
|
// 公共请求:调用封装好的基础请求方法 doRequest,进行发送请求与响应内容处理
|
|
254
247
|
async request(method, action, req, options, cb) {
|
|
255
|
-
if (typeof options ===
|
|
248
|
+
if (typeof options === 'function') {
|
|
256
249
|
cb = options;
|
|
257
250
|
options = {};
|
|
258
251
|
}
|
|
259
252
|
try {
|
|
260
|
-
const result = await this.
|
|
253
|
+
const result = await this.doBaseRequest(method, action, req !== null && req !== void 0 ? req : {});
|
|
261
254
|
// 错误码处理 > 验签 > 解密
|
|
262
255
|
const responseData = await this.parseResponse(result, options === null || options === void 0 ? void 0 : options.encryption);
|
|
263
256
|
cb && cb(null, responseData);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
class YZHSDKHttpException extends Error {
|
|
4
|
-
constructor(error, request_id =
|
|
4
|
+
constructor(error, request_id = '') {
|
|
5
5
|
super(error);
|
|
6
|
-
this.request_id = request_id ||
|
|
6
|
+
this.request_id = request_id || '';
|
|
7
7
|
}
|
|
8
8
|
getMessage() {
|
|
9
9
|
return this.message;
|
package/yzh/common/http/index.js
CHANGED
|
@@ -3,17 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const axios_1 = require("axios");
|
|
4
4
|
const urlencode = require("urlencode");
|
|
5
5
|
const pkg = require("../../../package.json");
|
|
6
|
-
const JsonBigString = require(
|
|
7
|
-
const BASE_URL =
|
|
6
|
+
const JsonBigString = require('json-bigint')({ storeAsString: true });
|
|
7
|
+
const BASE_URL = 'https://api-service.yunzhanghu.com/';
|
|
8
8
|
const getInstance = (config = {}) => {
|
|
9
9
|
var _a;
|
|
10
10
|
const instance = axios_1.default.create({
|
|
11
11
|
baseURL: config.base_url || BASE_URL,
|
|
12
12
|
headers: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
'request-id': config === null || config === void 0 ? void 0 : config.request_id,
|
|
14
|
+
'dealer-id': config === null || config === void 0 ? void 0 : config.dealer_id,
|
|
15
|
+
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
|
16
|
+
'User-Agent': `yunzhanghu-sdk-nodejs/${pkg.version}/${process.version}`,
|
|
17
17
|
},
|
|
18
18
|
timeout: (_a = config.timeout) !== null && _a !== void 0 ? _a : 30 * 1000,
|
|
19
19
|
transformResponse: [
|
|
@@ -29,9 +29,9 @@ const getInstance = (config = {}) => {
|
|
|
29
29
|
],
|
|
30
30
|
});
|
|
31
31
|
// 拦截器
|
|
32
|
-
instance.interceptors.request.use(
|
|
32
|
+
instance.interceptors.request.use(config => {
|
|
33
33
|
// URL Encode
|
|
34
|
-
if (config.method ===
|
|
34
|
+
if (config.method === 'get') {
|
|
35
35
|
const { params: urlData } = config;
|
|
36
36
|
const { data, sign, ...resData } = urlData;
|
|
37
37
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -43,7 +43,7 @@ const getInstance = (config = {}) => {
|
|
|
43
43
|
}
|
|
44
44
|
return config;
|
|
45
45
|
});
|
|
46
|
-
instance.interceptors.response.use(
|
|
46
|
+
instance.interceptors.response.use(response => {
|
|
47
47
|
const { data } = response;
|
|
48
48
|
if (data) {
|
|
49
49
|
const { request_id, requestID, ...resResponse } = data;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import YZHclient from
|
|
1
|
+
import YZHclient from '../client';
|
|
2
2
|
export declare class Util extends YZHclient {
|
|
3
3
|
constructor(conf: {
|
|
4
4
|
dealer_id: string;
|
|
@@ -7,7 +7,7 @@ export declare class Util extends YZHclient {
|
|
|
7
7
|
des3_key: string;
|
|
8
8
|
private_key: string;
|
|
9
9
|
yzh_public_key: string;
|
|
10
|
-
sign_type:
|
|
10
|
+
sign_type: 'rsa' | 'sha256';
|
|
11
11
|
base_url?: string;
|
|
12
12
|
timeout?: number;
|
|
13
13
|
});
|
package/yzh/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './services';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import YZHClient from '../../common/client';
|
|
2
|
+
export declare class CustomClient extends YZHClient {
|
|
3
|
+
constructor(conf: {
|
|
4
|
+
dealer_id: string;
|
|
5
|
+
broker_id: string;
|
|
6
|
+
app_key: string;
|
|
7
|
+
des3_key: string;
|
|
8
|
+
private_key: string;
|
|
9
|
+
yzh_public_key: string;
|
|
10
|
+
sign_type: 'rsa' | 'sha256';
|
|
11
|
+
base_url?: string;
|
|
12
|
+
timeout?: number;
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* 通用请求函数
|
|
16
|
+
* @param req 请求参数
|
|
17
|
+
* @param url 请求地址
|
|
18
|
+
* @param method 请求方式 'post' | 'get'
|
|
19
|
+
* @param cb
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
doRequest<CustomRequest, CustomResponse>(
|
|
23
|
+
req: CustomRequest,
|
|
24
|
+
url: string,
|
|
25
|
+
method: string,
|
|
26
|
+
cb?: (error: null | string, rep: CustomResponse) => void
|
|
27
|
+
): Promise<CustomResponse>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.CustomClient = void 0;
|
|
4
|
+
const client_1 = require('../../common/client');
|
|
5
|
+
class CustomClient extends client_1.default {
|
|
6
|
+
// eslint-disable-next-line no-useless-constructor
|
|
7
|
+
constructor(conf) {
|
|
8
|
+
super(conf);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 通用请求函数
|
|
12
|
+
* @param req 请求参数
|
|
13
|
+
* @param url 请求地址
|
|
14
|
+
* @param method 请求方式 'post' | 'get'
|
|
15
|
+
* @param cb
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
async doRequest(req, url, method, cb) {
|
|
19
|
+
const lower_method = method.toLowerCase();
|
|
20
|
+
return this.request(lower_method, url, req, { encryption: false }, cb);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.CustomClient = CustomClient;
|
package/yzh/services/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
export { Util } from
|
|
2
|
-
export { ApiUserSignServiceClient } from
|
|
3
|
-
export { AuthenticationClient } from
|
|
4
|
-
export { BizlicXjjH5ServiceClient } from
|
|
5
|
-
export { BizlicXjjH5APIServiceClient } from
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
1
|
+
export { Util } from '../common/utils';
|
|
2
|
+
export { ApiUserSignServiceClient } from './apiusersign';
|
|
3
|
+
export { AuthenticationClient } from './authentication';
|
|
4
|
+
export { BizlicXjjH5ServiceClient } from './bizlicxjjh5';
|
|
5
|
+
export { BizlicXjjH5APIServiceClient } from './bizlicxjjh5api';
|
|
6
|
+
export { CustomClient } from './custom';
|
|
7
|
+
export { DataServiceClient } from './dataservice';
|
|
8
|
+
export { H5UserSignServiceClient } from './h5usersign';
|
|
9
|
+
export { InvoiceClient } from './invoice';
|
|
10
|
+
export { PaymentClient } from './payment';
|
|
11
|
+
export { TaxClient } from './tax';
|
|
12
|
+
export { UploadUserSignServiceClient } from './uploadusersign';
|
package/yzh/services/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UploadUserSignServiceClient = exports.TaxClient = exports.PaymentClient = exports.InvoiceClient = exports.H5UserSignServiceClient = exports.DataServiceClient = exports.BizlicXjjH5APIServiceClient = exports.BizlicXjjH5ServiceClient = exports.AuthenticationClient = exports.ApiUserSignServiceClient = exports.Util = void 0;
|
|
3
|
+
exports.UploadUserSignServiceClient = exports.TaxClient = exports.PaymentClient = exports.InvoiceClient = exports.H5UserSignServiceClient = exports.DataServiceClient = exports.CustomClient = exports.BizlicXjjH5APIServiceClient = exports.BizlicXjjH5ServiceClient = exports.AuthenticationClient = exports.ApiUserSignServiceClient = exports.Util = void 0;
|
|
4
4
|
var utils_1 = require("../common/utils");
|
|
5
5
|
Object.defineProperty(exports, "Util", { enumerable: true, get: function () { return utils_1.Util; } });
|
|
6
6
|
var apiusersign_1 = require("./apiusersign");
|
|
@@ -11,6 +11,8 @@ var bizlicxjjh5_1 = require("./bizlicxjjh5");
|
|
|
11
11
|
Object.defineProperty(exports, "BizlicXjjH5ServiceClient", { enumerable: true, get: function () { return bizlicxjjh5_1.BizlicXjjH5ServiceClient; } });
|
|
12
12
|
var bizlicxjjh5api_1 = require("./bizlicxjjh5api");
|
|
13
13
|
Object.defineProperty(exports, "BizlicXjjH5APIServiceClient", { enumerable: true, get: function () { return bizlicxjjh5api_1.BizlicXjjH5APIServiceClient; } });
|
|
14
|
+
var custom_1 = require("./custom");
|
|
15
|
+
Object.defineProperty(exports, "CustomClient", { enumerable: true, get: function () { return custom_1.CustomClient; } });
|
|
14
16
|
var dataservice_1 = require("./dataservice");
|
|
15
17
|
Object.defineProperty(exports, "DataServiceClient", { enumerable: true, get: function () { return dataservice_1.DataServiceClient; } });
|
|
16
18
|
var h5usersign_1 = require("./h5usersign");
|