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
0dc6a0ac
Commit
0dc6a0ac
authored
Oct 23, 2019
by
李尚科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
100e1921
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
29 deletions
+32
-29
wechat.js
app/controller/gjj/wechat.js
+31
-28
gjj.js
app/router/gjj.js
+1
-1
No files found.
app/controller/gjj/wechat.js
View file @
0dc6a0ac
...
@@ -3,10 +3,10 @@
...
@@ -3,10 +3,10 @@
const
Controller
=
require
(
'egg'
).
Controller
;
const
Controller
=
require
(
'egg'
).
Controller
;
const
WECHAT_CODE_URL
=
'https://open.weixin.qq.com/connect/oauth2/authorize'
;
const
WECHAT_CODE_URL
=
'https://open.weixin.qq.com/connect/oauth2/authorize'
;
const
WECHAT_AUTH
=
'https://api.weixin.qq.com/sns/oauth2/access_token'
;
const
WECHAT_AUTH
=
'https://api.weixin.qq.com/sns/oauth2/access_token'
;
const
WECHAT_APPID
=
''
;
const
WECHAT_APPID
=
'
wx3c772df2d8d78da3
'
;
const
WECHAT_SECRET
=
''
;
const
WECHAT_SECRET
=
''
;
const
NO_GJJ
_PAGE
=
'https://www.baidu.com'
;
// const REDIRECT
_PAGE = 'https://www.baidu.com';
const
GJJ_DETAIL_PAGE
=
'https://www.jianbing.com
'
;
const
REDIRECT_PAGE
=
'/webserve/accumulation/index
'
;
class
WechatController
extends
Controller
{
class
WechatController
extends
Controller
{
...
@@ -16,8 +16,9 @@ class WechatController extends Controller {
...
@@ -16,8 +16,9 @@ class WechatController extends Controller {
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
const
code
=
ctx
.
query
.
code
;
const
code
=
ctx
.
query
.
code
;
const
channel_id
=
ctx
.
query
.
channel_id
;
const
channel_id
=
ctx
.
query
.
channel_id
;
const
app_id
=
ctx
.
query
.
app_id
||
WECHAT_APPID
;
// if (!code || code.length === 0) {
// 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`;
// const target_url = WECHAT_CODE_URL + `?appid=${
app_id
}&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);
// ctx.redirect(target_url);
// }
// }
// const url = `${WECHAT_AUTH}?appid=${WECHAT_APPID}&secret=${WECHAT_SECRET}&code=${code}&grant_type=authorization_code`
// const url = `${WECHAT_AUTH}?appid=${WECHAT_APPID}&secret=${WECHAT_SECRET}&code=${code}&grant_type=authorization_code`
...
@@ -31,51 +32,53 @@ class WechatController extends Controller {
...
@@ -31,51 +32,53 @@ class WechatController extends Controller {
// }
// }
// const openid = wx_ret.openid;
// const openid = wx_ret.openid;
const
openid
=
'lishangke'
;
const
openid
=
'lishangke'
;
ctx
.
session
.
openid
=
openid
;
const
redirect_url
=
this
.
app
.
config
.
OUT_P_NODE_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
:
bind_phone_result
}));
if
(
bind_phone_result
.
status
!==
200
)
{
if
(
bind_phone_result
.
status
!==
200
)
{
ctx
.
redirect
(
NO_GJJ_PAGE
);
return
;
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=noLogin&openid=
${
openid
}
`
);
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
(
NO_GJJ_PAGE
);
return
;
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=noLogin&openid=
${
openid
}
`
);
return
;
}
}
const
user_id
=
user_exist_ret
.
uid
;
const
user_id
=
user_exist_ret
.
uid
;
//判断是否有导入公积金
//已绑定手机的 继续 判断是否有导入公积金
await
this
.
user_login
({
code
,
openid
,
channel_id
});
//已绑定的用户 直接登录
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
:
gjj_exist_result
}));
if
(
gjj_exist_result
.
status
!==
200
)
{
if
(
gjj_exist_result
.
status
!==
200
)
{
//调用公积金接口出错
ctx
.
redirect
(
NO_GJJ_PAGE
);
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(NO_GJJ_PAGE
); return;
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=noLogin`
);
return
;
}
}
await
this
.
user_login
({
code
,
openid
,
channel_id
});
//用户直接登录
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=hasLogin`
);
return
;
//已导入公积金
ctx
.
redirect
(
GJJ_DETAIL_PAGE
);
return
;
}
}
//判断是否有公积金导入并跳转
//判断是否有公积金导入并跳转
async
checkGjj
()
{
//
async checkGjj() {
const
{
ctx
}
=
this
;
//
const { ctx } = this;
const
user_id
=
ctx
.
userId
;
//
const user_id = ctx.userId;
//判断是否有导入公积金
//
//判断是否有导入公积金
console
.
info
(
user_id
);
//
console.info(user_id);
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: gjj_exist_result }));
if
(
gjj_exist_result
.
status
!==
200
)
{
//
if (gjj_exist_result.status !== 200) {
ctx
.
redirect
(
NO_GJJ_PAGE
);
return
;
//
ctx.redirect(NO_GJJ_PAGE); return;
}
//
}
ctx
.
redirect
(
GJJ_DETAIL_PAGE
);
return
;
//
ctx.redirect(GJJ_DETAIL_PAGE); return;
}
//
}
async
checkLogin
()
{
async
checkLogin
()
{
...
...
app/router/gjj.js
View file @
0dc6a0ac
...
@@ -8,5 +8,5 @@ module.exports = app => {
...
@@ -8,5 +8,5 @@ module.exports = app => {
router
.
get
(
'/wechat/check_login'
,
'gjj.wechat.checkLogin'
);
// 公积金公众号检查用户是否登录
router
.
get
(
'/wechat/check_login'
,
'gjj.wechat.checkLogin'
);
// 公积金公众号检查用户是否登录
router
.
get
(
'third'
,
'/wechat/oauth_login'
,
'gjj.wechat.oauthLogin'
);
// 公积金公众号授权登录
router
.
get
(
'third'
,
'/wechat/oauth_login'
,
'gjj.wechat.oauthLogin'
);
// 公积金公众号授权登录
router
.
get
(
'/wechat/check_gjj'
,
'gjj.wechat.checkGjj'
);
// 公积金公众号授权登录
//
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