Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
doc_phone
Project
Project
Details
Activity
Releases
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
jiangyipeng
doc_phone
Commits
4e7fa389
Commit
4e7fa389
authored
May 27, 2020
by
huanle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
0527
parent
84dcbc37
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
195 additions
and
7 deletions
+195
-7
config.php
application/login/config.php
+15
-0
Index.php
application/login/controller/Index.php
+22
-7
Token.php
application/login/controller/Token.php
+86
-0
Token.php
application/login/model/Token.php
+72
-0
No files found.
application/login/config.php
0 → 100644
View file @
4e7fa389
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
return
[
// token过期时间
'token_expire_second'
=>
86400
,
];
application/login/controller/Index.php
View file @
4e7fa389
<?php
namespace
app\login\controller
;
use
app\login\model\Token
as
TokenModel
;
use
cjango\Dingtalk\User
;
use
src\Dingtalk\Utils
;
use
think\Controller
;
...
...
@@ -8,12 +9,20 @@ use src\Dingtalk;
use
think\Session
;
class
Index
extends
Controller
{
// public function index(){
//
// return $this->fetch();
//
//
// }
public
function
check
()
{
$token
=
input
(
'post.token'
);
$tokenModel
=
new
TokenModel
();
$checkResult
=
$tokenModel
->
check
(
$token
);
if
(
$checkResult
==
false
)
{
return
json
(
code
([],
$tokenModel
->
getErrCode
(),
$tokenModel
->
getError
()));
}
else
{
return
json
(
code
([
'bind_info'
=>
json_decode
(
$checkResult
)]));
}
}
public
function
config
(){
$Ding
=
new
Dingtalk
();
$Token
=
new
Dingtalk\Token
();
...
...
@@ -41,6 +50,9 @@ class Index extends Controller
$User
=
new
Dingtalk\User
();
$userid
=
$User
->
code
(
$code
);
$token
=
new
Token
();
$gettoken
=
$token
->
create
(
$userid
);
if
(
$userid
===
false
){
$data
[
'status'
]
=-
10001
;
$data
[
'errmsg'
]
=
'登录失败'
;
...
...
@@ -51,6 +63,9 @@ class Index extends Controller
}
// return json($data);
return
json
(
code
([
$data
],
0
,
'ok'
));
// var_dump($_SESSION);
// var_dump($_SESSION);
}
public
function
checkToken
(){
}
}
application/login/controller/Token.php
0 → 100644
View file @
4e7fa389
<?php
/**
* Created by PhpStorm.
* User: liupei
* Date: 2018/1/30
* Time: 14:25
*/
namespace
app\login\controller
;
use
think\Controller
;
use
app\login\model\Token
as
TokenModel
;
/**
* 处理用户token
* @package app\access\controller
*/
class
Token
extends
Controller
{
/**
* 检测token是否合法
* @return array
*/
public
function
check
()
{
$token
=
input
(
'post.token'
);
$tokenModel
=
new
TokenModel
();
$checkResult
=
$tokenModel
->
check
(
$token
);
if
(
$checkResult
==
false
)
{
return
json
(
code
([],
$tokenModel
->
getErrCode
(),
$tokenModel
->
getError
()));
}
else
{
return
json
(
code
([
'bind_info'
=>
json_decode
(
$checkResult
)]));
}
}
public
function
login
(){
$code
=
input
(
'post.code'
);
//var_dump($code);
//$access_token= Session::get('access_token');
$User
=
new
Dingtalk\User
();
$userid
=
$User
->
code
(
$code
);
$result
=
$this
->
create
(
$userid
);
var_dump
(
$result
);
die
();
if
(
$userid
===
false
){
$data
[
'status'
]
=-
10001
;
$data
[
'errmsg'
]
=
'登录失败'
;
}
else
{
$data
[
'status'
]
=
0
;
$data
[
'errmsg'
]
=
'登录成功'
;
$data
[
'userid'
]
=
$userid
;
}
// return json($data);
return
json
(
code
([
$data
],
0
,
'ok'
));
}
public
function
create
(
$uid
)
{
//$client = data('client', 'pc');// 客户端标识phone,pc,pc_msg目前只支持3 种
$tokenModel
=
new
TokenModel
();
// if ($getOld == 1) {
// $exist = $tokenModel->getUserToken($uid, $client);
// if (!empty($exist)) {
// // 更新过期时间
// $tokenModel->updateExpire($exist, config('token_expire_second'));
// return code(['token' => $exist, 'expire_second' => config('token_expire_second')]);
// }
// }
$token
=
$tokenModel
->
createToken
(
$uid
);
if
(
$token
==
false
)
{
return
json
(
code
([],
$tokenModel
->
getErrCode
(),
$tokenModel
->
getError
()));
}
else
{
return
json
(
code
([
'token'
=>
$token
,
'expire_second'
=>
config
(
'token_expire_second'
)]));
}
}
}
\ No newline at end of file
application/login/model/Token.php
0 → 100644
View file @
4e7fa389
<?php
/**
* Created by PhpStorm.
* User: liupei
* Date: 2018/1/30
* Time: 14:34
*/
namespace
app\login\model
;
use
think\Model
;
class
Token
extends
Model
{
/**
* 检测token是否合法
* @param $token string 用户token
* @return bool
*/
public
function
check
(
$token
)
{
$info
=
cache
(
'token_'
.
$token
);
if
(
$info
===
false
)
{
$this
->
errCode
=
10003
;
$this
->
error
=
'没有token'
;
return
false
;
}
return
$info
;
}
/**
* 生成token并绑定数据,2小时内重新请求自动续期
* @param $uid binint 用户uid
* @param $bindInfo string 要绑定的数据
* @param $client string 客户端标识phone,pc目前只支持2 种
* @return bool|string
*/
public
function
createToken
(
$uid
)
{
if
(
empty
(
$uid
))
{
$this
->
error
=
'绑定uid的数据不能为空'
;
$this
->
errCode
=
1001
;
return
false
;
}
$token
=
md5
(
create_unique
());
$expireSecond
=
config
(
'token_expire_second'
);
// 清除token
$this
->
removeToken
(
$uid
);
// 设置新的token
$rs
=
cache
(
'token_'
.
$token
,
$expireSecond
);
if
(
$rs
)
{
// 设置我的新缓存记录
$record
=
cache
(
'token_'
.
$uid
);
$record
=
json_decode
(
$record
,
true
);
is_array
(
$record
)
||
$record
=
[];
$record
[]
=
[
'token'
=>
$token
];
cache
(
'token_'
.
$uid
,
json_encode
(
$record
),
0
);
return
$token
;
}
else
{
$this
->
errCode
=
10000
;
$this
->
error
=
'token写入失败'
;
return
false
;
}
}
}
\ No newline at end of file
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