/** * @author mohuishou<*****@*****.**> * @return $this * @throws \Exception */ protected function login() { //判断是否已经登录 if (!empty($this->_login_cookie)) { return $this; } //设置header伪造来源以及ip $ip = rand(1, 233) . '.' . rand(1, 233) . '.' . rand(1, 233) . '.' . rand(1, 233); $this->_curl->setHeader("X-Forwarded-For", $ip); $this->_curl->setHeader("Referer", 'http://202.115.47.141/login.jsp'); $param = ["zjh" => $this->_uid, "mm" => $this->_password]; $this->_curl->post('http://202.115.47.141/loginAction.do', $param); if ($this->_curl->error) { throw new \Exception('Error: ' . $this->_curl->errorCode . ': ' . $this->_curl->errorMessage, 5001); } //判断是否登录成功 $page = $this->_curl->response; $page = iconv('GBK', 'UTF-8//IGNORE', $page); $rule = ['err' => ['.errorTop', 'text']]; $err = QueryList::Query($page, $rule)->data; if (!empty($err)) { throw new \Exception('Error:' . $err[0]['err'], 4011); } //登录成功之后设置cookie $this->_login_cookie = $this->_curl->getResponseCookie("JSESSIONID"); $this->_curl->setCookie('JSESSIONID', $this->_login_cookie); return $this; }