1. 首页
  2. 一键登录
  3. 一键登录接口文档

一键登录接口文档

接口地址

POST https://sim-api.upyun.com/login/token/verify

REST API

又拍 REST API 采用 HTTP 基本认证的验证方式。基本做法为,HTTP Header 中加 Authorization:

Authorization: Basic ${base64_auth_string}

Header 名称是 “Authorization”, 值是 base64转换过的 “appKey:appSecret”(中间有个冒号)。这两者可以在又拍控制台的[应用管理]-[查看详情]中查看。

鉴权举例

你的 appKey 是 “1499041e1685bc89c6bd87b2”, appSecret 是 “cff319cc2fa157811ae549eb”,则调用 REST API 时,使用 curl 命令的话,是这样写:

  curl --insecure -X POST -v https://sim-api.upyun.com/login/token/verify 
   -H "Content-Type: application/json"
   -u "1499041e1685bc89c6bd87b2:cff319cc2fa157811ae549eb"
   ...

HTTP 请求是:

   > POST /login/token/verify HTTP/1.1
   > Authorization: Basic N2Q0MzFlNDJkZmE2YTZkNjkzYWMyZDA0OjVlOTg3YWM2ZDJlMDRkOTVhOWQ4ZjBkMQ==

功能说明

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

  • 请求示例

    curl –insecure -X POST -v https://sim-api.upyun.com/login/token/verify -H “Content-Type: application/json” -u “1499041e1685bc89c6bd87b2:cff319cc2fa157811ae549eb” -d ‘{“loginToken”:”STsid0000001542695429579Ob28vB7b0cYTI9w0GGZrv8ujUu05qZvw”,”exID”:”1234567″}’

  • 请求参数

请求头参数 说明 Required(必填)
loginToken 认证SDK获取到的loginToken ✔️
exID 开发者自定义的id
  • 响应示例 请求成功

    {“id”:298168956165083136,”code”:8000,”content”:”get phone success”,”exID”:”1234567″,”phone”:”bTvgTKkXYiNWQ7LtAJbQrC+C8JGejSySaCAMV/hZnnS2gPQM/ZHEf5b28PCiaMeQE+Jx8s8j9f89yowAFiAfOVwTsYAuEdHGj4ruFb22kgeCS+W8BNop7BjJlPdB+I4a5Vi9rqScYuHOC8mEJWEXJsQiZnbaS4U9TV9hrDag25o=”}

  • 请求失败

    {“code”:8001,”content”:”get phone fail”}

响应参数 请求头参数 说明
id 流水号,请求出错时可能为空
exID 开发者自定义的id,若请求时为空返回为空
code 返回码
content 返回码说明
phone 加密后的手机号码,需用配置在又拍的公钥对应的私钥解密
  • RSA 私钥解密示例(私钥需要用户自行生成)

Java

import javax.crypto.Cipher; 
import java.security.KeyFactory; 
import java.security.PrivateKey; 
import java.security.spec.PKCS8EncodedKeySpec; 
import java.util.Base64;

       public class RSADecrypt {
           public static void main(String[] args) throws Exception {
               String encrypted = args[0];
               String prikey = args[1];

               String result = decrypt(encrypted, prikey);
               System.out.println(result);
           }

           public static String decrypt(String cryptograph, String prikey) throws Exception {
               PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(prikey));
               PrivateKey privateKey = KeyFactory.getInstance("RSA").generatePrivate(keySpec);

               Cipher cipher=Cipher.getInstance("RSA");
               cipher.init(Cipher.DECRYPT_MODE, privateKey);

               byte [] b = Base64.getDecoder().decode(cryptograph);
               return new String(cipher.doFinal(b));
           }
       }

Python

#!/usr/bin/env python3

   # 需要先安装 pycryptodome,直接使用 pip 安装即可,仅在 python3 环境下测试通过

   from Crypto.PublicKey import RSA
   from Crypto.Cipher import PKCS1_v1_5
   import base64

   PREFIX = '-----BEGIN RSA PRIVATE KEY-----'
   SUFFIX = '-----END RSA PRIVATE KEY-----'

   encrypted = None
   prikey = None

   key = "{}\n{}\n{}".format(PREFIX, prikey, SUFFIX)
   cipher = PKCS1_v1_5.new(RSA.import_key(key))
   result = cipher.decrypt(base64.b64decode(encrypted.encode()), None).decode()

   print(result)

PHP

<?php
   // https://www.php.net/manual/en/function.openssl-private-decrypt.php

   $prefix = '-----BEGIN RSA PRIVATE KEY-----';
   $suffix = '-----END RSA PRIVATE KEY-----';
   $result = '';

   $encrypted = null;
   $prikey = null;

   $key = $prefix . "\n" . $prikey . "\n" . $suffix;
   $r = openssl_private_decrypt(base64_decode($encrypted), $result, openssl_pkey_get_private($key));

   echo $result . "\n";

这篇文章有帮助吗?

相关文章