安全微伴助手

感谢git上的GitHub - Coaixy/weiban-tool: 安全微伴自动刷课助手项目提供的api以及思路

import requests
import time
import re
import random
import os
import json

j = 0
ts = int(time.time()*1000)
session = requests.Session()


XToken = "7f6c31e5-07ca-4c40-be98-40cb4b1ca176"
userId = "a5035f91-a2ee-42f6-a8f0-da2f7c98f281"
userProjectId = "75a173d5-5ed0-47b3-ab69-5ecef2578bc0"

headers = {
    "ContentType": "application/x-www-form-urlencoded;charset=UTF-8",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
    "X-Token": XToken,
    "Accept-Language": 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
    "Accept": 'application/json, text/plain, */*'
            }
categoryCodes = ['101001001', '101003006', '101004002', '101004003', '101004007', '101005001']
categoryCodes2 = []

data0 = {"tenantCode":	"4152011731",
        "userId": userId,
        "userProjectId": userProjectId,
        "chooseType": "3",
        "categoryCode":	""}#遍历找courseid
url = "https://weiban.mycourse.cn/pharos/usercourse/listCourse.do"
urlcd = "https://weiban.mycourse.cn/pharos/usercourse/getCourseUrl.do?"

data = {"tenantCode":	"4152011731",
        "userId": userId,
        "courseId": " ",
        "userProjectId": userProjectId,

        }#请求userCourseId

for i in categoryCodes:
    data0["categoryCode"] = i
    res = requests.post(url, data0, headers=headers).text
    print(res)
    ResourceIds = re.findall(r'"resourceId":"([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})"', res)
    for ResourceId in ResourceIds:
        data["courseId"] = ResourceId
        userCourseId = session.post(urlcd, data, headers=headers).text
        match = re.search(r'userCourseId\\u003d([a-f0-9\-]+)', userCourseId)
        user_course_id = match.group(1)
#启动课程
        urlstar = "https://weiban.mycourse.cn/pharos/usercourse/study.do"
        data1 = {
            "userProjectId": userProjectId,
            "tenantCode": "4152011731",
            "userId": userId,
            "courseId": ResourceId,
        }
        text1 = session.post(url=urlstar, data=data1, headers=headers).text
        print("等待刷课————")
        time.sleep(random.randint(15, 20))


#构造完成请求
        genrand = ("3.4.1" + str(random.random())).replace(".", "")
        finurl = "https://open.mycourse.cn/proteus/usercourse/finish.do"
        finurl1 = finurl.format(user_course_id)
        finish_url = "https://weiban.mycourse.cn/pharos/usercourse/v2/{}.do"


#验证码
        url4 = "https://weiban.mycourse.cn/pharos/usercourse/getCaptcha.do"
        params1 = {
            "userCourseId": user_course_id,
            "userProjectId": userProjectId,
            "userId": userId,
            "tenantCode": "4152011731"
        }
        text = requests.get(url4, headers=headers, params=params1).text
        question_id = json.loads(text)['captcha']['questionId']
        url5 = "https://weiban.mycourse.cn/pharos/usercourse/checkCaptcha.do"
        params8 = {
            "userCourseId": user_course_id,
            "userProjectId": userProjectId,
            "userId": userId,
            "tenantCode": "4152011731",
            "questionId": question_id
        }
        data123 = {
            "coordinateXYs": "[{\"x\":77,\"y\":417},{\"x\":162,\"y\":426},{\"x\":211,\"y\":417}]"
        }
        text123 = session.post(url5, headers=headers, params=params8, data=data123).text
        token =json.loads(text123)['data']['methodToken']
        finish_url = finish_url.format(token)

        param = {
                        "callback": "jQuery{}_{}".format(genrand, ts),
                        "userCourseId": user_course_id,
                        "tenantCode": 4152011731,
                        "_": str(ts + 1),
                    }
        text = requests.get(finish_url, params=param, headers=headers).text
        while True:
            if ('{"msg":"ok"' in text):
                j = j + 1
                print("第{}次刷课成功".format(j))
                break
            else:
                text = requests.get(finish_url, params=param, headers=headers).text













        第一次写,写的太差了,由于那个登录的表单似乎加密了,得不到有效的data,所以我干脆用x—token登录,tenanCode我们学校都是一样的我也懒得改了,categoryCodes也需要改,我还需要二改的,先不用慌。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值