Commit d162153b by 宋毅

百度加日志

parent 045a1ff9
......@@ -3,7 +3,8 @@ const sha256 = require('sha256');
const system = require("../system");
var settings = require("../../config/settings");
const AppServiceBase = require("../service/app.base");
class baiduClient extends AppServiceBase{
class baiduClient extends AppServiceBase {
constructor() {
super();
this.pushlogSve = system.getObject("service.common.pushlogSve");
......@@ -12,31 +13,31 @@ class baiduClient extends AppServiceBase{
}
//2020 1027 laolan 调用百度网关
async baiduPost( path, actionBody) {
console.log('actionBody++',actionBody)
async baiduPost(path, actionBody) {
console.log('actionBody++', actionBody)
let domain = this.baiduClientParams.domain;
let url = domain+path;
let version ="bce-auth-v1";
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"
timestamp = timestamp.substring(0, site) + "Z"
let signedHeaders = "host";
let extime = 1800;
let canonicalHeaders = "host:"+this.baiduClientParams.host;
let canonicalHeaders = "host:" + this.baiduClientParams.host;
//中间结果1:规范化请求和前缀字符串
var canonicalRequest = null
var pathParams = path.split("?");
if(pathParams && pathParams.length > 1){
if (pathParams && pathParams.length > 1) {
canonicalRequest = "POST" + "\n" + pathParams[0] + "\n" + pathParams[1] + "\n" + canonicalHeaders;
}else{
} else {
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字段外的签名信息生成)
let authStringPrefix = version+"/"+accessKey+"/"+timestamp+"/"+extime;
let authStringPrefix = version + "/" + accessKey + "/" + timestamp + "/" + extime;
//中间结果2:派生签名密钥 signingKey
let signingKey = crypto.createHmac('sha256', secretKey)
.update(authStringPrefix)
......@@ -46,12 +47,13 @@ class baiduClient extends AppServiceBase{
.update(canonicalRequest)
.digest('hex');
//最终结果:认证字符串 authorization
let authorization = authStringPrefix+"/"+signedHeaders+"/"+signature;
var baiduObj={
authorization:authorization,
data:actionBody
let authorization = authStringPrefix + "/" + signedHeaders + "/" + signature;
var baiduObj = {
authorization: authorization,
data: actionBody
}
var 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);
......@@ -65,18 +67,18 @@ class baiduClient extends AppServiceBase{
var path = obj.path;
var reqbody = obj.reqbody;
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条会超时
formatAction: true, // default true, format the action to Action
formatParams: true, // default true, format the parameter name to first letter upper case
method: 'POST', // set the http method, default is GET
headers: {
host:this.baiduClientParams.host
host: this.baiduClientParams.host
}, // set the http request headers
});
if(res.status == 0){
if (res.status == 0) {
await this.disposePushResult(obj, res, "baidu->pushBusiness2Baidu->result", "");
}else{
} else {
await this.disposePushResultFail(obj, res, "badiu->pushBusiness2Baidu->catchError", this.pushlogFailType.FAILLOG);
}
// this.pushlogSve.createDb({
......@@ -105,6 +107,7 @@ class baiduClient extends AppServiceBase{
}
}
}
module.exports = baiduClient;
// var task = new baiduClient();
// console.log(task.baiduClientParams,"11111111111111111");
\ No newline at end of file
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