Commit 1185ad77 authored by 姜登's avatar 姜登

短信

parent 3ee28cbf
Pipeline #6973 passed with stage
in 2 seconds
module.exports = app => {
// 自定义内容
app.beforeStart(async () => {
const ctx = app.createAnonymousContext();
// ctx.helper.sendMsg({ message: '服务重启' });
});
};
\ No newline at end of file
'use strict'; 'use strict';
const querystring = require('querystring');
const crypto = require('crypto'); const crypto = require('crypto');
const uuid = require('uuid/v1'); const uuid = require('uuid/v1');
function process(params) { function process(data) {
const keys = Object.keys(params) const keys = Object.keys(data);
.filter(key => { keys.sort();
return ( let sign_str = '';
params[key] !== undefined && keys.forEach(key => {
params[key] !== '' && const v = data[key];
['appSecret', 'partner_key', 'sign', 'key'].indexOf(key) < 0 sign_str += `${key}=${v}&`;
); });
}) return sign_str;
.sort();
const result = {};
for (const key of keys) {
result[key] = params[key];
}
return result;
} }
module.exports.buildRequestBody = function(params, needNonceStr = false) { module.exports.getUuid = function() {
const { app } = this; return uuid();
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.paramSign = function(appSecret, params) { /**
if (!params) { * @desc:通知中心
const err = new Error('parameter params missing'); * @author: JD
err.name = 'ParameterSignError'; * @param {Object} content: 需要发送的预警信息模板
throw err; * @return {Boolean} 信息发送状态
} */
if (!appSecret) { module.exports.sendMsg = async function(content) {
const err = new Error('parameter appSecret missing'); if (!content) return false;
err.name = 'ParamSignError'; const { app } = this;
throw err; const { baseURL, settingid, appSecret } = app.config.JBnotifyCenter;
} const t = +new Date();
const newParams = process(params); let sign_str = process({ timestamp: t, settingid, params: JSON.stringify(content) });
let query = querystring.stringify(newParams); sign_str += `appsecret=${appSecret}`;
query += '&appSecret=' + appSecret; console.log(sign_str);
const signStr = crypto const sign = crypto
.createHash('md5') .createHash('md5')
.update(query) .update(sign_str)
.digest('hex') .digest('hex')
.toUpperCase(); .toUpperCase();
return signStr; const option = {
}; settingid,
timestamp: t,
module.exports.getUuid = function() { sign,
return uuid(); params: content,
};
const result = await this.app.curl(baseURL, {
method: 'POST',
data: option,
dataType: 'json',
contentType: 'json',
});
return result;
}; };
...@@ -14,6 +14,11 @@ module.exports = () => { ...@@ -14,6 +14,11 @@ module.exports = () => {
db: 0, db: 0,
}, },
}; };
config.JBnotifyCenter = {
baseURL: 'https://notifier.getxumi.com/api/notify',
settingid: '5cbef46823775d0001640fc8',
appSecret: '6bc693e3ce84478482880a3600c9a78c',
};
config.taskAPI = { config.taskAPI = {
host: 'http://tm.51gjj.com:4821', host: 'http://tm.51gjj.com:4821',
createTaskUrl: '/gjjServices/createGjjTask', createTaskUrl: '/gjjServices/createGjjTask',
......
...@@ -17,6 +17,12 @@ module.exports = () => { ...@@ -17,6 +17,12 @@ module.exports = () => {
db: 0, db: 0,
}, },
}; };
config.JBnotifyCenter = {
baseURL: 'https://notifier.getxumi.com/api/notify',
settingid: '5cbef46823775d0001640fc8',
appSecret: '6bc693e3ce84478482880a3600c9a78c',
};
config.taskAPI = { config.taskAPI = {
host: process.env.TASKAPI_HOST || 'http://tm.51gjj.com:4821', host: process.env.TASKAPI_HOST || 'http://tm.51gjj.com:4821',
createTaskUrl: '/gjjServices/createGjjTask', createTaskUrl: '/gjjServices/createGjjTask',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment