Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
5
51business
Project
Project
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
方斌
51business
Commits
8c00b500
Commit
8c00b500
authored
Oct 16, 2019
by
李尚科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
a149c56e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
9 deletions
+88
-9
wechat.js
app/controller/gjj/wechat.js
+88
-9
No files found.
app/controller/gjj/wechat.js
View file @
8c00b500
...
...
@@ -14,8 +14,9 @@ class WechatController extends Controller {
const
{
ctx
}
=
this
;
const
code
=
ctx
.
query
.
code
;
const
channel_id
=
ctx
.
query
.
channel_id
;
if
(
!
code
||
code
.
length
===
0
)
{
const
target_url
=
WECHAT_CODE_URL
+
`?appid=
${
WECHAT_APPID
}
&redirect_uri=
${
encodeURIComponent
(
`https://p.jianbing.com/51ucenter/api/user/oauth?
business_url=
${
encodeURIComponent
(
business_url
)}
&login_url=
${
encodeURIComponent
(
login_url
)}
&appid=
${
appid
}
&
`
)}
&response_type=code&scope=snsapi_base&state=gjjquery#wechat_redirect`
;
const
target_url
=
WECHAT_CODE_URL
+
`?appid=
${
WECHAT_APPID
}
&redirect_uri=
${
encodeURIComponent
(
`https://p.jianbing.com/51ucenter/api/user/oauth?
&channel_id=
${
channel_id
}
`
)}
&response_type=code&scope=snsapi_base&state=gjjquery#wechat_redirect`
;
ctx
.
redirect
(
target_url
);
}
const
url
=
`
${
WECHAT_AUTH
}
?appid=
${
WECHAT_APPID
}
&secret=
${
WECHAT_SECRET
}
&code=
${
code
}
&grant_type=authorization_code`
...
...
@@ -51,14 +52,7 @@ class WechatController extends Controller {
ctx
.
redirect
(
NO_GJJ_PAGE
);
return
;
}
const
login_params
=
{
code
:
code
,
login_type
:
'5'
,
passport
:
code
,
password
:
code
,
openid
:
openid
,
}
await
ctx
.
service
.
user
.
user_login
(
login_params
);
//用户直接登录
await
this
.
user_login
({
code
,
openid
,
channel_id
});
//用户直接登录
ctx
.
redirect
(
GJJ_DETAIL_PAGE
);
return
;
}
...
...
@@ -74,6 +68,91 @@ class WechatController extends Controller {
const
phone
=
await
ctx
.
helper
.
getPhoneCity
(
'15968762898'
);
ctx
.
success
({
result
:
is_login
,
phone
});
}
async
user_login
(
params
){
const
{
ctx
}
=
this
;
const
{
code
,
openid
,
channel_id
}
=
params
;
const
user_agent
=
ctx
.
request
.
header
.
user_agent
?
ctx
.
request
.
header
.
user_agent
:
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'
;
const
ip
=
ctx
.
helper
.
getClientIP
();
const
past_deviceno
=
ctx
.
helper
.
md5
(
user_agent
+
ip
);
const
app_channel_info
=
await
ctx
.
poseidonModel
.
AppChannel
.
one
({
where
:
{
alias
:
channel_id
}
});
if
(
!
app_channel_info
||
Object
.
keys
(
app_channel_info
).
length
===
0
)
{
ctx
.
failed
(
'渠道未配置'
);
}
if
(
!
app_channel_info
.
app_id
)
{
ctx
.
failed
(
'渠道未关联APPID'
);
}
const
device_login_params
=
{
past_deviceno
:
past_deviceno
,
channel_id
:
app_channel_info
.
channel_id
,
app_id
:
app_channel_info
.
app_id
,
device_info
:
{},
}
const
result_device_login
=
await
ctx
.
helper
.
send_request
(
this
.
config
.
NODE_URL
+
'/login/device'
,
device_login_params
,
{
method
:
'POST'
});
//设备登录
const
device_login_data
=
result_device_login
.
data
;
//设备登录返回结果
if
(
!
device_login_data
||
Object
.
keys
(
device_login_data
).
length
===
0
)
{
ctx
.
failed
(
'device login error, device_login_data empty'
);
}
if
(
!
device_login_data
.
past_deviceno
)
{
//使用设备码+时间+随机数产生的一个尽量避免重复的字符串,类似游客版h5
ctx
.
failed
(
'device login error, past_deviceno empty'
);
}
if
(
!
device_login_data
.
device_id
)
{
//Devices字段表主键ID
ctx
.
failed
(
'device login error, device_id empty'
);
}
if
(
!
device_login_data
.
device_login_logs_id
)
{
//DeviceLoginLogs字段表主键ID
ctx
.
failed
(
'device login error, device_login_logs_id empty'
);
}
const
user_login_params
=
{
//用户登录传递的参数
past_deviceno
:
past_deviceno
,
//使用设备码+时间+随机数产生的一个尽量避免重复的字符串,类似游客版h5登
// device_no: device_login_data.device_no,//使用新的sdk生成的设备指纹
login_type
:
'5'
,
//登录类型:1 验证码手机登录, 2 password手机登录,4 token登录,5 微信登录,
passport
:
code
,
//登录账号:手机登录值为手机
password
:
code
,
//类型对应的值
app_user_id
:
input_params
.
app_user_id
||
''
,
//app用户ID token登陆时传的参数 可空
code
:
code
||
''
,
//第三方授权登录时的code 可空
device_info
:
{},
//设备信息
openid
:
openid
||
''
//例如微信公众号的appid(不传默认是51查个税)
};
const
result_user_login
=
await
ctx
.
helper
.
send_request
(
this
.
config
.
NODE_URL
+
'/login/user'
,
user_login_params
,
{
method
:
'POST'
});
//用户登录
const
user_login_data
=
result_user_login
.
data
;
//用户登录返回结果
if
(
!
user_login_data
||
Object
.
keys
(
user_login_data
).
length
===
0
)
{
ctx
.
failed
(
'用户的登录失败'
);
}
if
(
!
user_login_data
.
token
||
!
user_login_data
.
uid
)
{
const
error_msg
=
user_login_data
.
error
?
user_login_data
.
error
:
'用户的登录失败'
;
ctx
.
failed
(
error_msg
);
}
//获取用户信息
const
login_token
=
user_login_data
.
token
;
const
app_user_id
=
user_login_data
.
app_user_id
;
const
user_id
=
user_login_data
.
uid
;
const
device_id
=
device_login_data
.
device_id
;
const
device_login_id
=
device_login_data
.
device_login_logs_id
;
const
env
=
this
.
app
.
config
.
env
;
let
host
=
this
.
config
.
NODE_BASE_URL
;
if
(
env
===
'prod'
)
host
=
host
.
replace
(
'lan-nginx.jianbing.com'
,
'p.jianbing.com'
);
const
user_info
=
{
token
:
login_token
,
app_user_id
:
app_user_id
,
user_id
:
user_id
,
device_id
:
device_id
,
device_login_id
:
device_login_id
,
android_url
:
`
${
host
}
/frontendh5/lp/wc/index?down=
${
encodeURIComponent
(
app_channel_info
.
android_url
)}
`
,
ios_url
:
app_channel_info
.
ios_url
,
}
for
(
let
key
in
user_info
)
{
const
value
=
user_info
[
key
];
ctx
.
cookies
.
set
(
key
,
value
,
{
httpOnly
:
false
,
signed
:
false
,
path
:
'/'
,
overwrite
:
true
});
}
return
user_info
;
}
}
module
.
exports
=
WechatController
;
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