1. 南猫Home
  2. 干货满满

利用腾讯云函数 实现超星全自动签到

感谢大佬的开源项目https://github.com/yuban10703/chaoxingsign

但账号目前估算是完全免费 具体的价格我还没有计算过 补充:外网出流量会产生计费 但是量特别低,大约110天左右产生一次计费 国内地区8毛

首先是需要在腾讯云后台创建一个云函数环境 地址:https://console.cloud.tencent.com/scf

云函数位置目前不要选择广东无法运行 实测中可能会出现不知名报错,建议多设置几个云函数进行运行 建议选择上海区域实测 运行稳定

新建函数服务 环境选择python3.6 空白函数 名称随便

利用腾讯云函数 实现超星全自动签到

点击下一步跳转到编辑器页面

利用腾讯云函数 实现超星全自动签到

在右侧输入框替换成以下代码

import requests
import json
import time
import datetime
session = requests.session()
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36'}
allsubject = []
allname = []
allclassid = []
allcourseid=[]
activates=[]
allaid=[]
cook=[]
allobjectid=[]
with open('config.json', 'r', encoding='utf-8') as f:
    conf = json.loads(f.read())
    print('获取配置成功')
class CxSign(): #搞不懂class怎么用.........
    def __init__(self,num): #读取配置......(感觉可以写的更简单的......)
        CxSign.username = conf['username'][num]
        CxSign.passwd = conf['passwd'][num]
        if len(conf['SCKEY'])==1:
            CxSign.SCKEY = conf['SCKEY'][0]
        else:
            CxSign.SCKEY = conf['SCKEY'][num]

        if len(conf['name'])==1:
            CxSign.name = conf['name'][0]
        else:
            CxSign.name = conf['name'][num]

        if len(conf['address'])==1:
            CxSign.address = conf['address'][0]
        else:
            CxSign.address = conf['address'][num]

        if len(conf['longitude'])==1:
            CxSign.longitude = conf['longitude'][0]
        else:
            CxSign.longitude = conf['longitude'][num]

        if len(conf['latitude'])==1:
            CxSign.latitude = conf['latitude'][0]
        else:
            CxSign.latitude = conf['latitude'][num]

        if len(conf['picname'])==1:
            CxSign.picname = conf['picname'][0]
        else:
            CxSign.picname = conf['picname'][num]
        # self.name = conf['name'][num]
        # self.address = conf['address'][num]
        # self.longitude = conf['longitude'][num]
        # self.latitude = conf['latitude'][num]
        # self.picname = conf['picname'][num]
        # self.speed = conf['speed']

    def login(num):  # 获取cookie
        url = 'https://passport2-api.chaoxing.com/v11/loginregister'
        data = {'uname': CxSign(num).username, 'code': CxSign(num).passwd, }
        session = requests.session()
        cookie_jar = session.post(url=url, data=data, headers=headers).cookies
        cookie_t = requests.utils.dict_from_cookiejar(cookie_jar)
        cook.append(cookie_t) #把所有用户的cookie写进一个列表
        return cookie_t

    def subject(i):  # 获取课程
        url = "http://mooc1-api.chaoxing.com/mycourse/backclazzdata"
        res = requests.get(url, headers=headers, cookies=cook[i])
        cdata = json.loads(res.text)
        # coursedata=[]
        # dict_n = {}
        name = []
        classid = []
        courseid = []
        if (cdata['result'] != 1):
            print("课程列表获取失败")
        for item in cdata['channelList']:
            if ("course" not in item['content']):
                continue
            pushdata = {}
            # pushdata['user'] = str(i)  # 插入用户标记
            courseid.append(item['content']['course']['data'][0]['id'])
            name.append(item['content']['course']['data'][0]['name'])
            classid.append(item['content']['id'])
        allname.append(name)#把所有用户的数据存进列表......
        allclassid.append(classid)
        allcourseid.append(courseid)
            # coursedata.append(pushdata)
        # allsubject.append(coursedata)
        # return coursedata

    def taskactivelist(i):  # 查找签到任务
        global a
        aid=[]
        url = "https://mobilelearn.chaoxing.com/ppt/activeAPI/taskactivelist"
        for index in range(len(allname[i])):#轮询这个用户的所有课程...
            payload = {'courseId': str(allcourseid[i][index]), 'classId': str(allclassid[i][index]), 'uid': cook[i]['UID']}
            time.sleep(1.5)
            print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'用户:',i,'正在查询课程:',allname[i][index])
            res = requests.get(url, params=payload, headers=headers, cookies=cook[i])
            respon = res.status_code
            # print(index)
            if respon == 200:  # 网页状态码正常
                # print(res.text)
                data = json.loads(res.text)
                # print(data)
                activeList = data['activeList']  # 把所有任务提出来
                for item in activeList:  # 轮询所有的任务
                    if ("nameTwo" not in item):
                        continue
                    if (item['activeType'] == 2 and item['status'] == 1):  # 查找进行中的签到任务
                        # signurl = item['url']  # 提取activePrimaryId
                        aid = item['id']  # 提取activePrimaryId
                        if (aid not in activates):  # 查看是否签到过
                            print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
                                  '[签到]', allname[i][index], '查询到待签到活动 活动名称:%s 活动状态:%s 活动时间:%s aid:%s' % (
                                      item['nameOne'], item['nameTwo'], item['nameFour'], aid))
                            CxSign.sign(aid,i,index)  # 调用签到函数
            else:
                print('error', respon)  # 不知道为啥...

    def token(self):  # 获取上传图片用的token
        url = 'https://pan-yz.chaoxing.com/api/token/uservalid'
        res = requests.get(url, headers=headers, cookies=cook[0])
        tokendict = json.loads(res.text)
        return (tokendict['_token'])

    def upload(i):  # 上传图片
        try:
            picname=CxSign(i).picname
        except:
            picname=''

        if picname.isspace() or len(picname) == 0:
            return
        else:
            url = 'https://pan-yz.chaoxing.com/upload'
            files = {'file': (picname, open(picname, 'rb'),
                              'image/webp,image/*',), }
            res = requests.post(url, data={'puid': cook[0]['UID'], '_token': CxSign.token(i)}, files=files, headers=headers, cookies=cook[0])
            resdict = json.loads(res.text)
            allobjectid.append(resdict['objectId'])
            # return (resdict['objectId'])

    def sign(aid,i,index):  # 签到,偷了个懒,所有的签到类型都用这个,我测试下来貌似都没问题
        url = "https://mobilelearn.chaoxing.com/pptSign/stuSignajax"
        if len(CxSign(i).picname)==0:
            allobjectid.append('') #占位置,不然和用户ID对不上
            objectId =''

        else:
            CxSign.upload(i)
            objectId=allobjectid[i]
        try:
            name=CxSign(i).name
        except:
            try:
                name = CxSign.name
            except:
                name=''

        try:
            address=CxSign(i).address
        except:
            try:
                address = CxSign.address
            except:
                address=''

        try:
            longitude = CxSign(i).longitude
        except:
            try:
                longitude = CxSign.longitude
            except:
                longitude=''
        try:
            latitude = CxSign(i).latitude
        except:
            try:
                latitude = CxSign.latitude
            except:
                latitude = ''

        data = {'name': name, 'address': address, 'activeId': aid, 'uid': cook[i]['UID'],
                'longitude': longitude, 'latitude': latitude, 'objectId': objectId}
        # data = { 'activeId': aid, 'uid': cook[i]['UID'],}
        res = requests.post(url, data=data, headers=headers, cookies=cook[i])
        print("签到状态:", res.text)
        if res.text == 'success':
            CxSign.push(i, index, res.text)

    def push(i,index, msg):
        try:
            E_SCKEY=CxSign(i).SCKEY
        except:
            try:
                E_SCKEY = CxSign.SCKEY
            except:
                E_SCKEY =''
        if E_SCKEY.isspace() or len(E_SCKEY) == 0:

            return
        else:
            api = 'https://sc.ftqq.com/' +E_SCKEY + '.send'
            title = u"签到辣!"
            content ='用户:'+ str(i) + '\n\n课程: ' + allname[i][index] + '\n\n签到状态:' + msg
            data = {
                "text": title,
                "desp": content
            }
            requests.post(api, data=data)
            print('已推送')

