wx.login已经获得了用户的code并传给了后端,后端如何调用官方给出的https接口获得session_key
和openid?后端语言为nodejs
你后台用的nodejs?如果是的话试试这
const qs = require(‘querystring’);
const request = require(‘request’);
router.get(‘openid’,function(req, res) => {
var data = {
‘appid’: appid,//你的appid
‘secret’: secret,//你的secret
‘js_code’: req.query.code,
‘grant_type’: ‘authorization_code’
};
var content = qs.stringify(data);
var url = 'https://api.weixin.qq.com/sns/jscode2session?’ + content;
request.get({
‘url’: url
}, (error, response, body) => {
// 处理结果
let body= JSON.parse(body);
})
})