python接口脚本_shell脚本和python脚本批量调用post接口

说明:python脚本批量处理加解密四要素,得到的是excel输出文件,无需额外加工处理数据;

shell脚本批量处理加解密数据,得到的数据,需要使用文本编辑器在额外处理输出的数据,最终得到加解密数据;

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) # 获取需要写入数据的行数

workbook = xlwt.Workbook() # 新建一个工作簿

sheet = workbook.add_sheet(sheet_name) # 在工作簿中新建一个表格

for j in range(0, index):

sheet.write(0, j, value[j]) # 像表格中写入数据(对应的行和列)

workbook.save(path) # 保存工作簿

print("xls格式表格写入数据成功!")

#excel数据内容写入

def write_excel_xls_append(path, policylist,nameList,mobileList,idList):

index = len(policylist) # 获取需要写入数据的行数

workbook = xlrd.open_workbook(path) # 打开工作簿

sheets = workbook.sheet_names() # 获取工作簿中的所有表格

worksheet = workbook.sheet_by_name(sheets[0]) # 获取工作簿中所有表格中的的第一个表格

rows_old = worksheet.nrows # 获取表格中已存在的数据的行数

new_workbook = copy(workbook) # 将xlrd对象拷贝转化为xlwt对象

new_worksheet = new_workbook.get_sheet(0) # 获取转化后工作簿中的第一个表格

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格式表格【追加】写入数据成功!")

#调用四要素的解密接口

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 = '四要素解密结果表'

#标题

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值