...
secret只在待签名字符串中使用,请求接口时,请勿带上secret参数
代码参考
代码块 | ||
---|---|---|
| ||
<script>
const iframe = document.querySelector('#test-iframe');
function getUnionLoginParams() {
const nonce = 'fb4706';
const opfid = '57213854015641423875';
const uid = '18576626619';
const secret = '92cba47febae4a529d02a143a0c22ee7';
const timestamp = Date.now().toString();
const params = { opfid, secret, uid, nonce, timestamp };
const query = Object.keys(params)
.sort(
(key1, key2) => key1.charCodeAt(0) - key2.charCodeAt(0)
)
.reduce((str, key) => (str += `${key}=${params[key]}&`), '')
.slice(0, -1);
const signature = CryptoJS.SHA1(query).toString(CryptoJS.enc.Hex);
return { nonce, opfid, uid, timestamp, signature };
}
const params = getUnionLoginParams();
let loginUrl = 'https://open.rabbitpre.com/union-login.html';
loginUrl += `?nonce=${params.nonce}`;
loginUrl += `&opfid=${params.opfid}`;
loginUrl += `&uid=${params.uid}`;
loginUrl += `×tamp=${params.timestamp}`;
loginUrl += `&signature=${params.signature}`;
loginUrl += `&redirecturl=${encodeURIComponent('https://www.rabbitpre.com/template/multipage.html')}`;
iframe.setAttribute('src', loginUrl);
</script> |