Files
python----/智慧校园/同文/同文下发学生门锁.ipynb
2025-10-20 12:32:18 +08:00

12 KiB
Raw Permalink Blame History

In [1]:
import pandas as pd
df = pd.read_excel('./学生信息_最新.xlsx',dtype='str')
In [5]:
get(url=f"http://band.hxzhxy.cn/oauth/token?username=zhongwei&password=123456a&client_id=client&grant_type=password&client_secret=123456").text
Out [5]:
'<html>\r\n<head><title>404 Not Found</title></head>\r\n<body bgcolor="white">\r\n<center><h1>404 Not Found</h1></center>\r\n<hr><center>nginx/1.4.0</center>\r\n</body>\r\n</html>\r\n'
In [1]:
from requests import get,post
import time
ip = "http://band.hxzhxy.cn"
param = {
    "username": "tangchao",
    "password": "123456a",
    "client_id": "client",
    "grant_type": "password",
    "client_secret": "123456",
}
data = get(url=f"http://band.hxzhxy.cn/oauth/token?username=zhongwei&password=123456a&client_id=client&grant_type=password&client_secret=123456").json()
token = data["access_token"]
header = {
    "content-type": "application/json",
    "authorization": f"Bearer {token}",
}
In [3]:
a = df.groupby("教室").apply(lambda x:x["手环号"].tolist())
C:\Users\Administrator\AppData\Local\Temp\ipykernel_11244\3332289157.py:1: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  a = df.groupby("教室").apply(lambda x:x["手环号"].tolist())
In [ ]:
In [4]:
doors = get(f"https://band.hxzhxy.cn/door/lock/listLockPage?teamId=119&pageSize=60&pageNumber=0&value=&areaId=&tierId=&regionId=&bindType=&lockName=&type=2&mainTypeId=&sizeType=&lockType=&access_token={token}").json()
In [5]:
doors_map ={}
for item in doors["data"]["content"]:
    doors_map[item["lockName"]] = item["lockNo"]
