<?php
/**
* 学信网
* User: Reaper
* Date: 2021/8/20
*/
namespace App\Entities;
use QL\QueryList;
class ChSi
{
//学信网账号密码
static $User, $PassWord, $School;
// 初始化抓取学籍信息
static protected function login()
{
$url = "https://account.chsi.com.cn/passport/login?service=https%3A%2F%2Fmy.chsi.com.cn%2Farchive%2Fj_spring_cas_security_check";
$token = QueryList::get($url);
$lt = $token->find("input")->eq(2)->attr('value');
$execution = $token->find("input")->eq(3)->attr('value');
$_eventId = $token->find("input")->eq(4)->attr('value');
$submit = $token->find("input")->eq(5)->attr('value');
if (empty($lt) || empty($execution) || empty($_eventId) || empty($submit)) {
self::login();
return 0;
}
$postData = array(
'lt' => $lt,
'username' => self::$User,
'password' => self::$PassWord,
"execution" => $execution,
'_eventId' => $_eventId,
'submit' => $submit
);
$correct = $token->post($url, $postData)->get("https://my.chsi.com.cn/archive/gdjy/check/show.action?from=xj")->getHtml();
if (empty($correct)) {
self::login();
return 0;
}
if (strpos($correct, "微信登录仅支持个人用户使用") != false) {
return ["code" => 400, "msg" => "您输入的用户名或密码有误。"];
}
if (strpos($correct, "输入就读或毕业的学校名称") != false) {
preg_match("/checkP: \'(.*?)\'/", $correct, $checkP);
preg_match("/checkV: \'(.*?)\'/", $correct, $checkV);
$school = $token->post("https://my.chsi.com.cn/archive/gdjy/check/checkarchive.action", [
"from" => "xj",
"yxmc" => self::$School,
$checkP[1] => $checkV[1]
])->getHtml();
$school = json_decode($school, 1);
if (empty($school["result"]["backUrl"])) {
if ($school["result"]["leftTimes"]) {
return ["code" => 401, "msg" => $school["result"]["errorMessage"]] . ",目前已验证次数:" . $school["result"]["checkFailTimes"] . "剩余次数:" . $school["result"]["leftTimes"];
} else {
return ["code" => 401, "msg" => "验证次数已用完,请明天在试。"];
}
}
}
$UserHtml = $token->get("https://my.chsi.com.cn/archive/gdjy/xj/show.action");
$src = $UserHtml->find(".xjxx-img")->src;
return $token->get($src)->getHtml(0);
}
static protected function captcha()
{
$id = self::$User . self::$PassWord . self::$School . rand(10000, 99999);
return "https://account.chsi.com.cn/passport/captcha.image?id=" . $id;
}
static public function StudentStatus($User, $PassWord, $School)
{
self::$User = $User;
self::$PassWord = $PassWord;
self::$School = $School;
if (empty($User) || empty($PassWord) || empty($School)) {
return ["code" => 402, "msg" => "账号密码学校不能为空"];
}
$login = self::login();
return $login;
}
}
最后修改:2023 年 07 月 25 日
© 允许规范转载