微信小程序获取手机号

详细代码


复制代码
<t-button size="large" theme="primary" variant="outline" data-type="hasCancelBtn" bind:tap="showDialog" block style="display: none;">
  开放能力按钮
</t-button>
<t-dialog id="t-dialog" />

 // 获取手机号
  showDialog() {
    let that = this
    interface PhoneNumberDetail {
      iv: string;              // 解密向量
      encryptedData: string;   // 加密数据
      errMsg: string;          // 错误信息
    }
    const dialogConfig = {
      context: this,
      title: '小程序',
      content: '申请获取并验证你的手机号。',
      cancelBtn: '取消',
      confirmBtn: {
        openType: 'getPhoneNumber',
        content: '获取手机号',
        bindgetphonenumber({ detail }: { detail: PhoneNumberDetail }) {
          console.log(detail,'555')
          that.setData({
            encryptedData: detail.encryptedData,
            iv: detail.iv
          })
          if (detail.errMsg.includes('fail')) {
            return false; // 不关闭弹窗
          }
          return true; // 关闭弹窗
        },
      },
    };

    Dialog.confirm(dialogConfig)
      .then(() => {
        console.log('点击确定');
      })
      .catch(() => {
        console.log('点击取消');
      });
  },

  // 页面初始加载
  onLoad() {
    let iv = this.data.iv
    if (!iv) {
      this.showDialog()
    }
  },

  // 页面的初始数据
  data: {
    encryptedData: '',//手机号参数
    iv: '',//手机号参数
  },
相关推荐
格调UI成品6 分钟前
政务小程序TOP3交互设计分析:便民服务的隐藏心机
microsoft·小程序·政务
声声codeGrandMaster1 小时前
uni-app开发特殊社交APP
小程序·uni-app·web app
—Qeyser2 小时前
让 Deepseek 写一个尺码计算器
微信小程序·小程序·deepseek
鲨鱼辣椒_TUT3 小时前
封装一个小程序选择器(可多选、单选、搜索)
windows·小程序
半梅芒果干5 小时前
微信小程序页面嵌套web-view点击系统导航返回时进行弹窗处理
前端·微信小程序·小程序
Xj_925 小时前
微信小程序返回上一页监听
微信小程序·小程序
汤姆yu7 小时前
基于微信小程序的漫展系统的设计与实现
微信小程序·小程序·漫展
一蓑烟雨,一任平生15 小时前
基于 uni-app + <movable-view>拖拽实现的标签排序-适用于微信小程序、H5等多端
微信小程序·小程序·uni-app
UzumakiHan15 小时前
微信小程序一次性订阅封装
微信小程序·小程序
老李不敲代码21 小时前
榕壹云物品回收系统实战案例:基于ThinkPHP+MySQL+UniApp的二手物品回收小程序开发与优化
数据库·mysql·微信小程序·uni-app·软件需求