Skip to content

Commit

Permalink
修正校园网升级后注销和获取公告功能失败的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
CHN-STUDENT committed Jun 29, 2018
1 parent 5980ffc commit 96ce5dc
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 73 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SRUN-3K登陆器UI界面学习
本程序受大佬学长们的 Python , Html , Java , C#版启发制作。


## 注意:现在校园网更新后本版本可能已经失效,正在维护中,请先使用网页版 https://github.com/noisky/srun3k-sb-client ,感谢~ ##
## 注意:虽然已经修复注销和公告系统可以正常使用,但是还是希望有人能和一起研究深入,给我指点,帮助我更好,感谢~ ##


-----------------------
Expand Down
169 changes: 98 additions & 71 deletions srun-3k-ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "QtNetwork/QNetworkRequest"
#include "QTextCodec"
#include "QJsonObject"
#include "QJsonArray"
#include "QJsonDocument"
#include "QFile"
#include "QTimer"
Expand Down Expand Up @@ -37,6 +38,7 @@ QString error4="login_error#INFO failed, BAS respond timeout."; //ACI
QString error5="login_error#You are not online."; //你不在线
QString error6="login_error#E2901: (Third party 1)Status_Err"; //状态错误,一般指欠费
QString error7="login_error#E2901: (Third party 1)User Locked"; //用户锁定,一般也指欠费
QString error8="ip_already_online_error"; //IP已经在线
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
Expand Down Expand Up @@ -198,7 +200,7 @@ void MainWindow::Start(void)
void MainWindow::GetServerInfo(void)
{
QNetworkAccessManager *GetServerMessageManager = new QNetworkAccessManager(this);
QString url=login_server+"/get_msg.php";
QString url=login_server+"/v2/srun_portal_message";
GetServerMessageManager->get(QNetworkRequest(QUrl(url)));
connect(GetServerMessageManager, &QNetworkAccessManager::finished,[this](QNetworkReply *reply){
if (reply->error() == QNetworkReply::NoError)
Expand All @@ -207,47 +209,59 @@ void MainWindow::GetServerInfo(void)
QNetworkAccessManager *GetINFOManager = new QNetworkAccessManager(this);
GetINFOManager->get(QNetworkRequest(QUrl(login_server+"/cgi-bin/rad_user_info")));
connect(GetINFOManager, SIGNAL(finished(QNetworkReply*)),this,SLOT(GET_INFO_Finished(QNetworkReply*)));
/*对这次公告进行转码*/
QTextCodec *codec =QTextCodec::codecForName("GB2312");
QString all = codec->toUnicode(reply->readAll());
ui->Message_show->setText(all);
/*自动读取上次公告*/
QString servermessage=QCoreApplication::applicationDirPath()+"/lastservermessage.txt";
QFile m(servermessage);
if(m.open(QIODevice::ReadOnly))
{//读取上次公告文件
QTextStream op(&m);
QString ServerMessage=op.readAll();
m.close();//关闭上次读的动作
if(ServerMessage!=all)
{//服务器公告更新
ui->ShowServerMessage->setText("显示(新)公告");
/*自动重写公告*/
QFile r(servermessage);
if(r.open(QIODevice::WriteOnly|QIODevice::Truncate))
{
QTextStream ts(&r);
ts<<all;
r.close();
}
else
ui->Message_show->setText("无法将服务器公告写入文件!");
}
}
else
{//如果读取不到上次公告文件
ui->ShowServerMessage->setText("显示(新)公告");
/*自动重写公告*/
QFile r(servermessage);
if(r.open(QIODevice::WriteOnly|QIODevice::Truncate))
{
QTextStream ts(&r);
ts<<all;
r.close();
}
else
ui->Message_show->setText("无法将服务器公告写入文件!");
}
//QTextCodec *codec =QTextCodec::codecForName("GB2312");
QByteArray all =reply->readAll();
QJsonDocument info = QJsonDocument::fromJson(all);
QJsonObject obj=info.object();
if(obj.contains("Data"))
{

QJsonValue value=obj.value("Data");
QJsonArray message=value.toArray();
QJsonValue info = message.at(0);
QString display="<h3>"+\
info.toObject().value("Title").toString()+"</h3>------------------<br>"+\
info.toObject().value("Content").toString();
ui->Message_show->setText(display);
/*自动读取上次公告*/
QString servermessage=QCoreApplication::applicationDirPath()+"/lastservermessage.txt";
QFile m(servermessage);
if(m.open(QIODevice::ReadOnly))
{//读取上次公告文件
QTextStream op(&m);
QString ServerMessage=op.readAll();
m.close();//关闭上次读的动作
if(ServerMessage!=display)
{//服务器公告更新
ui->ShowServerMessage->setText("显示(新)公告");
/*自动重写公告*/
QFile r(servermessage);
if(r.open(QIODevice::WriteOnly|QIODevice::Truncate))
{
QTextStream ts(&r);
ts<<display;
r.close();
}
else
ui->Message_show->setText("无法将服务器公告写入文件!");
}
}
else
{//如果读取不到上次公告文件
ui->ShowServerMessage->setText("显示(新)公告");
/*自动重写公告*/
QFile r(servermessage);
if(r.open(QIODevice::WriteOnly|QIODevice::Truncate))
{
QTextStream ts(&r);
ts<<display;
r.close();
}
else
ui->Message_show->setText("无法将服务器公告写入文件!");
}
}

}
else
{
Expand All @@ -274,7 +288,7 @@ void MainWindow::GET_INFO_Finished(QNetworkReply *reply)
ui->stackedWidget->setCurrentIndex(2);
if(ui->AUTO_LOGIN->isChecked())
{
QTimer::singleShot(3000,[this](){ui->LoginButton->click();});
QTimer::singleShot(30,[this](){ui->LoginButton->click();});
}
}
else
Expand Down Expand Up @@ -496,14 +510,22 @@ void MainWindow::on_LogoutButton_clicked()
QNetworkAccessManager *LogoutManger = new QNetworkAccessManager(this);
QByteArray POST;
QNetworkRequest request;
//fixed logout issue
char *name=yourname.toLatin1().data();
QByteArray NAME_ENCRYPT="";
for (;*name!='\0';name++)
{//用户名加密
NAME_ENCRYPT.append(QString(*name+4));
}
POST.append(post);
POST.append(acid);
POST.append("&mac=");
POST.append(mac);
POST.append("&type=");
POST.append(type);
POST.append("&username=");
POST.append(yourname);
POST.append("&username=%7BSRUN3%7D%0D%0A");
//POST.append(yourname);
POST.append(NAME_ENCRYPT.toPercentEncoding());
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
request.setUrl(QUrl(login_server+":"+login_port+"/cgi-bin/srun_portal"));
LogoutManger->post(request,POST);
Expand All @@ -518,29 +540,29 @@ void MainWindow::POST_LOGOUT_Finished(QNetworkReply *reply)
QString all = codec->toUnicode(reply->readAll());
if(all.indexOf(logout_ok)!=-1)
{
QTimer::singleShot(1000,[this](){state=0;ui->ShowState->setText("注销中......成功!");});
QTimer::singleShot(3000,[this](){ui->stackedWidget->setCurrentIndex(2);ui->LogoutButton->setEnabled(true);});
QTimer::singleShot(10,[this](){state=0;ui->ShowState->setText("注销中......成功!");});
QTimer::singleShot(30,[this](){ui->stackedWidget->setCurrentIndex(2);ui->LogoutButton->setEnabled(true);});
}
else if(all.indexOf(error5)!=-1)
{
QTimer::singleShot(1000,[this](){state=0;ui->ShowState->setText("您不在线,无法完成注销!");});
QTimer::singleShot(3000,[this](){ui->stackedWidget->setCurrentIndex(2);ui->LogoutButton->setEnabled(true);});
QTimer::singleShot(10,[this](){state=0;ui->ShowState->setText("您不在线,无法完成注销!");});
QTimer::singleShot(30,[this](){ui->stackedWidget->setCurrentIndex(2);ui->LogoutButton->setEnabled(true);});
}
else if(all.indexOf(error4)!=-1)
{
QTimer::singleShot(1000,[this](){ui->ShowState->setText("注销中......ACID错误!请更改高级设置中的ACID值后重试!");});
QTimer::singleShot(3000,[this](){ui->LogoutButton->setEnabled(true);});
QTimer::singleShot(10,[this](){ui->ShowState->setText("注销中......ACID错误!请更改高级设置中的ACID值后重试!");});
QTimer::singleShot(30,[this](){ui->LogoutButton->setEnabled(true);});
}
else if(all.indexOf(error1)!=-1)
{
QTimer::singleShot(1000,[this](){ui->ShowState->setText("注销中......错误!请重试!");});
QTimer::singleShot(3000,[this](){ui->LogoutButton->setEnabled(true);});
QTimer::singleShot(10,[this](){ui->ShowState->setText("注销中......错误!请重试!");});
QTimer::singleShot(30,[this](){ui->LogoutButton->setEnabled(true);});
}
}
else
{
QTimer::singleShot(1000,[this](){ui->ShowState->setText("注销中......网络错误!请重试!");});
QTimer::singleShot(3000,[this](){ui->LogoutButton->setEnabled(true);});
QTimer::singleShot(10,[this](){ui->ShowState->setText("注销中......网络错误!请重试!");});
QTimer::singleShot(30,[this](){ui->LogoutButton->setEnabled(true);});
}
reply->deleteLater();//回收
}
Expand Down Expand Up @@ -639,52 +661,57 @@ void MainWindow::POST_LOGIN_Finished(QNetworkReply *reply)
QString all = codec->toUnicode(reply->readAll());
if(all.indexOf(login_ok_short)!=-1)
{
QTimer::singleShot(1000,[this](){
QTimer::singleShot(10,[this](){
state=1;
QNetworkAccessManager *GetINFOManager = new QNetworkAccessManager(this);
GetINFOManager->get(QNetworkRequest(QUrl(login_server+"/cgi-bin/rad_user_info")));
connect(GetINFOManager, SIGNAL(finished(QNetworkReply*)),this,SLOT(GET_INFO_Finished(QNetworkReply*)));
ui->ShowState->setText("登陆中......成功!");});
QTimer::singleShot(3000,[this](){ui->stackedWidget->setCurrentIndex(3);ui->LoginButton->setEnabled(true);});
QTimer::singleShot(30,[this](){ui->stackedWidget->setCurrentIndex(3);ui->LoginButton->setEnabled(true);});
}
else if((all.indexOf(error6)!=-1)||(all.indexOf(error7)!=-1))
{
QTimer::singleShot(1000,[this](){ui->ShowState->setText("您已欠费,无法使用,请充值!");});
QTimer::singleShot(3000,[this](){ui->LoginButton->setEnabled(true);});
QTimer::singleShot(10,[this](){ui->ShowState->setText("您已欠费,无法使用,请充值!");});
QTimer::singleShot(30,[this](){ui->LoginButton->setEnabled(true);});
}
else if(all.indexOf(error2)!=-1)
{
file_state=-1;//密码错误或者用户名错误就会重写储存登陆信息
QTimer::singleShot(1000,[this](){ui->ShowState->setText("密码错误,请检查输入后重试!");});
QTimer::singleShot(3000,[this](){ui->LoginButton->setEnabled(true);});
QTimer::singleShot(10,[this](){ui->ShowState->setText("密码错误,请检查输入后重试!");});
QTimer::singleShot(30,[this](){ui->LoginButton->setEnabled(true);});
}
else if(all.indexOf(error3)!=-1)
{
file_state=-1;//密码错误或者用户名错误就会重写储存登陆信息
QTimer::singleShot(1000,[this](){ui->ShowState->setText("用户名错误,请检查输入后重试!");});
QTimer::singleShot(3000,[this](){ui->LoginButton->setEnabled(true);});
QTimer::singleShot(10,[this](){ui->ShowState->setText("用户名错误,请检查输入后重试!");});
QTimer::singleShot(30,[this](){ui->LoginButton->setEnabled(true);});
}
else if(all.indexOf(error4)!=-1)
{
QTimer::singleShot(1000,[this](){ui->ShowState->setText("登陆中......ACID错误!请更改高级设置中的ACID值后重试!");});
QTimer::singleShot(3000,[this](){ui->LoginButton->setEnabled(true);});
QTimer::singleShot(10,[this](){ui->ShowState->setText("登陆中......ACID错误!请更改高级设置中的ACID值后重试!");});
QTimer::singleShot(30,[this](){ui->LoginButton->setEnabled(true);});
}
else if(all.indexOf(error1)!=-1)
{
QTimer::singleShot(1000,[this](){ui->ShowState->setText("登陆中......错误!请重试!");});
QTimer::singleShot(3000,[this](){ui->LoginButton->setEnabled(true);});
QTimer::singleShot(10,[this](){ui->ShowState->setText("登陆中......错误!请重试!");});
QTimer::singleShot(30,[this](){ui->LoginButton->setEnabled(true);});
}
else if(all.indexOf(error8)!=-1)
{
QTimer::singleShot(10,[this](){ui->ShowState->setText("登陆中......当前用户已经在线!请重试!");});
QTimer::singleShot(30,[this](){ui->LoginButton->setEnabled(true);});
}
else
{
QTimer::singleShot(1000,[this](){ui->ShowState->setText("登陆中......错误!请重试!");});
QTimer::singleShot(3000,[this](){ui->LoginButton->setEnabled(true);});
QTimer::singleShot(10,[this](){ui->ShowState->setText("登陆中......错误!请重试!");});
QTimer::singleShot(30,[this](){ui->LoginButton->setEnabled(true);});
}

}
else
{
QTimer::singleShot(1000,[this](){ui->ShowState->setText("登陆中......网络错误!请重试!");});
QTimer::singleShot(3000,[this](){ui->LoginButton->setEnabled(true);});
QTimer::singleShot(10,[this](){ui->ShowState->setText("登陆中......网络错误!请重试!");});
QTimer::singleShot(30,[this](){ui->LoginButton->setEnabled(true);});
}
reply->deleteLater();//回收
}
Expand Down
4 changes: 3 additions & 1 deletion srun-3k-ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ QMenu::indicator {width: 13px;height: 13px;} </string>
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;校园网登录器 V1.04&lt;/p&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;校园网登录器 V1.05&lt;/p&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;By CHN-STUDENT&lt;/p&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Copyright(C) 2018&lt;/p&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;-----------------------&lt;/p&gt;
Expand All @@ -1270,6 +1270,8 @@ p, li { white-space: pre-wrap; }
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;-----------------------&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;更新日志:&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;V1.05 修正校园网升级后无法注销和获取公告失败的问题。&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;V1.04 修复公告文件重复写入文件,改变个人信息读取方法,界面居中化改观。&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;V1.03.3.1修复TAB聚焦问题,修复右键菜单选中高亮,支持在关于里直接打开链接。&lt;/p&gt;
Expand Down

0 comments on commit 96ce5dc

Please sign in to comment.