# 前提条件
# 开发要求
调用接口需要使用appId、accessKeyId、accessSecret这些参数
accessKey、accessSecret:登录到系统之后,在个人中心->AccessKey页面创建密钥对
appId:登录到系统之后,在项目管理中新建获得
# 签名认证
RESTful请求认证需要使用AccessKey和AccessSecret对请求进行签名认证,设置请求头 head('Authorization', xxx); 认证Authorization加密串的java版本生成代码如下:
private String genAuthorization(String accessKey, String accessSecret) {
Long timestamp = System.currentTimeMillis();
Long cnounce = (long) Math.floor(Math.random() * 99999);
String toSign = timestamp + "," + cnounce;
String encodeStr = Base64Utils.encodeToString(HashUtils.sha256_HMAC(toSign, accessSecret).getBytes());
String header = "MAuth realm=,mauth_signature_method=HMAC_SHA256,mauth_serviceid={0},mauth_cnonce={1,number,#},mauth_timestamp={2,number,#},mauth_signature={3}";
header = MessageFormat.format(header, accessKey, cnounce, timestamp, encodeStr);
return header;
}
mauth_serviceid=accessKey
mauth_cnonce=5位随机数
mauth_timestamp=时间戳(13位,如:1615518848701,就是js里面的=new Date().getTime())
mauth_signature=base64(sha256_HMAC(timestamp + "," + cnounce, accessSecret))
# Gateway签名认证
Gateway签名认证,设置请求头 head('GatewayAuthorization', xxx);
head('GatewayAuthorization', "加密字符串");
# 其他说明
接口调用地址
BaseUrl=https://{domain}/client
如:https://{domain}/client/api/v1/channel/createOrJoin/{appId}
# 请求格式
POST方法:请求数据使用JSON串提交
示例:
创建加入https://{domain}/client/api/v1/channel/createOrJoin/{appId}
[POST] https://192.168.2.251/client/api/v1/channel/createOrJoin/5fe01af888eab97a6136da53
setHeader("Content-Type", "application/json;charset=utf8");
setHeader("Authorization", "xxxx");
请求JSON数据:
{
"channelName":"dddfff",
"uid":"1",
"hostname":"192.168.2.251",
"nickName":"n1"
}
响应:
{
"msg": "操作成功",
"code": 200,
"data": {
"appId": "5fe01af888eab97a6136da53",
"appKey": "JgKogm",
"channelId": "5f5700276736dc5f76ba5120",
"token": "eyJ0b2tlbklkIjoiNWY1NzAwMjc2NzM2ZGM1Zjc2YmE1MTIxIiwiaG9zdCI6IjE5Mi4xNjguMi4xNTE6ODA4MCIsInNlY3VyZSI6dHJ1ZSwic2lnbmF0dXJlIjoiTnpKaFpERXhOelppT1RVeU5EZ3haRFpqTlRneVltWmpNREU1WkdJNE1UZzBaRGN5WkRKbU16WXlNemhpTmpBME1XVm1PR05tWXpGaFpUTTBORFJqWWc9PSJ9"
}
}
编码及说明 →