Commit 3ab45cec3cfe70769607a90cc87aec3c153ca53b
1 parent
9560d0a0
授权登录
Showing
2 changed files
with
84 additions
and
7 deletions
pages/togoin/togoin.js
| ... | ... | @@ -13,6 +13,12 @@ Page({ |
| 13 | 13 | config2:null, |
| 14 | 14 | }, |
| 15 | 15 | onLoad: function (options) { |
| 16 | + if (wx.getUserProfile) { | |
| 17 | + this.setData({ | |
| 18 | + canIUseGetUserProfile: true | |
| 19 | + }) | |
| 20 | + } | |
| 21 | + | |
| 16 | 22 | getApp().globalData.isLoad_ad=1; |
| 17 | 23 | //--判断是否有接受到邀请人的ID-- |
| 18 | 24 | if(options.first_leader){ |
| ... | ... | @@ -108,6 +114,7 @@ Page({ |
| 108 | 114 | }); |
| 109 | 115 | } |
| 110 | 116 | }) |
| 117 | + | |
| 111 | 118 | }) |
| 112 | 119 | }, |
| 113 | 120 | |
| ... | ... | @@ -207,7 +214,63 @@ Page({ |
| 207 | 214 | var _errObj = {}; |
| 208 | 215 | _errObj[_errImg] = this.data.imghots+"/miniapp/images/logo.png"; |
| 209 | 216 | this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; |
| 217 | + }, | |
| 218 | + | |
| 219 | + //-- 会员授权 -- | |
| 220 | + bindUserInfo: function(ee) { | |
| 221 | + var that = this; | |
| 222 | + var user=ee.detail.userInfo; | |
| 223 | + //此处授权得到userInfo | |
| 224 | + getApp().globalData.getu = user; | |
| 225 | + | |
| 226 | + //--拿下code-- | |
| 227 | + wx.login({ | |
| 228 | + success: function (o) { | |
| 229 | + var dd = { | |
| 230 | + js_code:o.code, | |
| 231 | + store_id: os.stoid, | |
| 232 | + nickname: app.clear_word(app.globalData.getu.nickName), | |
| 233 | + head_pic: app.clear_word(app.globalData.getu.avatarUrl) | |
| 234 | + }; | |
| 235 | + //-- 导购会员ID -- | |
| 236 | + if(getApp().globalData.guide_id){ | |
| 237 | + dd.guide_id=getApp().globalData.guide_id; | |
| 238 | + } | |
| 239 | + | |
| 240 | + getApp().request.get("/api/weshop/users/openidandkey", { | |
| 241 | + data: dd, | |
| 242 | + success: function (e) { | |
| 243 | + if(e.data.code==0){ | |
| 244 | + that.setData({user:user}) | |
| 245 | + //如果有会员的话,没有sessionKey | |
| 246 | + if(!e.data.data.sessionKey){ | |
| 247 | + getApp().showWarning("登录成功"); | |
| 248 | + getApp().globalData.userInfo=e.data.data; | |
| 249 | + getApp().globalData.user_id=e.data.data.user_id; | |
| 250 | + getApp().globalData.openid = e.data.data.weapp_openid; | |
| 251 | + //把会员的信息存在内存 | |
| 252 | + wx.setStorageSync("userinfo",e.data.data); | |
| 253 | + | |
| 254 | + setTimeout(function () { | |
| 255 | + wx.navigateBack({ delta: 1}) //返回上一页 | |
| 256 | + },1000) | |
| 257 | + }else{ | |
| 258 | + getApp().globalData.sessionKey=e.data.data.sessionKey; | |
| 259 | + getApp().globalData.openid=e.data.data.openid; | |
| 260 | + that.setData({show_bind:1}); | |
| 261 | + } | |
| 262 | + }else{ | |
| 263 | + getApp().confirmBox(e.data.msg); | |
| 264 | + } | |
| 265 | + } | |
| 266 | + }); | |
| 267 | + } | |
| 268 | + }) | |
| 269 | + | |
| 270 | + | |
| 210 | 271 | } |
| 272 | + | |
| 273 | + | |
| 211 | 274 | |
| 212 | 275 | |
| 213 | 276 | }) | ... | ... |
pages/togoin/togoin.wxml
| ... | ... | @@ -14,13 +14,27 @@ |
| 14 | 14 | <!-- 登录按钮 --> |
| 15 | 15 | <view> |
| 16 | 16 | <view class="phones"> |
| 17 | - <!-- 授权获取基础信息 --> | |
| 18 | - <button hidden="{{user}}" class="getPhoneNumber" bindtap="bindGetUserInfo"> | |
| 19 | - <view class="flex flex-center2 ali-c"> | |
| 20 | - <image class="we_chat" src="{{imghots}}/miniapp/images/we_chat.png"></image> | |
| 21 | - <view>微信账号快捷登录</view> | |
| 22 | - </view> | |
| 23 | - </button> | |
| 17 | + | |
| 18 | + <!-- 授权获取基础信息 --> | |
| 19 | + <block wx:if="{{canIUseGetUserProfile}}"> | |
| 20 | + <button hidden="{{user}}" class="getPhoneNumber" bindtap="bindGetUserInfo"> | |
| 21 | + <view class="flex flex-center ali-c"> | |
| 22 | + <image class="we_chat" src="/images/we_chat.png"></image> | |
| 23 | + <view>微信账号快捷登录</view> | |
| 24 | + </view> | |
| 25 | + </button> | |
| 26 | + </block> | |
| 27 | + | |
| 28 | + <block wx:else> | |
| 29 | + <!-- 授权获取基础信息 --> | |
| 30 | + <button hidden="{{user}}" class="getPhoneNumber" open-type="getUserInfo" bindgetuserinfo="bindUserInfo"> | |
| 31 | + <view class="flex flex-center ali-c"> | |
| 32 | + <image class="we_chat" src="/images/we_chat.png"></image> | |
| 33 | + <view>微信账号快捷登录</view> | |
| 34 | + </view> | |
| 35 | + </button> | |
| 36 | + </block> | |
| 37 | + | |
| 24 | 38 | <!-- 点击显示绑定手机的对话框 --> |
| 25 | 39 | <button hidden="{{!user}}" class="getPhoneNumber" bindtap="show_bind_mobile"> |
| 26 | 40 | <view class="flex flex-center2 ali-c" > | ... | ... |