![](/style/images/good.png)
![](/style/images/bad.png)
青年大学习自助脚本
source link: https://tinyshellbo.github.io/2021/09/26/other/%E5%A4%A7%E5%AD%A6%E4%B9%A0%E8%84%9A%E6%9C%AC/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
![neoserver,ios ssh client](/neoserver-download.png)
青年大学习自助脚本
此处是脚本存放的地方
获取token的脚本
import string
import time
import traceback
import random
import re
from urllib.parse import urlencode
import requests
from faker import Faker
def gen_rand_str(len):
return ''.join(random.sample(string.ascii_letters + string.digits, len))
def get_token():
url = "https://jxtw.h5yunban.cn/jxtw-qndxx/cgi-bin/login/we-chat/callback?callback=https%3A%2F%2Fjxtw.h5yunban.cn%2Fjxtw-qndxx%2FsignUp.php&scope=snsapi_userinfo&appid=wxe9a08de52d2723ba&openid={}&{}&headimg=https://thirdwx.qlogo.cn/mmopen/vi_32/I7gbHHRj903RFibtlB4jrz1T1jTJ3eCWsCJwibQIT5hLRXO25ib9AHeqUjsPGmwhtiaBuzhQfhEZ6ibBdGbyZuM72LA/132&time={}&source=common&t={}"
try:
faker = Faker('zh_CN') # 此处用到了 faker 执行pip install faker安装faker
openid = gen_rand_str(28) # openid 是一个 28 长度字符串,我这里随机生成的
nickname = urlencode({'j': faker.name()}) # 随机名称字
newurl = url.format(openid, nickname, "%d" % time.time(), "%d" % time.time()) # 生成 一个新的url
print(newurl)
res = requests.get(newurl) # 返回的这个内容包含 access_token
text = res.text
print(text)
token = re.findall("<script>localStorage.setItem\('accessToken', '(.*?)'\)", text)
if token:
token = token[0]
except:
traceback.print_exception()
print('获取token出错')
return None
else:
return token
if __name__ == '__main__':
print(get_token())
发起一次请求的脚本
import json
import string
import time
import traceback
import random
import re
from urllib.parse import urlencode
import requests
from faker import Faker
def gen_rand_str(len):
return ''.join(random.sample(string.ascii_letters + string.digits, len))
def get_token():
url = "https://jxtw.h5yunban.cn/jxtw-qndxx/cgi-bin/login/we-chat/callback?callback=https%3A%2F%2Fjxtw.h5yunban.cn%2Fjxtw-qndxx%2FsignUp.php&scope=snsapi_userinfo&appid=wxe9a08de52d2723ba&openid={}&{}&headimg=https://thirdwx.qlogo.cn/mmopen/vi_32/I7gbHHRj903RFibtlB4jrz1T1jTJ3eCWsCJwibQIT5hLRXO25ib9AHeqUjsPGmwhtiaBuzhQfhEZ6ibBdGbyZuM72LA/132&time={}&source=common&t={}"
try:
faker = Faker('zh_CN') # 此处用到了 faker 执行pip install faker安装faker
openid = gen_rand_str(28) # openid 是一个 28 长度字符串,我这里随机生成的
nickname = urlencode({'j': faker.name()}) # 随机名称字
newurl = url.format(openid, nickname, "%d" % time.time(), "%d" % time.time()) # 生成 一个新的url
res = requests.get(newurl) # 返回的这个内容包含 access_token
text = res.text
token = re.findall("<script>localStorage.setItem\('accessToken', '(.*?)'\)", text)
if token:
token = token[0]
except:
traceback.print_exception()
print('获取token出错')
return None
else:
return token
def onepost(access_token, course_id, nid, class_name, username):
'''
发起一次请求
:param access_token:
:param course_id: 课程id
:param nid: 团委id
:param class_name: 班级
:param username: 学生姓名
:return:
'''
post_data = {
"course": course_id,
"nid": nid,
"subOrg": class_name,
"cardNo": username
}
# 发送请求url post
try:
post_url = "https://jxtw.h5yunban.cn/jxtw-qndxx/cgi-bin/user-api/course/join?accessToken="
res = requests.post(url=post_url + access_token, data=json.dumps(post_data))
if res.status_code == 200:
print(res.json())
return True
else:
return False
except:
print('发送请求出错!')
return False
def get_current_course_id(token):
if not token:
return None
# 获取当前课程的url地址
current_url = "https://jxtw.h5yunban.cn/jxtw-qndxx/cgi-bin/common-api/course/current?accessToken="
new_current_url = current_url + token
course_id = None
try:
res = requests.get(new_current_url)
if res.status_code == 200:
res_json = res.json()
if res_json.get('status') != 200:
return None
result = res_json['result']
course_id = result.get('id')
title = result.get('title')
except:
print('获取课程id出错')
return None
else:
return (course_id, title)
def main():
faker = Faker('zh_CN')
# 获取当前课程的 course_id
course_res = get_current_course_id(get_token())
if not course_res:
print('获取course_id出错')
return
course_id = course_res[0]
course_title = course_res[1]
nid = "" # 团委id 自行修改
'''
班级 注意: 如果有的团委组织是第四级组织,那么这个class_name就为空值就行,
否则会出现以下响应
{'status': 400, 'message': '已选择四级组织,无需输入', 'result': None, 'debug': None}
'''
class_name = '班级' #
username = faker.name() # 你的姓名
token = get_token() # 获取token
if not token:
return
# 发起一次请求 ,可以自行改造成批量
res = onepost(token, course_id, nid, class_name, username)
if res:
print('成功')
if __name__ == '__main__':
main()
团委id获取
有的同学可能不知道如何去获取自己的团委所属的id
在这里我贴一下获取团委id的脚本
def print_org(item=None):
print(item)
url = "https://jxtw.h5yunban.cn/jxtw-qndxx/cgi-bin/common-api/organization/children?pid="
if item == None:
url = url+'N'
else:
url = url+item.get('id')
res = requests.get(url)
if res.status_code != 200:
print('请求失败')
return
# 获取返回的 json数据
res_json = res.json()
# 获取团委列表
result_list = res_json.get('result')
# 如果团委列表为空,则 return
if not result_list:
print('该团委没有下级团委了')
print('您的最终团委id: '+item.get('id')+' 您的团委是第%s级'%item.get('level'))
return None
print('找到以下团委列表:')
for index,item in enumerate(result_list):
print(str(index+1)+'、团委id: '+item.get('id')+'团委名字: '+item.get('title'))
index = int(input('请选择以下第几个团委(输入 1、2、3 等数字):'))
if index > len(result_list) or index <0:
print('你所选的下标越界! 退出!')
return
# 递归查找
return print_org(result_list[index-1])
if __name__ == '__main__':
print_org()
运行后最终会根据你的选择一步一步的直到获取到你的团委,并且显示你的团委等级,这个团委等级有一定的用处
再说一下这几个参数如何传递
{
"course": course_id,
"nid": nid,
"subOrg": class_name,
"cardNo": username
}
course_id: 就是当前课程的id(可以理解为代号)
nid: 团委id
subOrg: 这个值是根据nid的值来变的,重点: 如果你的团委是四级团委,那么这个subOrg就填None,也就是函数传参时,class_name=None,如果时三级团委,那么就需要填写班级,
cardNo: 你的名字
以上脚本保证有效,可以自行根据一次请求的脚本编写批量脚本,部署服务器定时运行,帮全校乃至全省弄青年大学习
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK