Skip to content

Commit

Permalink
Update AutoXGP.py
Browse files Browse the repository at this point in the history
修复部分问题
  • Loading branch information
AneryCoft authored Sep 15, 2023
1 parent fd21ebe commit 0a1137d
Showing 1 changed file with 126 additions and 103 deletions.
229 changes: 126 additions & 103 deletions AutoXGP.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import configparser
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.edge.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
Expand All @@ -30,7 +29,7 @@ def retry(func):
func()
return
except:
time.sleep(0.2)
time.sleep(delay)


# Logo
Expand All @@ -47,7 +46,7 @@ def retry(func):
[+]自动为您的微软账户注册Xbox并使用支付宝订阅XGP、设置MinecraftIGN、 取消订阅XGP
[Version]当前版本 B230821 DEBUG
[Version]当前版本 B230915 DEBUG
"""
)

Expand Down Expand Up @@ -103,7 +102,7 @@ def retry(func):
# 从cfg.ini文件中读取配置
config.read("config/cfg.ini")
# 支付宝支付密码
alipay_pay_password = int(config.getint("PASSWORD", "alipay_pay_password"))
alipay_pay_password = config.getint("PASSWORD", "alipay_pay_password")
if alipay_pay_password == 0:
# 输入支付宝支付密码
alipay_pay_password = input("输入你的支付宝支付密码:")
Expand All @@ -112,13 +111,15 @@ def retry(func):
config.write(configFile)
configFile.close()
print("[Debugger]保存支付宝支付密码成功......")
delay = config.getfloat("PARAMETER", "delay")

# 打开微软账户管理页面
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, "a[data-bi-source='CFQ7TTC0KGQ8']"
By.CSS_SELECTOR, "#pc > div > div.intro > div.c-group > a"
).click()
retry(join_button)
time.sleep(1.5)
Expand All @@ -136,45 +137,58 @@ def retry(func):
# 点击登录
login_button = lambda: driver.find_element(By.ID, "idSIButton9").click()
retry(login_button)
time.sleep(1)
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(8)
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.back()
# 输入Xbox用户名
try: # 检测是否注册了XBox
while True:

while True:
try:
Xbox_prefix = config.get("PROFILE", "Xbox_prefix")
Xbox_User = Xbox_prefix + randomUsername(15 - len(Xbox_prefix))
Xbox_username = driver.find_element(By.ID, "create-account-gamertag-input")
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")
)
start_button = WebDriverWait(driver, 5).until(
expected_conditions.element_to_be_clickable(
(By.ID, "inline-continue-control")
)
.click()
)
).click()
print("[Debugger]Xbox用户名设置为:" + Xbox_User)
time.sleep(3)
break
except:
continue
driver.find_element(By.XPATH, '//button[@aria-label="下一步"]')
except:
pass
next_button_2 = lambda: driver.find_element(
By.XPATH, '//button[@aria-label="下一步"]'
).click()
retry(next_button_2)
time.sleep(2)
except:
pass
try:
next_button_2 = lambda: driver.find_element(
By.XPATH, '//button[@aria-label="下一步"]'
).click()
retry(next_button_2)
break
except:
pass
time.sleep(delay)
# 添加付款方式
print("[Debugger]即将添加支付宝付款......")
driver.switch_to.frame("purchase-sdk-hosted-iframe")
Expand All @@ -184,103 +198,111 @@ def retry(func):
retry(add_payment_button)
time.sleep(2)
# 账户可能已经选择了支付方式
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()
# 输入名字与姓氏
while True:
try:
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"
# 选择PayPal或支付宝支付
eWallet_button = driver.find_element(By.ID, "displayId_ewallet").click()
# 选择支付宝支付
Alipay_button = driver.find_element(
By.ID, "displayId_ewallet_alipay_billing_agreement"
).click()
time.sleep(2)
except NoSuchElementException:
time.sleep(0.5)
# 输入名字与姓氏
try:
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
except:
pass
try:
# 新增支付宝账户
next_button_4 = lambda: driver.find_element(
By.ID, "pidlddc-button-saveNextButton"
).click()
retry(next_button_4)
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(3)
# 返回
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)
except:
pass
# 输入城市 & 地址
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)
print("[Debugger]订阅成功!")
driver.switch_to.default_content()
next_button_4 = lambda: driver.find_element(
By.ID, "pidlddc-button-saveNextButton"
).click()
retry(next_button_4)
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(3)
# 返回
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)
print("[Debugger]订阅成功!")
driver.switch_to.default_content()
break
except:
pass
time.sleep(delay)

# 打开官网设置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.CSS_SELECTOR, "a[aria-label='Sign in with Microsoft account']"
).click()
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)
)send_keys(IGN)
retry(input_ID)
# 确认
set_ID_button = driver.find_element(
By.CSS_SELECTOR, "button[aria-label='Set up your Profile Name']"
).click()
)click()
time.sleep(2)
print("[Debugger]ID设置成功! ID为:" + IGN)

# 打开微软退款
print("[Debugger]即将打开退款链接......")
driver.get(
Expand All @@ -296,16 +318,17 @@ def retry(func):
# 点击取消订阅
cancel_button = lambda: driver.find_element(
By.CSS_SELECTOR, "button[aria-label='Cancel subscription']"
).click()
)click()
retry(cancel_button)
# 选择立即退款按钮
refund_button = driver.find_element(
By.CSS_SELECTOR, "input[aria-label='Cancel now and get refund']"
).click() # ChoiceGroup92-cancel-now
)click() # ChoiceGroup92-cancel-now
# 点击取消订阅按钮
cancel_button = driver.find_element(By.ID, "cancel-select-cancel").click()
time.sleep(3)
print("[Debugger]已经成功退款!")

# 退出Edge
driver.quit()
account = Email + "----" + Password + "----" + IGN
Expand Down

0 comments on commit 0a1137d

Please sign in to comment.