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
100e1921
Commit
100e1921
authored
Oct 22, 2019
by
李尚科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix
parent
04d781ac
Pipeline
#15193
passed with stage
in 7 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
23 deletions
+48
-23
wechat.js
app/controller/gjj/wechat.js
+46
-23
gjj.js
app/router/gjj.js
+2
-0
No files found.
app/controller/gjj/wechat.js
View file @
100e1921
...
...
@@ -6,33 +6,36 @@ const WECHAT_AUTH = 'https://api.weixin.qq.com/sns/oauth2/access_token';
const
WECHAT_APPID
=
''
;
const
WECHAT_SECRET
=
''
;
const
NO_GJJ_PAGE
=
'https://www.baidu.com'
;
const
GJJ_DETAIL_PAGE
=
'https:www.jianbing.com'
;
const
GJJ_DETAIL_PAGE
=
'https:
//
www.jianbing.com'
;
class
WechatController
extends
Controller
{
//公众号公积金查询H5授权跳转
async
oauthLogin
()
{
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?&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`
const
result
=
await
ctx
.
helper
.
send_request
(
url
,
{},
{
method
:
'GET'
});
if
(
result
.
status
!==
200
)
{
ctx
.
failed
(
'获取openid失败'
);
}
const
wx_ret
=
result
.
data
;
if
(
!
wx_ret
.
openid
)
{
ctx
.
failed
(
'获取openid失败'
);
}
const
openid
=
wx_ret
.
openid
;
// 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?&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`
// const result = await ctx.helper.send_request(url, {}, { method: 'GET' });
// if (result.status !== 200) {
// ctx.failed('获取openid失败');
// }
// const wx_ret = result.data;
// if (!wx_ret.openid) {
// ctx.failed('获取openid失败');
// }
// const openid = wx_ret.openid;
const
openid
=
'lishangke'
;
//判断是否已绑定手机号
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
,
{},
{
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
}));
if
(
bind_phone_result
.
status
!==
200
)
{
ctx
.
redirect
(
NO_GJJ_PAGE
);
return
;
}
...
...
@@ -44,12 +47,13 @@ class WechatController extends Controller {
//判断是否有导入公积金
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'
});
ctx
.
logger
.
info
(
JSON
.
stringify
({
gjj_exist_result
:
gjj_exist_result
}));
if
(
gjj_exist_result
.
status
!==
200
)
{
ctx
.
redirect
(
NO_GJJ_PAGE
);
return
;
}
const
gjj_exist_ret
=
gjj_exist_result
.
data
;
if
(
!
gjj_exist_ret
.
ret
||
gjj_exist_ret
.
ret
.
length
===
0
)
{
//没有导入公积金时
ctx
.
redirect
(
NO_GJJ_PAGE
);
return
;
//
ctx.redirect(NO_GJJ_PAGE); return;
}
await
this
.
user_login
({
code
,
openid
,
channel_id
});
//用户直接登录
...
...
@@ -57,6 +61,22 @@ class WechatController extends Controller {
ctx
.
redirect
(
GJJ_DETAIL_PAGE
);
return
;
}
//判断是否有公积金导入并跳转
async
checkGjj
()
{
const
{
ctx
}
=
this
;
const
user_id
=
ctx
.
userId
;
//判断是否有导入公积金
console
.
info
(
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'
});
ctx
.
logger
.
info
(
JSON
.
stringify
({
gjj_exist_result
:
gjj_exist_result
}));
if
(
gjj_exist_result
.
status
!==
200
)
{
ctx
.
redirect
(
NO_GJJ_PAGE
);
return
;
}
ctx
.
redirect
(
GJJ_DETAIL_PAGE
);
return
;
}
async
checkLogin
()
{
const
{
ctx
}
=
this
;
...
...
@@ -65,11 +85,13 @@ class WechatController extends Controller {
if
(
user_id
)
{
is_login
=
true
;
}
const
phone
=
await
ctx
.
helper
.
getPhoneCity
(
'15968762898'
);
ctx
.
success
({
result
:
is_login
,
phone
});
//
const phone = await ctx.helper.getPhoneCity('15968762898');
ctx
.
success
({
result
:
is_login
});
}
async
user_login
(
params
){
async
user_login
(
params
)
{
const
{
ctx
}
=
this
;
const
{
code
,
openid
,
channel_id
}
=
params
;
...
...
@@ -78,7 +100,7 @@ class WechatController extends Controller {
const
ip
=
ctx
.
helper
.
getClientIP
();
const
past_deviceno
=
ctx
.
helper
.
md5
(
user_agent
+
ip
);
const
app_channel_info
=
await
ctx
.
poseidon
Model
.
AppChannel
.
one
({
where
:
{
alias
:
channel_id
}
});
const
app_channel_info
=
await
ctx
.
block
Model
.
AppChannel
.
one
({
where
:
{
alias
:
channel_id
}
});
if
(
!
app_channel_info
||
Object
.
keys
(
app_channel_info
).
length
===
0
)
{
ctx
.
failed
(
'渠道未配置'
);
}
...
...
@@ -113,12 +135,13 @@ class WechatController extends Controller {
login_type
:
'5'
,
//登录类型:1 验证码手机登录, 2 password手机登录,4 token登录,5 微信登录,
passport
:
code
,
//登录账号:手机登录值为手机
password
:
code
,
//类型对应的值
app_user_id
:
input_
params
.
app_user_id
||
''
,
//app用户ID token登陆时传的参数 可空
app_user_id
:
params
.
app_user_id
||
''
,
//app用户ID token登陆时传的参数 可空
code
:
code
||
''
,
//第三方授权登录时的code 可空
device_info
:
{},
//设备信息
openid
:
openid
||
''
//例如微信公众号的
app
id(不传默认是51查个税)
openid
:
openid
||
''
//例如微信公众号的
open
id(不传默认是51查个税)
};
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
}));
const
user_login_data
=
result_user_login
.
data
;
//用户登录返回结果
if
(
!
user_login_data
||
Object
.
keys
(
user_login_data
).
length
===
0
)
{
ctx
.
failed
(
'用户的登录失败'
);
...
...
app/router/gjj.js
View file @
100e1921
...
...
@@ -7,4 +7,6 @@ module.exports = app => {
router
.
get
(
'/mine/creditcards'
,
'gjj.mine.getMyCreditCards'
);
// 我的信用卡
router
.
get
(
'/wechat/check_login'
,
'gjj.wechat.checkLogin'
);
// 公积金公众号检查用户是否登录
router
.
get
(
'third'
,
'/wechat/oauth_login'
,
'gjj.wechat.oauthLogin'
);
// 公积金公众号授权登录
router
.
get
(
'/wechat/check_gjj'
,
'gjj.wechat.checkGjj'
);
// 公积金公众号授权登录
};
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