@yunzhanghu/sdk-nodejs 0.0.1-beta.1
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 +4 -0
- package/.eslintrc.json +19 -0
- package/.husky/pre-commit +7 -0
- package/LICENSE +201 -0
- package/README.md +114 -0
- package/example/apiUserSign.js +70 -0
- package/example/authentication.js +142 -0
- package/example/bizlicXjjH5.js +46 -0
- package/example/bizlicXjjH5Api.js +65 -0
- package/example/conf/config.js +30 -0
- package/example/dataService.js +98 -0
- package/example/h5UserSign.js +68 -0
- package/example/invoice.js +91 -0
- package/example/notify.js +36 -0
- package/example/package.json +12 -0
- package/example/payment.js +186 -0
- package/example/tax.js +34 -0
- package/package.json +47 -0
- package/prettier.config.js +32 -0
- package/src/common/client.ts +367 -0
- package/src/common/exception/yzhSDKHttpException.ts +32 -0
- package/src/common/http/index.ts +57 -0
- package/src/common/utils/index.ts +18 -0
- package/src/index.ts +1 -0
- package/src/services/apiusersign/index.ts +125 -0
- package/src/services/authentication/index.ts +247 -0
- package/src/services/bizlicxjjh5/index.ts +129 -0
- package/src/services/bizlicxjjh5api/index.ts +169 -0
- package/src/services/dataservice/index.ts +315 -0
- package/src/services/h5usersign/index.ts +145 -0
- package/src/services/index.ts +10 -0
- package/src/services/invoice/index.ts +257 -0
- package/src/services/payment/index.ts +523 -0
- package/src/services/tax/index.ts +77 -0
- package/src/typings.d.ts +1 -0
- package/tsconfig.json +25 -0
- package/yzh/common/client.d.ts +119 -0
- package/yzh/common/client.js +314 -0
- package/yzh/common/exception/yzhSDKHttpException.d.ts +10 -0
- package/yzh/common/exception/yzhSDKHttpException.js +21 -0
- package/yzh/common/http/index.d.ts +6 -0
- package/yzh/common/http/index.js +51 -0
- package/yzh/common/utils/index.d.ts +14 -0
- package/yzh/common/utils/index.js +11 -0
- package/yzh/index.d.ts +1 -0
- package/yzh/index.js +4 -0
- package/yzh/services/apiusersign/index.d.ts +86 -0
- package/yzh/services/apiusersign/index.js +26 -0
- package/yzh/services/authentication/index.d.ts +153 -0
- package/yzh/services/authentication/index.js +42 -0
- package/yzh/services/bizlicxjjh5/index.d.ts +76 -0
- package/yzh/services/bizlicxjjh5/index.js +18 -0
- package/yzh/services/bizlicxjjh5api/index.d.ts +107 -0
- package/yzh/services/bizlicxjjh5api/index.js +22 -0
- package/yzh/services/dataservice/index.d.ts +243 -0
- package/yzh/services/dataservice/index.js +38 -0
- package/yzh/services/h5usersign/index.d.ts +90 -0
- package/yzh/services/h5usersign/index.js +26 -0
- package/yzh/services/index.d.ts +10 -0
- package/yzh/services/index.js +23 -0
- package/yzh/services/invoice/index.d.ts +158 -0
- package/yzh/services/invoice/index.js +34 -0
- package/yzh/services/payment/index.d.ts +358 -0
- package/yzh/services/payment/index.js +50 -0
- package/yzh/services/tax/index.d.ts +55 -0
- package/yzh/services/tax/index.js +18 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
export type ResponseCallback<TReuslt = any> = (error: null | string, rep: TReuslt) => void;
|
|
2
|
+
type ResponseData = any;
|
|
3
|
+
export declare class YZHClient {
|
|
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
|
+
/**
|
|
13
|
+
* 构造函数参数
|
|
14
|
+
* @param {string} dealer_id 平台企业 ID
|
|
15
|
+
* @param {string} broker_id 综合服务主体 ID
|
|
16
|
+
* @param {string} app_key App Key
|
|
17
|
+
* @param {string} des3_key 3DES Key
|
|
18
|
+
* @param {string} private_key 平台企业私钥
|
|
19
|
+
* @param {string} yzh_public_key 云账户公钥
|
|
20
|
+
* @param {string} sign_type 签名方式"rsa" | "sha256"
|
|
21
|
+
* @param {string} base_url 可选,默认为 https://api-service.yunzhanghu.com/
|
|
22
|
+
*/
|
|
23
|
+
constructor(conf: {
|
|
24
|
+
dealer_id: string;
|
|
25
|
+
broker_id: string;
|
|
26
|
+
app_key: string;
|
|
27
|
+
des3_key: string;
|
|
28
|
+
private_key: string;
|
|
29
|
+
yzh_public_key: string;
|
|
30
|
+
sign_type: "rsa" | "sha256";
|
|
31
|
+
base_url?: string;
|
|
32
|
+
});
|
|
33
|
+
private doRequest;
|
|
34
|
+
request(method: string, action: string, req?: any, options?: {
|
|
35
|
+
encryption: boolean;
|
|
36
|
+
}, cb?: ResponseCallback): Promise<ResponseData>;
|
|
37
|
+
/**
|
|
38
|
+
* 请求参数加密
|
|
39
|
+
* @param {object} params
|
|
40
|
+
* @returns {*} object
|
|
41
|
+
*/
|
|
42
|
+
private generatorResquestParams;
|
|
43
|
+
/**
|
|
44
|
+
* 生成签名(RSA-SHA256)
|
|
45
|
+
* @param {string} data 经过加密后的具体数据
|
|
46
|
+
* @param {string} mess 自定义随机字符串,用于签名
|
|
47
|
+
* @param {string} timestamp 时间戳,精确到秒
|
|
48
|
+
* @returns {string} 签名内容
|
|
49
|
+
*/
|
|
50
|
+
private generatorSignRSASHA256;
|
|
51
|
+
/**
|
|
52
|
+
* 生成签名(HmacSHA256)
|
|
53
|
+
* @param {string} data 经过加密后的具体数据
|
|
54
|
+
* @param {string} mess 自定义随机字符串,用于签名
|
|
55
|
+
* @param {string} timestamp 时间戳,精确到秒
|
|
56
|
+
* @returns {string} 签名内容
|
|
57
|
+
*/
|
|
58
|
+
private generatorSignHmacSHA256;
|
|
59
|
+
/**
|
|
60
|
+
* 生成签名
|
|
61
|
+
* @param {string} data 经过加密后的具体数据
|
|
62
|
+
* @param {string} mess 自定义随机字符串,用于签名
|
|
63
|
+
* @param {string} timestamp 时间戳,精确到秒
|
|
64
|
+
* @param {string} sign_type 签名方式
|
|
65
|
+
* @returns {string} 签名内容
|
|
66
|
+
*/
|
|
67
|
+
private generatorSign;
|
|
68
|
+
private mess;
|
|
69
|
+
/**
|
|
70
|
+
* 3DES 加密数据
|
|
71
|
+
* @param plaintext
|
|
72
|
+
* @returns 字符串加密数据
|
|
73
|
+
*/
|
|
74
|
+
private encrypt;
|
|
75
|
+
private parseResponse;
|
|
76
|
+
/**
|
|
77
|
+
* 3DES 解密数据
|
|
78
|
+
* @param ciphertext
|
|
79
|
+
* @returns 明文数据
|
|
80
|
+
*/
|
|
81
|
+
decryption: (ciphertext: string) => any;
|
|
82
|
+
/**
|
|
83
|
+
* 验签
|
|
84
|
+
* @param {string} data 返回的数据
|
|
85
|
+
* @param {string} mess 返回的随机字符串
|
|
86
|
+
* @param {string} timestamp 返回的时间戳
|
|
87
|
+
* @param {string} sign 返回的签名
|
|
88
|
+
* @returns {boolean} true:验签成功;false:验签失败
|
|
89
|
+
*/
|
|
90
|
+
verifyRSASHA256: (data: string, mess: string, timestamp: string, sign: string) => boolean;
|
|
91
|
+
verifyHmacSHA256: (data: string, mess: string, timestamp: string, sign: string) => boolean;
|
|
92
|
+
/**
|
|
93
|
+
* 文件密码解密
|
|
94
|
+
* @param ciphertextbase64
|
|
95
|
+
* @returns 解密后的密码
|
|
96
|
+
*/
|
|
97
|
+
filePassWordDecryption: (ciphertextbase64: string) => string;
|
|
98
|
+
/**
|
|
99
|
+
* 验签+解密
|
|
100
|
+
* @param responseData 回调返回对象
|
|
101
|
+
* @returns
|
|
102
|
+
*/
|
|
103
|
+
notifyDecoder: (params: {
|
|
104
|
+
/** 返回的数据 */
|
|
105
|
+
data: string;
|
|
106
|
+
/** 返回的随机字符串 */
|
|
107
|
+
mess: string;
|
|
108
|
+
/** 返回的时间戳 */
|
|
109
|
+
timestamp: string;
|
|
110
|
+
/** 返回的签名 */
|
|
111
|
+
sign: string;
|
|
112
|
+
}) => {
|
|
113
|
+
/** 验签结果 */
|
|
114
|
+
result: boolean;
|
|
115
|
+
/** 解密结果 */
|
|
116
|
+
plaintext: object;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
export default YZHClient;
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.YZHClient = void 0;
|
|
4
|
+
const http_1 = require("../common/http");
|
|
5
|
+
const crypto = require("crypto");
|
|
6
|
+
const yzhSDKHttpException_1 = require("./exception/yzhSDKHttpException");
|
|
7
|
+
const clearEncoding = "utf8";
|
|
8
|
+
const cipherEncoding = "base64";
|
|
9
|
+
class YZHClient {
|
|
10
|
+
/**
|
|
11
|
+
* 构造函数参数
|
|
12
|
+
* @param {string} dealer_id 平台企业 ID
|
|
13
|
+
* @param {string} broker_id 综合服务主体 ID
|
|
14
|
+
* @param {string} app_key App Key
|
|
15
|
+
* @param {string} des3_key 3DES Key
|
|
16
|
+
* @param {string} private_key 平台企业私钥
|
|
17
|
+
* @param {string} yzh_public_key 云账户公钥
|
|
18
|
+
* @param {string} sign_type 签名方式"rsa" | "sha256"
|
|
19
|
+
* @param {string} base_url 可选,默认为 https://api-service.yunzhanghu.com/
|
|
20
|
+
*/
|
|
21
|
+
constructor(conf) {
|
|
22
|
+
/**
|
|
23
|
+
* 生成签名(RSA-SHA256)
|
|
24
|
+
* @param {string} data 经过加密后的具体数据
|
|
25
|
+
* @param {string} mess 自定义随机字符串,用于签名
|
|
26
|
+
* @param {string} timestamp 时间戳,精确到秒
|
|
27
|
+
* @returns {string} 签名内容
|
|
28
|
+
*/
|
|
29
|
+
this.generatorSignRSASHA256 = (data, mess, timestamp) => {
|
|
30
|
+
try {
|
|
31
|
+
const plaintext = `data=${data}&mess=${mess}×tamp=${timestamp}&key=${this.app_key}`;
|
|
32
|
+
const sign = crypto.createSign("RSA-SHA256");
|
|
33
|
+
sign.update(plaintext);
|
|
34
|
+
sign.end();
|
|
35
|
+
return sign.sign(this.private_key, cipherEncoding);
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
throw new yzhSDKHttpException_1.default(`${err}`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* 生成签名(HmacSHA256)
|
|
43
|
+
* @param {string} data 经过加密后的具体数据
|
|
44
|
+
* @param {string} mess 自定义随机字符串,用于签名
|
|
45
|
+
* @param {string} timestamp 时间戳,精确到秒
|
|
46
|
+
* @returns {string} 签名内容
|
|
47
|
+
*/
|
|
48
|
+
this.generatorSignHmacSHA256 = (data, mess, timestamp) => {
|
|
49
|
+
try {
|
|
50
|
+
const plaintext = `data=${data}&mess=${mess}×tamp=${timestamp}&key=${this.app_key}`;
|
|
51
|
+
const hmac = crypto.createHmac("sha256", this.app_key);
|
|
52
|
+
hmac.update(plaintext);
|
|
53
|
+
return hmac.digest("hex");
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
throw new yzhSDKHttpException_1.default(`${err}`);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* 生成签名
|
|
61
|
+
* @param {string} data 经过加密后的具体数据
|
|
62
|
+
* @param {string} mess 自定义随机字符串,用于签名
|
|
63
|
+
* @param {string} timestamp 时间戳,精确到秒
|
|
64
|
+
* @param {string} sign_type 签名方式
|
|
65
|
+
* @returns {string} 签名内容
|
|
66
|
+
*/
|
|
67
|
+
this.generatorSign = (data, mess, timestamp) => {
|
|
68
|
+
try {
|
|
69
|
+
switch (this.sign_type) {
|
|
70
|
+
case "rsa": {
|
|
71
|
+
return this.generatorSignRSASHA256(data, mess, timestamp);
|
|
72
|
+
}
|
|
73
|
+
case "sha256": {
|
|
74
|
+
return this.generatorSignHmacSHA256(data, mess, timestamp);
|
|
75
|
+
}
|
|
76
|
+
default:
|
|
77
|
+
throw new yzhSDKHttpException_1.default(`sign_type类型不存在`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
throw new yzhSDKHttpException_1.default(`${err}`);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
// 自定义随机字符串
|
|
85
|
+
this.mess = () => {
|
|
86
|
+
const buf = crypto.randomBytes(16);
|
|
87
|
+
const token = buf.toString("hex");
|
|
88
|
+
return token.toString();
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* 3DES 加密数据
|
|
92
|
+
* @param plaintext
|
|
93
|
+
* @returns 字符串加密数据
|
|
94
|
+
*/
|
|
95
|
+
this.encrypt = (plaintext) => {
|
|
96
|
+
try {
|
|
97
|
+
const iv = this.des3_key.slice(0, 8);
|
|
98
|
+
const cipherChunks = [];
|
|
99
|
+
const cipher = crypto.createCipheriv("des-ede3-cbc", this.des3_key, iv);
|
|
100
|
+
cipher.setAutoPadding(true);
|
|
101
|
+
cipherChunks.push(cipher.update(plaintext, clearEncoding, cipherEncoding));
|
|
102
|
+
cipherChunks.push(cipher.final(cipherEncoding));
|
|
103
|
+
return cipherChunks.join("");
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
throw new yzhSDKHttpException_1.default(`${err}`);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* 3DES 解密数据
|
|
111
|
+
* @param ciphertext
|
|
112
|
+
* @returns 明文数据
|
|
113
|
+
*/
|
|
114
|
+
this.decryption = (ciphertext) => {
|
|
115
|
+
try {
|
|
116
|
+
const iv = this.des3_key.slice(0, 8);
|
|
117
|
+
const cipherChunks = [];
|
|
118
|
+
const decipher = crypto.createDecipheriv("des-ede3-cbc", this.des3_key, iv);
|
|
119
|
+
decipher.setAutoPadding(true);
|
|
120
|
+
cipherChunks.push(decipher.update(ciphertext, cipherEncoding, clearEncoding));
|
|
121
|
+
cipherChunks.push(decipher.final(clearEncoding));
|
|
122
|
+
return JSON.parse(cipherChunks.join(""));
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
throw new yzhSDKHttpException_1.default(`${err}`);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* 验签
|
|
130
|
+
* @param {string} data 返回的数据
|
|
131
|
+
* @param {string} mess 返回的随机字符串
|
|
132
|
+
* @param {string} timestamp 返回的时间戳
|
|
133
|
+
* @param {string} sign 返回的签名
|
|
134
|
+
* @returns {boolean} true:验签成功;false:验签失败
|
|
135
|
+
*/
|
|
136
|
+
this.verifyRSASHA256 = (data, mess, timestamp, sign) => {
|
|
137
|
+
try {
|
|
138
|
+
const plaintext = `data=${data}&mess=${mess}×tamp=${timestamp}&key=${this.app_key}`;
|
|
139
|
+
const verify = crypto.createVerify("RSA-SHA256");
|
|
140
|
+
verify.update(plaintext);
|
|
141
|
+
return verify.verify(this.yzh_public_key, sign, cipherEncoding);
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
throw new yzhSDKHttpException_1.default(`${err}`);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
this.verifyHmacSHA256 = (data, mess, timestamp, sign) => {
|
|
148
|
+
try {
|
|
149
|
+
const plaintext = `data=${data}&mess=${mess}×tamp=${timestamp}&key=${this.app_key}`;
|
|
150
|
+
const hmac = crypto.createHmac("sha256", this.app_key);
|
|
151
|
+
hmac.update(plaintext);
|
|
152
|
+
return hmac.digest("hex") === sign;
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
throw new yzhSDKHttpException_1.default(`${err}`);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* 文件密码解密
|
|
160
|
+
* @param ciphertextbase64
|
|
161
|
+
* @returns 解密后的密码
|
|
162
|
+
*/
|
|
163
|
+
this.filePassWordDecryption = (ciphertextbase64) => {
|
|
164
|
+
try {
|
|
165
|
+
const buff = Buffer.from(ciphertextbase64, "base64");
|
|
166
|
+
const decrypted = crypto.privateDecrypt({
|
|
167
|
+
key: this.private_key,
|
|
168
|
+
padding: crypto.constants.RSA_PKCS1_PADDING,
|
|
169
|
+
}, buff);
|
|
170
|
+
return decrypted.toString("utf8");
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
throw new yzhSDKHttpException_1.default(`${err}`);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* 验签+解密
|
|
178
|
+
* @param responseData 回调返回对象
|
|
179
|
+
* @returns
|
|
180
|
+
*/
|
|
181
|
+
this.notifyDecoder = (responseData) => {
|
|
182
|
+
const notifyDecoderResult = (data, mess, timestamp, sign) => {
|
|
183
|
+
const verifyMap = {
|
|
184
|
+
rsa: this.verifyRSASHA256,
|
|
185
|
+
sha256: this.verifyHmacSHA256,
|
|
186
|
+
};
|
|
187
|
+
// 验签结果 boolean
|
|
188
|
+
const verifyResult = verifyMap[this.sign_type](data, mess, timestamp, sign);
|
|
189
|
+
let plaintext = {};
|
|
190
|
+
if (verifyResult) {
|
|
191
|
+
plaintext = this.decryption(data);
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
result: verifyResult,
|
|
195
|
+
plaintext,
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
const { data, mess, timestamp, sign } = responseData !== null && responseData !== void 0 ? responseData : {};
|
|
199
|
+
if (data && mess && timestamp && sign) {
|
|
200
|
+
return notifyDecoderResult(data, mess, timestamp, sign);
|
|
201
|
+
}
|
|
202
|
+
return { result: false, plaintext: "" };
|
|
203
|
+
};
|
|
204
|
+
const { dealer_id, broker_id, app_key, des3_key, private_key, yzh_public_key, sign_type } = conf || {};
|
|
205
|
+
if (conf &&
|
|
206
|
+
dealer_id &&
|
|
207
|
+
broker_id &&
|
|
208
|
+
app_key &&
|
|
209
|
+
des3_key &&
|
|
210
|
+
private_key &&
|
|
211
|
+
yzh_public_key &&
|
|
212
|
+
sign_type) {
|
|
213
|
+
this.dealer_id = conf.dealer_id;
|
|
214
|
+
this.broker_id = conf.broker_id;
|
|
215
|
+
this.app_key = conf.app_key;
|
|
216
|
+
this.des3_key = conf.des3_key;
|
|
217
|
+
this.private_key = conf.private_key;
|
|
218
|
+
this.yzh_public_key = conf.yzh_public_key;
|
|
219
|
+
this.sign_type = conf.sign_type;
|
|
220
|
+
this.base_url = conf === null || conf === void 0 ? void 0 : conf.base_url;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
throw new yzhSDKHttpException_1.default(`实例初始化失败,请检查以下配置是否缺失:\ndealer_id、broker_id、app_key、des3_key、private_key、yzh_public_key、sign_type`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
// 基础请求:进行请求实例生成 Header,动态设置、请求体包装等偏底层操作
|
|
227
|
+
doRequest(method, action, req) {
|
|
228
|
+
var _a;
|
|
229
|
+
// 请求参数加密
|
|
230
|
+
const encryptParams = this.generatorResquestParams(req);
|
|
231
|
+
// 生成请求实例,配置 Header
|
|
232
|
+
const instance = (0, http_1.default)({
|
|
233
|
+
request_id: (_a = req === null || req === void 0 ? void 0 : req.request_id) !== null && _a !== void 0 ? _a : this.mess(),
|
|
234
|
+
dealer_id: this.dealer_id,
|
|
235
|
+
base_url: this.base_url,
|
|
236
|
+
});
|
|
237
|
+
// 返回请求实例
|
|
238
|
+
const baseInstanceConf = { method: method, url: action };
|
|
239
|
+
let instanceConf;
|
|
240
|
+
if (method === "get") {
|
|
241
|
+
instanceConf = { ...baseInstanceConf, params: encryptParams };
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
instanceConf = { ...baseInstanceConf, data: encryptParams };
|
|
245
|
+
}
|
|
246
|
+
return instance(instanceConf);
|
|
247
|
+
}
|
|
248
|
+
// 公共请求:调用封装好的基础请求方法 doRequest,进行发送请求与响应内容处理
|
|
249
|
+
async request(method, action, req, options, cb) {
|
|
250
|
+
if (typeof options === "function") {
|
|
251
|
+
cb = options;
|
|
252
|
+
options = {};
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
const result = await this.doRequest(method, action, req !== null && req !== void 0 ? req : {});
|
|
256
|
+
// 错误码处理 > 验签 > 解密
|
|
257
|
+
const responseData = await this.parseResponse(result, options === null || options === void 0 ? void 0 : options.encryption);
|
|
258
|
+
cb && cb(null, responseData);
|
|
259
|
+
return responseData;
|
|
260
|
+
}
|
|
261
|
+
catch (e) {
|
|
262
|
+
if (cb) {
|
|
263
|
+
cb(e, null);
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
throw e;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* 请求参数加密
|
|
272
|
+
* @param {object} params
|
|
273
|
+
* @returns {*} object
|
|
274
|
+
*/
|
|
275
|
+
generatorResquestParams(params) {
|
|
276
|
+
try {
|
|
277
|
+
const t = Date.now().toString();
|
|
278
|
+
const m = this.mess();
|
|
279
|
+
const plaintext = JSON.stringify(params);
|
|
280
|
+
const data = this.encrypt(plaintext);
|
|
281
|
+
const signStr = this.generatorSign(data, m, t);
|
|
282
|
+
return {
|
|
283
|
+
data,
|
|
284
|
+
mess: m,
|
|
285
|
+
timestamp: t,
|
|
286
|
+
sign: signStr,
|
|
287
|
+
sign_type: this.sign_type,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
catch (err) {
|
|
291
|
+
throw new yzhSDKHttpException_1.default(`${err}`);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
// 返回处理结果
|
|
295
|
+
async parseResponse(result, encryption) {
|
|
296
|
+
if (result.status !== 200) {
|
|
297
|
+
const yzhError = new yzhSDKHttpException_1.default(result.statusText);
|
|
298
|
+
yzhError.httpCode = result.status;
|
|
299
|
+
throw yzhError;
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
// httpcode 200
|
|
303
|
+
const { data: axiosData } = result;
|
|
304
|
+
let response = axiosData;
|
|
305
|
+
// 需解密
|
|
306
|
+
if (encryption) {
|
|
307
|
+
response = { ...response, data: this.decryption(response.data) };
|
|
308
|
+
}
|
|
309
|
+
return response;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
exports.YZHClient = YZHClient;
|
|
314
|
+
exports.default = YZHClient;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default class YZHSDKHttpException extends Error {
|
|
2
|
+
request_id: string;
|
|
3
|
+
httpCode?: number;
|
|
4
|
+
code?: string;
|
|
5
|
+
constructor(error: string, request_id?: string);
|
|
6
|
+
getMessage(): string;
|
|
7
|
+
getRequestId(): string;
|
|
8
|
+
toString(): string;
|
|
9
|
+
toLocaleString(): string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class YZHSDKHttpException extends Error {
|
|
4
|
+
constructor(error, request_id = "") {
|
|
5
|
+
super(error);
|
|
6
|
+
this.request_id = request_id || "";
|
|
7
|
+
}
|
|
8
|
+
getMessage() {
|
|
9
|
+
return this.message;
|
|
10
|
+
}
|
|
11
|
+
getRequestId() {
|
|
12
|
+
return this.request_id;
|
|
13
|
+
}
|
|
14
|
+
toString() {
|
|
15
|
+
return `[yzh_sdk_exception] ${this.code && `code:${this.code}`} requestId:${this.getRequestId()} message:${this.getMessage()}`;
|
|
16
|
+
}
|
|
17
|
+
toLocaleString() {
|
|
18
|
+
return `[yzh_sdk_exception] ${this.code && `code:${this.code}`} requestId:${this.getRequestId()} message:${this.getMessage()}`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = YZHSDKHttpException;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const axios_1 = require("axios");
|
|
4
|
+
const urlencode = require("urlencode");
|
|
5
|
+
const pkg = require("../../../package.json");
|
|
6
|
+
const child_process = require("child_process");
|
|
7
|
+
const BASE_URL = "https://api-service.yunzhanghu.com/";
|
|
8
|
+
const getInstance = (config = {}) => {
|
|
9
|
+
const instance = axios_1.default.create({
|
|
10
|
+
baseURL: config.base_url || BASE_URL,
|
|
11
|
+
headers: {
|
|
12
|
+
"request-id": config === null || config === void 0 ? void 0 : config.request_id,
|
|
13
|
+
"dealer-id": config === null || config === void 0 ? void 0 : config.dealer_id,
|
|
14
|
+
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
|
15
|
+
"User-Agent": `yunzhanghu-sdk-nodejs/${pkg.version}/${child_process
|
|
16
|
+
.execSync("uname -m -r -s")
|
|
17
|
+
.toString("utf-8")
|
|
18
|
+
.replace("\n", "")}/${process.version}`,
|
|
19
|
+
},
|
|
20
|
+
timeout: 30 * 1000,
|
|
21
|
+
});
|
|
22
|
+
// 拦截器
|
|
23
|
+
instance.interceptors.request.use(function (config) {
|
|
24
|
+
// URL Encode
|
|
25
|
+
if (config.method === "get") {
|
|
26
|
+
const { params: urlData } = config;
|
|
27
|
+
const { data, sign, ...resData } = urlData;
|
|
28
|
+
config.data = {
|
|
29
|
+
data: urlencode(data),
|
|
30
|
+
sign: urlencode(sign),
|
|
31
|
+
...resData,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return config;
|
|
35
|
+
});
|
|
36
|
+
instance.interceptors.response.use(function (response) {
|
|
37
|
+
const { data } = response;
|
|
38
|
+
if (data) {
|
|
39
|
+
const { request_id, requestID, ...resResponse } = data;
|
|
40
|
+
if (request_id || requestID) {
|
|
41
|
+
response.data = {
|
|
42
|
+
...resResponse,
|
|
43
|
+
request_id: request_id || requestID,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return response;
|
|
48
|
+
});
|
|
49
|
+
return instance;
|
|
50
|
+
};
|
|
51
|
+
exports.default = getInstance;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import YZHclient from "../client";
|
|
2
|
+
export declare class Util 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
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export default Util;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Util = void 0;
|
|
4
|
+
const client_1 = require("../client");
|
|
5
|
+
class Util extends client_1.default {
|
|
6
|
+
constructor(conf) {
|
|
7
|
+
super(conf);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.Util = Util;
|
|
11
|
+
exports.default = Util;
|
package/yzh/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./services";
|
package/yzh/index.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import YZHclient from "../../common/client";
|
|
2
|
+
/** ApiUseSignContractRequest 获取协议预览 URL 请求 */
|
|
3
|
+
interface ApiUseSignContractRequest {
|
|
4
|
+
/** 平台企业 ID */
|
|
5
|
+
dealer_id: string;
|
|
6
|
+
/** 综合服务主体 ID */
|
|
7
|
+
broker_id: string;
|
|
8
|
+
}
|
|
9
|
+
/** ApiUseSignContractResponse 获取协议预览 URL 返回 */
|
|
10
|
+
interface ApiUseSignContractResponse {
|
|
11
|
+
/** 预览跳转 URL */
|
|
12
|
+
url: string;
|
|
13
|
+
/** 协议名称 */
|
|
14
|
+
title: string;
|
|
15
|
+
}
|
|
16
|
+
/** ApiUserSignRequest 用户签约请求 */
|
|
17
|
+
interface ApiUserSignRequest {
|
|
18
|
+
/** 综合服务主体 ID */
|
|
19
|
+
broker_id: string;
|
|
20
|
+
/** 平台企业 ID */
|
|
21
|
+
dealer_id: string;
|
|
22
|
+
/** 姓名 */
|
|
23
|
+
real_name: string;
|
|
24
|
+
/** 证件号码 */
|
|
25
|
+
id_card: string;
|
|
26
|
+
/** 证件类型 idcard:身份证 passport:护照 mtphkm:港澳居民来往内地通行证 mtpt:台湾居民往来大陆通行证 rphkm:中华人民共和国港澳居民居住证 rpt:中华人民共和国台湾居民居住证 fpr:外国人永久居留身份证 ffwp:中华人民共和国外国人就业许可证书 */
|
|
27
|
+
card_type: string;
|
|
28
|
+
}
|
|
29
|
+
/** ApiUserSignResponse 用户签约返回 */
|
|
30
|
+
interface ApiUserSignResponse {
|
|
31
|
+
/** 是否签约成功 */
|
|
32
|
+
status: string;
|
|
33
|
+
}
|
|
34
|
+
/** GetApiUserSignStatusRequest 获取用户签约状态请求 */
|
|
35
|
+
interface GetApiUserSignStatusRequest {
|
|
36
|
+
/** 平台企业 ID */
|
|
37
|
+
dealer_id: string;
|
|
38
|
+
/** 综合服务主体 ID */
|
|
39
|
+
broker_id: string;
|
|
40
|
+
/** 姓名 */
|
|
41
|
+
real_name: string;
|
|
42
|
+
/** 证件号码 */
|
|
43
|
+
id_card: string;
|
|
44
|
+
}
|
|
45
|
+
/** GetApiUserSignStatusResponse 获取用户签约状态返回 */
|
|
46
|
+
interface GetApiUserSignStatusResponse {
|
|
47
|
+
/** 签约时间 */
|
|
48
|
+
signed_at: string;
|
|
49
|
+
/** 用户签约状态 */
|
|
50
|
+
status: string;
|
|
51
|
+
}
|
|
52
|
+
/** ApiUserSignReleaseRequest 用户解约(测试账号专用接口)请求 */
|
|
53
|
+
interface ApiUserSignReleaseRequest {
|
|
54
|
+
/** 综合服务主体 ID */
|
|
55
|
+
broker_id: string;
|
|
56
|
+
/** 平台企业 ID */
|
|
57
|
+
dealer_id: string;
|
|
58
|
+
/** 姓名 */
|
|
59
|
+
real_name: string;
|
|
60
|
+
/** 证件号码 */
|
|
61
|
+
id_card: string;
|
|
62
|
+
/** 证件类型 idcard:身份证 passport:护照 mtphkm:港澳居民来往内地通行证 mtpt:台湾居民往来大陆通行证 rphkm:中华人民共和国港澳居民居住证 rpt:中华人民共和国台湾居民居住证 fpr:外国人永久居留身份证 ffwp:中华人民共和国外国人就业许可证书 */
|
|
63
|
+
card_type: string;
|
|
64
|
+
}
|
|
65
|
+
/** ApiUserSignReleaseResponse 用户解约(测试账号专用接口)返回 */
|
|
66
|
+
interface ApiUserSignReleaseResponse {
|
|
67
|
+
/** 是否解约成功 */
|
|
68
|
+
status: string;
|
|
69
|
+
}
|
|
70
|
+
export declare class Apiusersign extends YZHclient {
|
|
71
|
+
constructor(conf: {
|
|
72
|
+
dealer_id: string;
|
|
73
|
+
broker_id: string;
|
|
74
|
+
app_key: string;
|
|
75
|
+
des3_key: string;
|
|
76
|
+
private_key: string;
|
|
77
|
+
yzh_public_key: string;
|
|
78
|
+
sign_type: "rsa" | "sha256";
|
|
79
|
+
base_url?: string;
|
|
80
|
+
});
|
|
81
|
+
ApiUseSignContract(req: ApiUseSignContractRequest, cb?: (error: null | string, rep: ApiUseSignContractResponse) => void): Promise<ApiUseSignContractResponse>;
|
|
82
|
+
ApiUserSign(req: ApiUserSignRequest, cb?: (error: null | string, rep: ApiUserSignResponse) => void): Promise<ApiUserSignResponse>;
|
|
83
|
+
GetApiUserSignStatus(req: GetApiUserSignStatusRequest, cb?: (error: null | string, rep: GetApiUserSignStatusResponse) => void): Promise<GetApiUserSignStatusResponse>;
|
|
84
|
+
ApiUserSignRelease(req: ApiUserSignReleaseRequest, cb?: (error: null | string, rep: ApiUserSignReleaseResponse) => void): Promise<ApiUserSignReleaseResponse>;
|
|
85
|
+
}
|
|
86
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Apiusersign = void 0;
|
|
4
|
+
const client_1 = require("../../common/client");
|
|
5
|
+
class Apiusersign extends client_1.default {
|
|
6
|
+
constructor(conf) {
|
|
7
|
+
super(conf);
|
|
8
|
+
}
|
|
9
|
+
// ApiUseSignContract 获取协议预览 URL
|
|
10
|
+
async ApiUseSignContract(req, cb) {
|
|
11
|
+
return this.request("get", "/api/sign/v1/user/contract", req, { encryption: false }, cb);
|
|
12
|
+
}
|
|
13
|
+
// ApiUserSign 用户签约
|
|
14
|
+
async ApiUserSign(req, cb) {
|
|
15
|
+
return this.request("post", "/api/sign/v1/user/sign", req, { encryption: false }, cb);
|
|
16
|
+
}
|
|
17
|
+
// GetApiUserSignStatus 获取用户签约状态
|
|
18
|
+
async GetApiUserSignStatus(req, cb) {
|
|
19
|
+
return this.request("get", "/api/sign/v1/user/status", req, { encryption: false }, cb);
|
|
20
|
+
}
|
|
21
|
+
// ApiUserSignRelease 用户解约(测试账号专用接口)
|
|
22
|
+
async ApiUserSignRelease(req, cb) {
|
|
23
|
+
return this.request("post", "/api/sign/v1/user/release", req, { encryption: false }, cb);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.Apiusersign = Apiusersign;
|