概述
已更新于2022/12/28 目前可用
import requests
import json
import time
from datetime import datetime
import pytz
import hashlib
import urllib3
import base64
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
from requests.packages.urllib3.exceptions import InsecureRequestWarning
urllib3.disable_warnings()
tz = pytz.timezone('Asia/Shanghai')
class EncryptDate:
def __init__(self, key):
self.key = key
self.length = AES.block_size
self.aes = AES.new(self.key.encode("utf-8"), AES.MODE_ECB)
self.unpad = lambda date: date[0:-ord(date[-1])]
def fill_method(self, aes_str):
pad_pkcs7 = pad(aes_str.encode('utf-8'), AES.block_size, style='pkcs7')
return pad_pkcs7
def encrypt(self, encrData):
res = self.aes.encrypt(self.fill_method(encrData))
msg = str(base64.b64encode(res), encoding="utf-8")
return msg
def decrypt(self, decrData):
res = base64.decodebytes(decrData.encode("utf-8"))
msg = self.aes.decrypt(res).decode("utf-8")
return self.unpad(msg)
# 登录
def login(user, pwd,t):
global token, userId, roleKey
url = "https://api.moguding.net:9000/session/user/v3/login"
headers = {
'content-type': 'application/json; charset=utf-8'
}
data = {
"captcha" : 'null',
"device" : "android",
"password": pwd,
"loginType": "android",
"t" : t,
"uuid" : "",
"version" : "5.3.0",
"phone": user
}
r = requests.post(url, data=json.dumps(data), headers=headers, verify=False)
j = json.loads(r.text)
code = j['code']
name = j['data']['nikeName']
token = j['data']['token']
userId = j['data']['userId']
roleKey = j['data']['roleGroup'][0]['roleKey']
if code == 200:
print('login sign successful,welcome~ ')
else:
print('login failed')
# 获取学院信息
def getPlanByStu():
global planId
sign = getPlanByStuSign()
url = "https://api.moguding.net:9000/practice/plan/v3/getPlanByStu"
headers = {
'content-type': 'application/json; charset=utf-8',
"Host": "api.moguding.net:9000",
"Accept-Language": "zh-CN,zh;q=0.8",
"User-Agent": "Mozilla/5.0 (Linux; U; Android 7.1.2; zh-cn; SKW-A0 Build/N2G47H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
"roleKey": str(roleKey),
"Sign": str(sign),
"Authorization": str(token),
"Accept-Encoding": "",
"Cache-Control": "no-cache"
}
data = {
"state": ""
}
r = requests.post(url, data=json.dumps(data), headers=headers)
j = json.loads(r.text)
j = json.loads(r.text)
code = j['code']
planId = j['data'][0]['planId']
if code == 200:
print('query successful!')
else:
print('query failed!')
# 获取学院信息接口的sign
def getPlanByStuSign():
screet = "3478cbbc33f84bd00d75d7dfa69e0daa"
s = str(userId)+str(roleKey)+screet
sign = getmd5(s)
print("sign1====> "+str(sign))
return sign
# md5加密
def getmd5(s):
md = hashlib.md5()
md.update(s.encode(encoding='utf-8'))
get_md5 = md.hexdigest()
return get_md5
# 获取签到sign为tosign_sign
def get_tosign(address):
# %Y-%m-%d %H:%M:%S
times = datetime.fromtimestamp(int(time.time()),
pytz.timezone('Asia/Shanghai')).strftime('%H')
type = ""
if int(times) < 12:
# 早上打卡
type = "START"
else:
# 下午打卡
type = "END"
s = "Android"+str(type)+str(planId)+str(userId) +
str(address)+"3478cbbc33f84bd00d75d7dfa69e0daa"
tosign_sign = getmd5(s)
# print("sign2====> "+str(tosign_sign))
return tosign_sign
# 去签到任务
def tosign(description, address, province, city, longitude, latitude):
"""
description:打卡备注
address:地址
province:省份
city:城市
longitude:经度
latitude:纬度
"""
to_sign = get_tosign(address)
# %Y-%m-%d %H:%M:%S
times = datetime.fromtimestamp(int(time.time()),
pytz.timezone('Asia/Shanghai')).strftime('%H')
type = ""
if int(times) < 12:
# 早上打卡
type = "START"
else:
# 下午打卡
type = "END"
url = "https://api.moguding.net:9000/attendence/clock/v2/save"
data = {
"device": "Android",
"address": address,
"t": "",
"description": description,
"country": "中国",
"longitude": longitude,
"latitude": latitude,
"city": city,
"province": province,
"planId": planId,
"type": type
}
headers = {
'content-type': 'application/json; charset=utf-8',
"Host": "api.moguding.net:9000",
"Accept-Language": "zh-CN,zh;q=0.8",
"User-Agent": "Mozilla/5.0 (Linux; U; Android 7.1.2; zh-cn; SKW-A0 Build/N2G47H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
"Sign": str(to_sign),
"Authorization": str(token),
"Accept-Encoding": "",
"Cache-Control": "no-cache"
}
r = requests.post(url, data=json.dumps(data), headers=headers)
j = json.loads(r.text)
j = json.loads(r.text)
code = j['code']
if code == 200:
print('sign successful!~')
else:
print('sign failed')
def get_encrypt(s):
eg = EncryptDate("23DbtQHR2UMbH6mJ") # key
en = eg.encrypt(s)
de = eg.decrypt(en) # 解密
res = base64.b64decode(en).hex()
print(s+" ---> "+res)
return res
# 任务启动
def run():
# 填好配置,且不能注释下面调用的函数,否则报错.
user = get_encrypt('这里写账号') # 账号
pwd = get_encrypt('这里写密码') # 密码
t = get_encrypt(str(int(round(time.time() * 1000))))
description = "打卡"
province = "" # 实习所在省份
city = "" # 实习所在市区
longitude = "" # 经度
latitude = "" # 纬度
address = "" # 实习打卡所在的详细信息
login(user, pwd,t)
getPlanByStu()
get_tosign(address)
tosign(description, address, province, city, longitude, latitude)
# 云函数使用
def main_handler(event, context):
run()
return("------ end ------")
if __name__ == '__main__':
run()
最后
以上就是生动老虎为你收集整理的工学云打卡记录已更新于2022/12/28 目前可用的全部内容,希望文章能够帮你解决工学云打卡记录已更新于2022/12/28 目前可用所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复