#导入requests库
import requests
# 获取省id
def get_city1():
url= 'https://api.sdb.shuiditech.com/api/sdb/order/get-city-xxx'
params= {'baseProductNo': 'hk_dlabqj'}
r= requests.get(url, params, verify=False).json()
city_code_list= []
for iin range(len(r['data'])):
del r['data'][i]['firstLetter']
del r['data'][i]['level']
city_code_list.append(r['data'][i])
return city_code_list
# 获取市区id
import unittest
class adress(unittest.TestCase):
def test_get_city2(self):
city_code_list= get_city1() # 省一级编码
l = []
for iin range(len(city_code_list)):
url= 'https://api.sdb.shuiditech.com/api/sdb/order/get-city-xxxx'
params= {'baseProductNo': 'hk_dlabqj',
'parentCode': city_code_list[i]['code']}
requests.packages.urllib3.disable_warnings()
r= requests.get(url, params, verify=False).json()
for kin range(len(r['data'])): # 循环市区二级编码
city_code2_list= r['data'][k]
# print(city_code_list[i],city_code2_list)
url1= 'https://api.zelda.shuiditech.com/api/sdb/order/get-city'
params1= {
'baseProductNo': 'hk_dlabqj',
'parentCode': city_code2_list['code']}
requests.packages.urllib3.disable_warnings()
r3= requests.get(url1, params1, verify=False).json()
for min range(len(r3['data'])):
city_code3_list= r3['data'][m]
# print(city_code_list[i]['code'],city_code2_list['code'],city_code3_list['code'])
city_code= city_code_list[i]['code'] + ',' + \
city_code2_list['code'] + ',' + city_code3_list['code']
# print(city_code)
print(city_code_list[i]['name'],city_code2_list['name'],city_code3_list['name'])
from common.Common.Common_CreateIDCardimport getAddrCode
idNumber, adarName= getAddrCode()
birthday= '19900510'
gender= 1
url= "http://sfz.uzuzuz.com/"
params= {
"birthday": birthday,
"region": idNumber,
"num": 100,
"sex": gender,
}
import random
import re
id_card= random.choice(
re.findall(
r'
requests.get(
url,
params).text))
from common.Common.Common_requestimport phone_num
phone= phone_num(1000)
HK_url= 'https://api.zelda.shuiditech.com/api/sdb/order/storage-insurance-order'
headers= {
"content-type": "application/json",
"authorizationv2": "TyHAU6cxprfPzgbvEXhYsZa22oil_o5DyY1_ky9d6IA="}
data= {
"applierUser": {
"applierName": "赵艳",
"applierIdCard": id_card,
"applierMobile": phone,
"applierArea": city_code,
"applierAddress": "那些难吃难兄难弟100",
"applierIdCardInvalid": "20191205",
"applierIdCardInvalidType": "1",
"applierJob": "0003102"
},
"insuredUserList": [{
"relType": "1",
"insuredName": "赵艳",
"insuredIdCard": id_card,
"insuredJob": "0003102",
"insuredHeight": "175",
"insuredWeight": "60",
"insuredIdCardInvalid": "20191205",
"beneficiary": "0",
"insuredIdCardInvalidType": "1"
}],
"attInsuredUserList": [],
"statisticsParam": {
"channel": "default_channel",
"subChannel": "default_subchannel",
"payPlatform": 18,
"toMp": [],
"wxMpType": 0
},
"baseProductNo": "hk_dlabqj",
"payPremium": 3640,
"totalPremium": "3640.00",
"orderPayType": None,
"risks": [{
"name": "HKAZX",
"value": "0"
}, {
"name": "HKDBB",
"value": "0"
}, {
"name": "HKHMX",
"value": "0"
}],
"planNo": "hk_dlabqj_10w",
"protectPeriodTypeValues": "5_0",
"paymentMethod": "2_10_4",
"effectTime": "2019-11-04 00:00:00",
"calculateRiskList": None
}
data['applierUser']['applierArea'] = city_code
import json,time
data1= json.dumps(data)
time.sleep(2)
response= requests.post(
url=HK_url, data=data1, headers=headers, verify=False)
print(response.text)
b = response.json()
# self.assertEqual(b['code'],0,msg=city_code+"地区失败")
# if b['code'] == 99999:
# continue
# for i in range(index,len(r['data']),1):
# sheet.write_string(i,0,city_code_list[i]['name'])
# sheet.write_string(i,1,city_code2_list['name'])
# sheet.write_string(i,2,city_code3_list['name'])
# sheet.write_string(i, 3, response.text)
# sheet.set_column('A:B', 30)
city= city_code_list[i]['name']+','+city_code2_list['name']+','+city_code3_list['name']+','+response.text
filename= 'C:\\Users\\zhaoyan\\Desktop\\sdbao_peoject\\testFile\\黑名单地区测试.txt'
with open(filename,'a') as f:
f.write(city+'\n'+'\n')
if __name__== '__main__':
a= adress()
a.test_get_city2()