获取用户手机号
该接口在用户公开信息的基础上,额外获取用户的手机号。
- •Scope: mobile_alert
- •需要申请权限。(已下架,不开放新增)
接口说明
注意
前提条件
注意事项
- •用户授权后,获取用户公开信息接口会额外返回 encrypt_mobile 字段。
- •解密手机号,使用 AES 算法解密,密钥是 client_secret, 向量 lv 是 client_secret 前 16 字节。
- •通过辅助手机号绑定的信息不会返回。
示例解密代码
Java
PHP
Golang
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); } }