欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

uniapp抖音小程序一鍵獲取用戶手機(jī)號(hào)的示例代碼

 更新時(shí)間:2024年12月26日 11:54:37   作者:還這么多錯(cuò)誤?!  
文章介紹了如何在uniapp抖音小程序中通過點(diǎn)擊按鈕一鍵獲取用戶手機(jī)號(hào),encryptedData和iv通過點(diǎn)擊按鈕回傳,后端部分通過解密獲取手機(jī)號(hào),感興趣的朋友一起看看吧

前端部分

點(diǎn)擊按鈕,獲取手機(jī)號(hào)

<button class="button" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">一鍵獲取</button>

傳入sessionKey和encryptedData、iv

其中sessionKey是通過登錄時(shí),調(diào)用抖音接口https://developer.toutiao.com/api/apps/v2/jscode2session獲得

encryptedData、iv則通過點(diǎn)擊按鈕回傳的事件參數(shù)

  getPhoneNumber(e) {
    if (e.detail) {
      if (e.detail.errMsg == "getPhoneNumber:fail auth den") {
        uni.showToast({
          title: '小程序通過試運(yùn)營期,才能一鍵獲取手機(jī)號(hào)',
          icon: 'none'
        });
      }
      this.getUserPhone(e.detail)
    } else {
      this.hasPhoneValue = false
    }
  },
  async getUserPhone(query) {
    // douyin-ad-1ddba+123456 /admin/dyinAd/answerAd
    let Authorization = this.$user.token || "none Authorization";
    let http_url = this.$config.base_url + '/app/user/login/getDyPhone'
    let http_data = {
      sessionKey: this.$user.sessionKey,
      encryptedData: query.encryptedData,
      iv: query.iv,
      "admin": this.$config.admin,
    }
    let http_header = {
      Authorization
    }
    let result = await this.$http.post(http_url, http_data, http_header, 'json')
      .then(async (res) => {
        if (res && res.data) {
          let phone = {}
          Object.assign(phone, JSON.parse(res.data))
          this.formPhone = phone.phoneNumber
        }
      })
      .catch((err) => {
      });
  },

后端部分

解密手機(jī)號(hào)

async getDyPhone(query){
    const decipher = crypto.createDecipheriv(
      "aes-128-cbc",
      Buffer.from(query.sessionKey, "base64"),
      Buffer.from(query.iv, "base64")
    );
    let ret = decipher.update(query.encryptedData, "base64", 'utf8');
    ret += decipher.final('utf8');
    return ret;
  }

到此這篇關(guān)于uniapp抖音小程序一鍵獲取用戶手機(jī)號(hào)的示例代碼的文章就介紹到這了,更多相關(guān)uniapp抖音小程序獲取用戶手機(jī)號(hào)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論