/**
* projectKeyId: 项目ID
* secretKey: 项目私钥
* keyArray: loginUserId用逗号拼接的字符串
*/
javapublic String authToken(String projectKeyId, String secretKey, String keyArray) throws Exception {
String message = "ai="+projectKeyId+"&loginUserId="+keyArray;
Mac hmac = Mac.getInstance("HmacSHA256");
hmac.init(new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA256"));
byte[] signature = hmac.doFinal(message.getBytes("UTF-8"));
return Hex.encodeHexString(signature);
}
/**
* projectKeyId: 项目ID
* secretKey: 项目私钥
* keyArray: loginUserId用逗号拼接的字符串
*/
def authToken(projectKeyId: String, secretKey: String, keyArray: String): String = {
val message = s"ai=$projectKeyId&loginUserId=$keyArray"
val hmac: Mac = Mac.getInstance("HmacSHA256")
hmac.init(new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA256"))
val signature = hmac.doFinal(message.getBytes("UTF-8"))
Hex.encodeHexString(signature)
}
/**
* projectKeyId: 项目ID
* secretKey: 项目私钥
* keyArray: loginUserId用逗号拼接的字符串
*/
#coding:utf-8
import hashlib
import hmac
def authToken(projectKeyId,secretKey,keyArray):
message = ("ai=" + projectKeyId + "&loginUserId=" + keyArray).encode('utf-8')
signature = hmac.new(bytes(secretKey.encode('utf-8')), bytes(message), digestmod=hashlib.sha256).hexdigest()
return signature
/**
* projectKeyId: 项目ID
* secretKey: 项目私钥
* keyArray: loginUserId用逗号拼接的字符串
*/
function authToken($projectKeyId, $secretKey, $keyArray)
{
$message="ai=".$projectKeyId."&loginUserId=".$keyArray;
return hash_hmac('sha256',$message, $secretKey, false);
}