var crypto = require('crypto');
var jwt = require('jsonwebtoken')
var ObjectId = require('./objectId');

function guid() {
    return new ObjectId(new Date()).toString();
}
/**
 * 解译jwt token
 * 
 * @param {String} token 
 * @param {String} privateKey 
 * @returns {Promise(Object)} token source info
 */
function verifyToken(token, privateKey) {
    return new Promise((resolve) => {
        jwt.verify(token, privateKey, {
            algorithm: 'HS256',
            clockTolerance: '200'
        }, (err, decoded) => {
            err ? resolve({
                status: 'failuar'
            }) : resolve({
                status: 'success',
                decoded
            })
        })
    })
}

module.exports = {
    guid,
    verifyToken
};
@@ -726,16 +726,283 @@
   %7D)%0D%0A%7D%0D
+%0A/**%0D%0A * %E7%94%9F%E6%88%90token%0D%0A * %0D%0A * @param %7Bany%7D data %0D%0A * @param %7Bany%7D privateKey %0D%0A * @returns %0D%0A */%0D%0Afunction encodeToken(userId, privateKey) %7B%0D%0A    return jwt.sign(%7B%0D%0A        userId%0D%0A    %7D, privateKey, %7B%0D%0A        algorithm: 'HS256',%0D%0A        expiresIn: 30 * 60%0D%0A    %7D);%0D%0A%7D%0D
 %0A%0D%0Amodul

修改：完成token的生成与解析