Sinch with PHP获取无效签名错误

时间:2016-12-21 09:47:15

标签: php sinch android-sinch-api

我正在尝试使用Lumen和GuzzleHttp来测试Sinch SMS API,但我得到了#34;无效的签名"错误。我已经按照伪代码,这是我的代码示例:

$body = array('message' => 'sample message');
$contentMD5 = base64_encode(md5(utf8_encode(json_encode($body)), true));
$strToSign = "POST\n" .
    $contentMD5 . "\n" .
    "application/json\n" .
    "x-timestamp:2016-12-21T00:30:31.27Z\n" .
    "/v1/sms/+123456789";
$signature = base64_encode(hash_hmac('sha256', base64_decode($this->API_SECRET, true), utf8_encode($strToSign)));

然后,当我在此处发送请求时,我的附件标题为:

$headers = array(
  'Accept' => 'application/json',
  'Content-Type' => 'application/json',
  'X-Timestamp' => '2016-12-21T00:30:31.27Z',
  'Authorization' => "Application $this->API_KEY:" . $signature
);

假设我的x时间戳是正确的,我在这里做错了什么?希望您能够帮助我。提前谢谢!

1 个答案:

答案 0 :(得分:0)

不要base64编码

$contentMD5 = base64_encode(md5(utf8_encode(json_encode($body)), true));

只是md5它,然后base64编码所有