调接口新增车辆

Posted yanpan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了调接口新增车辆相关的知识,希望对你有一定的参考价值。

# coding = utf-8
import json
import os
import time

import requests

from getExcelData import get_excel_data, root_dir


def login(host, account, password):
headers = {"Content-Type": "application/json;charset=UTF-8"}
url = host + "/travel/admin/authenticate/login"
data = {"account": account, "userPwd": password}
response = requests.post(url=url, headers=headers, data=json.dumps(data))
cookie = response.headers[‘Set-Cookie‘].split(";")[0]
return cookie


def addCar(host, cookie, carModelId, carNo, carVin, colorId, seatsNumber, fileNumber, engineNumber):
url = host + "/travel/admin/car/add"
headers = {"Cookie": cookie, "Content-Type": "application/json;charset=UTF-8"}
data = {
"basic": {
"brandId": "26",
"carModelId": carModelId,
"carNo": carNo,
"companyId": 1,
"useNature": 1,
"carVin": carVin,
"ownerName": "张三",
"ownerAddress": "中盛大厦",
"registrationDate": "2019-02-10",
"certificateDate": "2019-02-01",
"annualInspection": "1",
"annualInspectionDueDate": "2021-02-18",
"carStatus": 10,
"colorId": colorId,
"namePlateTime": "",
"seatsNumber": seatsNumber,
"fileNumber": fileNumber,
"engineNumber": engineNumber,
"certificateNumber": "",
"operationCompanyId": 1,
"carHardware": 1,
"carPurchase": 0,
"drivingLicense": [],
"drivingLicenseUrl": ""
},
"hardwares": [{
"supplier": "全球鹰",
"terminalNumber": engineNumber,
"installationPosition": "11",
# "bluetoothNumber": engineNumber,
"simNumber": str(time.time()).split(".")[1],
"simSupplier": 1,
"simOpenDate": "2020-02-01",
"simExpireDate": "2022-02-28",
"simSetmealStandard": "111",
"paymentCycle": 6
}],
"purchase": None
}
if carModelId == 99:
data["basic"]["carSource"] = 2
else:
data["basic"]["carSource"] = 1
response = requests.post(url=url, headers=headers, data=json.dumps(data))
print(response.text)


if __name__ == "__main__":
account = "13649550277"
password = "admin123!@#$"
cookie = login(account, password)

carModelIdDict = {"EX3": 99, "K17A": 100, "K17AS": 101}
colourDict = {"白色": 128, "红色": 129, "金色": 130, "蓝色": 131}

excelPath = os.path.join(root_dir, "车辆列表.xlsx")
excelInfo = get_excel_data(excelPath)
rows = excelInfo.getRowsClosNum()

for i in range(2, rows[0] + 1): # rows[0] + 1
carInfo = excelInfo.getRowValues(i)
carModelId = carModelIdDict[carInfo[2]]
carNo = carInfo[1]
colorId = colourDict[carInfo[3]]
seatsNumber = carInfo[4]
carVin = carInfo[17]
fileNumber = str(time.time()).replace(".", "")
engineNumber = carInfo[18]
addCar(cookie, carModelId, carNo, carVin, colorId, seatsNumber, fileNumber, engineNumber)
print("车牌号%s新增成功" % carNo)
time.sleep(0.5)









以上是关于调接口新增车辆的主要内容,如果未能解决你的问题,请参考以下文章

AI人脸检测智能分析网关新增车辆检测/车牌识别,支持车辆违停告警

Flask 编写http接口api及接口自动化测试

java中封装,继承,多态,接口学习总结

汽车obd接口定义是啥

后台接口文档示例

汽车obd接口针脚详解