我在使用Facebooks php-sdk时遇到问题。打印时
$facebook->getSignedRequest()打印不显示任何"页面"或"用户"值。
我还试着打印$_REQUEST["已签名请求"],得到的只是
注意:未定义索引:signed_request
可能是我在php.ini文件中错过了一些设置吗?
谢谢你的帮助!
这只可能解决一半的问题,但请记住$_REQUEST['signed_REQUEST']而不是$_REQUEST('signed.REQUEST');
编辑:忽略您提到的最后一部分,这是您的答案:
你得到的变量不是你想要的。它正在返回一个已签名的请求,您需要使用私钥解密该请求。方法如下:
function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
error_log('Unknown algorithm. Expected HMAC-SHA256');
return null;
}
// check sig
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
}
return $data;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
将已签名的请求和您的应用程序机密传递到其中,它将返回您的数组。我确信有一种方法可以用Facebook SDK做到这一点,但我不确定,因为我不使用它。
更多信息:https://developers.facebook.com/docs/authentication/signed_request/
祝你好运!