コード例 #1
0
ファイル: Elective.php プロジェクト: qious/Hnust
 public function getList($term = null)
 {
     if (empty($term)) {
         $term = $this->term;
     }
     //随机登陆
     $passwdClass = new Passwd($this->sid);
     $students = $passwdClass->randJwc();
     foreach ($students as $student) {
         $this->sid = $student['sid'];
         $this->passwd = $student['jwc'];
         try {
             parent::login();
         } catch (\Exception $e) {
             if (Config::RETURN_NEED_PASSWORD === $e->getCode()) {
                 continue;
             }
             throw new \Exception($e->getMessage(), $e->getCode());
         }
     }
     //获取列表
     $list = parent::getList($term);
     //更新数据库
     $sql = 'INSERT INTO `elective_list`(
                 `school`, `course`, `college`, `credit`, `total`, `remain`,
                 `teacher`, `week`, `time`, `place`, `url`, `term`
             ) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY
             UPDATE `credit` = ?, `total` = ?, `remain` = ?,
             `week` = ?, `time` = ?, `place` = ?';
     $sqlArr = array();
     foreach ($list as $item) {
         $sqlArr[] = array($item['school'], $item['course'], $item['college'], $item['credit'], $item['total'], $item['remain'], $item['teacher'], $item['week'], $item['time'], $item['place'], $item['url'], $item['term'], $item['credit'], $item['total'], $item['remain'], $item['week'], $item['time'], $item['place']);
     }
     Mysql::executeMultiple($sql, $sqlArr);
     return $list;
 }
コード例 #2
0
ファイル: Update.php プロジェクト: qious/Hnust
 public function passwd()
 {
     //全负荷执行
     Config::fullLoad();
     //添加学生学号到密码数据库
     $sql = 'INSERT INTO `weak`(`passwd`)
               (SELECT `sid` FROM `student` WHERE `sid` NOT IN
                 (SELECT `passwd` FROM `weak`))';
     Mysql::execute($sql);
     //添加教工号到数据库
     $sql = 'INSERT INTO `weak`(`passwd`)
               (SELECT `tid` FROM `teacher` WHERE `tid` NOT IN
                 (SELECT `passwd` FROM `weak`))';
     Mysql::execute($sql);
     //更新数据库
     while (true) {
         $sql = "SELECT `passwd` FROM `weak` WHERE `sha1` = '' OR `md5` = '' LIMIT 10000";
         $passwds = Mysql::execute($sql);
         if (empty($passwds)) {
             break;
         }
         $sql = 'UPDATE `weak` SET `sha1` = ?, `md5` = ? WHERE `passwd` = ? LIMIT 1';
         for ($i = 0; $i < count($passwds); $i++) {
             $passwd = $passwds[$i]['passwd'];
             $passwds[$i] = array(sha1($passwd), md5($passwd), $passwd);
         }
         if (Mysql::executeMultiple($sql, $passwds)) {
             Log::file('passwd', '成功更新' . count($passwds) . '条密码');
         } else {
             Log::file('passwd', '密码更新失败');
             break;
         }
     }
 }