大葛们,为什么我这个userid怎么都读取不到,菜是原罪a
求大葛们教教我
function postUserData(){
return new Promise((resolve, reject) => {
mysql.getConnection(function(err,connection) {
if(err) {
console.log(err);
reject(err)
return res.status(500)
}
connection.query('insert into user values(0,?,?,?)',Object.values(users),function(error,results,fields){
if(error) {
console.log(error);
return res.status(500)
}
console.log('-----------users----------',users);
console.log('---------results-------------',results.insertId);
connection.release()
resolve(results.insertId)
})
})
})
}
router.post('/wx',async(req,res) => {
try {
let body = req.body
console.log('---body----',body);
USER_PRIVACY_DATA.js_code = body.code
let users = {
nickName:body.nickName,
avatarUrl:body.avatarUrl,
gender:body.gender
}
let userid;
const wxds = await axios.get(`https://api.weixin.qq.com/sns/jscode2session`,{params:USER_PRIVACY_DATA})
let length = 0
const ormUser = orm.model('user')
ormUser.sql(`select * from user where avatarUrl="${users.avatarUrl}"`,async(err,data) => {
if(err) {
console.log('select---------------err',err);
return res.status(500)
}
userid = data.id
length = data.length
if(length < 1) {
userid = await postUserData()
console.log('--------------00--userid--00-----',userid);
}
console.log('--------------11--userid--22-----',userid);
const token = jwt.sign(wxds.data, SIGNATERE, {expiresIn: 10 * 1})
res.send({code:200,msg:'做的很棒孩子',data:{userid,token}})
})
} catch (err) {
console.log(err);
res.status(500).send(err)
}
})