Commit cb79012f by 宋毅

添加推送判断

parent bbb32a1e
...@@ -192,7 +192,7 @@ module.exports = SignService; ...@@ -192,7 +192,7 @@ module.exports = SignService;
// }; // };
//需求 //需求
// var obj={ // var obj={
// "intentionBizId": "baidu_test_00087", // "intentionBizId": "baidu_test_00088",
// "phone": "18506013355", // "phone": "18506013355",
// "userName": "测试03", // "userName": "测试03",
// "description": "测试03描述", // "description": "测试03描述",
......
...@@ -6,22 +6,24 @@ const settings = require("../../../app/config/settings"); ...@@ -6,22 +6,24 @@ const settings = require("../../../app/config/settings");
const axios = require('axios'); const axios = require('axios');
const moment = require('moment'); const moment = require('moment');
const uuid = require('uuid'); const uuid = require('uuid');
class ExecClientNew { class ExecClientNew {
constructor() { constructor() {
this.cmdGetPattern = "curl -G -X GET '{url}'"; this.cmdGetPattern = "curl -G -X GET '{url}'";
this.cmdPostPattern = "curl -k -H 'Content-type: application/json' -d '{data}' {url}"; this.cmdPostPattern = "curl -k -H 'Content-type: application/json' -d '{data}' {url}";
// this.cmdPushDataPostPattern = "curl -k -H 'Content-type: application/json' -H 'token:{tk}' -H 'appkey:{appkey}' -d '{data}' {url}"; // this.cmdPushDataPostPattern = "curl -k -H 'Content-type: application/json' -H 'token:{tk}' -H 'appkey:{appkey}' -d '{data}' {url}";
} }
/** /**
* 带超时时间的post请求 * 带超时时间的post请求
* @param {*} execFile 执行文件 * @param {*} execFile 执行文件
* @param {*} params 请求数据-json格式 * @param {*} params 请求数据-json格式
* @param {*} url 请求地址 * @param {*} url 请求地址
* @param {*} ContentType 请求头类型,默认application/json * @param {*} ContentType 请求头类型,默认application/json
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"} * @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
* @param {*} timeOut 超时时间设置,单位秒 * @param {*} timeOut 超时时间设置,单位秒
* @param {*} req 请求信息 * @param {*} req 请求信息
*/ */
async execPostTimeOutByBusiness(execFile, params, url, ContentType, headData, timeOut = 60, req) { async execPostTimeOutByBusiness(execFile, params, url, ContentType, headData, timeOut = 60, req) {
var rtn = null; var rtn = null;
var reqResult = null; var reqResult = null;
...@@ -99,6 +101,7 @@ class ExecClientNew { ...@@ -99,6 +101,7 @@ class ExecClientNew {
return reqResult; return reqResult;
} }
} }
/** /**
* 记录日志信息 * 记录日志信息
* @param {*} opTitle 操作的标题 * @param {*} opTitle 操作的标题
...@@ -109,37 +112,39 @@ class ExecClientNew { ...@@ -109,37 +112,39 @@ class ExecClientNew {
*/ */
async execLogs(opTitle, params, identifyCode, resultInfo, errorInfo) { async execLogs(opTitle, params, identifyCode, resultInfo, errorInfo) {
var reqUrl = settings.opNewLogUrl(); var reqUrl = settings.opNewLogUrl();
params = typeof params === 'object' ? JSON.stringify(params) : params || ""; let tmpParams1 = typeof params === 'object' ? JSON.stringify(params) : params || "";
resultInfo = typeof resultInfo === 'object' ? JSON.stringify(resultInfo) : resultInfo || ""; let tmpResultInfo = typeof resultInfo === 'object' ? JSON.stringify(resultInfo) : resultInfo || "";
errorInfo = typeof errorInfo === 'object' ? JSON.stringify(errorInfo) : errorInfo || ""; let tmpErrorInfo = typeof errorInfo === 'object' ? JSON.stringify(errorInfo) : errorInfo || "";
var tmpParams = { var tmpParams = {
opTitle: opTitle || "", opTitle: opTitle || "",
identifyCode: identifyCode || "", identifyCode: identifyCode || "",
messageBody: params, messageBody: tmpParams1,
resultInfo: resultInfo || "", resultInfo: tmpResultInfo || "",
errorInfo: errorInfo || "", errorInfo: tmpErrorInfo || "",
requestId: resultInfo ? resultInfo.requestId || "" : "", requestId: resultInfo ? resultInfo.requestId || "" : "",
created_at: moment().format("YYYY-MM-DD HH:mm:ss:SSS"), created_at: moment().format("YYYY-MM-DD HH:mm:ss:SSS"),
timestamp: Date.now() timestamp: Date.now()
} }
this.execPostTimeOut(tmpParams, reqUrl, 'application/json', null, 20); this.execPostTimeOut(tmpParams, reqUrl, 'application/json', null, 20);
} }
/** /**
* get请求 * get请求
* @param {*} params 提交的数据-格式JSON * @param {*} params 提交的数据-格式JSON
* @param {*} url * @param {*} url
* @param {*} headData 请求信息,JSON格式 * @param {*} headData 请求信息,JSON格式
*/ */
async execGet(params, url, headData) { async execGet(params, url, headData) {
let cmd = this.FetchGetCmd(params, url, headData); let cmd = this.FetchGetCmd(params, url, headData);
var result = await this.exec(cmd); var result = await this.exec(cmd);
return result; return result;
} }
/** /**
* *
* @param {*} params 提交的数据JSON格式 * @param {*} params 提交的数据JSON格式
* @param {*} url * @param {*} url
* @param {*} headData 请求信息,JSON格式 * @param {*} headData 请求信息,JSON格式
* @param {*} timeOut 超时时间 * @param {*} timeOut 超时时间
*/ */
async execGetTimeOut(params, url, headData, timeOut = 5000) { async execGetTimeOut(params, url, headData, timeOut = 5000) {
...@@ -148,9 +153,10 @@ class ExecClientNew { ...@@ -148,9 +153,10 @@ class ExecClientNew {
var options = { var options = {
timeout: timeOut, timeout: timeOut,
}; };
const { stdout, stderr } = await exec(cmd, options); const {stdout, stderr} = await exec(cmd, options);
return { stdout, stderr }; return {stdout, stderr};
} }
/** /**
* 带超时时间的post请求 * 带超时时间的post请求
* @param {*} params 请求数据-json格式 * @param {*} params 请求数据-json格式
...@@ -169,6 +175,7 @@ class ExecClientNew { ...@@ -169,6 +175,7 @@ class ExecClientNew {
var result = await this.exec(cmd, options, headData); var result = await this.exec(cmd, options, headData);
return result; return result;
} }
/** /**
* 带超时时间的post请求 * 带超时时间的post请求
* @param {*} params 请求数据-json格式 * @param {*} params 请求数据-json格式
...@@ -195,14 +202,16 @@ class ExecClientNew { ...@@ -195,14 +202,16 @@ class ExecClientNew {
async exec(cmd) { async exec(cmd) {
//await后面表达式返回的promise对象,是then的语法糖,await返回then函数的返回值 //await后面表达式返回的promise对象,是then的语法糖,await返回then函数的返回值
//异常需要try/catch自己捕获或外部catch捕获 //异常需要try/catch自己捕获或外部catch捕获
const { stdout, stderr } = await exec(cmd); const {stdout, stderr} = await exec(cmd);
return { stdout, stderr }; return {stdout, stderr};
} }
FetchGetCmd(params, url, headData) { FetchGetCmd(params, url, headData) {
var cmd = this.cmdGetPattern.replace( var cmd = this.cmdGetPattern.replace(
/\{data\}/g, params).replace(/\{url\}/g, url); /\{data\}/g, params).replace(/\{url\}/g, url);
return cmd; return cmd;
} }
FetchPostCmd(params, url, ContentType, headData) { FetchPostCmd(params, url, ContentType, headData) {
if (!ContentType) { if (!ContentType) {
ContentType = "application/json"; ContentType = "application/json";
...@@ -245,9 +254,9 @@ class ExecClientNew { ...@@ -245,9 +254,9 @@ class ExecClientNew {
} }
/** /**
* 返回20位业务订单号 * 返回20位业务订单号
* @param {*} prefix 业务前缀 * @param {*} prefix 业务前缀
*/ */
async getBusUid(prefix) { async getBusUid(prefix) {
prefix = (prefix || ""); prefix = (prefix || "");
if (prefix) { if (prefix) {
...@@ -262,6 +271,7 @@ class ExecClientNew { ...@@ -262,6 +271,7 @@ class ExecClientNew {
var timStr = moment().format("YYYYMMDDHHmm"); var timStr = moment().format("YYYYMMDDHHmm");
return prefix + timStr + uidStr; return prefix + timStr + uidStr;
} }
/** /**
* 返回指定长度的字符串 * 返回指定长度的字符串
* @param {*} len 返回长度 * @param {*} len 返回长度
...@@ -286,6 +296,7 @@ class ExecClientNew { ...@@ -286,6 +296,7 @@ class ExecClientNew {
} }
return uuid.join(''); return uuid.join('');
} }
//--------------------------------------------------辅助方法end----------------- //--------------------------------------------------辅助方法end-----------------
} }
......
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