微信小程序最新受權方法,getUserInfo

 

20180511微信小程序正式關閉原先getUserInfo的邏輯小程序

        

再也不容許自動彈出受權框。微信小程序

 

方法一:服務器

index.wxml(準備一個用於給用戶受權的頁面,我這裏直接用了一個全屏按鈕)微信

<view class='warp' hidden='{{eye}}'>
    <button open-type="getUserInfo" hover-class='none' bindgetuserinfo="getUserInfoFun">.</button> 
</view>

 

index.wxss    (設置按鈕鋪滿屏幕,同時配置按鈕背景圖)網絡

page {
    height: 100%;
}
button::after{
    border: none;
}
.warp button {
    width: 100%;
    height:100%;
    position: absolute;
    border-radius:0px 0px 0px 0px;
    color: transparent;
    background:transparent no-repeat center center;
    background-size: cover;   
    background-image: url("");
}

注意 background-image: url("");     url 須要使用網絡地址圖片,或者 base64數據圖片 (目前版本微信這樣限制,不知道爲什麼)xss

 

index.jsthis

Page({
  data:{
    eye:true
  },
  onLoad:function(){
   
  },
  onShow: function (options){
    this.getUserInfoFun()
  },
  getUserInfoFun: function (){
    var S = this;
    wx.getUserInfo({
        success: function (res){
            console.log("userInfo:"+res)
       //do anything }, fail: S.showPrePage }) }, showPrePage:
function(){ this.setData({ eye:false }) } })

 

以上邏輯 url

未受權用戶打開小程序spa

  setp1 顯示受權預覽頁面 也就是index.wxml裏的內容,code

  step2 用戶點擊按鈕,彈出微信的受權對話窗,

  step3-1 用戶點擊取消 -> 停留在當前頁

  step3-2 用戶點擊受權 -> 獲取信息成功  -> Do anything

 

已受權用戶打開小程序,則直接去 -> Do anything

 

 

方法二: 

  經過login拿到code, 而後請求自家服務器,去拿用戶的openid,等信息。

相關文章
相關標籤/搜索