Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第一次PR , 增加了几个比较实用的功能~ #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/public/adminer.php
/public/phpinfo.php
/data/amsProxy.db
/runtime/cache
/runtime/views
/runtime
/public/img/captcha
/public/img/cache
*.swp
.idea
/bower_components
Expand All @@ -12,3 +13,4 @@ tags
*.js.map
.ropeproject
*.pyc
config.php
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
广西民族大学教务系统代理
========================

惠大微报做的更新在`weibao`分支~ 也可以查看上游的[PR](https://github.com/xshwz/amsproxy/pull/2)

http://xsh.gxun.edu.cn/ams/

生成sqlite数据库文件
----

可以参考`data/Makefile`
或者直接运行下面命令生成`amsProxy.db`文件
可以参考`data/Makefile`
或者直接运行下面命令生成`amsProxy.db`文件

```shell
cd data
Expand Down Expand Up @@ -39,8 +41,8 @@ params 的配置
学校的url

### schoolcode
青果用于验证请求真实性.
每个学校的`schoolcode`都不一样.
青果用于验证请求真实性.
每个学校的`schoolcode`都不一样.

**可以通过查看学校教务系统的html页面源代码, 获得自己学校的`schoolcode`.**

Expand Down
17 changes: 13 additions & 4 deletions config.php → config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
),
'components' => array(
'db' => array(
'connectionString' => 'sqlite:../data/amsProxy.db',
// 'connectionString' => 'sqlite:../data/amsProxy.db',
'class'=>'CDbConnection',
'connectionString'=>'',
'username'=>'',
'password'=>'',
'emulatePrepare'=>true,
),
'viewRenderer' => array(
'class' => 'ext.view.CPradoViewRenderer',
Expand All @@ -31,7 +36,8 @@
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'' => 'site/home/index',
'' => 'proxy/',
// '' => 'site/home/index',
'about' => 'site/home/about',
'faq' => 'site/home/faq',
'wechat' => 'site/wechat/index',
Expand All @@ -52,11 +58,14 @@
),
'params' => array(
'debug' => true,
'baseUrl' => 'http://ams.gxun.edu.cn/',
'schoolcode' => '10608',
'curl_debug' => true,
'useCaptcha'=>true,
'baseUrl' => 'http://proxy.ngrok.deepkolos.cn:8081/jwweb/',
'schoolcode' => '10577',
'superAdmin' => array(
'110263100136',
'111253050122',
'1514080902121'
),
),
);
146 changes: 146 additions & 0 deletions data/edusystem.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
-- phpMyAdmin SQL Dump
-- version 4.6.5.2
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: 2017-01-19 06:53:57
-- 服务器版本: 5.7.13
-- PHP Version: 5.6.22

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `edusystem`
--

-- --------------------------------------------------------

--
-- 表的结构 `common`
--

CREATE TABLE `common` (
`id` varchar(10) NOT NULL,
`rankExamForm` text
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


-- --------------------------------------------------------

--
-- 表的结构 `message`
--

CREATE TABLE `message` (
`id` int(11) NOT NULL,
`sender` text NOT NULL,
`receiver` text NOT NULL,
`message` text NOT NULL,
`time` decimal(10,0) NOT NULL,
`state` int(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- 表的结构 `setting`
--

CREATE TABLE `setting` (
`start_date` date NOT NULL,
`end_date` date NOT NULL,
`wechat_auto_reply` int(11) NOT NULL,
`wechat_token` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- 转存表中的数据 `setting`
--

INSERT INTO `setting` (`start_date`, `end_date`, `wechat_auto_reply`, `wechat_token`) VALUES
('2017-02-16', '2017-07-02', 1, 'you-token');

-- --------------------------------------------------------

--
-- 表的结构 `student`
--

CREATE TABLE `student` (
`sid` varchar(20) NOT NULL,
`pwd` varchar(20) DEFAULT NULL,
`archives` text,
`course` text,
`scoreAffirm` text,
`validScore` text,
`rank_exam` text,
`exam_arrangement` text,
`theory_subject` text,
`last_login_time` date DEFAULT NULL,
`openid_subscribe` text,
`openid_server` text,
`is_admin` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- 表的结构 `wechat_log`
--

CREATE TABLE `wechat_log` (
`id` int(11) NOT NULL,
`message` text NOT NULL,
`state` int(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `common`
--
ALTER TABLE `common`
ADD PRIMARY KEY (`id`);

--
-- Indexes for table `message`
--
ALTER TABLE `message`
ADD PRIMARY KEY (`id`);

--
-- Indexes for table `student`
--
ALTER TABLE `student`
ADD PRIMARY KEY (`sid`);

--
-- Indexes for table `wechat_log`
--
ALTER TABLE `wechat_log`
ADD PRIMARY KEY (`id`);

--
-- 在导出的表使用AUTO_INCREMENT
--

--
-- 使用表AUTO_INCREMENT `message`
--
ALTER TABLE `message`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- 使用表AUTO_INCREMENT `wechat_log`
--
ALTER TABLE `wechat_log`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
104 changes: 78 additions & 26 deletions extensions/controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,36 +54,80 @@ public function init() {
/**
* @return string error message
*/
public function login($sid, $pwd, $captcha) {
if ($error = $this->AmsProxy()->login($sid, $pwd, $captcha)) {
return $error;
} else {
$this->saveStudent();
$this->updateStudentLastLoginTime(
Student::model()->findByPk($sid));
$_SESSION['session'] = $this->AmsProxy()->getSession();
$_SESSION['student'] = array(
'sid' => $sid,
'pwd' => $pwd,
'isAdmin' => $this->isAdmin($sid),
);
public function login($sid, $pwd, $captcha=null, $force=false) {
$student = Student::model()->findByPk($sid);

if( ($captcha == null|| $captcha == '') && isset($student->sid) && $pwd == $student->pwd && !$force){
$this->afterLogin($sid,$pwd,false);
}elseif($captcha){
if ($error = $this->AmsProxy()->login($sid, $pwd, $captcha)) {
return $error;
} else {
$this->afterLogin($sid,$pwd,true);
}
}else{
$count = 0;
$url = 'public/img/captcha/'.$sid.'.jpg';
$url = dirname(__FILE__).'/../../'.$url;
do{
$check = file_put_contents($url,$this->AmsProxy()->getCaptcha());
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->AmsProxy()->orcApi.'http://proxy.deepkolos.cn/img/captcha/'.$sid.'.jpg?t='.time());
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, "3");//单位为秒
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true); //完成重定向
// curl_setopt($ch,CURLOPT_PROXY,'127.0.0.1:8887');//设置代理服务器
// curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);//若PHP编译时不带openssl则需要此行
$captcha = curl_exec($ch);
curl_close($ch);

// $error = $captcha;
if(strlen($captcha) == 4)
if($error = $this->AmsProxy()->login($sid, $pwd, $captcha)){
;
}else{
$this->afterLogin($sid,$pwd,true);
}
else{
$error = '验证码错误!';
// echo '收到的验证码长度为:'.$captcha.'<br>';
}
$count++;
}while($error == '验证码错误!' && $count < 5);
// unlink($url);
if($error != null)
return $error;
}
}

/**
* @return bool
*/
public function isLogged() {
return isset($_SESSION['student']);
}

public function saveStudent() {
if (Student::model()->findByPk($this->AmsProxy()->sid) == null) {
public function afterLogin($sid,$pwd,$setSession){
$this->saveStudent($sid,$pwd);
$this->updateStudentLastLoginTime(
Student::model()->findByPk($sid));
if($setSession)
$_SESSION['session'] = $this->AmsProxy()->getSession();
$_SESSION['student'] = array(
'sid' => $sid,
'pwd' => $pwd,
'isAdmin' => $this->isAdmin($sid),
);
}
public function saveStudent($sid,$pwd) {
$student = Student::model()->findByPk($sid);
if (!$student) {
$student = new Student;
$student->sid = $this->AmsProxy()->sid;
$student->archives = json_encode($this->get_archives());
$student->save();
}
$student->sid = $sid;
$student->pwd = $pwd;
// $student->archives = json_encode($this->get_archives());
$student->save();
}

/**
Expand Down Expand Up @@ -120,7 +164,8 @@ public function AmsProxy() {
}
else {
$this->amsProxy = new AmsProxy;
$_SESSION['session'] = $this->amsProxy->getSession();
if($this->amsProxy->getSession())
$_SESSION['session'] = $this->amsProxy->getSession();
}
}

Expand Down Expand Up @@ -228,12 +273,15 @@ public function information($message) {
*/
public function weekNumber($date=null) {
if ($date)
$time = strtotime($date);
$now = strtotime($date);
else
$time = time();

$time -= strtotime($this->setting['start_date']);
return (int)($time / 86400 / 7 + 1);
$now = time();
$start = strtotime($this->setting['start_date']);
$week_offset = (int)date('N',$start) - 1;
$start_ajusted = $start - $week_offset * 86400;
$day = ($now - $start_ajusted)/86400;
$week = floor($day/7);
return $week;
}

/**
Expand All @@ -244,6 +292,10 @@ public function createFullUrl($route, $params=array(), $ampersand='&') {
$route, $params, $ampersand);
}

public function noneNull(&$obj){
return (isset($obj))?$obj:null;
}//我觉得应该这个使用宏比较好吧

/**
* get request param with get or post
*
Expand Down
Loading