小程序获取用户的信息
<!--获取用户的信息--> wx.getSetting({ success(res) { if (!res.authSetting['scope.userInfo']) { wx.authorize({ scope: 'scope.userInfo', success(res) { } }) } } }) <!--把数据返回给后台并获取open_id--> wx.login({ success: function (res) { // 获取openID; var openId = res.code; var that = this; wx.getUserInfo({ withCredentials: true, success: function (res) { var send_data = md5.hexMD5({ act: 'get_user_info_or_log', headimgurl: res.userInfo.avatarUrl, open_id: openId, nickName:res.userInfo.nickName}); wx.request({ //后台接口地址 url: "https://xcx.baidu.com", data: send_data, method: 'POST', header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res) { wx.setStorageSync('user_id', res.data.user_id); } }) }, }) },
<!--把user_id储存在本地-->
user_id:function(){
// 获取本地的user_id
var user_id = wx.getStorageSync('user_id');
console.log(user_id);
},
})