| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- import json
- import hashlib
- import time
- import requests
- from requests.auth import HTTPBasicAuth
- def get_equip_list(d_id, isfullId=0):
- """
- 跨平台获取设备信息
- :param d_id: 设备号
- :param isfullId:0模糊匹配,1表示完整设备号匹配
- :return:列表数据,相同设备号放一起,并且最近更新数据靠前,最近更新数据可认为设备最后所在平台
- """
- if isfullId == 1:
- bigdata_res = requests.post("http://8.136.98.49:8002/search/equip", data={"device_id": d_id, "isfullId": "1"},
- timeout=5)
- siqing_res = requests.post("http://www.yfzhwlw.com/search/equip", data={"device_id": d_id, "isfullId": "1"},
- timeout=5)
- else:
- bigdata_res = requests.post("http://8.136.98.49:8002/search/equip", data={"device_id": d_id}, timeout=5)
- siqing_res = requests.post("http://www.yfzhwlw.com/search/equip", data={"device_id": d_id}, timeout=5)
- django_data = json.loads(bigdata_res.content.decode()).get("data", [])
- siqing_data = json.loads(siqing_res.content.decode()).get("data", [])
- data = []
- data.extend(django_data)
- data.extend(siqing_data)
- data = sorted(data, key=lambda e: e.__getitem__('uptime'), reverse=True)
- data = sorted(data, key=lambda e: e.__getitem__('device_id'), reverse=True)
- return data
- class Get_SIM_info(object):
- """
- 自定义获取SIM卡对应卡商及数据
- """
- def __init__(self, iccid) -> None:
- self.iccid = iccid
- self.hz_status = {
- 0: "未知",
- 1: "测试期",
- 2: "沉默期",
- 3: "使用中",
- 4: "停机",
- 5: "停机保号",
- 6: "预销号",
- 7: "销号"
- }
- self.qp_status = {
- "testing": "测试中",
- "inventory": "库存",
- "pending-activation": "待激活",
- "activation": "已激活",
- "deactivation": "已停卡",
- "retired": "已销卡"
- }
- def hz_sim_info(self):
- """获取合宙流量卡信息"""
- url = "http://api.openluat.com/sim/iotcard/card"
- payload = {
- 'iccid': self.iccid,
- }
- appkey = 'KDlhc9VY4rWSXkbM'
- appsecret = 'DmwxcSB1b8dx7kLWqWMJNRLgyQhCvPJ7DHIfLdHIz9A18CifSHqJk3nWZ1vHv4cR'
- auth = HTTPBasicAuth(appkey, appsecret)
- try:
- res = requests.post(url, json=payload, auth=auth, timeout=5)
- data = json.loads(res.text)
- except Exception as e:
- data = {'code': 99999, 'msg': '接口调用异常异常'}
- return data
- def qp_sim_info(self):
- """ 获取企鹏(SIMBOSS)流量卡信息 """
- url = "https://api.simboss.com/2.0/device/detail"
- current_milli_time = lambda: int(round(time.time() * 1000))
- data_1 = "appid=%s&iccid=%s×tamp=%s%s" % (
- "102420177762", self.iccid, current_milli_time(), "6397d7e6a56589f1d93284e9800493e1")
- sign = hashlib.sha256(data_1.encode('utf-8')).hexdigest()
- data = {"appid": "102420177762", "iccid": self.iccid, "timestamp": current_milli_time(), "sign": sign}
- try:
- res = requests.post(url, data=data, timeout=5)
- data = json.loads(res.text)
- except Exception as e:
- data = {'code': 99999, 'msg': '接口调用异常异常'}
- return data
- def get_sim_info(self):
- """未知卡商情况下获取卡信息"""
- hz_data = self.hz_sim_info()
- if hz_data["code"] == 0: # 合宙
- sim_operators = 1
- account_status = self.hz_status[hz_data["data"]["account_status"]]
- if hz_data["data"]["active"] == 1:
- active_date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(hz_data["data"]["active_date"]))
- data_plan = str(hz_data["data"]["data_plan"]) + "M"
- data_usage = str(hz_data["data"]["data_usage"]) + "M"
- data_balance = str(hz_data["data"]["data_balance"]) + "M"
- expiry_date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(hz_data["data"]["expiry_date"]))
- else:
- active_date = "未激活"
- data_plan = "未激活"
- data_usage = "未激活"
- data_balance = "未激活"
- expiry_date = "未激活"
- else:
- qp_data = self.qp_sim_info()
- if qp_data["code"] == "0":
- sim_operators = 2
- account_status = self.qp_status[qp_data["data"]["status"]]
- active_date = qp_data["data"].get("startDate", "")
- if active_date:
- if qp_data["data"]["useCountAsVolume"] == False:
- data_plan = str(qp_data["data"]["totalDataVolume"]) + "M"
- data_usage = str(qp_data["data"]["usedDataVolume"]) + "M"
- data_balance = str(qp_data["data"]["totalDataVolume"] - qp_data["data"]["usedDataVolume"]) + "M"
- else:
- data_plan = str(qp_data["data"]["totalDataVolume"] * 1024) + "M"
- data_usage = str(qp_data["data"]["usedDataVolume"] * 1024) + "M"
- data_balance = str(
- (qp_data["data"]["totalDataVolume"] - qp_data["data"]["usedDataVolume"]) * 1024) + "M"
- expiry_date = qp_data["data"]["expireDate"]
- else:
- data_plan = "未激活"
- data_usage = "未激活"
- data_balance = "未激活"
- expiry_date = "未激活"
- else:
- sim_operators = 3
- account_status = "未知"
- active_date = "未知"
- data_plan = "未知"
- data_usage = "未知"
- data_balance = "未知"
- expiry_date = "未知"
- return sim_operators, account_status, active_date, data_plan, data_usage, data_balance, expiry_date
|