Commit 24eacb20 authored by liyuanhong's avatar liyuanhong

首次提交

parents
Pipeline #364 canceled with stages
# coding: utf-8
import hashlib
import json
import time
import pymysql
import requests
'''
流程:
1、在boss系统上导入车机
2、在数据库里面添加云镜 appserver里的 t_app_mirror 表
2、使用脚本注册新用户,并添加车辆
3、绑定云镜
4、开始压力测试
'''
class BindMirrorTools():
def __init__(self):
self.SSL_VERIFY = True
self.dbhost = "114.116.196.12"
self.dbuser = "root"
self.dbpassword = "root"
self.database = "appserver"
self.dbport = 3308
self.sn = 123456 # 车机SN码
self.pad = 0 # 车牌号累加起始
self.mobile = 181000000001 # 将要累加的手机号 (累加方式)
self.carId = 202108286000 # 将要累加得车机 (累加方式)
self.imei = 863000000000000 # 将要累加的云镜 (累加方式)
self.count = 99 # 累加次数
def setMobile(self,data):
self.mobile = data
def setCarId(self,data):
self.carId = data
def setImei(self,data):
self.imei = data
def setCount(self,data):
self.count = data
##############################################
# 获取短信验证码
##############################################
def getMsgCode(self,mobile):
url = "http://api-test.vandyo.com/user/authorize/authcode/get"
ts = int(time.time())
headers = {"Accept-Encoding": "gzip", "Content-Type": "application/json; charset=UTF-8"}
params = {}
params["reqtype"] = 1
params["ts"] = ts
params["mobile"] = mobile
cs = self.getSignature(params)
params["cs"] = cs
resObj = requests.get(url, headers=headers, params=params, verify=self.SSL_VERIFY)
# print("\n请求地址:" + url)
# print("-------------------------返回结果:-------------------------")
# print(resObj.text)
##############################################
# 使用短信验证码登录
##############################################
def loginByMsgCode(self,mobile,msgCode):
url = "http://api-test.vandyo.com/user/authorize/authcode/login"
ts = int(time.time())
headers = {"Accept-Encoding": "gzip", "Content-Type": "application/json; charset=UTF-8"}
params = {}
params["ts"] = ts
postData = {}
postData["mobile"] = mobile
postData["verify"] = msgCode
postData["inviteCode"] = ""
postData["type"] = 1
resObj = requests.post(url, headers=headers, params=params, data=json.dumps(postData), verify=self.SSL_VERIFY)
# print("\n请求地址:" + url)
# print("-------------------------返回结果:-------------------------")
# print(resObj.text)
resObj = json.loads(resObj.text)
uData = {}
uData["sid"] = resObj["result"]["sid"]
uData["uid"] = resObj["result"]["uid"]
return uData
#################################################
# 获取一个Md5的字符串
#################################################
def getMd5String(self,data):
m = hashlib.md5()
b = data.encode(encoding='utf-8')
m.update(b)
str_md5 = m.hexdigest()
return str_md5
#################################################
# 获取签名,传入一个map,
# (需要对传入的参数,按照key的升序排列)
#################################################
def getSignature(self,data,postData={}):
sMd5 = ""
if len(postData) == 0:
keys = sorted(data.keys())
s = ""
for key in keys:
s = s + key + "[" + str(data[key]) + "];"
sMd5 = self.getMd5String(s)
else:
data["Data"] = postData
keys = sorted(data.keys())
s = ""
for key in keys:
s = s + key + "[" + str(data[key]) + "];"
sMd5 = self.getMd5String(s)
return sMd5
#################################################
# 连接数据库
#################################################
def dbConnect(self):
self.db = pymysql.connect(host=self.dbhost, user=self.dbuser, password=self.dbpassword, database=self.database, port=self.dbport)
#################################################
# 关闭数据库
#################################################
def dbClose(self):
self.db.close()
#################################################
# 查询最新的验证码
#################################################
def getMsgCodeSql(self,mobile):
self.db = pymysql.connect(host=self.dbhost, user=self.dbuser, password=self.dbpassword, database=self.database,
port=self.dbport)
sql = 'select code from t_app_verify_mobile t where t.mobile=' + mobile + ' and t.status=1 order by t.insert_time desc'
cursor = self.db.cursor()
cursor.execute(sql)
self.db.close()
cursor.close()
res = cursor.fetchone()
code = res[0]
return code
#################################################
# 获取车id
#################################################
def getCar_id(self,din):
url = "http://bds-test.vandyo.com/dev-manage/carInfo"
headers = {"Accept-Encoding": "gzip", "Content-Type": "application/json; charset=UTF-8"}
postData = {}
postData["din"] = din
resObj = requests.post(url, headers=headers, data=json.dumps(postData), verify=self.SSL_VERIFY)
resObj = json.loads(resObj.text)
# print("\n请求地址:" + url)
# print("-------------------------返回结果:-------------------------")
# print(resObj.text)
return resObj["data"]["carId"]
##############################################
# 绑定车机
##############################################
def bindCar(self,uid,sid,din):
url = "http://api-test.vandyo.com/car/car_add"
ts = int(time.time())
headers = {"Accept-Encoding": "gzip", "Content-Type": "application/json; charset=UTF-8"}
params = {}
params["ts"] = ts
params["sid"] = sid
params["uid"] = uid
postData = {}
postData["din"] = din
postData["dsn"] = self.sn
postData["gasno"] = "95"
postData["mmile"] = ""
postData["plate"] = "渝Z" + str(11000 + self.pad)
self.pad = self.pad + 1
postData["tid"] = "129577"
cs = self.getSignature(params, json.dumps(postData))
params["cs"] = cs
params.pop("sid")
resObj = requests.post(url, headers=headers, params=params, data=json.dumps(postData), verify=self.SSL_VERIFY)
# print("\n请求地址:" + url)
# print("-------------------------返回结果:-------------------------")
# print(resObj.text)
##############################################
# 绑定云镜
##############################################
def bindMirror(self,uid,sid,imei,din):
url = "http://api-test.vandyo.com/car/bind_mirror"
ts = int(time.time())
headers = {"Accept-Encoding": "gzip", "Content-Type": "application/json; charset=UTF-8"}
params = {}
params["ts"] = ts
params["sid"] = sid
params["uid"] = uid
postData = {}
postData["cid"] = self.getCar_id(din)
postData["imei"] = imei
cs = self.getSignature(params, json.dumps(postData))
params["cs"] = cs
params.pop("sid")
resObj = requests.post(url, headers=headers, params=params, data=json.dumps(postData), verify=self.SSL_VERIFY)
# print("\n请求地址:" + url)
# print("-------------------------返回结果:-------------------------")
print(resObj.text)
##############################################
# 绑定多个云镜设备
##############################################
def bindManyMirror(self):
for i in range(0,self.count):
print("=======================================: " + str(i))
mobile = str(self.mobile + i)
imei = str(self.imei + i)
din = "M" + str(self.carId + i)
self.getMsgCode(mobile)
time.sleep(0.5)
msgCode = self.getMsgCodeSql(mobile)
loginInfo = self.loginByMsgCode(mobile, msgCode)
obj.bindCar(loginInfo["uid"], loginInfo["sid"], din)
obj.bindMirror(loginInfo["uid"], loginInfo["sid"], imei, din)
if __name__ == "__main__":
obj = BindMirrorTools()
obj.setImei(863000000040000)
obj.setCarId(202118387001)
obj.setMobile(18100040000)
obj.setCount(80)
obj.bindManyMirror()
# 使用方法
* 在boss系统上导入车机
* 使用addMirror脚本向数据库插入一批云镜数据
* 使用BindMirrorTools 注册用户,绑定车机,添加车辆
* 使用presssureUpload脚本做文件上传压力测试
\ No newline at end of file
File added
#coding: utf-8
#################################################
# 连接数据库
#################################################
import time
import pymysql
################################################
# 向数据库添加云镜
################################################
def addMirror():
dbhost = "114.116.196.12"
dbuser = "root"
dbpassword = "root"
database = "appserver"
dbport = 3308
count = 97
imei = 863000000040000
db = pymysql.connect(host=dbhost, user=dbuser, password=dbpassword, database=database,
port=dbport)
cursor = db.cursor()
for i in range(0,count):
id = "8djwab2ahr7p" + getStr(i)
imei = imei + 1
print(imei)
sql = 'insert into t_app_mirror (id,imei) values ("' + id + '","' + str(imei) + '")'
cursor.execute(sql)
db.commit()
cursor.close()
db.close()
def getStr(data):
st = str(data)
while len(st) < 4:
st = "0" +st
return st
if __name__ == "__main__":
addMirror()
\ No newline at end of file
# coding:utf-8
import os
import threading
import time
import traceback
import requests
class PressureUpload():
def __init__(self):
self.filePath = ""
self.imei = 863000000000000
self.count = 10 # 上传的线程个数
self.threadsInfo = {}
self.threadsInfo["all"] = {}
self.threadsInfo["sucess"] = {}
self.threadsInfo["fail"] = {}
def setFilePath(self,data):
self.filePath = data
def setImei(self,data):
self.imei = data
def setCount(self,data):
self.count = data
def uploadFile(self,threadId,imei):
cam = 1
iscapture = 2
filePath = self.filePath
params = {}
imei = imei
lat = "29.569187"
lng = "106.592613"
timeCur = int(time.time())
try:
with open(filePath, "rb") as fi:
files = {'file': fi}
params["fileaddress"] = "/bbb"
params["cam"] = cam
params["imei"] = imei
params["iscapture"] = iscapture
params["lat"] = lat
params["lng"] = lng
params["time"] = timeCur
res = requests.post("http://api-test.vandyo.com/mirror/upload/file", files=files, params=params)
print(res.text)
self.threadsInfo["sucess"][threadId] = threadId
self.threadsInfo["all"].pop(threadId)
except:
traceback.print_exc()
self.threadsInfo["fail"][threadId] = threadId
self.threadsInfo["all"].pop(threadId)
def startService(self):
for i in range(0,self.count):
imei = str(self.imei + i)
threadId = "threadId_" + str(i)
theThread = threading.Thread(target=self.uploadFile, args=(threadId,imei))
self.threadsInfo["all"][threadId] = theThread
theThread.start()
print(threadId + "启动了:" + imei)
threadNums = len(self.threadsInfo["all"])
while threadNums > 0:
time.sleep(5)
print("启动线程个数:" + str(self.count))
print("剩余线程个数" + str(len(self.threadsInfo["all"])))
threadNums = len(self.threadsInfo["all"])
if __name__ == "__main__":
pre = PressureUpload()
fi = os.getcwd() + "/aaa.mp4"
pre.setFilePath(fi)
pre.setCount(60)
pre.setImei(863000000040001)
pre.startService()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment