From 35bed086134c0987bdf4e04d4a4a7f865008e356 Mon Sep 17 00:00:00 2001 From: Rycarl Date: Thu, 13 Mar 2025 19:20:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加了对openid有效性的判断以及用户手动确认是否继续运行 --- main.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index e41e0a9..bb58ac0 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,5 @@ +from distutils.command.check import check +from symbol import continue_stmt from time import sleep import requests @@ -17,7 +19,12 @@ headers = { def login(openid, phone_type="PJF110_Android%2015"): url = f"https://sport.cqupt.edu.cn/wxapp/wxUnifyId/checkBinding?wxCode=&openid={openid}&phoneType={phone_type}" - response = requests.get(url, headers=headers).json() + response = requests.get(url, headers=headers,verify=False).json() + print(response) + if response['data']['isBind']=='true' : + print("成功获取数据") + else: + raise ValueError("openid错误") print(f"正在登入, MSG: {response['msg']}, CODE: {response['code']}") print(f"Token: {response['data']['token']}") headers['token'] = response['data']['token'] @@ -25,9 +32,21 @@ def login(openid, phone_type="PJF110_Android%2015"): def get_user(): url = f"https://sport.cqupt.edu.cn/wxapp/wxUnifyId/getUser" - response = requests.get(url, headers=headers).json() + response = requests.get(url, headers=headers,verify=False).json() print(f"获取用户信息, MSG: {response['msg']}, CODE: {response['code']}") print(f"姓名: {response['data']['username']}, 学号: {response['data']['studentNo']}") + while True: + print(f"是否继续进行跑步打卡(Y/N)") + user_input=input() + if user_input == "Y" or user_input == "y": + break + elif user_input == "N" or user_input == "n": + print("bye") + exit() + else: + print("输入无效") + + def start(place_name="太极运动场",place_code="T1005"): url = f"https://sport.cqupt.edu.cn/wxapp/sportRecord/sport/start2" @@ -35,13 +54,13 @@ def start(place_name="太极运动场",place_code="T1005"): "placeName": place_name, "placeCode": place_code } - response = requests.post(url, headers=headers,json=data).json() + response = requests.post(url, headers=headers,json=data,verify=False).json() print(f"开始打卡, MSG: {response['msg']}, CODE: {response['code']}, DATA: {response['data']}") return response['data'] def sport_record(record_no): url = f"https://sport.cqupt.edu.cn/wxapp/sportRecord/info/{record_no}" - response = requests.get(url, headers=headers).json() + response = requests.get(url, headers=headers,verify=False).json() print(f"获取打卡信息, MSG: {response['msg']}, CODE: {response['code']}") print(f"打卡信息: {response['data']['studentName']}, 公里: {response['data']['mileage']}") @@ -51,7 +70,7 @@ def post_record_data(record_no,pointlist): "sportRecordNo": record_no, "sportPointList": pointlist } - response = requests.post(url, headers=headers,json=data).json() + response = requests.post(url, headers=headers,json=data,verify=False).json() print(f"提交打卡信息, MSG: {response['msg']}, CODE: {response['code']}, 路程: {response['data']['mileage']}, 时间: {response['data']['timeConsuming']}") if response['code'] == '10200': return 0 @@ -66,7 +85,7 @@ def get_point_from_file(): def end(record_no): url = f"https://sport.cqupt.edu.cn/wxapp/sportRecord/sport/end/{record_no}" data = {} - response = requests.post(url, headers=headers,json=data).json() + response = requests.post(url, headers=headers,json=data,verify=False).json() print(f"结束打卡, MSG: {response['msg']}, CODE: {response['code']}") def main():