<?php
    session_start();
    header('Access-Control-Allow-Origin: *');
    error_reporting(E_ALL & ~E_NOTICE);
    //header("Content-type: text/html; charset=gbk");
    /*
        注意:
            本php是gbk编码的,因为mysise就是gbk编码没办法
            json_encode()里面的值要先转换为utf-8才能被识别
    */
    $user=$_POST['user']?$_POST['user']:$_SESSION['user']['user'];
    $pass=$_POST['pass']?$_POST['pass']:$_SESSION['user']['pass'];
    $sise_cookie=$_POST['sise_cookie']?$_POST['sise_cookie']:$_SESSION['user']['sise_cookie'];

    //echo $_POST['sise_cookie'];


    //测试账号110
    if($_POST['user']=='110'&&$_POST['pass']=='110') {
        include("./user.php");
        exit();
    }


    //登录页面
    if($_GET["method"] == 'login'){            
        $curlpost="number=$user&pwd=$pass";              
        $scse_cookie=tempnam('./temp','cookie');               

        //模拟登录scse
        $scse_url="http://my.scse.com.cn/login_pro.asp";               
        LinkCurl($scse_url,$curlpost,$scse_cookie);                  

        //获取管理系统隐藏字段
        $sise_login_url="http://class.sise.com.cn:7001/sise/login.jsp";            
        $sise_login_html=getCurlCon($sise_login_url,$scse_cookie);
        preg_match('/<input type=\"hidden\" name=\"(.*)\"  value=\"(.*)\">/', $sise_login_html,$arr);   
        //print_r($arr);

        //模拟登录管理系统
        $curlpost="username=$user&password=$pass&$arr[1]=$arr[2]"; 
        $sise_cookie=tempnam('./temp','cookie');               
        $sise_login_check_url="http://class.sise.com.cn:7001/sise/login_check.jsp";        
        LinkCurl($sise_login_check_url,$curlpost,$sise_cookie); 

        //正常用户登录
        $res = array(
            "code" => 404,
            "msg" => "failed"
        );
        $course_url="http://class.sise.com.cn:7001/sise/module/student_schedular/student_schedular.jsp";
        $course_html=getCurlCon($course_url,$sise_cookie);
        preg_match_all('/<span class=\"style16\">((.*) &nbsp;(.*) &nbsp;(.*) &nbsp;(.*))<\/span>/', $course_html,$user_info);
        if(!empty($user_info[2][0])){
            //登录成功后保存用户数据
            $_SESSION['user']= array(
                'user' => $user,
                'pass' => $pass,
                'sise_cookie' => $sise_cookie
            );
            $res = array(
                "code" => 200,
                "msg" => "success",
                'sise_cookie' => $sise_cookie
            );
        }
        print_r(json_encode($res));
    }

    //课程表页面
    if($_GET["method"] == 'course'){
        //正常用户登录
        $res = array(
            "code" => 404,
            "msg" => "failed",
            "resData" => []
        );
        $course_url="http://class.sise.com.cn:7001/sise/module/student_schedular/student_schedular.jsp";
        $course_html=getCurlCon($course_url,$sise_cookie);
        preg_match_all('/<span class=\"style16\">(.*) &nbsp;(.*) &nbsp;(.*) &nbsp;(.*)<\/span>/U', $course_html,$user_info);
        preg_match_all("/<td width=\'10%\' align=\'left\' valign=\'top\' class=\'font12\'>(.*)<\/td>/U", $course_html,$course);
        $res_course=array();
        for($i=0;$i<8;$i++){
            for($j=$i*7,$k=0;$j<$i*7+7;$j++,$k++){
                if ($course[1][$j] == '&nbsp;') $course[1][$j] = '';
                if($k!=5 && $k!=6) {
                    $res_course[$i][$k] = iconv('gbk', 'utf-8', $course[1][$j]);
                }   
            }
        }
        $res = array(
            "code" => 200,
            "msg" => "success",
            "resData" => array(
                "info" => array(
                    "stuNum" => iconv('gbk', 'utf-8', mb_substr($user_info[1][0],6,null)),
                    "name" => iconv('gbk', 'utf-8', mb_substr($user_info[2][0],6,null)),
                    "grade" => iconv('gbk', 'utf-8', mb_substr($user_info[3][0],6,null)),
                    "major" => iconv('gbk', 'utf-8', mb_substr($user_info[4][0],6,null)),
                ),
                "course" => $res_course
            )
        );
        print_r(json_encode($res));
        //print_r($res_course);
    }

    //查找老师页面
    if($_GET["method"] == 'teacher'){
        // gei请求的name查询字符串
        $name = $_GET["name"];
        //获取老师的json数据库
        $data = json_decode(file_get_contents("./json/teacher.json" ));
        //老师的信息
        $arr = array();
        //响应数据
        $res = array();
        //查询json数据库
        for($i=0;$i<count($data);$i++){
            if($data[$i]->name == $name){
                $arr = $data[$i];
            }
        }
        //判断查询数据
        if(!empty($arr)){
            //如果工号为三位就前面加个0
            if(mb_strlen($arr->num) ==3 ){
                $arr->num = "0".$arr->num;
            }
            $res = array(
                "code" => 200,
                "msg" => "success",
                "resData" => $arr
            );
        } else {
            $res = array(
                "code" => 404,
                "msg" => "failed",
                "resData" => array()
            );
        }
        print_r(json_encode($res));
    }

    //考勤信息页面
    if($_GET["method"] == 'attendance'){
        //正常用户登录
        $res = array(
            "code" => 404,
            "msg" => "failed",
            "resData" => []
        );
        $main_url="http://class.sise.com.cn:7001/sise/module/student_states/student_select_class/main.jsp";
        $main_html=getCurlCon($main_url,$sise_cookie);
        preg_match_all('/window\.location=\'\.\.\/\.\.\/\.\.\/\.\.\/\.\.\/(.*)\'\"/Um', $main_html,$main);
        $attendance_url='http://class.sise.com.cn:7001/'.$main[1][1];
        $attendance_html = getCurlCon($attendance_url,$sise_cookie);
        //print_r($attendance_html);
        preg_match_all('/<td>(.*)(\d+)<\/td>/U', $attendance_html,$count);
        preg_match_all('/<td align=\"center\">(.*)<\/td>/U', $attendance_html,$attendance);
        $res_attendance=array();
        for($i=0;$i<count($attendance[1])/3;$i++){
            for($j=$i*3,$k=0;$j<$i*3+3;$j++,$k++){
                switch ($k) {
                    case 0:
                        $res_attendance[$i]["num"] = iconv('gbk', 'utf-8', $attendance[1][$j]);
                        break;
                    case 1:
                        $res_attendance[$i]["name"] = iconv('gbk', 'utf-8', $attendance[1][$j]);
                        break;
                    case 2:
                        //匹配请假次数
                        preg_match_all('/\[<a href=\'(.*)\'>(.*)<\/a>\]/U', $attendance[1][$j],$count);
                        if(empty($count[2][0])){
                            $res_attendance[$i]["detail"] = iconv('gbk', 'utf-8', mb_substr($attendance[1][$j],0,4)).$count[2][0];
                        }else{
                            $res_attendance[$i]["detail"] = iconv('gbk', 'utf-8', mb_substr($attendance[1][$j],0,4)).$count[2][0].'次';
                        }
                        break;                  
                    default:
                        break;
                }                               
            }
        }
        $res = array(
            "code" => 200,
            "msg" => "success",
            "resData" => array(
                "total" => $count[2][0],
                "list" => $res_attendance
            )
        );
        print_r(json_encode($res));
    }

    //模拟登录函数
    function LinkCurl($url,$curlpost,$cookie_file){
        $curl=curl_init($url);                         
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);         
        curl_setopt($curl, CURLOPT_POST, 1);                   
        curl_setopt($curl, CURLOPT_POSTFIELDS, $curlpost);            
        curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file);         
        curl_exec($curl);                          
        curl_close($curl);                         
    }

    //模拟登录后获取页面内容函数
    function getCurlCon($url,$cookie_file){
        $curl=curl_init($url);                         
        curl_setopt($curl, CURLOPT_HEADER, 0);             
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);         
        curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file);         
        $data=curl_exec($curl);    
        curl_close($curl);                         
        return $data;
    }

?>
Logo

前往低代码交流专区

更多推荐