{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "res = requests.get('https://api.weixin.qq.com/cgi-bin/token',params={'grant_type':'client_credential','appid':'wx7273bd391daeaa5e','secret':'3a29254970ea6734667c8dd9f89e03e2'})\n",
    "token = res.json()['access_token']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'access_token': '90_YsZlhxbTpcJlnuJpXIekDsYN93KqznAu-uyYjA9nS7JOd14qTV8HzYD2w8U6GXl1tL81_zU7oi6XqMdskDaDVfhZLR2t8wBLJRmgiHFU0GG8QiO4qUvEFKg9kbcYGHjACACKL',\n",
       " 'expires_in': 7200}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'90_kxhA5L3rPQdG4OxzT8Oq2W-vNnjxUv8Xafaqxcl7l0oGpqMaczFA-CXkwskQaTfOyWVw9nXmR90ouKmGYAIWG80EgTSO7fFnnh57UfdUfiO1UKgG8z28YNkRtksDFOgAJAJLU'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# requests.post(f\"https://api.weixin.qq.com/wxa/business/group/createid?access_token={token}\",json={\n",
    "#     \"model_id\":\"mF-Q0Xm2du_uZtkVqdgo8A\",\n",
    "#     \"group_name\":\"泡中\".encode('utf-8').hex()\n",
    "# }).json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "res = requests.post(f\"https://api.weixin.qq.com/wxa/getsnticket?access_token={token}\",json={\n",
    "    \"sn\":\"20241121003\",\n",
    "    \"model_id\":\"mF-Q0Xm2du_uZtkVqdgo8A\"\n",
    "    }).json()\n",
    "snTicket = res[\"sn_ticket\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'883d090a8523334f268b8a008d9d76e7'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "snTicket"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'errcode': 0,\n",
       " 'errmsg': 'ok',\n",
       " 'device_list': [{'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A',\n",
       "   'sn': '20241121018',\n",
       "   'errcode': 0},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121019', 'errcode': 0},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121020', 'errcode': 0}]}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "requests.post(f\"https://api.weixin.qq.com/wxa/business/group/adddevice?access_token={token}\",json={\n",
    "    \"group_id\":'gs4PzpoaibE6XsOCEqhU14w',\n",
    "    \"device_list\":[ \n",
    "  {\n",
    "      \"model_id\": \"mF-Q0Xm2du_uZtkVqdgo8A\",\n",
    "      \"sn\": \"20241121018\",\n",
    "    },\n",
    "  {\n",
    "      \"model_id\": \"mF-Q0Xm2du_uZtkVqdgo8A\",\n",
    "      \"sn\": \"20241121019\",\n",
    "    },\n",
    "  {\n",
    "      \"model_id\": \"mF-Q0Xm2du_uZtkVqdgo8A\",\n",
    "      \"sn\": \"20241121020\",\n",
    "    }\n",
    "  ],\n",
    "}).json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'errcode': 0,\n",
       " 'errmsg': 'ok',\n",
       " 'group_name': '泡中',\n",
       " 'device_list': [{'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '1813523'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121001'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121002'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121003'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121004'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121005'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121006'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121007'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121008'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121009'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121010'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121011'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121012'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121013'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121014'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121015'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121016'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121017'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121018'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121019'},\n",
       "  {'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A', 'sn': '20241121020'}],\n",
       " 'model_id': 'mF-Q0Xm2du_uZtkVqdgo8A',\n",
       " 'model_type': '校园电话',\n",
       " 'max_device_count': 50}"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "requests.post(f\"https://api.weixin.qq.com/wxa/business/group/getinfo?access_token={token}\",json={\n",
    "    \"group_id\":'gs4PzpoaibE6XsOCEqhU14w',\n",
    "}).json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "res = requests.get('https://api.weixin.qq.com/cgi-bin/token',params={'grant_type':'client_credential','appid':'wx9a2bab77ffb917d6','secret':'106eaa4c37dd4b7fe8fde7da3fb35be5'})\n",
    "token = res.json()['access_token']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'errcode': 0, 'errmsg': 'ok'}\n"
     ]
    }
   ],
   "source": [
    "#设备注册\n",
    "res = requests.post(f\"https://api.weixin.qq.com/wxa/business/runtime/adddevice?access_token={token}\",json={\n",
    "    \"product_id\":7344,\n",
    "    \"device_id_list\":['20241121001','20241121002','20241121003','20241121004','20241121005','20241121006','20241121007','20241121008','20241121009','20241121010','20241121011','20241121012','20241121013','20241121014','20241121015','20241121016','20241121017','20241121018','20241121019','20241121020'],\n",
    "    \"model_name\":'SP033-KC-WB-TR5-G'\n",
    "}).json()\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'errcode': 48001, 'errmsg': 'api unauthorized rid: 67cabfeb-54d3be5f-005627d1'}\n"
     ]
    }
   ],
   "source": [
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "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": [
    "with open(\"./tt005.png\",\"rb\") as f:\n",
    "    data = f.read()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "requests.post(f\"{ip}/\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
