Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
services
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tencent
services
Commits
9f676bb2
Commit
9f676bb2
authored
Jul 27, 2018
by
zhufx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
从redis获取用户信息
parent
21c7d3a0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
125 additions
and
7 deletions
+125
-7
src/Auth/Enum/AuthError.php
+8
-0
src/Auth/Exception/AuthException.php
+16
-0
src/Common/Entity/User.php
+101
-7
No files found.
src/Auth/Enum/AuthError.php
View file @
9f676bb2
...
...
@@ -12,6 +12,8 @@ class AuthError
const
TOKEN_ERROR
=
[
"msg"
=>
"token写入失败"
,
"code"
=>
500
,
"errorCode"
=>
25100
];
const
WX_ERROR
=
[
"msg"
=>
"获取信息失败"
,
"code"
=>
500
,
"errorCode"
=>
25101
];
const
CONFIG_ERROR
=
[
"msg"
=>
"配置不正确"
,
"code"
=>
500
,
"errorCode"
=>
25102
];
const
GET_TOKEN_ERROR
=
[
"msg"
=>
"获取token失败"
,
"code"
=>
500
,
"errorCode"
=>
25103
];
const
NOT_FOUND_USER
=
[
"msg"
=>
"获取用户信息失败"
,
"code"
=>
404
,
"errorCode"
=>
25104
];
public
static
function
atranslate
(
$message
,
$param
)
...
...
@@ -23,4 +25,9 @@ class AuthError
return
sprintf
(
...
$param
);
}
public
static
function
getError
(
$code
)
{
$reflect
=
new
\ReflectionClass
(
StoreError
::
class
);
return
$reflect
->
getConstant
(
'E'
.
$code
);
}
}
\ No newline at end of file
src/Auth/Exception/AuthException.php
0 → 100644
View file @
9f676bb2
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/7/27
* Time: 14:47
*/
namespace
Hdll\Services\Auth\Exception
;
use
Hdll\Services\Common\Exception\CommonException
;
class
AuthException
extends
CommonException
{
}
\ No newline at end of file
src/Common/Entity/User.php
View file @
9f676bb2
...
...
@@ -10,7 +10,11 @@
namespace
Hdll\Services\Common\Entity
;
use
Hdll\Services\Auth\Enum\AuthError
;
use
Hdll\Services\Auth\Exception\AuthException
;
use
Swoft\App
;
use
Swoft\Bean\Annotation\Bean
;
use
Swoft\Cache\Cache
;
/**
* 用户实体
...
...
@@ -34,17 +38,20 @@ class User
private
$token
;
private
$cmId
;
private
$sessionKey
;
private
$scope
;
private
$referId
;
private
$unionid
;
private
$openId
;
public
function
__construct
(
$token
=
''
)
{
$this
->
setHeadImg
(
"test"
);
$this
->
setId
(
1
);
$this
->
setNickName
(
"zhangsan"
);
$this
->
setStoreId
(
"2"
);
$this
->
setToken
(
$token
);
}
public
function
getId
()
...
...
@@ -92,9 +99,54 @@ class User
return
$this
->
headImg
=
$value
;
}
public
function
setSessionKey
(
$value
)
{
$this
->
sessionKey
=
$value
;
}
public
function
setOpenId
(
$value
)
{
$this
->
openId
=
$value
;
}
public
function
setUnionid
(
$value
)
{
$this
->
unionid
=
$value
;
}
public
function
setReferId
(
$value
)
{
$this
->
referId
=
$value
;
}
public
function
setScope
(
$value
)
{
$this
->
scope
=
$value
;
}
public
function
setToken
(
$value
)
{
return
$this
->
token
=
$value
;
if
(
empty
(
$value
)
)
{
return
[
false
,
AuthError
::
GET_TOKEN_ERROR
];
}
/**
* @var Cache $cache
*/
$cache
=
App
::
getBean
(
"cache"
);
$info
=
$cache
->
get
(
'AUTH:'
.
$value
);
if
(
empty
(
$info
)
)
{
return
[
false
,
AuthError
::
NOT_FOUND_USER
];
}
$info
=
json_decode
(
$info
,
true
);
$this
->
fill
(
$info
);
$this
->
token
=
$value
;
return
true
;
}
public
function
setCmId
(
$value
)
...
...
@@ -106,5 +158,47 @@ class User
{
return
$this
->
cmId
;
}
public
function
fill
(
$arr
)
{
foreach
(
$arr
as
$name
=>
$value
)
{
$methodName
=
sprintf
(
'set%s'
,
ucfirst
(
$name
));
var_dump
(
method_exists
(
$this
,
$methodName
),
$this
,
$methodName
);
if
(
method_exists
(
$this
,
$methodName
))
{
$this
->
$methodName
(
$value
);
}
}
}
public
function
getSessionKey
(
$value
)
{
return
$this
->
sessionKey
;
}
public
function
getOpenId
(
$value
)
{
return
$this
->
openId
;
}
public
function
getUnionid
(
$value
)
{
return
$this
->
unionid
;
}
public
function
getReferId
(
$value
)
{
return
$this
->
referId
;
}
public
function
getScope
(
$value
)
{
return
$this
->
scope
;
}
}
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