微信小程序获取手机号

详细代码


复制代码
<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: '',//手机号参数
  },
相关推荐
宁夏雨科网12 小时前
文具办公用品小程序商城,开发一个难吗
小程序·商城小程序·文具小程序·文具商城
说私域19 小时前
开源链动2+1模式商城小程序在深度分销数字化转型中的应用研究
人工智能·小程序·开源·流量运营·私域运营
咖啡の猫20 小时前
微信小程序案例 - 自定义 tabBar
微信小程序·小程序·notepad++
咖啡の猫21 小时前
微信小程序全局数据共享
微信小程序·小程序
桐溪漂流21 小时前
微信小程序cli脚本预览上传
微信小程序·小程序
咖啡の猫21 小时前
微信小程序使用 npm 包
微信小程序·小程序·npm
说私域21 小时前
开源链动2+1模式商城小程序的营销技术与私域运营策略研究
人工智能·小程序·开源·流量运营·私域运营
小小王app小程序开发1 天前
淘宝扭蛋机小程序核心玩法拆解与技术运营分析
大数据·小程序
说私域2 天前
AI智能名片商城小程序数据清洗的持续运营策略与实践研究
大数据·人工智能·小程序·流量运营·私域运营
东东5162 天前
xxx食堂移动预约点餐系统 (springboot+微信小程序)
spring boot·微信小程序·小程序·毕业设计·个人开发·毕设