├── LICENSE ├── README.md ├── index.php └── weibo.php /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | weibo-publisher 2 | =============== 3 | 4 | Use Sina & Weibo's Web API to Publish Weibo 5 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 43 | 44 | -------------------------------------------------------------------------------- /weibo.php: -------------------------------------------------------------------------------- 1 | 'weibo', 162 | 'gateway'=>'1', 163 | 'from'=>'', 164 | 'savestate'=>'7', 165 | 'userticket'=>'1', 166 | 'ssosimplelogin'=>'1', 167 | 'vsnf'=>'1', 168 | 'vsnval'=>'', 169 | 'su'=>base64_encode($username), 170 | 'service'=>'miniblog', 171 | 'servertime'=>$servertime , 172 | 'nonce'=>$nonce, 173 | 'pwencode'=>'rsa2', 174 | 'sp'=>$ciphertext_web_safe, 175 | 'encoding'=>'UTF-8', 176 | 'url'=>'http://weibo.com/ajaxlogin.php?framelogin=1&callback=parent.sinaSSOController.feedBackUrlCallBack', 177 | 'returntype'=>'META', 178 | 'rsakv' =>$rsakv, 179 | ); 180 | 181 | $temp = web_post('http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.5)', $data, null, $cookiefile, null); 182 | 183 | preg_match('/replace\(\'(.*?)\'\)/', $temp, $matchs); 184 | $url = $matchs[1]; 185 | $temp = web_get($url, null, $cookiefile, null); 186 | preg_match('/"uniqueid":"(\d+)"/', $temp, $matchs); 187 | return $matchs[1]; 188 | } 189 | 190 | function weibo_publish($content, $cookiefile, $widget = FALSE) { 191 | 192 | if ($widget) { // DEPRECATED 193 | $url = "http://widget.weibo.com/public/aj_addMblog.php"; 194 | $referer = 'http://widget.weibo.com/dialog/publish.php?button=pubilish&language=zh_cn&refer=1&rnd=1391939263231'; 195 | $data = array( 196 | 'content'=>$content, 197 | 'visible'=>'0', 198 | 'refer'=>'', 199 | 'url'=>'', 200 | 'pic_url'=>'', 201 | 'pic_id'=>'', 202 | 'ext'=>'', 203 | 'vsrc'=>'publish_web', 204 | 'app_src'=>'69yt1V', // 69yt1V 3olT89 205 | 'language'=>'zh_cn', 206 | 'wsrc'=>'app_publish', 207 | 'mid'=>'', 208 | '_t'=>'0', 209 | ); 210 | } else { 211 | $cookies = curl_parse_cookiefile($cookiefile); 212 | $sup = urldecode($cookies['SUP']); 213 | $sup = url_query_parse($sup); 214 | $url = "http://weibo.com/aj/mblog/add?_wv=5&__".sys_microtime(); 215 | $referer = 'http://weibo.com/u/'.$sup['uid'].'/home?topnav=1&wvr=5'; 216 | $data = array( 217 | 'text'=>$content, 218 | 'pic_id'=>'', 219 | 'rank'=>'0', 220 | 'rankid'=>'', 221 | '_surl'=>'', 222 | 'hottopicid'=>'', 223 | 'location'=>'home', 224 | 'module'=>'stissue', 225 | '_t'=>'0' 226 | ); 227 | } 228 | 229 | $data = web_post($url, $data, $referer, $cookiefile, array("X-Requested-With: XMLHttpRequest")); 230 | 231 | $ret = json_decode ($data , true); 232 | if ($ret['code'] == '100000') { 233 | return TRUE; 234 | } else { 235 | return $data; 236 | } 237 | } 238 | 239 | function weibo_get_image_url($pid) { 240 | $zone = 0; 241 | $pid_zone = crc32 ($pid); 242 | $type = 'large'; //bmiddle 243 | if ($pid[9] == 'w') { 244 | $zone = ($pid_zone & 3) + 1; 245 | $ext = ($pid[21] == 'g') ? 'gif' : 'jpg'; 246 | $url = 'http://ww'.$zone.'.sinaimg.cn/'.$type.'/'.$pid.'.'.$ext; 247 | } else { 248 | $zone = (hexdec(substr($pid, -2)) & 0xf) + 1; 249 | $url = 'http://ss'.$zone.'.sinaimg.cn/'.$type.'/'.$pid.'&690'; 250 | } 251 | return $url; 252 | } 253 | 254 | function weibo_upload_image($data, $mime, $cookiefile) { 255 | $cookies = curl_parse_cookiefile($cookiefile); 256 | $sup = urldecode($cookies['SUP']); 257 | $sup = url_query_parse($sup); 258 | $url = "http://picupload.service.weibo.com/interface/pic_upload.php?&mime=".$mime."&data=1&url=0&markpos=1&logo=&nick=0&marks=1&app=miniblog"; 259 | $referer = 'http://js.t.sinajs.cn/t5/home/static/swf/MultiFilesUpload.swf?version=27f562792e3b5f71'; 260 | $data = web_post($url, $data, $referer, $cookiefile, array("X-Requested-With: XMLHttpRequest", 'Content-Type: application/octet-stream')); 261 | 262 | if (substr($data, 0, 139) != '') { 263 | return 'failed:'."\r\n".$data; 264 | } else { 265 | $data = substr($data, 139); 266 | $ret = json_decode ($data , true); 267 | if ($ret['code'] == 'A00006') { 268 | $pid = $ret['data']['pics']['pic_1']['pid']; 269 | return $pid; 270 | } else { 271 | return 'failed:'."\r\n".$data; 272 | } 273 | } 274 | } --------------------------------------------------------------------------------