phpå©ç¨CURLå½æ°ç»å ¥163é®ç®±å¹¶è·åèªå·±çé讯å½
程序员文章站
2022-05-06 22:30:17
...
æ们使ç¨phpmailerç»å½é®ä»¶åé®ä»¶ä¹æ¯ä½¿ç¨äºcurlåçæ¥å®ç°æ¨¡ä»¿ç¨æ·(www.phprm.com)åé®ä»¶äº,ä»å¤©çäºä¸¤ä¸ªå©ç¨CURLå½æ°ç»å
¥163é®ç®±å¹¶è·åèªå·±çé讯å½çä¾å.
å¦ä¹ äºä¸äºCURLçåºç¡ç¥è¯å¹¶åäºè¿ä¸ªç¤ºä¾,å ³äºCURLçç¥è¯å¯ä»¥ä»phpçå®ç½ä¸æ¥çï¼ç¹å»æ¥ç.
示ä¾ä»£ç è°è¯æ¹å¼:æ$userNameå$passwordæ¢æèªå·±163é®ç®±çç¨æ·ååå¯ç å³å¯.
注æ:ç¨æ·ååå¯ç ä¸å®è¦æ£ç¡®,å¦åæ¥é,没æå容éå¤ç,示ä¾ä»£ç å¦ä¸:
"http://mail.163.com/errorpage/error163.htm", "savelogin" => 0, "username" => trim($userName) , "password" => $password, ); $postString = ''; foreach ($postArray as $key => $value) { $postString.= "{$key}={$value}&"; } $postString = trim($postString, '&'); //åå§åCURL对象 $curl = curl_init(); //设置请æ±å°å curl_setopt($curl, CURLOPT_URL, $loginUrl); //ç¦ç¨åCURLå°ç»æ¢ä»æå¡ç«¯è¿è¡éªè¯ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); //å¯ç¨æ¶å°è·åçä¿¡æ¯ä»¥æ件æµçå½¢å¼è¿åï¼èä¸æ¯ç´æ¥è¾åº curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); //å¯ç¨æ¶ä¼å°å¤´æ件çä¿¡æ¯ä½ä¸ºæ°æ®æµè¾åº curl_setopt($curl, CURLOPT_HEADER, TRUE); //设置POSTåæ° curl_setopt($curl, CURLOPT_POST, TRUE); curl_setopt($curl, CURLOPT_POSTFIELDS, $postString); //æ§è¡ç»å®çCURLä¼è¯ //æåæ¶è¿å TRUEï¼å¤±è´¥æ¶è¿å FALSE //ç¶èï¼å¦æ CURLOPT_RETURNTRANSFERé项被设置ï¼å½æ°æ§è¡æåæ¶ä¼è¿åæ§è¡çç»æï¼å¤±è´¥æ¶è¿å FALSE $html = curl_exec($curl); //æè·åå°çæ°æ®åå ¥æ件ä¸ä»¥ä¾¿æ¥ç //file_put_contents('temp1.txt', $html); //åå²å¤´æ件åå 容 list($head, $content) = explode("\r\n\r\n", $html, 2); //æè·åå°çæ°æ®åå ¥æ件ä¸ä»¥ä¾¿æ¥ç //file_put_contents('temp2.txt', $head); //file_put_contents('temp3.txt', $content); $head = explode("\r\n", $head); //è·åcookieä¿¡æ¯ $cookieString = ''; foreach ($head as $value) { if (stripos($value, "Set-Cookie: ") !== false) { $cookieString.= str_replace("Set-Cookie: ", "", $value); } } //ä»contentéåæåºsidå¼(读åé讯å½ä¿¡æ¯çåæ°) $startString = 'top.location.href = "'; $endString = '";'; $start = strpos($content, $startString); $end = strpos($content, $endString); $tempUrl = substr($content, $start + strlen($startString) , $end - $start - strlen($startString)); $tempUrlVals = parse_url($tempUrl); parse_str($tempUrlVals['query'], $queryVals); $sid = $queryVals['sid']; //==================读åé®ç®±================== //读åé®ç®±å°å $readUrl = "http://twebmail.mail.163.com/contacts/call.do?uid={$email}&sid={$sid}&from=webmail&cmd=newapi.getContacts&vcardver=3.0&ctype=all&attachinfos=yellowpage"; //设置请æ±å°å curl_setopt($curl, CURLOPT_URL, $readUrl); //设置POSTåæ° curl_setopt($curl, CURLOPT_POST, TRUE); curl_setopt($curl, CURLOPT_POSTFIELDS, 'order=[{"field":"N","desc":"false"}]'); //注æè¿éè¦è®¾ç½®ä»ç»å½æä½ä¸è·åçcookie curl_setopt($curl, CURLOPT_COOKIE, $cookieString); //ç¦ç¨å¤´æ件è¾åº curl_setopt($curl, CURLOPT_HEADER, FALSE); //æ§è¡ç»å®çCURLä¼è¯ //æåæ¶è¿å TRUEï¼å¤±è´¥æ¶è¿å FALSE //ç¶èï¼å¦æ CURLOPT_RETURNTRANSFERé项被设置ï¼å½æ°æ§è¡æåæ¶ä¼è¿åæ§è¡çç»æï¼å¤±è´¥æ¶è¿å FALSE $content = curl_exec($curl); //æè·åå°çæ°æ®åå ¥æ件ä¸ä»¥ä¾¿æ¥ç //file_put_contents('temp4.txt', $content); //å ³éä¸ä¸ªCURLä¼è¯ï¼å¹¶éæ¾èµæº curl_close($curl); echo ''; print_r(json_decode($content, true)); echo ''; ?>
ä¾åäº,è¿ä¸ªæ´é«çº§ä¸äºå¯ä»¥è¾å ¥ä¿¡æ¯,代ç å¦ä¸:
ç»é163é®ç®±
mail.php,代ç å¦ä¸:
"https://reg.163.com/logins.jsp", CURLOPT_SSL_VERIFYPEER => false, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => "username=" . $username . "&password=" . $password, CURLOPT_COOKIEJAR => COOKIEJAR, ); curl_quest($options); //å©ç¨ä¸ä¸æ¥è·å¾çcookieè¿ä¸æ¥åå¾cookie $options2 = array( CURLOPT_URL => "http://fm163.163.com/coremail/fcg/ntesdoor2?verifycookie=1&lightweight=1", CURLOPT_COOKIEFILE => COOKIEJAR, CURLOPT_COOKIEJAR => COOKIEJAR, ); curl_quest($options2); //åæcookieæ件ï¼åå¾coremail. $cookiefile = file_get_contents(COOKIEJAR); preg_match('|Coremail.*?%(\S*)|', $cookiefile, $sid); //åéè·å¾é讯å½xml请æ±. $postStr3 = ''; $options3 = array( CURLOPT_URL => 'http://eg1a120.mail.163.com/a/s?sid=' . $sid[1] . '&func=global:sequential', CURLOPT_HTTPHEADER => array( 'Content-Type: application/xml' ) , CURLOPT_POST => 1, CURLOPT_COOKIEFILE => COOKIEJAR, CURLOPT_POSTFIELDS => $postStr3, CURLOPT_REFERER => 'http://eg1a120.mail.163.com/a/f/js3/0811050934/index_v12.htm', ); $mailsxml = curl_quest($options3, true); //è¾åºè·å¾çé讯å½xml header("Content-Type: application/xml"); echo $mailsxml; function curl_quest($ops, $return = false) { $ch = curl_init(); curl_setopt_array($ch, $ops); ob_start(); curl_exec($ch); if ($return) { $content = ob_get_contents(); } curl_close($ch); ob_end_clean(); if ($return) { return $content; } } ?> user:getSignatures pab:getAllGroups
æç« å°å:
转载éæ^^请带ä¸æ¬æå°å!
上一篇: ajax php仿网易文章评论顶一下效果_PHP教程
下一篇: php自定义函数的参数实例详解