說明:python腳本批量處理加解密四要素街图,得到的是excel輸出文件碌补,無需額外加工處理數(shù)據(jù);
shell腳本批量處理加解密數(shù)據(jù),得到的數(shù)據(jù)蚁阳,需要使用文本編輯器在額外處理輸出的數(shù)據(jù),最終得到加解密數(shù)據(jù)沫浆;
python腳本批量處理加解密四要素信息警绩,使用方法:
0:使用DB工具,導出需要加解密的字段晓锻,為json文件格式歌焦,如four.json;
1:在mac主機里面安裝python3和pip砚哆;
2:使用pip來安裝模塊xlrd独撇、xlwt、json、requests纷铣、xlutils卵史;
3:解壓下方的zip壓縮文件,進入目錄搜立,并直接在mac終端使用python3命令運行腳本:python3 fourElementDecode.py以躯;
# coding=UTF-8
import subprocess
import json
import requests
import xlrd
import xlwt
from xlutils.copy import copy
#excel標題寫入
def write_excel_xls(path, sheet_name, value):
index = len(value) # 獲取需要寫入數(shù)據(jù)的行數(shù)
workbook = xlwt.Workbook() # 新建一個工作簿
sheet = workbook.add_sheet(sheet_name) # 在工作簿中新建一個表格
for j in range(0, index):
sheet.write(0, j, value[j]) # 像表格中寫入數(shù)據(jù)(對應的行和列)
workbook.save(path) # 保存工作簿
print("xls格式表格寫入數(shù)據(jù)成功!")
#excel數(shù)據(jù)內(nèi)容寫入
def write_excel_xls_append(path, policylist,nameList,mobileList,idList):
index = len(policylist) # 獲取需要寫入數(shù)據(jù)的行數(shù)
workbook = xlrd.open_workbook(path) # 打開工作簿
sheets = workbook.sheet_names() # 獲取工作簿中的所有表格
worksheet = workbook.sheet_by_name(sheets[0]) # 獲取工作簿中所有表格中的的第一個表格
rows_old = worksheet.nrows # 獲取表格中已存在的數(shù)據(jù)的行數(shù)
new_workbook = copy(workbook) # 將xlrd對象拷貝轉(zhuǎn)化為xlwt對象
new_worksheet = new_workbook.get_sheet(0) # 獲取轉(zhuǎn)化后工作簿中的第一個表格
for i in range(0, index):
new_worksheet.write(i+rows_old, 0, policylist[i])
new_worksheet.write(i+rows_old, 1, nameList[i])
new_worksheet.write(i+rows_old, 2, mobileList[i])
new_worksheet.write(i+rows_old, 3, idList[i])
new_workbook.save(path) # 保存工作簿
print("xls格式表格【追加】寫入數(shù)據(jù)成功啄踊!")
#調(diào)用四要素的解密接口
headers= {"Content-Type": "application/json; charset=UTF-8"}
url = "http://ip:port/path"
policylist=[]
nameList=[]
mobileList=[]
idList=[]
with open("/Users/apple/Downloads/output/20200601_20200607/20200601_20200607_four.json",encoding='utf-8') as f:
for single in json.loads(f.read())['result']:
policylist.append(single['policy_no'])
nameDec = {'key': single['full_name_encrypt'], 'method': 'Name', 'func': 'dec'}
nameDecResult = requests.post(url,str(nameDec).encode("utf-8"),headers=headers)
nameList.append(json.loads(nameDecResult.text)['value'])
mobileDec = {'key': single['mobile_encrypt'], 'method': 'Mobile', 'func': 'dec'}
mobileDecResult = requests.post(url,str(mobileDec).encode("utf-8"),headers=headers)
mobileList.append(json.loads(mobileDecResult.text)['value'])
idDec = {'key': single['govt_id_encrypt'], 'method': 'GOVTID', 'func': 'dec'}
idDecResult = requests.post(url,str(idDec).encode("utf-8"),headers=headers)
idList.append(json.loads(idDecResult.text)['value'])
book_name_xls = '20200601_20200607_four.xls'
sheet_name_xls = '四要素解密結(jié)果表'
#標題
value_title = ["保單","姓名","手機號碼","身份證號碼"]
write_excel_xls(book_name_xls, sheet_name_xls, value_title)
write_excel_xls_append(book_name_xls, policylist,nameList,mobileList,idList)
shell腳本批量處理加解密四要素信息忧设,使用方法:
0:使用DB工具,導出需要加解密的字段颠通,為txt文件格式址晕,可見zip壓縮文件里面的nameEncodeData.txt;
1:解壓下方的zip壓縮文件顿锰,進入目錄谨垃,并直接在mac終端運行腳本:./nameDecode.sh;
#!/bin/bash
count=0
for line in $(cat nameEncodeData.txt)
do
#echo ${line}
namejson="{\"key\":\"${line}\",\"method\":\"Name\",\"func\":\"dec\"}"
#mobilejson="{\"key\":\"${line}\",\"method\":\"Mobile\",\"func\":\"dec\"}"
#idjson="{\"key\":\"${line}\",\"method\":\"GOVTID\",\"func\":\"dec\"}"
curl -k -H "Content-Type:application/json;charset=utf-8" http://ip:port/path -X POST -d "${namejson}" >> nameOutput.txt
echo >> nameOutput.txt
done