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
11b7e488
Commit
11b7e488
authored
Nov 19, 2019
by
李尚科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
user_sid fix
parent
cf7d8cae
Pipeline
#16680
passed with stage
in 6 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
43 deletions
+43
-43
wechat.js
app/controller/gjj/wechat.js
+41
-42
helper.js
app/extend/helper.js
+2
-1
No files found.
app/controller/gjj/wechat.js
View file @
11b7e488
...
@@ -12,7 +12,7 @@ const REDIRECT_PAGE = '/webserve/accumulation/index';
...
@@ -12,7 +12,7 @@ const REDIRECT_PAGE = '/webserve/accumulation/index';
class
WechatController
extends
Controller
{
class
WechatController
extends
Controller
{
//
公众号公积金查询H5授权跳转
//
公众号公积金查询H5授权跳转
async
oauthLogin
()
{
async
oauthLogin
()
{
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
...
@@ -20,11 +20,11 @@ class WechatController extends Controller {
...
@@ -20,11 +20,11 @@ class WechatController extends Controller {
const
channel_id
=
ctx
.
query
.
channel_id
;
const
channel_id
=
ctx
.
query
.
channel_id
;
const
app_id
=
[
'https://lan-nginx.jianbing.com'
,
'https://pro-nginx.jianbing.com'
].
includes
(
this
.
config
.
NODE_BASE_URL
)
?
WECHAT_APPID
:
WECHAT_APPID_TEST
;
const
app_id
=
[
'https://lan-nginx.jianbing.com'
,
'https://pro-nginx.jianbing.com'
].
includes
(
this
.
config
.
NODE_BASE_URL
)
?
WECHAT_APPID
:
WECHAT_APPID_TEST
;
const
appsecret
=
[
'https://lan-nginx.jianbing.com'
,
'https://pro-nginx.jianbing.com'
].
includes
(
this
.
config
.
NODE_BASE_URL
)
?
WECHAT_SECRET
:
WECHAT_SECRET_TEST
;
const
appsecret
=
[
'https://lan-nginx.jianbing.com'
,
'https://pro-nginx.jianbing.com'
].
includes
(
this
.
config
.
NODE_BASE_URL
)
?
WECHAT_SECRET
:
WECHAT_SECRET_TEST
;
if
(
!
code
||
code
.
length
===
0
)
{
//
this.app.config.OUT_P_NODE_URL
if
(
!
code
||
code
.
length
===
0
)
{
//
this.app.config.OUT_P_NODE_URL
const
target_url
=
WECHAT_CODE_URL
+
`?appid=
${
app_id
}
&redirect_uri=
${
encodeURIComponent
(
`
${
this
.
app
.
config
.
PULIC_BASE_URL
}
/51business/api/gjj/wechat/oauth_login?&channel_id=
${
channel_id
}
`
)}
&response_type=code&scope=snsapi_base&state=gjjquery#wechat_redirect`
;
const
target_url
=
WECHAT_CODE_URL
+
`?appid=
${
app_id
}
&redirect_uri=
${
encodeURIComponent
(
`
${
this
.
app
.
config
.
PULIC_BASE_URL
}
/51business/api/gjj/wechat/oauth_login?&channel_id=
${
channel_id
}
`
)}
&response_type=code&scope=snsapi_base&state=gjjquery#wechat_redirect`
;
ctx
.
redirect
(
target_url
);
return
;
ctx
.
redirect
(
target_url
);
return
;
}
}
const
url
=
`
${
WECHAT_AUTH
}
?appid=
${
app_id
}
&secret=
${
appsecret
}
&code=
${
code
}
&grant_type=authorization_code`
const
url
=
`
${
WECHAT_AUTH
}
?appid=
${
app_id
}
&secret=
${
appsecret
}
&code=
${
code
}
&grant_type=authorization_code`
;
const
result
=
await
ctx
.
helper
.
send_request
(
url
,
{},
{
method
:
'GET'
});
const
result
=
await
ctx
.
helper
.
send_request
(
url
,
{},
{
method
:
'GET'
});
ctx
.
logger
.
info
(
JSON
.
stringify
({
wx_gjj_query
:
result
}));
ctx
.
logger
.
info
(
JSON
.
stringify
({
wx_gjj_query
:
result
}));
if
(
result
.
status
!==
200
)
{
if
(
result
.
status
!==
200
)
{
...
@@ -35,7 +35,7 @@ class WechatController extends Controller {
...
@@ -35,7 +35,7 @@ class WechatController extends Controller {
ctx
.
failed
(
'获取openid失败2'
);
ctx
.
failed
(
'获取openid失败2'
);
}
}
const
openid
=
wx_ret
.
openid
;
const
openid
=
wx_ret
.
openid
;
//
在微信端需要关闭微信重新打开才会销毁cookie值,所以在这里重置cookie值
//
在微信端需要关闭微信重新打开才会销毁cookie值,所以在这里重置cookie值
ctx
.
cookies
.
set
(
'openid'
,
openid
,
{
httpOnly
:
false
,
signed
:
false
,
path
:
'/'
,
overwrite
:
true
});
ctx
.
cookies
.
set
(
'openid'
,
openid
,
{
httpOnly
:
false
,
signed
:
false
,
path
:
'/'
,
overwrite
:
true
});
ctx
.
cookies
.
set
(
'token'
,
null
,
{
httpOnly
:
false
,
signed
:
false
,
path
:
'/'
,
overwrite
:
true
});
ctx
.
cookies
.
set
(
'token'
,
null
,
{
httpOnly
:
false
,
signed
:
false
,
path
:
'/'
,
overwrite
:
true
});
ctx
.
cookies
.
set
(
'user_id'
,
null
,
{
httpOnly
:
false
,
signed
:
false
,
path
:
'/'
,
overwrite
:
true
});
ctx
.
cookies
.
set
(
'user_id'
,
null
,
{
httpOnly
:
false
,
signed
:
false
,
path
:
'/'
,
overwrite
:
true
});
...
@@ -44,40 +44,40 @@ class WechatController extends Controller {
...
@@ -44,40 +44,40 @@ class WechatController extends Controller {
ctx
.
cookies
.
set
(
'auth_token'
,
null
,
{
httpOnly
:
false
,
signed
:
false
,
path
:
'/'
,
overwrite
:
true
});
ctx
.
cookies
.
set
(
'auth_token'
,
null
,
{
httpOnly
:
false
,
signed
:
false
,
path
:
'/'
,
overwrite
:
true
});
const
redirect_url
=
this
.
app
.
config
.
PULIC_BASE_URL
+
REDIRECT_PAGE
;
const
redirect_url
=
this
.
app
.
config
.
PULIC_BASE_URL
+
REDIRECT_PAGE
;
//
判断是否已绑定手机号
//
判断是否已绑定手机号
const
user_exist_url
=
`
${
this
.
app
.
config
.
NODE_BASE_URL
}
/user_api/v1/user/is_exist/
${
openid
}
`
;
const
user_exist_url
=
`
${
this
.
app
.
config
.
NODE_BASE_URL
}
/user_api/v1/user/is_exist/
${
openid
}
`
;
const
bind_phone_result
=
await
ctx
.
helper
.
send_request
(
user_exist_url
,
{
type
:
5
},
{
method
:
'GET'
});
const
bind_phone_result
=
await
ctx
.
helper
.
send_request
(
user_exist_url
,
{
type
:
5
},
{
method
:
'GET'
});
ctx
.
logger
.
info
(
JSON
.
stringify
({
bind_phone_result
:
bind_phone_result
}));
ctx
.
logger
.
info
(
JSON
.
stringify
({
bind_phone_result
}));
if
(
bind_phone_result
.
status
!==
200
)
{
if
(
bind_phone_result
.
status
!==
200
)
{
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=noLogin`
);
return
;
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=noLogin`
);
return
;
}
}
const
user_exist_ret
=
bind_phone_result
.
data
;
const
user_exist_ret
=
bind_phone_result
.
data
;
if
(
user_exist_ret
.
result
!=
'true'
)
{
//
未绑定的手机号时
if
(
user_exist_ret
.
result
!=
'true'
)
{
//
未绑定的手机号时
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=noLogin`
);
return
;
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=noLogin`
);
return
;
}
}
const
user_id
=
user_exist_ret
.
uid
;
const
user_id
=
user_exist_ret
.
uid
;
//
已绑定手机的 继续 判断是否有导入公积金
//
已绑定手机的 继续 判断是否有导入公积金
const
login_result
=
await
this
.
user_login
({
code
,
openid
,
channel_id
});
//
已绑定的用户 直接登录
const
login_result
=
await
this
.
user_login
({
code
,
openid
,
channel_id
});
//
已绑定的用户 直接登录
if
(
login_result
.
anew
&&
!
login_result
.
token
)
{
if
(
login_result
.
anew
&&
!
login_result
.
token
)
{
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=noLogin`
);
return
;
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=noLogin`
);
return
;
}
}
const
gjj_exist_url
=
`
${
this
.
app
.
config
.
NODE_BASE_URL
}
/cassandra-server/gjj/list/
${
user_id
}
`
;
const
gjj_exist_url
=
`
${
this
.
app
.
config
.
NODE_BASE_URL
}
/cassandra-server/gjj/list/
${
user_id
}
`
;
const
gjj_exist_result
=
await
ctx
.
helper
.
send_request
(
gjj_exist_url
,
{},
{
method
:
'GET'
});
const
gjj_exist_result
=
await
ctx
.
helper
.
send_request
(
gjj_exist_url
,
{},
{
method
:
'GET'
});
ctx
.
logger
.
info
(
JSON
.
stringify
({
gjj_exist_result
:
gjj_exist_result
}));
ctx
.
logger
.
info
(
JSON
.
stringify
({
gjj_exist_result
}));
if
(
gjj_exist_result
.
status
!==
200
)
{
//
调用公积金接口出错
if
(
gjj_exist_result
.
status
!==
200
)
{
//
调用公积金接口出错
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=noLogin`
);
return
;
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=noLogin`
);
return
;
}
}
const
gjj_exist_ret
=
gjj_exist_result
.
data
;
const
gjj_exist_ret
=
gjj_exist_result
.
data
;
if
(
!
gjj_exist_ret
.
ret
||
gjj_exist_ret
.
ret
.
length
===
0
)
{
//
没有导入公积金时
if
(
!
gjj_exist_ret
.
ret
||
gjj_exist_ret
.
ret
.
length
===
0
)
{
//
没有导入公积金时
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=noLogin`
);
return
;
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=noLogin`
);
return
;
}
}
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=hasLogin`
);
return
;
//
已导入公积金
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=hasLogin`
);
return
;
//
已导入公积金
}
}
//
判断是否有公积金导入并跳转
//
判断是否有公积金导入并跳转
// async checkGjj() {
// async checkGjj() {
// const { ctx } = this;
// const { ctx } = this;
...
@@ -106,7 +106,6 @@ class WechatController extends Controller {
...
@@ -106,7 +106,6 @@ class WechatController extends Controller {
}
}
async
user_login
(
params
)
{
async
user_login
(
params
)
{
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
...
@@ -125,40 +124,40 @@ class WechatController extends Controller {
...
@@ -125,40 +124,40 @@ class WechatController extends Controller {
}
}
const
device_login_params
=
{
const
device_login_params
=
{
past_deviceno
:
past_deviceno
,
past_deviceno
,
channel_id
:
app_channel_info
.
channel_id
,
channel_id
:
app_channel_info
.
channel_id
,
app_id
:
app_channel_info
.
app_id
,
app_id
:
app_channel_info
.
app_id
,
device_info
:
{},
device_info
:
{},
}
};
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
;
// 设备登录返回结果
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'
);
}
}
const
user_login_params
=
{
//
用户登录传递的参数
const
user_login_params
=
{
//
用户登录传递的参数
past_deviceno
:
past_deviceno
,
//
使用设备码+时间+随机数产生的一个尽量避免重复的字符串,类似游客版h5登
past_deviceno
,
//
使用设备码+时间+随机数产生的一个尽量避免重复的字符串,类似游客版h5登
// device_no: device_login_data.device_no,//使用新的sdk生成的设备指纹
// device_no: device_login_data.device_no,//使用新的sdk生成的设备指纹
login_type
:
'5'
,
//
登录类型:1 验证码手机登录, 2 password手机登录,4 token登录,5 微信登录,
login_type
:
'5'
,
//
登录类型:1 验证码手机登录, 2 password手机登录,4 token登录,5 微信登录,
passport
:
code
,
//
登录账号:手机登录值为手机
passport
:
code
,
//
登录账号:手机登录值为手机
password
:
code
,
//
类型对应的值
password
:
code
,
//
类型对应的值
app_user_id
:
params
.
app_user_id
||
''
,
//app用户ID token登陆时传的参数 可空
app_user_id
:
params
.
app_user_id
||
''
,
// app用户ID token登陆时传的参数 可空
code
:
code
||
''
,
//第三方授权登录时的code 可空
code
:
code
||
''
,
// 第三方授权登录时的code 可空
device_info
:
{},
//
设备信息
device_info
:
{},
//
设备信息
openid
:
openid
||
''
//
例如微信公众号的openid(不传默认是51查个税)
openid
:
openid
||
''
,
//
例如微信公众号的openid(不传默认是51查个税)
};
};
const
result_user_login
=
await
ctx
.
helper
.
send_request
(
this
.
config
.
NODE_URL
+
'/login/user'
,
user_login_params
,
{
method
:
'POST'
});
//
用户登录
const
result_user_login
=
await
ctx
.
helper
.
send_request
(
this
.
config
.
NODE_URL
+
'/login/user'
,
user_login_params
,
{
method
:
'POST'
});
//
用户登录
ctx
.
logger
.
info
(
JSON
.
stringify
({
user_login_params
:
user_login_params
,
result_user_login
:
result_user_login
}));
ctx
.
logger
.
info
(
JSON
.
stringify
({
user_login_params
,
result_user_login
}));
const
user_login_data
=
result_user_login
.
data
;
//
用户登录返回结果
const
user_login_data
=
result_user_login
.
data
;
//
用户登录返回结果
if
(
!
user_login_data
||
Object
.
keys
(
user_login_data
).
length
===
0
)
{
if
(
!
user_login_data
||
Object
.
keys
(
user_login_data
).
length
===
0
)
{
ctx
.
failed
(
'用户的登录失败'
);
ctx
.
failed
(
'用户的登录失败'
);
}
}
...
@@ -169,14 +168,14 @@ class WechatController extends Controller {
...
@@ -169,14 +168,14 @@ class WechatController extends Controller {
}
}
ctx
.
failed
(
error_msg
);
ctx
.
failed
(
error_msg
);
}
}
//
获取用户信息
//
获取用户信息
const
login_token
=
user_login_data
.
token
;
const
login_token
=
user_login_data
.
token
;
const
app_user_id
=
user_login_data
.
app_user_id
;
const
app_user_id
=
user_login_data
.
app_user_id
;
const
user_id
=
user_login_data
.
uid
;
const
user_id
=
user_login_data
.
uid
;
const
device_id
=
device_login_data
.
device_id
;
const
device_id
=
device_login_data
.
device_id
;
const
device_login_id
=
device_login_data
.
device_login_logs_id
;
const
device_login_id
=
device_login_data
.
device_login_logs_id
;
//
老版用户信息
//
老版用户信息
const
old_user_sid
=
user_login_data
.
old_uid
;
const
old_user_sid
=
user_login_data
.
old_uid
;
let
auth_token
=
''
;
let
auth_token
=
''
;
if
(
old_user_sid
)
{
if
(
old_user_sid
)
{
...
@@ -185,16 +184,16 @@ class WechatController extends Controller {
...
@@ -185,16 +184,16 @@ class WechatController extends Controller {
const
user_info
=
{
const
user_info
=
{
token
:
login_token
,
token
:
login_token
,
app_user_id
:
app_user_id
,
app_user_id
,
user_id
:
user_id
,
user_id
,
device_id
:
device_id
,
device_id
,
device_login_id
:
device_login_id
,
device_login_id
,
android_url
:
`
${
this
.
config
.
OUT_P_NODE_URL
}
/frontendh5/lp/wc/index?down=
${
encodeURIComponent
(
app_channel_info
.
android_url
)}
`
,
android_url
:
`
${
this
.
config
.
OUT_P_NODE_URL
}
/frontendh5/lp/wc/index?down=
${
encodeURIComponent
(
app_channel_info
.
android_url
)}
`
,
ios_url
:
app_channel_info
.
ios_url
,
ios_url
:
app_channel_info
.
ios_url
,
jianbing_customer_id
:
old_user_sid
,
jianbing_customer_id
:
old_user_sid
,
auth_token
,
auth_token
,
}
};
for
(
le
t
key
in
user_info
)
{
for
(
cons
t
key
in
user_info
)
{
const
value
=
user_info
[
key
];
const
value
=
user_info
[
key
];
ctx
.
cookies
.
set
(
key
,
value
,
{
httpOnly
:
false
,
signed
:
false
,
path
:
'/'
,
overwrite
:
true
});
ctx
.
cookies
.
set
(
key
,
value
,
{
httpOnly
:
false
,
signed
:
false
,
path
:
'/'
,
overwrite
:
true
});
}
}
...
...
app/extend/helper.js
View file @
11b7e488
...
@@ -437,8 +437,9 @@ module.exports = {
...
@@ -437,8 +437,9 @@ module.exports = {
decodeUserSid
(
code
)
{
decodeUserSid
(
code
)
{
if
(
!
code
)
return
code
;
const
rand
=
'OU1WjLvZCrRJ7Yo0gE2XDjuuaSAUuaH1bhHPuMymcdfEeKz0igRhXQkMuLTm1'
;
const
rand
=
'OU1WjLvZCrRJ7Yo0gE2XDjuuaSAUuaH1bhHPuMymcdfEeKz0igRhXQkMuLTm1'
;
code
=
code
.
s
ubstr
(
5
);
code
=
code
.
s
lice
(
5
,
code
.
length
);
const
begin
=
code
.
slice
(
0
,
1
);
const
begin
=
code
.
slice
(
0
,
1
);
let
rtn
=
''
;
let
rtn
=
''
;
const
codelen
=
rand
.
slice
(
0
,
11
);
const
codelen
=
rand
.
slice
(
0
,
11
);
...
...
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