微信小程序 雲開發天然鑒權獲取手機號


 

<!--miniprogram/pages/my/info/modify/cellphone/cellphone.wxml--> <button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">手機號碼</button>

2,js cellphone.js

Page({ /** * 頁面的初始數據 */ data: { }, getPhoneNumber(e) { console.log(JSON.stringify(e)); wx.cloud.callFunction({ name: 'openapi', data: { action:'getcellphone', id:e.detail.cloudID } }).then(res => { console.log('res: ', res) }) }, /** * 生命周期函數--監聽頁面加載 */ onLoad: function (options) { }, /** * 生命周期函數--監聽頁面初次渲染完成 */ onReady: function () { }, /** * 生命周期函數--監聽頁面顯示 */ onShow: function () { }, /** * 生命周期函數--監聽頁面隱藏 */ onHide: function () { }, /** * 生命周期函數--監聽頁面卸載 */ onUnload: function () { }, /** * 頁面相關事件處理函數--監聽用戶下拉動作 */ onPullDownRefresh: function () { }, /** * 頁面上拉觸底事件的處理函數 */ onReachBottom: function () { }, /** * 用戶點擊右上角分享 */ onShareAppMessage: function () { } })

3,雲函數 openapi 的index.js

// 雲函數入口文件
const cloud = require('wx-server-sdk') //const requestpromise = require('request-promise'); cloud.init() // 雲函數入口函數 exports.main = async (event, context) => { switch (event.action) { case 'getcellphone':{ return getCellphone(event); } default: { return } } } async function getCellphone(event){ const res = await cloud.getOpenData({ list: [event.id], // 假設 event.openData.list 是一個 CloudID 字符串列表 }) return {res,event}; }

全程沒有code,session_key,和加密解密啥事。就是這么簡單。雲開發天然鑒權。用什么直接隨便拿就行啊。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM