抖音开放平台Logo
开发者文档
控制台

获取用户手机号

收藏
我的收藏
该接口在用户公开信息的基础上,额外获取用户的手机号。​
    Scope: mobile_alert​
    需要申请权限路径:抖音开放平台控制台 > 应用详情 > 能力管理 > 用户权限 > 获取用户手机号

接口说明​

前提条件​

请先获取用户公开信息,才能获取用户手机号。

注意事项​

    解密手机号,使用 AES 算法解密,密钥是 client_secret, 向量 lv 是 client_secret 前 16 字节。

示例解密代码​

    Java​
import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.IvParameterSpec; import java.util.Base64; import java.util.Arrays; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.spec.InvalidKeySpecException; import javax.crypto.NoSuchPaddingException; import javax.crypto.IllegalBlockSizeException; import javax.crypto.BadPaddingException; public class DecryptMobile{ public static String decrypt(String algorithm, String cipherText, SecretKey key,IvParameterSpec iv) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException { Cipher cipher = Cipher.getInstance(algorithm); cipher.init(Cipher.DECRYPT_MODE, key, iv); byte[] plainText = cipher.doFinal(Base64.getDecoder().decode(cipherText)); return new String(plainText); } public static void main(String []args) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException { String clientSecret = "0123456789abcdef0123456789abcdef"; String encryptedMobile = "tyUWQwYuUmVFJtElAL+D7Q=="; byte[] clientSecretBytes = clientSecret.getBytes(); SecretKey secretKey = new SecretKeySpec(clientSecretBytes, 0, clientSecretBytes.length, "AES"); byte[] iv = Arrays.copyOfRange(clientSecretBytes, 0, 16); IvParameterSpec ivParameterSpec = new IvParameterSpec(iv); String algorithm = "AES/CBC/PKCS5Padding"; String mobile = decrypt(algorithm, encryptedMobile, secretKey, ivParameterSpec); System.out.println(mobile); } }
    PHP​
<?php $client_secret = '0123456789abcdef0123456789abcdef'; $encrypted_mobile = 'tyUWQwYuUmVFJtElAL+D7Q=='; function decrypt($encrypted_mobile, $client_secret) { $iv = substr($client_secret, 0, 16); return openssl_decrypt($encrypted_mobile, 'aes-256-cbc', $client_secret, 0, $iv); } echo decrypt($encrypted_mobile, $client_secret); ?>
    Golang​
package main import ( "crypto/aes" "crypto/cipher" "encoding/base64" "errors" "fmt" ) const ( clientSecret = "0123456789abcdef0123456789abcdef" encryptedMobile = "tyUWQwYuUmVFJtElAL+D7Q==" ) func main() { fmt.Println(DecryptString(clientSecret, encryptedMobile)) } func DecryptString(clientSecret, encryptStr string) string { origData := decodeBase64(encryptStr) key := []byte(clientSecret) iv := []byte(clientSecret)[:16] ret, _ := aesDecrypt(origData, key, iv) return string(ret) } func aesDecrypt(crypted, key, iv []byte) ([]byte, error) { block, err := aes.NewCipher(key) if err != nil { return nil, err } if len(iv) != block.BlockSize() { return nil, errors.New("ErrAesDecryptBlockSize") } encrypter := cipher.NewCBCDecrypter(block, iv) origData := make([]byte, len(crypted)) encrypter.CryptBlocks(origData, crypted) return pkcs5UnPadding(origData) } func decodeBase64(in string) []byte { out := make([]byte, base64.StdEncoding.DecodedLen(len(in))) n, err := base64.StdEncoding.Decode(out, []byte(in)) if err != nil { return nil } return out[0:n] } func pkcs5UnPadding(origData []byte) ([]byte, error) { length := len(origData) unpadding := int(origData[length-1]) end := length - unpadding if end > length || end < 0 { return []byte{}, errors.New("array bound") } return origData[:end], nil }