@yunzhanghu/sdk-nodejs 1.0.20 → 1.0.21
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/package.json
CHANGED
package/src/common/client.ts
CHANGED
|
@@ -157,7 +157,7 @@ export class YZHClient {
|
|
|
157
157
|
* @param {string} timestamp 时间戳,精确到秒
|
|
158
158
|
* @returns {string} 签名内容
|
|
159
159
|
*/
|
|
160
|
-
|
|
160
|
+
protected signRSASHA256 = (data: string, mess: string, timestamp: string) => {
|
|
161
161
|
try {
|
|
162
162
|
const plaintext = `data=${data}&mess=${mess}×tamp=${timestamp}&key=${this.app_key}`;
|
|
163
163
|
const sign = crypto.createSign('RSA-SHA256');
|
|
@@ -176,7 +176,7 @@ export class YZHClient {
|
|
|
176
176
|
* @param {string} timestamp 时间戳,精确到秒
|
|
177
177
|
* @returns {string} 签名内容
|
|
178
178
|
*/
|
|
179
|
-
|
|
179
|
+
protected signHmacSHA256 = (data: string, mess: string, timestamp: string) => {
|
|
180
180
|
try {
|
|
181
181
|
const plaintext = `data=${data}&mess=${mess}×tamp=${timestamp}&key=${this.app_key}`;
|
|
182
182
|
const hmac = crypto.createHmac('sha256', this.app_key);
|
|
@@ -214,7 +214,7 @@ export class YZHClient {
|
|
|
214
214
|
|
|
215
215
|
// 自定义随机字符串
|
|
216
216
|
// eslint-disable-next-line class-methods-use-this
|
|
217
|
-
|
|
217
|
+
protected mess = () => {
|
|
218
218
|
const buf = crypto.randomBytes(16);
|
|
219
219
|
const token = buf.toString('hex');
|
|
220
220
|
return token.toString();
|
|
@@ -15,6 +15,42 @@ export class Util extends YZHclient {
|
|
|
15
15
|
}) {
|
|
16
16
|
super(conf);
|
|
17
17
|
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 生成最终客服链接
|
|
21
|
+
* @param {string} baseUrl 基础链接
|
|
22
|
+
* @param {string} memberId 客户系统内用户唯一ID
|
|
23
|
+
* @returns {string} customerLink:最终客服链接
|
|
24
|
+
*/
|
|
25
|
+
getCustomerLink = (baseUrl: string, memberId: string): string => {
|
|
26
|
+
try {
|
|
27
|
+
const m = this.mess();
|
|
28
|
+
const t = Date.now().toString();
|
|
29
|
+
const data = `member_id=${memberId}`;
|
|
30
|
+
|
|
31
|
+
let sign = '';
|
|
32
|
+
if (this.sign_type === 'rsa') {
|
|
33
|
+
sign = this.signRSASHA256(data, m, t);
|
|
34
|
+
} else if (this.sign_type === 'sha256') {
|
|
35
|
+
sign = this.signHmacSHA256(data, m, t);
|
|
36
|
+
} else {
|
|
37
|
+
throw new Error(`Unsupported sign_type: ${this.sign_type}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const params = [
|
|
41
|
+
`sign_type=${this.sign_type}`,
|
|
42
|
+
`sign=${encodeURIComponent(sign)}`,
|
|
43
|
+
`member_id=${memberId}`,
|
|
44
|
+
`mess=${m}`,
|
|
45
|
+
`timestamp=${t}`,
|
|
46
|
+
].join('&');
|
|
47
|
+
|
|
48
|
+
const separator = baseUrl.includes('?') ? '&' : '?';
|
|
49
|
+
return `${baseUrl}${separator}${params}`;
|
|
50
|
+
} catch (err) {
|
|
51
|
+
throw new Error(`${err}`);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
18
54
|
}
|
|
19
55
|
|
|
20
56
|
export default Util;
|
package/yzh/common/client.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export declare class YZHClient {
|
|
|
50
50
|
* @param {string} timestamp 时间戳,精确到秒
|
|
51
51
|
* @returns {string} 签名内容
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
protected signRSASHA256: (data: string, mess: string, timestamp: string) => string;
|
|
54
54
|
/**
|
|
55
55
|
* 生成签名(HMAC 签名算法)
|
|
56
56
|
* @param {string} data 经过加密后的具体数据
|
|
@@ -58,7 +58,7 @@ export declare class YZHClient {
|
|
|
58
58
|
* @param {string} timestamp 时间戳,精确到秒
|
|
59
59
|
* @returns {string} 签名内容
|
|
60
60
|
*/
|
|
61
|
-
|
|
61
|
+
protected signHmacSHA256: (data: string, mess: string, timestamp: string) => string;
|
|
62
62
|
/**
|
|
63
63
|
* 生成签名
|
|
64
64
|
* @param {string} data 经过加密后的具体数据
|
|
@@ -68,7 +68,7 @@ export declare class YZHClient {
|
|
|
68
68
|
* @returns {string} 签名内容
|
|
69
69
|
*/
|
|
70
70
|
private sign;
|
|
71
|
-
|
|
71
|
+
protected mess: () => string;
|
|
72
72
|
/**
|
|
73
73
|
* 3DES 加密数据
|
|
74
74
|
* @param plaintext
|
|
@@ -11,5 +11,12 @@ export declare class Util extends YZHclient {
|
|
|
11
11
|
base_url?: string;
|
|
12
12
|
timeout?: number;
|
|
13
13
|
});
|
|
14
|
+
/**
|
|
15
|
+
* 生成最终客服链接
|
|
16
|
+
* @param {string} baseUrl 基础链接
|
|
17
|
+
* @param {string} memberId 客户系统内用户唯一ID
|
|
18
|
+
* @returns {string} customerLink:最终客服链接
|
|
19
|
+
*/
|
|
20
|
+
getCustomerLink: (baseUrl: string, memberId: string) => string;
|
|
14
21
|
}
|
|
15
22
|
export default Util;
|
|
@@ -6,6 +6,41 @@ class Util extends client_1.default {
|
|
|
6
6
|
// eslint-disable-next-line no-useless-constructor
|
|
7
7
|
constructor(conf) {
|
|
8
8
|
super(conf);
|
|
9
|
+
/**
|
|
10
|
+
* 生成最终客服链接
|
|
11
|
+
* @param {string} baseUrl 基础链接
|
|
12
|
+
* @param {string} memberId 客户系统内用户唯一ID
|
|
13
|
+
* @returns {string} customerLink:最终客服链接
|
|
14
|
+
*/
|
|
15
|
+
this.getCustomerLink = (baseUrl, memberId) => {
|
|
16
|
+
try {
|
|
17
|
+
const m = this.mess();
|
|
18
|
+
const t = Date.now().toString();
|
|
19
|
+
const data = `member_id=${memberId}`;
|
|
20
|
+
let sign = '';
|
|
21
|
+
if (this.sign_type === 'rsa') {
|
|
22
|
+
sign = this.signRSASHA256(data, m, t);
|
|
23
|
+
}
|
|
24
|
+
else if (this.sign_type === 'sha256') {
|
|
25
|
+
sign = this.signHmacSHA256(data, m, t);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
throw new Error(`Unsupported sign_type: ${this.sign_type}`);
|
|
29
|
+
}
|
|
30
|
+
const params = [
|
|
31
|
+
`sign_type=${this.sign_type}`,
|
|
32
|
+
`sign=${encodeURIComponent(sign)}`,
|
|
33
|
+
`member_id=${memberId}`,
|
|
34
|
+
`mess=${m}`,
|
|
35
|
+
`timestamp=${t}`,
|
|
36
|
+
].join('&');
|
|
37
|
+
const separator = baseUrl.includes('?') ? '&' : '?';
|
|
38
|
+
return `${baseUrl}${separator}${params}`;
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
throw new Error(`${err}`);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
9
44
|
}
|
|
10
45
|
}
|
|
11
46
|
exports.Util = Util;
|