我尝试使用Gigya的评论通知功能,并且我已遵循以下指南: http://developers.gigya.com/010_Developer_Guide/18_Plugins/022_Comments_Version_2/Comment_Notifications
我开发了以下代码:
<?php
require_once('GSSDK.php');
$event = $_POST['event'];
$eventData = $_POST['eventData'];
$nonce = $_POST['nonce'];
$timestamp = $_POST['timestamp'];
$signature = $_POST['signature'];
$signatureBase = sprintf("%s_%s_%s_%s", $event, $eventData, $nonce, $timestamp);
$expectedSignature = SigUtils::calcSignature(
$signatureBase,
MY_SECRET_KEY);
if($signature !== $expectedSignature) {
header('HTTP/1.0 403 Forbidden');
die();
}
//Some other stuff
exit();
?>
但它永远不会进入&#34; //其他一些东西&#34;部分。 始终预期的签名与Gigya服务器提供的签名不同。 我做错了什么?
答案 0 :(得分:0)
请尝试使用以下代码:
<?php
static function calcSignature($baseString,$key)
{
$baseString = utf8_encode($baseString);
$rawHmac = hash_hmac("sha1", utf8_encode($baseString), base64_decode($key), true);
$sig = base64_encode($rawHmac);
return $sig;
}
function checkSignature()
{
$event = $_POST["event"];
$eventData = $_POST["eventData"];
$nonce = $_POST["nonce"];
$timestamp = $_POST["timestamp"];
$signature = $_POST["signature"];
$signatureBase = $event . "_" . $eventData . "_" . $nonce . "_" . $timestamp;
$secret = "[your gigya secret key]";
$expectedSignature = calcSignature($signatureBase, $secret);
// Now compare the expectedSignature value to the signature value returned in the callback
if ($signature !== $expectedSignature)
{
header('HTTP/1.0 403 Forbidden');
die();
}
}
checkSignature();
//Some other stuff
exit();
?>
此代码仅删除对GigyaSDK的依赖性以检查签名。提供的方法与GigyaSDK使用的方法相同,但这里的优点是这是一个小得多的内存占用,因为不需要加载整个GigyaSDK。
此外,我不确定这是否是故意的,但您的比较有代码:
if(!$signature !== $expectedSignature) {
而不是:
if ($signature !== $expectedSignature) {
我不太确定$ signature上的无关逻辑 - 非运算符的目的应该是什么,但看起来这会导致意外行为。