账号登录部分

VUE HTML登录界面
实现账号密码输入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<template>
<div id="app" class="container">

<div style="text-align:center;margin-top:60px;">

<img src="../icon/vlogo.png" style="width:20rem;height:auto;" alt="">

</div>

<form class="form middle">

<br>

<div class="form-group">

<input type="text" class="form-control input100" v-model="userid" placeholder="用户名 / 邮箱"/>

</div>

<div class="form-group">

<!-- <input type="password" class="form-control input100" v-model="usercode" placeholder="密码" @keyup.13="login" /> -->
<!-- Vue 3 Key Modifier on v-on -->
<!-- <input v-on:keyup.delete="confirmDelete" /> -->

<input type="password" class="form-control input100" v-model="usercode" placeholder="密码" v-on:keyup.delete="login" />
</div>

<label class="errorMsg" v-if="errorFlag" v-cloak >{{ errorMsg }}</label>



<div class="form-group btn100">

<button type="button" @click="login" class="btn btn-primary btn100">登陆</button>

</div>

<div class="form-group btn100">

<!-- <a href="./registermobile.html" class="btn btn-default btn100">注册</a> -->
<button v-on:click="Gotoregister">注册</button>


</div>

<h6 style="text-align:right;">

<a href="./findpassword.html" style="margin-right:2rem;">找回密码</a>

</h6>

<hr>

<h6 style="text-align:center;margin-top:3rem;">

<a style="margin-right:2rem;">© vchenzhe</a>

<a href='http://www.beian.gov.cn' style="text-decoration:none;color:black;" target='_blank'>闽ICP备19008574号-1</a>

</h6>

</form>

</div>

</template>

VUE JavaScript方法功能
实现登录验证和路由跳转

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<script>
import { useRouter } from "vue-router"; //引入路由

export default {
name: 'HelloWorld',
setup(){
const router=useRouter();
let Gotoregister=function(){
router.push({name: "Registermobile",})}

return{
Gotoregister
};
},
props: {
msg: String
},
data() {
return {
userid:'33',
usercode:'55',
errorFlag:false,
errorMsg:''
}
},
methods:{
login(){
var thisvue = this;
if(thisvue.userid==''||thisvue.usercode=='')
{
thisvue.errorMsg = '请输入用户名和密码';
thisvue.errorFlag = true;
}
else
{
this.$axios({
method:'POST',
url:'/api/myBlog/axios-login.php',
data:{

userid:thisvue.userid,
usercode:thisvue.usercode
},

}).then((res)=>{
if(res.data.length == 0)
{
console.log("Mysql 数据错误!")
}
else
if(res.data[0].code==1)
{
alert("登录成功")
thisvue.errorFlag = false;
window.location.href="./homemobile.html";
}
else{
thisvue.errorMsg = '账号或密码错误';
thisvue.errorFlag = true;
}
})

}

}
},// methods
}
</script>

PHP 数据处理
接收来自 VUE 的数据并对接 mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
session_start();
header('Content-Type:application/json; charset=utf-8');

$form = file_get_contents('php://input'); //在这里post方法是无效得,所以用这个语句,无需任何配置
$formi = json_decode($form,true); //JSON转换。 from是数组, true
$arr2=$formi; //我多做了一些步骤测试

$myid = $arr2["userid"];
$mycode = md5($arr2['usercode']);

if($myid!=''&&$mycode!='')
{
$pwd="*****";
$conn = new mysqli("localhost:3306", "root", $pwd, "student");
if($conn != null)
{
$sql = "select * FROM user_login where user_id='$myid' or user_mail = '$myid' ";
$result =$conn->query($sql);
$resArray = mysqli_fetch_array($result);
if($resArray == null) {goto __ERENO_SSID;}

if($resArray["user_password"] == $mycode)
{
$_SESSION['chenzhe_user_id'] = $resArray['user_id'];
$result_array[0] = ['code'=>'1','msg'=>'登陆成功'];
echo json_encode($result_array);
}
else
{
__ERENO_SSID:{}
$result_array[0] = ['code'=>'0','msg'=>'用户名或密码输入错误'];
echo json_encode($result_array);
}

$conn->close();
}
else {$result_array[0] = ['code'=>'0','msg'=>'mysql not connect'];}
}
else
{
$result_array[0] = ['code'=>'0','msg'=>'请输入用户名或密码'];
echo json_encode($result_array);
}
?>

账号注册部分

VUE HTML注册界面
实现数据FORM表格界面输入和检测

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<div class="container" style="margin-top:2rem;" id="app">

