# 接入要求
# Token获取接口
# 调用地址
http://ip:port/api/apicenter/token
# 请求头
Content-Type:application/json;charset=UTF-8
# 请求体(json body)
参数名 | 描述 | 类型 | 为空 | 备注 |
---|---|---|---|---|
appKey | 分配的应用key(内部分配) | String | 必填 | |
timestamp | 时间戳字符串(yyyyMMddHHmmss) | String | 必填 | |
sign | 签名算法生成(参见下文签名算法) | String | 必填 |
# 参数示例
{
"sign":"c9cc8dc82c8207627db6e18fbbc4c854aae31080",
"appKey":"78ecca9cf93e42438c0eb5181221316d",
"timestamp":"20210906143804"
}
# 签名算法示例
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.CharsetUtils;
import org.apache.http.util.EntityUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public class SignTest {
private final static String APP_KEY = "78ecca9cf93e42438c0eb5181221316d";
private final static String APP_SECRET = "79ea2c207fe048f585442320018f2880";
private final static String HOST = "http://ip:port";
public static String getToken(String host, String appKey, String appSecret) {
String path = "/api/apicenter/token";
String url = host + path;
String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
// 签名算法(将appKey,appSecret的,时间戳按顺序拼接,使用sha1算法转16进制字符串)
String text = String.format("%s%s%s", appKey, appSecret, timestamp);
String sign = DigestUtils.sha1Hex(text);
System.out.println("sign is :" + token);
Map<String, Object> body = new HashMap<>();
body.put("appKey", appKey);
body.put("sign", sign);
body.put("timestamp", timestamp);
String json = JSON.toJSONString(body);
String responseBody = httpPost(url, json);
JSONObject responseJson = JSON.parseObject(responseBody);
return (String) responseJson.get("token");
}
public static void main(String[] args) {
String token = getToken(HOST, APP_KEY, APP_SECRET);
System.out.println("token is :" + token);
}
}
# 请求示例
curl -H "Content-Type:application/json;charset=UTF-8" -X POST -d '{"sign":"c9cc8dc82c8207627db6e18fbbc4c854aae31080","appKey":"78ecca9cf93e42438c0eb5181221316d","timestamp":"20210906143804"}' http://ip:port/api/apicenter/token
# 返回示例
{
"token":"53774b0a-ea96-459d-93c6-3ab9dd784d5b",
"expireIn":86400
}
← 一、对接说明 三、业务中台能力接入 →