123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- const app = getApp();
- Page({
- data: {
- canIUse: wx.canIUse('button.open-type.getUserInfo')
- },
-
- onLoad() {
- setTimeout(function () {
- wx.hideLoading()
- })
-
- },
- bindGetUserInfo(e) {
- var that = this;
- app.showLoading();
- wx.login({
- success: function (res) {
- console.log(res.code)
- if (res.code) {
- wx.getUserInfo({
- withCredentials: true,
- success: function (res_user) {
- console.log(res_user);
- console.log(res_user.userInfo.avatarUrl);
- console.log(res_user.userInfo.city);
- console.log(res_user.userInfo.country);
- console.log(res_user.userInfo.gender);
- console.log(res_user.userInfo.language);
- console.log(res_user.userInfo.nickName);
- console.log(res_user.userInfo.province);
-
-
- let p_url = 'public/wxlogin';
- let p_data = {
- encryptedData: res_user.encryptedData,
- iv: res_user.iv,
- code: res.code,
- headimgurl: res_user.userInfo.avatarUrl,
- city: res_user.userInfo.city,
- country: res_user.userInfo.country,
- sex: res_user.userInfo.gender,
- language: res_user.userInfo.language,
- nickname: res_user.userInfo.nickName,
- province: res_user.userInfo.province,
- };
- app.postRequest(p_url, p_data, function (res) {
- console.log(res);
- if (res.code==201){
- app.cancelLoading();
- if (res.data.openid && res.data.wx_id){
- wx.navigateTo({
- url: '/pages/Landpage/Land/Land'
- })
- }
-
- }
- // console.log(res.data.openid);
- // that.setData({
- // selectArray: 123
- // })
- // 同步传参
- try {
- wx.setStorageSync('openid', res.data.openid)
- } catch (e) {
- }
- // 同步传参
- try {
- wx.setStorageSync('wx_id', res.data.wx_id)
- } catch (e) {
- }
-
- })
- }, fail: function () {
- wx.showToast({
- title: '您拒绝了,无法登陆,请重新授权',
- icon: 'none', // 不显示图标
- mask: true, // 是否显示透明蒙层,防止触摸穿透
- duration: 3000
- })
- // console.log('您拒绝了,无法登陆,请重新授权');
- }, complete: function (res) {
- }
- })
- }
- }
- })
- },
-
- }) // Page
|