81 lines
1.8 KiB
PHP
81 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace app\kami\controller\getcookie;
|
|
|
|
|
|
|
|
class KaiDianBao 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,"token")){
|
|
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();
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
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);
|
|
if(str_contains($response, "登录成功")){
|
|
return $cookie_path;
|
|
}else{
|
|
return 'error';
|
|
}
|
|
|
|
|
|
}
|
|
|
|
} |