send($request);
if($cookie_path == 'eroor'){
return 'error';
}
$cookies = file_get_contents($cookie_path);
// }
// }
if(strpos($cookies,"PHPSESSID")){
return $cookie_path;
}else{
return 'error';
}
}
public function get_between($str, $start, $end) {
$substr = substr($str, strlen($start)+strpos($str, $start),(strlen($str) - strpos($str, $end))*(-1));
return $substr;
}
public function send($request)
{
$ch = curl_init();
// 设置登录接口地址
// $url = 'http://58.220.211.41:12008/login';
$url = $request['login_url'];
// 设置POST请求的数据
// $postData = array(
// 'username' => 'dx18867907766',
// 'password' => '123456'
// );
#file_get_contents(/www/sites/reapi/index/extend/data/cookie/5/cookie.txt): Failed to open stream: No such file or directory
$postData = $request['login_info'];
$result = http_get( $url);
$table= $this->get_between($result, '
', '
');
$need_value= $this->get_between($table, '');
$postData["remember_user"]="on";
$postData["__token__"]=$need_value;
$cookie_path = $this->cookiePatch($request['cid']);
$cookie_path = $cookie_path.'cookie.txt';
$ch = curl_init();
$headers = array(
'X-Requested-With: XMLHttpRequest',
'Accept: */*',
'Connection: keep-alive',
'Content-Type: application/x-www-form-urlencoded',
);
curl_setopt($ch, CURLOPT_URL, $url);
// 添加请求头
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_path);
$response = curl_exec($ch);
// iconv('utf-8', 'gbk', $cookie_path);
// chmod($cookie_path, 0755);
// system('chmod -R 777 ' . $cookie_path);
// sleep(5);
curl_close($ch);
// var_dump($response);die;
if(str_contains($response, "登录成功")){
// var_dump($cookie_path);die;
return $cookie_path;
}else{
return 'error';
}
}
}