我在连接我们的系统在Lazada和需要检索项目。这是我的代码。
$region = "https://api.lazada.com.ph/rest";
$getproductitem = "/products/get";
$app_key = 110150;
$date = new DateTime();
$timestamp = 1656029861000;
$access_token = "token***";
$app_secret = "secret***";
$sign_method="sha256";
$base_str = $getproductitem.'access_token'.$access_token.'app_key'.$app_key.'sign_method'.$sign_method.'timestamp'.$timestamp;
$sign = hash_hmac('sha256', $base_str, $app_secret, false);
//$sign = hex(sha256($getproductitem.'access_token'.$access_token.'app_key'.$app_key.'sign_method'.$sign_method.'timestamp'.$timestamp));
//return $uri = "https://api.lazada.com.ph/rest/products/get?app_key=$app_key&access_token=$access_token&sign_method=$sign_method×tamp=$timestamp&sign=$sign";
$response = Http::get($region.$getproductitem, [
"app_key" => $app_key,
"access_token" => $access_token,
"sign_method" => $sign_method,
"timestamp" => $timestamp,
"sign" => $sign,
]);
return $response->json();
但是返回值是这样的
{"type"ISV"code"IncompleteSignature"请求签名不符合平台标准,"request_id"212 a721616560299294283218"}
我按照他们的文档中关于符号设置的说明进行操作,但还是出现了错误。谢谢你的帮助。
用大写字母签名
$sign = strtoupper(hash_hmac('sha256', $base_str, $app_secret));
这是SDK中生成签名
的代码protected function generateSign($apiName,$params)
{
ksort($params);
$stringToBeSigned = '';
$stringToBeSigned .= $apiName;
foreach ($params as $k => $v)
{
$stringToBeSigned .= "$k$v";
}
unset($k, $v);
return strtoupper($this->hmac_sha256($stringToBeSigned,$this->secretKey));
}
function hmac_sha256($data, $key){
return hash_hmac('sha256', $data, $key);
}
文档样本也都是大写的https://open.lazada.com/doc/doc.htm?spm=a2o9m.11193531.0.0.622b6bbeRPVsjG ? docId = 108069, nodeId = 10451