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
a760e4fd
Commit
a760e4fd
authored
Sep 07, 2021
by
pengfei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'colonel' of
https://git.yidian-inc.com:8021/bp/goods
into colonel
parents
fa50faa6
eac4daa5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
37 deletions
+44
-37
UserService.php
application/services/user/UserService.php
+44
-37
No files found.
application/services/user/UserService.php
View file @
a760e4fd
...
...
@@ -3,6 +3,7 @@
namespace
App\Services\user
;
use
Api\PhpUtils\Mon\MonUtil
;
use
App\Models\user\mysql\UserWechatBind
;
use
Api\PhpUtils\Http\Request
;
use
App\Services\user\Weixin\WxBizDataCrypt
;;
...
...
@@ -29,36 +30,42 @@ class UserService
$code
=
!
empty
(
$params
[
'code'
])
?
$params
[
'code'
]
:
''
;
//小程序授权code
$openid
=
!
empty
(
$params
[
'openid'
])
?
$params
[
'openid'
]
:
''
;
//小程序授权code
if
(
empty
(
$code
)
&&
empty
(
$openid
))
{
FileLog
::
error
(
"wechatLogin:获取参数为空"
,
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
''
,
'jianghaiming@yidian-inc.com'
);
FileLog
::
error
(
"wechatLogin:获取参数为空"
,
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
''
,
'jianghaiming@yidian-inc.com'
);
throw
new
UserException
([
'cus'
=>
0
]);
}
//需要授权微信
//if (empty($openid)) {
$appid
=
\Yaf\Registry
::
get
(
'config'
)
->
wechat
->
appid
;
$secret
=
\Yaf\Registry
::
get
(
'config'
)
->
wechat
->
secret
;
$grant_type
=
'authorization_code'
;
$loginUrl
=
'https://api.weixin.qq.com/sns/jscode2session'
;
//请求接口,获取用户openid
$params
=
[
'appid'
=>
$appid
,
'secret'
=>
$secret
,
'js_code'
=>
$code
,
'grant_type'
=>
$grant_type
,
];
$response
=
(
new
Request
())
->
post
(
$loginUrl
,
$params
);
if
(
$response
[
'code'
]
==
0
)
{
$response
=
$response
[
'response'
];
}
$appid
=
\Yaf\Registry
::
get
(
'config'
)
->
wechat
->
appid
;
$secret
=
\Yaf\Registry
::
get
(
'config'
)
->
wechat
->
secret
;
$grant_type
=
'authorization_code'
;
$loginUrl
=
'https://api.weixin.qq.com/sns/jscode2session'
;
//请求接口,获取用户openid
$params
=
[
'appid'
=>
$appid
,
'secret'
=>
$secret
,
'js_code'
=>
$code
,
'grant_type'
=>
$grant_type
,
];
$begin
=
microtime
(
true
);
$response
=
(
new
Request
())
->
post
(
$loginUrl
,
$params
);
if
(
empty
(
$response
)
||
array_key_exists
(
'errcode'
,
$response
))
{
//throw new \Exception('获取openid失败:' . $response['errcode']);
FileLog
::
error
(
"wechatLogin:获取openid失败"
,
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
''
,
'jianghaiming@yidian-inc.com'
);
throw
new
UserException
([
'cus'
=>
1
]);
}
//检查系统是已注册
$openid
=
!
empty
(
$response
[
'openid'
])
?
$response
[
'openid'
]
:
''
;
$end
=
microtime
(
true
);
$totalTime
=
round
((
$end
-
$begin
),
4
)
*
1000
;
if
(
$response
[
'code'
]
==
0
)
{
$response
=
$response
[
'response'
];
}
//mon打点
$env
=
Application
::
app
()
->
environ
()
??
"dev"
;
MonUtil
::
proxyMon
(
$loginUrl
,
$response
[
'code'
],
'weixin_'
.
$env
,
$totalTime
);
if
(
empty
(
$response
)
||
array_key_exists
(
'errcode'
,
$response
))
{
//throw new \Exception('获取openid失败:' . $response['errcode']);
FileLog
::
error
(
"wechatLogin:获取openid失败"
,
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
''
,
'jianghaiming@yidian-inc.com'
);
throw
new
UserException
([
'cus'
=>
1
]);
}
//检查系统是已注册
$openid
=
!
empty
(
$response
[
'openid'
])
?
$response
[
'openid'
]
:
''
;
//}
...
...
@@ -75,34 +82,34 @@ class UserService
$sessionKey
=
!
empty
(
$response
[
'session_key'
])
?
$response
[
'session_key'
]
:
''
;
//$newWechatId = UserWechatBind::save($insert);
$newWechatId
=
UserWechatBind
::
insertDuplicate
(
$insert
,
[
'session_key'
=>
$sessionKey
,
'create_time'
=>
date
(
"Y-m-d H:i:s"
)]);
$newWechatId
=
UserWechatBind
::
insertDuplicate
(
$insert
,
[
'session_key'
=>
$sessionKey
,
'create_time'
=>
date
(
"Y-m-d H:i:s"
)]);
if
(
!
$newWechatId
)
{
FileLog
::
error
(
"wechatLogin:登陆创建用户失败"
,
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
''
,
'jianghaiming@yidian-inc.com'
);
FileLog
::
error
(
"wechatLogin:登陆创建用户失败--insert"
,
json_encode
(
$insert
,
JSON_UNESCAPED_UNICODE
),
''
,
'jianghaiming@yidian-inc.com'
);
FileLog
::
error
(
"wechatLogin:登陆创建用户失败"
,
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
''
,
'jianghaiming@yidian-inc.com'
);
FileLog
::
error
(
"wechatLogin:登陆创建用户失败--insert"
,
json_encode
(
$insert
,
JSON_UNESCAPED_UNICODE
),
''
,
'jianghaiming@yidian-inc.com'
);
throw
new
UserException
([
'cus'
=>
2
]);
}
$user
[
'wechat_id'
]
=
$newWechatId
;
$user
[
'openid'
]
=
$response
[
'openid'
];
$user
[
'session_key'
]
=
$response
[
'session_key'
];
}
else
{
}
else
{
if
(
empty
(
$user
))
{
FileLog
::
error
(
"wechatLogin:登陆创建用户失败-- 微信response"
,
json_encode
(
$response
,
JSON_UNESCAPED_UNICODE
),
''
,
'jianghaiming@yidian-inc.com'
);
FileLog
::
error
(
"wechatLogin:登陆创建用户失败-- 微信response"
,
json_encode
(
$response
,
JSON_UNESCAPED_UNICODE
),
''
,
'jianghaiming@yidian-inc.com'
);
throw
new
UserException
([
'cus'
=>
2
]);
}
if
(
empty
(
$response
)){
FileLog
::
error
(
"wechatLogin:登陆创建用户失败-- 微信response 获取失败"
,
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
''
,
'jianghaiming@yidian-inc.com'
);
if
(
empty
(
$response
))
{
FileLog
::
error
(
"wechatLogin:登陆创建用户失败-- 微信response 获取失败"
,
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
''
,
'jianghaiming@yidian-inc.com'
);
throw
new
UserException
([
'cus'
=>
2
]);
}
$insert
=
[
'session_key'
=>
!
empty
(
$response
[
'session_key'
])
?
$response
[
'session_key'
]
:
''
,
];
$newWechatId
=
UserWechatBind
::
save
(
$insert
,[
'openid'
=>
$openid
]);
$newWechatId
=
UserWechatBind
::
save
(
$insert
,
[
'openid'
=>
$openid
]);
}
$user
[
'third_session'
]
=
self
::
generate3rdSession
(
$openid
);
return
$user
;
return
$user
;
}
/**
...
...
@@ -117,9 +124,9 @@ class UserService
{
$openid
=
!
empty
(
$params
[
'openid'
])
?
$params
[
'openid'
]
:
''
;
$encryptedData
=
!
empty
(
$params
[
'encryptedData'
])
?
$params
[
'encryptedData'
]
:
''
;
$iv
=
!
empty
(
$params
[
'iv'
])
?
$params
[
'iv'
]
:
''
;
$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'
);
throw
new
UserException
([
'cus'
=>
3
]);
...
...
@@ -204,7 +211,7 @@ class UserService
public
static
function
userWechatBind
(
$params
)
{
$data
[
'wechat_id[>]'
]
=
0
;
if
(
!
empty
(
$params
[
'openid'
]))
{
...
...
@@ -218,7 +225,7 @@ class UserService
if
(
!
empty
(
$params
[
'phone'
]))
{
$data
[
'phone'
]
=
$params
[
'phone'
];
}
$userList
=
UserWechatBind
::
getRecords
(
$data
);
return
$userList
;
}
...
...
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