Home

PHP

Mysql

Linux

Jquery

Module

Tblog

新浪API, 利用get_uid获取是uid的数据溢出问题解决方案

 
0 投票
 
 

开发中发现此BUG, 因为新浪的API返回的UID为int(64), 在32位的系统上就会产生数据溢出,

解决方案:

saetv2.ex.class.php
function get($url, $parameters = array()) {

    $response = $this->oAuthRequest($url, 'GET', $parameters);

    // 32bit int bug repair
    if ($url == 'account/get_uid')
    {
        preg_match('/\{\"uid\":(.+?)\}/',$response, $item);
        $data = array('uid'=>"{$item[1]}");
        $response = json_encode($data);
    }

    if ($this->format === 'json' && $this->decode_json) {
        return json_decode($response, true);
    }
    return $response;
}

关键在于:$data = array('uid'=>"{$item[1]}"); 把match出来的正确数字以字符串的形式再json一下。 就OK了。


这是一个BUG, 应该引起新浪的开发人员注意, 他们只是简单一行代码, 可能会浪费掉我们一天的时间。  要命!

 

posted @ 2012-11-26 14:49  追逐_something  阅读(1065)  评论(0编辑  收藏  举报