php中文网最新课程
每日17点准时技术干货分享
部署源码之后自行修改账号密码为自己的新浪账号
20*3600||$config['COOKIE']=='SUB;') { $COOKIE = login($sinauser,$sinapwd); if($COOKIE&&$COOKIE!='SUB;'){ COOKIESet($COOKIE,$time = time()); }else{ return error('203','获取COOKIE出现错误,请检查账号状态或者重新获取COOKIE'); }}if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {exit;}$type=$_GET['type'];if($type=='multipart'){ $multipart = true; $file = $_FILES["file"]["tmp_name"];}elseif(isset($_GET['img'])){ $multipart = false; $file = $_GET['img'];}else{ return error('404','请勿直接访问');}if (isset($file) && $file != "") { include 'sina_config.php'; $COOKIE = $config['COOKIE']; echo upload($file, $multipart,$COOKIE);}else{ return error('201','上传错误');} function COOKIESet($COOKIE,$time){ $newConfig = ' "'.$COOKIE.'", "time" => "'.$time.'", );'; @file_put_contents('sina_config.php', $newConfig);} function error($code,$msg){ $arr = array('code'=>$code,'msg'=>$msg); echo json_encode($arr);}/** * 新浪微博登录(无加密接口版本) * @param string $u 用户名 * @param string $p 密码 * @return string 返回最有用最精简的COOKIE */function login($u,$p){ $loginUrl = 'https://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.15)&_=1403138799543'; $loginData['entry'] = 'sso'; $loginData['gateway'] = '1'; $loginData['from'] = 'null'; $loginData['savestate'] = '30'; $loginData['useticket'] = '0'; $loginData['pagerefer'] = ''; $loginData['vsnf'] = '1'; $loginData['su'] = base64_encode($u); $loginData['service'] = 'sso'; $loginData['sp'] = $p; $loginData['sr'] = '1920*1080'; $loginData['encoding'] = 'UTF-8'; $loginData['cdult'] = '3'; $loginData['domain'] = 'sina.com.cn'; $loginData['prelt'] = '0'; $loginData['returntype'] = 'TEXT'; return loginPost($loginUrl,$loginData); } /** * 发送微博登录请求 * @param string $url 接口地址 * @param array $data 数据 * @return json 算了,还是返回COOKIE吧//返回登录成功后的用户信息json */function loginPost($url,$data){ $tmp = ''; if(is_array($data)){ foreach($data as $key =>$value){ $tmp .= $key."=".$value."&"; } $post = trim($tmp,"&"); }else{ $post = $data; } $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_HEADER,1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,$post); $return = curl_exec($ch); curl_close($ch); return 'SUB' . getSubstr($return,"Set-COOKIE: SUB",'; ') . ';';} /** * 取本文中间 */function getSubstr($str,$leftStr,$rightStr){ $left = strpos($str, $leftStr); //echo '左边:'.$left; $right = strpos($str, $rightStr,$left); //echo '
右边:&#39;.$right; if($left <&#61; 0 or $right <$left) return &#39;&#39;; return substr($str, $left &#43; strlen($leftStr), $right-$left-strlen($leftStr));} function upload($file, $multipart &#61; true,$COOKIE) { $url &#61; &#39;http://picupload.service.weibo.com/interface/pic_upload.php&#39;.&#39;?mime&#61;image%2Fjpeg&data&#61;base64&url&#61;0&markpos&#61;1&logo&#61;&nick&#61;0&marks&#61;1&app&#61;miniblog&#39;; if($multipart) { $url .&#61; &#39;&cb&#61;http://weibo.com/aj/static/upimgback.html?_wv&#61;5&callback&#61;STK_ijax_&#39;.time(); if (class_exists(&#39;CURLFile&#39;)) { // php 5.5 $post[&#39;pic1&#39;] &#61; new \CURLFile(realpath($file)); } else { $post[&#39;pic1&#39;] &#61; &#39;&#64;&#39;.realpath($file); } } else { $post[&#39;b64_data&#39;] &#61; base64_encode(file_get_contents($file)); } // Curl提交 $ch &#61; curl_init($url); curl_setopt_array($ch, array( CURLOPT_POST &#61;> true, CURLOPT_VERBOSE &#61;> true, CURLOPT_RETURNTRANSFER &#61;> true, CURLOPT_HTTPHEADER &#61;> array("COOKIE: $COOKIE"), CURLOPT_POSTFIELDS &#61;> $post, )); $output &#61; curl_exec($ch); curl_close($ch); // 正则表达式提取返回结果中的json数据 preg_match(&#39;/({.*)/i&#39;, $output, $match); if(!isset($match[1])) return error(&#39;201&#39;,&#39;上传错误&#39;); $a&#61;json_decode($match[1],true); $width &#61; $a[&#39;data&#39;][&#39;pics&#39;][&#39;pic_1&#39;][&#39;width&#39;]; $size &#61; $a[&#39;data&#39;][&#39;pics&#39;][&#39;pic_1&#39;][&#39;size&#39;]; $height &#61; $a[&#39;data&#39;][&#39;pics&#39;][&#39;pic_1&#39;][&#39;height&#39;]; $pid &#61; $a[&#39;data&#39;][&#39;pics&#39;][&#39;pic_1&#39;][&#39;pid&#39;]; if(!$pid){return error(&#39;201&#39;,&#39;上传错误&#39;);} $arr &#61; array(&#39;code&#39;&#61;>&#39;200&#39;,&#39;width&#39;&#61;>$width,"height"&#61;>$height,"size"&#61;>$size,"pid"&#61;>$pid,"url"&#61;>"http://ws3.sinaimg.cn/thumb150/".$pid.".jpg"); return json_encode($arr);}
-END-
▼