Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
taxh5
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
data_server
taxh5
Commits
0c7a5ca6
Commit
0c7a5ca6
authored
Mar 24, 2019
by
何娜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
8ff64eac
Pipeline
#4990
passed with stage
in 2 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
265 additions
and
168 deletions
+265
-168
script.js
app/controller/script.js
+1
-0
scripts.js
app/service/scripts.js
+264
-168
No files found.
app/controller/script.js
View file @
0c7a5ca6
...
@@ -32,6 +32,7 @@ class ScriptController extends Controller {
...
@@ -32,6 +32,7 @@ class ScriptController extends Controller {
const
data
=
await
service
.
scripts
.
fetchOneScripts
(
scriptId
);
const
data
=
await
service
.
scripts
.
fetchOneScripts
(
scriptId
);
ctx
.
success
(
data
);
ctx
.
success
(
data
);
}
}
async
fetchParamsInfo
()
{
async
fetchParamsInfo
()
{
const
{
ctx
,
service
}
=
this
;
const
{
ctx
,
service
}
=
this
;
const
{
refresh
=
false
}
=
ctx
.
query
;
const
{
refresh
=
false
}
=
ctx
.
query
;
...
...
app/service/scripts.js
View file @
0c7a5ca6
...
@@ -3,184 +3,281 @@
...
@@ -3,184 +3,281 @@
const
Service
=
require
(
'egg'
).
Service
;
const
Service
=
require
(
'egg'
).
Service
;
class
ScriptsService
extends
Service
{
class
ScriptsService
extends
Service
{
constructor
(
ctx
)
{
constructor
(
ctx
)
{
super
(
ctx
);
super
(
ctx
);
const
{
config
}
=
this
;
const
{
config
}
=
this
;
const
{
scriptsAPI
}
=
config
;
const
{
scriptsAPI
,
taskAPI
}
=
config
;
this
.
scriptsAPI
=
scriptsAPI
;
this
.
scriptsAPI
=
scriptsAPI
;
this
.
baseURL
=
scriptsAPI
.
host
;
this
.
baseURL
=
scriptsAPI
.
host
;
this
.
fetchScriptsUrl
=
scriptsAPI
.
fetchScriptsUrl
;
this
.
fetchScriptsUrl
=
scriptsAPI
.
fetchScriptsUrl
;
this
.
fetchOneScriptUrl
=
scriptsAPI
.
fetchOneScriptUrl
;
this
.
fetchOneScriptUrl
=
scriptsAPI
.
fetchOneScriptUrl
;
this
.
fetchParamsInfoUrl
=
scriptsAPI
.
fetchParamsInfoUrl
;
this
.
fetchParamsInfoUrl
=
scriptsAPI
.
fetchParamsInfoUrl
;
this
.
fetchHelpUrl
=
scriptsAPI
.
fetchHelpUrl
;
this
.
fetchHelpUrl
=
scriptsAPI
.
fetchHelpUrl
;
this
.
redisScriptsKey
=
scriptsAPI
.
redisScriptsKey
;
this
.
redisScriptsKey
=
scriptsAPI
.
redisScriptsKey
;
this
.
redisParamsKey
=
scriptsAPI
.
redisParamsKey
;
this
.
redisParamsKey
=
scriptsAPI
.
redisParamsKey
;
this
.
redisScriptListKey
=
scriptsAPI
.
redisScriptListKey
;
this
.
redisScriptListKey
=
scriptsAPI
.
redisScriptListKey
;
}
this
.
newhost
=
taskAPI
.
newhost
;
this
.
cityConfigUrl
=
taskAPI
.
cityConfigUrl
;
async
fetchScripts
()
{
const
{
baseURL
,
fetchScriptsUrl
,
redisScriptsKey
,
ctx
}
=
this
;
const
data
=
await
this
.
app
.
redis
.
get
(
redisScriptsKey
);
if
(
data
)
{
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Scripts】fetchScriptsFromRedis'
,
'result:'
,
data
,
err
);
await
this
.
app
.
redis
.
del
(
redisScriptsKey
);
}
}
}
const
result
=
await
ctx
.
curl
(
baseURL
+
fetchScriptsUrl
,
{
charset
:
'utf-8'
,
async
fetchScripts
()
{
timeout
:
[
'30s'
,
'30s'
],
const
{
baseURL
,
fetchScriptsUrl
,
redisScriptsKey
,
newhost
,
cityConfigUrl
,
ctx
}
=
this
;
dataType
:
'json'
,
const
data
=
await
this
.
app
.
redis
.
get
(
redisScriptsKey
);
contentType
:
'json'
,
if
(
data
)
{
});
try
{
ctx
.
logger
.
info
(
`【Scripts】fetchScripts,
${
baseURL
+
fetchScriptsUrl
}
`
,
'result:'
,
result
.
data
[
1
]);
return
JSON
.
parse
(
data
);
if
(
result
.
data
&&
result
.
data
.
length
>
0
)
{
}
catch
(
err
)
{
await
this
.
app
.
redis
.
set
(
redisScriptsKey
,
JSON
.
stringify
(
result
.
data
),
'EX'
,
300
);
ctx
.
logger
.
error
(
'【Scripts】fetchScriptsFromRedis'
,
'result:'
,
data
,
err
);
await
this
.
app
.
redis
.
del
(
redisScriptsKey
);
}
}
let
cityLists
=
[];
let
newCityMap
=
new
Map
();
//个税管家
const
gsgjRet
=
await
ctx
.
curl
(
newhost
+
cityConfigUrl
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
contentType
:
'json'
,
});
ctx
.
logger
.
info
(
`【Scripts】fetchScripts,gsgjRet,
${
baseURL
+
fetchScriptsUrl
}
`
,
'result:'
,
gsgjRet
.
data
[
1
]);
if
(
gsgjRet
.
data
&&
gsgjRet
.
data
.
code
===
0
)
{
gsgjRet
.
data
.
data
.
map
(
Prov
=>
{
Prov
.
citys
.
map
(
city
=>
{
let
state
=
city
.
state
===
1
?
'online'
:
'offline'
;
let
obj
=
{
id
:
city
.
id
,
state
:
state
,
hub_name
:
city
.
name
,
hub_id
:
city
.
id
,
province_name
:
Prov
.
provinceName
,
province_id
:
city
.
province
,
};
newCityMap
.
set
(
String
(
city
.
id
),
obj
)
})
});
}
//爬虫
const
result
=
await
ctx
.
curl
(
baseURL
+
fetchScriptsUrl
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
contentType
:
'json'
,
});
ctx
.
logger
.
info
(
`【Scripts】fetchScripts,result,
${
baseURL
+
fetchScriptsUrl
}
`
,
'result:'
,
result
.
data
[
1
]);
if
(
result
.
data
&&
result
.
data
.
length
>
0
)
{
result
.
data
.
map
(
city
=>
{
if
(
city
.
state
===
'offline'
&&
newCityMap
.
get
(
String
(
city
.
id
))
&&
newCityMap
.
get
(
String
(
city
.
id
)).
state
===
'online'
)
{
city
=
newCityMap
.
get
(
String
(
city
.
id
));
city
.
channelType
=
"gsgj"
;
ctx
.
logger
.
info
(
city
.
id
,
city
.
hub_name
)
}
else
{
city
.
channelType
=
"51gs"
;
}
cityLists
.
push
(
city
)
});
await
this
.
app
.
redis
.
set
(
redisScriptsKey
,
JSON
.
stringify
(
cityLists
),
'EX'
,
300
);
}
return
cityLists
;
}
}
return
result
.
data
;
async
fetchOneScripts
(
scriptId
)
{
}
const
{
baseURL
,
fetchOneScriptUrl
,
redisScriptListKey
,
newhost
,
cityConfigUrl
,
ctx
}
=
this
;
const
data
=
await
this
.
app
.
redis
.
get
(
redisScriptListKey
+
scriptId
);
async
fetchOneScripts
(
scriptId
)
{
if
(
data
)
{
const
{
baseURL
,
fetchOneScriptUrl
,
redisScriptListKey
,
ctx
}
=
this
;
try
{
const
data
=
await
this
.
app
.
redis
.
get
(
redisScriptListKey
+
scriptId
);
return
JSON
.
parse
(
data
);
if
(
data
)
{
}
catch
(
err
)
{
try
{
ctx
.
logger
.
error
(
'【Scripts】fetchOneScriptsFromRedis'
,
'result:'
,
data
,
err
);
return
JSON
.
parse
(
data
);
await
this
.
app
.
redis
.
del
(
redisScriptListKey
+
scriptId
);
}
catch
(
err
)
{
}
ctx
.
logger
.
error
(
'【Scripts】fetchOneScriptsFromRedis'
,
'result:'
,
data
,
err
);
}
await
this
.
app
.
redis
.
del
(
redisScriptListKey
+
scriptId
);
let
scriptData
;
}
const
result
=
await
ctx
.
curl
(
baseURL
+
fetchOneScriptUrl
+
'/'
+
scriptId
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
contentType
:
'json'
,
});
if
(
result
.
data
)
{
if
(
result
.
data
.
state
!=
'online'
)
{
//个税管家
// let newCityMap = new Map();
const
gsgjRet
=
await
ctx
.
curl
(
newhost
+
cityConfigUrl
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
contentType
:
'json'
,
});
if
(
gsgjRet
.
data
&&
gsgjRet
.
data
.
code
===
0
)
{
gsgjRet
.
data
.
data
.
map
(
Prov
=>
{
Prov
.
citys
.
map
(
city
=>
{
if
(
city
.
state
===
1
)
{
result
.
data
.
params
=
[];
for
(
let
item
of
queryParam
)
{
let
objs
=
{
login_type_id
:
''
,
name
:
''
,
login_step_detail
:
[{
current_step
:
''
,
login_param
:
[],
next_step
:
''
,
step_name
:
''
,
pre_step
:
''
}],
};
for
(
let
gjParams
of
item
.
loginParam
)
{
let
gjObj
=
{};
if
(
gjParams
.
type
===
'radio'
)
{
gjObj
=
{
name
:
gjParams
.
name
,
note
:
''
,
placeholder
:
gjParams
.
note
,
type
:
'radio'
,
}
}
else
{
gjObj
=
{
name
:
gjParams
.
name
,
note
:
gjParams
.
note
,
placeholder
:
''
,
type
:
gjParams
.
type
,
}
}
objs
.
login_step_detail
.
login_param
.
push
(
gjObj
)
}
result
.
data
.
params
.
push
(
objs
)
}
}
})
});
}
}
else
{
scriptData
=
result
.
data
;
}
await
this
.
app
.
redis
.
set
(
redisScriptListKey
+
scriptId
,
JSON
.
stringify
(
scriptData
),
'EX'
,
60
);
}
return
scriptData
;
}
}
const
result
=
await
ctx
.
curl
(
baseURL
+
fetchOneScriptUrl
+
'/'
+
scriptId
,
{
charset
:
'utf-8'
,
async
fetchParams
(
refresh
=
false
)
{
timeout
:
[
'30s'
,
'30s'
],
const
{
baseURL
,
fetchParamsInfoUrl
,
redisParamsKey
,
ctx
}
=
this
;
dataType
:
'json'
,
if
(
!
refresh
)
{
contentType
:
'json'
,
const
data
=
await
this
.
app
.
redis
.
get
(
redisParamsKey
);
});
if
(
data
)
{
if
(
result
.
data
&&
(
String
(
result
.
data
.
id
)
===
scriptId
))
{
try
{
await
this
.
app
.
redis
.
set
(
redisScriptListKey
+
scriptId
,
JSON
.
stringify
(
result
.
data
),
'EX'
,
60
);
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Scripts】fetchParams'
,
'result:'
,
data
,
err
);
await
this
.
app
.
redis
.
del
(
redisParamsKey
);
}
}
}
const
result
=
await
ctx
.
curl
(
baseURL
+
fetchParamsInfoUrl
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
contentType
:
'json'
,
});
ctx
.
logger
.
info
(
`【Scripts】fetchParams,
${
baseURL
+
fetchParamsInfoUrl
}
`
,
'result:'
,
result
.
data
);
if
(
result
.
data
&&
result
.
data
.
length
>
0
)
{
await
this
.
app
.
redis
.
set
(
redisParamsKey
,
JSON
.
stringify
(
result
.
data
),
'EX'
,
300
);
}
return
result
.
data
;
}
}
return
result
.
data
;
}
async
fetchHelp
(
scriptId
)
{
const
{
baseURL
,
scriptsAPI
:
{
fetchHelpUrl
},
ctx
}
=
this
;
async
fetchParams
(
refresh
=
false
)
{
const
result
=
await
ctx
.
curl
(
baseURL
+
fetchHelpUrl
+
'/'
+
scriptId
,
{
const
{
baseURL
,
fetchParamsInfoUrl
,
redisParamsKey
,
ctx
}
=
this
;
charset
:
'utf-8'
,
if
(
!
refresh
)
{
timeout
:
[
'30s'
,
'30s'
],
const
data
=
await
this
.
app
.
redis
.
get
(
redisParamsKey
);
dataType
:
'json'
,
if
(
data
)
{
contentType
:
'json'
,
try
{
});
return
JSON
.
parse
(
data
);
return
result
.
data
;
}
catch
(
err
)
{
}
ctx
.
logger
.
error
(
'【Scripts】fetchParams'
,
'result:'
,
data
,
err
);
await
this
.
app
.
redis
.
del
(
redisParamsKey
);
async
fetchQueryButton
(
scriptId
)
{
const
{
baseURL
,
scriptsAPI
:
{
fetchQueryButtonUrl
},
ctx
}
=
this
;
const
result
=
await
ctx
.
curl
(
baseURL
+
fetchQueryButtonUrl
+
'/'
+
scriptId
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
contentType
:
'json'
,
});
return
result
.
data
;
}
async
fetchNotice
(
scriptId
)
{
const
{
baseURL
,
scriptsAPI
:
{
fetchNoticeUrl
},
ctx
}
=
this
;
const
result
=
await
ctx
.
curl
(
baseURL
+
fetchNoticeUrl
+
'/'
+
scriptId
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
contentType
:
'json'
,
});
return
result
.
data
;
}
async
fetchHubSeripts
(
hubId
)
{
const
{
baseURL
,
scriptsAPI
:
{
fetchHubSeriptsUrl
},
ctx
}
=
this
;
const
result
=
await
ctx
.
curl
(
baseURL
+
fetchHubSeriptsUrl
+
'/'
+
hubId
+
'/scripts'
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
contentType
:
'json'
,
});
return
result
.
data
;
}
async
fetchCityFormIp
()
{
const
{
ctx
}
=
this
;
const
{
ip
}
=
ctx
.
request
;
ctx
.
logger
.
info
(
ctx
.
request
);
const
url
=
`https://api.map.baidu.com/location/ip?ak=3TBenWOhPygtFFazaR5kSibU&ip=
${
ip
}
`
;
const
result
=
await
ctx
.
curl
(
url
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
contentType
:
'json'
,
});
if
(
result
.
data
.
status
===
0
)
{
return
result
.
data
.
content
.
address_detail
.
city
;
}
}
}
ctx
.
logger
.
error
(
'fetchCityFormIp'
,
url
,
JSON
.
stringify
(
result
.
data
));
return
'北京市'
;
}
}
const
result
=
await
ctx
.
curl
(
baseURL
+
fetchParamsInfoUrl
,
{
async
fetchScriptByCityName
(
name
)
{
charset
:
'utf-8'
,
const
{
baseURL
,
scriptsAPI
:
{
fetchScriptByCityNameUrl
},
ctx
}
=
this
;
timeout
:
[
'30s'
,
'30s'
],
const
result
=
await
ctx
.
curl
(
baseURL
+
fetchScriptByCityNameUrl
+
'?name='
+
encodeURIComponent
(
name
)
+
'&type=query'
,
{
dataType
:
'json'
,
charset
:
'utf-8'
,
contentType
:
'json'
,
timeout
:
[
'30s'
,
'30s'
],
});
dataType
:
'json'
,
ctx
.
logger
.
info
(
`【Scripts】fetchParams,
${
baseURL
+
fetchParamsInfoUrl
}
`
,
'result:'
,
result
.
data
);
contentType
:
'json'
,
if
(
result
.
data
&&
result
.
data
.
length
>
0
)
{
});
await
this
.
app
.
redis
.
set
(
redisParamsKey
,
JSON
.
stringify
(
result
.
data
),
'EX'
,
300
);
ctx
.
logger
.
info
(
`fetchScriptByCityName,
${
baseURL
+
fetchScriptByCityNameUrl
+
'?name='
+
name
}
`
,
'result:'
,
JSON
.
stringify
(
result
.
data
));
return
result
.
data
;
}
}
return
result
.
data
;
}
async
fetchScriptIdByIp
()
{
const
city
=
await
this
.
fetchCityFormIp
();
async
fetchHelp
(
scriptId
)
{
const
scriptList
=
await
this
.
fetchScriptByCityName
(
city
);
const
{
baseURL
,
scriptsAPI
:
{
fetchHelpUrl
},
ctx
}
=
this
;
return
scriptList
;
const
result
=
await
ctx
.
curl
(
baseURL
+
fetchHelpUrl
+
'/'
+
scriptId
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
contentType
:
'json'
,
});
return
result
.
data
;
}
async
fetchQueryButton
(
scriptId
)
{
const
{
baseURL
,
scriptsAPI
:
{
fetchQueryButtonUrl
},
ctx
}
=
this
;
const
result
=
await
ctx
.
curl
(
baseURL
+
fetchQueryButtonUrl
+
'/'
+
scriptId
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
contentType
:
'json'
,
});
return
result
.
data
;
}
async
fetchNotice
(
scriptId
)
{
const
{
baseURL
,
scriptsAPI
:
{
fetchNoticeUrl
},
ctx
}
=
this
;
const
result
=
await
ctx
.
curl
(
baseURL
+
fetchNoticeUrl
+
'/'
+
scriptId
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
contentType
:
'json'
,
});
return
result
.
data
;
}
async
fetchHubSeripts
(
hubId
)
{
const
{
baseURL
,
scriptsAPI
:
{
fetchHubSeriptsUrl
},
ctx
}
=
this
;
const
result
=
await
ctx
.
curl
(
baseURL
+
fetchHubSeriptsUrl
+
'/'
+
hubId
+
'/scripts'
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
contentType
:
'json'
,
});
return
result
.
data
;
}
async
fetchCityFormIp
()
{
const
{
ctx
}
=
this
;
const
{
ip
}
=
ctx
.
request
;
ctx
.
logger
.
info
(
ctx
.
request
);
const
url
=
`https://api.map.baidu.com/location/ip?ak=3TBenWOhPygtFFazaR5kSibU&ip=
${
ip
}
`
;
const
result
=
await
ctx
.
curl
(
url
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
contentType
:
'json'
,
});
if
(
result
.
data
.
status
===
0
)
{
return
result
.
data
.
content
.
address_detail
.
city
;
}
}
ctx
.
logger
.
error
(
'fetchCityFormIp'
,
url
,
JSON
.
stringify
(
result
.
data
));
return
'北京市'
;
async
fetchScriptName
(
scriptId
)
{
}
try
{
const
city
=
await
this
.
fetchOneScripts
(
scriptId
);
async
fetchScriptByCityName
(
name
)
{
return
city
.
name
||
'未知'
;
const
{
baseURL
,
scriptsAPI
:
{
fetchScriptByCityNameUrl
},
ctx
}
=
this
;
}
catch
(
err
)
{
const
result
=
await
ctx
.
curl
(
baseURL
+
fetchScriptByCityNameUrl
+
'?name='
+
encodeURIComponent
(
name
)
+
'&type=query'
,
{
return
'未知'
;
charset
:
'utf-8'
,
}
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
contentType
:
'json'
,
});
ctx
.
logger
.
info
(
`fetchScriptByCityName,
${
baseURL
+
fetchScriptByCityNameUrl
+
'?name='
+
name
}
`
,
'result:'
,
JSON
.
stringify
(
result
.
data
));
return
result
.
data
;
}
async
fetchScriptIdByIp
()
{
const
city
=
await
this
.
fetchCityFormIp
();
const
scriptList
=
await
this
.
fetchScriptByCityName
(
city
);
return
scriptList
;
}
async
fetchScriptName
(
scriptId
)
{
try
{
const
city
=
await
this
.
fetchOneScripts
(
scriptId
);
return
city
.
name
||
'未知'
;
}
catch
(
err
)
{
return
'未知'
;
}
}
}
}
}
module
.
exports
=
ScriptsService
;
module
.
exports
=
ScriptsService
;
\ 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