问题:(1)接口返回值加密
- f = d.a.enc.Utf8.parse("jo8j9wGw%6HbxfFn")
-
- m = d.a.enc.Utf8.parse("0123456789ABCDEF")
- var CryptoJS = require('C:/Data/npm/node_modules/crypto-js')
-
- function getDecryptedData(t) {
- var m = CryptoJS.enc.Utf8.parse("0123456789ABCDEF"),
- f = CryptoJS.enc.Utf8.parse("jo8j9wGw%6HbxfFn"),
- e = CryptoJS.enc.Hex.parse(t),
- n = CryptoJS.enc.Base64.stringify(e),
- a = CryptoJS.AES.decrypt(n, f, {
- iv: m,
- mode: CryptoJS.mode.CBC,
- padding: CryptoJS.pad.Pkcs7
- }),
- r = a.toString(CryptoJS.enc.Utf8);
- return r.toString()
- }
-
- var fs = require('fs')
-
- fs.readFile('./jzsc_mohurd.txt','utf8',function(err,dataStr) {
- if(err){
- return console.log("读取文件失败!"+err.message)
- }
-
- console.log(getDecryptedData(dataStr))
- })
- def get_data(projectType, region_id, page):
- '''
- 获取接口数据
- @return:
- '''
-
- url = 'https://jzsc.mohurd.gov.cn/api/webApi/dataservice/query/project/list?projectType={}&projectRegionId={}&pg={}&pgsz=15'.format(
- projectType, region_id, page)
- headers = {
- 'Host': 'jzsc.mohurd.gov.cn',
- 'Referer': 'http://jzsc.mohurd.gov.cn/data/project',
- 'User-Agent': getUserAgent()
- }
- res = requests.get(url, headers=headers)
-
- logger.debug('接口:{}'.format(url))
- logger.debug('获取的密文为:{}'.format(res.text))
-
- with open('./jzsc_mohurd.txt', 'w', encoding='utf-8') as f:
- f.write(res.text)
- decrypt_data()
-
- def decrypt_data():
- """
- 解密接口数据
- @param ciphertext:
- @return:
- """
- logger.debug('数据解密...')
- cmd = "node jzsc_mohurd.js"
-
- with os.popen(cmd) as fp:
- bf = fp._stream.buffer.read()
- try:
- plaintext = bf.decode().strip()
- except UnicodeDecodeError:
- plaintext = bf.decode('gbk').strip()
- logger.debug('解密后的数据为:{}'.format(plaintext))
- return plaintext