<ol class="breadcrumb btn100">

<li><a href="./indexmobile.html">返回</a></li>

<li class="active">注册</li>

</ol>

<p class="errorMsg" v-if="errorFlag==1" v-cloak >{{errorMsg}}</p>

<form class="form" id="registerForm">

<div class="form-group has-feedback">

<input type="text" @keyup="testUserIdFunc" v-model="userid" name="userid" minlength=9 maxlength=16 class="form-control input100" placeholder="用户名" required>

<span v-show="testUserId" class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true" style="color:#5cb85c;"></span>

</div>

<div class="form-group">

<input type="text" v-model="username" name="username" maxlength=10 class="form-control input100" placeholder="昵称" required>

</div>



<div class="form-group has-feedback ">

<input type="password" @keyup="readInfo" v-model="usercode" name="usercode" minlength=9 maxlength=20 class="form-control input100" placeholder="密码" required>

<span v-show="testpass" class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true" style="color:#5cb85c;"></span>

</div>



<div class="form-group has-feedback ">

<input type="password" @keyup="readInfo" v-model="usercodes" name="checkusercode" maxlength=20 class="form-control input100" placeholder="确认密码" required>

<span v-show="testpass" class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true" style="color:#5cb85c;"></span>

</div>



<div class="form-group has-feedback ">

<input type="email" @keyup="testmailFunc" v-model="usermail" name="usermail" class="form-control input100" placeholder="邮箱" required>

<span v-show="testmail" class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true" style="color:#5cb85c;"></span>

</div>

<div class="form-group btn100" style="display:flex;" >

<input type="number" v-model="code" class="form-control" placeholder="验证码" required>

<button v-if="testUserId==0||testpass==false||usermail==''||testmail==false" type="button" class="btn btn-default btn80 btn-disabled" disabled style="margin-left:1rem;">获取验证码</button>

<button v-show="btnGetCode==0" v-if="testUserId==1&&testpass==true&&usermail!=''&&testmail==true" type="button" class="btn btn-default btn80" @click="getCode" style="margin-left:1rem;">获取验证码</button>

<button v-show="btnGetCode==1" type="button" class="btn btn-disabled btn80" disabled style="margin-left:1rem;">已发送({{ clock }}s)</button>

</div>



<div class="btn100">

<button type="button" class="btn btn-primary btn100" @click="register">注册</button>

</div>

</form>



<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false">

<div class="modal-dialog">

<div class="modal-content">

<div class="modal-header">

<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

<h4 class="modal-title" id="myModalLabel">消息</h4>

</div>

<div class="modal-body">

{{ errorMsg }}

</div>

<div class="modal-footer">

<button type="button" class="btn btn-primary" data-dismiss="modal">确认</button>

</div>

</div><!-- /.modal-content -->

</div><!-- /.modal -->

</div>



<h6 style="text-align:center;margin-top:3rem;">

<a href="./index.html" style="margin-right:2rem;">电脑版</a>

<a href='http://www.beian.gov.cn' style="text-decoration:none;color:black;" target='_blank'>闽ICP备19008574号-1</a>

</h6>

</div>

