3.重点来了!

不赘述

请移步 正方爬虫简介

奈何 python用的没有php顺利,所以用php写了一个

直接使用大神的 解密包

login_bg_pic.jpg

ps:新版正方教务还很好看

直接上代码

// 用的laravel 框架
// config('sys.server_url')  是目标教务系统的地址[![login_bg_pic.jpg](http://www.xingxings.cn/uploads/images/gallery/2020-12/scaled-1680-/nOK7UvMbzmbdMIuC-login_bg_pic.jpg)](http://www.xingxings.cn/uploads/images/gallery/2020-12/nOK7UvMbzmbdMIuC-login_bg_pic.jpg)
// 引入解密包
// 
	include_once  base_path('extend/rsa/Crypt/RSA.php') ;

        $student_id = '你的学号';
        $password = '你的密码';

        $key_url = config('sys.server_url') . '/xtgl/login_getPublicKey.html?time=' . time() . '&_=' . time();
        $login_url = config('sys.server_url') . '/xtgl/login_slogin.html?language=zh_CN&_t=' . time();

        // 存储cookie
        $jar = new \GuzzleHttp\Cookie\CookieJar();
        $login_response = Http::withOptions([
            'cookies' => $jar,
            'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36',
            'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
            'Referer' => $login_url
        ])->get($login_url);
        // 获取csrftoken
        $ql = QueryList::html($login_response->body());
        $csrftoken = $ql->find('#csrftoken')->val();
        $key_response = Http::withOptions([
//            'debug' => true,
            'cookies' => $login_response->cookies(),
            'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36',
            'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
            'Referer' => $login_url
        ])->get($key_url);
		// 获取key
        $key = json_decode($key_response->body(), true);
        $exponent   = $key['exponent'];
        $modulus    = $key['modulus'];
        $rsa        = new \Crypt_RSA();
        $mykey['n'] = new \Math_BigInteger(bin2hex(base64_decode($modulus)), 16);
        $mykey['e'] = new \Math_BigInteger(bin2hex(base64_decode($exponent)), 16);
        $rsa->loadKey($mykey, CRYPT_RSA_PUBLIC_FORMAT_RAW);
        $rsa->getPublicKey(CRYPT_RSA_ENCRYPTION_PKCS1);
        $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
        $res      = $rsa->encrypt($password);
        $password = base64_encode($res);
        $response = Http::withOptions([
//            'debug' => true,
            'cookies' => $login_response->cookies(),
            'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36',
            'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
            'Referer' => $login_url
        ])->asForm()->post($login_url, [
            'csrftoken'=>$csrftoken,
            'yhm' => $student_id ,
            'mm'  => $password
        ]);
		// 判断是否有错误信息
        if (strpos($response->body(), '用户名或密码不正确') !== false) {
            // 不能输入过多
            return '用户名或密码不正确!';
        }

        dd('success');


备案号:鲁ICP备17018368号-1