Commit 97d6a397 by 任晓松

update

parent 3375ccf7
......@@ -4,6 +4,7 @@ const settings = require("../../config/settings");
const md5 = require("MD5");
class AppServiceBase {
constructor() {
this.execClientNew = system.getObject("util.execClientNew");
this.restClient = system.getObject("util.restClient");
this.execClient = system.getObject("util.execClient");
this.cacheManager = system.getObject("db.common.cacheManager");
......@@ -57,5 +58,18 @@ class AppServiceBase {
var result = JSON.parse(rtn.stdout);
return result;
}
/**
* 带超时时间的post请求
* @param {*} req 请求信息
* @param {*} params 请求数据-json格式
* @param {*} url 请求地址
* @param {*} ContentType 请求头类型,默认application/json
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
* @param {*} timeOut 超时时间
*/
async execPostByTimeOut(req, params, url, ContentType, headData, timeOut = 60) {
const result = await this.execClientNew.execPostTimeOutByBusiness('sve.base', params, url, ContentType, headData, timeOut, req);
return result;
}
}
module.exports = AppServiceBase;
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const AppBase = require("../../app.base");
var settings = require("../../../../config/settings");
class Push360Service {
class Push360Service extends AppBase{
constructor() {
this.pushlogDao = system.getObject("db.common.pushlogDao");
super()
this.ordercontactsDao = system.getObject("db.dbcorder.ordercontactsDao");
this.orderinfoDao = system.getObject("db.dbcorder.orderinfoDao");
this.push360Url = settings.push360Url();
......@@ -18,50 +18,35 @@ class Push360Service {
status = 40;
}
let order_id = actionBody.orderNo;
var result, pushObj, url;
try {
var rc = system.getObject("util.execClient");
let rtn = await rc.exec360GetToken(this.auth360Url)
let rtn = await this.execClient.exec360GetToken(this.auth360Url)
if (!rtn || !rtn.stdout) {
return system.getResult(null, "restPost data is empty");
}
let tokenResult = JSON.parse(rtn.stdout);
let token = tokenResult.access_token;
let url = this.push360Url + '/api/v1/eshop/GsbOrderUpdate?token=' + token;
let pushObj = {
url = this.push360Url + '/api/v1/eshop/GsbOrderUpdate?token=' + token;
pushObj = {
order_id: order_id,
status: status
}
let result = await rc.execPost(pushObj, url);
var logObj = {
appid: "",
appkey: "",
op: url,
content: JSON.stringify(actionBody),
resultInfo: result ? JSON.stringify(result) : ""
};
if (!result || !result.stdout) {
logObj["returnType"] = "0";
logObj["opTitle"] = "数据推送360返回失败";
this.pushlogDao.create(logObj);
return system.getResultFail(-502, "execPost data is empty");
} else {
logObj["returnType"] = "1";
logObj["opTitle"] = "数据推送360返回成功";
this.pushlogDao.create(logObj);
let stdout = JSON.parse(result.stdout);
return system.getResultSuccess(stdout);
result = await this.execPostByTimeOut(pushObj, url);
if (result.status != 0) {
return result;
}
if (result.data.status != 0) {
return result.data;
}
return system.getResultSuccess(result.data.data);
} catch (e) {
this.pushlogDao.create({
appid: "",
appkey: "",
logLevel: "3",
op: this.push360Url,
content: JSON.stringify(actionBody),
resultInfo: JSON.stringify(e.stack),
returnType: "0",
opTitle: "数据推送360---异常"
});
this.execClientNew.execLogs({
opTitle:"360订单状态推送",
params:actionBody.orderNo,
identifyCode: "360TmStatus",
resultInfo:"",
errorInfo: e.stack
})
return system.getResultFail(-500, JSON.stringify(e.stack));
}
}
......@@ -70,6 +55,12 @@ class Push360Service {
async sendMessage(actionBody) {
try {
let orderNo = actionBody.orderNo;
if(!actionBody.registNumInfo){
return system.getResultFail(-1,'')
}
if(!actionBody.officialInfo){
return system.getResultFail(-1,'')
}
//获取联系人信息
let item = await this.ordercontactsDao.getItemByOrderNo(actionBody.orderNo);
let deliveryInfo = actionBody.deliveryInfo;
......@@ -95,8 +86,7 @@ class Push360Service {
// templateId = 2;
// }
var rc = system.getObject("util.execClient");
let rtn = await rc.exec360GetToken(this.auth360Url)
let rtn = await this.execClient.exec360GetToken(this.auth360Url)
if (!rtn || !rtn.stdout) {
return system.getResult(null, "restPost data is empty");
}
......@@ -105,37 +95,23 @@ class Push360Service {
let url = this.push360Url + '/api/v1/GsbSendsms';
let params = tmName + "|" + oneNcl + "|" + tmRegistNum + "|" + uploadFileName;
let subData = "token=" + token + "&mobile=" + mobile + "&templated=" + templateId + "&replaceContent=" + params;
let result = await rc.execGet(subData, url);
var logObj = {
appid: "",
appkey: "",
op: url,
content: JSON.stringify(actionBody),
resultInfo: result ? JSON.stringify(result) : ""
};
if (!result || !result.stdout) {
logObj["returnType"] = "0";
logObj["opTitle"] = "数据推送360返回失败";
this.pushlogDao.create(logObj);
return system.getResultFail(-502, "execPost data is empty");
} else {
logObj["returnType"] = "1";
logObj["opTitle"] = "数据推送360返回成功";
this.pushlogDao.create(logObj);
let stdout = JSON.parse(result.stdout);
return system.getResultSuccess(stdout);
}
let result = await this.execClient.execGet(subData, url);
this.execClientNew.execLogs({
opTitle:"360短信推送",
params:params,
identifyCode: "360Message",
resultInfo:result.data,
errorInfo: ""
})
return system.getResultSuccess()
} catch (e) {
this.pushlogDao.create({
appid: "",
appkey: "",
logLevel: "3",
op: this.push360Url,
content: JSON.stringify(actionBody),
resultInfo: JSON.stringify(e.stack),
returnType: "0",
opTitle: "数据推送360短信---异常"
});
this.execClientNew.execLogs({
opTitle:"360短信推送",
params:actionBody.orderNo,
identifyCode: "360Message",
resultInfo:"",
errorInfo: e.stack
})
return system.getResultFail(-500, JSON.stringify(e.stack));
}
}
......
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