Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gjjh5
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
gjjh5
Commits
9efa73a9
Commit
9efa73a9
authored
Mar 28, 2020
by
姜登
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加密解密
parent
daa42889
Pipeline
#21140
passed with stage
in 16 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
63 deletions
+84
-63
task.js
app/controller/task.js
+67
-61
helper.js
app/extend/helper.js
+17
-2
No files found.
app/controller/task.js
View file @
9efa73a9
...
...
@@ -63,6 +63,12 @@ class TaskController extends Controller {
const
{
ctx
,
service
,
config
}
=
this
;
ctx
.
validate
(
this
.
submitRule
);
const
{
taskId
}
=
ctx
.
params
;
let
key
=
taskId
+
ctx
.
request
.
body
.
timestamp
;
if
(
key
.
length
<
16
)
{
while
(
key
.
length
<
16
)
key
+=
'0'
;
}
key
=
key
.
substring
(
0
,
16
);
ctx
.
request
.
body
=
ctx
.
helper
.
aesDecrypt
({
algorithm
:
'aes-128-ecb'
,
key
,
data
:
ctx
.
request
.
body
});
await
service
.
cache
.
set
({
key
:
String
(
taskId
),
value
:
{
status
:
'login'
,
note
:
{
message
:
'login'
}
},
...
...
@@ -107,73 +113,73 @@ class TaskController extends Controller {
note
:
{
message
:
'init'
},
};
switch
(
result
.
code
)
{
case
-
1
:
case
106
:
case
102
:
case
204
:
taskNote
=
{
status
:
'failure'
,
note
:
{
message
:
result
.
msg
},
};
break
;
case
1
:
if
(
result
.
data
.
data
)
{
result
.
data
=
{
data
:
JSON
.
parse
(
JSON
.
parse
(
result
.
data
.
data
).
post_data
.
strForNextStep
),
loginParam
:
result
.
data
.
loginParam
,
case
-
1
:
case
106
:
case
102
:
case
204
:
taskNote
=
{
status
:
'failure'
,
note
:
{
message
:
result
.
msg
},
};
}
taskNote
=
{
status
:
'next'
,
note
:
{
message
:
'waiting'
,
nextStep
:
result
.
data
},
};
break
;
case
110
:
taskNote
=
{
status
:
'query'
,
note
:
{
message
:
'login success'
},
};
break
;
case
0
:
taskNote
=
{
status
:
'success'
,
note
:
{
message
:
'task success'
},
};
try
{
const
insertData
=
await
service
.
washData
.
wash
(
result
);
const
order
=
await
service
.
order
.
getOneByTaskId
(
String
(
taskId
));
if
(
!
order
)
{
throw
new
Error
(
'任务已经结束了'
);
break
;
case
1
:
if
(
result
.
data
.
data
)
{
result
.
data
=
{
data
:
JSON
.
parse
(
JSON
.
parse
(
result
.
data
.
data
).
post_data
.
strForNextStep
),
loginParam
:
result
.
data
.
loginParam
,
};
}
const
{
orderId
,
appKey
}
=
order
;
insertData
.
orderId
=
orderId
;
insertData
.
cityName
=
await
service
.
scripts
.
fetchScriptName
(
insertData
.
cid
);
insertData
.
taskId
=
taskId
;
insertData
.
appKey
=
appKey
;
delete
insertData
.
code
;
await
service
.
storage
.
write
(
insertData
);
await
service
.
order
.
oldgjjStatus
({
orderId
,
status
:
'success'
});
await
service
.
cache
.
set
({
key
:
String
(
taskId
),
value
:
taskNote
,
});
await
service
.
partner
.
notice
(
order
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'handleCallback'
,
JSON
.
stringify
(
err
),
JSON
.
stringify
(
result
));
taskNote
=
{
status
:
'
failure
'
,
note
:
{
message
:
err
.
message
},
status
:
'
next
'
,
note
:
{
message
:
'waiting'
,
nextStep
:
result
.
data
},
};
if
(
!
/token|appKey/
.
test
(
err
.
message
))
{
if
(
/
[
a-zA-Z
]
+/
.
test
(
err
.
message
))
{
taskNote
.
note
=
'系统错误, 请稍后再试'
;
break
;
case
110
:
taskNote
=
{
status
:
'query'
,
note
:
{
message
:
'login success'
},
};
break
;
case
0
:
taskNote
=
{
status
:
'success'
,
note
:
{
message
:
'task success'
},
};
try
{
const
insertData
=
await
service
.
washData
.
wash
(
result
);
const
order
=
await
service
.
order
.
getOneByTaskId
(
String
(
taskId
));
if
(
!
order
)
{
throw
new
Error
(
'任务已经结束了'
);
}
const
{
orderId
,
appKey
}
=
order
;
insertData
.
orderId
=
orderId
;
insertData
.
cityName
=
await
service
.
scripts
.
fetchScriptName
(
insertData
.
cid
);
insertData
.
taskId
=
taskId
;
insertData
.
appKey
=
appKey
;
delete
insertData
.
code
;
await
service
.
storage
.
write
(
insertData
);
await
service
.
order
.
oldgjjStatus
({
orderId
,
status
:
'success'
});
await
service
.
cache
.
set
({
key
:
String
(
taskId
),
value
:
taskNote
,
});
await
service
.
partner
.
notice
(
order
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'handleCallback'
,
JSON
.
stringify
(
err
),
JSON
.
stringify
(
result
));
taskNote
=
{
status
:
'failure'
,
note
:
{
message
:
err
.
message
},
};
if
(
!
/token|appKey/
.
test
(
err
.
message
))
{
if
(
/
[
a-zA-Z
]
+/
.
test
(
err
.
message
))
{
taskNote
.
note
=
'系统错误, 请稍后再试'
;
}
}
}
}
break
;
default
:
ctx
.
logger
.
warn
(
'handleCallback'
,
JSON
.
stringify
(
result
));
break
;
break
;
default
:
ctx
.
logger
.
warn
(
'handleCallback'
,
JSON
.
stringify
(
result
));
break
;
}
if
(
result
.
code
!==
0
)
{
await
service
.
cache
.
set
({
...
...
app/extend/helper.js
View file @
9efa73a9
...
...
@@ -13,7 +13,7 @@ function process(data) {
return
sign_str
;
}
module
.
exports
.
getUuid
=
function
()
{
module
.
exports
.
getUuid
=
function
()
{
return
uuid
();
};
...
...
@@ -23,7 +23,7 @@ module.exports.getUuid = function() {
* @param {Object} content: 需要发送的预警信息模板
* @return {Boolean} 信息发送状态
*/
module
.
exports
.
sendMsg
=
async
function
(
content
)
{
module
.
exports
.
sendMsg
=
async
function
(
content
)
{
if
(
!
content
)
return
false
;
const
{
app
}
=
this
;
const
{
baseURL
,
settingid
,
appSecret
}
=
app
.
config
.
JBnotifyCenter
;
...
...
@@ -50,3 +50,18 @@ module.exports.sendMsg = async function(content) {
});
return
result
;
};
module
.
exports
.
aesDecrypt
=
function
({
algorithm
,
key
,
data
,
iv
=
''
})
{
const
{
ctx
}
=
this
;
try
{
const
decipher
=
crypto
.
createDecipheriv
(
algorithm
,
key
,
iv
);
decipher
.
setAutoPadding
(
true
);
const
cipherChunks
=
[];
cipherChunks
.
push
(
decipher
.
update
(
data
,
'base64'
,
'utf8'
));
cipherChunks
.
push
(
decipher
.
final
(
'utf8'
));
return
cipherChunks
.
join
(
''
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'aesdecrupt_ERROR'
,
err
,
JSON
.
stringify
({
algorithm
,
key
,
data
,
iv
}));
ctx
.
throw
(
'参数解密有误'
);
}
}
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