Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
goods
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
bp
goods
Commits
ccebc0c4
Commit
ccebc0c4
authored
Sep 29, 2021
by
jianghaiming
Browse files
Options
Browse Files
Download
Plain Diff
update:修改冲突
parents
ace9831e
91132a3f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
18 deletions
+44
-18
UserException.php
application/exception/custom/UserException.php
+2
-1
UserService.php
application/services/user/UserService.php
+32
-17
application.ini
conf/application.ini
+10
-0
No files found.
application/exception/custom/UserException.php
View file @
ccebc0c4
...
...
@@ -9,7 +9,7 @@ use App\Exception\BaseException;
class
UserException
extends
BaseException
{
protected
$base_code
=
Code
::
USUR
;
const
APP_ID_NULL
=
15
;
protected
$cus
=
[
0
=>
'code 无效'
,
1
=>
'获取openid失败'
,
...
...
@@ -26,5 +26,6 @@ class UserException extends BaseException
12
=>
'绑定手机号保存失败'
,
13
=>
'请求太频繁,稍后重试'
,
14
=>
'手机号格式错误'
,
self
::
APP_ID_NULL
=>
'AppId 不能为空'
,
];
}
\ No newline at end of file
application/services/user/UserService.php
View file @
ccebc0c4
...
...
@@ -37,19 +37,16 @@ class UserService
public
static
function
wechatLogin
(
$params
)
{
self
::
$code
=
!
empty
(
$params
[
'code'
])
?
$params
[
'code'
]
:
''
;
//小程序授权code
$appid
=
!
empty
(
$params
[
'appid'
])
?
$params
[
'appid'
]
:
1
;
//登陆来源
$appid
=
!
empty
(
$params
[
'appid'
])
?
$params
[
'appid'
]
:
''
;
//登陆来源
$inviteUserId
=
!
empty
(
$params
[
'invite_user_id'
])
?
intval
(
$params
[
'invite_user_id'
])
:
0
;
//邀请用户id
$activityType
=
!
empty
(
$params
[
'activity_type'
])
?
intval
(
$params
[
'activity_type'
])
:
0
;
//活动类型
if
(
empty
(
self
::
$code
))
{
FileLog
::
error
(
"wechatLogin:获取参数为空"
,
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
''
,
'jianghaiming@yidian-inc.com'
);
throw
new
UserException
([
'cus'
=>
0
]);
}
//验证登陆参数
self
::
checkWechatLoginParams
(
$params
);
$lock
=
self
::
getWechatLoginLock
(
$params
);
if
(
!
empty
(
$lock
)){
return
$lock
;
}
//设置小程序配置
self
::
setWechatConfig
(
$appid
);
//获取小程序用户信息
...
...
@@ -103,6 +100,22 @@ class UserService
return
$user
;
}
/**
* 验证登陆参数
* @param $params
* @throws UserException
*/
public
static
function
checkWechatLoginParams
(
$params
)
{
if
(
empty
(
self
::
$code
))
{
FileLog
::
error
(
"wechatLogin:获取参数为空"
,
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
''
,
'jianghaiming@yidian-inc.com'
);
throw
new
UserException
([
'cus'
=>
0
]);
}
if
(
empty
(
$params
[
'appid'
]))
{
throw
new
UserException
([
'cus'
=>
UserException
::
APP_ID_NULL
]);
}
}
/**
* 初始化微信配置
* @param $wechatFrom
...
...
@@ -110,13 +123,8 @@ class UserService
public
static
function
setWechatConfig
(
$wechatFrom
)
{
//需要授权微信
if
(
$wechatFrom
==
'merchant-pub-deliverer'
)
{
self
::
$appid
=
\Yaf\Registry
::
get
(
'config'
)
->
deliverer
->
wechat
->
appid
;
self
::
$secret
=
\Yaf\Registry
::
get
(
'config'
)
->
deliverer
->
wechat
->
secret
;
}
else
{
self
::
$appid
=
\Yaf\Registry
::
get
(
'config'
)
->
wechat
->
appid
;
self
::
$secret
=
\Yaf\Registry
::
get
(
'config'
)
->
wechat
->
secret
;
}
self
::
$appid
=
\Yaf\Registry
::
get
(
'config'
)
->
wechat
->
appid
->
$wechatFrom
;
self
::
$secret
=
\Yaf\Registry
::
get
(
'config'
)
->
wechat
->
secret
->
$wechatFrom
;
}
/**
...
...
@@ -186,6 +194,8 @@ class UserService
public
static
function
bindPhone
(
$params
){
self
::
$openid
=
!
empty
(
$params
[
'openid'
])
?
$params
[
'openid'
]
:
''
;
$phone
=
!
empty
(
$params
[
'mobile'
])
?
$params
[
'mobile'
]
:
''
;
$wechatFrom
=
!
empty
(
$params
[
'appid'
])
?
$params
[
'appid'
]
:
''
;
self
::
setWechatConfig
(
$wechatFrom
);
if
(
!
empty
(
$phone
)){
$userInfo
=
self
::
delivererBindPhone
(
$params
);
}
else
{
...
...
@@ -213,9 +223,15 @@ class UserService
if
(
!
empty
(
$check
)
&&
$check
[
'status'
]
==
'failed'
)
{
throw
new
BaseException
([
'code'
=>
$check
[
'code'
],
'msg'
=>
$check
[
'reason'
]]);
}
$jwUser
=
(
new
JwUser
())
->
getUserInfo
([
'mobile'
=>
$mobile
]);
$userId
=
''
;
if
(
!
empty
(
$jwUser
[
'data'
]))
{
$data
=
$jwUser
[
'data'
];
$userId
=
!
empty
(
$data
[
'userId'
])
?
$data
[
'userId'
]
:
''
;
}
$userInfo
=
UserWechatBind
::
getRecordMaster
([
'openid'
=>
self
::
$openid
]);
CommonService
::
activateDeliverer
([
'user_id'
=>
$userId
,
'phone'
=>
$mobile
]);
$userInfo
=
array_merge
(
$userInfo
,
self
::
saveWechatPhone
(
$mobile
,
$userInfo
))
;
CommonService
::
activateDeliverer
([
'user_id'
=>
$userInfo
[
'user_id'
],
'phone'
=>
$userInfo
[
'phone'
]]);
return
$userInfo
;
}
...
...
@@ -262,7 +278,6 @@ class UserService
{
$encryptedData
=
!
empty
(
$params
[
'encryptedData'
])
?
$params
[
'encryptedData'
]
:
''
;
$iv
=
!
empty
(
$params
[
'iv'
])
?
$params
[
'iv'
]
:
''
;
$appid
=
\Yaf\Registry
::
get
(
'config'
)
->
wechat
->
appid
;
if
(
!
$encryptedData
)
{
FileLog
::
error
(
"bindPhone:encryptedData 为空"
,
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
''
,
'jianghaiming@yidian-inc.com'
);
...
...
@@ -284,7 +299,7 @@ class UserService
//解密
$decryptData
=
[];
$wXBizDataCrypt
=
new
WxBizDataCrypt
(
$appid
,
$sessionKey
);
$wXBizDataCrypt
=
new
WxBizDataCrypt
(
self
::
$appid
,
$sessionKey
);
$errCode
=
$wXBizDataCrypt
->
decryptData
(
$encryptedData
,
$iv
,
$decryptData
);
if
(
$errCode
)
{
...
...
conf/application.ini
View file @
ccebc0c4
...
...
@@ -21,6 +21,16 @@ idgen.key = "5cfdb867e96374c7883b31d6928cc4cb"
wechat.appid
=
"wx4e0d92499185fb74"
;
wechat.secret = "731bcf2f7ebb1ebddb677618c2008b25";
wechat.appid.merchant-pub-pin
=
"wx4e0d92499185fb74"
wechat.secret.merchant-pub-pin
=
"731bcf2f7ebb1ebddb677618c2008b25"
wechat.appid.merchant-pub-deliverer
=
"wx91042f2a75f8b994"
wechat.secret.merchant-pub-deliverer
=
"09d7ea5472d871b4b1a0f3100bdfe1c9"
wechat.appid.merchant-pub-idle
=
"wx415fe9cb54be1e09"
wechat.secret.merchant-pub-idle
=
"b1badcd547f47a456f400016af90b46f"
deliverer.wechat.appid
=
"wx91042f2a75f8b994"
;
deliverer.wechat.secret = "09d7ea5472d871b4b1a0f3100bdfe1c9";
...
...
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