[
  {
    "path": ".gitattributes",
    "content": "# Auto detect text files and perform LF normalization\n* text=auto\n"
  },
  {
    "path": ".github/pull.yml",
    "content": "version: \"1\"\nrules:                      # Array of rules\n  - base: main            # Required. Target branch\n    upstream: Squaregentleman:main    # Required. Must be in the same fork network.\n    mergeMethod: hardreset  # Optional, one of [none, merge, squash, rebase, hardreset], Default: none.\n    mergeUnstable: true    # Optional, merge pull request even when the mergeable_state is not clean. Default: false\n"
  },
  {
    "path": ".github/workflows/run.yml",
    "content": "name: 刷步数\n\non:\n  push:\n    branches: [ main ]\n  pull_request:\n    branches: [ main ]\n  schedule:\n    - cron: 0 9 * * *\n  watch:\n    types: started\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n    if: github.event.repository.owner.id == github.event.sender.id\n\n    steps:\n      - uses: actions/checkout@v2\n      - name: 初始化Python\n        uses: actions/setup-python@v2\n        with:\n          python-version: 3.7\n      - name: 开始\n        run: |\n          pip install requests\n          pmode='${{ secrets.PMODE }}'\n          pkey='${{ secrets.PKEY }}'\n          user='${{ secrets.USER }}'\n          pwd='${{ secrets.PWD }}'\n          step='${{ secrets.STEP }}'\n          python3 main.py ${pmode} ${pkey} ${user} ${pwd} ${step}\n"
  },
  {
    "path": "LICENSE",
    "content": "                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "README.md",
    "content": "# 小米运动自动刷步数\n请移步至 [原作：方块君577fkj](https://github.com/577fkj/mimotion)\n\n# run 跑起来\n"
  },
  {
    "path": "TG_PUSH.md",
    "content": "**TG_PUSH教程**\n\n如何获取token以及UserID\n\nⅠ.首先在Telegram上搜索[BotFather](https://t.me/BotFather)机器人<br>\n\n![TG_PUSH1](https://gitee.com/lxk0301/jd_docker/raw/master/icon/TG_PUSH1.png)\n\nⅡ.利用[BotFather](https://t.me/BotFather)创建一个属于自己的通知机器人，按照下图中的1、2、3步骤拿到token，格式形如```10xxx4:AAFcqxxxxgER5uw```。<br>\n\n![TG_PUSH2](https://gitee.com/lxk0301/jd_docker/raw/master/icon/TG_PUSH2.png)<br>\n\n**新创建的机器人需要跟它发一条消息来开启对话，否则可能会遇到PEKY填对了但是收不到消息的情况**<br>\n\nⅢ.再次在Telegram上搜索[getuserIDbot](https://t.me/getuserIDbot)机器人，获取UserID。<br>\n\n![TG_PUSH3](https://gitee.com/lxk0301/jd_docker/raw/master/icon/TG_PUSH3.png)\n"
  },
  {
    "path": "main.py",
    "content": "\"\"\"\n主程序脚本\n\"\"\"\n# -*- coding: utf8 -*-\n# python >=3.8\n\nimport json\nimport random\nimport re\nimport json\nimport sys\nimport time\nfrom urllib.parse import quote\n\nimport requests\n\nnow = time.strftime(\"%Y-%m-%d %H:%M:%S\", time.localtime())\nheaders = {\n    'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 9; MI 6 MIUI/20.6.18)'\n}\n\n\ndef get_code(location):\n    \"\"\"\n    获取登录code\n    \"\"\"\n    code_pattern = re.compile(\"(?<=access=).*?(?=&)\")\n    code = code_pattern.findall(location)[0]\n    return code\n\n\ndef login(_user, password):\n    \"\"\"\n    登录\n    \"\"\"\n    url1 = \"https://api-user.huami.com/registrations/+86\" + _user + \"/tokens\"\n    _headers = {\n        \"Content-Type\": \"application/x-www-form-urlencoded;charset=UTF-8\",\n        \"User-Agent\": \"MiFit/4.6.0 (iPhone; iOS 14.0.1; Scale/2.00)\"\n    }\n    data1 = {\n        \"client_id\": \"HuaMi\",\n        \"password\": f\"{password}\",\n        \"redirect_uri\": \"https://s3-us-west-2.amazonaws.com/hm-registration/successsignin.html\",\n        \"token\": \"access\"\n    }\n    r1 = requests.post(url1, data=data1, headers=_headers, allow_redirects=False)\n    try:\n        location = r1.headers[\"Location\"]\n        code = get_code(location)\n    except:\n        return 0, 0\n    # print(\"access_code获取成功！\")\n    # print(code)\n\n    url2 = \"https://account.huami.com/v2/client/login\"\n    data2 = {\n        \"app_name\": \"com.xiaomi.hm.health\",\n        \"app_version\": \"4.6.0\",\n        \"code\": f\"{code}\",\n        \"country_code\": \"CN\",\n        \"device_id\": \"2C8B4939-0CCD-4E94-8CBA-CB8EA6E613A1\",\n        \"device_model\": \"phone\",\n        \"grant_type\": \"access_token\",\n        \"third_name\": \"huami_phone\",\n    }\n    r2 = requests.post(url2, data=data2, headers=_headers).json()\n    login_token = r2[\"token_info\"][\"login_token\"]\n    # print(\"login_token获取成功！\")\n    # print(login_token)\n    userid = r2[\"token_info\"][\"user_id\"]\n    # print(\"userid获取成功！\")\n    # print(userid)\n\n    return login_token, userid\n\n\ndef main(_user, _passwd, _step):\n    \"\"\"\n    主函数\n    \"\"\"\n    _user = str(_user)\n    password = str(_passwd)\n    _step = str(_step)\n    if _user == '' or password == '':\n        print(\"用户名或密码不能为空！\")\n        return \"user and passwd not empty！\"\n\n    if _step == '':\n        print(\"已设置为随机步数（10000-19999）\")\n        _step = str(random.randint(10000, 19999))\n    login_token, userid = login(_user, password)\n    if login_token == 0:\n        print(\"登陆失败！\")\n        return \"login fail!\"\n\n    t = get_time()\n\n    app_token = get_app_token(login_token)\n\n    today = time.strftime(\"%F\")\n\n    summary = {\n        \"v\": 6,\n        \"slp\": {\n            \"st\": int(time.time()),\n            \"ed\": int(time.time()),\n            \"dp\": 0,\n            \"lt\": 0,\n            \"wk\": 0,\n            \"usrSt\": -1440,\n            \"usrEd\": -1440,\n            \"wc\": 0,\n            \"is\": 0,\n            \"lb\": 0,\n            \"to\": 0,\n            \"dt\": 0,\n            \"rhr\": 0,\n            \"ss\": 0\n        },\n        \"stp\": {\n            \"ttl\": _step,\n            \"dis\": 10627,\n            \"cal\": 510,\n            \"wk\": 41,\n            \"rn\": 50,\n            \"runDist\": 7654,\n            \"runCal\": 397,\n            \"stage\": [\n                {\n                    \"start\": 327,\n                    \"stop\": 341,\n                    \"mode\": 1,\n                    \"dis\": 481,\n                    \"cal\": 13,\n                    \"step\": 680\n                },\n                {\n                    \"start\": 342,\n                    \"stop\": 367,\n                    \"mode\": 3,\n                    \"dis\": 2295,\n                    \"cal\": 95,\n                    \"step\": 2874\n                },\n                {\n                    \"start\": 368,\n                    \"stop\": 377,\n                    \"mode\": 4,\n                    \"dis\": 1592,\n                    \"cal\": 88,\n                    \"step\": 1664\n                },\n                {\n                    \"start\": 378,\n                    \"stop\": 386,\n                    \"mode\": 3,\n                    \"dis\": 1072,\n                    \"cal\": 51,\n                    \"step\": 1245\n                },\n                {\n                    \"start\": 387,\n                    \"stop\": 393,\n                    \"mode\": 4,\n                    \"dis\": 1036,\n                    \"cal\": 57,\n                    \"step\": 1124\n                },\n                {\n                    \"start\": 394,\n                    \"stop\": 398,\n                    \"mode\": 3,\n                    \"dis\": 488,\n                    \"cal\": 19,\n                    \"step\": 607\n                },\n                {\n                    \"start\": 399,\n                    \"stop\": 414,\n                    \"mode\": 4,\n                    \"dis\": 2220,\n                    \"cal\": 120,\n                    \"step\": 2371\n                },\n                {\n                    \"start\": 415,\n                    \"stop\": 427,\n                    \"mode\": 3,\n                    \"dis\": 1268,\n                    \"cal\": 59,\n                    \"step\": 1489\n                },\n                {\n                    \"start\": 428,\n                    \"stop\": 433,\n                    \"mode\": 1,\n                    \"dis\": 152,\n                    \"cal\": 4,\n                    \"step\": 238\n                },\n                {\n                    \"start\": 434,\n                    \"stop\": 444,\n                    \"mode\": 3,\n                    \"dis\": 2295,\n                    \"cal\": 95,\n                    \"step\": 2874\n                },\n                {\n                    \"start\": 445,\n                    \"stop\": 455,\n                    \"mode\": 4,\n                    \"dis\": 1592,\n                    \"cal\": 88,\n                    \"step\": 1664\n                },\n                {\n                    \"start\": 456,\n                    \"stop\": 466,\n                    \"mode\": 3,\n                    \"dis\": 1072,\n                    \"cal\": 51,\n                    \"step\": 1245\n                },\n                {\n                    \"start\": 467,\n                    \"stop\": 477,\n                    \"mode\": 4,\n                    \"dis\": 1036,\n                    \"cal\": 57,\n                    \"step\": 1124\n                },\n                {\n                    \"start\": 478,\n                    \"stop\": 488,\n                    \"mode\": 3,\n                    \"dis\": 488,\n                    \"cal\": 19,\n                    \"step\": 607\n                },\n                {\n                    \"start\": 489,\n                    \"stop\": 499,\n                    \"mode\": 4,\n                    \"dis\": 2220,\n                    \"cal\": 120,\n                    \"step\": 2371\n                },\n                {\n                    \"start\": 500,\n                    \"stop\": 511,\n                    \"mode\": 3,\n                    \"dis\": 1268,\n                    \"cal\": 59,\n                    \"step\": 1489\n                },\n                {\n                    \"start\": 512,\n                    \"stop\": 522,\n                    \"mode\": 1,\n                    \"dis\": 152,\n                    \"cal\": 4,\n                    \"step\": 238\n                }\n            ]\n        },\n        \"goal\": 8000,\n        \"tz\": \"28800\"\n    }\n\n    data_json = [\n        {\n            \"data_hr\": \"//////9L////////////Vv///////////0v///////////9e/////0n/a///S////////////0b//////////1FK////////////R/////////////////9PTFFpaf9L////////////R////////////0j///////////9K////////////Ov///////////zf///86/zr/Ov88/zf/Pf///0v/S/8/////////////Sf///////////z3//////0r/Ov//////S/9L/zb/Sf9K/0v/Rf9H/zj/Sf9K/0//N////0D/Sf83/zr/Pf9M/0v/Ov9e////////////S////////////zv//z7/O/83/zv/N/83/zr/N/86/z//Nv83/zn/Xv84/zr/PP84/zj/N/9e/zr/N/89/03/P/89/z3/Q/9N/0v/Tv9C/0H/Of9D/zz/Of88/z//PP9A/zr/N/86/zz/Nv87/0D/Ov84/0v/O/84/zf/MP83/zH/Nv83/zf/N/84/zf/Of82/zf/OP83/zb/Mv81/zX/R/9L/0v/O/9I/0T/S/9A/zn/Pf89/zn/Nf9K/07/N/83/zn/Nv83/zv/O/9A/0H/Of8//zj/PP83/zj/S/87/zj/Nv84/zf/Of83/zf/Of83/zb/Nv9L/zj/Nv82/zb/N/85/zf/N/9J/zf/Nv83/zj/Nv84/0r/Sv83/zf/MP///zb/Mv82/zb/Of85/z7/Nv8//0r/S/85/0H/QP9B/0D/Nf89/zj/Ov83/zv/Nv8//0f/Sv9O/0ZeXv///////////1X///////////9B////////////TP///1b//////0////////////9N/////////v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+\",\n            \"date\": today,\n            \"data\": [\n                {\n                    \"start\": 0,\n                    \"stop\": 1439,\n                    \"value\": \"UA8AUBQAUAwAUBoAUAEAYCcAUBkAUB4AUBgAUCAAUAEAUBkAUAwAYAsAYB8AYB0AYBgAYCoAYBgAYB4AUCcAUBsAUB8AUBwAUBIAYBkAYB8AUBoAUBMAUCEAUCIAYBYAUBwAUCAAUBgAUCAAUBcAYBsAYCUAATIPYD0KECQAYDMAYB0AYAsAYCAAYDwAYCIAYB0AYBcAYCQAYB0AYBAAYCMAYAoAYCIAYCEAYCYAYBsAYBUAYAYAYCIAYCMAUB0AUCAAUBYAUCoAUBEAUC8AUB0AUBYAUDMAUDoAUBkAUC0AUBQAUBwAUA0A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gAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAA\",\n                    \"tz\": 32,\n                    \"did\": \"DA932FFFFE8816E7\",\n                    \"src\": 24\n                }\n            ],\n            \"summary\": json.dumps(summary),\n            \"source\": 24,\n            \"type\": 0\n        }\n    ]\n\n    url = f'https://api-mifit-cn.huami.com/v1/data/band_data.json?&t={t}'\n    head = {\n        \"apptoken\": app_token,\n        \"Content-Type\": \"application/x-www-form-urlencoded\"\n    }\n\n    data = f'userid={userid}&last_sync_data_time=1597306380&device_type=0&last_deviceid=DA932FFFFE8816E7&data_json={quote(json.dumps(data_json))}'\n\n    response = requests.post(url, data=data, headers=head).json()\n    # print(response)\n    result = f\"{_user[:4]}****{_user[-4:]}: [{now}] 修改步数（{_step}）\" + response['message']\n    print(result)\n    return result\n\n\ndef get_time():\n    \"\"\"\n    获取时间戳\n    \"\"\"\n    url = 'http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp'\n    response = requests.get(url, headers=headers).json()\n    t = response['data']['t']\n    return t\n\n\ndef get_app_token(login_token):\n    \"\"\"\n    获取app_token\n    \"\"\"\n    url = f\"https://account-cn.huami.com/v1/client/app_tokens\" \\\n          f\"?app_name=com.xiaomi.hm.health&dn=api-user.huami.com%2Capi-mifit.huami.com%2Capp-analytics.huami.com\" \\\n          f\"&login_token={login_token}\"\n    response = requests.get(url, headers=headers).json()\n    app_token = response['token_info']['app_token']\n    # print(\"app_token获取成功！\")\n    # print(app_token)\n    return app_token\n\n\ndef push_wx(_sckey, desp=\"\"):\n    \"\"\"\n    推送server酱\n    \"\"\"\n    if _sckey == '':\n        print(\"[注意] 未提供sckey，不进行推送！\")\n    else:\n        server_url = f\"https://sc.ftqq.com/{_sckey}.send\"\n        params = {\n            \"text\": '小米运动 步数修改',\n            \"desp\": desp\n        }\n\n        response = requests.get(server_url, params=params)\n        json_data = response.json()\n\n        if json_data['errno'] == 0:\n            print(f\"[{now}] 推送成功。\")\n        else:\n            print(f\"[{now}] 推送失败：{json_data['errno']}({json_data['errmsg']})\")\n\n\ndef push_server(_sckey, desp=\"\"):\n    \"\"\"\n    推送消息到微信\n    \"\"\"\n    if _sckey == '':\n        print(\"[注意] 未提供sckey，不进行微信推送！\")\n    else:\n        server_url = f\"https://sctapi.ftqq.com/{_sckey}.send\"\n        params = {\n            \"title\": '小米运动 步数修改',\n            \"desp\": desp\n        }\n\n        response = requests.get(server_url, params=params)\n        json_data = response.json()\n\n        if json_data['code'] == 0:\n            print(f\"[{now}] 推送成功。\")\n        else:\n            print(f\"[{now}] 推送失败：{json_data['code']}({json_data['message']})\")\n\n\ndef push_pushplus(token, content=\"\"):\n    \"\"\"\n    推送消息到pushplus\n    \"\"\"\n    if token == '':\n        print(\"[注意] 未提供token，不进行pushplus推送！\")\n    else:\n        server_url = \"http://www.pushplus.plus/send\"\n        params = {\n            \"token\": token,\n            \"title\": '小米运动 步数修改',\n            \"content\": content\n        }\n\n        response = requests.get(server_url, params=params)\n        json_data = response.json()\n\n        if json_data['code'] == 200:\n            print(f\"[{now}] 推送成功。\")\n        else:\n            print(f\"[{now}] 推送失败：{json_data['code']}({json_data['message']})\")\n\n\ndef push_tg(token, chat_id, desp=\"\"):\n    \"\"\"\n    推送消息到TG\n    \"\"\"\n    if token == '':\n        print(\"[注意] 未提供token，不进行tg推送！\")\n    elif chat_id == '':\n        print(\"[注意] 未提供chat_id，不进行tg推送！\")\n    else:\n        server_url = f\"https://api.telegram.org/bot{token}/sendmessage\"\n        params = {\n            \"text\": '小米运动 步数修改\\n\\n' + desp,\n            \"chat_id\": chat_id\n        }\n\n        response = requests.get(server_url, params=params)\n        json_data = response.json()\n\n        if json_data['ok']:\n            print(f\"[{now}] 推送成功。\")\n        else:\n            print(f\"[{now}] 推送失败：{json_data['error_code']}({json_data['description']})\")\n\n\ndef wxpush(msg, usr, corpid, corpsecret, agentid=1000002):\n    \"\"\"\n    企业微信推送\n    \"\"\"\n    base_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?'\n    req_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token='\n    corpid = corpid\n    corpsecret = corpsecret\n    agentid = agentid\n\n    if agentid == 0:\n        agentid = 1000002\n\n    def get_access_token(_base_url, _corpid, _corpsecret):\n        \"\"\"\n        获取access_token，每次的access_token都不一样，所以需要运行一次请求一次\n        \"\"\"\n        urls = _base_url + 'corpid=' + _corpid + '&corpsecret=' + _corpsecret\n        resp = requests.get(urls).json()\n        access_token = resp['access_token']\n        return access_token\n\n    def send_message(_msg, _usr):\n        \"\"\"\n        发送消息\n        \"\"\"\n        data = get_message(_msg, _usr)\n        req_urls = req_url + get_access_token(base_url, corpid, corpsecret)\n        res = requests.post(url=req_urls, data=data)\n        ret = res.json()\n        if ret[\"errcode\"] == 0:\n            print(f\"[{now}] 企业微信推送成功\")\n        else:\n            print(f\"[{now}] 推送失败：{ret['errcode']} 错误信息：{ret['errmsg']}\")\n\n    def get_message(_msg, _usr):\n        \"\"\"\n        获取消息\n        \"\"\"\n        data = {\n            \"touser\": _usr,\n            \"toparty\": \"@all\",\n            \"totag\": \"@all\",\n            \"msgtype\": \"text\",\n            \"agentid\": agentid,\n            \"text\": {\n                \"content\": _msg\n            },\n            \"safe\": 0,\n            \"enable_id_trans\": 0,\n            \"enable_duplicate_check\": 0,\n            \"duplicate_check_interval\": 1800\n        }\n        data = json.dumps(data)\n        return data\n\n    msg = msg\n    usr = usr\n    if corpid == '':\n        print(\"[注意] 未提供corpid，不进行企业微信推送！\")\n    elif corpsecret == '':\n        print(\"[注意] 未提供corpsecret，不进行企业微信推送！\")\n    else:\n        send_message(msg, usr)\n\n\nclass ToPush:\n    \"\"\"\n    推送接口类\n    处理pkey并转发推送消息到推送函数\n    \"\"\"\n    push_msg: str\n\n    def __init__(self, _pkey):\n        self.pkey = _pkey\n\n    def to_push_wx(self):\n        \"\"\"\n        推送server酱接口\n        \"\"\"\n        if str(self.pkey) == '0':\n            self.pkey = ''\n        push_wx(self.pkey, self.push_msg)\n\n    def to_push_server(self):\n        \"\"\"\n        推送消息到微信接口\n        \"\"\"\n        if str(self.pkey) == '0':\n            self.pkey = ''\n        push_server(self.pkey, self.push_msg)\n\n    def to_push_tg(self):\n        \"\"\"\n        推送消息到TG接口\n        \"\"\"\n        try:\n            token, chat_id = self.pkey.split('@')\n            push_tg(token, chat_id, self.push_msg)\n        except ValueError:\n            print('tg推送参数有误！')\n\n    def to_wxpush(self):\n        \"\"\"\n        企业微信推送接口\n        \"\"\"\n        try:\n            usr, corpid, corpsecret, *agentid = self.pkey.split('-')\n            if agentid:\n                wxpush(self.push_msg, usr, corpid, corpsecret, int(agentid[0]))\n            else:\n                wxpush(self.push_msg, usr, corpid, corpsecret)\n        except ValueError:\n            print('企业微信推送参数有误！')\n\n    def to_push_pushplus(self):\n        \"\"\"\n        接口\n        \"\"\"\n        if self.pkey == '':\n            print('pushplus token错误')\n        else:\n            push_pushplus(self.pkey, self.push_msg)\n\n    @staticmethod\n    def no_push():\n        \"\"\"\n        不推送\n        \"\"\"\n        print('不推送')\n\n\nif __name__ == \"__main__\":\n    # Push Mode\n    # print(sys.argv)\n    try:\n        Pm = sys.argv[1]\n        pkey = sys.argv[2]\n\n        to_push = ToPush(pkey)\n\n        # 用户名（格式为 13800138000）\n        user = sys.argv[3]\n        # 登录密码\n        passwd = sys.argv[4]\n        # 要修改的步数，直接输入想要修改的步数值，0为随机步数\n        step = sys.argv[5].replace('[', '').replace(']', '')\n    except IndexError as e:\n        print(\"参数有误: \" + str(e))\n        exit(1)\n\n    user_list = user.split('#')\n    passwd_list = passwd.split('#')\n    setp_array = step.split('-')\n\n    if len(user_list) == len(passwd_list):\n        to_push.push_msg = ''\n        for user, passwd in zip(user_list, passwd_list):\n            if len(setp_array) == 2:\n                step = str(random.randint(int(setp_array[0]), int(setp_array[1])))\n                print(f\"已设置为随机步数（{setp_array[0]}-{setp_array[1]}）\")\n            elif str(step) == '0':\n                step = ''\n            to_push.push_msg += main(user, passwd, step) + '\\n'\n\n        push = {\n            'wx': to_push.to_push_wx,\n            'nwx': to_push.to_push_server,\n            'tg': to_push.to_push_tg,\n            'qwx': to_push.to_wxpush,\n            'pp': to_push.to_push_pushplus,\n            'off': to_push.no_push\n        }\n        try:\n            push[Pm]()\n        except KeyError:\n            print('推送选项有误！')\n            exit(0)\n    else:\n        print('用户名和密码数量不对')\n"
  },
  {
    "path": "xiaomisport-ql.py",
    "content": "\"\"\"\n主程序脚本\n\"\"\"\n# -*- coding: utf8 -*-\n# python >=3.8\n#环境变量: xppmode xppkey xpuser xppwd xpstep 使用方法：https://github.com/577fkj/mimotion.git\n\nimport json\nimport random\nimport re\nimport json\nimport sys\nimport os\nimport time\nfrom urllib.parse import quote\n\nimport requests\n\nnow = time.strftime(\"%Y-%m-%d %H:%M:%S\", time.localtime())\nheaders = {\n    'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 9; MI 6 MIUI/20.6.18)'\n}\n\n\ndef get_code(location):\n    \"\"\"\n    获取登录code\n    \"\"\"\n    code_pattern = re.compile(\"(?<=access=).*?(?=&)\")\n    code = code_pattern.findall(location)[0]\n    return code\n\n\ndef login(_user, password):\n    \"\"\"\n    登录\n    \"\"\"\n    url1 = \"https://api-user.huami.com/registrations/+86\" + _user + \"/tokens\"\n    _headers = {\n        \"Content-Type\": \"application/x-www-form-urlencoded;charset=UTF-8\",\n        \"User-Agent\": \"MiFit/4.6.0 (iPhone; iOS 14.0.1; Scale/2.00)\"\n    }\n    data1 = {\n        \"client_id\": \"HuaMi\",\n        \"password\": f\"{password}\",\n        \"redirect_uri\": \"https://s3-us-west-2.amazonaws.com/hm-registration/successsignin.html\",\n        \"token\": \"access\"\n    }\n    r1 = requests.post(url1, data=data1, headers=_headers, allow_redirects=False)\n    try:\n        location = r1.headers[\"Location\"]\n        code = get_code(location)\n    except:\n        return 0, 0\n    # print(\"access_code获取成功！\")\n    # print(code)\n\n    url2 = \"https://account.huami.com/v2/client/login\"\n    data2 = {\n        \"app_name\": \"com.xiaomi.hm.health\",\n        \"app_version\": \"4.6.0\",\n        \"code\": f\"{code}\",\n        \"country_code\": \"CN\",\n        \"device_id\": \"2C8B4939-0CCD-4E94-8CBA-CB8EA6E613A1\",\n        \"device_model\": \"phone\",\n        \"grant_type\": \"access_token\",\n        \"third_name\": \"huami_phone\",\n    }\n    r2 = requests.post(url2, data=data2, headers=_headers).json()\n    login_token = r2[\"token_info\"][\"login_token\"]\n    # print(\"login_token获取成功！\")\n    # print(login_token)\n    userid = r2[\"token_info\"][\"user_id\"]\n    # print(\"userid获取成功！\")\n    # print(userid)\n\n    return login_token, userid\n\n\ndef main(_user, _passwd, _step):\n    \"\"\"\n    主函数\n    \"\"\"\n    _user = str(_user)\n    password = str(_passwd)\n    _step = str(_step)\n    if _user == '' or password == '':\n        print(\"用户名或密码不能为空！\")\n        return \"user and passwd not empty！\"\n\n    if _step == '':\n        print(\"已设置为随机步数（10000-19999）\")\n        _step = str(random.randint(10000, 19999))\n    login_token, userid = login(_user, password)\n    if login_token == 0:\n        print(\"登陆失败！\")\n        return \"login fail!\"\n\n    t = get_time()\n\n    app_token = get_app_token(login_token)\n\n    today = time.strftime(\"%F\")\n\n    summary = {\n        \"v\": 6,\n        \"slp\": {\n            \"st\": int(time.time()),\n            \"ed\": int(time.time()),\n            \"dp\": 0,\n            \"lt\": 0,\n            \"wk\": 0,\n            \"usrSt\": -1440,\n            \"usrEd\": -1440,\n            \"wc\": 0,\n            \"is\": 0,\n            \"lb\": 0,\n            \"to\": 0,\n            \"dt\": 0,\n            \"rhr\": 0,\n            \"ss\": 0\n        },\n        \"stp\": {\n            \"ttl\": _step,\n            \"dis\": 10627,\n            \"cal\": 510,\n            \"wk\": 41,\n            \"rn\": 50,\n            \"runDist\": 7654,\n            \"runCal\": 397,\n            \"stage\": [\n                {\n                    \"start\": 327,\n                    \"stop\": 341,\n                    \"mode\": 1,\n                    \"dis\": 481,\n                    \"cal\": 13,\n                    \"step\": 680\n                },\n                {\n                    \"start\": 342,\n                    \"stop\": 367,\n                    \"mode\": 3,\n                    \"dis\": 2295,\n                    \"cal\": 95,\n                    \"step\": 2874\n                },\n                {\n                    \"start\": 368,\n                    \"stop\": 377,\n                    \"mode\": 4,\n                    \"dis\": 1592,\n                    \"cal\": 88,\n                    \"step\": 1664\n                },\n                {\n                    \"start\": 378,\n                    \"stop\": 386,\n                    \"mode\": 3,\n                    \"dis\": 1072,\n                    \"cal\": 51,\n                    \"step\": 1245\n                },\n                {\n                    \"start\": 387,\n                    \"stop\": 393,\n                    \"mode\": 4,\n                    \"dis\": 1036,\n                    \"cal\": 57,\n                    \"step\": 1124\n                },\n                {\n                    \"start\": 394,\n                    \"stop\": 398,\n                    \"mode\": 3,\n                    \"dis\": 488,\n                    \"cal\": 19,\n                    \"step\": 607\n                },\n                {\n                    \"start\": 399,\n                    \"stop\": 414,\n                    \"mode\": 4,\n                    \"dis\": 2220,\n                    \"cal\": 120,\n                    \"step\": 2371\n                },\n                {\n                    \"start\": 415,\n                    \"stop\": 427,\n                    \"mode\": 3,\n                    \"dis\": 1268,\n                    \"cal\": 59,\n                    \"step\": 1489\n                },\n                {\n                    \"start\": 428,\n                    \"stop\": 433,\n                    \"mode\": 1,\n                    \"dis\": 152,\n                    \"cal\": 4,\n                    \"step\": 238\n                },\n                {\n                    \"start\": 434,\n                    \"stop\": 444,\n                    \"mode\": 3,\n                    \"dis\": 2295,\n                    \"cal\": 95,\n                    \"step\": 2874\n                },\n                {\n                    \"start\": 445,\n                    \"stop\": 455,\n                    \"mode\": 4,\n                    \"dis\": 1592,\n                    \"cal\": 88,\n                    \"step\": 1664\n                },\n                {\n                    \"start\": 456,\n                    \"stop\": 466,\n                    \"mode\": 3,\n                    \"dis\": 1072,\n                    \"cal\": 51,\n                    \"step\": 1245\n                },\n                {\n                    \"start\": 467,\n                    \"stop\": 477,\n                    \"mode\": 4,\n                    \"dis\": 1036,\n                    \"cal\": 57,\n                    \"step\": 1124\n                },\n                {\n                    \"start\": 478,\n                    \"stop\": 488,\n                    \"mode\": 3,\n                    \"dis\": 488,\n                    \"cal\": 19,\n                    \"step\": 607\n                },\n                {\n                    \"start\": 489,\n                    \"stop\": 499,\n                    \"mode\": 4,\n                    \"dis\": 2220,\n                    \"cal\": 120,\n                    \"step\": 2371\n                },\n                {\n                    \"start\": 500,\n                    \"stop\": 511,\n                    \"mode\": 3,\n                    \"dis\": 1268,\n                    \"cal\": 59,\n                    \"step\": 1489\n                },\n                {\n                    \"start\": 512,\n                    \"stop\": 522,\n                    \"mode\": 1,\n                    \"dis\": 152,\n                    \"cal\": 4,\n                    \"step\": 238\n                }\n            ]\n        },\n        \"goal\": 8000,\n        \"tz\": \"28800\"\n    }\n\n    data_json = [\n        {\n            \"data_hr\": \"//////9L////////////Vv///////////0v///////////9e/////0n/a///S////////////0b//////////1FK////////////R/////////////////9PTFFpaf9L////////////R////////////0j///////////9K////////////Ov///////////zf///86/zr/Ov88/zf/Pf///0v/S/8/////////////Sf///////////z3//////0r/Ov//////S/9L/zb/Sf9K/0v/Rf9H/zj/Sf9K/0//N////0D/Sf83/zr/Pf9M/0v/Ov9e////////////S////////////zv//z7/O/83/zv/N/83/zr/N/86/z//Nv83/zn/Xv84/zr/PP84/zj/N/9e/zr/N/89/03/P/89/z3/Q/9N/0v/Tv9C/0H/Of9D/zz/Of88/z//PP9A/zr/N/86/zz/Nv87/0D/Ov84/0v/O/84/zf/MP83/zH/Nv83/zf/N/84/zf/Of82/zf/OP83/zb/Mv81/zX/R/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/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+\",\n            \"date\": today,\n            \"data\": [\n                {\n                    \"start\": 0,\n                    \"stop\": 1439,\n                    \"value\": \"UA8AUBQAUAwAUBoAUAEAYCcAUBkAUB4AUBgAUCAAUAEAUBkAUAwAYAsAYB8AYB0AYBgAYCoAYBgAYB4AUCcAUBsAUB8AUBwAUBIAYBkAYB8AUBoAUBMAUCEAUCIAYBYAUBwAUCAAUBgAUCAAUBcAYBsAYCUAATIPYD0KECQAYDMAYB0AYAsAYCAAYDwAYCIAYB0AYBcAYCQAYB0AYBAAYCMAYAoAYCIAYCEAYCYAYBsAYBUAYAYAYCIAYCMAUB0AUCAAUBYAUCoAUBEAUC8AUB0AUBYAUDMAUDoAUBkAUC0AUBQAUBwAUA0AUBsAUAoAUCEAUBYAUAwAUB4AUAwAUCcAUCYAUCwKYDUAAUUlEC8IYEMAYEgAYDoAYBAAUAMAUBkAWgAAWgAAWgAAWgAAWgAAUAgAWgAAUBAAUAQAUA4AUA8AUAkAUAIAUAYAUAcAUAIAWgAAUAQAUAkAUAEAUBkAUCUAWgAAUAYAUBEAWgAAUBYAWgAAUAYAWgAAWgAAWgAAWgAAUBcAUAcAWgAAUBUAUAoAUAIAWgAAUAQAUAYAUCgAWgAAUAgAWgAAWgAAUAwAWwAAXCMAUBQAWwAAUAIAWgAAWgAAWgAAWgAAWgAAWgAAWgAAWgAAWREAWQIAUAMAWSEAUDoAUDIAUB8AUCEAUC4AXB4AUA4AW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 24\n                }\n            ],\n            \"summary\": json.dumps(summary),\n            \"source\": 24,\n            \"type\": 0\n        }\n    ]\n\n    url = f'https://api-mifit-cn.huami.com/v1/data/band_data.json?&t={t}'\n    head = {\n        \"apptoken\": app_token,\n        \"Content-Type\": \"application/x-www-form-urlencoded\"\n    }\n\n    data = f'userid={userid}&last_sync_data_time=1597306380&device_type=0&last_deviceid=DA932FFFFE8816E7&data_json={quote(json.dumps(data_json))}'\n\n    response = requests.post(url, data=data, headers=head).json()\n    # print(response)\n    result = f\"{_user[:4]}****{_user[-4:]}: [{now}] 修改步数（{_step}）\" + response['message']\n    print(result)\n    return result\n\n\ndef get_time():\n    \"\"\"\n    获取时间戳\n    \"\"\"\n    url = 'http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp'\n    response = requests.get(url, headers=headers).json()\n    t = response['data']['t']\n    return t\n\n\ndef get_app_token(login_token):\n    \"\"\"\n    获取app_token\n    \"\"\"\n    url = f\"https://account-cn.huami.com/v1/client/app_tokens\" \\\n          f\"?app_name=com.xiaomi.hm.health&dn=api-user.huami.com%2Capi-mifit.huami.com%2Capp-analytics.huami.com\" \\\n          f\"&login_token={login_token}\"\n    response = requests.get(url, headers=headers).json()\n    app_token = response['token_info']['app_token']\n    # print(\"app_token获取成功！\")\n    # print(app_token)\n    return app_token\n\n\ndef push_wx(_sckey, desp=\"\"):\n    \"\"\"\n    推送server酱\n    \"\"\"\n    if _sckey == '':\n        print(\"[注意] 未提供sckey，不进行推送！\")\n    else:\n        server_url = f\"https://sc.ftqq.com/{_sckey}.send\"\n        params = {\n            \"text\": '小米运动 步数修改',\n            \"desp\": desp\n        }\n\n        response = requests.get(server_url, params=params)\n        json_data = response.json()\n\n        if json_data['errno'] == 0:\n            print(f\"[{now}] 推送成功。\")\n        else:\n            print(f\"[{now}] 推送失败：{json_data['errno']}({json_data['errmsg']})\")\n\n\ndef push_server(_sckey, desp=\"\"):\n    \"\"\"\n    推送消息到微信\n    \"\"\"\n    if _sckey == '':\n        print(\"[注意] 未提供sckey，不进行微信推送！\")\n    else:\n        server_url = f\"https://sctapi.ftqq.com/{_sckey}.send\"\n        params = {\n            \"title\": '小米运动 步数修改',\n            \"desp\": desp\n        }\n\n        response = requests.get(server_url, params=params)\n        json_data = response.json()\n\n        if json_data['code'] == 0:\n            print(f\"[{now}] 推送成功。\")\n        else:\n            print(f\"[{now}] 推送失败：{json_data['code']}({json_data['message']})\")\n\n\ndef push_pushplus(token, content=\"\"):\n    \"\"\"\n    推送消息到pushplus\n    \"\"\"\n    if token == '':\n        print(\"[注意] 未提供token，不进行pushplus推送！\")\n    else:\n        server_url = \"http://www.pushplus.plus/send\"\n        params = {\n            \"token\": token,\n            \"title\": '小米运动 步数修改',\n            \"content\": content\n        }\n\n        response = requests.get(server_url, params=params)\n        json_data = response.json()\n\n        if json_data['code'] == 200:\n            print(f\"[{now}] 推送成功。\")\n        else:\n            print(f\"[{now}] 推送失败：{json_data['code']}({json_data['message']})\")\n\n\ndef push_tg(token, chat_id, desp=\"\"):\n    \"\"\"\n    推送消息到TG\n    \"\"\"\n    if token == '':\n        print(\"[注意] 未提供token，不进行tg推送！\")\n    elif chat_id == '':\n        print(\"[注意] 未提供chat_id，不进行tg推送！\")\n    else:\n        server_url = f\"https://api.telegram.org/bot{token}/sendmessage\"\n        params = {\n            \"text\": '小米运动 步数修改\\n\\n' + desp,\n            \"chat_id\": chat_id\n        }\n\n        response = requests.get(server_url, params=params)\n        json_data = response.json()\n\n        if json_data['ok']:\n            print(f\"[{now}] 推送成功。\")\n        else:\n            print(f\"[{now}] 推送失败：{json_data['error_code']}({json_data['description']})\")\n\n\ndef wxpush(msg, usr, corpid, corpsecret, agentid=1000002):\n    \"\"\"\n    企业微信推送\n    \"\"\"\n    base_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?'\n    req_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token='\n    corpid = corpid\n    corpsecret = corpsecret\n    agentid = agentid\n\n    if agentid == 0:\n        agentid = 1000002\n\n    def get_access_token(_base_url, _corpid, _corpsecret):\n        \"\"\"\n        获取access_token，每次的access_token都不一样，所以需要运行一次请求一次\n        \"\"\"\n        urls = _base_url + 'corpid=' + _corpid + '&corpsecret=' + _corpsecret\n        resp = requests.get(urls).json()\n        access_token = resp['access_token']\n        return access_token\n\n    def send_message(_msg, _usr):\n        \"\"\"\n        发送消息\n        \"\"\"\n        data = get_message(_msg, _usr)\n        req_urls = req_url + get_access_token(base_url, corpid, corpsecret)\n        res = requests.post(url=req_urls, data=data)\n        ret = res.json()\n        if ret[\"errcode\"] == 0:\n            print(f\"[{now}] 企业微信推送成功\")\n        else:\n            print(f\"[{now}] 推送失败：{ret['errcode']} 错误信息：{ret['errmsg']}\")\n\n    def get_message(_msg, _usr):\n        \"\"\"\n        获取消息\n        \"\"\"\n        data = {\n            \"touser\": _usr,\n            \"toparty\": \"@all\",\n            \"totag\": \"@all\",\n            \"msgtype\": \"text\",\n            \"agentid\": agentid,\n            \"text\": {\n                \"content\": _msg\n            },\n            \"safe\": 0,\n            \"enable_id_trans\": 0,\n            \"enable_duplicate_check\": 0,\n            \"duplicate_check_interval\": 1800\n        }\n        data = json.dumps(data)\n        return data\n\n    msg = msg\n    usr = usr\n    if corpid == '':\n        print(\"[注意] 未提供corpid，不进行企业微信推送！\")\n    elif corpsecret == '':\n        print(\"[注意] 未提供corpsecret，不进行企业微信推送！\")\n    else:\n        send_message(msg, usr)\n\n\nclass ToPush:\n    \"\"\"\n    推送接口类\n    处理pkey并转发推送消息到推送函数\n    \"\"\"\n    push_msg: str\n\n    def __init__(self, _pkey):\n        self.pkey = _pkey\n\n    def to_push_wx(self):\n        \"\"\"\n        推送server酱接口\n        \"\"\"\n        if str(self.pkey) == '0':\n            self.pkey = ''\n        push_wx(self.pkey, self.push_msg)\n\n    def to_push_server(self):\n        \"\"\"\n        推送消息到微信接口\n        \"\"\"\n        if str(self.pkey) == '0':\n            self.pkey = ''\n        push_server(self.pkey, self.push_msg)\n\n    def to_push_tg(self):\n        \"\"\"\n        推送消息到TG接口\n        \"\"\"\n        try:\n            token, chat_id = self.pkey.split('@')\n            push_tg(token, chat_id, self.push_msg)\n        except ValueError:\n            print('tg推送参数有误！')\n\n    def to_wxpush(self):\n        \"\"\"\n        企业微信推送接口\n        \"\"\"\n        try:\n            usr, corpid, corpsecret, *agentid = self.pkey.split('-')\n            if agentid:\n                wxpush(self.push_msg, usr, corpid, corpsecret, int(agentid[0]))\n            else:\n                wxpush(self.push_msg, usr, corpid, corpsecret)\n        except ValueError:\n            print('企业微信推送参数有误！')\n\n    def to_push_pushplus(self):\n        \"\"\"\n        接口\n        \"\"\"\n        if self.pkey == '':\n            print('pushplus token错误')\n        else:\n            push_pushplus(self.pkey, self.push_msg)\n\n    @staticmethod\n    def no_push():\n        \"\"\"\n        不推送\n        \"\"\"\n        print('不推送')\n\n\nif __name__ == \"__main__\":\n    # Push Mode\n    # print(sys.argv)\n    try:\n        Pm = os.environ[\"xppmode\"]\n        #sys.argv[1]\n        pkey = os.environ[\"xppkey\"]\n        #sys.argv[2]\n\n        to_push = ToPush(pkey)\n\n        # 用户名（格式为 13800138000）\n        user = os.environ[\"xpuser\"]\n        #sys.argv[3]\n        # 登录密码\n        passwd = os.environ[\"xppwd\"]\n        #sys.argv[4]\n        # 要修改的步数，直接输入想要修改的步数值，0为随机步数\n        step = os.environ[\"xpstep\"].replace('[', '').replace(']', '')\n        #sys.argv[5].replace('[', '').replace(']', '')\n    except IndexError as e:\n        print(\"参数有误: \" + str(e))\n        exit(1)\n\n    user_list = user.split('#')\n    passwd_list = passwd.split('#')\n    setp_array = step.split('-')\n\n    if len(user_list) == len(passwd_list):\n        to_push.push_msg = ''\n        for user, passwd in zip(user_list, passwd_list):\n            if len(setp_array) == 2:\n                step = str(random.randint(int(setp_array[0]), int(setp_array[1])))\n                print(f\"已设置为随机步数（{setp_array[0]}-{setp_array[1]}）\")\n            elif str(step) == '0':\n                step = ''\n            to_push.push_msg += main(user, passwd, step) + '\\n'\n\n        push = {\n            'wx': to_push.to_push_wx,\n            'nwx': to_push.to_push_server,\n            'tg': to_push.to_push_tg,\n            'qwx': to_push.to_wxpush,\n            'pp': to_push.to_push_pushplus,\n            'off': to_push.no_push\n        }\n        try:\n            push[Pm]()\n        except KeyError:\n            print('推送选项有误！')\n            exit(0)\n    else:\n        print('用户名和密码数量不对')\n"
  }
]