每刻认证
- 接口: /auth/login
- Method-Type:POST
- 数据格式:Json
- 调用方:第三方
- 接口说明:第三方调用每刻接口需要使用每刻的签名认证,每刻将分配给第三方 platformCode 与 secretKey, 第三方通过该接口获取到
token,接下来所有调用每刻的接口都将带上这个 token。
请求参数
参数 |
类型 |
必须 |
描述 |
platformCode |
String |
Y |
认证 key |
timestamp |
long |
Y |
时间戳(毫秒级) |
signature |
String |
Y |
签名 |
[info] 签名的计算方式:
signature = SHA256(secretKey + “:” + platformCode + “:” + timestamp)
响应结构
参数 |
类型 |
必须 |
描述 |
code |
String |
Y |
请求是否成功 (ACK / NACK) |
message |
String |
N |
调用详情(如果 code 为 NACK, 该值为必填,表示为失败信息) |
data |
Token |
Y |
token 对象 |
errData |
String |
N |
请求失败信息 |
Token
参数 |
类型 |
必须 |
描述 |
tokenId |
String |
Y |
token |
expireDate |
long |
Y |
过期时间 [1] |
[warning] 注意:
[1] 过期时间为距离过期的时间,而不是过期时间点,单位是毫秒,-1 表示永远有效。
在后续的所有接口都将使用 token 来验签, 使用方法是在 headers 中带上 tokenId
请求示例:
{
"platformCode": "XXXXXXXXXXXX",
"timestamp": 1603270491107,
"signature": "6c9337215ea098842451a7bc22122eaa"
}
响应示例:
{
"code": "ACK",
"message": "message.success",
"data": {
"tokenId": "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJtYXljdXJfand0X2Rldl9pZCIsInN1YiI6IlBGMjAwNjIwMTI1NU5GTk8iLCJpYXQiOjE2MDU2OTEyODUsImF1ZCI6IlBMQVRGT1JNIiwiZXhwIjoxNjA1Njk0ODg1LCJwcm9kdWN0TGluZSI6IkRBVEFfSFVCIn0.XLspt2cVZPgnBrY1vt3Vs304dsqNy2sDXhm_2b0gnqE",
"expireDate": null
},
"errData": null
}
代码示例(Java):
String platformCode = "PF.............";
String secretKey = "xxxxxxxxxx";
long timestamp = new Date().getTime();
String text = secretKey + ":" + platformCode + ":" + timestamp;
System.out.println("Before message digest: " + text);
byte[] hash = null;
try {
hash = MessageDigest.getInstance("SHA-256").digest(text.getBytes(StandardCharsets.UTF_8));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
if (hash == null) {
throw new Exception();
}
StringBuilder hashHexStr = new StringBuilder();
for (byte b : hash) {
String hex = Integer.toHexString(0xff & b);
if (hex.length() == 1) {
hashHexStr.append('0');
}
hashHexStr.append(hex);
}
System.out.println("After message digest: " + hashHexStr.toString());