android - 如何解决android中的Sinch Invalid signature错误
问题描述
我正在尝试使用 sinch 的 callout rest 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"
解决方案
推荐阅读
- reactjs - HapiJS + create-react-app + webpack-dev-middleware 配置
- docker - 如何创建正确的 Dockerfile
- mongodb - Mongodb如何获取$type“对象”
- kubernetes - “请求的地址无效”试图从 K8S 外部的客户端访问 K8S 中的 Consul 服务器
- node.js - 如何限制显示的对象数量?
- go - 使用 sendgrid 发送 ssl 电子邮件而未完成
- sql-server - 如何从日期中选择MM
- r - 如何使用 aws.s3 包函数(write_using 和 read_using)从 EC2 上的 R 访问 S3 数据?
- debugging - Visual Studio 2017 中的“启用 GPU 反汇编集合”在哪里?
- java - 什么可以在不更改代码的情况下破坏 android 构建?