微信小程序获取手机号

详细代码


复制代码
<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: '',//手机号参数
  },
相关推荐
前端小万1 天前
写公众号赚了 3000 块后,我做了一款叫 "一键成稿" 的软件
前端·微信小程序
MoonMoonLee1 天前
小程序配置
小程序
拖孩1 天前
代码我能全交给 AI,流量主这 500 个访客它一个都替不了我
前端·后端·微信小程序
2501_916007471 天前
苹果商店iOS应用上架费用全面解析:开发者计划与审核费用计算
android·ios·小程序·https·uni-app·iphone·webview
JQweryuiop1 天前
中小型游戏陪练工作室数字化管理实践:基于七彩屋电竞护航小程序订单、履约与绩效系统的落地复盘
大数据·游戏·小程序·架构
Ai-_Man2 天前
您您这可以把Mistral AI的多个会话比如说。左侧的多个会话一次性导出吗?不是单条会话里面的多次会对话。
人工智能·ai·小程序·电脑
2501_916008892 天前
如何实现iOS App代码混淆:SwiftShield使用指南
android·ios·小程序·https·uni-app·iphone·webview
微擎应用市场2 天前
简单拼车小程序系统:实现出行与物流资源的高效精准匹配
小程序
甜到心里的蛋糕2 天前
如何用企业微信实现让微信收到通知实时通知
服务器·python·微信小程序·fastapi
2501_916008892 天前
怎么用 Godot 导出 iOS 应用并上架 App Store?签名字段该填什么?
android·ios·小程序·https·uni-app·iphone·webview