Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sb_h5
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
data_server
sb_h5
Commits
e5db8927
Commit
e5db8927
authored
Feb 26, 2019
by
高诸锋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
0bfcae7d
Pipeline
#3890
passed with stage
in 2 seconds
Changes
14
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
171 additions
and
104 deletions
+171
-104
order.js
app/controller/order.js
+1
-1
partner.js
app/controller/partner.js
+62
-4
script.js
app/controller/script.js
+1
-0
task.js
app/controller/task.js
+3
-1
application.js
app/extend/application.js
+8
-38
router.js
app/router.js
+3
-2
cache.js
app/service/cache.js
+1
-1
order.js
app/service/order.js
+1
-0
partner.js
app/service/partner.js
+44
-6
storage.js
app/service/storage.js
+1
-1
task.js
app/service/task.js
+2
-0
config.local.js
config/config.local.js
+0
-8
config.prod.js
config/config.prod.js
+43
-41
plugin.js
config/plugin.js
+1
-1
No files found.
app/controller/order.js
View file @
e5db8927
...
...
@@ -17,7 +17,7 @@ class OrderController extends Controller {
type
:
'object'
,
rule
:
{
token
:
'string'
,
order
Sn
:
'string'
,
order
Id
:
'string'
,
appKey
:
'string'
,
timestamp
:
'string'
,
},
...
...
app/controller/partner.js
View file @
e5db8927
...
...
@@ -3,10 +3,21 @@
const
Controller
=
require
(
'egg'
).
Controller
;
class
PartnerController
extends
Controller
{
// constructor(ctx) {
// super(ctx);
// }
constructor
(
ctx
)
{
super
(
ctx
);
this
.
showRule
=
{
sign
:
{
type
:
'string'
,
required
:
true
},
type
:
{
type
:
'string'
,
required
:
false
},
params
:
{
type
:
'object'
,
required
:
true
,
rule
:
{
appKey
:
{
type
:
'string'
,
required
:
true
},
timestamp
:
{
type
:
'string'
,
required
:
true
},
token
:
{
type
:
'string'
,
required
:
true
},
orderId
:
{
type
:
'string'
,
required
:
true
},
},
},
};
}
async
show
()
{
const
{
ctx
,
service
}
=
this
;
...
...
@@ -18,6 +29,53 @@ class PartnerController extends Controller {
}
ctx
.
fail
(
'尚未配置主题'
);
}
async
getToken
()
{
const
{
ctx
,
service
}
=
this
;
ctx
.
status
=
200
;
try
{
ctx
.
validate
(
this
.
createRule
);
const
token
=
await
service
.
signature
.
createTokenForPartner
(
ctx
.
request
.
body
);
ctx
.
body
=
{
code
:
0
,
data
:
token
};
}
catch
(
err
)
{
if
(
err
.
code
===
'invalid_param'
)
{
ctx
.
body
=
{
code
:
-
1
,
message
:
err
.
message
||
''
};
return
;
}
ctx
.
body
=
{
code
:
err
.
code
||
-
1
,
message
:
err
.
message
||
''
};
return
;
}
}
async
partnerShow
()
{
const
{
ctx
,
service
}
=
this
;
ctx
.
status
=
200
;
try
{
ctx
.
validate
(
this
.
showRule
);
const
orderId
=
ctx
.
request
.
body
.
params
.
orderId
;
await
service
.
signature
.
signatureCheck
(
ctx
.
request
.
body
);
const
data
=
await
service
.
order
.
getOneByOrderId
(
orderId
);
if
(
data
&&
data
.
status
===
'success'
)
{
const
result
=
await
service
.
storage
.
read
(
orderId
);
ctx
.
body
=
{
code
:
0
,
data
:
result
,
};
return
;
}
ctx
.
body
=
{
code
:
-
1
,
message
:
'无此订单号'
,
};
}
catch
(
err
)
{
if
(
err
.
code
===
'invalid_param'
)
{
ctx
.
body
=
{
code
:
-
1
,
message
:
err
.
message
||
''
};
return
;
}
ctx
.
body
=
{
code
:
err
.
code
||
-
1
,
message
:
err
.
message
||
''
};
return
;
}
}
}
module
.
exports
=
PartnerController
;
app/controller/script.js
View file @
e5db8927
...
...
@@ -30,6 +30,7 @@ class ScriptController extends Controller {
const
data
=
await
service
.
scripts
.
fetchOneScripts
(
scriptId
);
ctx
.
success
(
data
);
}
async
fetchParamsInfo
()
{
const
{
ctx
,
service
}
=
this
;
const
{
refresh
=
false
}
=
ctx
.
query
;
...
...
app/controller/task.js
View file @
e5db8927
...
...
@@ -74,6 +74,7 @@ class TaskController extends Controller {
ctx
.
success
(
data
);
}
// 处理模拟器回调知
async
handleCallback
()
{
const
{
ctx
,
service
}
=
this
;
const
{
taskId
}
=
ctx
.
request
.
body
;
...
...
@@ -114,7 +115,7 @@ class TaskController extends Controller {
const
insertData
=
await
service
.
washData
.
wash
(
result
);
const
order
=
await
service
.
order
.
getOneByTaskId
(
taskId
);
if
(
!
order
)
{
throw
new
Error
(
'任务已经结束了'
);
throw
new
Error
(
`【taskId】:
${
taskId
}
任务已经结束.`
);
}
const
{
orderId
,
appkey
}
=
order
;
insertData
.
orderId
=
orderId
;
...
...
@@ -123,6 +124,7 @@ class TaskController extends Controller {
insertData
.
appKey
=
appkey
;
delete
insertData
.
code
;
await
service
.
storage
.
write
(
insertData
);
await
service
.
partner
.
notify
({
taskId
,
cb
:
order
.
callbackUrl
,
orderId
:
order
.
orderId
,
userId
:
order
.
userId
});
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'handleCallback'
,
err
,
result
);
taskNote
=
{
...
...
app/extend/application.js
View file @
e5db8927
'use strict'
;
const
REDIS_CACHE
=
Symbol
(
'Context#RedisCache'
);
const
NODE_CACHE
=
Symbol
(
'Context#NodeCache'
);
const
NodeCache
=
require
(
'node-cache'
);
const
INCR_SCRIPT
=
'return redis.call("INCR", ARGV[1])'
;
class
Cache
{
constructor
(
app
)
{
this
.
app
=
app
;
this
.
name
=
'unknown-cache'
;
this
.
app
.
redis
.
defineCommand
(
'INCR'
,
{
numberOfKeys
:
0
,
lua
:
INCR_SCRIPT
,
});
}
async
val
(
key
,
next
,
ttl
)
{
...
...
@@ -51,33 +45,10 @@ class Cache {
this
.
app
.
logger
.
info
(
`【Cache Set】(
${
+
new
Date
()
-
startTime
}
ms) Key:
${
key
}
value:
${
JSON
.
stringify
(
value
)}
`
);
return
;
}
}
class
RedisCacheWrap
extends
Cache
{
constructor
(
app
,
redis
)
{
super
(
app
);
this
.
redis
=
redis
;
this
.
name
=
'redis-cache'
;
}
async
_get
(
key
)
{
const
{
redis
}
=
this
;
let
value
=
await
redis
.
get
(
key
);
if
(
value
===
null
)
{
value
=
undefined
;
}
if
(
value
)
{
value
=
JSON
.
parse
(
value
);
}
return
value
;
}
async
_set
(
key
,
value
,
ttl
)
{
const
{
redis
}
=
this
;
value
=
JSON
.
stringify
(
value
);
if
(
ttl
>
0
)
{
await
redis
.
set
(
key
,
value
,
'EX'
,
ttl
);
}
else
{
await
redis
.
set
(
key
,
value
);
async
del
(
key
)
{
if
(
key
)
{
return
await
this
.
_del
(
key
);
}
}
}
...
...
@@ -92,6 +63,7 @@ class NodeCacheWrap extends Cache {
async
_get
(
key
)
{
return
this
.
cache
.
get
(
key
);
}
async
_set
(
key
,
value
,
ttl
)
{
const
{
cache
}
=
this
;
value
=
JSON
.
parse
(
JSON
.
stringify
(
value
));
...
...
@@ -101,15 +73,13 @@ class NodeCacheWrap extends Cache {
cache
.
set
(
key
,
value
);
}
}
async
_del
(
key
)
{
return
this
.
cache
.
del
(
key
);
}
}
module
.
exports
=
{
get
memcache
()
{
if
(
!
this
[
REDIS_CACHE
])
{
this
[
REDIS_CACHE
]
=
new
RedisCacheWrap
(
this
,
this
.
redis
);
}
return
this
[
REDIS_CACHE
];
},
get
cache
()
{
if
(
!
this
[
NODE_CACHE
])
{
this
[
NODE_CACHE
]
=
new
NodeCacheWrap
(
this
);
...
...
app/router.js
View file @
e5db8927
...
...
@@ -8,7 +8,7 @@ module.exports = app => {
const
sbRouter
=
app
.
router
.
namespace
(
app
.
config
.
projectRootPath
);
sbRouter
.
post
(
'/tasks'
,
controller
.
task
.
create
);
// 创建任务
sbRouter
.
get
(
'/tasks/:taskId'
,
controller
.
task
.
show
);
// 获取任务状态
sbRouter
.
get
(
'/tasks/:taskId'
,
controller
.
task
.
show
);
// 获取任务状态
前端轮询的接口
sbRouter
.
post
(
'/tasks/:taskId/submit'
,
controller
.
task
.
submit
);
// 提交任务参数
sbRouter
.
post
(
'/tasks/:taskId/capture'
,
controller
.
task
.
fetchCapture
);
// 获取验证码
...
...
@@ -34,5 +34,6 @@ module.exports = app => {
// 这个接口之后会移除掉
sbRouter
.
get
(
'/orders'
,
controller
.
order
.
fetchOrderId
);
sbRouter
.
post
(
'/getToken'
,
controller
.
token
.
createForPartner
);
sbRouter
.
post
(
'/getToken'
,
controller
.
partner
.
getToken
);
sbRouter
.
post
(
'/getData'
,
controller
.
partner
.
partnerShow
);
};
app/service/cache.js
View file @
e5db8927
...
...
@@ -55,7 +55,7 @@ class CacheService extends Service {
return
{
status
:
order
.
status
,
note
:
order
.
note
};
}
ctx
.
logger
.
error
(
`【Cache】get No Result
${
key
}
`
);
ctx
.
throw
.
error
(
400
,
{
message
:
'no taskId'
});
ctx
.
throw
(
400
,
{
message
:
'no taskId'
});
}
}
...
...
app/service/order.js
View file @
e5db8927
...
...
@@ -10,6 +10,7 @@ class OrderService extends Service {
});
return
order
;
}
async
getOneByTaskId
(
taskId
)
{
const
{
ctx
}
=
this
;
const
order
=
await
ctx
.
model
.
TaskStatus
.
findOne
({
...
...
app/service/partner.js
View file @
e5db8927
...
...
@@ -12,13 +12,13 @@ class PartnerService extends Service {
async
fetchTheme
(
appKey
)
{
const
{
ctx
,
partnerAPI
:
{
fetchTheme
,
host
,
redisThemePrefix
}
}
=
this
;
if
(
appKey
)
{
const
data
=
await
this
.
app
.
redis
.
get
(
redisThemePrefix
+
appKey
);
const
data
=
await
this
.
app
.
cache
.
get
(
redisThemePrefix
+
appKey
);
if
(
data
)
{
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Scripts】fetchParams'
,
redisThemePrefix
+
appKey
,
'result:'
,
data
,
err
);
await
this
.
app
.
redis
.
del
(
redisThemePrefix
+
appKey
);
await
this
.
app
.
cache
.
del
(
redisThemePrefix
+
appKey
);
}
}
}
...
...
@@ -30,7 +30,7 @@ class PartnerService extends Service {
});
ctx
.
logger
.
info
(
`【Partner】 fetchTheme
${
host
+
fetchTheme
}
/
${
appKey
}
`
,
ret
.
data
);
if
(
ret
.
status
===
200
&&
ret
.
data
&&
ret
.
data
.
id
===
appKey
)
{
await
this
.
app
.
redis
.
set
(
redisThemePrefix
+
appKey
,
JSON
.
stringify
(
ret
.
data
),
'EX'
,
7200
);
await
this
.
app
.
cache
.
set
(
redisThemePrefix
+
appKey
,
JSON
.
stringify
(
ret
.
data
)
,
7200
);
}
return
ret
.
data
;
}
...
...
@@ -39,13 +39,13 @@ class PartnerService extends Service {
const
{
ctx
,
partnerAPI
:
{
fetchScripts
,
host
,
redisScriptsPrefix
}
}
=
this
;
if
(
appKey
)
{
const
data
=
await
this
.
app
.
redis
.
get
(
redisScriptsPrefix
+
appKey
);
const
data
=
await
this
.
app
.
cache
.
get
(
redisScriptsPrefix
+
appKey
);
if
(
data
)
{
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Partner】 fetchScripts'
,
redisScriptsPrefix
+
appKey
,
'result:'
,
data
,
err
);
await
this
.
app
.
redis
.
del
(
redisScriptsPrefix
+
appKey
);
await
this
.
app
.
cache
.
del
(
redisScriptsPrefix
+
appKey
);
}
}
}
...
...
@@ -58,10 +58,48 @@ class PartnerService extends Service {
});
ctx
.
logger
.
info
(
`【Partner】 fetchTheme
${
url
}
`
,
ret
.
data
);
if
(
ret
.
status
===
200
&&
ret
.
data
&&
ret
.
data
.
id
===
appKey
)
{
await
this
.
app
.
redis
.
set
(
redisScriptsPrefix
+
appKey
,
JSON
.
stringify
(
ret
.
data
),
'EX'
,
7200
);
await
this
.
app
.
cache
.
set
(
redisScriptsPrefix
+
appKey
,
JSON
.
stringify
(
ret
.
data
)
,
7200
);
}
return
ret
.
data
;
}
// 查询结束后回调通知合作方
// 对于状态已经是成功的订单号不会在做通知
// orderId/userId/status
async
notify
({
taskId
,
cb
,
orderId
,
userId
})
{
const
{
ctx
,
service
}
=
this
;
if
(
!
cb
)
{
ctx
.
logger
.
info
(
`【orderId】:
${
orderId
}
没有回调地址`
);
return
;
}
const
data
=
await
service
.
cache
.
get
({
key
:
taskId
});
if
(
data
&&
data
.
status
===
'success'
)
{
ctx
.
logger
.
info
(
`【taskId】:
${
taskId
}
模拟器多次通知任务成功情况`
);
return
;
}
if
(
data
)
{
try
{
await
ctx
.
curl
(
cb
,
{
method
:
'POST'
,
data
:
{
orderId
,
status
:
'success'
,
userId
},
dataType
:
'json'
,
contentType
:
'json'
,
timeout
:
[
'30s'
,
'30s'
],
});
ctx
.
model
.
TaskStatus
.
update
(
{
notice
:
1
},
{
where
:
{
taskId
}
}
);
}
catch
(
e
)
{
// 回调失败
ctx
.
logger
.
error
(
`【cb】:
${
cb
}
回调通知失败`
);
ctx
.
model
.
TaskStatus
.
update
(
{
notice
:
0
},
{
where
:
{
taskId
}
}
);
}
}
}
}
module
.
exports
=
PartnerService
;
app/service/storage.js
View file @
e5db8927
...
...
@@ -48,7 +48,7 @@ class StorageService extends Service {
method
:
'get'
,
contentType
:
'json'
,
});
ctx
.
logger
.
info
(
`【Storage】read url:
${
readUrl
}
/
${
orderId
}
write result:`
,
result
.
data
);
ctx
.
logger
.
info
(
`【Storage】read url:
${
readUrl
}
/
${
orderId
}
`
);
if
(
result
&&
result
.
data
&&
result
.
data
.
code
!==
0
)
{
ctx
.
logger
.
error
(
`storageAPI read
${
readUrl
}
/
${
orderId
}
`
,
result
.
data
);
...
...
app/service/task.js
View file @
e5db8927
...
...
@@ -77,6 +77,7 @@ class TaskService extends Service {
this
.
_checkSuccess
(
result
);
return
result
.
data
.
data
;
}
async
submit
(
data
)
{
const
{
taskAPI
,
ctx
}
=
this
;
const
{
submitTaskUrl
}
=
taskAPI
;
...
...
@@ -89,6 +90,7 @@ class TaskService extends Service {
this
.
_checkSuccess
(
result
);
return
result
;
}
async
fetchTask
(
data
)
{
const
{
taskAPI
,
ctx
}
=
this
;
const
{
fetchTaskUrl
}
=
taskAPI
;
...
...
config/config.local.js
View file @
e5db8927
...
...
@@ -4,14 +4,6 @@ module.exports = () => {
const
config
=
exports
=
{};
config
.
debug
=
true
;
config
.
redis
=
{
client
:
{
port
:
6379
,
host
:
'127.0.0.1'
,
password
:
'DEV8redis'
,
db
:
0
,
},
};
config
.
taskAPI
=
{
host
:
'http://tm.51gjj.com:4831'
,
fetchHubsUrl
:
''
,
...
...
config/config.prod.js
View file @
e5db8927
...
...
@@ -2,23 +2,23 @@
module
.
exports
=
()
=>
{
const
config
=
exports
=
{};
config
.
debug
=
tru
e
;
config
.
debug
=
fals
e
;
config
.
redis
=
{
client
:
{
port
:
6379
,
host
:
process
.
env
.
REDIS_HOST
,
password
:
'DEV8redis'
,
db
:
0
,
},
};
config
.
taskAPI
=
{
host
:
'http://tm.51gjj.com:4831'
,
fetchHubsUrl
:
''
,
createTaskUrl
:
'/gjjServices/createGjjTask'
,
fetchCodeUrl
:
'/gjjServices/queryGjjCode'
,
submitTaskUrl
:
'/gjjServices/queryGjj'
,
fetchTaskUrl
:
'/gjjServices/getGjjData'
,
createTaskUrl
:
'/shebao/createSbTask'
,
fetchCodeUrl
:
'/shebao/getSbCode'
,
submitTaskUrl
:
'/shebao/loginSbWeb'
,
fetchTaskUrl
:
'/shebao/getSbData'
,
// 获取该task状态
};
config
.
partnerAPI
=
{
host
:
'https://dev-nginx.jianbing.com/zeus-api/v1'
,
fetchTheme
:
'/chaos/partners/theme'
,
fetchScripts
:
'/chaos/partners/scripts'
,
redisThemePrefix
:
'URANUS.HF.PARNTERS.THEME'
,
redisScriptsPrefix
:
'URANUS.HF.PARNTERS.SCRIPTS'
,
};
config
.
scriptsAPI
=
{
...
...
@@ -38,14 +38,14 @@ module.exports = () => {
config
.
storageAPI
=
{
host
:
'http://tv.51gjj.com:11252'
,
writeUrl
:
'/data'
,
readUrl
:
'/
gjj
'
,
writeType
:
'
gjj
'
,
readDataKey
:
'
gjj
Data'
,
readUrl
:
'/
shebao
'
,
writeType
:
'
shebao
'
,
readDataKey
:
'
shebao
Data'
,
};
config
.
washAPI
=
{
host
:
'http://tt.51gjj.com:11101'
,
washUrl
:
'/
gjj/analyzeGjj
'
,
washUrl
:
'/
si/analyzeSI
'
,
};
config
.
signatureAPI
=
{
...
...
@@ -54,25 +54,16 @@ module.exports = () => {
fetchOrderIdUrl
:
'/Order/GetOrderSn'
,
signatureUrl
:
'/Access/SignValidityCheck'
,
fetchParnterUrl
:
''
,
signatureType
:
'gjj'
,
};
config
.
partnerAPI
=
{
host
:
'https://dev-nginx.jianbing.com/zeus-api/v1'
,
fetchTheme
:
'/chaos/partners/theme'
,
fetchScripts
:
'/chaos/partners/scripts'
,
redisThemePrefix
:
'URANUS.HF.PARNTERS.THEME'
,
redisScriptsPrefix
:
'URANUS.HF.PARNTERS.SCRIPTS'
,
signatureType
:
'shebao'
,
};
config
.
lockKeys
=
{
fecthHub
:
'
URANUS
.HF.HUBS.LOCK'
,
fecteToken
:
'
URANUS
.HF.TOKEN.LOCK'
,
token
:
'
URANUS
.HF.TOKEN'
,
fecthParnters
:
'
URANUS
.PARNTERS.LOCK'
,
taskPrefix
:
'
URANUS.HFH5
.TASK'
,
fecthHub
:
'
NEWSB
.HF.HUBS.LOCK'
,
fecteToken
:
'
NEWSB
.HF.TOKEN.LOCK'
,
token
:
'
NEWSB
.HF.TOKEN'
,
fecthParnters
:
'
NEWSB
.PARNTERS.LOCK'
,
taskPrefix
:
'
NEWSB
.TASK'
,
};
config
.
projectRootPath
=
''
;
config
.
sequelize
=
{
datasources
:
[{
...
...
@@ -81,20 +72,31 @@ module.exports = () => {
delegate
:
'model'
,
baseDir
:
'model'
,
dialect
:
'mysql'
,
host
:
'rm-bp1272001633qc0x9.mysql.rds.aliyuncs.com'
,
database
:
'nodetest'
,
username
:
'hexin'
,
password
:
'gYUHszn9#q'
,
port
:
3306
,
host
:
process
.
env
.
MYSQL_PACHONG_HOST
||
'rm-bp1272001633qc0x9.mysql.rds.aliyuncs.com'
,
database
:
process
.
env
.
MYSQL_DATA_SERVER_DB_NAME
||
'data_service_dev'
,
username
:
process
.
env
.
MYSQL_USER
||
'hexin'
,
password
:
process
.
env
.
MYSQL_PWD
||
'gYUHszn9#q'
,
port
:
process
.
env
.
MYSQL_PORT
||
3306
,
},
{
// 东八时区
timezone
:
'+08:00'
,
delegate
:
'cusPro'
,
baseDir
:
'model'
,
dialect
:
'mysql'
,
host
:
process
.
env
.
MYSQL_PACHONG_HOST
||
'rm-bp1272001633qc0x9.mysql.rds.aliyuncs.com'
,
database
:
process
.
env
.
MYSQL_JAVA_DB_NAME
||
'java_open_platform'
,
username
:
process
.
env
.
MYSQL_USER
||
'hexin'
,
password
:
process
.
env
.
MYSQL_PWD
||
'gYUHszn9#q'
,
port
:
process
.
env
.
MYSQL_PORT
||
3306
,
}],
};
config
.
GJJ
_OpenAPI
=
{
appKey
:
'
9FBBA75BBFC24401AA6A76AEFC277346
'
,
appSecret
:
'
D7FEA664E0CD4336BEAA1B3569393A301DBB6995
'
,
config
.
SB
_OpenAPI
=
{
appKey
:
'
60670203E411FD62BA9E953CFB73F881
'
,
appSecret
:
'
0BDD1ECC147503C477563E5C1438C366D70E4F80
'
,
};
config
.
callbackUrl
=
'http
s://dev-nginx.jianbing.com/hf_h5
_server/callback'
;
config
.
callbackUrl
=
'http
://ti.51gjj.com:7001/shebao
_server/callback'
;
return
config
;
};
config/plugin.js
View file @
e5db8927
...
...
@@ -14,7 +14,7 @@ exports.sequelize = {
};
exports
.
redis
=
{
enable
:
tru
e
,
enable
:
fals
e
,
package
:
'egg-redis'
,
};
...
...
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