15 lines
438 B
TypeScript
15 lines
438 B
TypeScript
import crypto from 'crypto'
|
|
import { nanoid } from 'nanoid'
|
|
|
|
// 生成签名字段
|
|
// paramStr 为key1=val1&key2=val2, key1, key2按字母升序
|
|
|
|
export function createSign(secretKey: string, paramStr: string, timestamp: number) {
|
|
paramStr = `${paramStr}:${timestamp}${secretKey}`;
|
|
return crypto.createHash('md5').update(paramStr, 'utf8').digest('hex');
|
|
}
|
|
|
|
export function generateId(length: number = 21) {
|
|
return nanoid(length);
|
|
}
|