| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import json
- from aliyunsdkcore.vendored.requests.auth import HTTPBasicAuth
- import requests
- import datetime
- import time
- import hashlib
- def __time_dif(checkdatetime):
- """计算时间差"""
- nowdatetime = datetime.datetime.now()
- checkdatetime = datetime.datetime.strptime(checkdatetime, "%Y-%m-%d %H:%M:%S")
- timedif = checkdatetime - nowdatetime
- return timedif.days
- def sim_updata(iccid):
- # 时间戳 用于获取sign
- timestamp = int(time.time())
- current_milli_time = lambda: int(round(time.time() * 1000))
- data_1 = "appid=%s&iccid=%s×tamp=%s%s"%("102420177762",iccid,current_milli_time(),"6397d7e6a56589f1d93284e9800493e1")
- sign = hashlib.sha256(data_1.encode('utf-8')).hexdigest()
- data = {"appid": "102420177762", "iccid": iccid, "timestamp":current_milli_time(),"sign":sign}
- url = "https://api.simboss.com/2.0/device/detail"
- try:
- status = 1
- ret = requests.post(url, data=data)
- code = json.loads(ret.text)["code"]
- if code == "0":
- status = 1
- else:
- url = 'http://sim.brlink.cn/api/open/iotcard/card'
- appkey = "iaO2DKgS8KdlnVgU"
- appsecret = "qzKgO4sBdzMrjRwv9H22S9ufepNv8Hl5ehPqkYVD31DCICjyKwqUdj7zihQQKfgx"
- status = 2
- ret = requests.post(url,json={'iccid':iccid},auth=HTTPBasicAuth(appkey,appsecret),timeout=(5,10))
- codes = json.loads(ret.text)["code"]
- if codes == 0:
- status = 2
- else:
- url = "https://jsnl.xmnengjia.com/open/api/module/cards"
- data = {"iccids":[iccid]}
- data = json.dumps(data)
- ret = requests.post(url,data=data,timeout=(10,30))
- print(ret.text)
- status = 3
- except:
- status = 0
- ret = 0
- day = 0
- print(status, ret)
- if ret:
- try:
- result = json.loads(ret.text)
- expiry_date = result.get("data", {}).get("expiry_date")
- now_date = int(time.time())
- time_difference = int((expiry_date - now_date) / 3600 / 24)
- print(time_difference)
- if time_difference < 30:
- return [0,"有效期剩余{}天".format(time_difference)]
- elif time_difference >= 181:
- return [1,"有效期剩余{}天".format(time_difference)]
- else:
- return [2,"有效期剩余{}天".format(time_difference)]
- except:
- return [0, "查询无结果"]
- else:
- return [0, "查询无结果"]
- def sim_info(iccid):
- """查询卡信息"""
- url = "http://8.136.98.49:10001/iotcard/platsimview/inquiries/"
- try:
- response = requests.request("POST", url, data={"iccid":iccid})
- except:
- return [0,"查询卡信息异常稍后重试"]
- else:
- res_data = json.loads(response.text)
- if res_data["msg"]=="success" and res_data["data"]:
- expiry_date = res_data["data"]["expiry_date"]
- if expiry_date == "未知":
- return [0,"未查询到卡信息"]
- elif expiry_date == "未激活":
- return [3, "未激活"]
- else:
- time_difference = __time_dif(expiry_date)
- if time_difference < 30:
- return [0,"有效期剩余{}天".format(time_difference)]
- elif time_difference >= 181:
- return [1,"有效期剩余{}天".format(time_difference)]
- else:
- return [2,"有效期剩余{}天".format(time_difference)]
- else:
- return [0,"查询无结果"]
- if __name__ == "__main__":
- # result = sim_info("89860480192280587662")
-
- # result = sim_updata("89860480192280587662")
- result = sim_updata("898604C32622D0173770")
- print(result)
|