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
61378267
Commit
61378267
authored
Apr 21, 2022
by
谢永靖
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
f268444c
Pipeline
#36755
passed with stage
in 9 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
26 deletions
+30
-26
response.js
app/controller/response.js
+30
-26
No files found.
app/controller/response.js
View file @
61378267
...
@@ -4,9 +4,9 @@ const Controller = require('egg').Controller;
...
@@ -4,9 +4,9 @@ const Controller = require('egg').Controller;
class
ResponseController
extends
Controller
{
class
ResponseController
extends
Controller
{
//
内部授权注册
//
内部授权注册
async
internalAuth
()
{
async
internalAuth
()
{
//
https://b.jianbing.com/51business/api/response/internal/auth?target_url=https://b.jianbing.com/webserve/51estate/index&channel_id=fc_gjjfc1
//
https://b.jianbing.com/51business/api/response/internal/auth?target_url=https://b.jianbing.com/webserve/51estate/index&channel_id=fc_gjjfc1
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
const
header
=
ctx
.
request
.
header
;
const
header
=
ctx
.
request
.
header
;
const
input_params
=
ctx
.
query
;
const
input_params
=
ctx
.
query
;
...
@@ -14,7 +14,8 @@ class ResponseController extends Controller {
...
@@ -14,7 +14,8 @@ class ResponseController extends Controller {
const
rule
=
{
const
rule
=
{
target_url
:
{
type
:
'string'
,
required
:
true
},
target_url
:
{
type
:
'string'
,
required
:
true
},
channel_id
:
{
type
:
'string'
,
required
:
true
},
channel_id
:
{
type
:
'string'
,
required
:
true
},
}
auth_token
:
{
type
:
'string'
,
required
:
false
},
};
ctx
.
validate
(
rule
,
input_params
);
ctx
.
validate
(
rule
,
input_params
);
const
channel_alias
=
input_params
.
channel_id
;
const
channel_alias
=
input_params
.
channel_id
;
...
@@ -27,7 +28,7 @@ class ResponseController extends Controller {
...
@@ -27,7 +28,7 @@ class ResponseController extends Controller {
const
target_url1
=
decodeURI
(
target_url
);
const
target_url1
=
decodeURI
(
target_url
);
const
target_url2
=
encodeURI
(
target_url1
);
const
target_url2
=
encodeURI
(
target_url1
);
//
如果cookie中已存在 5要素 则可直接 跳到目标地址
//
如果cookie中已存在 5要素 则可直接 跳到目标地址
const
token
=
ctx
.
cookies
.
get
(
'token'
,
{
signed
:
false
});
const
token
=
ctx
.
cookies
.
get
(
'token'
,
{
signed
:
false
});
const
user_id
=
ctx
.
cookies
.
get
(
'user_id'
,
{
signed
:
false
});
const
user_id
=
ctx
.
cookies
.
get
(
'user_id'
,
{
signed
:
false
});
const
app_user_id
=
ctx
.
cookies
.
get
(
'app_user_id'
,
{
signed
:
false
});
const
app_user_id
=
ctx
.
cookies
.
get
(
'app_user_id'
,
{
signed
:
false
});
...
@@ -51,9 +52,12 @@ class ResponseController extends Controller {
...
@@ -51,9 +52,12 @@ class ResponseController extends Controller {
}
}
}
}
const
auth_token
=
ctx
.
cookies
.
get
(
'auth_token'
,
{
signed
:
false
});
let
auth_token
=
ctx
.
cookies
.
get
(
'auth_token'
,
{
signed
:
false
});
if
(
!
auth_token
&&
input_params
.
auth_token
)
{
auth_token
=
input_params
.
auth_token
;
}
ctx
.
logger
.
info
(
'target_user--'
+
new
Date
().
getTime
()
+
JSON
.
stringify
({
target_old_user
:
{
auth_token
,
user_sid
}
}));
ctx
.
logger
.
info
(
'target_user--'
+
new
Date
().
getTime
()
+
JSON
.
stringify
({
target_old_user
:
{
auth_token
,
user_sid
}
}));
const
phone_info
=
await
ctx
.
service
.
user
.
get_phone_by_user_sid
({
user_sid
:
user_sid
,
token
:
auth_token
});
//
获取用户手机号码
const
phone_info
=
await
ctx
.
service
.
user
.
get_phone_by_user_sid
({
user_sid
,
token
:
auth_token
});
//
获取用户手机号码
ctx
.
logger
.
info
(
'phone_info: '
+
JSON
.
stringify
(
phone_info
));
ctx
.
logger
.
info
(
'phone_info: '
+
JSON
.
stringify
(
phone_info
));
const
phone
=
phone_info
.
phone
;
const
phone
=
phone_info
.
phone
;
// const phone = '15968762898';
// const phone = '15968762898';
...
@@ -63,19 +67,19 @@ class ResponseController extends Controller {
...
@@ -63,19 +67,19 @@ class ResponseController extends Controller {
const
app_id
=
(
app_channel_info
&&
app_channel_info
.
app_id
)
?
app_channel_info
.
app_id
:
false
;
const
app_id
=
(
app_channel_info
&&
app_channel_info
.
app_id
)
?
app_channel_info
.
app_id
:
false
;
let
node_user_center_login_ret
=
{};
let
node_user_center_login_ret
=
{};
if
(
phone
&&
channel_id
&&
app_id
)
{
//
当配置的渠道别名 无法找到对应的 channel_id 和app_id时 使用设备登录
if
(
phone
&&
channel_id
&&
app_id
)
{
//
当配置的渠道别名 无法找到对应的 channel_id 和app_id时 使用设备登录
const
go_register_params
=
{
const
go_register_params
=
{
phone
:
phone
,
phone
,
app_id
:
app_id
,
app_id
,
channel_id
:
channel_id
,
channel_id
,
}
};
ctx
.
logger
.
info
(
'go_register_params: '
+
JSON
.
stringify
(
go_register_params
));
ctx
.
logger
.
info
(
'go_register_params: '
+
JSON
.
stringify
(
go_register_params
));
// console.info(this.config.NODE_URL + '/login/go_register');
// console.info(this.config.NODE_URL + '/login/go_register');
const
result_go_register
=
await
ctx
.
helper
.
send_request
(
this
.
config
.
NODE_URL
+
'/login/go_register'
,
go_register_params
,
{
method
:
'POST'
});
//
通过手机号直接注册新用户中心
const
result_go_register
=
await
ctx
.
helper
.
send_request
(
this
.
config
.
NODE_URL
+
'/login/go_register'
,
go_register_params
,
{
method
:
'POST'
});
//
通过手机号直接注册新用户中心
node_user_center_login_ret
=
result_go_register
.
data
;
node_user_center_login_ret
=
result_go_register
.
data
;
ctx
.
logger
.
info
(
'target_user--'
+
new
Date
().
getTime
()
+
JSON
.
stringify
({
target_old_user
:
{
go_register_params
,
node_user_center_login_ret
}
}));
ctx
.
logger
.
info
(
'target_user--'
+
new
Date
().
getTime
()
+
JSON
.
stringify
({
target_old_user
:
{
go_register_params
,
node_user_center_login_ret
}
}));
ctx
.
logger
.
info
(
'go_register_result: '
+
JSON
.
stringify
(
node_user_center_login_ret
));
ctx
.
logger
.
info
(
'go_register_result: '
+
JSON
.
stringify
(
node_user_center_login_ret
));
ctx
.
logger
.
info
(
JSON
.
stringify
({
url
:
ctx
.
app
.
config
.
NODE_URL
+
'/login/go_register'
,
go_register_params
:
go_register_params
,
go_register_result
:
node_user_center_login_ret
}));
ctx
.
logger
.
info
(
JSON
.
stringify
({
url
:
ctx
.
app
.
config
.
NODE_URL
+
'/login/go_register'
,
go_register_params
,
go_register_result
:
node_user_center_login_ret
}));
node_user_center_login_ret
.
user_id
=
node_user_center_login_ret
.
uid
;
node_user_center_login_ret
.
user_id
=
node_user_center_login_ret
.
uid
;
node_user_center_login_ret
.
device_login_id
=
node_user_center_login_ret
.
device_login_logs_id
;
node_user_center_login_ret
.
device_login_id
=
node_user_center_login_ret
.
device_login_logs_id
;
delete
(
node_user_center_login_ret
.
uid
);
delete
(
node_user_center_login_ret
.
uid
);
...
@@ -83,32 +87,32 @@ class ResponseController extends Controller {
...
@@ -83,32 +87,32 @@ class ResponseController extends Controller {
}
}
// ctx.logger.info('target_user--' + new Date().getTime() + JSON.stringify({ target_old_user: { channel_id, app_id } }));
// ctx.logger.info('target_user--' + new Date().getTime() + JSON.stringify({ target_old_user: { channel_id, app_id } }));
if
(
!
phone
||
!
channel_id
||
!
app_id
||
!
node_user_center_login_ret
.
token
)
{
// 或渠道错误 或直接注册新用户中心失败时 使用设备登录
if
(
!
phone
||
!
channel_id
||
!
app_id
||
!
node_user_center_login_ret
.
token
)
{
// 或渠道错误 或直接注册新用户中心失败时 使用设备登录
const
user_agent
=
header
.
user_agent
?
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
user_agent
=
header
.
user_agent
?
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
ip
=
ctx
.
helper
.
getClientIP
();
const
device_no
=
ctx
.
helper
.
md5
(
user_agent
+
ip
);
const
device_no
=
ctx
.
helper
.
md5
(
user_agent
+
ip
);
const
past_deviceno
=
device_no
+
new
Date
().
getTime
();
//
根据 user_agent 和ip生成设备号
const
past_deviceno
=
device_no
+
new
Date
().
getTime
();
//
根据 user_agent 和ip生成设备号
const
device_login_params
=
{
const
device_login_params
=
{
past_deviceno
:
past_deviceno
,
past_deviceno
,
channel_id
:
channel_id
,
channel_id
,
app_id
:
app_id
,
app_id
,
device_info
:
{},
device_info
:
{},
}
};
ctx
.
logger
.
info
(
'device_login_params: '
+
JSON
.
stringify
(
device_login_params
));
//
设备登录参数
ctx
.
logger
.
info
(
'device_login_params: '
+
JSON
.
stringify
(
device_login_params
));
//
设备登录参数
const
result_device_login
=
await
ctx
.
helper
.
send_request
(
this
.
config
.
NODE_URL
+
'/login/device'
,
device_login_params
,
{
method
:
'POST'
});
//
设备登录
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
;
//
设备登录返回结果
const
device_login_data
=
result_device_login
.
data
;
//
设备登录返回结果
ctx
.
logger
.
info
(
'device_login_result: '
+
JSON
.
stringify
(
device_login_data
));
ctx
.
logger
.
info
(
'device_login_result: '
+
JSON
.
stringify
(
device_login_data
));
ctx
.
logger
.
info
(
'target_user--'
+
new
Date
().
getTime
()
+
JSON
.
stringify
({
target_old_user
:
{
device_login_params
,
result_device_login
}
}));
ctx
.
logger
.
info
(
'target_user--'
+
new
Date
().
getTime
()
+
JSON
.
stringify
({
target_old_user
:
{
device_login_params
,
result_device_login
}
}));
if
(
!
device_login_data
||
Object
.
keys
(
device_login_data
).
length
===
0
)
{
if
(
!
device_login_data
||
Object
.
keys
(
device_login_data
).
length
===
0
)
{
ctx
.
failed
(
'device login error, device_login_data empty'
);
ctx
.
failed
(
'device login error, device_login_data empty'
);
}
}
if
(
!
device_login_data
.
past_deviceno
)
{
//
使用设备码+时间+随机数产生的一个尽量避免重复的字符串,类似游客版h5
if
(
!
device_login_data
.
past_deviceno
)
{
//
使用设备码+时间+随机数产生的一个尽量避免重复的字符串,类似游客版h5
ctx
.
failed
(
'device login error, past_deviceno empty'
);
ctx
.
failed
(
'device login error, past_deviceno empty'
);
}
}
if
(
!
device_login_data
.
device_id
)
{
//
Devices字段表主键ID
if
(
!
device_login_data
.
device_id
)
{
//
Devices字段表主键ID
ctx
.
failed
(
'device login error, device_id empty'
);
ctx
.
failed
(
'device login error, device_id empty'
);
}
}
if
(
!
device_login_data
.
device_login_logs_id
)
{
//
DeviceLoginLogs字段表主键ID
if
(
!
device_login_data
.
device_login_logs_id
)
{
//
DeviceLoginLogs字段表主键ID
ctx
.
failed
(
'device login error, device_login_logs_id empty'
);
ctx
.
failed
(
'device login error, device_login_logs_id empty'
);
}
}
node_user_center_login_ret
.
device_id
=
device_login_data
.
device_id
;
node_user_center_login_ret
.
device_id
=
device_login_data
.
device_id
;
...
@@ -117,7 +121,7 @@ class ResponseController extends Controller {
...
@@ -117,7 +121,7 @@ class ResponseController extends Controller {
const
expire
=
7200
*
1000
;
const
expire
=
7200
*
1000
;
const
date
=
new
Date
();
const
date
=
new
Date
();
for
(
le
t
key
in
node_user_center_login_ret
)
{
for
(
cons
t
key
in
node_user_center_login_ret
)
{
const
value
=
node_user_center_login_ret
[
key
];
const
value
=
node_user_center_login_ret
[
key
];
// const exist_value = ctx.cookies.get(key, { signed: false });
// const exist_value = ctx.cookies.get(key, { signed: false });
// if (!exist_value) {
// if (!exist_value) {
...
...
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