-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
223 lines (197 loc) · 6.48 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# -*- coding: utf8 -*-
# -*- by:look新
# -*- 2021年10月12日
#
import datetime
import json
import pytz
import requests
import urllib3
import os
urllib3.disable_warnings()
pwd = os.path.dirname(os.path.abspath(__file__)) + os.sep
BASE_URL = "https://api.moguding.net:9000/"
SIGN_URL = "http://api.mcyou.xyz/"
headers = {
"Host": "api.moguding.net:9000",
"accept-language": "zh-CN,zh;q=0.8",
"user-agent": "手机的ua",#查询https://www.ip138.com/useragent/查询
"sign": "",
"authorization": "",
"rolekey": "",
"content-type": "application/json; charset=UTF-8",
"accept-encoding": "gzip",
"cache-control": "no-cache"
}
INFORMATION = {"phone":"账号",
"password":"密码"}
MESSAGE = ""
TITLE = ""
UPDATE_INFO = ""
FAILURES_COUNT = 0
# 登录
def login():
global MESSAGE,FAILURES_COUNT
if INFORMATION.get("phone") is None or INFORMATION.get("phone").strip() == '':
MESSAGE += "\n手机号为空"
return
if INFORMATION.get("password") is None or INFORMATION.get("password").strip() == '':
MESSAGE += "\n密码为空"
return
requestsBody = {
"phone": INFORMATION["phone"],
"password": INFORMATION["password"],
"loginType": "android",
"uuid": ""
}
url = BASE_URL + "session/user/v1/login"
response = requests.post(url=url, headers=headers, data=json.dumps(requestsBody), verify=False)
responseJson = response.json()
if responseJson["code"] != 200:
msg = responseJson["msg"]
FAILURES_COUNT+=1
print(msg)
return
data = responseJson["data"]
#print(data)
nikeName = data["nikeName"]
userId = data["userId"]
token = data["token"]
userType = data["userType"]
moguNo = data["moguNo"]
newData = {
"nikeName": nikeName,
"userId": userId,
"token": token,
"userType": userType,
"moguNo": moguNo
}
INFORMATION.update(newData)
def getUserInfo():
global MESSAGE
headers.update(
{"authorization": INFORMATION.get("token"), "rolekey": "student"}
)
requestsBody = {}
url = BASE_URL + "usercenter/user/v1/info"
response = requests.post(url=url, headers=headers, data=json.dumps(requestsBody), verify=False)
responseJson = response.json()
if responseJson["code"] != 200:
MESSAGE = responseJson["msg"]
print(responseJson["msg"])
else:
data = responseJson["data"]
nikeName = data["nikeName"]
userId = data["userId"]
userType = data["userType"]
moguNo = data["moguNo"]
newData = {
"nikeName": nikeName,
"userId": userId,
"userType": userType,
"moguNo": moguNo
}
INFORMATION.update(newData)
# 获取计划
def getPlanByStu():
global TITLE, MESSAGE
# 没有token则重新登录
login()
getUserInfo()
paramString = ""
parameterSign = {
"userId": INFORMATION["userId"],
"paramString": paramString,
"moguNo": INFORMATION["moguNo"],
"userType": INFORMATION["userType"],
}
sign = getSign("getsigninfo.php", parameterSign)
headers.update(
{"authorization": INFORMATION.get("token"), "rolekey": "student", "sign": sign}
)
requestsBody = {
"state": paramString
}
url = BASE_URL + "practice/plan/v3/getPlanByStu"
response = requests.post(url=url, headers=headers, data=json.dumps(requestsBody), verify=False)
responseJson = response.json()
print(responseJson)
if responseJson["code"] != 200:
print(responseJson["msg"])
else:
dataList = responseJson["data"]
data = dataList[len(dataList) - 1]
planName = data["planName"]
planId = data["planId"]
dataNew = {
"planName": planName,
"planId": planId,
}
INFORMATION.update(dataNew)
# 获取sign
def getSign(url,parameter):
response = requests.post(url=SIGN_URL + url,data=parameter)
responseJson = response.json()
print(responseJson)
if responseJson["code"] == 200 :
return responseJson["sign"]
def signIn(type):
global TITLE, MESSAGE
if INFORMATION.get("token") is None or INFORMATION.get("token").strip() == '':
print("没有获取到token,请检查是否正确登录!")
return
if INFORMATION.get("planId") is None or INFORMATION.get("planId").strip() == '':
print("没有获取到planId,请检查是否正确指定签到对象!")
MESSAGE = "没有获取到planId,请检查是否正确指定签到对象!"
return
typeStr = "START" if type == 1 else "END"
parameterSign = {
"userId": INFORMATION["userId"],
"moguNo": INFORMATION["moguNo"],
"address": "签到地址",
"device": "Android",
"planId": INFORMATION["planId"],
"type": typeStr,
"latitude": "经度",
"longitude": "维度"
}
sign = getSign("getsignseve.php", parameterSign)
headers.update({"authorization": INFORMATION.get("token"), "rolekey": "student", "sign": sign})
requestsBody = {
"country": "",
"address": "签到地址",
"province": "",
"city": "",
"latitude": INFORMATION.get("latitude"),
"description": "",
"planId": INFORMATION["planId"],
"type": typeStr,
"device": "经度",
"longitude": "维度"
}
url = BASE_URL + "attendence/clock/v2/save"
response = requests.post(url=url, headers=headers, data=json.dumps(requestsBody), verify=False)
responseJson = response.json()
if responseJson["code"] != 200:
msg = responseJson["msg"]
MESSAGE = msg
print(msg)
else:
createTime = responseJson["data"]["createTime"]
TITLE = "%s,%s打卡成功!" % (INFORMATION["nikeName"], "上班" if typeStr == "START" else "下班")
MESSAGE = " 目标:%s\n\n 打卡时间:%s \n\n 打卡地点:%s" % (INFORMATION["planName"], createTime, INFORMATION['address'])
# 主程序
def main():
global INFORMATION, TITLE, MESSAGE
getPlanByStu()
hourNow = datetime.datetime.now(pytz.timezone('PRC')).hour
signIn(1) #1上班 0下班
MESSAGE = UPDATE_INFO + MESSAGE
if TITLE == "":
TITLE = "%s,打卡失败!" % (INFORMATION["nikeName"])
INFORMATION = {}
MESSAGE = ""
TITLE = ""
if __name__ == '__main__':
main()
#sign的地址可能会过期,记得可以加群获取最新签名:568330068