【发布时间】:2019-04-06 13:24:11
【问题描述】:
我正在尝试调用 Marvel Api,但是我得到的返回是 code = 401 Unauthorized,这是由于无法正确发送 timeStamp 和 hash 参数。
网址基数是http://gateway.marvel.com/v1/public/ -> 我的网址是:= http://gateway.marvel.com/v1/public/characters?名称 = wolverine & apikey = XXX & ts = 2019-04-06% 2013: 09: 10.272 & hash = [B @ afad7ce8] 在文档中描述了我需要发送这些参数: 参数:{ "apikey": "你的 api 密钥", "ts": "一个时间戳", “哈希”:“你的哈希” } 我需要帮助才能正确生成 ts 和散列。 注:hash = ts + apiKey + publicKey
var ts = Timestamp(System.currentTimeMillis())
var hash = getHash(ts.toString())
fun getHash(ts: String): ByteArray? {
val byte = ts.toByteArray() + API_KEY.toByteArray() + PUBLIC_KEY.toByteArray()
val md = MessageDigest.getInstance("MD5")
return md.digest(byte)
}
【问题讨论】:
标签: android kotlin retrofit md5