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
d62c2c7c
Commit
d62c2c7c
authored
Nov 12, 2020
by
linboxuan
Browse files
Options
Browse Files
Download
Plain Diff
lin pannog
parents
951c229a
024a9eff
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
1 deletions
+36
-1
center-channel/app/base/utils/execClient.js
+36
-1
No files found.
center-channel/app/base/utils/execClient.js
View file @
d62c2c7c
...
@@ -3,6 +3,7 @@ const util = require('util');
...
@@ -3,6 +3,7 @@ const util = require('util');
const
exec
=
util
.
promisify
(
require
(
'child_process'
).
exec
);
const
exec
=
util
.
promisify
(
require
(
'child_process'
).
exec
);
const
uuidv4
=
require
(
'uuid/v4'
);
const
uuidv4
=
require
(
'uuid/v4'
);
var
settings
=
require
(
"../../config/settings"
);
var
settings
=
require
(
"../../config/settings"
);
const
axios
=
require
(
'axios'
);
class
ExecClient
{
class
ExecClient
{
constructor
()
{
constructor
()
{
this
.
cmdPostPattern
=
"curl --user admines:adminGSBes. -k -H 'Content-type: application/json' -d '{data}' {url}"
;
this
.
cmdPostPattern
=
"curl --user admines:adminGSBes. -k -H 'Content-type: application/json' -d '{data}' {url}"
;
...
@@ -23,7 +24,10 @@ class ExecClient {
...
@@ -23,7 +24,10 @@ class ExecClient {
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
);
var
options
=
{
maxBuffer
:
1024
*
1024
*
20
};
const
{
stdout
,
stderr
}
=
await
exec
(
cmd
,
options
);
return
{
stdout
,
stderr
};
return
{
stdout
,
stderr
};
}
}
...
@@ -62,6 +66,13 @@ class ExecClient {
...
@@ -62,6 +66,13 @@ class ExecClient {
return
cmd
;
return
cmd
;
}
}
async
execPost
(
subData
,
url
)
{
async
execPost
(
subData
,
url
)
{
if
(
settings
.
env
==
'dev'
){
const
rs
=
await
axios
.
post
(
url
,
subData
);
const
ret
=
{
stdout
:
JSON
.
stringify
(
rs
.
data
)
}
return
ret
;
}
let
cmd
=
this
.
FetchPostCmd
(
subData
,
url
);
let
cmd
=
this
.
FetchPostCmd
(
subData
,
url
);
var
result
=
await
this
.
exec
(
cmd
);
var
result
=
await
this
.
exec
(
cmd
);
return
result
;
return
result
;
...
@@ -77,6 +88,15 @@ class ExecClient {
...
@@ -77,6 +88,15 @@ class ExecClient {
return
result
;
return
result
;
}
}
async
execPushDataPost
(
subData
,
url
,
token
,
requestId
)
{
async
execPushDataPost
(
subData
,
url
,
token
,
requestId
)
{
if
(
settings
.
env
==
'dev'
){
axios
.
defaults
.
headers
[
'token'
]
=
token
;
// axios.defaults.headers['request-id'] = requestId;
const
rs
=
await
axios
.
post
(
url
,
subData
);
const
ret
=
{
stdout
:
JSON
.
stringify
(
rs
.
data
)
}
return
ret
;
}
let
cmd
=
this
.
FetchPushDataPostCmd
(
subData
,
url
,
token
,
requestId
);
let
cmd
=
this
.
FetchPushDataPostCmd
(
subData
,
url
,
token
,
requestId
);
var
options
=
{
var
options
=
{
maxBuffer
:
1024
*
1024
*
20
maxBuffer
:
1024
*
1024
*
20
...
@@ -127,6 +147,21 @@ class ExecClient {
...
@@ -127,6 +147,21 @@ class ExecClient {
async
exec360GetToken
(
url
){
async
exec360GetToken
(
url
){
const
qs
=
require
(
'qs'
)
const
qs
=
require
(
'qs'
)
let
obj
=
{
"scope"
:
"smart_business"
,
"grant_type"
:
"client_credentials"
}
let
obj
=
{
"scope"
:
"smart_business"
,
"grant_type"
:
"client_credentials"
}
if
(
settings
.
env
==
'dev'
){
const
rs
=
await
axios
({
method
:
'post'
,
url
:
url
,
data
:
qs
.
stringify
(
obj
),
auth
:
{
username
:
"gongsibao"
,
password
:
"qPa4PsVsxbQ847i5pOKSmfPKrzRoNKqx"
}
})
const
ret
=
{
stdout
:
JSON
.
stringify
(
rs
.
data
)
}
return
ret
;
}
let
cmd
=
this
.
Fetch360PostCmd
(
qs
.
stringify
(
obj
),
url
);
let
cmd
=
this
.
Fetch360PostCmd
(
qs
.
stringify
(
obj
),
url
);
console
.
log
(
cmd
);
console
.
log
(
cmd
);
var
result
=
await
this
.
exec
(
cmd
);
var
result
=
await
this
.
exec
(
cmd
);
...
...
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