Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tl_estate
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujun
tl_estate
Commits
db77d583
Commit
db77d583
authored
Dec 14, 2017
by
clone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
basic
parent
e08f0af6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
23 deletions
+40
-23
Basic.php
application/api/extend/Basic.php
+27
-23
Users.php
application/model/Users.php
+13
-0
No files found.
application/api/extend/Basic.php
View file @
db77d583
...
@@ -9,8 +9,8 @@ namespace app\api\extend;
...
@@ -9,8 +9,8 @@ namespace app\api\extend;
* Time: 9:35
* Time: 9:35
* 基类
* 基类
*/
*/
use
app\model\Users
;
use
think\Controller
;
use
think\Controller
;
use
think\Exception
;
use
think\helper\Time
;
use
think\helper\Time
;
use
think\Request
;
use
think\Request
;
use
think\Response
;
use
think\Response
;
...
@@ -44,10 +44,10 @@ class Basic extends Controller
...
@@ -44,10 +44,10 @@ class Basic extends Controller
public
function
__construct
(
Request
$request
=
null
)
public
function
__construct
(
Request
$request
=
null
)
{
{
/* ob_start();
/* ob_start();
ob_end_flush();
ob_end_flush();
ob_end_clean();
ob_end_clean();
ob_get_contents();*/
ob_get_contents();*/
// CORS 跨域 Options 检测响应
// CORS 跨域 Options 检测响应
...
@@ -66,19 +66,19 @@ class Basic extends Controller
...
@@ -66,19 +66,19 @@ class Basic extends Controller
}
}
throw
new
Exception
(
$this
->
response
(
"101"
,
"AuthToken失效,请重新登录!"
));
if
(
!
isset
(
$this
->
params
[
'AuthToken'
]))
{
echo
json_encode
(
array
(
"code"
=>
"101"
,
"msg"
=>
"AuthToken不能为空!"
,
"data"
=>
[],
"type"
=>
"json"
));
exit
;
/* $jwt = new \Firebase\JWT\JWT();
}
$jwt
=
new
\Firebase\JWT\JWT
();
$this->authToken = $this->params['AuthToken'];
$this
->
authToken
=
$this
->
params
[
'AuthToken'
];
$result = $jwt->decode($this->authToken, config('jwt_key'), array( 'HS256' )); //解码token
$result
=
$jwt
->
decode
(
$this
->
authToken
,
config
(
'jwt_key'
),
array
(
'HS256'
));
//解码token
$this->userId = $result->data->id;
$this
->
userId
=
$result
->
data
->
id
;
$this->phone = $result->data->phone;
$this
->
phone
=
$result
->
data
->
phone
;
$this->phone
= $result->data->user_nick;
$this
->
user_nick
=
$result
->
data
->
user_nick
;
$this->timeStamp_ = $result->timeStamp_;
$this
->
timeStamp_
=
$result
->
timeStamp_
;
$this->verifyTime(); */
$this
->
verifyTime
();
}
}
...
@@ -87,16 +87,20 @@ class Basic extends Controller
...
@@ -87,16 +87,20 @@ class Basic extends Controller
$today
=
Time
::
today
();
$today
=
Time
::
today
();
//authToken有效期为30天
//authToken有效期为30天
if
((
$today
-
$this
->
timeStamp_
)
>
2592000
)
{
if
((
$today
-
$this
->
timeStamp_
)
>
2592000
)
{
$this
->
response
(
"101"
,
"AuthToken失效,请重新登录!"
);
echo
json_encode
(
array
(
"code"
=>
"101"
,
"msg"
=>
"AuthToken失效,请重新登录!"
,
"data"
=>
[],
"type"
=>
"json"
));
exit
;
}
}
}
}
public
function
verifyUserInfo
(){
public
function
verifyUserInfo
()
{
//todo 待完成
//todo 待完成
$userArr
=
Session
::
get
(
"u_user"
);
$userModel
=
new
Users
();
if
(
count
(
$userArr
)
>
0
&&
(
$userArr
[
"status"
]
!=
0
||
$userArr
[
"id"
]
!=
$this
->
userId
||
$userArr
[
"user_phone"
]
!=
$this
->
phone
)
){
$userArr
=
$userModel
->
selectUser
(
$this
->
userId
);
$this
->
response
(
"101"
,
"用户验证失败,重新登录!"
);
if
(
count
(
$userArr
)
>
0
&&
(
$userArr
[
"status"
]
!=
0
||
$userArr
[
"id"
]
!=
$this
->
userId
||
$userArr
[
"user_phone"
]
!=
$this
->
phone
))
{
echo
json_encode
(
array
(
"code"
=>
"101"
,
"msg"
=>
"用户验证失败,重新登录!"
,
"data"
=>
[],
"type"
=>
"json"
));
exit
;
}
}
return
true
;
return
true
;
}
}
...
...
application/model/Users.php
View file @
db77d583
...
@@ -2,10 +2,23 @@
...
@@ -2,10 +2,23 @@
namespace
app\model
;
namespace
app\model
;
use
think\Db
;
use
think\Model
;
use
think\Model
;
class
Users
extends
Model
class
Users
extends
Model
{
{
// 设置当前模型对应的完整数据表名称
// 设置当前模型对应的完整数据表名称
protected
$table
=
'u_users'
;
protected
$table
=
'u_users'
;
protected
$db
;
public
function
__construct
()
{
$this
->
db
=
Db
(
$this
->
table
);
}
public
function
selectUser
(
$user_id
){
return
$this
->
db
->
field
(
"id,status,user_phone"
)
->
find
(
$user_id
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment