微信小程序前端获取OpenID和session_key
code2Session:
https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code
wx.login({success: (res) => {console.log(res.code) //拿到codeuni.request({url:`https://api.weixin.qq.com/sns/jscode2session?appid=${appid}&secret=${密钥}&js_code=${res.code}&grant_type=authorization_code `,method: 'GET',success: (res) => {const {openid,session_key} = res.data;//拿到openid和session_key// 若要进行登录状态校验,需要在后端调用checkSessionKey接口}})}
})
checkSessionKey:
https://api.weixin.qq.com/wxa/checksession?access_token=ACCESS_TOKEN&signature=SIGNATURE&openid=OPENID&sig_method=SIG_METHOD
参考文档1
参考文档2