Created
January 8, 2013 09:45
-
-
Save stephenjtong/4482523 to your computer and use it in GitHub Desktop.
模拟新浪微博网页发送和转发
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//forward('3514498319000665', '转发'); | |
function add($text){ | |
$params = array( | |
'text'=>$text, | |
'rank'=>0, | |
'location'=>'home', | |
'module'=>'stissue', | |
'_t'=>0, | |
); | |
_ajax_call('http://weibo.com/aj/mblog/add?_wv=5&__rnd=1353934711413', $params); | |
} | |
function forward($mid, $content){ | |
$params = array( | |
'mid'=>$mid, | |
'style_type'=>2, | |
'reason'=>$content, | |
'rank'=> 0, | |
'location'=>'mblog', | |
'_t'=>0, | |
); | |
_ajax_call('http://weibo.com/aj/mblog/forward?_wv=5&__rnd=1353931179366', $params); | |
} | |
function _ajax_call($url, $posts = array()) | |
{ | |
$cookie = '你的cookie'; | |
$ch = curl_init(); | |
curl_setopt_array($ch, array( | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_POST => true, | |
CURLOPT_URL => $url, | |
CURLOPT_POSTFIELDS => http_build_query($posts), | |
CURLOPT_COOKIE => $cookie, | |
CURLOPT_HEADER=>false, | |
CURLOPT_HTTPHEADER => array( | |
'X-Requested-With: XMLHttpRequest', | |
'Content-Type: application/x-www-form-urlencoded; charset=UTF-8', | |
'Host: weibo.com', | |
'Origin: http://weibo.com', | |
'Referer: http://weibo.com/u/3118088481?from=profile&wvr=5&loc=tabprofile', | |
'User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11', | |
), | |
CURLOPT_HEADER => 1, | |
)); | |
if (false === ($json = curl_exec($ch))) { | |
return false; | |
} | |
curl_close($ch); | |
// var_dump($json); | |
$json = json_decode($json, true); | |
return $json; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment