2010-11-23 90 views
0

爲什麼這短短的PHP腳本:計算簽名

<?php 

$args = array(
     'api_id' => $_GET['api_id'], 
     'method' => 'getProfiles', 
     'sid'  => $_GET['sid'], 
     'uids'  => $_GET['viewer_id'], 
     'v'   => '3.0', 
); 

$req = $_GET['api_url'] . '?sig=' . 
    calc_sig($_GET['viewer_id'], $args, $_GET['secret']); 

foreach ($args as $key => $val) 
     $req .= "&$key=$val"; 

$page = file_get_contents($req); 

header('Content-Type: text/plain'); 
print_r($_GET); 
print("\n\n req: " . $req); 
print("\n\n page: " . $page); 

function calc_sig($viewer_id, $arr, $secret) { 
     $kv = array(); 
     foreach ($arr as $key => $val) { 
       if ($key != 'sid') 
         $kv[] = "$key=$val"; 
     } 
     sort($kv); 

     $str = $viewer_id . join('', $kv) . $secret; 
     print("\n\n str: " . $str); 
     return md5($str); 
} 
?> 

打印錯誤:

str: 59751265api_id=1762950method=getProfilesuids=59751265v=3.0a551fa3416 
req: http://api.vkontakte.ru/api.php?sig=490142d9c3eb65ee64045a2ea754266c&api_id=1762950&method=getProfiles&sid=1bc83d2ed0db52b8ad45d8ddf36780f52944d5f6340ffa47ad5fef9594&uids=59751265&v=3.0 
page: <?xml version="1.0" encoding="utf-8"?> 
<error> 
<error_code>4</error_code> 
<error_msg>Incorrect signature</error_msg> 
...... 

?> 

我一直一次又一次閱讀the doc ......

回答

0

好的,這個工程:

​​