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
ce5f3be2
Commit
ce5f3be2
authored
Feb 12, 2020
by
任国军
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://t-git.51gjj.com/fangbin/51business
parents
facab3dc
47d85cc9
Pipeline
#19310
passed with stage
in 8 seconds
Changes
7
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
259 additions
and
5 deletions
+259
-5
check.js
app/controller/duxiaoman/check.js
+26
-0
response.js
app/controller/response.js
+6
-3
sys_user.js
app/model/gjj/sys_user.js
+1
-1
duxiaoman_log.js
app/model/prometheus/duxiaoman_log.js
+36
-0
duxiaoman.js
app/router/duxiaoman.js
+10
-0
check.js
app/service/duxiaoman/check.js
+169
-0
config.prod.js
config/config.prod.js
+11
-1
No files found.
app/controller/duxiaoman/check.js
0 → 100644
View file @
ce5f3be2
'use strict'
;
const
Controller
=
require
(
'egg'
).
Controller
;
class
CheckController
extends
Controller
{
/**
* 获取用户手机
*/
async
getUserHidePhone
()
{
const
{
ctx
}
=
this
;
let
ret
=
await
ctx
.
service
.
duxiaoman
.
check
.
getUserHidePhone
();
ctx
.
success
(
ret
);
}
/**
* 获取度小满查询结果
*/
async
getCheck
()
{
const
{
ctx
}
=
this
;
const
ret
=
await
ctx
.
service
.
duxiaoman
.
check
.
check
();
ctx
.
success
(
ret
);
}
}
module
.
exports
=
CheckController
;
app/controller/response.js
View file @
ce5f3be2
...
...
@@ -24,6 +24,9 @@ class ResponseController extends Controller {
target_url
+=
`?channel_id=
${
channel_alias
}
`
;
}
const
target_url1
=
decodeURI
(
target_url
);
const
target_url2
=
encodeURI
(
target_url1
);
//如果cookie中已存在 5要素 则可直接 跳到目标地址
const
token
=
ctx
.
cookies
.
get
(
'token'
,
{
signed
:
false
});
const
user_id
=
ctx
.
cookies
.
get
(
'user_id'
,
{
signed
:
false
});
...
...
@@ -32,7 +35,7 @@ class ResponseController extends Controller {
const
device_login_id
=
ctx
.
cookies
.
get
(
'device_login_id'
,
{
signed
:
false
});
ctx
.
logger
.
info
(
'target_user--'
+
JSON
.
stringify
({
target_cookies_user
:
{
token
,
user_id
,
app_user_id
,
device_id
,
device_login_id
}
}));
if
(
token
&&
user_id
&&
app_user_id
&&
device_id
&&
device_login_id
)
{
ctx
.
redirect
(
target_url
);
ctx
.
redirect
(
target_url
2
);
return
;
}
...
...
@@ -110,8 +113,8 @@ class ResponseController extends Controller {
ctx
.
cookies
.
set
(
key
,
value
,
{
httpOnly
:
false
,
signed
:
false
,
path
:
'/'
,
overwrite
:
true
});
}
}
ctx
.
redirect
(
target_url
);
ctx
.
redirect
(
target_url
2
);
return
;
}
...
...
app/model/gjj/sys_user.js
View file @
ce5f3be2
...
...
@@ -5,7 +5,7 @@ const moment = require('moment');
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
}
=
app
.
Sequelize
;
const
SysUser
=
app
.
gjjModel
.
define
(
'sys_
su
er'
,
{
const
SysUser
=
app
.
gjjModel
.
define
(
'sys_
us
er'
,
{
sid
:
{
type
:
INTEGER
,
primaryKey
:
true
,
...
...
app/model/prometheus/duxiaoman_log.js
0 → 100644
View file @
ce5f3be2
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
INTEGER
,
STRING
,
DATE
}
=
app
.
Sequelize
;
const
DuxiaomanLog
=
app
.
prometheusModel
.
define
(
'duxiaoman_log'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
user_id
:
STRING
,
app_user_id
:
STRING
,
app_id
:
STRING
,
app_type_id
:
STRING
,
user_sid
:
INTEGER
,
phone
:
STRING
,
is_target_user
:
INTEGER
,
request
:
STRING
,
response
:
STRING
,
created_at
:
{
type
:
DATE
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_at'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
}
},
{
timestamps
:
false
,
tableName
:
'duxiaoman_log'
,
});
return
DuxiaomanLog
;
};
app/router/duxiaoman.js
0 → 100644
View file @
ce5f3be2
'use strict'
;
module
.
exports
=
app
=>
{
const
router
=
app
.
router
.
namespace
(
app
.
config
.
projectRootPath
+
'/duxiaoman'
);
const
loginAuth
=
app
.
middleware
.
loginAuth
({
type
:
'new'
});
//登录中间件
router
.
get
(
'/user/phone'
,
loginAuth
,
'duxiaoman.check.getUserHidePhone'
);
router
.
get
(
'/check'
,
loginAuth
,
'duxiaoman.check.getCheck'
);
};
app/service/duxiaoman/check.js
0 → 100644
View file @
ce5f3be2
'use strict'
;
const
Service
=
require
(
'egg'
).
Service
;
const
moment
=
require
(
'moment'
);
class
CheckService
extends
Service
{
/**
* 获取用户的手机号(打码)
*/
async
getUserHidePhone
()
{
const
{
ctx
}
=
this
;
let
ret
=
{
hide_phone
:
''
,
is_reject
:
false
,
//30天之内是否有被拒记录
};
if
(
!
ctx
.
oldUserId
||
!
ctx
.
userId
)
{
//如果没有登录就不做处理
return
ret
;
}
let
userSid
=
isNaN
(
ctx
.
oldUserId
)
?
ctx
.
helper
.
decodeUserSid
(
ctx
.
oldUserId
)
:
ctx
.
oldUserId
;
let
filter
=
{
attributes
:
[
'passport'
],
where
:
{
sid
:
userSid
,
yys_cid
:
10
}
}
let
userInfo
=
await
ctx
.
gjjModel
.
SysUser
.
findOne
(
filter
);
if
(
!
userInfo
)
{
ctx
.
failed
(
'没有找到对应的手机号'
);
}
ret
.
hide_phone
=
userInfo
.
passport
.
replace
(
/
(\d{3})\d{4}(\d{4})
/
,
'$1****$2'
);
//最近30天是否有被拒记录
let
rejectFilter
=
{
attributes
:
[
'user_sid'
],
where
:
{
user_sid
:
userSid
,
created_at
:
{
$gt
:
moment
().
subtract
(
30
,
'days'
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
},
is_target_user
:
{
$ne
:
1
}
}
}
let
rejectRecord
=
await
ctx
.
prometheusModel
.
DuxiaomanLog
.
findOne
(
rejectFilter
);
ret
.
is_reject
=
!
rejectRecord
?
false
:
true
;
return
ret
;
}
/**
* 签名,加密
* @param {object} params 需要加密的参数对象
*/
async
sign
(
params
)
{
const
{
ctx
}
=
this
;
let
signKey
=
this
.
config
.
DXM_SECRET
;
let
sign
=
''
;
if
(
!
params
)
{
ctx
.
failed
(
'params is empty'
);
}
//键名排序
const
sortParamsKey
=
Object
.
keys
(
params
).
sort
();
//键值拼接-升序
let
sortValues
=
''
;
for
(
let
i
in
sortParamsKey
)
{
if
([
'sign'
,
'Sign'
].
includes
(
sortParamsKey
[
i
]))
{
continue
;
}
sortValues
+=
sortParamsKey
[
i
]
+
'='
+
params
[
sortParamsKey
[
i
]]
+
'&'
;
}
sortValues
=
sortValues
.
substring
(
0
,
sortValues
.
length
-
1
)
+
signKey
;
sign
=
ctx
.
helper
.
md5
(
sortValues
);
ctx
.
logger
.
info
({
sign
:
sign
});
return
sign
;
}
async
check
()
{
const
{
ctx
}
=
this
;
let
ret
=
{
is_target_user
:
0
,
//1 true 0 false -1 NOT_FOUND
url
:
''
}
if
(
!
ctx
.
oldUserId
||
!
ctx
.
userId
)
{
//如果没有登录就不做处理
ctx
.
failed
(
'登录异常'
);
}
let
userSid
=
isNaN
(
ctx
.
oldUserId
)
?
ctx
.
helper
.
decodeUserSid
(
ctx
.
oldUserId
)
:
ctx
.
oldUserId
;
let
filter
=
{
attributes
:
[
'passport'
],
where
:
{
sid
:
userSid
,
yys_cid
:
10
}
}
let
userInfo
=
await
ctx
.
gjjModel
.
SysUser
.
findOne
(
filter
);
if
(
!
userInfo
)
{
ctx
.
failed
(
'没有找到对应的手机号'
);
}
let
params
=
{
app_id
:
this
.
config
.
DXM_APP_ID
,
datetime
:
new
Date
().
getTime
(),
phone_md5
:
ctx
.
helper
.
md5
(
userInfo
.
passport
),
fr
:
'gjj_test'
,
//TODO,线下测试随意,不为空即可
sign
:
''
,
}
params
.
sign
=
await
this
.
sign
(
params
);
let
dxmUrl
=
this
.
config
.
DXM_URL
+
'?'
;
for
(
let
i
in
params
)
{
dxmUrl
+=
i
+
'='
+
params
[
i
]
+
'&'
;
}
dxmUrl
=
dxmUrl
.
substring
(
0
,
dxmUrl
.
length
-
1
);
ctx
.
logger
.
info
(
'dxmUrl:'
+
dxmUrl
);
let
result
=
await
ctx
.
helper
.
send_request
(
dxmUrl
,
{},
{
method
:
'GET'
});
ctx
.
logger
.
info
(
'result:'
+
JSON
.
stringify
(
result
));
if
(
result
.
status
===
200
)
{
if
(
result
.
data
.
retCode
===
0
)
{
ret
.
is_target_user
=
result
.
data
.
result
.
is_target_user
;
}
//数据库记录
let
addData
=
{
user_id
:
ctx
.
userId
,
app_user_id
:
ctx
.
appUserId
,
app_id
:
ctx
.
appId
,
app_type_id
:
ctx
.
appTypeId
,
user_sid
:
userSid
,
phone
:
userInfo
.
passport
,
is_target_user
:
result
.
data
.
result
.
is_target_user
,
request
:
JSON
.
stringify
(
params
),
response
:
JSON
.
stringify
(
result
.
data
),
}
await
ctx
.
prometheusModel
.
DuxiaomanLog
.
create
(
addData
);
}
else
{
ctx
.
failed
(
'服务异常,请稍后再试'
);
}
if
(
ret
.
is_target_user
===
1
)
{
let
businessId
=
this
.
config
.
CFG_ENV
===
'dev'
?
1
:
(
this
.
config
.
CFG_ENV
===
'uat'
?
175
:
3
);
let
businessInfo
=
await
this
.
getBusinessInfo
(
businessId
);
ret
.
url
=
businessInfo
.
url
;
}
return
ret
;
}
/**
* 获取业务信息,type=4表示普通贷款
* @param {integer|string} id 业务编号
* @returns {object} businessInfo 业务相关信息
*/
async
getBusinessInfo
(
id
)
{
const
{
ctx
}
=
this
;
let
url
=
this
.
config
.
CASSANDRA_API
+
'/huodong/bu_basic/'
+
id
+
'?type=4'
;
let
result
=
await
ctx
.
helper
.
send_request
(
url
,
{},
{
method
:
'GET'
,
});
ctx
.
logger
.
info
(
url
+
':'
+
JSON
.
stringify
(
result
));
let
businessInfo
=
(
result
.
status
===
200
&&
result
.
data
&&
result
.
data
.
ret
)
?
result
.
data
.
ret
:
{};
return
businessInfo
;
}
}
module
.
exports
=
CheckService
;
config/config.prod.js
View file @
ce5f3be2
...
...
@@ -14,7 +14,7 @@ module.exports = appInfo => {
dir
:
'/jianbing/logs/51business'
,
};
// add your config here
config
.
middleware
=
[
'errorHandler'
,
'deviceLogin'
,
'deviceInit'
,
'responseSet'
];
config
.
middleware
=
[
'errorHandler'
,
'deviceLogin'
,
'deviceInit'
,
'responseSet'
];
// 是否启用csrf安全
config
.
security
=
{
...
...
@@ -159,5 +159,15 @@ module.exports = appInfo => {
config
.
YYS_REPORT_APPSECRET
=
process
.
env
.
YYS_REPORT_APPSECRET
;
config
.
YYS_REPORT_URL
=
process
.
env
.
YYS_REPORT_URL
;
//度小满金融查询
config
.
DXM_APP_ID
=
process
.
env
.
DXM_APP_ID
;
config
.
DXM_SECRET
=
process
.
env
.
DXM_SECRET
;
config
.
DXM_URL
=
process
.
env
.
DXM_URL
;
config
.
CFG_ENV
=
process
.
env
.
CFG_ENV
;
config
.
CASSANDRA_API
=
process
.
env
.
CASSANDRA_API
;
return
config
;
};
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