获取微信公众号openid参考https://blog.csdn.net/ou24689/article/details/117648499
node.js接口代码
var axios = require('axios');
var wxLogin = async (ctx, next) => {
var {
openid
} = ctx.request.body
var appid = "appid "; //平安临沂
var secret = "secret ";
var bodyData={};
let requrl= "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appid+"&secret="+secret //普通token
// let requrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + secret + "&code=" + code + "&grant_type=authorization_code"; //这个链接是授权获取用户信息,判断不了是否关注
let wxInfoUrl = ''
await axios.get(requrl).then(res => {
wxInfoUrl1 = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token=' + res.data.access_token + '&openid=' + openid1 + '&lang=zh_CN'
})
await axios.get(wxInfoUrl).then(res => {
bodyData=res.data
})
ctx.body=bodyData
}
module.exports = {
'POST /wxLogin': wxLogin,
}