loginTokenVerify API

功能说明

  • 提交loginToken,验证后返回手机号码

调用地址

请求示例

  1. curl --insecure -X POST -v https://api.verification.jpush.cn/v1/web/loginTokenVerify -H "Content-Type: application/json" -u "7d431e42dfa6a6d693ac2d04:5e987ac6d2e04d95a9d8f0d1" -d '{"loginToken":"STsid0000001542695429579Ob28vB7b0cYTI9w0GGZrv8ujUu05qZvw","exID":"1234566"}'
  • 请求参数
KEY REQUIRE DESCRIPTION
loginToken True 认证SDK获取到的loginToken
exID False 开发者自定义的id,非必填

响应示例

请求成功

  1. {"id":117270465679982592,"code":8000,"content":"get phone success","exID":"1234566","phone":"HpBLIQ/6SkFl0pAq0LMdw1aZ8RHoofgWmaY//LE+0ahkSdHC5oTCnjrR8Tj8y5naKVI03torFU+EzAQnwtVqAoQyYckT0S3Q02TKuAal3VRGiR5Lmp4g2A5Mh4/W5A4o6QFviHuBVJZE/WV0AzU5w4NGhpyQntOeF0UyovYATy4="}

请求失败

  1. {"code":8001,"content":"get phone fail"}
  • 响应参数
KEY DESCRIPTION
id 流水号,请求出错时可能为空
exID 开发者自定义的id,若请求时为空返回为空
code 返回码
content 返回码说明
phone 加密后的手机号码,需用配置在极光的公钥对应的私钥解密

RSA私钥解密示例

Java

  1. import javax.crypto.Cipher;
  2. import java.security.KeyFactory;
  3. import java.security.PrivateKey;
  4. import java.security.spec.PKCS8EncodedKeySpec;
  5. import java.util.Base64;
  6. public class RSADecrypt {
  7. public static void main(String[] args) throws Exception {
  8. String encrypted = args[0];
  9. String prikey = args[1];
  10. String result = decrypt(encrypted, prikey);
  11. System.out.println(result);
  12. }
  13. public static String decrypt(String cryptograph, String prikey) throws Exception {
  14. PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(prikey));
  15. PrivateKey privateKey = KeyFactory.getInstance("RSA").generatePrivate(keySpec);
  16. Cipher cipher=Cipher.getInstance("RSA");
  17. cipher.init(Cipher.DECRYPT_MODE, privateKey);
  18. byte [] b = Base64.getDecoder().decode(cryptograph);
  19. return new String(cipher.doFinal(b));
  20. }
  21. }

Python

  1. #!/usr/bin/env python3
  2. # 需要先安装 pycryptodome,直接使用 pip 安装即可,仅在 python3 环境下测试通过
  3. from Crypto.PublicKey import RSA
  4. from Crypto.Cipher import PKCS1_v1_5
  5. import base64
  6. PREFIX = '-----BEGIN RSA PRIVATE KEY-----'
  7. SUFFIX = '-----END RSA PRIVATE KEY-----'
  8. encrypted = None
  9. prikey = None
  10. key = "{}\n{}\n{}".format(PREFIX, prikey, SUFFIX)
  11. cipher = PKCS1_v1_5.new(RSA.import_key(key))
  12. result = cipher.decrypt(base64.b64decode(encrypted.encode()), None).decode()
  13. print(result)

PHP

  1. <?php
  2. // https://www.php.net/manual/en/function.openssl-private-decrypt.php
  3. $prefix = '-----BEGIN RSA PRIVATE KEY-----';
  4. $suffix = '-----END RSA PRIVATE KEY-----';
  5. $result = '';
  6. $encrypted = null;
  7. $prikey = null;
  8. $key = $prefix . "\n" . $prikey . "\n" . $suffix;
  9. $r = openssl_private_decrypt(base64_decode($encrypted), $result, openssl_pkey_get_private($key));
  10. echo $result . "\n";