{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "853a3284",
   "metadata": {},
   "outputs": [],
   "source": [
    "from requests import get,post\n",
    "import time\n",
    "import json\n",
    "ip = \"http://band.hxzhxy.cn\"\n",
    "param = {\n",
    "    \"username\": \"tangchao\",\n",
    "    \"password\": \"123456a\",\n",
    "    \"client_id\": \"client\",\n",
    "    \"grant_type\": \"password\",\n",
    "    \"client_secret\": \"123456\",\n",
    "}\n",
    "data = get(url=f\"http://band.hxzhxy.cn/oauth/token?username=zhongwei&password=123456a&client_id=client&grant_type=password&client_secret=123456\").json()\n",
    "token = data[\"access_token\"]\n",
    "header = {\n",
    "    \"content-type\": \"application/json\",\n",
    "    \"authorization\": f\"Bearer {token}\",\n",
    "}\n",
    "# http://139.159.182.121:8092/card/findUser?bandNo=0269414644&controllerSN=233159158\n",
    "data = get(f\"https://band.hxzhxy.cn/card/listStuWithRule?gradeId=&classId=&screen=0&param=&board=2&type=1&currentPage=1&pageNumber=0&pageSize=1000&pageTotal=593&teamId=110\",headers=header).json()\n",
    "stus2 = data[\"data\"][\"listData\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4bbd5102",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = get(f\"https://band.hxzhxy.cn/card/listStuWithRule?gradeId=&classId=&screen=0&param=&board=2&type=1&currentPage=1&pageNumber=0&pageSize=1000&pageTotal=593&teamId=110\",headers=header).json()\n",
    "stus2 = data[\"data\"][\"listData\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "24f76d62",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7fe5e94c",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'stus' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[4], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m stus[\u001b[38;5;241m0\u001b[39m]\n",
      "\u001b[1;31mNameError\u001b[0m: name 'stus' is not defined"
     ]
    }
   ],
   "source": [
    "stus[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "93cec8e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns =  [\n",
    "            {\n",
    "                \"id\": 12,\n",
    "                \"serialNo\": \"233159161\",\n",
    "                \"teamId\": 110,\n",
    "                \"readHeadCount\": 2,\n",
    "                \"name\": \"1号通道\",\n",
    "                \"ip\": \"10.68.66.55\",\n",
    "                \"remark\": \"\",\n",
    "                \"online\": 1,\n",
    "                \"onlineTime\": \"2025-11-17 18:54:13\",\n",
    "                \"existingRules\": [\n",
    "                    {\n",
    "                        \"name\": \"全勤\",\n",
    "                        \"id\": 68,\n",
    "                        \"typeId\": 155\n",
    "                    },\n",
    "                    {\n",
    "                        \"name\": \"学生临时规则-上晚自习\",\n",
    "                        \"id\": 69,\n",
    "                        \"typeId\": 156\n",
    "                    },\n",
    "                    {\n",
    "                        \"name\": \"不上晚自习\",\n",
    "                        \"id\": 70,\n",
    "                        \"typeId\": 157\n",
    "                    }\n",
    "                ]\n",
    "            },\n",
    "            {\n",
    "                \"id\": 16,\n",
    "                \"serialNo\": \"233159158\",\n",
    "                \"teamId\": 110,\n",
    "                \"readHeadCount\": 2,\n",
    "                \"name\": \"2号道闸\",\n",
    "                \"ip\": \"10.68.66.56\",\n",
    "                \"remark\": \"\",\n",
    "                \"online\": 1,\n",
    "                \"onlineTime\": \"2025-11-17 18:54:14\",\n",
    "                \"existingRules\": [\n",
    "                    {\n",
    "                        \"name\": \"全勤\",\n",
    "                        \"id\": 68,\n",
    "                        \"typeId\": 124\n",
    "                    },\n",
    "                    {\n",
    "                        \"name\": \"学生临时规则-上晚自习\",\n",
    "                        \"id\": 69,\n",
    "                        \"typeId\": 125\n",
    "                    },\n",
    "                    {\n",
    "                        \"name\": \"不上晚自习\",\n",
    "                        \"id\": 70,\n",
    "                        \"typeId\": 126\n",
    "                    }\n",
    "                ]\n",
    "            },\n",
    "            {\n",
    "                \"id\": 17,\n",
    "                \"serialNo\": \"233159159\",\n",
    "                \"teamId\": 110,\n",
    "                \"readHeadCount\": 2,\n",
    "                \"name\": \"3号道闸\",\n",
    "                \"ip\": \"10.68.66.57\",\n",
    "                \"remark\": \"\",\n",
    "                \"online\": 1,\n",
    "                \"onlineTime\": \"2025-11-17 18:54:13\",\n",
    "                \"existingRules\": [\n",
    "                    {\n",
    "                        \"name\": \"学生临时规则-上晚自习\",\n",
    "                        \"id\": 69,\n",
    "                        \"typeId\": 172\n",
    "                    },\n",
    "                    {\n",
    "                        \"name\": \"全勤\",\n",
    "                        \"id\": 68,\n",
    "                        \"typeId\": 180\n",
    "                    },\n",
    "                    {\n",
    "                        \"name\": \"不上晚自习\",\n",
    "                        \"id\": 70,\n",
    "                        \"typeId\": 183\n",
    "                    }\n",
    "                ]\n",
    "            },\n",
    "            {\n",
    "                \"id\": 18,\n",
    "                \"serialNo\": \"233159157\",\n",
    "                \"teamId\": 110,\n",
    "                \"readHeadCount\": 2,\n",
    "                \"name\": \"4号道闸\",\n",
    "                \"ip\": \"10.68.66.58\",\n",
    "                \"remark\": \"\",\n",
    "                \"online\": 1,\n",
    "                \"onlineTime\": \"2025-11-17 18:54:13\",\n",
    "                \"existingRules\": [\n",
    "                    {\n",
    "                        \"name\": \"全勤\",\n",
    "                        \"id\": 68,\n",
    "                        \"typeId\": 188\n",
    "                    },\n",
    "                    {\n",
    "                        \"name\": \"学生临时规则-上晚自习\",\n",
    "                        \"id\": 69,\n",
    "                        \"typeId\": 189\n",
    "                    },\n",
    "                    {\n",
    "                        \"name\": \"不上晚自习\",\n",
    "                        \"id\": 70,\n",
    "                        \"typeId\": 190\n",
    "                    }\n",
    "                ]\n",
    "            },\n",
    "            {\n",
    "                \"id\": 19,\n",
    "                \"serialNo\": \"233159164\",\n",
    "                \"teamId\": 110,\n",
    "                \"readHeadCount\": 2,\n",
    "                \"name\": \"广告门\",\n",
    "                \"ip\": \"10.68.66.59\",\n",
    "                \"remark\": \"\",\n",
    "                \"online\": 1,\n",
    "                \"onlineTime\": \"2025-11-17 18:54:13\",\n",
    "                \"existingRules\": [\n",
    "                    {\n",
    "                        \"name\": \"全勤\",\n",
    "                        \"id\": 68,\n",
    "                        \"typeId\": 191\n",
    "                    },\n",
    "                    {\n",
    "                        \"name\": \"学生临时规则-上晚自习\",\n",
    "                        \"id\": 69,\n",
    "                        \"typeId\": 192\n",
    "                    },\n",
    "                    {\n",
    "                        \"name\": \"不上晚自习\",\n",
    "                        \"id\": 70,\n",
    "                        \"typeId\": 193\n",
    "                    }\n",
    "                ]\n",
    "            }\n",
    "        ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3a35ac84",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1号通道 熊浩宇 无权限\n",
      "1号通道 郭思垚 无权限\n",
      "1号通道 雷林皓 无权限\n",
      "1号通道 汪梓衡 无权限\n",
      "1号通道 徐沐瑶 无权限\n",
      "1号通道 方苇骐 无权限\n",
      "2号道闸 熊浩宇 无权限\n",
      "2号道闸 郭思垚 无权限\n",
      "2号道闸 雷林皓 无权限\n",
      "2号道闸 汪梓衡 无权限\n",
      "2号道闸 方苇骐 无权限\n",
      "3号道闸 熊浩宇 无权限\n",
      "3号道闸 郭思垚 无权限\n",
      "3号道闸 雷林皓 无权限\n",
      "3号道闸 汪梓衡 无权限\n",
      "3号道闸 徐沐瑶 无权限\n",
      "3号道闸 方苇骐 无权限\n",
      "4号道闸 熊浩宇 无权限\n",
      "4号道闸 郭思垚 无权限\n",
      "4号道闸 雷林皓 无权限\n",
      "4号道闸 汪梓衡 无权限\n",
      "4号道闸 徐沐瑶 无权限\n",
      "4号道闸 方苇骐 无权限\n",
      "广告门 熊浩宇 无权限\n",
      "广告门 郭思垚 无权限\n",
      "广告门 雷林皓 无权限\n",
      "广告门 汪梓衡 无权限\n",
      "广告门 徐沐瑶 无权限\n",
      "广告门 方苇骐 无权限\n"
     ]
    }
   ],
   "source": [
    "for sn in sns:\n",
    "    for stu in stus:\n",
    "        res = get( f\"http://139.159.182.121:8092/card/findUser?bandNo={stu['手环号']}&controllerSN={sn['serialNo']}\").json()\n",
    "        if res['success']:\n",
    "            result = json.loads(res['msg'])\n",
    "            flag = result['result']['success']\n",
    "            if flag:\n",
    "                pass\n",
    "                # print(f\"{stu['姓名']} 有权限\")\n",
    "            else:\n",
    "                print(f\"{sn['name']} {stu['姓名']} 无权限\")\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "c7349202",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "e7166b72",
   "metadata": {},
   "outputs": [
    {
     "ename": "",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m在当前单元格或上一个单元格中执行代码时 Kernel 崩溃。\n",
      "\u001b[1;31m请查看单元格中的代码，以确定故障的可能原因。\n",
      "\u001b[1;31m单击<a href='https://aka.ms/vscodeJupyterKernelCrash'>此处</a>了解详细信息。\n",
      "\u001b[1;31m有关更多详细信息，请查看 Jupyter <a href='command:jupyter.viewOutput'>log</a>。"
     ]
    }
   ],
   "source": [
    "while True:\n",
    "    data = get(\"https://www.hxzhxy.cn/hxyd-api/gate/card/list2?teamId=110&name=&screen=3&startDate=1763378175113&state=&endDate=1763378175113&type=0&gateNo=&pageSize=30&pageNumber=0&teaType=0&doorInfo=&access_token=e8ae9533-ebbe-4d14-8251-6a587ca40ac2\").json()\n",
    "    \n",
    "    for stu in data[\"data\"][\"content\"]:\n",
    "        if stu[\"eventName\"] !='正常刷卡开门':\n",
    "            print(stu['name'])\n",
    "    time.sleep(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "700384c1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "251"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(list(stus))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "95aa8903",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "289"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "251+38"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "b7febbf5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "李翰玟 上晚自习\n",
      "许睿 上晚自习\n",
      "吕文轩 上晚自习\n",
      "杨宇晨 上晚自习\n",
      "赖馨玥 上晚自习\n",
      "张成 上晚自习\n",
      "佘锦宸 上晚自习\n",
      "钟雅祺 上晚自习\n",
      "罗凯玟 上晚自习\n",
      "张翼然 上晚自习\n",
      "贾玥彤 上晚自习\n",
      "李晞彤 上晚自习\n",
      "徐欣渝 上晚自习\n",
      "王为 上晚自习\n",
      "赖桔兴 上晚自习\n",
      "龚跃鑫 上晚自习\n",
      "郑好 上晚自习\n",
      "苟恩瑞 上晚自习\n",
      "顾子昂 上晚自习\n",
      "符曾洋 上晚自习\n",
      "吴嘉唐 上晚自习\n",
      "张思雅 上晚自习\n",
      "管子漩 上晚自习\n",
      "张文杰 上晚自习\n",
      "陈熙辰 上晚自习\n",
      "代芸萱 上晚自习\n",
      "刘星彤 上晚自习\n",
      "肖茜茜 上晚自习\n",
      "白益轩 上晚自习\n",
      "冯靖 上晚自习\n",
      "陈诗雨 上晚自习\n",
      "周渤灵 上晚自习\n",
      "李文斌 上晚自习\n",
      "王震宇 上晚自习\n",
      "王正豪 上晚自习\n",
      "李漪诺 上晚自习\n",
      "吴金龙 上晚自习\n",
      "马鸿森 上晚自习\n"
     ]
    }
   ],
   "source": [
    "for item in stus2:\n",
    "    if item[\"姓名\"] in stus:\n",
    "        if item['晚自习']==2 :\n",
    "            tag='上晚自习'\n",
    "        else:\n",
    "            tag='不上晚自习'\n",
    "        print(f'{item[\"姓名\"]} {tag}' )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "f34f6606",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"success\":true,\"msg\":\"操作成功\",\"code\":0,\"data\":null}\n",
      "{\"success\":true,\"msg\":\"操作成功\",\"code\":0,\"data\":null}\n",
      "{\"success\":true,\"msg\":\"操作成功\",\"code\":0,\"data\":null}\n",
      "{\"success\":true,\"msg\":\"操作成功\",\"code\":0,\"data\":null}\n",
      "{\"success\":true,\"msg\":\"操作成功\",\"code\":0,\"data\":null}\n"
     ]
    }
   ],
   "source": [
    "for sn in sns:\n",
    "    print(get(f\"http://139.159.182.121:8092/card/getTime\",params={\"controllerSN\":int(sn['serialNo'])}).text)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
