UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

27 lines (22 loc) 1.02 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var nodejs_crypto = require('../../nodejs/crypto.js'); function getAuthOfTai(_ref) { var paasToken = _ref.paasToken, paasId = _ref.paasId; var crypto = nodejs_crypto.getCrypto(); var timestamp = (Date.now() / 1000).toFixed(); // 生成时间戳,注意服务器的时间与标准时间差不能大于180秒 var nonce = Math.random().toString(36).slice(2); // 随机字符串,十分钟内不重复即可 // 计算签名并转换为大写 var signature = crypto.createHash('sha256').update(timestamp + paasToken + nonce + timestamp, 'utf-8').digest('hex'); return { 'Cache-Control': 'no-cache', 'Content-Type': 'application/json', // 设置鉴权参数,如果此参数设置错误,将触发“AGW.xxxxx”类型的错误,详见3.4章节 'x-rio-nonce': nonce, 'x-rio-signature': signature, 'x-rio-timestamp': timestamp, 'x-rio-paasid': paasId }; } exports.getAuthOfTai = getAuthOfTai;