155 lines
3.8 KiB
PHP
155 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace app\kami\controller\getcookie;
|
|
|
|
|
|
#中兆登录cookie获取
|
|
class Whymcl 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 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)
|
|
{
|
|
|
|
$url = $request['login_url'];
|
|
|
|
$postData = $request['login_info'];
|
|
|
|
|
|
// $result = http_get($url);
|
|
//
|
|
// $table= $this->get_between($result, '_token__', 'button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login"');
|
|
//// print_r($table);die;
|
|
//
|
|
// $need_value= $this->get_between($table, 'value="', '" /');
|
|
// return $need_value;
|
|
|
|
$postData["remember_user"]="on";
|
|
$cookie_path = $this->cookiePatch($request['cid']);
|
|
$cookie_path = $cookie_path.'cookie.txt';
|
|
|
|
// $postData["__token__"]=$need_value;
|
|
$ch = curl_init();
|
|
|
|
// $headers = array(
|
|
// 'X-Requested-With: XMLHttpRequest',
|
|
// 'Accept: */*',
|
|
// 'Connection: keep-alive',
|
|
// 'Content-Type: application/json',
|
|
// );
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
|
|
|
// curl_setopt($ch, CURLOPT_POST, 1);
|
|
// curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($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);
|
|
$table= $this->get_between($response, '_token__', 'button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login"');
|
|
//// print_r($table);die;
|
|
//
|
|
$need_value= $this->get_between($table, 'value="', '" /');
|
|
// var_dump($response);die;
|
|
// $result = http_get('http://taobao.whymcl.cn/tb.php/login/sendmsg.html');
|
|
// $json = json_decode($result,true);
|
|
|
|
|
|
$postData["__token__"]=$need_value;
|
|
// var_dump($postData);die;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$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/json',
|
|
);
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
|
|
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_path); // 从文件中读取 cookies
|
|
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;
|
|
// var_dump($response);die;
|
|
if(str_contains($response, "登录成功")){
|
|
// var_dump($cookie_path);die;
|
|
return $cookie_path;
|
|
}else{
|
|
return 'error';
|
|
}
|
|
|
|
|
|
}
|
|
|
|
} |