def main_handler(event, context):
    number=len(conf['username'])
    for n in range(number):
        CxSign.login(n)
        time.sleep(0.5)

    for m in range(number):
        CxSign.subject(m)
        time.sleep(0.5)

    for o in range(number):
        CxSign.taskactivelist(o)


if __name__ == "__main__":
    main_handler("", "")

然后点击左侧config.json输入下列代码

  
{
"username": [""],
"passwd": [""],
"SCKEY": [""],
"name": [""],
"address": [""],
"latitude": ["32.2829260000"],
"longitude": ["43.9237990000"],
"picname": [""]
}

username填写手机号 passwd填写密码 address填写签到地址 latitude填写经度 longitude填写纬度 这两个自行百度就可以 其他的可以不用填写

点击完成然后点击左侧的触发管理 创建触发器 选择5分钟执行一次就可以

可以自行创建crontab规则进行监控 出发周期选择自定义即可 自行输入表达式 比如

0 */5 6-20 * * * *

代表每天6点到20点执行 每5分钟执行一次

利用腾讯云函数 实现超星全自动签到

然后回到函数管理 点击右上角编辑 提高超时时间 建议设置60秒的超时时间

最后保存点击函数代码 点击底部测试查看返回信息即可

正确返回信息:

利用腾讯云函数 实现超星全自动签到

原创文章,作者:南猫,如若转载,请注明出处:https://southcat.net/2634/


不妨点个广告再走嘛

Leave a Reply

Your email address will not be published. Required fields are marked *