-
Notifications
You must be signed in to change notification settings - Fork 0
/
testapi.py
235 lines (223 loc) · 10.4 KB
/
testapi.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
224
225
226
227
228
229
230
231
232
233
234
235
# -*- coding: UTF-8 -*-
import requests as req
import json,sys,time,random
#注册后一定要再点代表xxx授予管理员同意,否则outlook api无法调用
#以下空行不要删除,以便运行时插入机密
id_list2 = [1]
secret_list2 = [1]
config_list = {'每次轮数':6,
'是否启动随机时间':'Y','延时范围起始':600,'结束':1200,
'是否开启随机api顺序':'Y',
'是否开启各api延时':'N','api延时范围开始':2,'api延时结束':5,
'是否开启各账号延时':'Y','账号延时范围开始':60,'账号延时结束':120,
'是否开启备用应用':'N','是否开启测试':'N'}
num1 = [0]*len(id_list)
path2=sys.path[0]+r'/config/randomapi.txt'
path3=sys.path[0]+r'/config/buconfig.txt'
rapi = {'1':r'https://graph.microsoft.com/v1.0/me/',
'2':r'https://graph.microsoft.com/v1.0/users',
'3':r'https://graph.microsoft.com/v1.0/me/people',
'4':r'https://graph.microsoft.com/v1.0/groups',
'5':r'https://graph.microsoft.com/v1.0/me/contacts',
'6':r'https://graph.microsoft.com/v1.0/me/drive/root',
'7':r'https://graph.microsoft.com/v1.0/me/drive/root/children',
'8':r'https://graph.microsoft.com/v1.0/drive/root',
'9':r'https://graph.microsoft.com/v1.0/me/drive',
'10':r'https://graph.microsoft.com/v1.0/me/drive/recent',
'11':r'https://graph.microsoft.com/v1.0/me/drive/sharedWithMe',
'12':r'https://graph.microsoft.com/v1.0/me/calendars',
'13':r'https://graph.microsoft.com/v1.0/me/events',
'14':r'https://graph.microsoft.com/v1.0/sites/root',
'15':r'https://graph.microsoft.com/v1.0/sites/root/sites',
'16':r'https://graph.microsoft.com/v1.0/sites/root/drives',
'17':r'https://graph.microsoft.com/v1.0/sites/root/columns',
'18':r'https://graph.microsoft.com/v1.0/me/onenote/notebooks',
'19':r'https://graph.microsoft.com/v1.0/me/onenote/sections',
'20':r'https://graph.microsoft.com/v1.0/me/onenote/pages',
'21':r'https://graph.microsoft.com/v1.0/me/messages',
'22':r'https://graph.microsoft.com/v1.0/me/mailFolders',
'23':r'https://graph.microsoft.com/v1.0/me/outlook/masterCategories',
'24':r'https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages/delta',
'25':r'https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messageRules',
'26':r"https://graph.microsoft.com/v1.0/me/messages?$filter=importance eq 'high'",
'27':r'https://graph.microsoft.com/v1.0/me/messages?$search="hello world"',
'28':r'https://graph.microsoft.com/beta/me/messages?$select=internetMessageHeaders&$top',
'29':r'https://api.powerbi.com/v1.0/myorg/apps'}
rapi2 = {'1':r'https://graph.microsoft.com/v1.0/me/drive/root',
'2':r'https://graph.microsoft.com/v1.0/me/drive',
'3':r'https://graph.microsoft.com/v1.0/drive/root',
'4':r'https://graph.microsoft.com/v1.0/users',
'5':r'https://graph.microsoft.com/v1.0/me/messages',
'6':r'https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messageRules',
'7':r'https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages/delta',
'8':r'https://graph.microsoft.com/v1.0/me/drive/root/children',
'9':r'https://graph.microsoft.com/v1.0/me/mailFolders',
'10':r'https://graph.microsoft.com/v1.0/me/outlook/masterCategories',
'11':r'https://api.powerbi.com/v1.0/myorg/apps'}
fc = open(path2, "r+")
randapi = fc.read()
fc.close()
fh = open(path3, "r+")
buconfig = fh.read()
fh.close()
randomapi = randapi.split(',')
def gettoken(refresh_token,a):
headers={'Content-Type':'application/x-www-form-urlencoded'
}
data={'grant_type': 'refresh_token',
'refresh_token': refresh_token,
'client_id':id_lists[a],
'client_secret':secret_lists[a],
'redirect_uri':'http://localhost:53682/'
}
html = req.post('https://login.microsoftonline.com/common/oauth2/v2.0/token',data=data,headers=headers)
jsontxt = json.loads(html.text)
refresh_token = jsontxt['refresh_token']
access_token = jsontxt['access_token']
return access_token
def testapi(path,a,ls):
fo = open(path, "r+")
refresh_token = fo.read()
fo.close()
localtime = time.asctime( time.localtime(time.time()) )
access_token=gettoken(refresh_token,a)
headers={
'Authorization':access_token,
'Content-Type':'application/json'
}
print('账号 '+str(a)+'\n第 '+str(ls)+' 轮运行开始时间为 :', localtime)
if config_list['是否开启随机api顺序'] == 'Y':
print('总api数13个,请自行确认个数')
for ra in range(14):
rana = str(randomapi[ra])
try:
if req.get(rapi[rana],headers=headers).status_code == 200:
num1[a]+=1
print("账号"+str(a)+"的"+rana+"号api调用成功,所有api总成功"+str(num1[a])+'次')
if config_list['是否开启各api延时'] != 'N':
gg = random.randint(config_list['api延时范围开始'],config_list['api延时结束'])
time.sleep(gg)
except:
print("pass")
pass
else:
print('总api数10个,请自行确认个数')
for ra in range(1,12):
rana = str(ra)
try:
if req.get(rapi2[rana],headers=headers).status_code == 200:
num1[a]+=1
print("账号"+str(a)+"的"+rana+"号api调用成功,所有api总成功"+str(num1[a])+'次')
if config_list['是否开启各api延时'] != 'N':
gg = random.randint(config_list['api延时范围开始'],config_list['api延时结束'])
time.sleep(gg)
except:
print("pass")
pass
def testapi2(path,a,ls):
fo = open(path, "r+")
refresh_token = fo.read()
fo.close()
localtime = time.asctime( time.localtime(time.time()) )
access_token=gettoken(refresh_token,a)
headers={
'Authorization':access_token,
'Content-Type':'application/json'
}
print('账号 '+str(a)+' 备用应用\n第 '+str(ls)+' 轮运行开始时间为 :', localtime)
if config_list['是否开启随机api顺序'] == 'Y':
print('总api数13个,请自行确认个数')
else:
print('总api数10个,请自行确认个数')
if config_list['是否开启随机api顺序'] == 'Y':
for ra in range(14):
rana = str(randomapi[ra])
try:
if req.get(rapi[rana],headers=headers).status_code == 200:
num1[a]+=1
print("账号"+str(a)+"备用的"+rana+"号api调用成功,所有api总成功"+str(num1[a])+'次')
if config_list['是否开启各api延时'] != 'N':
gg = random.randint(config_list['api延时范围开始'],config_list['api延时结束'])
time.sleep(gg)
except:
print("pass")
pass
else:
for ra in range(1,12):
rana = str(ra)
try:
if req.get(rapi2[rana],headers=headers).status_code == 200:
num1[a]+=1
print("账号"+str(a)+"备用的"+rana+"号api调用成功,所有api总成功"+str(num1[a])+'次')
if config_list['是否开启各api延时'] != 'N':
gg = random.randint(config_list['api延时范围开始'],config_list['api延时结束'])
time.sleep(gg)
except:
print("pass")
pass
def main():
if config_list['是否启动随机时间'] == 'Y':
for ls in range(config_list['每次轮数']):
b=random.randint(config_list['延时范围起始'],config_list['结束'])
time.sleep(b)
for a in range(0, len(id_lists)):
if config_list['是否开启各账号延时'] == 'Y':
c = random.randint(config_list['账号延时范围开始'],config_list['账号延时结束'])
time.sleep(c)
path=sys.path[0]+r'/token/'+str(a)+'.txt'
testapi(path,a,ls)
else:
for ls in range(config_list['每次轮数']):
for a in range(0, len(id_lists)):
if config_list['是否开启各账号延时'] == 'Y':
c = random.randint(config_list['账号延时范围开始'],config_list['账号延时结束'])
time.sleep(c)
path=sys.path[0]+r'/token/'+str(a)+'.txt'
testapi(path,a,ls)
def main2():
if config_list['是否启动随机时间'] == 'Y':
for ls in range(config_list['每次轮数']):
b=random.randint(config_list['延时范围起始'],config_list['结束'])
time.sleep(b)
for a in range(0, len(id_lists)):
if config_list['是否开启各账号延时'] == 'Y':
c = random.randint(config_list['账号延时范围开始'],config_list['账号延时结束'])
time.sleep(c)
path=sys.path[0]+r'/backuptoken/'+str(a)+'.txt'
testapi2(path,a,ls)
else:
for ls in range(config_list['每次轮数']):
for a in range(0, len(id_lists)):
if config_list['是否开启各账号延时'] == 'Y':
c = random.randint(config_list['账号延时范围开始'],config_list['账号延时结束'])
time.sleep(c)
path=sys.path[0]+r'/backuptoken/'+str(a)+'.txt'
testapi2(path,a,ls)
if config_list['是否开启测试'] == 'Y':
config_list = {'每次轮数':1,'是否启动随机时间':'N','延时范围起始':600,'结束':1200,'是否开启随机api顺序':'Y','是否开启各api延时':'N','api延时范围开始':2,'api延时结束':5,'是否开启各账号延时':'N','账号延时范围开始':60,'账号延时结束':120,'是否开启备用应用':'N','是否开启测试':'N'}
id_lists=id_list
secret_lists=secret_list
main()
if id_list2 != [1]:
id_lists=id_list2
secret_lists=secret_list2
main2()
else:
if config_list['是否开启备用应用'] == 'Y':
if buconfig == 'Y':
id_lists=id_list
secret_lists=secret_list
main()
else:
if id_list2 == [1]:
id_lists=id_list
secret_lists=secret_list
main()
else:
id_lists=id_list2
secret_lists=secret_list2
main2()
else:
id_lists=id_list
secret_lists=secret_list
main()