鉴权

首汽约车对请求合法性进行一定程度鉴别,渠道方使用首汽约车提供的platformId和 secret,按照如下规则生成请求头Authorization :

一次请求类似如下格式:

POST  {url}  HTTP/1.1
Content-Type: application/x-www-form-urlencoded;charset=utf-8
Authorization: platformId=test001903250001,timestamp=1552561215000,signature=0123456789
ABCDEF0123456789ABCDEF
cache-control: no-cache
Host: localhost:8080
…
k1=v1&k2=v2&k3=v3…

其中platformId为首汽约车提供的长度为16的字符串,timestamp为请求生成时当前时间戳(精确到毫秒,允许误差3分钟),signature为经过一定规则生成的16进制大写字符组成的字符串。具体生成步骤如下(Java 代码示例):

  1. String s1 = “platformId=abc”

  2. String s2 = “timestamp=123456”

  3. String s3 = “secret=mysecret”,其中secret为首汽约车提供的platformId的配套密码,请妥善保存

  4. 使用英文逗号无空格连接s1、s2、s3,生成s4, 如 String s4 = “platformId=abc, timestamp=123456, secret=mysecret”

  5. 使用MD5摘要算法计算出 s4 的散列值,转换为32位16进制大写字符串,生成字符串s5, 如 String s5 = "signature=0123abc..."

  6. 使用英文逗号无空格连接s1、s2、s5生成字符串即为Authorization头部的值, 如String headerValue = “platformId=abc, timestamp=123456, signature=0123abc…”,将此值以“Authorization”为key放入请求头即可

Copyright © 首约科技(北京)有限公司 2020 all right reserved,powered by Gitbook该文件修订时间: 2024-09-10 08:00:38

results matching ""

    No results matching ""