Commit d835e1c1 by 宋毅

Merge branch 'center-channel' of gitlab.gongsibao.com:jiangyong/zhichan into center-channel

parents d1c59db0 7b8b8b00
...@@ -3,6 +3,7 @@ FROM registry.cn-beijing.aliyuncs.com/hantang2/node105:v2 ...@@ -3,6 +3,7 @@ FROM registry.cn-beijing.aliyuncs.com/hantang2/node105:v2
MAINTAINER jy "jiangyong@gongsibao.com" MAINTAINER jy "jiangyong@gongsibao.com"
ADD center-channel /apps/center-channel/ ADD center-channel /apps/center-channel/
WORKDIR /apps/center-channel/ WORKDIR /apps/center-channel/
RUN yum install gcc-c++.x86_64 -y
RUN npm install --unsafe-perm=true --allow-root RUN npm install --unsafe-perm=true --allow-root
CMD ["node","/apps/center-channel/main.js"] CMD ["node","/apps/center-channel/main.js"]
......
var APIBase = require("../../api.base"); var APIBase = require("../../api.base");
var system = require("../../../system"); var system = require("../../../system");
var settings = require("../../../../config/settings"); var settings = require("../../../../config/settings");
class QcAPI extends APIBase { class QcAPI extends APIBase {
constructor() { constructor() {
super(); super();
...@@ -9,12 +10,13 @@ class QcAPI extends APIBase { ...@@ -9,12 +10,13 @@ class QcAPI extends APIBase {
this.ncSve = system.getObject("service.common.ncSve"); this.ncSve = system.getObject("service.common.ncSve");
this.rtSve = system.getObject("service.common.rtSve"); this.rtSve = system.getObject("service.common.rtSve");
} }
/** /**
* 接口跳转-POST请求 * 接口跳转-POST请求
* action_process 执行的流程 * action_process 执行的流程
* action_type 执行的类型 * action_type 执行的类型
* action_body 执行的参数 * action_body 执行的参数
*/ */
async springBoard(pobj, qobj, req) { async springBoard(pobj, qobj, req) {
if (!pobj.actionType) { if (!pobj.actionType) {
return system.getResult(null, "actionType参数不能为空"); return system.getResult(null, "actionType参数不能为空");
...@@ -22,6 +24,7 @@ class QcAPI extends APIBase { ...@@ -22,6 +24,7 @@ class QcAPI extends APIBase {
var result = await this.opActionProcess(pobj, pobj.actionType, req); var result = await this.opActionProcess(pobj, pobj.actionType, req);
return result; return result;
} }
async opActionProcess(pobj, action_type, req) { async opActionProcess(pobj, action_type, req) {
var opResult = null; var opResult = null;
switch (action_type) { switch (action_type) {
...@@ -55,7 +58,7 @@ class QcAPI extends APIBase { ...@@ -55,7 +58,7 @@ class QcAPI extends APIBase {
case "closeOrderDelivery"://交付商关闭交付单 case "closeOrderDelivery"://交付商关闭交付单
opResult = await this.qcCenterOrderSve.closeOrderDelivery(pobj); opResult = await this.qcCenterOrderSve.closeOrderDelivery(pobj);
break; break;
// 2021-3-23 laolan 易名退款 // 2021-3-23 laolan 易名退款
case "eNameCloseOrder": case "eNameCloseOrder":
opResult = await this.baseOrderSve.eNameCloseOrder(pobj); opResult = await this.baseOrderSve.eNameCloseOrder(pobj);
...@@ -71,7 +74,7 @@ class QcAPI extends APIBase { ...@@ -71,7 +74,7 @@ class QcAPI extends APIBase {
case "ncSubmitSolution"://提交方案(网文)2020-11-11 case "ncSubmitSolution"://提交方案(网文)2020-11-11
opResult = await this.ncSve.ncSubmitSolution(pobj); opResult = await this.ncSve.ncSubmitSolution(pobj);
break; break;
// --------- 广电 --------- // --------- 广电 ---------
...@@ -85,7 +88,7 @@ class QcAPI extends APIBase { ...@@ -85,7 +88,7 @@ class QcAPI extends APIBase {
opResult = await this.rtSve.rtSubmitSolution(pobj); opResult = await this.rtSve.rtSubmitSolution(pobj);
break; break;
// --------- 推送icp信息至渠道和作方 zhuangbing-20201116-------- // --------- 推送icp信息至渠道和作方 zhuangbing-20201116--------
case "pushIcpSolution2Channel"://推送ICP方案至渠道(百度) case "pushIcpSolution2Channel"://推送ICP方案至渠道(百度)
opResult = await this.baseOrderSve.pushIcpSolution2Channel(pobj); opResult = await this.baseOrderSve.pushIcpSolution2Channel(pobj);
break; break;
...@@ -97,4 +100,5 @@ class QcAPI extends APIBase { ...@@ -97,4 +100,5 @@ class QcAPI extends APIBase {
} }
} }
module.exports = QcAPI; module.exports = QcAPI;
\ No newline at end of file
...@@ -36,6 +36,10 @@ class AccessAuthAPI extends APIBase { ...@@ -36,6 +36,10 @@ class AccessAuthAPI extends APIBase {
await this.redisClient.set("start_time_18",endtime+1) await this.redisClient.set("start_time_18",endtime+1)
return res return res
} }
//后台任务调度这个方法,获取暂存的需求信息
//igirl_api数据库gateway_pushlog
//gateway_pushlog表中且未推送且推送次数(pushtimes)少于4的数据
//
async taskAliIcapi() { async taskAliIcapi() {
var rtn = await this.gatewaypushlogSve.taskAliIcapi(); var rtn = await this.gatewaypushlogSve.taskAliIcapi();
return rtn; return rtn;
......
...@@ -21,44 +21,21 @@ class Order extends APIBase { ...@@ -21,44 +21,21 @@ class Order extends APIBase {
if (!pobj.orderNo) { if (!pobj.orderNo) {
return regCfg.getResultFail("orderNo不能为空"); return regCfg.getResultFail("orderNo不能为空");
} }
// var i = 0;
// var orderLength = pobj.subOrderList.lenght;
// for (i = 0; i <= orderLength; i++) {
// if (!pobj.subOrderList[i].orderNo) {
// return regCfg.getResultFail("orderNo不能为空");
// }
// if (pobj.isDirectBuy == 0 && !pobj.subOrderList[i].bizId) {
// return regCfg.getResultFail("非直接下单bizId不能为空");
// }
// if (pobj.isDirectBuy == 1 && !pobj.subOrderList[i].phone) {
// return regCfg.getResultFail("直接下单phone不能为空");
// }
// if (pobj.isDirectBuy == 1 && !pobj.subOrderList[i].consultType) {
// return regCfg.getResultFail("直接下单consultType不能为空");
// }
// // if (pobj.subOrderList[i].area) {
// // pobj.subOrderList[i].area = regCfg.baiduArea[pobj.subOrderList[i].area]
// // }
// if (!pobj.subOrderList[i].area) {
// return regCfg.getResultFail("area参数错误");
// }
// }
if (!pobj.orderNo) { if (!pobj.orderNo) {
return regCfg.getResultFail("orderNo不能为空"); return regCfg.getResultFail("orderNo不能为空");
} }
if (pobj.isDirectBuy==0 && !pobj.bizId) { if (pobj.isDirectBuy == 0 && !pobj.bizId) {
return regCfg.getResultFail("非直接下单bizId不能为空"); return regCfg.getResultFail("非直接下单bizId不能为空");
} }
if (pobj.isDirectBuy==1 && !pobj.phone) { if (pobj.isDirectBuy == 1 && !pobj.phone) {
return regCfg.getResultFail("直接下单phone不能为空"); return regCfg.getResultFail("直接下单phone不能为空");
} }
if (pobj.isDirectBuy==1 && !pobj.consultType) { if (pobj.isDirectBuy == 1 && !pobj.consultType) {
return regCfg.getResultFail("直接下单consultType不能为空"); return regCfg.getResultFail("直接下单consultType不能为空");
} }
if (pobj.area) { if (pobj.area) {
pobj.area = regCfg.baiduArea[pobj.area] pobj.area = regCfg.baiduArea[pobj.area]
} }
pobj.status = 1; pobj.status = 1;
pobj.action_type = "regOrderStatus"; pobj.action_type = "regOrderStatus";
...@@ -98,4 +75,5 @@ class Order extends APIBase { ...@@ -98,4 +75,5 @@ class Order extends APIBase {
} }
} }
module.exports = Order; module.exports = Order;
\ No newline at end of file
...@@ -4,80 +4,74 @@ var settings = require("../../../../config/settings"); ...@@ -4,80 +4,74 @@ var settings = require("../../../../config/settings");
//此类用来db中配置来进行调用-主要功能是推送交付系统 //此类用来db中配置来进行调用-主要功能是推送交付系统
class UtilsDeliverSystemService extends AppServiceBase { class UtilsDeliverSystemService extends AppServiceBase {
constructor() { constructor() {
super(); super();
this.opPushQueueUrl = settings.opPushQueueUrl(); this.opPushQueueUrl = settings.opPushQueueUrl();
}
/**
* 推送业务信息到交付系统
* 业务操作的信息不变外加增加组装的一些参数(推送需求商机、关闭需求、订单商机、关闭订单)
* @param {*} pobj
*/
async pushBusiness2DeliverSystem(pobj) {//推送业务信息到交付系统
var verifyResult = await this.verifyParam(pobj);
if (verifyResult.status != 0) {
return await this.disposePushResultFail(pobj, verifyResult, "deliver->pushBusiness2DeliverSystem->verifyResult", this.pushlogFailType.FQ);
} }
var interface_params_info = verifyResult.data;
// var reqParams = { /**
// actionType: "produceData",// Y 功能名称 * 推送业务信息到交付系统
// actionBody: { * 业务操作的信息不变外加增加组装的一些参数(推送需求商机、关闭需求、订单商机、关闭订单)
// pushUrl: interface_params_info.pushUrl,// Y 推送地址 * @param {*} pobj
// actionType: interface_params_info.actionType,// Y 推送地址接收时的功能名称 */
// notifyUrl: interface_params_info.notifyUrl || "",// N 推送成功后通知的Url async pushBusiness2DeliverSystem(pobj) {//推送业务信息到交付系统
// identifyCode: interface_params_info.identifyCode,// Y 操作的业务标识 this.execClientNew.execLogs(`推送资质宝结果->pushBusiness2DeliverSystem`, pobj, "center-channel-utilsDeliverSystemSve-pushBusiness2DeliverSystem", null, null);
// messageBody: pobj.actionBody, // Y 推送的业务消息,必须有一项对象属性值 var verifyResult = await this.verifyParam(pobj);
// headData: interface_params_info.headData //N 请求头信息,Json格式,如:{token:"XXXXXXX"} if (verifyResult.status != 0) {
// }, return await this.disposePushResultFail(pobj, verifyResult, "deliver->pushBusiness2DeliverSystem->verifyResult", this.pushlogFailType.FQ);
// requestId: pobj.requestId || "" // N 请求id }
// } var interface_params_info = verifyResult.data;
let parms = { let params = null
actionType:interface_params_info.actionType, let headInfo = {}
actionBody: pobj.actionBody if (pobj.appInfo) {
headInfo["appcode"] = pobj.appInfo.app_code
params = {
actionType: interface_params_info.actionType,
actionBody: pobj.actionBody,
headData: headInfo
}
} else {
params = {
actionType: interface_params_info.actionType,
actionBody: pobj.actionBody
}
}
let url = interface_params_info.opUrl;
var opQueuePushClientPostRes = await this.opQueuePushClientPost(pobj, url, params);
return await this.disposePushResult(pobj, opQueuePushClientPostRes, "delivery->pushBusiness2DeliverSystem->result", this.pushlogFailType.FQ);
} }
let url = interface_params_info.opUrl;
var opQueuePushClientPostRes = await this.opQueuePushClientPost(pobj, url, parms);
return await this.disposePushResult(pobj, opQueuePushClientPostRes, "delivery->pushBusiness2DeliverSystem->result", this.pushlogFailType.FQ);
}
//--------------------------------------------------内部辅助方法-------------------start----------------- //--------------------------------------------------内部辅助方法-------------------start-----------------
async opQueuePushClientPost(pobj, pushQueueUrl, reqParams) { async opQueuePushClientPost(pobj, pushQueueUrl, reqParams) {
try { try {
var rtn = await this.restPostUrl(reqParams, pushQueueUrl); var rtn = await this.restPostUrl(reqParams, pushQueueUrl);
if (rtn.status != 1) { this.execClientNew.execLogs(`推送资质宝结果->opQueuePushClientPost->url:` + pushQueueUrl, reqParams, "center-channel-utilsDeliverSystemSve-opQueuePushClientPost", rtn, null);
this.execClientNew.execLogs(`推送资质宝失败->opQueuePushClientPost`, pobj, "center-channel-utilsDeliverSystemSve-opQueuePushClientPost", rtn, JSON.stringify(rtn)); if (rtn.status != 1) {
return system.getResult(null, "推送资质宝失败,失败原因:" + JSON.stringify(rtn)); return system.getResult(null, "推送资质宝失败,失败原因:" + JSON.stringify(rtn));
} }
return system.getResultSuccess(null, "推送成功"); return system.getResultSuccess(null, "推送成功");
} catch (e) { } catch (e) {
//日志记录 const stackStr = e.stack ? e.stack : JSON.stringify(e);
// this.logCtl.error({ this.execClientNew.execLogs(`推送操作异常deliver->opQueuePushClientPost`, pobj, "center-channel-utilsDeliverSystemSve-opQueuePushClientPost", null, stackStr);
// appid: pobj.appInfo ? pobj.appInfo.uapp_id || "" : "", return system.getResult(null, "推送操作异常deliver->opQueuePushClientPost->error:" + stackStr);
// appkey: pobj.appInfo ? pobj.appInfo.uapp_key || "" : "", }
// requestId: pobj.requestId || "",
// op: "utilsSve/utilsDeliverSystemSve/opQueuePushClientPost",
// content: "error:" + e.stack,
// // clientIp: pobj.clientIp,
// optitle: pobj.opType + "推送操作异常deliver->opQueuePushClientPost",
// });
this.execClientNew.execLogs(`推送资质宝失败->opQueuePushClientPost`, pobj, "center-channel-utilsDeliverSystemSve-opQueuePushClientPost", null, JSON.stringify(e.stack));
return system.getResult(null, "推送操作异常deliver->opQueuePushClientPost->error:" + e.stack);
}
}
async verifyParam(pobj) {//参数信息验证
var verify = system.getResultSuccess();
if (!pobj.interface_params) {
verify = system.getResult(null, "interface_params can not be empty,100400");
} }
var interface_params_info = JSON.parse(pobj.interface_params);
if (!interface_params_info || !interface_params_info.opUrl || !interface_params_info.headData) { async verifyParam(pobj) {//参数信息验证
verify = system.getResult(null, "interface_params(opUrl、headData) can not be empty,100430"); var verify = system.getResultSuccess();
if (!pobj.interface_params) {
verify = system.getResult(null, "interface_params can not be empty,100400");
}
var interface_params_info = JSON.parse(pobj.interface_params);
if (!interface_params_info || !interface_params_info.opUrl || !interface_params_info.headData) {
verify = system.getResult(null, "interface_params(opUrl、headData) can not be empty,100430");
}
verify.data = interface_params_info;
return verify;
} }
verify.data = interface_params_info;
return verify;
}
//--------------------------------------------------内部辅助方法-------------------end----------------- //--------------------------------------------------内部辅助方法-------------------end-----------------
} }
module.exports = UtilsDeliverSystemService; module.exports = UtilsDeliverSystemService;
...@@ -66,16 +66,31 @@ class UtilsNeedService extends AppServiceBase { ...@@ -66,16 +66,31 @@ class UtilsNeedService extends AppServiceBase {
pobj.actionBody.idempotentSource = "edi_ali"; pobj.actionBody.idempotentSource = "edi_ali";
} else if (pobj.actionBody.channel_type_code == "tmjy") { } else if (pobj.actionBody.channel_type_code == "tmjy") {
// 阿里商标交易 // 阿里商标交易
if(pobj.actionBody.phone.length>11){
// 如果是密文手机号,则设置为空
pobj.actionBody.phone = ""
pobj.actionBody.mobile = ""
}
pobj.actionBody.type = "ali.tmd"; pobj.actionBody.type = "ali.tmd";
pobj.actionBody.idempotentSource = "tmd_ali"; pobj.actionBody.idempotentSource = "tmd_ali";
pobj.actionBody.contactsDingtalk = pobj.actionBody.idempotentId; pobj.actionBody.contactsDingtalk = pobj.actionBody.idempotentId;
}else if (pobj.actionBody.channel_type_code == 1) { }else if (pobj.actionBody.channel_type_code == 1) {
// 阿里商标交易 // 阿里商标交易
if(pobj.actionBody.phone.length>11){
// 如果是密文手机号,则设置为空
pobj.actionBody.phone = ""
pobj.actionBody.mobile = ""
}
pobj.actionBody.type = "ali.tmd"; pobj.actionBody.type = "ali.tmd";
pobj.actionBody.idempotentSource = "tmd_ali"; pobj.actionBody.idempotentSource = "tmd_ali";
pobj.actionBody.contactsDingtalk = pobj.actionBody.idempotentId; pobj.actionBody.contactsDingtalk = pobj.actionBody.idempotentId;
}else if (pobj.actionBody.channel_type_code == 2) { }else if (pobj.actionBody.channel_type_code == 2) {
// 阿里商标注册 // 阿里商标注册
if(pobj.actionBody.phone.length>11){
// 如果是密文手机号,则设置为空
pobj.actionBody.phone = ""
pobj.actionBody.mobile = ""
}
pobj.actionBody.type = "ali.tm"; pobj.actionBody.type = "ali.tm";
pobj.actionBody.idempotentSource = "tm_ali"; pobj.actionBody.idempotentSource = "tm_ali";
pobj.actionBody.contactsDingtalk = pobj.actionBody.idempotentId; pobj.actionBody.contactsDingtalk = pobj.actionBody.idempotentId;
...@@ -114,11 +129,6 @@ class UtilsNeedService extends AppServiceBase { ...@@ -114,11 +129,6 @@ class UtilsNeedService extends AppServiceBase {
this.utilsPushSve.business2Channel(pobj, "pushNeedBusiness"); this.utilsPushSve.business2Channel(pobj, "pushNeedBusiness");
} else { } else {
if (["ali.tm","ali.tmd"].includes(pobj.actionBody.type)){ if (["ali.tm","ali.tmd"].includes(pobj.actionBody.type)){
if(pobj.actionBody.phone.length>11){
// 如果是密文手机号,则设置为空
pobj.actionBody.phone = ""
pobj.actionBody.mobile = ""
}
this.utilsPushSve.business2Channel(pobj, "pushNeedTMBusiness"); this.utilsPushSve.business2Channel(pobj, "pushNeedTMBusiness");
}else { }else {
var reqParams = { var reqParams = {
......
...@@ -164,7 +164,6 @@ class UtilsOrderService extends AppServiceBase { ...@@ -164,7 +164,6 @@ class UtilsOrderService extends AppServiceBase {
pobj.actionType = "addOrder"; pobj.actionType = "addOrder";
var reqUrl = this.centerOrderUrl + "action/order/springBoard"; var reqUrl = this.centerOrderUrl + "action/order/springBoard";
// console.log(pobj);
var result = await this.execPostByTimeOut(null, pobj, reqUrl); var result = await this.execPostByTimeOut(null, pobj, reqUrl);
if (result.status != 0) { if (result.status != 0) {
return result; return result;
......
...@@ -184,7 +184,7 @@ class aliyunClient { ...@@ -184,7 +184,7 @@ class aliyunClient {
headers: {}, // set the http request headers headers: {}, // set the http request headers
}); });
console.log(`结束调用阿里云-发起双呼接口。参数reqbody=`,reqbody,'结果=',JSON.stringify(res)) console.log(`结束调用阿里云-发起双呼接口。参数reqbody=`,reqbody,'结果=',JSON.stringify(res))
this.execClientNew.execLogs(`获取可用外呼号码列表成功`, reqbody, "center-channel-aliyunClient-queryAvailabelNumbers", res, null); this.execClientNew.execLogs(`调用阿里云发起双呼接口成功`, reqbody, "center-channel-aliyunClient-startBackToBackCall", res, null);
return system.getResultSuccess(res.Data||res.data); return system.getResultSuccess(res.Data||res.data);
}catch (e){ }catch (e){
console.log(`调用异常:阿里云-发起双呼接口。参数reqbody=`,reqbody,'结果=',JSON.stringify(res),`异常信息=${e.stack}`) console.log(`调用异常:阿里云-发起双呼接口。参数reqbody=`,reqbody,'结果=',JSON.stringify(res),`异常信息=${e.stack}`)
......
...@@ -3,108 +3,87 @@ const sha256 = require('sha256'); ...@@ -3,108 +3,87 @@ const sha256 = require('sha256');
const system = require("../system"); const system = require("../system");
var settings = require("../../config/settings"); var settings = require("../../config/settings");
const AppServiceBase = require("../service/app.base"); const AppServiceBase = require("../service/app.base");
class baiduClient extends AppServiceBase{
constructor() { class baiduClient extends AppServiceBase {
super(); constructor() {
this.pushlogSve = system.getObject("service.common.pushlogSve"); super();
this.execClient = system.getObject("util.execClient"); this.pushlogSve = system.getObject("service.common.pushlogSve");
this.baiduClientParams = settings.baiduClientParams(); this.execClient = system.getObject("util.execClient");
} this.baiduClientParams = settings.baiduClientParams();
//2020 1027 laolan 调用百度网关
async baiduPost( path, actionBody) {
console.log('actionBody++',actionBody)
let domain = this.baiduClientParams.domain;
let url = domain+path;
let version ="bce-auth-v1";
let accessKey = this.baiduClientParams.accessKey;
let secretKey = this.baiduClientParams.secretKey;
let timestamp = new Date().toISOString()
let site = timestamp.lastIndexOf(".");
timestamp = timestamp.substring(0,site)+"Z"
let signedHeaders = "host";
let extime = 1800;
let canonicalHeaders = "host:"+this.baiduClientParams.host;
//中间结果1:规范化请求和前缀字符串
var canonicalRequest = null
var pathParams = path.split("?");
if(pathParams && pathParams.length > 1){
canonicalRequest = "POST" + "\n" + pathParams[0] + "\n" + pathParams[1] + "\n" + canonicalHeaders;
}else{
canonicalRequest = "POST" + "\n" + path + "\n" + "\n" + canonicalHeaders;
}
// let canonicalRequest = "POST" + "\n" + path + "\n" + "\n" + canonicalHeaders;
console.log('canonicalRequest+++++++',canonicalRequest)
//authStringPrefix(前缀字符串,由除sk字段外的签名信息生成)
let authStringPrefix = version+"/"+accessKey+"/"+timestamp+"/"+extime;
//中间结果2:派生签名密钥 signingKey
let signingKey = crypto.createHmac('sha256', secretKey)
.update(authStringPrefix)
.digest('hex');
//中间结果3:签名摘要 signature
let signature = crypto.createHmac('sha256', signingKey)
.update(canonicalRequest)
.digest('hex');
//最终结果:认证字符串 authorization
let authorization = authStringPrefix+"/"+signedHeaders+"/"+signature;
var baiduObj={
authorization:authorization,
data:actionBody
} }
var rtn = await this.execClient.execBaiduPost(baiduObj, url);
if (!rtn || !rtn.stdout) { //2020 1027 laolan 调用百度网关
this.execClientNew.execLogs(`baiduClient-opBaiduClientPost-result:url=${url}`, actionBody, "center-channel-opBaiduClientPost", null, rtn); async baiduPost(path, actionBody) {
return system.getResult(null, rtn); console.log('baiduPost-actionBody++', actionBody)
let domain = this.baiduClientParams.domain;
let url = domain + path;
let version = "bce-auth-v1";
let accessKey = this.baiduClientParams.accessKey;
let secretKey = this.baiduClientParams.secretKey;
let timestamp = new Date().toISOString()
let site = timestamp.lastIndexOf(".");
timestamp = timestamp.substring(0, site) + "Z"
let signedHeaders = "host";
let extime = 1800;
let canonicalHeaders = "host:" + this.baiduClientParams.host;
//中间结果1:规范化请求和前缀字符串
let canonicalRequest = null
let pathParams = path.split("?");
if (pathParams && pathParams.length > 1) {
canonicalRequest = "POST" + "\n" + pathParams[0] + "\n" + pathParams[1] + "\n" + canonicalHeaders;
} else {
canonicalRequest = "POST" + "\n" + path + "\n" + "\n" + canonicalHeaders;
}
// let canonicalRequest = "POST" + "\n" + path + "\n" + "\n" + canonicalHeaders;
console.log('canonicalRequest+++++++', canonicalRequest)
//authStringPrefix(前缀字符串,由除sk字段外的签名信息生成)
let authStringPrefix = version + "/" + accessKey + "/" + timestamp + "/" + extime;
//中间结果2:派生签名密钥 signingKey
let signingKey = crypto.createHmac('sha256', secretKey)
.update(authStringPrefix)
.digest('hex');
//中间结果3:签名摘要 signature
let signature = crypto.createHmac('sha256', signingKey)
.update(canonicalRequest)
.digest('hex');
//最终结果:认证字符串 authorization
let authorization = authStringPrefix + "/" + signedHeaders + "/" + signature;
let baiduObj = {
authorization: authorization,
data: actionBody
}
let rtn = await this.execClient.execBaiduPost(baiduObj, url);
this.execClientNew.execLogs(`baiduClient-baiduPost-result:url=${url}`, baiduObj, "center-channel-opBaiduClientPost", rtn, null);
if (!rtn || !rtn.stdout) {
this.execClientNew.execLogs(`baiduClient-opBaiduClientPost-result:url=${url}`, actionBody, "center-channel-opBaiduClientPost", null, rtn);
return system.getResult(null, rtn);
}
let result = JSON.parse(rtn.stdout);
return result;
} }
var result = JSON.parse(rtn.stdout);
return result;
}
//百度接口 2020-10-27 laolan //百度接口 2020-10-27 laolan
async baiduReqbyget(obj, cbk) { async baiduReqbyget(obj, cbk) {
var path = obj.path; var path = obj.path;
var reqbody = obj.reqbody; var reqbody = obj.reqbody;
try { try {
var res = await this.baiduPost( path, reqbody, { var res = await this.baiduPost(path, reqbody, {
timeout: 10000, // default 3000 ms 修改3000为10000,原因ConfirmIcpIntention BizIds 超过5条会超时 timeout: 10000, // default 3000 ms 修改3000为10000,原因ConfirmIcpIntention BizIds 超过5条会超时
formatAction: true, // default true, format the action to Action formatAction: true, // default true, format the action to Action
formatParams: true, // default true, format the parameter name to first letter upper case formatParams: true, // default true, format the parameter name to first letter upper case
method: 'POST', // set the http method, default is GET method: 'POST', // set the http method, default is GET
headers: { headers: {
host:this.baiduClientParams.host host: this.baiduClientParams.host
}, // set the http request headers }, // set the http request headers
}); });
if(res.status == 0){ return system.getResultSuccess(res);
await this.disposePushResult(obj, res, "baidu->pushBusiness2Baidu->result", ""); } catch (e) {
}else{ await this.disposePushResultFail(obj, e, "badiu->baiduReqbyget->catchError", this.pushlogFailType.FAILLOG);
await this.disposePushResultFail(obj, res, "badiu->pushBusiness2Baidu->catchError", this.pushlogFailType.FAILLOG); return system.getResultFail(-200, "出现异常,error:" + e.stack);
} }
// this.pushlogSve.createDb({
// op: "new-baiduReqbyget",
// content: JSON.stringify(obj),//推送的参数信息
// resultInfo: JSON.stringify(res),
// returnType: '1',
// logLevel: '1',
// opTitle: "new-baiduReqbyget推送百度信息返回成功"
// });
return system.getResultSuccess(res);
} catch (e) {
await this.disposePushResultFail(obj, e, "badiu->pushBusiness2Baidu->catchError", this.pushlogFailType.FAILLOG);
// this.pushlogSve.createFailLogDb({
// appid: obj.appInfo ? obj.appInfo.uapp_id || "" : "",
// appkey: obj.appInfo ? obj.appInfo.uapp_key || "" : "",
// requestId: obj.requestId || "",
// content: JSON.stringify(obj),//推送的参数信息
// resultInfo: "error:" + JSON.stringify(e),
// clientIp: obj.clientIp || "",
// failType: 1,
// opTitle: "new-baiduReqbyget推送百度信息返回异常",
// pushNumber: obj.pushNumber || 1
// });
return system.getResultFail(-200, "出现异常,error:" + e.stack);
} }
}
} }
module.exports = baiduClient; module.exports = baiduClient;
// var task = new baiduClient(); // var task = new baiduClient();
// console.log(task.baiduClientParams,"11111111111111111"); // console.log(task.baiduClientParams,"11111111111111111");
\ No newline at end of file
...@@ -6,12 +6,13 @@ class baiduRegClient { ...@@ -6,12 +6,13 @@ class baiduRegClient {
constructor() { constructor() {
this.pushlogSve = system.getObject("service.common.pushlogSve"); this.pushlogSve = system.getObject("service.common.pushlogSve");
this.execClient = system.getObject("util.execClient"); this.execClient = system.getObject("util.execClient");
this.execClientNew = system.getObject("util.execClientNew");
this.baiduRegClientParams = settings.baiduRegClientParams(); this.baiduRegClientParams = settings.baiduRegClientParams();
} }
//2020 1027 laolan 调用百度网关 //2020 1027 laolan 调用百度网关
async baiduPost( path, actionBody) { async baiduPost( path, actionBody) {
console.log('actionBody++',actionBody) // console.log('actionBody++',actionBody)
let domain = this.baiduRegClientParams.domain; let domain = this.baiduRegClientParams.domain;
let url = domain+path; let url = domain+path;
let version ="bce-auth-v1"; let version ="bce-auth-v1";
...@@ -32,7 +33,7 @@ class baiduRegClient { ...@@ -32,7 +33,7 @@ class baiduRegClient {
canonicalRequest = "POST" + "\n" + path + "\n" + "\n" + canonicalHeaders; canonicalRequest = "POST" + "\n" + path + "\n" + "\n" + canonicalHeaders;
} }
// let canonicalRequest = "POST" + "\n" + path + "\n" + "\n" + canonicalHeaders; // let canonicalRequest = "POST" + "\n" + path + "\n" + "\n" + canonicalHeaders;
console.log('canonicalRequest+++++++',canonicalRequest) // console.log('canonicalRequest+++++++',canonicalRequest)
//authStringPrefix(前缀字符串,由除sk字段外的签名信息生成) //authStringPrefix(前缀字符串,由除sk字段外的签名信息生成)
let authStringPrefix = version+"/"+accessKey+"/"+timestamp+"/"+extime; let authStringPrefix = version+"/"+accessKey+"/"+timestamp+"/"+extime;
//中间结果2:派生签名密钥 signingKey //中间结果2:派生签名密钥 signingKey
...@@ -50,9 +51,10 @@ class baiduRegClient { ...@@ -50,9 +51,10 @@ class baiduRegClient {
data:actionBody data:actionBody
} }
var rtn = await this.execClient.execBaiduPost(baiduObj, url); var rtn = await this.execClient.execBaiduPost(baiduObj, url);
console.log("baiduObj+++++",baiduObj) this.execClientNew.execLogs("api-center-channel-baiduPost:"+url, baiduObj, "center-channel-baiduPost", rtn, null);
console.log("url+++++",url) // console.log("baiduObj+++++",baiduObj)
console.log("rtn+++++",rtn) // console.log("url+++++",url)
// console.log("rtn+++++",rtn)
if (!rtn || !rtn.stdout) { if (!rtn || !rtn.stdout) {
return system.getResult(null, "execPost data is empty"); return system.getResult(null, "execPost data is empty");
} }
......
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