From 3ab45cec3cfe70769607a90cc87aec3c153ca53b Mon Sep 17 00:00:00 2001 From: yvan.ni Date: Thu, 29 Apr 2021 16:19:05 +0800 Subject: [PATCH] 授权登录 --- pages/togoin/togoin.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pages/togoin/togoin.wxml | 28 +++++++++++++++++++++------- 2 files changed, 84 insertions(+), 7 deletions(-) diff --git a/pages/togoin/togoin.js b/pages/togoin/togoin.js index cf1e890..5a0a930 100644 --- a/pages/togoin/togoin.js +++ b/pages/togoin/togoin.js @@ -13,6 +13,12 @@ Page({ config2:null, }, onLoad: function (options) { + if (wx.getUserProfile) { + this.setData({ + canIUseGetUserProfile: true + }) + } + getApp().globalData.isLoad_ad=1; //--判断是否有接受到邀请人的ID-- if(options.first_leader){ @@ -108,6 +114,7 @@ Page({ }); } }) + }) }, @@ -207,7 +214,63 @@ Page({ var _errObj = {}; _errObj[_errImg] = this.data.imghots+"/miniapp/images/logo.png"; this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; + }, + + //-- 会员授权 -- + bindUserInfo: function(ee) { + var that = this; + var user=ee.detail.userInfo; + //此处授权得到userInfo + getApp().globalData.getu = user; + + //--拿下code-- + wx.login({ + success: function (o) { + var dd = { + js_code:o.code, + store_id: os.stoid, + nickname: app.clear_word(app.globalData.getu.nickName), + head_pic: app.clear_word(app.globalData.getu.avatarUrl) + }; + //-- 导购会员ID -- + if(getApp().globalData.guide_id){ + dd.guide_id=getApp().globalData.guide_id; + } + + getApp().request.get("/api/weshop/users/openidandkey", { + data: dd, + success: function (e) { + if(e.data.code==0){ + that.setData({user:user}) + //如果有会员的话,没有sessionKey + if(!e.data.data.sessionKey){ + getApp().showWarning("登录成功"); + getApp().globalData.userInfo=e.data.data; + getApp().globalData.user_id=e.data.data.user_id; + getApp().globalData.openid = e.data.data.weapp_openid; + //把会员的信息存在内存 + wx.setStorageSync("userinfo",e.data.data); + + setTimeout(function () { + wx.navigateBack({ delta: 1}) //返回上一页 + },1000) + }else{ + getApp().globalData.sessionKey=e.data.data.sessionKey; + getApp().globalData.openid=e.data.data.openid; + that.setData({show_bind:1}); + } + }else{ + getApp().confirmBox(e.data.msg); + } + } + }); + } + }) + + } + + }) diff --git a/pages/togoin/togoin.wxml b/pages/togoin/togoin.wxml index f783036..216e723 100644 --- a/pages/togoin/togoin.wxml +++ b/pages/togoin/togoin.wxml @@ -14,13 +14,27 @@ - - + + + + + + + + + + +