// app.js App({ getUserProfile: function (e) { // 推荐使用 wx.getUserProfile 获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认 // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 wx.getUserProfile({ desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { this.setData({ userInfo: res.userInfo, hasUserInfo: true }) } }) }, onLaunch: function (options) { console.log('start') if (!wx.cloud) { console.error('请使用 2.2.3 或以上的基础库以使用云能力'); } else { wx.cloud.init({ // env 参数说明: // env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源 // 此处请填入环境 ID, 环境 ID 可打开云控制台查看 // 如不填则使用默认环境(第一个创建的环境) // env: 'my-env-id', traceUser: true, }); } // 用户授权 wx.getUserProfile({ desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { console.info('用户授权', res) this.setData({ userInfo: res.userInfo, hasUserInfo: true }) } }) // 用户登录 let host = "https://example.com/onLogin" wx.login({ success(res) { console.log('res login', res) console.log('res code', res.code) // if (res.code) { // //发起网络请求 // wx.request({ // url: host, // data: { // code: res.code // } // }) // } else { // console.log('登录失败!' + res.errMsg) // } } }) let setting = null; wx.getSetting({ success(res) { setting = res console.log('res', res) } }) this.globalData = { setting: setting }; console.log('onLaunch', options) }, // // 引入`towxml3.0`解析方法 towxml:require('/towxml/index'), //声明一个数据请求方法 getText: (url, callback) => { wx.request({ url: url, header: { 'content-type': 'application/x-www-form-urlencoded' }, success: (res) => { if (typeof callback === 'function') { callback(res); }; } }); }, onShow(options) { // Do something when show. console.info('show', options) }, onHide(options) { console.info('onHide', options) // Do something when hide. }, onError(msg) { console.log('error', msg) } });