Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
d162153b
Commit
d162153b
authored
Mar 14, 2022
by
宋毅
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
百度加日志
parent
045a1ff9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
19 deletions
+23
-19
center-channel/app/base/utils/baiduClient.js
+23
-19
No files found.
center-channel/app/base/utils/baiduClient.js
View file @
d162153b
...
@@ -3,7 +3,8 @@ const sha256 = require('sha256');
...
@@ -3,7 +3,8 @@ 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
{
class
baiduClient
extends
AppServiceBase
{
constructor
()
{
constructor
()
{
super
();
super
();
this
.
pushlogSve
=
system
.
getObject
(
"service.common.pushlogSve"
);
this
.
pushlogSve
=
system
.
getObject
(
"service.common.pushlogSve"
);
...
@@ -12,31 +13,31 @@ class baiduClient extends AppServiceBase{
...
@@ -12,31 +13,31 @@ class baiduClient extends AppServiceBase{
}
}
//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
.
baiduClientParams
.
domain
;
let
domain
=
this
.
baiduClientParams
.
domain
;
let
url
=
domain
+
path
;
let
url
=
domain
+
path
;
let
version
=
"bce-auth-v1"
;
let
version
=
"bce-auth-v1"
;
let
accessKey
=
this
.
baiduClientParams
.
accessKey
;
let
accessKey
=
this
.
baiduClientParams
.
accessKey
;
let
secretKey
=
this
.
baiduClientParams
.
secretKey
;
let
secretKey
=
this
.
baiduClientParams
.
secretKey
;
let
timestamp
=
new
Date
().
toISOString
()
let
timestamp
=
new
Date
().
toISOString
()
let
site
=
timestamp
.
lastIndexOf
(
"."
);
let
site
=
timestamp
.
lastIndexOf
(
"."
);
timestamp
=
timestamp
.
substring
(
0
,
site
)
+
"Z"
timestamp
=
timestamp
.
substring
(
0
,
site
)
+
"Z"
let
signedHeaders
=
"host"
;
let
signedHeaders
=
"host"
;
let
extime
=
1800
;
let
extime
=
1800
;
let
canonicalHeaders
=
"host:"
+
this
.
baiduClientParams
.
host
;
let
canonicalHeaders
=
"host:"
+
this
.
baiduClientParams
.
host
;
//中间结果1:规范化请求和前缀字符串
//中间结果1:规范化请求和前缀字符串
var
canonicalRequest
=
null
var
canonicalRequest
=
null
var
pathParams
=
path
.
split
(
"?"
);
var
pathParams
=
path
.
split
(
"?"
);
if
(
pathParams
&&
pathParams
.
length
>
1
)
{
if
(
pathParams
&&
pathParams
.
length
>
1
)
{
canonicalRequest
=
"POST"
+
"
\
n"
+
pathParams
[
0
]
+
"
\
n"
+
pathParams
[
1
]
+
"
\
n"
+
canonicalHeaders
;
canonicalRequest
=
"POST"
+
"
\
n"
+
pathParams
[
0
]
+
"
\
n"
+
pathParams
[
1
]
+
"
\
n"
+
canonicalHeaders
;
}
else
{
}
else
{
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
let
signingKey
=
crypto
.
createHmac
(
'sha256'
,
secretKey
)
let
signingKey
=
crypto
.
createHmac
(
'sha256'
,
secretKey
)
.
update
(
authStringPrefix
)
.
update
(
authStringPrefix
)
...
@@ -46,12 +47,13 @@ class baiduClient extends AppServiceBase{
...
@@ -46,12 +47,13 @@ class baiduClient extends AppServiceBase{
.
update
(
canonicalRequest
)
.
update
(
canonicalRequest
)
.
digest
(
'hex'
);
.
digest
(
'hex'
);
//最终结果:认证字符串 authorization
//最终结果:认证字符串 authorization
let
authorization
=
authStringPrefix
+
"/"
+
signedHeaders
+
"/"
+
signature
;
let
authorization
=
authStringPrefix
+
"/"
+
signedHeaders
+
"/"
+
signature
;
var
baiduObj
=
{
var
baiduObj
=
{
authorization
:
authorization
,
authorization
:
authorization
,
data
:
actionBody
data
:
actionBody
}
}
var
rtn
=
await
this
.
execClient
.
execBaiduPost
(
baiduObj
,
url
);
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
)
{
if
(
!
rtn
||
!
rtn
.
stdout
)
{
this
.
execClientNew
.
execLogs
(
`baiduClient-opBaiduClientPost-result:url=
${
url
}
`
,
actionBody
,
"center-channel-opBaiduClientPost"
,
null
,
rtn
);
this
.
execClientNew
.
execLogs
(
`baiduClient-opBaiduClientPost-result:url=
${
url
}
`
,
actionBody
,
"center-channel-opBaiduClientPost"
,
null
,
rtn
);
return
system
.
getResult
(
null
,
rtn
);
return
system
.
getResult
(
null
,
rtn
);
...
@@ -65,18 +67,18 @@ class baiduClient extends AppServiceBase{
...
@@ -65,18 +67,18 @@ class baiduClient extends AppServiceBase{
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
)
{
if
(
res
.
status
==
0
)
{
await
this
.
disposePushResult
(
obj
,
res
,
"baidu->pushBusiness2Baidu->result"
,
""
);
await
this
.
disposePushResult
(
obj
,
res
,
"baidu->pushBusiness2Baidu->result"
,
""
);
}
else
{
}
else
{
await
this
.
disposePushResultFail
(
obj
,
res
,
"badiu->pushBusiness2Baidu->catchError"
,
this
.
pushlogFailType
.
FAILLOG
);
await
this
.
disposePushResultFail
(
obj
,
res
,
"badiu->pushBusiness2Baidu->catchError"
,
this
.
pushlogFailType
.
FAILLOG
);
}
}
// this.pushlogSve.createDb({
// this.pushlogSve.createDb({
...
@@ -105,6 +107,7 @@ class baiduClient extends AppServiceBase{
...
@@ -105,6 +107,7 @@ class baiduClient extends AppServiceBase{
}
}
}
}
}
}
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment