Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yysh5
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
yysh5
Commits
365b84c9
Commit
365b84c9
authored
May 06, 2019
by
姜登
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
yys
parent
934c92cc
Pipeline
#6950
passed with stage
in 2 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
57 deletions
+45
-57
app.js
app.js
+3
-3
helper.js
app/extend/helper.js
+42
-53
notifyUrl.js
app/schedule/notifyUrl.js
+0
-1
No files found.
app
/app
.js
→
app.js
View file @
365b84c9
...
...
@@ -2,8 +2,7 @@ module.exports = app => {
// 自定义内容
app
.
beforeStart
(
async
()
=>
{
// 应用会等待这个函数执行完成才启动
app
.
projectName
=
'eggManual'
console
.
log
(
"==app beforeStart=="
);
const
ctx
=
app
.
createAnonymousContext
();
ctx
.
helper
.
sendMsg
({
message
:
'服务重启'
});
});
};
\ No newline at end of file
app/extend/helper.js
View file @
365b84c9
'use strict'
;
const
querystring
=
require
(
'querystring'
);
const
crypto
=
require
(
'crypto'
);
const
uuid
=
require
(
'uuid/v1'
);
const
iconv
=
require
(
'iconv-lite'
);
function
process
(
params
)
{
const
keys
=
Object
.
keys
(
params
)
.
filter
(
key
=>
{
return
(
params
[
key
]
!==
undefined
&&
params
[
key
]
!==
''
&&
[
'appSecret'
,
'partner_key'
,
'sign'
,
'key'
].
indexOf
(
key
)
<
0
);
})
.
sort
();
const
result
=
{};
for
(
const
key
of
keys
)
{
result
[
key
]
=
params
[
key
];
}
return
result
;
function
process
(
data
)
{
const
keys
=
Object
.
keys
(
data
);
keys
.
sort
();
let
sign_str
=
''
;
keys
.
forEach
(
key
=>
{
const
v
=
data
[
key
];
sign_str
+=
`
${
key
}
=
${
v
}
&`
;
});
return
sign_str
;
}
module
.
exports
.
buildRequestBody
=
function
(
params
,
needNonceStr
=
false
)
{
const
{
app
}
=
this
;
const
{
appKey
,
appSecret
}
=
app
.
config
.
GJJ_OpenAPI
;
params
=
params
||
{};
params
.
appKey
=
appKey
;
params
.
timestamp
=
Date
.
now
();
if
(
needNonceStr
)
{
params
.
nonce_str
=
this
.
genRandomStr
(
16
);
}
const
signStr
=
this
.
paramSign
(
appSecret
,
params
);
return
{
sign
:
signStr
,
params
};
module
.
exports
.
getUuid
=
function
()
{
return
uuid
();
};
module
.
exports
.
genRandomStr
=
function
(
length
)
{
return
crypto
.
randomBytes
(
length
).
toString
(
'hex
'
);
module
.
exports
.
decode
=
function
(
data
)
{
return
iconv
.
decode
(
data
,
'gb2312
'
);
};
module
.
exports
.
paramSign
=
function
(
appSecret
,
params
)
{
if
(
!
params
)
{
const
err
=
new
Error
(
'parameter params missing'
);
err
.
name
=
'ParameterSignError'
;
throw
err
;
}
if
(
!
appSecre
t
)
{
const
err
=
new
Error
(
'parameter appSecret missing'
)
;
err
.
name
=
'ParamSignError'
;
throw
er
r
;
}
const
newParams
=
process
(
params
);
let
query
=
querystring
.
stringify
(
newParams
)
;
query
+=
'&appSecret='
+
appSecret
;
const
sign
Str
=
crypto
/**
* @desc:通知中心
* @author: JD
* @param {Object} content: 需要发送的预警信息模板
* @return {Boolean} 信息发送状态
*/
module
.
exports
.
sendMsg
=
async
function
(
conten
t
)
{
if
(
!
content
)
return
false
;
const
{
app
}
=
this
;
const
{
baseURL
,
settingid
,
appSecret
}
=
app
.
config
.
JBnotifyCente
r
;
const
t
=
+
new
Date
();
let
sign_str
=
process
({
timestamp
:
t
,
settingid
,
params
:
JSON
.
stringify
(
content
)
}
);
sign_str
+=
`appsecret=
${
appSecret
}
`
;
console
.
log
(
sign_str
)
;
const
sign
=
crypto
.
createHash
(
'md5'
)
.
update
(
query
)
.
update
(
sign_str
)
.
digest
(
'hex'
)
.
toUpperCase
();
return
signStr
;
};
module
.
exports
.
getUuid
=
function
()
{
return
uuid
();
const
option
=
{
settingid
,
timestamp
:
t
,
sign
,
params
:
content
,
};
const
result
=
await
this
.
app
.
curl
(
baseURL
,
{
method
:
'POST'
,
data
:
option
,
dataType
:
'json'
,
contentType
:
'json'
,
});
return
result
;
};
module
.
exports
.
decode
=
function
(
data
)
{
return
iconv
.
decode
(
data
,
'gb2312'
);
};
app/schedule/notifyUrl.js
View file @
365b84c9
...
...
@@ -26,7 +26,6 @@ module.exports = {
});
ctx
.
app
.
notifyMap
=
notifyMap
;
}
ctx
.
logger
.
info
(
ctx
.
app
.
projectName
)
// console.log(await ctx.helper.sendMsg({ message: 'test' }));
}
catch
(
e
)
{
ctx
.
logger
.
error
(
'【schedule/notifyUrlTask】catch error:'
,
JSON
.
stringify
(
e
));
...
...
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