SoFunction
Updated on 2025-04-11

Example code for obtaining user's mobile phone number with one click

Front-end part

Click the button to get your mobile phone number

<button class="button" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">Get one click</button>

Pass in sessionKey and encryptedData, iv

The sessionKey is obtained by calling the Douyin interface /api/apps/v2/jscode2session when logging in

encryptedData and iv are passed back by clicking the button

  getPhoneNumber(e) {
    if () {
      if ( == "getPhoneNumber:fail auth den") {
        ({
          title: 'You can only get your mobile phone number with one click through the trial operation period',
          icon: 'none'
        });
      }
      ()
    } else {
       = false
    }
  },
  async getUserPhone(query) {
    // douyin-ad-1ddba+123456 /admin/dyinAd/answerAd
    let Authorization = this.$ || "none Authorization";
    let http_url = this.$config.base_url + '/app/user/login/getDyPhone'
    let http_data = {
      sessionKey: this.$,
      encryptedData: ,
      iv: ,
      "admin": this.$,
    }
    let http_header = {
      Authorization
    }
    let result = await this.$(http_url, http_data, http_header, 'json')
      .then(async (res) => {
        if (res && ) {
          let phone = {}
          (phone, ())
           = 
        }
      })
      .catch((err) => {
      });
  },

Backend part

Decrypt the mobile phone number

async getDyPhone(query){
    const decipher = (
      "aes-128-cbc",
      (, "base64"),
      (, "base64")
    );
    let ret = (, "base64", 'utf8');
    ret += ('utf8');
    return ret;
  }

This is the article about the example code of uniapp Douyin applet to obtain user mobile phone number with one click. For more related uniapp Douyin applet to obtain user mobile phone number, please search for my previous article or continue browsing the related articles below. I hope everyone will support me in the future!