我正在尝试使用sinch的标注剩余api加入电话会议,但是使用翻新呼叫时得到响应40102无效签名。
我的代码是..
val instant: Instant = Instant.now()
val mainObject = JsonObject()
mainObject.addProperty("method", "conferenceCallout")
val jsonConferenc = JsonObject()
val jsonDestination = JsonObject()
jsonDestination.addProperty("type", "username")
jsonDestination.addProperty("endpoint", getUserInfo().id)
jsonConferenc.add("destination", jsonDestination)
jsonConferenc.addProperty("domain", "mxp")
jsonConferenc.addProperty("conferenceId", "4495")
jsonConferenc.addProperty("enableDice", false)
mainObject.add("conferenceCallout", jsonConferenc)
val contentMd5 = Base64.encodeToString(getMd5(mainObject.toString())?.toByteArray(), Base64.NO_WRAP)
val stringToSign = "POST\n" +
"$contentMd5\n" +
"application/json; charset=UTF-8\n" +
"x-timestamp:$instant\n" +
"/v1/callouts"
val key = Base64.decode(SinchServiceNew.APP_SECRET, Base64.DEFAULT)
val secret_key = SecretKeySpec(SinchServiceNew.APP_SECRET.toByteArray(Charsets.UTF_8), "HmacSHA256")
val sha256_HMAC = Mac.getInstance("HmacSHA256")
sha256_HMAC.init(secret_key)
val signature = Base64.encodeToString(sha256_HMAC.doFinal(stringToSign.toByteArray(Charsets.UTF_8)), Base64.NO_WRAP)
val headers = HashMap<String, String>()
headers["content-type"] = "application/json; charset=UTF-8"
headers["x-timestamp"] = instant.toString()
headers["authorization"] = "Application ${SinchServiceNew.APP_KEY}:$signature"