public function yzm($Url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $Url[1]); curl_setopt($ch, CURLOPT_REFERER, $Url[2]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 1); /* 设置代理 start */ $IP = array("202.106.16.36:3128"); $k = array_rand($IP, 1); // 获取随机 IP 的下标值 curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式 curl_setopt($ch, CURLOPT_PROXY, $IP[$k]); //代理服务器地址 //curl_setopt($ch, CURLOPT_PROXYPORT, 80); //代理服务器端口 //curl_setopt($ch, CURLOPT_PROXYUSERPWD, ":"); //http代理认证帐号,username:password的格式 curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //使用http代理模式 /* 设置代理 end */ /* 生成临时文件来保存cookie $ckFile = tempnam('temp','cookie'); curl_setopt($ch, CURLOPT_COOKIEJAR, $ckFile); */ $output = curl_exec($ch); curl_close($ch); //获取cookieStr $cookieStr = ""; preg_match('/Set-Cookie:(.*);/iU', $output, $matches); $cookieStr = $matches[1]; if ($cookieStr == "") { return -1; } //获取图片内容 $pos = strrpos($output, "JFIF"); $picContent = substr($output, $pos - 6); //保存图片 $picName = md5(time()); $verPic = "./Public/temp/" . "{$picName}" . ".jpg"; $file = new \Think\Storage\Driver\File(); $file->put($verPic, $picContent, "jpg"); // 验证码识别 $valid = new ValiteController(); $valid->setImage($verPic); $validCode = $valid->getResult(); // 验证码值 //设置 session session('cookie', $cookieStr); session('vercode', $validCode); // "1234" $validCode $file->unlink($verPic, "jpg"); //unlink($verPic);// 删除图片 }
public function log($post, $Url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $Url[1]); curl_setopt($ch, CURLOPT_REFERER, $Url[2]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 1); /* 设置代理 start */ $IP = array("202.106.16.36:3128"); $k = array_rand($IP, 1); // 获取随机 IP 的下标值 curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式 curl_setopt($ch, CURLOPT_PROXY, $IP[$k]); //代理服务器地址 //curl_setopt($ch, CURLOPT_PROXYPORT, 80); //代理服务器端口 //curl_setopt($ch, CURLOPT_PROXYUSERPWD, ":"); //http代理认证帐号,username:password的格式 curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //使用http代理模式 /* 设置代理 end */ $output = curl_exec($ch); //获取cookieStr $cookieStr = ""; preg_match('/Set-Cookie:(.*);/iU', $output, $matches); $cookieStr = $matches[1]; if ($cookieStr == "") { curl_close($ch); return -1; } //获取图片内容 $pos = strrpos($output, "JFIF"); $picContent = substr($output, $pos - 6); //保存图片 $picName = md5(time()); $verPic = "./Public/temp/" . "{$picName}" . ".jpg"; $file = new \Think\Storage\Driver\File(); $file->put($verPic, $picContent, "jpg"); // 验证码识别 $valid = new ValiteController(); $valid->setImage($verPic); $validCode = $valid->getResult(); // 验证码值 $file->unlink($verPic, "jpg"); //unlink($verPic);// 删除图片 curl_setopt($ch, CURLOPT_URL, $Url[3]); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); $flag = $post['username'] / 10000000 % 10; if ($flag < 5) { $_SESSION['cookieT'][1] = $cookieStr; $user = array(1001010109, 1001020115, 1001040102, 1002010331, 1002010430, 1002010431, 1002010706, 1002010707, 1002010807, 1002040211); $pass = array("254974", "080531", "088116", "182773", "025914", "124699", "152339", "204113", "256659", "289113"); $rand = mt_rand(0, 9); $username = $user[$rand]; $password = $pass[$rand]; } else { $_SESSION['cookieT'][2] = $cookieStr; $user = array(1052010130, 1052010332, 1052010513, 1052010628, 1052010632, 1052010701, 1052010830, 1052011113, 1053010112, 1053010126); $pass = array("01581X", "098333", "190018", "257219", "220319", "190015", "13651X", "283014", "060715", "256510"); $rand = mt_rand(0, 9); $username = $user[$rand]; $password = $pass[$rand]; } $postData = "USERNAME="******"&PASSWORD="******"&RANDOMCODE=" . $validCode; curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); curl_setopt($ch, CURLOPT_COOKIE, $cookieStr); $login = curl_exec($ch); curl_close($ch); if (strrpos($login, "验证码错误!") || strrpos($login, "该帐号不存在或密码错误,请联系管理员!")) { $this->log($post, $Url); } else { return 1; } }