95 lines
2.2 KiB
PHP
Raw Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\kami\controller\getcookie;
#中兆登录cookie获取
class ZhongZhao extends Core
{
# 登录获取
public function login($request)
{
// 初始化curl
$cookie_path = $this->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 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'];
$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';
}
}
}