我有一個API文檔。我在創建簽名請求時遇到問題。我有如何創建簽名的以下過程。有人可以幫助我從下面的步驟一個例子:使用php生成API調用簽名
生成簽名創建簽名
Create the canonical zed query string that you need later in this procedure:
Sort the UTF-8 query string components by parameter name with natural byte ordering. The parameters can come from the GET URI or from the POST body (when Content-Type is application/x-www-form-urlencoded).
URL encode the parameter name and values
Concatinate name and values to a single string (eg. var1value1var2value2)
Calculate an RFC 2104-compliant HMAC with the string you just created, your API Access Key as the key, and SHA1 as the hash algorithm.
Make the resulting value base64 encoded.
Use the Resulting value as the value of the Signature request parameter
編輯:
這裏是文檔的輸出樣本:
https://domain.com/api.php?action=checkDomain&version=20090622&keyId=123456 & name = glo0000w.com & signature = fvatTFVwRNF1cyH%2Fj%2Flaig8QytY%3D
下面是我試圖這樣做,但沒有奏效
<?php
$sig = urlencode('actioncheckDomainversion20090622keyId123456nameglo0000w.com');
$sig = hash_hmac('sha1', $sig, '123456');
$sig = base64_encode($sig);
?>
有人可以幫我實現用PHP生成簽名的程序?謝謝。
你遺漏了「使結果值base64編碼」。 '$ sig = base64_encode($ sig);' – 2014-09-03 20:43:11
您之前詢問的問題的副本 – 2014-09-03 20:46:17
@RocketHazmat我添加了它並仍然出現錯誤:錯誤的請求籤名UPL-TYQTSBHIYGRFHKXEPJNPELGY – Toni 2014-09-03 21:14:52