<!--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,和加密解密啥事。就是这么简单。云开发天然鉴权。用什么直接随便拿就行啊。
原文:https://www.cnblogs.com/chendahao/p/12696969.html