import cryptoJs from 'crypto-js';
|
import { type IRequestOptions } from 'senior-request';
|
|
const ApiSignPrivateKey = 'X07uIM2cHK5IJhDi4ppoxQglYE21gq3E';
|
|
export function getTimestampInSeconds() {
|
var date = new Date();
|
var timestampInSeconds = Math.floor(date.getTime() / 1000);
|
return timestampInSeconds;
|
}
|
|
export function generateApiSign(
|
token: string,
|
userId: string,
|
timestampInSeconds: number | string
|
) {
|
return cryptoJs.MD5(`${token}-${userId}-${timestampInSeconds}-${ApiSignPrivateKey}`).toString();
|
}
|
|
export function setRequestheaders(config: IRequestOptions, accessToken: string, userId: string) {
|
config.headers['Authorization'] = 'Bearer ' + accessToken;
|
const timestampInSeconds = getTimestampInSeconds();
|
config.headers['userId'] = userId;
|
config.headers['time'] = timestampInSeconds;
|
config.headers['sign'] = generateApiSign(
|
config.headers['Authorization'],
|
userId,
|
timestampInSeconds
|
);
|
return config;
|
}
|