21,887
社区成员
发帖
与我相关
我的任务
分享
$token_api = 'https://api.weibo.com/oauth2/access_token';
$data = array(
'client_id' => $_SESSION['sina_token'],
'client_secret' => $_SESSION['sina_token_secret'],
'grant_type' => 'authorization_code',
'redirect_uri' => $_SESSION['callback'],
'code' => $_REQUEST['code'],
);
$postdata = http_build_query($data);
$postdata = str_replace(" ", '%20', $postdata);
$opts = array(
'http' => array(
'method'=>"POST",
'header'=>"POST /oauth2/access_token HTTP/1.0\r\n User-Agent: Sae T OAuth2 v0.1\r\n Host: api.weibo.com\r\n Accept: */*\r\n Accept-Encoding: deflate, gzip\r\n API-RemoteIP: ".$_SERVER["REMOTE_ADDR"]."\r\n Content-Length: ".strlen($postdata)."\r\n Content-Type: application/x-www-form-urlencoded",
'timeout'=>30,
)
);
$context = stream_context_create($opts);
$result = @file_get_contents($token_api.'?'.$postdata,false,$context);