In [6]:
a
Out [6]:
教室
2210    [0022796140, 0022753212, 0022796172, 310863721...
2211    [3108594513, 3108622273, 3108583137, 002303998...
2212    [3108445809, 3108464161, 3108415601, 310846636...
2213    [0022820892, 3108624769, 3108605505, 310846235...
2214    [3108599409, 3107632929, 3108571601, 002272249...
2311    [3108598753, 3108438913, 3108358785, 310839236...
2312    [3108631313, 0022702140, 3108584241, 002283212...
2313    [3108562849, 0022679980, 3108437249, 310843908...
2314    [3108415473, 3108462385, 0022752972, 310862931...
2510    [0022822732, 3108606273, 3108390481, 002279577...
2511    [3108388321, 0022704076, 3108582545, 002270244...
2512    [3108606081, 3108614401, 3108600385, 310844576...
2513    [3108440913, 3108683713, 3108588817, 310868209...
2514    [3108361393, 3108600401, 3108597553, 310860504...
dtype: object
In [7]:
for key,value in a.items():
    lockNo = doors_map.get(f'{key}前门',None)
    addUserBand = ",".join(value)
In [2]:
result  =post("https://band.hxzhxy.cn/door/accredit/sendNews",json={"startTime":"25083115","endTime":"28052815","adminType":"55","type":"01","time":[1756625633772,1843112033772],"accountIp":"183.220.92.52","accountName":"183.220.92.52","lockNo":"181681774702","serialNo":"868002345684294","addAdminBand":"","addUserBand":"3108624305","removeBand":"","doorAccreditIds":""},headers=header).text
In [ ]:
from datetime import datetime,timedelta
start = datetime.now().strftime("%y%m%d%H")
end = (datetime.now()+ timedelta(days=365)).strftime("%y%m%d%H")
In [ ]:
start,end
('25091916', '26091916')
在当前单元格或上一个单元格中执行代码时 Kernel 崩溃。

请查看单元格中的代码,以确定故障的可能原因。

单击<a href='https://aka.ms/vscodeJupyterKernelCrash'>此处</a>了解详细信息。

有关更多详细信息,请查看 Jupyter <a href='command:jupyter.viewOutput'>log</a>。
In [ ]:
# for key,value in a.items():
#     lockNo = doors_map.get(f'{key}前门',None)
#     addUserBand = ",".join(value)
for key,value in a.items():
    lockNo = doors_map.get(f'{key}前门',None)
    addUserBand = ",".join(value)
    if key!='2512':continue
    for item in doors["data"]["content"]:
        if item["lockName"] == f'{key}前门':
            print( f'下发{key}前门')
            print(f"参数lockNo{lockNo}serialNo{item['serialNo']}addUserBand{addUserBand}")
            result  =post("https://band.hxzhxy.cn/door/accredit/sendNews",json={"startTime":"25083115","endTime":"28052815","adminType":"55","type":"01","time":[1756625633772,1843112033772],"accountIp":"183.220.92.52","accountName":"183.220.92.52","lockNo":lockNo,"serialNo":item["serialNo"],"addAdminBand":"","addUserBand":addUserBand,"removeBand":"","doorAccreditIds":""},headers=header).text
            print(result)
            # print(a)
            time.sleep(10)
            break
            
下发2512前门
参数lockNo181681774855serialNo868002345684074addUserBand3108606081,3108614401,3108600385,3108445761,0022754844,3108629505,3108601713,3108590993,0022722508,3108586817,3108354753,3108586769,3108386177,3108359649,3108584129,3108356609,0022830300,3108637281,3108637185,3108605073,3108605345,3108632769,0022796108,3108595409,3108562881,3108614321,3108388129,3108603841,0022821084,3108359713,3108358529,3108460625,0023038412,3108466545,3108681873,3108396257,3108652497
{"success":true,"msg":"操作成功","code":0,"data":null}
在当前单元格或上一个单元格中执行代码时 Kernel 崩溃。

请查看单元格中的代码,以确定故障的可能原因。

单击<a href='https://aka.ms/vscodeJupyterKernelCrash'>此处</a>了解详细信息。

有关更多详细信息,请查看 Jupyter <a href='command:jupyter.viewOutput'>log</a>。
In [12]:
import tqdm
In [31]:
data = get(f"https://band.hxzhxy.cn/door/lock/listLockPage?teamId=119&pageSize=60&pageNumber=0&value=&areaId=&tierId=&regionId=&bindType=&lockName=&type=2&mainTypeId=&sizeType=&lockType=&access_token={token}").json()
with tqdm.tqdm(total=len(data["data"]["content"])) as pbar:
    for item in data["data"]["content"]:
        if item["password"] == "12345687" or item["password"]==None: 
            pbar.update(1)
            continue
        post("https://band.hxzhxy.cn/door/password/send",json={"lockNos":item["lockNo"],"serialNos":item["serialNo"],"password":"12345687","type":"04","typeSend":"0","accountIp":"183.220.91.181","accountName":"183.220.91.181","account":"5789"},headers=header)
        time.sleep(7)
        pbar.update(1)
100%|██████████| 52/52 [00:07<00:00,  7.22it/s]
In [33]:
data = get(f"https://band.hxzhxy.cn/door/lock/listLockPage?teamId=119&pageSize=60&pageNumber=0&value=&areaId=&tierId=&regionId=&bindType=&lockName=&type=2&mainTypeId=&sizeType=&lockType=&access_token={token}").json()
for item in data["data"]["content"]:
    if item["password"] != "12345687" and item["password"]!=None:
        print(item)
        print(item['password'])
{'bandUserCount': 0, 'lockNo': '181681774855', 'teamId': 119, 'electric': 100, 'tierName': '5', 'doorName': '2512前门', 'ID': 723, 'lockType': 2, 'remark': None, 'mainType': '教室', 'type': '', 'password': '88888888', 'bandAdminCount': 4, 'remask': None, 'alias': '教学楼3-2门锁网关', 'createTime': 1755314698000, 'dongId': 28, 'genre': None, 'gateType': 1, 'dongName': '1栋', 'lockName': '2512前门', 'roomName': '2512', 'image': None, 'sizeType': 1, 'isPassword': 1, 'regionName': '无', 'areaId': 20, 'updateTime': None, 'version': None, 'serialNo': '868002345684074', 'opsTime': None, 'teamName': '2512', 'tierId': 64, 'doorId': 747, 'areaName': '教学楼', 'batteryType': None}
88888888
In [9]:
len("Xpaotongshutongwenzhongxue971001")
Out [9]:
32