// app.js App({ onLaunch() { // 展示本地存储能力 const logs = wx.getStorageSync('logs') || [] logs.unshift(Date.now()) wx.setStorageSync('logs', logs) //开发者信息 const wxInfo = { appid: 'wxc25f00d0fc026ae7', appSecret: '9e94011d65b0f4307b1cab14022ea060' } const ui_w = 360; //把vid存到缓存 wx.setStorage({ key: 'vid', data: '', success: function() { console.log('写入vid缓存成功') }, fail: function() { console.log('写入vid发生错误') } }) // 获取屏幕的宽度 var clientWidth = wx.getSystemInfoSync().windowWidth; // 登录 wx.login({ success: (res) => { //获取用户昵称和头像 //和微信接口服务校验 console.log("code: "+res.code); var url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + wxInfo.appid + '&secret=' + wxInfo.appSecret + '&js_code=' + res.code + '&grant_type=authorization_code' wx.request({ url: url, success(res){ wx.setStorageSync('vid', res.data.openid); console.log(wx.getStorageSync('vid')); wx.getUserProfile({ desc: '登录', success: (res) => { wx.setStorageSync('nickName', res.userInfo.nickuName); wx.setStorageSync('avatarUrl', res.userInfo.avatarUrl); } }); //登录 wx.request({ url: 'http://192.168.31.28:8084/user/login', method:'POST', header: { 'content-type': 'application/x-www-form-urlencoded' }, data:{ vid: wx.getStorageSync('vid') }, success(res){ console.log(res); var avatar = wx.getStorageSync('avatarUrl'); var name = wx.getStorageSync('nickName'); // console.log(vid); console.log('vid: '+ wx.getStorageSync('vid')); if(res.data.code == 403){ wx.request({ url: 'http://192.168.31.28:8084/user/register', method: 'POST', data: { avatar: avatar, name: name, vid: wx.getStorageSync('vid'), phone: '', sign: '', }, success(res){ console.log('注册成功'); console.log(res); wx.request({ url: 'http://192.168.31.28:8084/user/login', method: 'POST', header: { 'content-type': 'application/x-www-form-urlencoded' }, data:{ vid: wx.getStorageSync('vid') }, success(res){ console.log(res); } }) } }) } } }) } }) } }) }, globalData: { userInfo: null } })