
import jsSHA from 'jssha'
// 随机字符串产生函数
var createNonceStr = function () {
    return Math.random().toString(36).substr(2, 15);
};

// 时间戳产生函数
var createTimeStamp = function () {
    return parseInt(new Date().getTime() / 1000 + '');
};
var calcSignature = function (ticket: string, noncestr: string, timestamp: number, url: string) {

    var str = 'jsapi_ticket=' + ticket + '&noncestr=' + noncestr + '&timestamp=' + timestamp + '&url=' + url;
    var shaObj = new jsSHA(str, 'TEXT');
    return shaObj.getHash('SHA-1', 'HEX') as string;
}

export default { calcSignature, createNonceStr, createTimeStamp }