Esempio n. 1
0
 def iot_delete_answer(self):
     get_return = iot_get_return()
     csv_dict = Read_csv().read_csv()
     secretKey = get_return["data"]['secretKey']  # 每个接口必须要传AESkey
     secretuId = get_return["data"]['uId']  # 每个接口必须要传uId
     # 获取到的字符串格式数据转换成dict格式
     interface = json.loads(csv_dict[self.key], encoding='utf-8')
     # 读取url的value
     url = get_serveraddress.get_serveraddress(
     )[adressIndex] + interface["url"]
     # 判断uId 和token 字符串
     if "uId" in url:
         url = url.replace("uId", get_return["data"]['uId'])
     # 读取url的data
     data = interface["data"]
     if "token" in data:
         data["token"] = get_return["data"]['token']
     req_url = url + '?' + parse.urlencode(data)  # 构建get请求
     r = requests.delete(url=req_url)  # 发送请求
     getanswer = json.loads(r.text, encoding='utf-8')
     msgContent = getanswer['msgContent']
     # 解密msgContent
     msgContent_base64 = Base64(msgContent)
     msgContent_base64 = msgContent_base64.b64decode()
     return_data = Iot_encry_decry(msgContent_base64, secretKey, secretuId)
     return_data = return_data.decry()
     return return_data
Esempio n. 2
0
 def iot_post_answer(self):
     get_return = iot_get_return()
     csv_dict = Read_csv().read_csv()
     secretKey = get_return["data"]['secretKey']  # 每个接口必须要传AESkey
     secretuId = get_return["data"]['uId']  # 每个接口必须要传uId
     # 获取到的字符串格式数据转换成dict格式
     interface = json.loads(csv_dict[self.key], encoding='utf-8')
     # 读取url的value
     url = get_serveraddress.get_serveraddress(
     )[adressIndex] + interface["url"]
     # 判断uId 和token 字符串
     if "uId" in url:
         url = url.replace("uId", get_return["data"]['uId'])
     # 读取url的data
     data = interface["data"]
     if "token" in data:
         data["token"] = get_return["data"]['token']
     generate_nonce = iot_generate_nonce()  # 产生随机数
     timestamp = time.time()
     timestamp = str(int(round(timestamp * 1000)))
     data = json.dumps(data)  # 字符串数据
     iot_aes = Iot_aes(data, secretKey, generate_nonce, timestamp,
                       secretuId)
     msgContent = iot_aes.get_msgContent()
     signature = iot_aes.get_signature()
     message = {
         "signature": signature,
         "nonce": generate_nonce,
         "timestamp": timestamp,
         "msgContent": msgContent
     }
     r = requests.post(url=url, json=message)  # 发送请求
     postanswer = json.loads(r.text, encoding='utf-8')
     print(postanswer)
     msgContent = postanswer['msgContent']
     # 解密msgContent
     msgContent_base64 = Base64(msgContent)
     msgContent_base64 = msgContent_base64.b64decode()
     return_data = Iot_encry_decry(msgContent_base64, secretKey, secretuId)
     return_data = return_data.decry()
     return return_data