├── .gitattributes ├── README.md ├── .github ├── pull.yml └── workflows │ └── run.yml ├── TG_PUSH.md ├── LICENSE ├── main.py └── xiaomisport-ql.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 小米运动自动刷步数 2 | 请移步至 [原作:方块君577fkj](https://github.com/577fkj/mimotion) 3 | 4 | # run 跑起来 5 | -------------------------------------------------------------------------------- /.github/pull.yml: -------------------------------------------------------------------------------- 1 | version: "1" 2 | rules: # Array of rules 3 | - base: main # Required. Target branch 4 | upstream: Squaregentleman:main # Required. Must be in the same fork network. 5 | mergeMethod: hardreset # Optional, one of [none, merge, squash, rebase, hardreset], Default: none. 6 | mergeUnstable: true # Optional, merge pull request even when the mergeable_state is not clean. Default: false 7 | -------------------------------------------------------------------------------- /TG_PUSH.md: -------------------------------------------------------------------------------- 1 | **TG_PUSH教程** 2 | 3 | 如何获取token以及UserID 4 | 5 | Ⅰ.首先在Telegram上搜索[BotFather](https://t.me/BotFather)机器人
6 | 7 | ![TG_PUSH1](https://gitee.com/lxk0301/jd_docker/raw/master/icon/TG_PUSH1.png) 8 | 9 | Ⅱ.利用[BotFather](https://t.me/BotFather)创建一个属于自己的通知机器人,按照下图中的1、2、3步骤拿到token,格式形如```10xxx4:AAFcqxxxxgER5uw```。
10 | 11 | ![TG_PUSH2](https://gitee.com/lxk0301/jd_docker/raw/master/icon/TG_PUSH2.png)
12 | 13 | **新创建的机器人需要跟它发一条消息来开启对话,否则可能会遇到PEKY填对了但是收不到消息的情况**
14 | 15 | Ⅲ.再次在Telegram上搜索[getuserIDbot](https://t.me/getuserIDbot)机器人,获取UserID。
16 | 17 | ![TG_PUSH3](https://gitee.com/lxk0301/jd_docker/raw/master/icon/TG_PUSH3.png) 18 | -------------------------------------------------------------------------------- /.github/workflows/run.yml: -------------------------------------------------------------------------------- 1 | name: 刷步数 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | schedule: 9 | - cron: 0 9 * * * 10 | watch: 11 | types: started 12 | 13 | jobs: 14 | build: 15 | runs-on: ubuntu-latest 16 | if: github.event.repository.owner.id == github.event.sender.id 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | - name: 初始化Python 21 | uses: actions/setup-python@v2 22 | with: 23 | python-version: 3.7 24 | - name: 开始 25 | run: | 26 | pip install requests 27 | pmode='${{ secrets.PMODE }}' 28 | pkey='${{ secrets.PKEY }}' 29 | user='${{ secrets.USER }}' 30 | pwd='${{ secrets.PWD }}' 31 | step='${{ secrets.STEP }}' 32 | python3 main.py ${pmode} ${pkey} ${user} ${pwd} ${step} 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | """ 2 | 主程序脚本 3 | """ 4 | # -*- coding: utf8 -*- 5 | # python >=3.8 6 | 7 | import json 8 | import random 9 | import re 10 | import json 11 | import sys 12 | import time 13 | from urllib.parse import quote 14 | 15 | import requests 16 | 17 | now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 18 | headers = { 19 | 'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 9; MI 6 MIUI/20.6.18)' 20 | } 21 | 22 | 23 | def get_code(location): 24 | """ 25 | 获取登录code 26 | """ 27 | code_pattern = re.compile("(?<=access=).*?(?=&)") 28 | code = code_pattern.findall(location)[0] 29 | return code 30 | 31 | 32 | def login(_user, password): 33 | """ 34 | 登录 35 | """ 36 | url1 = "https://api-user.huami.com/registrations/+86" + _user + "/tokens" 37 | _headers = { 38 | "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", 39 | "User-Agent": "MiFit/4.6.0 (iPhone; iOS 14.0.1; Scale/2.00)" 40 | } 41 | data1 = { 42 | "client_id": "HuaMi", 43 | "password": f"{password}", 44 | "redirect_uri": "https://s3-us-west-2.amazonaws.com/hm-registration/successsignin.html", 45 | "token": "access" 46 | } 47 | r1 = requests.post(url1, data=data1, headers=_headers, allow_redirects=False) 48 | try: 49 | location = r1.headers["Location"] 50 | code = get_code(location) 51 | except: 52 | return 0, 0 53 | # print("access_code获取成功!") 54 | # print(code) 55 | 56 | url2 = "https://account.huami.com/v2/client/login" 57 | data2 = { 58 | "app_name": "com.xiaomi.hm.health", 59 | "app_version": "4.6.0", 60 | "code": f"{code}", 61 | "country_code": "CN", 62 | "device_id": "2C8B4939-0CCD-4E94-8CBA-CB8EA6E613A1", 63 | "device_model": "phone", 64 | "grant_type": "access_token", 65 | "third_name": "huami_phone", 66 | } 67 | r2 = requests.post(url2, data=data2, headers=_headers).json() 68 | login_token = r2["token_info"]["login_token"] 69 | # print("login_token获取成功!") 70 | # print(login_token) 71 | userid = r2["token_info"]["user_id"] 72 | # print("userid获取成功!") 73 | # print(userid) 74 | 75 | return login_token, userid 76 | 77 | 78 | def main(_user, _passwd, _step): 79 | """ 80 | 主函数 81 | """ 82 | _user = str(_user) 83 | password = str(_passwd) 84 | _step = str(_step) 85 | if _user == '' or password == '': 86 | print("用户名或密码不能为空!") 87 | return "user and passwd not empty!" 88 | 89 | if _step == '': 90 | print("已设置为随机步数(10000-19999)") 91 | _step = str(random.randint(10000, 19999)) 92 | login_token, userid = login(_user, password) 93 | if login_token == 0: 94 | print("登陆失败!") 95 | return "login fail!" 96 | 97 | t = get_time() 98 | 99 | app_token = get_app_token(login_token) 100 | 101 | today = time.strftime("%F") 102 | 103 | summary = { 104 | "v": 6, 105 | "slp": { 106 | "st": int(time.time()), 107 | "ed": int(time.time()), 108 | "dp": 0, 109 | "lt": 0, 110 | "wk": 0, 111 | "usrSt": -1440, 112 | "usrEd": -1440, 113 | "wc": 0, 114 | "is": 0, 115 | "lb": 0, 116 | "to": 0, 117 | "dt": 0, 118 | "rhr": 0, 119 | "ss": 0 120 | }, 121 | "stp": { 122 | "ttl": _step, 123 | "dis": 10627, 124 | "cal": 510, 125 | "wk": 41, 126 | "rn": 50, 127 | "runDist": 7654, 128 | "runCal": 397, 129 | "stage": [ 130 | { 131 | "start": 327, 132 | "stop": 341, 133 | "mode": 1, 134 | "dis": 481, 135 | "cal": 13, 136 | "step": 680 137 | }, 138 | { 139 | "start": 342, 140 | "stop": 367, 141 | "mode": 3, 142 | "dis": 2295, 143 | "cal": 95, 144 | "step": 2874 145 | }, 146 | { 147 | "start": 368, 148 | "stop": 377, 149 | "mode": 4, 150 | "dis": 1592, 151 | "cal": 88, 152 | "step": 1664 153 | }, 154 | { 155 | "start": 378, 156 | "stop": 386, 157 | "mode": 3, 158 | "dis": 1072, 159 | "cal": 51, 160 | "step": 1245 161 | }, 162 | { 163 | "start": 387, 164 | "stop": 393, 165 | "mode": 4, 166 | "dis": 1036, 167 | "cal": 57, 168 | "step": 1124 169 | }, 170 | { 171 | "start": 394, 172 | "stop": 398, 173 | "mode": 3, 174 | "dis": 488, 175 | "cal": 19, 176 | "step": 607 177 | }, 178 | { 179 | "start": 399, 180 | "stop": 414, 181 | "mode": 4, 182 | "dis": 2220, 183 | "cal": 120, 184 | "step": 2371 185 | }, 186 | { 187 | "start": 415, 188 | "stop": 427, 189 | "mode": 3, 190 | "dis": 1268, 191 | "cal": 59, 192 | "step": 1489 193 | }, 194 | { 195 | "start": 428, 196 | "stop": 433, 197 | "mode": 1, 198 | "dis": 152, 199 | "cal": 4, 200 | "step": 238 201 | }, 202 | { 203 | "start": 434, 204 | "stop": 444, 205 | "mode": 3, 206 | "dis": 2295, 207 | "cal": 95, 208 | "step": 2874 209 | }, 210 | { 211 | "start": 445, 212 | "stop": 455, 213 | "mode": 4, 214 | "dis": 1592, 215 | "cal": 88, 216 | "step": 1664 217 | }, 218 | { 219 | "start": 456, 220 | "stop": 466, 221 | "mode": 3, 222 | "dis": 1072, 223 | "cal": 51, 224 | "step": 1245 225 | }, 226 | { 227 | "start": 467, 228 | "stop": 477, 229 | "mode": 4, 230 | "dis": 1036, 231 | "cal": 57, 232 | "step": 1124 233 | }, 234 | { 235 | "start": 478, 236 | "stop": 488, 237 | "mode": 3, 238 | "dis": 488, 239 | "cal": 19, 240 | "step": 607 241 | }, 242 | { 243 | "start": 489, 244 | "stop": 499, 245 | "mode": 4, 246 | "dis": 2220, 247 | "cal": 120, 248 | "step": 2371 249 | }, 250 | { 251 | "start": 500, 252 | "stop": 511, 253 | "mode": 3, 254 | "dis": 1268, 255 | "cal": 59, 256 | "step": 1489 257 | }, 258 | { 259 | "start": 512, 260 | "stop": 522, 261 | "mode": 1, 262 | "dis": 152, 263 | "cal": 4, 264 | "step": 238 265 | } 266 | ] 267 | }, 268 | "goal": 8000, 269 | "tz": "28800" 270 | } 271 | 272 | data_json = [ 273 | { 274 | "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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fgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAA", 281 | "tz": 32, 282 | "did": "DA932FFFFE8816E7", 283 | "src": 24 284 | } 285 | ], 286 | "summary": json.dumps(summary), 287 | "source": 24, 288 | "type": 0 289 | } 290 | ] 291 | 292 | url = f'https://api-mifit-cn.huami.com/v1/data/band_data.json?&t={t}' 293 | head = { 294 | "apptoken": app_token, 295 | "Content-Type": "application/x-www-form-urlencoded" 296 | } 297 | 298 | data = f'userid={userid}&last_sync_data_time=1597306380&device_type=0&last_deviceid=DA932FFFFE8816E7&data_json={quote(json.dumps(data_json))}' 299 | 300 | response = requests.post(url, data=data, headers=head).json() 301 | # print(response) 302 | result = f"{_user[:4]}****{_user[-4:]}: [{now}] 修改步数({_step})" + response['message'] 303 | print(result) 304 | return result 305 | 306 | 307 | def get_time(): 308 | """ 309 | 获取时间戳 310 | """ 311 | url = 'http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp' 312 | response = requests.get(url, headers=headers).json() 313 | t = response['data']['t'] 314 | return t 315 | 316 | 317 | def get_app_token(login_token): 318 | """ 319 | 获取app_token 320 | """ 321 | url = f"https://account-cn.huami.com/v1/client/app_tokens" \ 322 | f"?app_name=com.xiaomi.hm.health&dn=api-user.huami.com%2Capi-mifit.huami.com%2Capp-analytics.huami.com" \ 323 | f"&login_token={login_token}" 324 | response = requests.get(url, headers=headers).json() 325 | app_token = response['token_info']['app_token'] 326 | # print("app_token获取成功!") 327 | # print(app_token) 328 | return app_token 329 | 330 | 331 | def push_wx(_sckey, desp=""): 332 | """ 333 | 推送server酱 334 | """ 335 | if _sckey == '': 336 | print("[注意] 未提供sckey,不进行推送!") 337 | else: 338 | server_url = f"https://sc.ftqq.com/{_sckey}.send" 339 | params = { 340 | "text": '小米运动 步数修改', 341 | "desp": desp 342 | } 343 | 344 | response = requests.get(server_url, params=params) 345 | json_data = response.json() 346 | 347 | if json_data['errno'] == 0: 348 | print(f"[{now}] 推送成功。") 349 | else: 350 | print(f"[{now}] 推送失败:{json_data['errno']}({json_data['errmsg']})") 351 | 352 | 353 | def push_server(_sckey, desp=""): 354 | """ 355 | 推送消息到微信 356 | """ 357 | if _sckey == '': 358 | print("[注意] 未提供sckey,不进行微信推送!") 359 | else: 360 | server_url = f"https://sctapi.ftqq.com/{_sckey}.send" 361 | params = { 362 | "title": '小米运动 步数修改', 363 | "desp": desp 364 | } 365 | 366 | response = requests.get(server_url, params=params) 367 | json_data = response.json() 368 | 369 | if json_data['code'] == 0: 370 | print(f"[{now}] 推送成功。") 371 | else: 372 | print(f"[{now}] 推送失败:{json_data['code']}({json_data['message']})") 373 | 374 | 375 | def push_pushplus(token, content=""): 376 | """ 377 | 推送消息到pushplus 378 | """ 379 | if token == '': 380 | print("[注意] 未提供token,不进行pushplus推送!") 381 | else: 382 | server_url = "http://www.pushplus.plus/send" 383 | params = { 384 | "token": token, 385 | "title": '小米运动 步数修改', 386 | "content": content 387 | } 388 | 389 | response = requests.get(server_url, params=params) 390 | json_data = response.json() 391 | 392 | if json_data['code'] == 200: 393 | print(f"[{now}] 推送成功。") 394 | else: 395 | print(f"[{now}] 推送失败:{json_data['code']}({json_data['message']})") 396 | 397 | 398 | def push_tg(token, chat_id, desp=""): 399 | """ 400 | 推送消息到TG 401 | """ 402 | if token == '': 403 | print("[注意] 未提供token,不进行tg推送!") 404 | elif chat_id == '': 405 | print("[注意] 未提供chat_id,不进行tg推送!") 406 | else: 407 | server_url = f"https://api.telegram.org/bot{token}/sendmessage" 408 | params = { 409 | "text": '小米运动 步数修改\n\n' + desp, 410 | "chat_id": chat_id 411 | } 412 | 413 | response = requests.get(server_url, params=params) 414 | json_data = response.json() 415 | 416 | if json_data['ok']: 417 | print(f"[{now}] 推送成功。") 418 | else: 419 | print(f"[{now}] 推送失败:{json_data['error_code']}({json_data['description']})") 420 | 421 | 422 | def wxpush(msg, usr, corpid, corpsecret, agentid=1000002): 423 | """ 424 | 企业微信推送 425 | """ 426 | base_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?' 427 | req_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' 428 | corpid = corpid 429 | corpsecret = corpsecret 430 | agentid = agentid 431 | 432 | if agentid == 0: 433 | agentid = 1000002 434 | 435 | def get_access_token(_base_url, _corpid, _corpsecret): 436 | """ 437 | 获取access_token,每次的access_token都不一样,所以需要运行一次请求一次 438 | """ 439 | urls = _base_url + 'corpid=' + _corpid + '&corpsecret=' + _corpsecret 440 | resp = requests.get(urls).json() 441 | access_token = resp['access_token'] 442 | return access_token 443 | 444 | def send_message(_msg, _usr): 445 | """ 446 | 发送消息 447 | """ 448 | data = get_message(_msg, _usr) 449 | req_urls = req_url + get_access_token(base_url, corpid, corpsecret) 450 | res = requests.post(url=req_urls, data=data) 451 | ret = res.json() 452 | if ret["errcode"] == 0: 453 | print(f"[{now}] 企业微信推送成功") 454 | else: 455 | print(f"[{now}] 推送失败:{ret['errcode']} 错误信息:{ret['errmsg']}") 456 | 457 | def get_message(_msg, _usr): 458 | """ 459 | 获取消息 460 | """ 461 | data = { 462 | "touser": _usr, 463 | "toparty": "@all", 464 | "totag": "@all", 465 | "msgtype": "text", 466 | "agentid": agentid, 467 | "text": { 468 | "content": _msg 469 | }, 470 | "safe": 0, 471 | "enable_id_trans": 0, 472 | "enable_duplicate_check": 0, 473 | "duplicate_check_interval": 1800 474 | } 475 | data = json.dumps(data) 476 | return data 477 | 478 | msg = msg 479 | usr = usr 480 | if corpid == '': 481 | print("[注意] 未提供corpid,不进行企业微信推送!") 482 | elif corpsecret == '': 483 | print("[注意] 未提供corpsecret,不进行企业微信推送!") 484 | else: 485 | send_message(msg, usr) 486 | 487 | 488 | class ToPush: 489 | """ 490 | 推送接口类 491 | 处理pkey并转发推送消息到推送函数 492 | """ 493 | push_msg: str 494 | 495 | def __init__(self, _pkey): 496 | self.pkey = _pkey 497 | 498 | def to_push_wx(self): 499 | """ 500 | 推送server酱接口 501 | """ 502 | if str(self.pkey) == '0': 503 | self.pkey = '' 504 | push_wx(self.pkey, self.push_msg) 505 | 506 | def to_push_server(self): 507 | """ 508 | 推送消息到微信接口 509 | """ 510 | if str(self.pkey) == '0': 511 | self.pkey = '' 512 | push_server(self.pkey, self.push_msg) 513 | 514 | def to_push_tg(self): 515 | """ 516 | 推送消息到TG接口 517 | """ 518 | try: 519 | token, chat_id = self.pkey.split('@') 520 | push_tg(token, chat_id, self.push_msg) 521 | except ValueError: 522 | print('tg推送参数有误!') 523 | 524 | def to_wxpush(self): 525 | """ 526 | 企业微信推送接口 527 | """ 528 | try: 529 | usr, corpid, corpsecret, *agentid = self.pkey.split('-') 530 | if agentid: 531 | wxpush(self.push_msg, usr, corpid, corpsecret, int(agentid[0])) 532 | else: 533 | wxpush(self.push_msg, usr, corpid, corpsecret) 534 | except ValueError: 535 | print('企业微信推送参数有误!') 536 | 537 | def to_push_pushplus(self): 538 | """ 539 | 接口 540 | """ 541 | if self.pkey == '': 542 | print('pushplus token错误') 543 | else: 544 | push_pushplus(self.pkey, self.push_msg) 545 | 546 | @staticmethod 547 | def no_push(): 548 | """ 549 | 不推送 550 | """ 551 | print('不推送') 552 | 553 | 554 | if __name__ == "__main__": 555 | # Push Mode 556 | # print(sys.argv) 557 | try: 558 | Pm = sys.argv[1] 559 | pkey = sys.argv[2] 560 | 561 | to_push = ToPush(pkey) 562 | 563 | # 用户名(格式为 13800138000) 564 | user = sys.argv[3] 565 | # 登录密码 566 | passwd = sys.argv[4] 567 | # 要修改的步数,直接输入想要修改的步数值,0为随机步数 568 | step = sys.argv[5].replace('[', '').replace(']', '') 569 | except IndexError as e: 570 | print("参数有误: " + str(e)) 571 | exit(1) 572 | 573 | user_list = user.split('#') 574 | passwd_list = passwd.split('#') 575 | setp_array = step.split('-') 576 | 577 | if len(user_list) == len(passwd_list): 578 | to_push.push_msg = '' 579 | for user, passwd in zip(user_list, passwd_list): 580 | if len(setp_array) == 2: 581 | step = str(random.randint(int(setp_array[0]), int(setp_array[1]))) 582 | print(f"已设置为随机步数({setp_array[0]}-{setp_array[1]})") 583 | elif str(step) == '0': 584 | step = '' 585 | to_push.push_msg += main(user, passwd, step) + '\n' 586 | 587 | push = { 588 | 'wx': to_push.to_push_wx, 589 | 'nwx': to_push.to_push_server, 590 | 'tg': to_push.to_push_tg, 591 | 'qwx': to_push.to_wxpush, 592 | 'pp': to_push.to_push_pushplus, 593 | 'off': to_push.no_push 594 | } 595 | try: 596 | push[Pm]() 597 | except KeyError: 598 | print('推送选项有误!') 599 | exit(0) 600 | else: 601 | print('用户名和密码数量不对') 602 | -------------------------------------------------------------------------------- /xiaomisport-ql.py: -------------------------------------------------------------------------------- 1 | """ 2 | 主程序脚本 3 | """ 4 | # -*- coding: utf8 -*- 5 | # python >=3.8 6 | #环境变量: xppmode xppkey xpuser xppwd xpstep 使用方法:https://github.com/577fkj/mimotion.git 7 | 8 | import json 9 | import random 10 | import re 11 | import json 12 | import sys 13 | import os 14 | import time 15 | from urllib.parse import quote 16 | 17 | import requests 18 | 19 | now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 20 | headers = { 21 | 'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 9; MI 6 MIUI/20.6.18)' 22 | } 23 | 24 | 25 | def get_code(location): 26 | """ 27 | 获取登录code 28 | """ 29 | code_pattern = re.compile("(?<=access=).*?(?=&)") 30 | code = code_pattern.findall(location)[0] 31 | return code 32 | 33 | 34 | def login(_user, password): 35 | """ 36 | 登录 37 | """ 38 | url1 = "https://api-user.huami.com/registrations/+86" + _user + "/tokens" 39 | _headers = { 40 | "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", 41 | "User-Agent": "MiFit/4.6.0 (iPhone; iOS 14.0.1; Scale/2.00)" 42 | } 43 | data1 = { 44 | "client_id": "HuaMi", 45 | "password": f"{password}", 46 | "redirect_uri": "https://s3-us-west-2.amazonaws.com/hm-registration/successsignin.html", 47 | "token": "access" 48 | } 49 | r1 = requests.post(url1, data=data1, headers=_headers, allow_redirects=False) 50 | try: 51 | location = r1.headers["Location"] 52 | code = get_code(location) 53 | except: 54 | return 0, 0 55 | # print("access_code获取成功!") 56 | # print(code) 57 | 58 | url2 = "https://account.huami.com/v2/client/login" 59 | data2 = { 60 | "app_name": "com.xiaomi.hm.health", 61 | "app_version": "4.6.0", 62 | "code": f"{code}", 63 | "country_code": "CN", 64 | "device_id": "2C8B4939-0CCD-4E94-8CBA-CB8EA6E613A1", 65 | "device_model": "phone", 66 | "grant_type": "access_token", 67 | "third_name": "huami_phone", 68 | } 69 | r2 = requests.post(url2, data=data2, headers=_headers).json() 70 | login_token = r2["token_info"]["login_token"] 71 | # print("login_token获取成功!") 72 | # print(login_token) 73 | userid = r2["token_info"]["user_id"] 74 | # print("userid获取成功!") 75 | # print(userid) 76 | 77 | return login_token, userid 78 | 79 | 80 | def main(_user, _passwd, _step): 81 | """ 82 | 主函数 83 | """ 84 | _user = str(_user) 85 | password = str(_passwd) 86 | _step = str(_step) 87 | if _user == '' or password == '': 88 | print("用户名或密码不能为空!") 89 | return "user and passwd not empty!" 90 | 91 | if _step == '': 92 | print("已设置为随机步数(10000-19999)") 93 | _step = str(random.randint(10000, 19999)) 94 | login_token, userid = login(_user, password) 95 | if login_token == 0: 96 | print("登陆失败!") 97 | return "login fail!" 98 | 99 | t = get_time() 100 | 101 | app_token = get_app_token(login_token) 102 | 103 | today = time.strftime("%F") 104 | 105 | summary = { 106 | "v": 6, 107 | "slp": { 108 | "st": int(time.time()), 109 | "ed": int(time.time()), 110 | "dp": 0, 111 | "lt": 0, 112 | "wk": 0, 113 | "usrSt": -1440, 114 | "usrEd": -1440, 115 | "wc": 0, 116 | "is": 0, 117 | "lb": 0, 118 | "to": 0, 119 | "dt": 0, 120 | "rhr": 0, 121 | "ss": 0 122 | }, 123 | "stp": { 124 | "ttl": _step, 125 | "dis": 10627, 126 | "cal": 510, 127 | "wk": 41, 128 | "rn": 50, 129 | "runDist": 7654, 130 | "runCal": 397, 131 | "stage": [ 132 | { 133 | "start": 327, 134 | "stop": 341, 135 | "mode": 1, 136 | "dis": 481, 137 | "cal": 13, 138 | "step": 680 139 | }, 140 | { 141 | "start": 342, 142 | "stop": 367, 143 | "mode": 3, 144 | "dis": 2295, 145 | "cal": 95, 146 | "step": 2874 147 | }, 148 | { 149 | "start": 368, 150 | "stop": 377, 151 | "mode": 4, 152 | "dis": 1592, 153 | "cal": 88, 154 | "step": 1664 155 | }, 156 | { 157 | "start": 378, 158 | "stop": 386, 159 | "mode": 3, 160 | "dis": 1072, 161 | "cal": 51, 162 | "step": 1245 163 | }, 164 | { 165 | "start": 387, 166 | "stop": 393, 167 | "mode": 4, 168 | "dis": 1036, 169 | "cal": 57, 170 | "step": 1124 171 | }, 172 | { 173 | "start": 394, 174 | "stop": 398, 175 | "mode": 3, 176 | "dis": 488, 177 | "cal": 19, 178 | "step": 607 179 | }, 180 | { 181 | "start": 399, 182 | "stop": 414, 183 | "mode": 4, 184 | "dis": 2220, 185 | "cal": 120, 186 | "step": 2371 187 | }, 188 | { 189 | "start": 415, 190 | "stop": 427, 191 | "mode": 3, 192 | "dis": 1268, 193 | "cal": 59, 194 | "step": 1489 195 | }, 196 | { 197 | "start": 428, 198 | "stop": 433, 199 | "mode": 1, 200 | "dis": 152, 201 | "cal": 4, 202 | "step": 238 203 | }, 204 | { 205 | "start": 434, 206 | "stop": 444, 207 | "mode": 3, 208 | "dis": 2295, 209 | "cal": 95, 210 | "step": 2874 211 | }, 212 | { 213 | "start": 445, 214 | "stop": 455, 215 | "mode": 4, 216 | "dis": 1592, 217 | "cal": 88, 218 | "step": 1664 219 | }, 220 | { 221 | "start": 456, 222 | "stop": 466, 223 | "mode": 3, 224 | "dis": 1072, 225 | "cal": 51, 226 | "step": 1245 227 | }, 228 | { 229 | "start": 467, 230 | "stop": 477, 231 | "mode": 4, 232 | "dis": 1036, 233 | "cal": 57, 234 | "step": 1124 235 | }, 236 | { 237 | "start": 478, 238 | "stop": 488, 239 | "mode": 3, 240 | "dis": 488, 241 | "cal": 19, 242 | "step": 607 243 | }, 244 | { 245 | "start": 489, 246 | "stop": 499, 247 | "mode": 4, 248 | "dis": 2220, 249 | "cal": 120, 250 | "step": 2371 251 | }, 252 | { 253 | "start": 500, 254 | "stop": 511, 255 | "mode": 3, 256 | "dis": 1268, 257 | "cal": 59, 258 | "step": 1489 259 | }, 260 | { 261 | "start": 512, 262 | "stop": 522, 263 | "mode": 1, 264 | "dis": 152, 265 | "cal": 4, 266 | "step": 238 267 | } 268 | ] 269 | }, 270 | "goal": 8000, 271 | "tz": "28800" 272 | } 273 | 274 | data_json = [ 275 | { 276 | "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/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AAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAAfgAA", 283 | "tz": 32, 284 | "did": "DA932FFFFE8816E7", 285 | "src": 24 286 | } 287 | ], 288 | "summary": json.dumps(summary), 289 | "source": 24, 290 | "type": 0 291 | } 292 | ] 293 | 294 | url = f'https://api-mifit-cn.huami.com/v1/data/band_data.json?&t={t}' 295 | head = { 296 | "apptoken": app_token, 297 | "Content-Type": "application/x-www-form-urlencoded" 298 | } 299 | 300 | data = f'userid={userid}&last_sync_data_time=1597306380&device_type=0&last_deviceid=DA932FFFFE8816E7&data_json={quote(json.dumps(data_json))}' 301 | 302 | response = requests.post(url, data=data, headers=head).json() 303 | # print(response) 304 | result = f"{_user[:4]}****{_user[-4:]}: [{now}] 修改步数({_step})" + response['message'] 305 | print(result) 306 | return result 307 | 308 | 309 | def get_time(): 310 | """ 311 | 获取时间戳 312 | """ 313 | url = 'http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp' 314 | response = requests.get(url, headers=headers).json() 315 | t = response['data']['t'] 316 | return t 317 | 318 | 319 | def get_app_token(login_token): 320 | """ 321 | 获取app_token 322 | """ 323 | url = f"https://account-cn.huami.com/v1/client/app_tokens" \ 324 | f"?app_name=com.xiaomi.hm.health&dn=api-user.huami.com%2Capi-mifit.huami.com%2Capp-analytics.huami.com" \ 325 | f"&login_token={login_token}" 326 | response = requests.get(url, headers=headers).json() 327 | app_token = response['token_info']['app_token'] 328 | # print("app_token获取成功!") 329 | # print(app_token) 330 | return app_token 331 | 332 | 333 | def push_wx(_sckey, desp=""): 334 | """ 335 | 推送server酱 336 | """ 337 | if _sckey == '': 338 | print("[注意] 未提供sckey,不进行推送!") 339 | else: 340 | server_url = f"https://sc.ftqq.com/{_sckey}.send" 341 | params = { 342 | "text": '小米运动 步数修改', 343 | "desp": desp 344 | } 345 | 346 | response = requests.get(server_url, params=params) 347 | json_data = response.json() 348 | 349 | if json_data['errno'] == 0: 350 | print(f"[{now}] 推送成功。") 351 | else: 352 | print(f"[{now}] 推送失败:{json_data['errno']}({json_data['errmsg']})") 353 | 354 | 355 | def push_server(_sckey, desp=""): 356 | """ 357 | 推送消息到微信 358 | """ 359 | if _sckey == '': 360 | print("[注意] 未提供sckey,不进行微信推送!") 361 | else: 362 | server_url = f"https://sctapi.ftqq.com/{_sckey}.send" 363 | params = { 364 | "title": '小米运动 步数修改', 365 | "desp": desp 366 | } 367 | 368 | response = requests.get(server_url, params=params) 369 | json_data = response.json() 370 | 371 | if json_data['code'] == 0: 372 | print(f"[{now}] 推送成功。") 373 | else: 374 | print(f"[{now}] 推送失败:{json_data['code']}({json_data['message']})") 375 | 376 | 377 | def push_pushplus(token, content=""): 378 | """ 379 | 推送消息到pushplus 380 | """ 381 | if token == '': 382 | print("[注意] 未提供token,不进行pushplus推送!") 383 | else: 384 | server_url = "http://www.pushplus.plus/send" 385 | params = { 386 | "token": token, 387 | "title": '小米运动 步数修改', 388 | "content": content 389 | } 390 | 391 | response = requests.get(server_url, params=params) 392 | json_data = response.json() 393 | 394 | if json_data['code'] == 200: 395 | print(f"[{now}] 推送成功。") 396 | else: 397 | print(f"[{now}] 推送失败:{json_data['code']}({json_data['message']})") 398 | 399 | 400 | def push_tg(token, chat_id, desp=""): 401 | """ 402 | 推送消息到TG 403 | """ 404 | if token == '': 405 | print("[注意] 未提供token,不进行tg推送!") 406 | elif chat_id == '': 407 | print("[注意] 未提供chat_id,不进行tg推送!") 408 | else: 409 | server_url = f"https://api.telegram.org/bot{token}/sendmessage" 410 | params = { 411 | "text": '小米运动 步数修改\n\n' + desp, 412 | "chat_id": chat_id 413 | } 414 | 415 | response = requests.get(server_url, params=params) 416 | json_data = response.json() 417 | 418 | if json_data['ok']: 419 | print(f"[{now}] 推送成功。") 420 | else: 421 | print(f"[{now}] 推送失败:{json_data['error_code']}({json_data['description']})") 422 | 423 | 424 | def wxpush(msg, usr, corpid, corpsecret, agentid=1000002): 425 | """ 426 | 企业微信推送 427 | """ 428 | base_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?' 429 | req_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' 430 | corpid = corpid 431 | corpsecret = corpsecret 432 | agentid = agentid 433 | 434 | if agentid == 0: 435 | agentid = 1000002 436 | 437 | def get_access_token(_base_url, _corpid, _corpsecret): 438 | """ 439 | 获取access_token,每次的access_token都不一样,所以需要运行一次请求一次 440 | """ 441 | urls = _base_url + 'corpid=' + _corpid + '&corpsecret=' + _corpsecret 442 | resp = requests.get(urls).json() 443 | access_token = resp['access_token'] 444 | return access_token 445 | 446 | def send_message(_msg, _usr): 447 | """ 448 | 发送消息 449 | """ 450 | data = get_message(_msg, _usr) 451 | req_urls = req_url + get_access_token(base_url, corpid, corpsecret) 452 | res = requests.post(url=req_urls, data=data) 453 | ret = res.json() 454 | if ret["errcode"] == 0: 455 | print(f"[{now}] 企业微信推送成功") 456 | else: 457 | print(f"[{now}] 推送失败:{ret['errcode']} 错误信息:{ret['errmsg']}") 458 | 459 | def get_message(_msg, _usr): 460 | """ 461 | 获取消息 462 | """ 463 | data = { 464 | "touser": _usr, 465 | "toparty": "@all", 466 | "totag": "@all", 467 | "msgtype": "text", 468 | "agentid": agentid, 469 | "text": { 470 | "content": _msg 471 | }, 472 | "safe": 0, 473 | "enable_id_trans": 0, 474 | "enable_duplicate_check": 0, 475 | "duplicate_check_interval": 1800 476 | } 477 | data = json.dumps(data) 478 | return data 479 | 480 | msg = msg 481 | usr = usr 482 | if corpid == '': 483 | print("[注意] 未提供corpid,不进行企业微信推送!") 484 | elif corpsecret == '': 485 | print("[注意] 未提供corpsecret,不进行企业微信推送!") 486 | else: 487 | send_message(msg, usr) 488 | 489 | 490 | class ToPush: 491 | """ 492 | 推送接口类 493 | 处理pkey并转发推送消息到推送函数 494 | """ 495 | push_msg: str 496 | 497 | def __init__(self, _pkey): 498 | self.pkey = _pkey 499 | 500 | def to_push_wx(self): 501 | """ 502 | 推送server酱接口 503 | """ 504 | if str(self.pkey) == '0': 505 | self.pkey = '' 506 | push_wx(self.pkey, self.push_msg) 507 | 508 | def to_push_server(self): 509 | """ 510 | 推送消息到微信接口 511 | """ 512 | if str(self.pkey) == '0': 513 | self.pkey = '' 514 | push_server(self.pkey, self.push_msg) 515 | 516 | def to_push_tg(self): 517 | """ 518 | 推送消息到TG接口 519 | """ 520 | try: 521 | token, chat_id = self.pkey.split('@') 522 | push_tg(token, chat_id, self.push_msg) 523 | except ValueError: 524 | print('tg推送参数有误!') 525 | 526 | def to_wxpush(self): 527 | """ 528 | 企业微信推送接口 529 | """ 530 | try: 531 | usr, corpid, corpsecret, *agentid = self.pkey.split('-') 532 | if agentid: 533 | wxpush(self.push_msg, usr, corpid, corpsecret, int(agentid[0])) 534 | else: 535 | wxpush(self.push_msg, usr, corpid, corpsecret) 536 | except ValueError: 537 | print('企业微信推送参数有误!') 538 | 539 | def to_push_pushplus(self): 540 | """ 541 | 接口 542 | """ 543 | if self.pkey == '': 544 | print('pushplus token错误') 545 | else: 546 | push_pushplus(self.pkey, self.push_msg) 547 | 548 | @staticmethod 549 | def no_push(): 550 | """ 551 | 不推送 552 | """ 553 | print('不推送') 554 | 555 | 556 | if __name__ == "__main__": 557 | # Push Mode 558 | # print(sys.argv) 559 | try: 560 | Pm = os.environ["xppmode"] 561 | #sys.argv[1] 562 | pkey = os.environ["xppkey"] 563 | #sys.argv[2] 564 | 565 | to_push = ToPush(pkey) 566 | 567 | # 用户名(格式为 13800138000) 568 | user = os.environ["xpuser"] 569 | #sys.argv[3] 570 | # 登录密码 571 | passwd = os.environ["xppwd"] 572 | #sys.argv[4] 573 | # 要修改的步数,直接输入想要修改的步数值,0为随机步数 574 | step = os.environ["xpstep"].replace('[', '').replace(']', '') 575 | #sys.argv[5].replace('[', '').replace(']', '') 576 | except IndexError as e: 577 | print("参数有误: " + str(e)) 578 | exit(1) 579 | 580 | user_list = user.split('#') 581 | passwd_list = passwd.split('#') 582 | setp_array = step.split('-') 583 | 584 | if len(user_list) == len(passwd_list): 585 | to_push.push_msg = '' 586 | for user, passwd in zip(user_list, passwd_list): 587 | if len(setp_array) == 2: 588 | step = str(random.randint(int(setp_array[0]), int(setp_array[1]))) 589 | print(f"已设置为随机步数({setp_array[0]}-{setp_array[1]})") 590 | elif str(step) == '0': 591 | step = '' 592 | to_push.push_msg += main(user, passwd, step) + '\n' 593 | 594 | push = { 595 | 'wx': to_push.to_push_wx, 596 | 'nwx': to_push.to_push_server, 597 | 'tg': to_push.to_push_tg, 598 | 'qwx': to_push.to_wxpush, 599 | 'pp': to_push.to_push_pushplus, 600 | 'off': to_push.no_push 601 | } 602 | try: 603 | push[Pm]() 604 | except KeyError: 605 | print('推送选项有误!') 606 | exit(0) 607 | else: 608 | print('用户名和密码数量不对') 609 | --------------------------------------------------------------------------------