小程序前端 app.js
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
if(res.code){
wx.getUserInfo({
success: function(res_user){
wx.request({
url: 'http://192.168.xx.xx:8080/test/v1/getOpenId', //这里是本地请求路径,可以写你自己的本地路径,也可以写线上环境
data: {
code: res.code,//获取openid的话 需要向后台传递code,利用code请求api获取openid
headurl: res_user.userInfo.avatarUrl,//这些是用户的基本信息
nickname:res_user.userInfo.nickName,//获取昵称
sex:res_user.userInfo.gender,//获取性别
country: res_user.userInfo.country,//获取国家
province: res_user.userInfo.province,//获取省份
city: res_user.userInfo.city//获取城市
},
success: function(res){
wx.setStorageSync("openid"