180 lines
4.0 KiB
PHP
180 lines
4.0 KiB
PHP
<?php
|
||
/*
|
||
* @author:administrator
|
||
* @createTime:2016-07-03
|
||
*/
|
||
header('Content-Type: text/html; charset=utf-8');
|
||
//include_once("../config.php");
|
||
include_once 'LoginResult.class.php';
|
||
//define('SERVERIP','168.160.19.48:8080');
|
||
|
||
Class UserLoginQ2
|
||
{
|
||
|
||
var $loginurl="chinadoi-manage/manage/login.action?";
|
||
var $loginresult=null;
|
||
|
||
var $ip=null;
|
||
|
||
function userlogin( $userName, $password,$ip)
|
||
{
|
||
|
||
if(empty($this->ip))
|
||
$this->ip=SERVERIP;
|
||
|
||
$loginState = "服务器连接失败";
|
||
|
||
/**
|
||
* 模拟登录
|
||
*/
|
||
|
||
//初始化变量
|
||
$cookie_file = COOKIEFILE;
|
||
|
||
$loginurl="chinadoi-manage/manage/login.action?";
|
||
$login_url = "http://$ip/$loginurl";
|
||
|
||
|
||
|
||
$post = "userName=".$userName."&password=".$password;
|
||
|
||
|
||
|
||
$ch = curl_init($login_url);
|
||
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5');
|
||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
|
||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
||
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
|
||
curl_setopt($ch, CURLOPT_POST, 1);
|
||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
||
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
|
||
curl_exec($ch);
|
||
curl_close($ch);
|
||
|
||
//带上cookie文件,访问需要访问的页面
|
||
|
||
$ch = curl_init($login_url);
|
||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
||
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
|
||
$result = curl_exec($ch);
|
||
curl_close($ch);
|
||
|
||
//清理cookie文件
|
||
// unlink($cookie_file);
|
||
|
||
|
||
|
||
//这一块根据自己抓包获取到的网站上的数据来做判断
|
||
|
||
$loginresult=new LoginResult();
|
||
//echo $result;
|
||
|
||
if(strpos($result, "user-login!loginOut.action") !== false)
|
||
{
|
||
$loginState = "登录成功";
|
||
|
||
$arycookie=ReadCookie();
|
||
|
||
//print_r($arycookie);
|
||
|
||
$loginresult->userId=$arycookie["userId"];
|
||
$loginresult->companyType=$arycookie["companyType"];
|
||
|
||
$loginresult->loginState=$loginState;
|
||
|
||
}else{
|
||
$loginresult->loginState= $loginState ;
|
||
exit;
|
||
}
|
||
|
||
|
||
return $loginresult;
|
||
|
||
}
|
||
|
||
|
||
}
|
||
?>
|
||
<?php
|
||
|
||
function ReadCookie()
|
||
{
|
||
$rtn=array();
|
||
|
||
$cookie_file = COOKIEFILE;
|
||
|
||
//$handle = fopen("c:\\folder\\resource.txt", "w+");
|
||
|
||
if(!file_exists($cookie_file))
|
||
{
|
||
return $rtn;
|
||
|
||
}
|
||
|
||
$lines = file($cookie_file);
|
||
|
||
$trows = '';
|
||
|
||
|
||
foreach($lines as $line) {
|
||
|
||
if($line[0] != '#' && substr_count($line, "\t") == 6) {
|
||
|
||
$tokens = explode("\t", $line);
|
||
|
||
$tokens = array_map('trim', $tokens);
|
||
|
||
$tokens[4] = date('Y-m-d h:i:s', $tokens[4]);
|
||
|
||
//echo $tokens[6]."<br/>";
|
||
|
||
if(strpos($tokens[6], "~")!=false )
|
||
{
|
||
|
||
$tmpary=explode("~",$tokens[6]);
|
||
|
||
|
||
|
||
$rtn["userId"]=$tmpary[0];
|
||
$rtn["userName"]=$tmpary[1];
|
||
$rtn["companyType"]=$tmpary[2];
|
||
|
||
return $rtn;
|
||
}
|
||
|
||
// $trows .= '<tr><td>' . implode('</td><td>', $tokens) . '</td></tr>' . PHP_EOL;
|
||
|
||
}
|
||
|
||
}
|
||
//echo '<table>'.PHP_EOL.'<tbody>'.PHP_EOL.$trows.'</tbody>'.PHP_EOL.'</table>';
|
||
|
||
return $rtn;
|
||
}
|
||
|
||
|
||
|
||
?>
|
||
<?php
|
||
/////////// test....
|
||
|
||
/*
|
||
|
||
$userloginQ2=new UserLoginQ2X();
|
||
|
||
$loginresult=$userloginQ2->userlogin("test01", "test01", "168.160.19.48:8080");
|
||
|
||
echo $loginresult->loginState;
|
||
|
||
echo "<br/>";
|
||
|
||
echo $loginresult->userId;
|
||
*/
|
||
|
||
?>
|
||
|