微信小程式例子——擷取使用者唯一標識openid,小程式openid

來源:互聯網
上載者:User

小程式例子——擷取使用者唯一標識openid,小程式openid

1、效果展示


2、關鍵代碼

1)WXML檔案

擷取使用者唯一標識openidopenid:{{openid}}session_key:{{session_key}}

2)JS檔案

const APP_ID ='';//輸入小程式appidconst APP_SECRET ='';//輸入小程式app_secretvar OPEN_ID=''//儲存擷取到openidvar SESSION_KEY=''//儲存擷取到session_keyPage({  getOpenIdTap:function(){    var that=this;    wx.login({      success:function(res){        wx.request({            //擷取openid介面          url: 'https://api.weixin.qq.com/sns/jscode2session',          data:{            appid:APP_ID,            secret:APP_SECRET,            js_code:res.code,            grant_type:'authorization_code'          },          method:'GET',          success:function(res){            console.log(res.data)            OPEN_ID = res.data.openid;//擷取到的openid            SESSION_KEY = res.data.session_key;//擷取到session_key            console.log(OPEN_ID.length)            console.log(SESSION_KEY.length)            that.setData({              openid: res.data.openid.substr(0, 10) + '********' + res.data.openid.substr(res.data.openid.length - 8, res.data.openid.length),              session_key: res.data.session_key.substr(0, 8) + '********' + res.data.session_key.substr(res.data.session_key.length - 6, res.data.session_key.length)            })          }        })      }    })  }})

3)WXSS檔案

button{  margin: 10px;  color: white;  background: green;}view{  margin: 10px;}

3、原始碼擷取方式

百度雲連結:http://pan.baidu.com/s/1miqPiBY


4、在擷取使用者唯一標識openid過程中有遇到任何問題或者不明白的地方,可以添加我的進行諮詢,感謝支援!號:FutureJet
5、覺得不錯請打賞,您的十分滿意是筆者的無限動力。




著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.