超星学习通网课协议分析

学校看网课好烦的是=-=,于是便有了写个辅助工具的想法。

由于没学过安卓开发,只能将目标瞄向了网页版的。
随便打开一节课播放,并利用google浏览器自带的network查看请求超星学习通网课协议分析_第1张图片

播放几分钟后,发现重复请求的url,推断应该是更新服务器当前观看的时间位置,请求值如下图:

超星学习通网课协议分析_第2张图片
对照几个GET请求,发现就playingTime 与 enc 两个参数不一样,并且playingTime的依次相差60,根据播放时间推测,60应该就是播放的时间了,而enc就是一个md5加密的值,于是在Sources中在所有文件中查找md5,
Ctrl + Shift + f, 超星学习通网课协议分析_第3张图片

查找出一个结果,于是在源码中找到
超星学习通网课协议分析_第4张图片
enc = md5(enc),说明enc是一个变量,于是搜索 var enc
超星学习通网课协议分析_第5张图片

断点查看enc值
超星学习通网课协议分析_第6张图片
var enc = ‘[4639198][][1413961781706][544613d8a310a7916bc462da][130000][d_yHJ!$pdA~5][1180000][0_1180]’

参数依次为:
[clazzId][userid][jobid][objectId][currentTimeSec * 1000][“d_yHJ!$pdA~5”][duration * 1000][clipTime]

因此请求的url= https://mooc1-2.chaoxing.com/multimedia/log/193c947385996c6b682611b3676d96b1
参数为:
clazzId: 4639198
playingTime: playingTime
duration: 1180
clipTime: 0_1180
objectId: 544613d8a310a7916bc462da
otherInfo: nodeId_102437947
jobid: 1413961781706
userid: 00000
isdrag: 0
view: pc
enc: md5(enc)
rt: 0.9
dtype: Video

其他参数在加载页面的时候都加载了,故而写出脚本:

# -*- coding: utf-8 -*-
"""
Created on Wed Oct 24 20:21:15 2018

@author: bear
"""
from urllib.request import urlopen
from urllib.request import Request
import hashlib
import random
import time
import json
import re

def getContent(url):
    req = Request(url)
    req.add_header("Host","mooc1-2.chaoxing.com")
    req.add_header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefo")
    req.add_header("Accept", "*/*")
    req.add_header("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")
    req.add_header("Connection", "keep-alive")
    req.add_header("Cookie", "")
    
    content=urlopen(req).read().decode("utf-8")
    return content

def GetA(courseid,clazzid,knowledgeid):
    urlA = 'https://mooc1-2.chaoxing.com/knowledge/cards?clazzid='+ clazzid +'&courseid=' + courseid + '&knowledgeid=' + knowledgeid
    text = getContent(urlA)
    searchObj = re.search(r'mArg = {(.*?)};',text)
    Restr = searchObj.group().replace('mArg = ', '')
    Restr = Restr.replace('};', '}')
    if searchObj:
        return json.loads(Restr)
    else:
        print('发生意外情况')
clazzid = ''
courseid = ''
knowledgeid = ''

def GetSee(courseid,clazzid,knowledgeid):
    returnA = GetA(courseid,clazzid,knowledgeid)
    objectid = returnA['attachments'][0]['property']['objectid']
    jobid = str(returnA['attachments'][0]['property']['jobid'])
    otherInfo = returnA['attachments'][0]['otherInfo']
    userid = str(returnA['defaults']['userid'])
    url = "https://mooc1-2.chaoxing.com/ananas/status/"  + objectid
    array = json.loads(getContent(url))
    dtoken = array['dtoken']
    duration = str(array['duration'])
    clipTime = '0_' + duration
    string = '['+clazzid+']['+userid+']['+jobid+']['+objectid+']['+str(60 * 60 * 1000)+'][d_yHJ!$pdA~5]['+duration+'000][0_'+duration+']'
    Rm = hashlib.md5()
    Rm.update(string.encode("gb2312"))
    enc = Rm.hexdigest()
    urlC = 'https://mooc1-2.chaoxing.com/multimedia/log/'+dtoken+'?clazzId='+clazzid+'&duration='+duration+'&clipTime='+clipTime+'&objectId='+objectid+'&otherInfo='+otherInfo+'&jobid='+jobid+'&userid='+userid+'&isdrag=0&view=pc&rt=0.9&dtype=Video&playingTime='+str(60 * 60)+'&enc=' + enc
    returnB = getContent(urlC)
    Rarray = json.loads(returnB)
    print(returnB)
    time.sleep(10)

def GetList():
    HtmlText = getContent('')
    searchObj = re.finditer(r'\/mycourse\/studentstudy\?chapterId=\d+&courseId=',HtmlText)
    lists = []
    for i in searchObj:
        Restr = i.group().replace('/mycourse/studentstudy?chapterId=', '')
        Restr = Restr.replace('&courseId=', '')
        lists.append(Restr)
    return lists

lists = GetList()
GetSee(courseid,clazzid,lists[0])

GetList()中的getContent(’’)请求url为 看课的目录网页,例如:https://mooc1-2.chaoxing.com/mycourse/studentcourse?courseId=&clazzid=&enc=

刷课需谨慎,在此只是分析玩玩,告诫各位同学们开挂容易被封号。
同样的原理,自动做题也不是不可以,只要取出问题,然后在题库中查找,选择正确的答案提交即可。

你可能感兴趣的:(超星学习通网课协议分析)