蘑菇丁自动打卡签到脚本源码 + 成品
网上找的接口可以稍作修改然后上传到服务器定时打卡 懒人福利 , 可以随意定位
处理函数:
!/usr/bin/env python3
# -*- coding: utf-8 -*-
# [url=home.php?mod=space&uid=2260]@Time[/url] : 2020/11/30 22:34
# @Author : Smida
# @FileName: mogudinF.py
# @Software: PyCharm
import requests
import json
import configparser
import sys
import os
from datetime import datetime
# from requests.packages.urllib3.exceptions import InsecureRequestWarning
# requests.packages.urllib3.disable_warnings(InsecureRequestWarning) # 去掉ssl烦人的警告
from PyQt5.QtWidgets import QApplication, QMainWindow
from mogudinGUI import Ui_MainWindow
loginUrl = "https://api.moguding.net:9000/session/user/v1/login"
getPlanIdUrl = "https://api.moguding.net:9000/practice/plan/v1/getPlanByStu"
startUrl = "https://api.moguding.net:9000/attendence/clock/v1/save"
def header_maker(token=""):
headers = {
"Accept-Language": "zh-CN,zh;q=0.8",
"User-Agent": "Mozilla/5.0 (Linux; U; Android 8.0.0; zh-cn; MI 6 Build/OPR1.170623.027) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
"Authorization": token,
"roleKey": "",
"Content-Type": "application/json; charset=UTF-8",
"Content-Length": "85",
"Host": "api.moguding.net:9000",
"Connection": "close",
"Accept-Encoding": "gzip, deflate",
"Cache-Control": "no-cache",
}
return headers
class CoreFunc(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(CoreFunc, self).__init__(parent)
self.setupUi(self)
self.location = {}
self.userNameInput.textChanged.connect(lambda: self.userNameInputChange())
self.passWordInput.textChanged.connect(lambda: self.passWordInputChange())
self.userName = ""
self.passWord = ""
self.startHook.clicked.connect(self.startHookSubmit)
self.stopHook.clicked.connect(self.stopHookSubmit)
self.token = ""
self.planId = ""
self.initApp()
def checkIni(self):
print(self.location)
for k,v in self.location.items():
if k != 'description':
if not v:
return False
return True if self.userName and self.passWord else False
def startHookSubmit(self):
if self.checkIni():
getToken = self.login()
if getToken:
getPlanId = self.getPlanId()
if getPlanId:
self.startHooks(True)
else:
self.printl("请完善config文件信息")
return
def stopHookSubmit(self):
if self.checkIni():
getToken = self.login()
if getToken:
getPlanId = self.getPlanId()
if getPlanId:
self.startHooks(False)
else:
self.printl("请完善config文件信息")
def userNameInputChange(self):
self.userName = self.userNameInput.toPlainText()
def passWordInputChange(self):
self.passWord = self.passWordInput.toPlainText()
def initApp(self):
iniPath = "config.ini"
readConfig = configparser.ConfigParser()
if not os.path.exists(iniPath):
readConfig.add_section("user_info")
readConfig.set("user_info", "username", "")
readConfig.set("user_info", "password", "")
readConfig.add_section("location_info")
readConfig.set("location_info", "country", "")
readConfig.set("location_info", "province", "")
readConfig.set("location_info", "city", "")
readConfig.set("location_info", "address", "")
readConfig.set("location_info", "latitude", "")
readConfig.set("location_info", "longitude", "")
readConfig.set("location_info", "description", "")
with open('config.ini','w') as configFile:
readConfig.write(configFile)
readConfig.write(sys.stdout)
config = readConfig.read('config.ini','utf-8')
self.userName = readConfig.get('user_info','username')
self.passWord = readConfig.get('user_info','password')
self.userNameInput.setText(self.userName)
self.passWordInput.setText(self.passWord)
self.location = {
'country':readConfig.get('location_info','country'),
'province': readConfig.get('location_info', 'province'),
'city': readConfig.get('location_info', 'city'),
'address': readConfig.get('location_info', 'address'),
'description': readConfig.get('location_info', 'description'),
'latitude':readConfig.get('location_info', 'latitude'),
"longitude": readConfig.get('location_info', 'longitude') # 经度
}
self.printl("{}:<{}>读取配置信息".format(datetime.now().strftime('%b-%d-%Y %H:%M:%S'),self.userName))
self.printIni()
def printIni(self):
for k,v in self.location.items():
if k:
if not v:
v = 'null'
self.printl("[{}] --> [{}]".format(k,v))
def login(self):
self.printl("{}:<{}>开始登录".format(datetime.now().strftime('%b-%d-%Y %H:%M:%S'),self.userName))
headers = header_maker()
pyload = {"password": self.passWord, "phone": self.userName, "loginType": "android", "uuid": ""}
response = requests.post(loginUrl, data=json.dumps(pyload), headers=headers, verify=False).text
response = json.loads(response)
if response.get('code') == 500 :
self.printl("<{}>登陆失败..Error:{}".format(self.userName,response.get('msg')))
return False
Authorization = response.get('data').get("token")
self.token = Authorization
self.printl("{}:<{}>登陆成功..".format(datetime.now().strftime('%b-%d-%Y %H:%M:%S'),self.userName) if Authorization else "{}:<{}>登陆失败..".format(datetime.now().strftime('%b-%d-%Y %H:%M:%S'),self.userName))
return Authorization # 这个就相当你开门的钥匙
def getPlanId(self):
self.printl("{}:<{}>获取PlanId".format(datetime.now().strftime('%b-%d-%Y %H:%M:%S'),self.userName))
data = {"state": ""}
response = requests.post(getPlanIdUrl,data=json.dumps(data), headers=header_maker(self.token), verify=False).text
response = json.loads(response)
self.planId = response.get('data')
if self.planId:
self.planId = self.planId[0].get('planId')
self.printl("{}:<{}>获取PlanId成功..".format(datetime.now().strftime('%b-%d-%Y %H:%M:%S'),self.userName) if self.planId else "{}:<{}>获取PlanId成功..".format(datetime.now().strftime('%b-%d-%Y %H:%M:%S'),self.userName))
return self.planId
def startHooks(self,START):
self.printl("{}:<{}>开始{}打卡".format(datetime.now().strftime('%b-%d-%Y %H:%M:%S'),self.userName,"上班" if START else "下班"))
data = {"country": self.location.get('country'), # 郭嘉
"address": self.location.get('address'), # 地址
"province": self.location.get('province'), # 省
"city": self.location.get('city'), # 城市
"latitude": self.location.get('latitude'), # 纬度
"description": self.location.get('description'), # 发表的信息
"planId": self.planId,
"type": "START" if START else "END", # START 上班 END 下班
"device": "Android",
"longitude": self.location.get('longitude') # 经度
}
print(data)
response2 = requests.post(startUrl, data=json.dumps(data), headers=header_maker(self.token), verify=False).text
res = json.loads(response2)
print(res)
self.printl("{}:<{}>{}打卡成功..".format(datetime.now().strftime('%b-%d-%Y %H:%M:%S'),self.userName,"上班" if START else "下班") if res.get('code') == 200 and res.get('msg') == 'success' else "{}:<{}>{}打卡失败..".format(datetime.now().strftime('%b-%d-%Y %H:%M:%S'),self.userName,"上班" if START else "下班"))
if __name__ == '__main__':
app = QApplication(sys.argv)
# 初始化
myWin = CoreFunc()
# 将窗口控件显示在屏幕上
myWin.show()
# 程序运行,sys.exit方法确保程序完整退出。
sys.exit(app.exec_())
# Authorization = log()
# planId = planId(Authorization)
# sin(Authorization, planId)
首次使用需要在同目录下的ini文件添加参数
exe文件成品: