Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gjj_api
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
gjj_api
Commits
ba39b29e
Commit
ba39b29e
authored
May 06, 2019
by
姜登
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
短信
parent
8ab26aa7
Pipeline
#6974
passed with stage
in 2 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
51 deletions
+61
-51
app.js
app.js
+9
-0
helper.js
app/extend/helper.js
+40
-51
config.local.js
config/config.local.js
+6
-0
config.prod.js
config/config.prod.js
+6
-0
No files found.
app.js
0 → 100644
View file @
ba39b29e
module
.
exports
=
app
=>
{
// 自定义内容
app
.
beforeStart
(
async
()
=>
{
const
ctx
=
app
.
createAnonymousContext
();
// ctx.helper.sendMsg({ message: '服务重启' });
});
};
\ No newline at end of file
app/extend/helper.js
View file @
ba39b29e
'use strict'
;
const
querystring
=
require
(
'querystring'
);
const
crypto
=
require
(
'crypto'
);
const
uuid
=
require
(
'uuid/v1'
);
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
.
genRandomStr
=
function
(
length
)
{
return
crypto
.
randomBytes
(
length
).
toString
(
'hex'
);
module
.
exports
.
getUuid
=
function
()
{
return
uuid
();
};
/**
* @desc:通知中心
* @author: JD
* @param {Object} content: 需要发送的预警信息模板
* @return {Boolean} 信息发送状态
*/
module
.
exports
.
paramSign
=
function
(
appSecret
,
params
)
{
if
(
!
params
)
{
const
err
=
new
Error
(
'parameter params missing'
);
err
.
name
=
'ParameterSignError'
;
throw
err
;
}
if
(
!
appSecret
)
{
const
err
=
new
Error
(
'parameter appSecret missing'
);
err
.
name
=
'ParamSignError'
;
throw
err
;
}
const
newParams
=
process
(
params
);
let
query
=
querystring
.
stringify
(
newParams
);
query
+=
'&appSecret='
+
appSecret
;
const
signStr
=
crypto
module
.
exports
.
sendMsg
=
async
function
(
content
)
{
if
(
!
content
)
return
false
;
const
{
app
}
=
this
;
const
{
baseURL
,
settingid
,
appSecret
}
=
app
.
config
.
JBnotifyCenter
;
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
;
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
.
getUuid
=
function
()
{
return
uuid
();
};
config/config.local.js
View file @
ba39b29e
...
...
@@ -14,6 +14,12 @@ module.exports = () => {
db
:
0
,
},
};
config
.
JBnotifyCenter
=
{
baseURL
:
'https://notifier.getxumi.com/api/notify'
,
settingid
:
'5cbef46823775d0001640fc8'
,
appSecret
:
'6bc693e3ce84478482880a3600c9a78c'
,
};
config
.
taskAPI
=
{
host
:
'http://tm.51gjj.com:4831'
,
createTaskUrl
:
'/gjjServices/createGjjTask'
,
...
...
config/config.prod.js
View file @
ba39b29e
...
...
@@ -17,6 +17,12 @@ module.exports = () => {
db
:
0
,
},
};
config
.
JBnotifyCenter
=
{
baseURL
:
'https://notifier.getxumi.com/api/notify'
,
settingid
:
'5cbef46823775d0001640fc8'
,
appSecret
:
'6bc693e3ce84478482880a3600c9a78c'
,
};
config
.
taskAPI
=
{
host
:
process
.
env
.
TASKAPI_HOST
||
'http://tm.51gjj.com:4821'
,
createTaskUrl
:
'/gjjServices/createGjjTask'
,
...
...
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