Commit 365b84c9 authored by 姜登's avatar 姜登

yys

parent 934c92cc
Pipeline #6950 passed with stage
in 2 seconds
...@@ -2,8 +2,7 @@ module.exports = app => { ...@@ -2,8 +2,7 @@ module.exports = app => {
// 自定义内容 // 自定义内容
app.beforeStart(async () => { app.beforeStart(async () => {
// 应用会等待这个函数执行完成才启动 const ctx = app.createAnonymousContext();
app.projectName = 'eggManual' ctx.helper.sendMsg({ message: '服务重启' });
console.log("==app beforeStart==");
}); });
}; };
\ 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');
const iconv = require('iconv-lite'); const iconv = require('iconv-lite');
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) { module.exports.decode = function(data) {
return crypto.randomBytes(length).toString('hex'); return iconv.decode(data, 'gb2312');
}; };
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;
}; };
module.exports.decode = function(data) {
return iconv.decode(data, 'gb2312');
};
...@@ -26,7 +26,6 @@ module.exports = { ...@@ -26,7 +26,6 @@ module.exports = {
}); });
ctx.app.notifyMap = notifyMap; ctx.app.notifyMap = notifyMap;
} }
ctx.logger.info(ctx.app.projectName)
// console.log(await ctx.helper.sendMsg({ message: 'test' })); // console.log(await ctx.helper.sendMsg({ message: 'test' }));
} catch (e) { } catch (e) {
ctx.logger.error('【schedule/notifyUrlTask】catch error:', JSON.stringify(e)); ctx.logger.error('【schedule/notifyUrlTask】catch error:', JSON.stringify(e));
......
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