Facebook-SDK:$ _REQUEST ['signed_request'] vs. $ facebook - > getSignedRequest()

时间:2012-11-29 21:32:18

标签: facebook facebook-php-sdk

有人可以解释一下这两者之间有什么区别吗?我认为他们应该返回相同的值,但我得到的是:

$ REQUEST [ 'signed_request']

    NAqZcEqPisfOqf_3SyKf_zvLyiE_gjpyQIknmQ1xXpQ.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImFwcF9kYXRhIjoiMTAwMDAxNDcwODI3NzQxIiwiZXhwaXJlcyI6MTM1NDIzMDAwMCwiaXNzdWVkX2F0IjoxMzU0MjI0NDAyLCJvYXV0aF90b2tlbiI6IkFBQUdEMzVJM0k3VUJBRDZ3a1pCWkJXbFhidUFuUEdVMERTUW93R1pCSUI1NDE1Zkt1RjdaQ1JrNjFaQWF4ZExBeHVIRWNYS2N2WkJBSlRtN01BOGx3YmZaQXIyRWhtWkFNY3JkQXQ2WkNZZ3lTdFFaRFpEIiwicGFnZSI6eyJpZCI6IjQwMDQ3MDE3MDAwOTQ4NSIsImxpa2VkIjp0cnVlLCJhZG1pbiI6dHJ1ZX0sInVzZXIiOnsiY291bnRyeSI6ImRlIiwibG9jYWxlIjoiZW5fVVMiLCJhZ2UiOnsibWluIjoyMX19LCJ1c2VyX2lkIjoiNjA0MjA3Njk0In0

和getSignedRequest()

Array ( [algorithm] => HMAC-SHA256 [app_data] => 100001470827741 [expires] => 1354230000 [issued_at] => 1354224402 [oauth_token] => AAAGD35I3I7UBAD6wkZBZBWlXbuAnPGU0DSQowGZBIB5415fKuF7ZCRk61ZAaxdLAxuHEcXKcvZBAJTm7MA8lwbfZAr2EhmZAMcrdAt6ZCYgyStQZDZD [page] => Array ( [id] => 40047123009485 [liked] => 1 [admin] => 1 ) [user] => Array ( [country] => de [locale] => en_US [age] => Array ( [min] => 21 ) ) [user_id] => 2237694 ) 

编辑:感谢黄色,我发现前者是base64encoded。它可以使用此function

进行解码
function parse_signed_request($signed_request) {
 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);

 return $data;
}

function base64_url_decode($input) {
  return base64_decode(strtr($input, '-_', '+/'));
}

2 个答案:

答案 0 :(得分:3)

可以是$ REQUEST ['signed_request']是base64url编码的吗? 您可以在此网站上详细了解signed_request:https://developers.facebook.com/docs/howtos/login/signed-request/

答案 1 :(得分:1)

getSignedRequest()返回$ REQUEST [' signed_request']的解析版本,这意味着它被解码并验证散列是否有效以确保请求实际来自Facebook。