VUE注册界面 JavaScript方法功能
实现注册数据检测和POST数据功能

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
import $ from './js/jquery.js';import './css/mobilecommon.css';import Vue from '../node_modules/vue/dist/vue.js';$(function(){

var vm = new Vue({

el:"#app",

data:{

errorMsg:'',

errorFlag:0,

//填写注册信息

userid:'',

username:'',

usercode:'',

usercodes:'',

usermail:'',

//验证注册信息

code:'',

btnGetCode:0, //用于判断当前是否获取了一次验证码,默认是0,获取一次后改成1

testcode:0, //用于判断当前是否完成了验证码验证,默认是0,验证通过是1

clock:60,

testUserId:false,//检测当前用户名是否已经注册

testpass:false,//检测密码安全

testmail:false, //检测邮箱是否被注册过了





},

methods:{

testUserIdFunc(){ //检测用户名是否已经注册

var thisvue = this;

var testall = /^[a-zA-Z][a-zA-Z0-9]*$/; //只能是数字和字母

if(thisvue.userid=='')

{

thisvue.testUserId = false;

return 0;

}

else if(!testall.test(thisvue.userid)) //检测英文和数字

{

this.errorFlag = 1;

this.errorMsg = '用户名必须以英文开头,且只能由英文和数字组成';

}

else if(thisvue.userid.length<9)

{

thisvue.errorFlag = 1;

thisvue.errorMsg = '用户名长度须在9-16之间';

thisvue.testUserId = false;

return 0;

}

else{

$.ajax({

type:'POST',

url:'../server/testUserId.php',

data:{

user_id:thisvue.userid },

success:function(res)

{

if(res.code==1)

{

thisvue.testUserId = true;

thisvue.errorFlag = 0;

}

else{

thisvue.testUserId = false;

thisvue.errorFlag = 1;

thisvue.errorMsg = res.msg;

}

}

})

}

},

readInfo(){ //检索密码安全等

var result = 1;

var testall = /^(?!\d+$)[\da-zA-Z]+$/; //只能是数字和字母

if(this.usercode.length<9) //检测长度

{

this.errorFlag = 1;

this.errorMsg = '密码长度须在9-20个字符,只能由英文和数字组成';

result = 0;

}

else if(!testall.test(this.usercode)) //检测英文和数字

{

this.errorFlag = 1;

this.errorMsg = '密码只能使用英文+数字,且不能为纯数字';

result = 0;



}

else if(this.usercode!=this.usercodes)

{

this.errorFlag = 1;

this.errorMsg = '两次密码输入不一致';

result = 0;



}

/*else if(testenglish.test(this.usercode))

{

this.errorFlag = 1;

this.errorMsg = '密码不能为纯数字';

result = 0;

}*/



if(result==1)

{

this.errorFlag = 0;

this.testpass = 1;//如果密码验证成功,则通过

}

return result;

},

register(){

var thisvue = this;

if(thisvue.usermail==''||thisvue.code=='')

{

thisvue.errorMsg = '你还没有进行邮箱验证';

thisvue.errorFlag = 1;

}

else{

thisvue.verifyCode();

$.ajax({

url:'../server/register.php',

type:'POST',

data:$("#registerForm").serialize(),

success:function(res)

{

if(res.code==1)

{

window.location.href = 'indexmobile.html';

}

else{

thisvue.errorMsg = '注册失败';

thisvue.errorFlag = 1;

}

}

})

}

},

getCode(){ //获取验证码

if(this.userid==''||this.username==''||this.usercode==''||this.usercodes==''||this.usermail=='')

{

this.errorFlag = 1;

this.errorMsg = '请填写全部的信息后获取验证码';

}

else if(this.usercode!=this.usercodes)

{

this.errorFlag = 1;

this.errorMsg = '两次密码输入不一致';

}

else{

var thisvue = this;

thisvue.btnGetCode = 1; //把获取验证码按钮禁用

var timer1 = setInterval(function(){thisvue.clock=thisvue.clock-1;},1000);

setTimeout(function(){

clearInterval(timer1);

thisvue.btnGetCode=0;

thisvue.clock=60;

},60000);

//发送邮件

$.ajax({

type:'POST',

url:'../server/mail/sendMail.php',

async:false,

data:{

address:thisvue.usermail },

success:function(res)

{

if(res.code==1)

{

thisvue.errorFlag = 1;

thisvue.errorMsg = '我们发送了一封邮件到你的邮箱,请尽快验证'

}

}

})

}

},

verifyCode(){ //验证验证码

var thisvue =this;

if(thisvue.code>100000&&thisvue.code<999999)

{

$.ajax({

type:'POST',

url:'../server/mail/verifyCode.php',

data:{code:thisvue.code},

success:function(res)

{

if(res.code=='1')

{

thisvue.testcode=1;

}

else{

thisvue.errorFlag=1;

thisvue.errorMsg='验证码不正确,请重新输入';

return 0;

}

}

})

}

},

testmailFunc(){

var thisvue = this;

if(this.usermail!=''&&this.usermail.indexOf('@')!='')

{

$.ajax({

type:'POST',

url:'../server/testmail.php',

data:{

user_mail:thisvue.usermail },

success:function(res){

if(res.code==1)

{

thisvue.testmail = true;

thisvue.errorFlag = 0;

}

else{

thisvue.testmail = false;

thisvue.errorFlag = 1;

thisvue.errorMsg = '此邮箱已被注册,换个邮箱试试吧';

}

}

})

}

}

}

})})

PHP注册数据功能
实现注册数据接收处理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php

session_start();

header('Content-Type:application/json; charset=utf-8');

$myid = $_POST[userid];

$mycode = md5($_POST[usercode]);

$myname = $_POST[username];

$mymail = $_POST[usermail];

$gm = 'vchenzhecom';

