forked from Sa3ura/XGP_V1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAutoXGP.py
386 lines (356 loc) · 13.5 KB
/
AutoXGP.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
import ctypes
import json
import random
import time
import configparser
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
# 设置控制台标题
ctypes.windll.kernel32.SetConsoleTitleW("Auto Xbox Game Pass")
# 随机生成Xbox用户名
def randomUsername(length):
base_Str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"
random_str = ""
for i in range(length):
random_str += base_Str[random.randint(0, (len(base_Str) - 1))]
return random_str
def retry(func):
while True:
try:
func()
return
except:
time.sleep(delay)
# Logo
print(
"""
_____ ____ _______ _
/ ____| |___ \ |__ __| | |
| (___ __ _ __) | _ _ _ __ __ _ | | ___ ___ | |__
\___ \ / _` | |__ < | | | || '__|/ _` | | | / _ \ / __|| '_ \
____) || (_| | ___) || |_| || | | (_| | _ | || __/| (__ | | | |
|_____/ \__,_||____/ \__,_||_| \__,_|(_)|_| \___| \___||_| |_|
[+]自动为您的微软账户注册Xbox并使用支付宝订阅XGP、设置MinecraftIGN、 取消订阅XGP
[Version]当前版本 B231003 DEBUG
[Release]github.com/AneryCoft/AutoXGP
"""
)
# 从文件中获取账户
# acc = input("输入你的账户(格式为邮箱----密码):")
account_file = open("account/account.txt")
accounts = account_file.readlines()
account_file.close()
# 保存XGP
XGP_file = open("account/XGP.txt","a+")
# 设置Edge浏览器驱动
edge_options = Options()
edge_options.binary_location = (
r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
)
edge_options.use_chromium = False
edge_options.add_experimental_option("useAutomationExtension", False)
edge_options.add_argument("--inprivate")
# 添加excludeSwitches参数,禁用调试信息
edge_options.add_experimental_option(
"excludeSwitches", ["enable-automation", "enable-logging"]
)
# 创建Edge浏览器对象
driver = webdriver.Edge(options=edge_options)
config = configparser.ConfigParser()
# 从cfg.ini文件中读取配置
config.read("config/cfg.ini")
delay = config.getfloat("PARAMETER", "delay")
# 获取保存的Cookie
cookie_file = open("cookies/alipay_cookies.json", "r+")
alipay_cookies = cookie_file.read()
if alipay_cookies == "":
# 登录支付宝并获取Cookie
print("[Debugger]请登录支付宝以获取Cookie......")
driver.get(
"https://auth.alipay.com/login/index.htm?goto=https%3A%2F%2Fwww.alipay.com%2F"
)
while True:
if driver.current_url.startswith("https://www.alipay.com/"):
break
else:
time.sleep(delay)
alipay_cookies = driver.get_cookies()
cookie_file.write(json.dumps(alipay_cookies))
print("[Debugger]保存支付宝Cookie成功......")
else:
driver.get("https://www.alipay.com/")
alipay_cookies = json.loads(alipay_cookies)
for cookie in alipay_cookies:
driver.add_cookie(cookie)
print("[Debugger]已添加支付宝Cookie......")
cookie_file.close()
# 支付宝支付密码
alipay_pay_password = config.getint("PASSWORD", "alipay_pay_password")
if alipay_pay_password == 0:
# 输入支付宝支付密码
alipay_pay_password = input("输入你的支付宝支付密码:")
config.set("PASSWORD", "alipay_pay_password", alipay_pay_password)
configFile = open("config/cfg.ini", "w")
config.write(configFile)
configFile.close()
print("[Debugger]保存支付宝支付密码成功......")
for account in accounts:
account = account.replace('\n','')
parts = account.split("----")
Email = parts[0]
Password = parts[1]
# 打开微软账户管理页面
print("[Debugger]即将打开Edge并进入XGP官网......")
driver.get("https://www.xbox.com/zh-HK/xbox-game-pass#join")
time.sleep(3)
# 在页面上查找29港币的PC Game pass
join_button = lambda: driver.find_element(
By.CSS_SELECTOR, "#pc > div > div.intro > div.c-group > a"
).click()
retry(join_button)
time.sleep(1.5)
# 输入邮箱
print("[Debugger]即将输入微软账户登录Xbox......")
input_email = lambda: driver.find_element(By.NAME, "loginfmt").send_keys(Email)
retry(input_email)
# 点击下一步
next_button = lambda: driver.find_element(By.ID, "idSIButton9").click()
retry(next_button)
time.sleep(1.5)
# 输入密码
input_pwd = lambda: driver.find_element(By.NAME, "passwd").send_keys(Password)
retry(input_pwd)
# 点击登录 readlines()获取的账户后带有换行符
login_button = lambda: driver.find_element(By.ID, "idSIButton9").click()
retry(login_button)
time.sleep(1.5)
# 跳过微软账户保护
try:
skip = driver.find_element(By.ID, "iShowSkip").click()
time.sleep(1.5)
except:
pass
# 点击保持登录状态
keep_login_button = lambda: driver.find_element(By.ID, "idSIButton9").click()
retry(keep_login_button)
time.sleep(1.5)
# 取消摆脱密码束缚
try:
cancel = driver.find_element(By.ID, "iCancel").click()
time.sleep(1.5)
except:
pass
time.sleep(5)
# 可能会跳转到Xbox官网
if driver.current_url.startswith("https://www.xbox.com/zh-CN/"):
driver.get("https://www.xbox.com/zh-HK/xbox-game-pass#join")
time.sleep(1)
join_button = lambda: driver.find_element(
By.CSS_SELECTOR, "#pc > div > div.intro > div.c-group > a"
).click()
retry(join_button)
time.sleep(1.5)
# 输入Xbox用户名
while True:
try:
Xbox_username = driver.find_element(By.ID, "create-account-gamertag-input")
Xbox_prefix = config.get("PROFILE", "Xbox_prefix")
Xbox_User = Xbox_prefix + randomUsername(15 - len(Xbox_prefix))
Xbox_username.clear()
Xbox_username.send_keys(Xbox_User)
try: # 防止用户名无法使用
start_button = WebDriverWait(driver, 5).until(
expected_conditions.element_to_be_clickable(
(By.ID, "inline-continue-control")
)
).click()
print("[Debugger]Xbox用户名设置为:" + Xbox_User)
time.sleep(3)
except:
continue
except:
pass
try:
next_button_2 = driver.find_element(
By.XPATH, '/html/body/reach-portal/div[3]/div/div/div/div/div/div/div/div/div/div/div[2]/div[4]/div/div[2]/button'
).click()
break
except:
pass
time.sleep(delay)
# 添加付款方式
print("[Debugger]即将添加支付宝付款......")
driver.switch_to.frame("purchase-sdk-hosted-iframe")
add_payment_button = lambda: driver.find_element(
By.XPATH, '//button[@class="primary--DXmYtnzQ base--kY64RzQE"]'
).click()
retry(add_payment_button)
time.sleep(2)
# 账户可能已经选择了支付方式
while True:
try:
# TODO:为什么这里无法运行
# driver.switch_to.default_content()
close = driver.find_element(
By.XPATH, "/html/body/reach-portal/div[3]/div/div/div/div/div/div/div/div[2]/div/div[1]/button"
).click()
break # 直接订阅成功
except:
pass
"""
try:
driver.switch_to.frame("purchase-sdk-hosted-iframe")
except:
continue
"""
try:
# 选择PayPal或支付宝支付
eWallet_button = driver.find_element(By.ID, "displayId_ewallet").click()
# 选择支付宝支付
Alipay_button = driver.find_element(
By.ID, "displayId_ewallet_alipay_billing_agreement"
).click()
# 输入名字与姓氏
first_name = driver.find_element(By.ID, "first_name").send_keys("a")
last_name = driver.find_element(By.ID, "last_name").send_keys("a")
# 点击下一步
next_button_3 = driver.find_element(
By.ID, "pidlddc-button-submitButton"
).click()
time.sleep(2)
except:
pass
try:
# 新增支付宝账户
next_button_4 = driver.find_element(
By.ID, "pidlddc-button-saveNextButton"
).click()
time.sleep(0.5)
"""
# 等待扫码
print('[Debugger]等待支付宝扫码......')
input("扫码后请回车")
"""
# 登入支付宝
login_alipay = lambda: driver.find_element(
By.ID, "pidlddc-hyperlink-alipayQrCodeChallengeRedirectionLink"
).click()
retry(login_alipay)
time.sleep(3)
driver.switch_to.window(driver.window_handles[1])
# 输入支付密码
pay_password = lambda: driver.find_element(
By.ID, "payPassword_rsainput"
).send_keys(alipay_pay_password)
retry(pay_password)
# 同意协议并提交
agree = driver.find_element(By.ID, "J_submit").click()
time.sleep(5)
# 返回
driver.close()
driver.switch_to.window(driver.window_handles[0])
driver.switch_to.frame("purchase-sdk-hosted-iframe")
time.sleep(1)
# back = driver.find_element(By.ID,'J_time').click()
# 点击继续
continue_button = lambda: driver.find_element(
By.ID, "pidlddc-button-alipayContinueButton"
).click()
retry(continue_button)
time.sleep(1)
# 输入城市 & 地址
input_city = lambda: driver.find_element(By.ID, "city").send_keys("1")
retry(input_city)
input_address = driver.find_element(By.ID, "address_line1").send_keys("1")
# 点击储存按钮
save_button = driver.find_element(By.ID, "pidlddc-button-saveButton").click()
time.sleep(3)
# 点击订阅按钮
print("[Debugger]即将为您订阅Xbox Game Pass PC......")
subscription_button = lambda: driver.find_element(
By.XPATH, '//button[@class="primary--DXmYtnzQ base--kY64RzQE"]'
).click()
retry(subscription_button)
time.sleep(3)
driver.switch_to.default_content()
break
except:
pass
time.sleep(delay)
print("[Debugger]订阅成功!")
# 打开官网设置ID
print("[Debugger]即将跳转Minecraft官网为您设置ID.....")
driver.get("https://www.minecraft.net/en-us/msaprofile/mygames/editprofile")
time.sleep(3)
# 点击微软登录登录按钮
home_login_button = lambda: driver.find_element(
By.XPATH, "/html/body/div[3]/div/main/div[2]/div/div/div/div[1]/div[1]/div[1]/a"
).click()
retry(home_login_button)
time.sleep(5)
# 输入随机ID
IGN_prefix = config.get("PROFILE", "IGN_prefix")
IGN = IGN_prefix + randomUsername(16 - len(IGN_prefix))
input_ID = lambda: driver.find_element(
By.CSS_SELECTOR, "input[name='profileName']"
).send_keys(IGN)
retry(input_ID)
# 确认
set_ID_button = driver.find_element(
By.CSS_SELECTOR, "button[aria-label='Set up your Profile Name']"
).click()
time.sleep(2)
print("[Debugger]ID设置成功! ID为:" + IGN)
# 打开微软退款
print("[Debugger]即将打开退款链接......")
driver.get(
"https://account.microsoft.com/services/pcgamepass/cancel?fref=billing-cancel&lang=en-US"
)
time.sleep(3)
# 继续账户内容汇集
try:
button = driver.find_element(By.XPATH, "/html/body/div/div/div[2]/button").click()
except:
pass
time.sleep(5)
# 点击取消订阅
cancel_button = lambda: driver.find_element(
By.CSS_SELECTOR, "button[aria-label='Cancel subscription']"
).click()
retry(cancel_button)
# 选择立即退款按钮
refund_button = driver.find_element(
By.CSS_SELECTOR, "input[aria-label='Cancel now and get refund']"
).click() # ChoiceGroup92-cancel-now
# 点击取消订阅按钮
cancel_button = driver.find_element(By.ID, "cancel-select-cancel").click()
time.sleep(3)
print("[Debugger]已经成功退款!")
account = Email + "----" + Password + "----" + IGN
print("账号信息:" + account)
XGP_file.write(account + "\n")
if(account == accounts[-1]):
account_manage = lambda: driver.find_element(By.XPATH, '//*[@id="O365_MainLink_Me"]').click()
retry(account_manage)
sign_out = lambda: driver.find_element(By.ID,"mectrl_body_signOut").click()
retry(sign_out)
time.sleep(3)
# 退出Edge
print(f"成功为{len(accounts)}个账户获取XGP!")
XGP_file.close()
driver.quit()
key = input("按回车键退出脚本,按'C'键清除支付宝Cookies。")
if(key.upper() == 'C'):
cookie_file = open("cookies/alipay_cookies.json", "w")
cookie_file.write("")
cookie_file.close()
"""
account = Email + "----" + Password + "----" + IGN
print("账号信息:" + account)
pyperclip.copy(account)
print("已经为您复制好。")
input("按回车键退出脚本。")
"""