自建应用身份源开放接口
接口说明
自建的OA系统可以集成联营通讯录OpenAPI,实现将OA系统账号、组织架构等信息导入到联营企业中。
接口签名:
自建OA系统每次调用云商店的接口时,需要按规则对请求生成X-MKP-Authorization,并且将X-MKP-Authorization通过URL PARAMS的方式添加到URL上,云商店在接收到请求后需要同样的规则对请求体进行重新计算X-MKP-Authorization,相比较且完全相同即为校验通过,通过URL PARAMS传递的参数有:
Headers请求参数:
|
参数 |
必选 |
参数类型 |
描述 |
|---|---|---|---|
|
X-MKP-Authorization |
M |
String(255) |
签名信息 |
X-MKP-Authorization字段生成方式:
|
字段名 |
是否必选 |
备注 |
|---|---|---|
|
algorithm |
M |
签名算法,目前固定为:HMAC-SHA256 |
|
appid |
M |
由自建应用自动生成的Client ID |
|
timestamp |
M |
时间戳,UTC时间,格式:YYYYMMDDhhmmss。 |
|
nonce |
M |
32位随机字符,包括字母和数字 |
|
signature |
M |
由字段0到3,按照顺序以英文分号(;)拼接, 例如: algorithm=HMAC-SHA256;appid=0001;timestamp=20231225121200;nonce=11111111222222223333333344444444; signature= 使用创建自建应用生成的ClientSecret,做HMAC-SHA256签名,并做Base64编码,得到Base64编码字符作为signature的值。 |
请求签名示例:
StringJoiner stringJoiner = new StringJoiner(";");
stringJoiner.add("algorithm=" + "HMAC-SHA256")
.add("appid=" + client_id)
.add("timestamp="
+ LocalDateTime.now(ZoneId.of("UTC")).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")))
.add("nonce=XXXX...XXX");
String contentToBeSign = stringJoiner.toString();
byte[] data;
try {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(contentToBeSign.getBytes(StandardCharsets.UTF_8));
data = md.digest();
} catch (NoSuchAlgorithmException exception) {
throw new IllegalArgumentException();
}
byte[] signingKey = Hex.decode(client_secret);
byte[] signatureByte;
try {
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(signingKey, "HmacSHA256"));
signatureByte = mac.doFinal(data);
} catch (InvalidKeyException | NoSuchAlgorithmException exception) {
throw new IllegalArgumentException();
}
String signature = Base64.getEncoder().encodeToString(signatureByte);
String X-MKP-Authorization = contentToBeSign + ";signature=" + signature;