├── .deepsource.toml ├── .gitignore ├── LICENSE ├── README.md └── main.py /.deepsource.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[analyzers]] 4 | name = "python" 5 | enabled = true 6 | 7 | [analyzers.meta] 8 | runtime_version = "3.x.x" 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Junyuan Feng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ChaoXingAutoSign 2 | 超星学习通**自动登录、签到** 3 | 4 | ## 20.6.1 5 | 新增`objectId`,自定义图片签到时使用的图片ID,此ID项可通过抓包获取,非必须修改 6 | 7 | 去除`debug`参数,需要调试请通过修改上课时间实现 8 | 9 | 10 | ## 20.5.22 11 | 新增`listen_time`参数,可设置每次监听时长 12 | 13 | `except JSONDeoderError`,强化cookie失效策略 14 | 15 | 16 | ## 20.5.17 17 | 周末自动暂停运行脚本,有需求请修改`start_day`参数 18 | 19 | 20 | ## 20.5.16 21 | 优化,支持多种签到方式 22 | 23 | 24 | ## 20.5.12 25 | 优化监听机制,减少占用、流量 26 | 27 | 28 | ## 20.5.4 29 | 自动获取新cookie,防止cookie失效 30 | 31 | 修复了API错误的问题 32 | 33 | 34 | ## 声明 35 | thanks to author 7z 36 | 37 | 38 | @LollipopKit MIT license 39 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | import multiprocessing 3 | import random 4 | from datetime import datetime, time 5 | from time import sleep 6 | from time import time as times 7 | import os 8 | from urllib import parse 9 | import json 10 | import requests 11 | 12 | 13 | # !!!请填写下面的参数 14 | # 填写用户名和密码,以便登录 15 | username = '' 16 | password = '' 17 | # uid为用户id 18 | uid = '' 19 | # 此三项为签到参数,经纬度和真实姓名 20 | latitude = '-1' 21 | longitude = '-1' 22 | name = '' 23 | # 下面三项一般不需要修改 24 | clientip = '' 25 | signuseragent = '' 26 | # 图片签到所需要的objectId,具体ID可抓包获得 27 | objectId = 'a58cb2acedf5fa10d2ad2fc421fb7d30' 28 | 29 | # 每次课的上课时间 30 | start_time = { 31 | time(8, 0), 32 | time(10, 0), 33 | time(13, 30), 34 | time(15, 30), 35 | } 36 | # 监听时长,例如设为20,就从每次上课开始监听20分钟 37 | listen_time = 20 38 | # 星期几上课,特殊:星期天是0 39 | start_day = [1, 2, 3, 4, 5] 40 | 41 | # 从这里开始不需要修改 42 | useragent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_4_1 like Mac OS X) ' \ 43 | 'AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 ' \ 44 | 'ChaoXingStudy/ChaoXingStudy_3_4.4.1_ios_phone_202004111750_39 (@Kalimdor)_4375872153618237766 ' \ 45 | 'ChaoXingStudy/ChaoXingStudy_3_4.4.1_ios_phone_202004111750_39 (@Kalimdor)_4375872153618237766' 46 | encode_name = parse.quote(name) 47 | cookie_filename = 'chaoxing_cookies' 48 | header = { 49 | 'Cookie': '', 50 | 'User-Agent': useragent 51 | } 52 | 53 | 54 | def myprint(string): 55 | print(datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S') + ' ' + string) 56 | 57 | 58 | def getCookies(): 59 | myprint('正在登录,获取新Cookie') 60 | if username and password: 61 | url = 'https://passport2-api.chaoxing.com/v11/loginregister' 62 | payload = { 63 | 'uname': username, 64 | 'code': password 65 | } 66 | cookie_jar = requests.session().post(url=url, data=payload, headers={'User-Agent': useragent}).cookies 67 | cookie_dict = requests.utils.dict_from_cookiejar(cookie_jar) 68 | cookie_str = '' 69 | for key in cookie_dict: 70 | cookie_str += key + '=' + cookie_dict[key] + '; ' 71 | header['cookie'] = cookie_str 72 | with open(cookie_filename, 'w', encoding='utf-8')as file: 73 | file.write(cookie_str) 74 | myprint('获取Cookie成功') 75 | else: 76 | myprint('plz edit username and password in this python file') 77 | 78 | 79 | def loadCookie(): 80 | if os.path.exists(cookie_filename): 81 | with open(cookie_filename, 'r', encoding='utf-8') as f: 82 | data = f.read().strip() 83 | if data: 84 | header['cookie'] = data 85 | else: 86 | getCookies() 87 | else: 88 | getCookies() 89 | 90 | 91 | should_run = False 92 | coursedata = [] 93 | activates = [] 94 | timestamp: float = 0 95 | 96 | 97 | def listenThread(): 98 | global should_run 99 | while should_run: 100 | def backClassData(): 101 | cdata = {} 102 | url = 'http://mooc1-api.chaoxing.com/mycourse/backclazzdata?view=json&rss=1' 103 | while not cdata: 104 | res = requests.get(url, headers=header) 105 | res_data = res.text 106 | if '请重新登录' in res_data: 107 | getCookies() 108 | continue 109 | try: 110 | cdata = json.loads(res_data) 111 | except json.JSONDecodeError: 112 | myprint('Cookie已失效,将重新获取') 113 | getCookies() 114 | continue 115 | if not cdata: 116 | getCookies() 117 | continue 118 | if cdata['result'] != 1: 119 | myprint('课程列表获取失败') 120 | sleep(10) 121 | continue 122 | for item in cdata['channelList']: 123 | if 'course' not in item['content']: 124 | continue 125 | pushdata = {'courseid': item['content']['course']['data'][0]['id'], 126 | 'name': item['content']['course']['data'][0]['name'], 127 | 'imageurl': item['content']['course']['data'][0]['imageurl'], 128 | 'classid': item['content']['id']} 129 | coursedata.append(pushdata) 130 | myprint('课程获取成功\n') 131 | printCourseData() 132 | 133 | def printCourseData(): 134 | global coursedata 135 | for index, item in enumerate(coursedata): 136 | print(str(index + 1) + "." + item['name']) 137 | startSign() 138 | 139 | def taskActiveList(courseId, classId): 140 | url = 'https://mobilelearn.chaoxing.com/ppt/activeAPI/taskactivelist?' \ 141 | 'courseId=' + str(courseId) + \ 142 | '&classId=' + str(classId) + \ 143 | '&uid=' + uid 144 | res = requests.get(url, headers=header) 145 | data_json = json.loads(res.text) 146 | activeList = data_json['activeList'] 147 | for item in activeList: 148 | if 'nameTwo' not in item: 149 | continue 150 | if item['activeType'] == 2 and item['status'] == 1: 151 | signurl = item['url'] 152 | aid = getVar(signurl) 153 | if aid not in activates: 154 | myprint('待签到活动 名称:%s 状态:%s 时间:%s ' % (item['nameOne'], item['nameTwo'], item['nameFour'])) 155 | sign(aid, uid, courseId) 156 | 157 | def getVar(url): 158 | var1 = url.split('&') 159 | for var in var1: 160 | var2 = var.split('=') 161 | if var2[0] == 'activePrimaryId': 162 | return var2[1] 163 | return 'notfound' 164 | 165 | def sign(aid, uid, courseid): 166 | global should_run, activates 167 | url = 'https://mobilelearn.chaoxing.com/pptSign/stuSignajax?' \ 168 | 'activeId=' + aid + \ 169 | '&uid=' + uid + \ 170 | '&clientip=' + clientip + \ 171 | '&useragent=' + signuseragent +\ 172 | '&latitude=' + latitude + \ 173 | '&longitude=' + longitude + \ 174 | '&appType=15' + \ 175 | '&fid=2378' + \ 176 | '&objectId=' + objectId + \ 177 | '&name=' + encode_name 178 | res = requests.get(url, headers=header) 179 | course_name = '' 180 | for item in coursedata: 181 | if item['courseid'] == courseid: 182 | course_name = item['name'] 183 | if res.text == 'success': 184 | myprint(course_name + ': 签到成功!') 185 | activates.append(aid) 186 | sleep(60) 187 | should_run = False 188 | elif res.text == '您已签到过了': 189 | myprint(course_name + ': 您已签到过了') 190 | activates.append(aid) 191 | sleep(60) 192 | should_run = False 193 | else: 194 | myprint(course_name + ': 签到失败') 195 | activates.append(aid) 196 | 197 | def startSign(): 198 | global should_run 199 | while should_run: 200 | print('\n') 201 | for item in coursedata: 202 | myprint('正在监听: ' + str(item['name'])) 203 | taskActiveList(item['courseid'], item['classid']) 204 | sleep(3.7) 205 | if not should_run: 206 | break 207 | if should_run: 208 | sleep(random.randint(37, 88)) 209 | myprint('任务结束') 210 | 211 | backClassData() 212 | 213 | 214 | def listen(): 215 | myprint('主程序启动') 216 | child_process = None 217 | global should_run, timestamp 218 | loadCookie() 219 | 220 | while True: 221 | current_time = datetime.now().strftime('%H:%M') 222 | weekday = datetime.now().strftime('%w') 223 | 224 | if int(weekday) in start_day: 225 | for item in start_time: 226 | if str(item)[:-3] == current_time: 227 | timestamp = times() 228 | should_run = True 229 | if should_run and times() - timestamp > 60 * listen_time: 230 | should_run = False 231 | 232 | if should_run and child_process is None: 233 | myprint('监听开始\n') 234 | child_process = multiprocessing.Process(target=listenThread) 235 | child_process.start() 236 | 237 | if not should_run and child_process is not None: 238 | myprint('监听结束\n') 239 | child_process.terminate() 240 | child_process.join() 241 | child_process = None 242 | 243 | sleep(10) 244 | 245 | 246 | if __name__ == '__main__': 247 | try: 248 | listen() 249 | except KeyboardInterrupt: 250 | myprint('主动停止运行') 251 | --------------------------------------------------------------------------------