同步国家卫健委风险地区数据
This commit is contained in:
60
project/pingchang/apps/AppRiskArea/riskareaCrawler.js
Normal file
60
project/pingchang/apps/AppRiskArea/riskareaCrawler.js
Normal file
@@ -0,0 +1,60 @@
|
||||
import hash from "hash.js"
|
||||
|
||||
const nonceHeader = "123456789abcdefg"
|
||||
let http = {}, riskareaList = []
|
||||
const getSHA256 = key => hash.sha256().update(key).digest("hex")
|
||||
const getData = (timestampHeader) => {
|
||||
return http.post("/app/appepidemicpreventionriskarea/apiForwardPost", {
|
||||
appId: "NcApplication",
|
||||
key: "3C502C97ABDA40D0A60FBEE50FAAD1DA",
|
||||
nonceHeader,
|
||||
paasHeader: "zdww",
|
||||
signatureHeader: getSHA256(`${timestampHeader}23y0ufFl5YxIyGrI8hWRUZmKkvtSjLQA${nonceHeader}${timestampHeader}`).toUpperCase(),
|
||||
timestampHeader
|
||||
}, {
|
||||
withoutToken: true,
|
||||
headers: {
|
||||
Referer: "http://bmfw.www.gov.cn/yqfxdjcx/risk.html",
|
||||
"x-wif-nonce": "QkjjtiLM2dCratiA",
|
||||
"x-wif-paasid": "smt-application",
|
||||
"x-wif-signature": getSHA256(`${timestampHeader}fTN2pfuisxTavbTuYVSsNJHetwq5bJvCQkjjtiLM2dCratiA${timestampHeader}`).toUpperCase(),
|
||||
"x-wif-timestamp": timestampHeader
|
||||
},
|
||||
params: {
|
||||
url: "http://bmfw.www.gov.cn/bjww/interface/interfaceJson"
|
||||
}
|
||||
}).then(res => {
|
||||
if (res?.data?.data) {
|
||||
const {highlist, lowlist, middlelist} = res.data.data
|
||||
return Promise.all([
|
||||
handleData(highlist, 2),
|
||||
handleData(middlelist, 1),
|
||||
// handleData(lowlist, 0)
|
||||
])
|
||||
}
|
||||
})
|
||||
}
|
||||
const transName2Code = area_name => http.post("/app/appepidemicpreventionriskarea/transformationAreaName", null, {
|
||||
params: {area_name}
|
||||
}).then(res => {
|
||||
if (res?.data) {
|
||||
return res.data
|
||||
}
|
||||
})
|
||||
const handleData = (list, riskLevel) => {
|
||||
return Promise.all(list.map(e => {
|
||||
const {province, city, county: district, area_name} = e
|
||||
return transName2Code(area_name).then(areaId => e?.communitys?.map(address => riskareaList.push({
|
||||
province, city, district, address, areaId,
|
||||
level: riskLevel,
|
||||
createUserName: "国家卫健委"
|
||||
})
|
||||
))
|
||||
}))
|
||||
}
|
||||
export const getRiskArea = ins => {
|
||||
http = ins
|
||||
const timestamp = Math.round(new Date().getTime() / 1000).toString()
|
||||
riskareaList = []
|
||||
return getData(timestamp).then(() => http.post("/app/appepidemicpreventionriskarea/batchInsert", riskareaList))
|
||||
}
|
||||
Reference in New Issue
Block a user