$conn = new mysqli("47.106.190.129:3306", "root", "52F7cbad94f2", "personal");

$test = "SELECT * FROM user_login WHERE `user_id` = '$myid'";

$testResult = $conn->query($test);

if(mysqli_num_rows($testResult)==0)

{

$path="/home/www/htdocs/carelesswhisper/src/img/".$myid; //判断目录存在否,存在给出提示,不存在则创建目录

if (is_dir($path)){

$result = ['code'=>'1','msg'=>'覆盖用户目录'];

}

else{//第三个参数是“true”表示能创建多级目录,iconv防止中文目录乱码

$res=mkdir(iconv("UTF-8", "GBK", $path),0777,true);

$result = ['code'=>'1','msg'=>'注册成功'];

}

$conn->query(" INSERT INTO user_login VALUES('$myid','$mycode','$myname','$mymail','imageFile/image.jpg','未填','未填','未填','未填','0') ");

$conn->query("INSERT INTO personal_follow VALUES('$gm','$myid',1,'2019',0)");

$conn->query("INSERT INTO personal_follow VALUES('$myid','$gm',1,'2019',0)");

$conn->close();



}

else{

$result = ['code'=>'0','msg'=>'此用户名已被使用'];

}

$_SESSION['code']='';

echo json_encode($result);

?>

后端PHP数据接口参考

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
session_start();
header('Access-Control-Allow-Origin: *');
error_reporting(E_ALL & ~E_NOTICE);
//header("Content-type: text/html; charset=gbk");
/*
注意:
本php是gbk编码的,因为mysise就是gbk编码没办法
json_encode()里面的值要先转换为utf-8才能被识别
*/
$user=$_POST['user']?$_POST['user']:$_SESSION['user']['user'];
$pass=$_POST['pass']?$_POST['pass']:$_SESSION['user']['pass'];
$sise_cookie=$_POST['sise_cookie']?$_POST['sise_cookie']:$_SESSION['user']['sise_cookie'];

//echo $_POST['sise_cookie'];


//测试账号110
if($_POST['user']=='110'&&$_POST['pass']=='110') {
include("./user.php");
exit();
}


//登录页面
if($_GET["method"] == 'login'){
$curlpost="number=$user&pwd=$pass";
$scse_cookie=tempnam('./temp','cookie');

//模拟登录scse
$scse_url="http://my.scse.com.cn/login_pro.asp";
LinkCurl($scse_url,$curlpost,$scse_cookie);

//获取管理系统隐藏字段
$sise_login_url="http://class.sise.com.cn:7001/sise/login.jsp";
$sise_login_html=getCurlCon($sise_login_url,$scse_cookie);
preg_match('/<input type=\"hidden\" name=\"(.*)\" value=\"(.*)\">/', $sise_login_html,$arr);
//print_r($arr);

//模拟登录管理系统
$curlpost="username=$user&password=$pass&$arr[1]=$arr[2]";
$sise_cookie=tempnam('./temp','cookie');
$sise_login_check_url="http://class.sise.com.cn:7001/sise/login_check.jsp";
LinkCurl($sise_login_check_url,$curlpost,$sise_cookie);

//正常用户登录
$res = array(
"code" => 404,
"msg" => "failed"
);
$course_url="http://class.sise.com.cn:7001/sise/module/student_schedular/student_schedular.jsp";
$course_html=getCurlCon($course_url,$sise_cookie);
preg_match_all('/<span class=\"style16\">((.*) &nbsp;(.*) &nbsp;(.*) &nbsp;(.*))<\/span>/', $course_html,$user_info);
if(!empty($user_info[2][0])){
//登录成功后保存用户数据
$_SESSION['user']= array(
'user' => $user,
'pass' => $pass,
'sise_cookie' => $sise_cookie
);
$res = array(
"code" => 200,
"msg" => "success",
'sise_cookie' => $sise_cookie
);
}
print_r(json_encode($res));
}

