Commit 130250860c7f00bc818eaa22896c818eed803933
1 parent
4f576c62
授权登录
Showing
2 changed files
with
62 additions
and
47 deletions
pages/togoin/togoin.js
| ... | ... | @@ -41,52 +41,67 @@ Page({ |
| 41 | 41 | //-- 会员授权 -- |
| 42 | 42 | bindGetUserInfo: function(ee) { |
| 43 | 43 | var that = this; |
| 44 | - var user=ee.detail.userInfo; | |
| 45 | - //此处授权得到userInfo | |
| 46 | - getApp().globalData.getu = user; | |
| 47 | - | |
| 48 | - //--拿下code-- | |
| 49 | - wx.login({ | |
| 50 | - success: function (o) { | |
| 51 | - var dd = { | |
| 52 | - js_code:o.code, | |
| 53 | - store_id: os.stoid, | |
| 54 | - nickname: app.clear_word(app.globalData.getu.nickName), | |
| 55 | - head_pic: app.clear_word(app.globalData.getu.avatarUrl) | |
| 56 | - }; | |
| 57 | - | |
| 58 | - //-- 导购会员ID -- | |
| 59 | - if(getApp().globalData.guide_id){ | |
| 60 | - dd.guide_id=getApp().globalData.guide_id; | |
| 61 | - } | |
| 62 | - | |
| 63 | - getApp().request.get("/api/weshop/users/openidandkey", { | |
| 64 | - data: dd, | |
| 65 | - success: function (e) { | |
| 66 | - if(e.data.code==0){ | |
| 67 | - that.setData({user:user}) | |
| 68 | - //如果有会员的话,没有sessionKey | |
| 69 | - if(!e.data.data.sessionKey){ | |
| 70 | - getApp().showWarning("登录成功"); | |
| 71 | - getApp().globalData.userInfo=e.data.data; | |
| 72 | - getApp().globalData.user_id=e.data.data.user_id; | |
| 73 | - getApp().globalData.openid = e.data.data.weapp_openid; | |
| 74 | - | |
| 75 | - setTimeout(function () { | |
| 76 | - wx.navigateBack({ delta: 1}) //返回上一页 | |
| 77 | - },1000) | |
| 78 | - }else{ | |
| 79 | - getApp().globalData.sessionKey=e.data.data.sessionKey; | |
| 80 | - getApp().globalData.openid=e.data.data.openid;; | |
| 81 | - that.setData({show_bind:1}) | |
| 82 | - } | |
| 83 | - }else{ | |
| 84 | - getApp().confirmBox(e.data.msg); | |
| 85 | - } | |
| 86 | - } | |
| 87 | - }); | |
| 88 | - } | |
| 89 | - }) | |
| 44 | + //-- 点击授权 -- | |
| 45 | + that.getUserProfile(function(res){ | |
| 46 | + var user=res; | |
| 47 | + //--拿下code-- | |
| 48 | + wx.login({ | |
| 49 | + success: function (o) { | |
| 50 | + var dd = { | |
| 51 | + js_code:o.code, | |
| 52 | + store_id: os.stoid, | |
| 53 | + nickname: app.clear_word(app.globalData.getu.nickName), | |
| 54 | + head_pic: app.clear_word(app.globalData.getu.avatarUrl) | |
| 55 | + }; | |
| 56 | + //-- 导购会员ID -- | |
| 57 | + if(getApp().globalData.guide_id){ | |
| 58 | + dd.guide_id=getApp().globalData.guide_id; | |
| 59 | + } | |
| 60 | + | |
| 61 | + getApp().request.get("/api/weshop/users/openidandkey", { | |
| 62 | + data: dd, | |
| 63 | + success: function (e) { | |
| 64 | + if(e.data.code==0){ | |
| 65 | + that.setData({user:user}) | |
| 66 | + //如果有会员的话,没有sessionKey | |
| 67 | + if(!e.data.data.sessionKey){ | |
| 68 | + getApp().showWarning("登录成功"); | |
| 69 | + getApp().globalData.userInfo=e.data.data; | |
| 70 | + getApp().globalData.user_id=e.data.data.user_id; | |
| 71 | + getApp().globalData.openid = e.data.data.weapp_openid; | |
| 72 | + //把会员的信息存在内存 | |
| 73 | + wx.setStorageSync("userinfo",e.data.data); | |
| 74 | + | |
| 75 | + setTimeout(function () { | |
| 76 | + wx.navigateBack({ delta: 1}) //返回上一页 | |
| 77 | + },1000) | |
| 78 | + }else{ | |
| 79 | + getApp().globalData.sessionKey=e.data.data.sessionKey; | |
| 80 | + getApp().globalData.openid=e.data.data.openid; | |
| 81 | + that.setData({show_bind:1}); | |
| 82 | + } | |
| 83 | + }else{ | |
| 84 | + getApp().confirmBox(e.data.msg); | |
| 85 | + } | |
| 86 | + } | |
| 87 | + }); | |
| 88 | + } | |
| 89 | + }) | |
| 90 | + }) | |
| 91 | + }, | |
| 92 | + | |
| 93 | + //-- 调整后的获取会员信息 -- | |
| 94 | + getUserProfile:function(func){ | |
| 95 | + var that=this; | |
| 96 | + wx.getUserProfile({ | |
| 97 | + desc:'获取用户相关信息', | |
| 98 | + success:res=>{ | |
| 99 | + console.log("getUserProfile",res); | |
| 100 | + //此处授权得到userInfo | |
| 101 | + getApp().globalData.getu = res.userInfo; | |
| 102 | + func(res.userInfo); | |
| 103 | + } | |
| 104 | + }); | |
| 90 | 105 | }, |
| 91 | 106 | |
| 92 | 107 | //暂不登录,返回上一页 | ... | ... |
pages/togoin/togoin.wxml
| ... | ... | @@ -15,7 +15,7 @@ |
| 15 | 15 | <view> |
| 16 | 16 | <view class="phones"> |
| 17 | 17 | <!-- 授权获取基础信息 --> |
| 18 | - <button hidden="{{user}}" class="getPhoneNumber" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo"> | |
| 18 | + <button hidden="{{user}}" class="getPhoneNumber" bindtap="bindGetUserInfo"> | |
| 19 | 19 | <view class="flex flex-center2 ali-c"> |
| 20 | 20 | <image class="we_chat" src="{{imghots}}/miniapp/images/we_chat.png"></image> |
| 21 | 21 | <view>微信账号快捷登录</view> | ... | ... |