//app.js App({ onLaunch: function () { wx.getStorage({ key: 'user', success: user => { //登录 this.wxlogin() } }) }, wxlogin(option) { // 登录 console.log("登录参数") wx.showLoading({ title: '加载中...', mask: true }) wx.login({ success: res => { if (res.code) { console.log(res) var code = res.code; wx.getUserProfile({ //getUserProfile流程 success: res2 => { //获取userinfo成功 console.log("res2", res2); wx.request({ url: this.globalData.ip + '/wisdommining/api/wechat/getOpenid', data: { code: code, }, success: suc => { console.log(suc); if (suc.data.code == 1) { this.login({ openid: suc.data.value, nicename: res2.userInfo.nickName, photo: res2.userInfo.avatarUrl }) } else { wx.showModal({ title: '提示!', content: suc.data.msg, showCancel: false, }) } }, fail: f => { wx.hideLoading(); console.log(f) } }); }, fail: ff => { wx.hideLoading(); console.log(f) } }) } }, fail: e => { wx.hideLoading(); wx.showToast({ title: '登录错误~', icon: 'none', }) }, }) }, //登录 login(options) { console.log(options) wx.request({ url: this.globalData.ip + '/wisdommining/api/wechat/addUser', method: 'POST', data: { wxNickname: options.nicename, wxPhoto: options.photo, wxOpenid: options.openid, userPid: parseInt(this.globalData.pId) }, success: res => { console.log(res); if (res.data.code == 1) { wx.setStorage({ key: 'user', data: res.data.value, }) //获取ID this.globalData.userId = res.data.value.id; wx.hideLoading() } else { wx.showModal({ title: '提示!', content: res.data.message, showCancel: false, }) } }, fail: f => { console.log(res) } }); }, //登录提醒 login_no() { wx.showModal({ title: '您还未登录!', content: '登录后可浏览更多内容,是否需要登录?', confirmText: '去登录', confirmColor: '#ee7b1e', success: res => { if (res.confirm) { wx.navigateTo({ url: '/pages/login/login', }) } } }) }, //分享的积分 share() { wx.request({ url: this.globalData.ip + '/wisdommining/api/user/putIntetralEarnings', method: 'PUT', header: { "content-type": "application/x-www-form-urlencoded", }, data: { userId: this.globalData.userId }, success: res => { console.log(res) } }) }, globalData: { statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'],//自定义导航栏顶部高度 cartNum: '',//购物车数量 userId: 0,//个人id pId: 0,//上级id bgImg: 'https://sanpinhuicai.com/wisdommining/static/icon/bg/',//背景图片地址 // ip: 'http://106.54.198.47/', //接口地址 // ip: 'https://sanpinhuicai.com/', //接口地址 ip: 'http://192.168.0.112:9000/', //接口地址/ // ip: 'http://127.0.0.1:9000/', //接口地址/ //appId wx65c9560afc9cbaa7 } })