12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- /**
- * 服务端token。token用于校验客户端权限。
- *
- * 此类暂时未使用,V1版本API暂时未传递此参数,V2版本API可计划增加此功能,提高系统安全性。
- *
- * HMAC: keyed-Hash Message Authentication Code
- *
- * author: Sand
- * since: 2016/11/21
- */
- "use strict";
- let crypto = require('crypto');
- let hmac = crypto.createHmac('sha1', 'theskyisblue');
- class Token{
- constructor(userId, clientId, platform){
- if(!userId || !clientId || !platform) throw {message: "Parameters must not be null."};
- hmac.update(userId + "->" + clientId + "->" + platform);
- let cipherText = hmac.digest('hex');
- this._userId = userId;
- this._clientId = clientId;
- this._platform = platform;
- this._value = cipherText;
- }
- get userId(){
- return this._userId;
- }
- get clientId(){
- return this._clientId;
- }
- get platform(){
- return this._platform;
- }
- get value(){
- return this._value;
- }
- }
- module.exports = Token;
|