You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
const jwt = require("jsonwebtoken")
|
|
|
|
const md5 = require("md5")
|
|
|
|
|
|
|
|
module.exports.formatResponse = function (code, msg, data) {
|
|
|
|
return {
|
|
|
|
code,
|
|
|
|
msg,
|
|
|
|
data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.analysisToken = function (token) {
|
|
|
|
return jwt.verify(token.split(" ")[1], md5(process.env.JWT_SECRET))
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.getJwtToken = function (payload) {
|
|
|
|
let loginPeriod = 1; //默认记住一天
|
|
|
|
return jwt.sign(payload, md5(process.env.JWT_SECRET), {
|
|
|
|
expiresIn: 60 * 60 * 24 * loginPeriod
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.getRandomExpressId = function () {
|
|
|
|
return "SF" + Math.floor(Math.random() * 1000000000000)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.handleArrayDaoData = function (arr) {
|
|
|
|
const result = []
|
|
|
|
for (const item of arr) {
|
|
|
|
result.push(item.dataValues)
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|