Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
personal
Overview
Overview
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
庄钊鑫
personal
Commits
45fa38dd
Commit
45fa38dd
authored
Mar 12, 2019
by
庄钊鑫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
token修改,返回参数格式修改
parent
78039aee
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
69 additions
and
40 deletions
+69
-40
workspace.xml
.idea/workspace.xml
+0
-0
Api.php
app/api/controller/Api.php
+23
-0
Send.php
app/api/controller/Send.php
+3
-1
Send.php
app/api/controller/v1/app/Send.php
+9
-2
User.php
app/api/controller/v1/app/User.php
+17
-24
Token.php
app/api/model/Token.php
+11
-8
User.php
app/api/model/User.php
+3
-2
Base.php
app/common/validate/Base.php
+3
-3
12.log
runtime/log/201903/12.log
+0
-0
No files found.
.idea/workspace.xml
View file @
45fa38dd
This diff is collapsed.
Click to expand it.
app/api/controller/Api.php
View file @
45fa38dd
...
...
@@ -8,6 +8,7 @@ namespace app\api\controller;
use
think\Controller
;
use
think\exception\HttpResponseException
;
use
think\Request
;
use
think\Cache
;
class
Api
extends
Controller
{
...
...
@@ -159,6 +160,28 @@ class Api extends Controller
}
/**
* 验证header参数
* @access protected
* @param array $data 数据
* @param string|array $validate 验证器名或者验证规则数组
* @param array $message 提示信息
*/
protected
function
checkHeader
(
$key
,
$mobile
)
{
$info
=
Request
::
instance
()
->
header
();
if
(
isset
(
$info
[
$key
])){
$getMobile
=
Cache
::
get
(
$info
[
$key
]);
$result
=
$getMobile
?
((
$getMobile
==
$mobile
)
?
[
'status'
=>
1
,
'message'
=>
$info
[
$key
]]
:
[
'status'
=>
0
,
'message'
=>
'手机号码不一致!'
])
:
[
'status'
=>
0
,
'message'
=>
'token已失效!'
];
return
$result
;
}
else
{
self
::
returnmsg
(
403
,
[],
[],
""
,
"param error"
,
"获取token失败!"
);
}
}
/**
* 获取页码和每页数量
* @param int $defaultIndex
* @param int $defaultSize
...
...
app/api/controller/Send.php
View file @
45fa38dd
...
...
@@ -147,7 +147,9 @@ trait Send
{
switch
(
$code
)
{
case
200
:
$error
=
"SUCCESS"
;
$error
[
'success'
][
'type'
]
=
"SUCCESS"
;
$error
[
'success'
][
'reason'
]
=
empty
(
$reason
)
?
"param missing"
:
$reason
;
$error
[
'success'
][
'message'
]
=
empty
(
$message
)
?
"请求体不完整"
:
$message
;
break
;
case
400
:
$error
[
'error'
][
'type'
]
=
"BAD REQUEST"
;
...
...
app/api/controller/v1/app/Send.php
View file @
45fa38dd
...
...
@@ -15,6 +15,7 @@ use think\Controller;
use
app\api\logic\app\SendLogic
;
use
app\common\tools\Guodulink
;
use
app\api\logic\app\UserLogic
;
use
think\Cache
;
/**
* 所有资源类接都必须继承基类控制器
...
...
@@ -93,7 +94,13 @@ class Send extends Base
if
(
$info
===
false
)
{
$this
->
returnmsg
(
403
,
[],
[],
""
,
[],
"验证码错误"
);
}
$success
[
'success'
][
'message'
]
=
'验证码正确!'
;
$this
->
render
(
200
,
$success
);
$tokenId
=
md5
(
md5
(
time
()));
Cache
::
set
(
$tokenId
,
$request
[
'mobile'
],
1800
);
if
(
Cache
::
get
(
$tokenId
)){
$result
[
'token'
]
=
$tokenId
;
}
$result
[
'message'
]
=
'验证码正确!'
;
$this
->
returnmsg
(
200
,[],[],
"validateCode"
,
"validateCode success"
,
$result
);
}
}
app/api/controller/v1/app/User.php
View file @
45fa38dd
...
...
@@ -101,7 +101,7 @@ class User extends Base
$this
->
check
(
$requestData
,
'Base.cmsLogin'
);
$result
=
UserModel
::
build
()
->
login
(
$requestData
);
if
(
$result
)
{
$this
->
re
nder
(
200
,
$result
);
$this
->
re
turnmsg
(
200
,[],[],
"login"
,
"login success"
,
$result
);
}
else
{
$this
->
returnmsg
(
403
,
$data
=
[],
$header
=
[],
$type
=
""
,
"Login error"
,
$message
=
"登录失败"
);
}
...
...
@@ -151,7 +151,7 @@ class User extends Base
}
$data
=
UserLogic
::
publicLogin
(
$requestData
);
$data
!==
false
?
$this
->
render
(
$data
)
:
$this
->
returnmsg
(
403
,
""
,
""
,
""
,
""
,
"登录失败"
);
$data
!==
false
?
$this
->
render
(
$data
)
:
$this
->
returnmsg
(
403
,
[],[]
,
""
,
""
,
"登录失败"
);
}
...
...
@@ -164,10 +164,10 @@ class User extends Base
{
$request
=
$this
->
selectParam
([
'mobile'
,
'sms_type'
=>
'bind'
]);
$this
->
check
(
$request
,
'Base.sendSms'
);
$bool
=
UserLogic
::
checkUser
(
$request
[
'mobile'
]);
if
(
!
empty
(
$bool
)){
$this
->
returnmsg
(
403
,
[],
[],
""
,
[],
"该手机号已注册"
);
}
//
$bool = UserLogic::checkUser($request['mobile']);
//
if(!empty($bool)){
//
$this->returnmsg(403, [], [],"", [], "该手机号已注册");
//
}
$success
[
'success'
][
'message'
]
=
'手机号码验证成功'
;
$this
->
render
(
200
,
$success
);
}
...
...
@@ -191,18 +191,12 @@ class User extends Base
$this
->
returnmsg
(
403
,
[],
[],
""
,
[],
"该手机号已注册"
);
}
}
$tokenId
=
md5
(
md5
(
time
()));
Cache
::
set
(
$tokenId
,
$request
[
'mobile'
],
1800
);
if
(
Cache
::
get
(
$tokenId
)){
$info
=
true
;
//$info = SendLogic::SendSms($request['mobile'], $request['sms_type']);
if
(
$info
===
false
)
{
$this
->
returnmsg
(
403
,
[],
[],
""
,
[],
"信息发送出现了一点小问题哟~"
);
}
$success
[
'success'
][
'token'
]
=
$tokenId
;
$success
[
'success'
][
'message'
]
=
'验证码发送成功'
;
$this
->
render
(
200
,
$success
);
//$info = true;
$info
=
SendLogic
::
SendSms
(
$request
[
'mobile'
],
$request
[
'sms_type'
]);
if
(
$info
===
false
)
{
$this
->
returnmsg
(
403
,
[],
[],
""
,
[],
"信息发送出现了一点小问题哟~"
);
}
$this
->
returnmsg
(
200
,[],[],
"sendCode"
,
"sendCode success"
,
'验证码发送成功'
);
}
/**
...
...
@@ -215,11 +209,11 @@ class User extends Base
*/
public
function
register
()
{
$request
=
$this
->
selectParam
([
'mobile'
,
'password'
,
'password2'
,
'token'
]);
$request
=
$this
->
selectParam
([
'mobile'
,
'password'
,
'password2'
]);
$this
->
check
(
$request
,
'Base.register'
);
$
result
=
Token
::
validateToken2
(
$request
[
'token'
]
,
$request
[
'mobile'
]);
if
(
$
r
esult
[
'status'
]
==
0
){
$this
->
returnmsg
(
403
,
[],
[],
""
,
[],
$
r
esult
[
'message'
]);
$
headerResult
=
$this
->
checkHeader
(
'regitser-access-token'
,
$request
[
'mobile'
]);
if
(
$
headerR
esult
[
'status'
]
==
0
){
$this
->
returnmsg
(
403
,
[],
[],
""
,
[],
$
headerR
esult
[
'message'
]);
}
$bool
=
UserLogic
::
checkUser
(
$request
[
'mobile'
]);
if
(
!
empty
(
$bool
)){
...
...
@@ -227,9 +221,8 @@ class User extends Base
}
$result
=
UserModel
::
build
()
->
register
(
$request
);
if
(
$result
)
{
Cache
::
rm
(
$request
[
'token'
]);
$success
[
'success'
][
'message'
]
=
'注册成功!'
;
$this
->
render
(
200
,
$success
);
Cache
::
rm
(
$headerResult
[
'message'
]);
$this
->
returnmsg
(
200
,[],[],
"register"
,
"register success"
,
$result
);
}
else
{
$this
->
returnmsg
(
403
,
$data
=
[],
$header
=
[],
$type
=
""
,
"Login error"
,
$message
=
"注册失败"
);
}
...
...
app/api/model/Token.php
View file @
45fa38dd
...
...
@@ -68,14 +68,17 @@ class Token extends Model
public
static
function
validateToken2
(
$tokenId
,
$mobile
)
{
$getMobile
=
Cache
::
get
(
$tokenId
);
if
(
$getMobile
){
if
(
$getMobile
==
$mobile
){
return
[
'status'
=>
1
];
}
else
{
return
[
'status'
=>
0
,
'message'
=>
'手机号码不一致!'
];
}
}
return
[
'status'
=>
0
,
'message'
=>
'token已失效!'
];
$result
=
$getMobile
?
((
$getMobile
==
$mobile
)
?
[
'status'
=>
1
]
:
[
'status'
=>
0
,
'message'
=>
'手机号码不一致!'
])
:
[
'status'
=>
0
,
'message'
=>
'token已失效!'
];
// if($getMobile){
// if($getMobile == $mobile){
// return ['status' => 1];
// }else{
// return ['status' => 0,'message' => '手机号码不一致!'];
// }
// }
return
$result
;
}
/**
...
...
app/api/model/User.php
View file @
45fa38dd
...
...
@@ -85,14 +85,15 @@ class User extends Model
$user
[
'name'
]
=
replaceToStar
(
$request
[
'mobile'
]);
$user
[
'create_time'
]
=
timeToDate
(
time
());
$user
[
'password'
]
=
md5
(
md5
(
$request
[
'password'
]));
$result
=
self
::
build
()
->
insert
(
$user
);
self
::
build
()
->
insert
(
$user
);
$result
=
$this
->
login
([
'mobile'
=>
$request
[
'mobile'
],
'password'
=>
$request
[
'password'
]]);
if
(
!
$result
)
{
Db
::
rollback
();
return
false
;
}
Db
::
commit
();
return
true
;
return
$result
;
}
...
...
app/common/validate/Base.php
View file @
45fa38dd
...
...
@@ -38,7 +38,7 @@ class Base extends Validate
'keyword'
=>
'chsDash'
,
'refresh_token'
=>
'require|length:32'
,
'collect_type'
=>
'require|in:school,speciality'
,
'token'
=>
'require'
,
'name'
=>
'require|chsAlphaNum|length:0,64'
,
'gender'
=>
'require|in:男,女'
,
'birth'
=>
'require|chsAlphaNum|length:0,64'
,
...
...
@@ -63,7 +63,7 @@ class Base extends Validate
'password.require'
=>
'密码必须'
,
'password.min'
=>
'密码过短'
,
'password2.confirm'
=>
'两次密码输入不一致'
,
'token.require'
=>
'token必须'
,
'message_type'
=>
'消息类型错误'
,
'province'
=>
'省份设置错误'
,
'city.json'
=>
'城市设置错误'
,
...
...
@@ -89,7 +89,7 @@ class Base extends Validate
'id'
=>
[
'id'
],
'uuid'
=>
[
'uuid'
],
'sendSms'
=>
[
'mobile'
,
'sms_type'
],
'register'
=>
[
'mobile'
,
'password'
,
'password2'
,
'token'
],
'register'
=>
[
'mobile'
,
'password'
,
'password2'
],
'sendPartnerSms'
=>
[
'mobile'
,
'sms_type_partner'
],
'validatePartnerCode'
=>
[
'mobile'
,
'sms_type_partner'
,
'code'
],
...
...
runtime/log/201903/12.log
View file @
45fa38dd
This diff is collapsed.
Click to expand it.
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