//课程表页面
if($_GET["method"] == 'course'){
//正常用户登录
$res = array(
"code" => 404,
"msg" => "failed",
"resData" => []
);
$course_url="http://class.sise.com.cn:7001/sise/module/student_schedular/student_schedular.jsp";
$course_html=getCurlCon($course_url,$sise_cookie);
preg_match_all('/<span class=\"style16\">(.*) &nbsp;(.*) &nbsp;(.*) &nbsp;(.*)<\/span>/U', $course_html,$user_info);
preg_match_all("/<td width=\'10%\' align=\'left\' valign=\'top\' class=\'font12\'>(.*)<\/td>/U", $course_html,$course);
$res_course=array();
for($i=0;$i<8;$i++){
for($j=$i*7,$k=0;$j<$i*7+7;$j++,$k++){
if ($course[1][$j] == '&nbsp;') $course[1][$j] = '';
if($k!=5 && $k!=6) {
$res_course[$i][$k] = iconv('gbk', 'utf-8', $course[1][$j]);
}
}
}
$res = array(
"code" => 200,
"msg" => "success",
"resData" => array(
"info" => array(
"stuNum" => iconv('gbk', 'utf-8', mb_substr($user_info[1][0],6,null)),
"name" => iconv('gbk', 'utf-8', mb_substr($user_info[2][0],6,null)),
"grade" => iconv('gbk', 'utf-8', mb_substr($user_info[3][0],6,null)),
"major" => iconv('gbk', 'utf-8', mb_substr($user_info[4][0],6,null)),
),
"course" => $res_course
)
);
print_r(json_encode($res));
//print_r($res_course);
}

//查找老师页面
if($_GET["method"] == 'teacher'){
// gei请求的name查询字符串
$name = $_GET["name"];
//获取老师的json数据库
$data = json_decode(file_get_contents("./json/teacher.json" ));
//老师的信息
$arr = array();
//响应数据
$res = array();
//查询json数据库
for($i=0;$i<count($data);$i++){
if($data[$i]->name == $name){
$arr = $data[$i];
}
}
//判断查询数据
if(!empty($arr)){
//如果工号为三位就前面加个0
if(mb_strlen($arr->num) ==3 ){
$arr->num = "0".$arr->num;
}
$res = array(
"code" => 200,
"msg" => "success",
"resData" => $arr
);
} else {
$res = array(
"code" => 404,
"msg" => "failed",
"resData" => array()
);
}
print_r(json_encode($res));
}

//考勤信息页面
if($_GET["method"] == 'attendance'){
//正常用户登录
$res = array(
"code" => 404,
"msg" => "failed",
"resData" => []
);
$main_url="http://class.sise.com.cn:7001/sise/module/student_states/student_select_class/main.jsp";
$main_html=getCurlCon($main_url,$sise_cookie);
preg_match_all('/window\.location=\'\.\.\/\.\.\/\.\.\/\.\.\/\.\.\/(.*)\'\"/Um', $main_html,$main);
$attendance_url='http://class.sise.com.cn:7001/'.$main[1][1];
$attendance_html = getCurlCon($attendance_url,$sise_cookie);
//print_r($attendance_html);
preg_match_all('/<td>(.*)(\d+)<\/td>/U', $attendance_html,$count);
preg_match_all('/<td align=\"center\">(.*)<\/td>/U', $attendance_html,$attendance);
$res_attendance=array();
for($i=0;$i<count($attendance[1])/3;$i++){
for($j=$i*3,$k=0;$j<$i*3+3;$j++,$k++){
switch ($k) {
case 0:
$res_attendance[$i]["num"] = iconv('gbk', 'utf-8', $attendance[1][$j]);
break;
case 1:
$res_attendance[$i]["name"] = iconv('gbk', 'utf-8', $attendance[1][$j]);
break;
case 2:
//匹配请假次数
preg_match_all('/\[<a href=\'(.*)\'>(.*)<\/a>\]/U', $attendance[1][$j],$count);
if(empty($count[2][0])){
$res_attendance[$i]["detail"] = iconv('gbk', 'utf-8', mb_substr($attendance[1][$j],0,4)).$count[2][0];
}else{
$res_attendance[$i]["detail"] = iconv('gbk', 'utf-8', mb_substr($attendance[1][$j],0,4)).$count[2][0].'次';
}
break;
default:
break;
}
}
}
$res = array(
"code" => 200,
"msg" => "success",
"resData" => array(
"total" => $count[2][0],
"list" => $res_attendance
)
);
print_r(json_encode($res));
}

//模拟登录函数
function LinkCurl($url,$curlpost,$cookie_file){
$curl=curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curlpost);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($curl);
curl_close($curl);
}

//模拟登录后获取页面内容函数
function getCurlCon($url,$cookie_file){
$curl=curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file);
$data=curl_exec($curl);
curl_close($curl);
return $data;
}

?>

相关链接

  1. vue加php怎么实现登陆
  2. Vue+php 后端PHP登录接口编写

=================我是分割线=================

欢迎到公众号来唠嗑: