Skip to content

Commit

Permalink
update and fix bugs (#110)
Browse files Browse the repository at this point in the history
## FriendshipEnder (fsender) 新功能

1. 多个NTP地址

2. 多语言

3. 购票人信息打码 (用*号) 隐私保护

4. 修复原作者的一部分bug和优化体验

5. 没有啦, 版本号改成0.8.4啦
  • Loading branch information
ZianTT authored Jun 28, 2024
2 parents 4b68e14 + 41069f7 commit 3c27ff0
Show file tree
Hide file tree
Showing 11 changed files with 1,007 additions and 323 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ srlandpic.py
venv
inquirer
agree-terms
share.json
share.json
language
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# BHYG

## FriendshipEnder 新功能

1. 多个NTP地址

2. 多语言

3. 购票人信息打码 (用*号) 隐私保护

4. 修复原作者的一部分bug和优化体验

5. 没有啦

## 总述

这是一款购票辅助工具。
Expand Down
76 changes: 38 additions & 38 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
from i18n import i18n

from utils import save, load
from globals import *

class BilibiliHyg:
global sdk
global i18n_lang
from globals import i18n_lang
def __init__(self, config, sdk,client,session):
self.waited = False
self.sdk = sdk
Expand All @@ -39,14 +43,14 @@ def __init__(self, config, sdk,client,session):
if self.client != None:
self.ip = self.client.tps_current_ip(sign_type="hmacsha1")
if self.config["mode"] == 'time':
logger.info("当前为定时抢票模式")
logger.info("等待到达开票时间前15分钟以获取token...")
logger.info(i18n[i18n_lang]["now_mode_time_on"])
logger.info(i18n[i18n_lang]["get_token_15min"])
while self.get_time() < self.config["time"]-900:
time.sleep(10)
logger.info("距离开票时间还有{:.2f}秒".format((self.config["time"]-self.get_time())))
logger.info("准备完毕,获取token中...")
logger.info(i18n[i18n_lang]["now_waiting_info"].format((self.config["time"]-self.get_time())))
logger.info(i18n[i18n_lang]["get_token_finish"])
self.token = self.get_token()
logger.info("即将开始下单")
logger.info(i18n[i18n_lang]["will_pay_bill"])

def get_time(self):
return float(time.time() + self.config["time_offset"])
Expand All @@ -63,11 +67,11 @@ def get_ticket_status(self):
requests.exceptions.ReadTimeout,
requests.exceptions.ConnectionError,
):
logger.error("网络连接超时")
logger.error(i18n[i18n_lang]["network_timeout"])
if self.config["proxy"]:
if self.ip == self.client.tps_current_ip(sign_type="hmacsha1"):
logger.info(
i18n["zh"]["manual_change_ip"].format(
i18n[i18n_lang]["manual_change_ip"].format(
self.client.change_tps_ip(sign_type="hmacsha1")
)
)
Expand All @@ -76,26 +80,22 @@ def get_ticket_status(self):
return -1, 0
try:
if response.status_code == 412:
logger.error(
"可能被业务风控\n该种业务风控请及时暂停,否则可能会引起更大问题。"
)
logger.error(i18n[i18n_lang]["wind_control"])
if self.config["proxy"]:
if self.ip == self.client.tps_current_ip(sign_type="hmacsha1"):
logger.info(
i18n["zh"]["manual_change_ip"].format(
i18n[i18n_lang]["manual_change_ip"].format(
self.client.change_tps_ip(sign_type="hmacsha1")
)
)
self.session.close()
return self.get_ticket_status()
else:
self.risk = True
logger.error(
"你也可以尝试更换网络环境,如重启流量(飞行模式开关)重新拨号(重启光猫)等"
)
input("请确认排除问题后按三下回车继续")
input("请再按两下回车继续")
input("请再按一下回车继续")
logger.error(i18n[i18n_lang]["net_method"])
input(i18n[i18n_lang]["res_3_returns"])
input(i18n[i18n_lang]["res_2_returns"])
input(i18n[i18n_lang]["res_1_return"])
return -1, 0
screens = response.json()["data"]["screen_list"]
# 找到 字段id为screen_id的screen
Expand All @@ -105,7 +105,7 @@ def get_ticket_status(self):
screen = screens[i]
break
if screen == {}:
logger.error("未找到场次")
logger.error(i18n[i18n_lang]["no_found_screen"])
return -1, 0
# 找到 字段id为sku_id的sku
skus = screen["ticket_list"]
Expand All @@ -115,11 +115,11 @@ def get_ticket_status(self):
sku = skus[i]
break
if sku == {}:
logger.error("未找到票档")
logger.error(i18n[i18n_lang]["no_found_sku"])
return -1, 0
return int(sku["sale_flag_number"]), sku["clickable"]
except:
logger.error("可能被风控")
logger.error(i18n[i18n_lang]["may_wind_control"])
return -1, 0

def get_prepare(self):
Expand All @@ -143,11 +143,11 @@ def get_prepare(self):
data["act_id"] = self.config["act_id"]
response = self.session.post(url, headers=self.headers, data=data)
if response.status_code == 412:
logger.error(i18n["zh"]["not_handled_412"])
logger.error(i18n[i18n_lang]["not_handled_412"])
if self.config["proxy"]:
if self.ip == self.client.tps_current_ip(sign_type="hmacsha1"):
logger.info(
i18n["zh"]["manual_change_ip"].format(
i18n[i18n_lang]["manual_change_ip"].format(
self.client.change_tps_ip(sign_type="hmacsha1")
)
)
Expand Down Expand Up @@ -192,7 +192,7 @@ def phone_verify(self, token):
if "phone" in self.config:
phone = self.config["phone"]
else:
phone = input("请输入手机号:")
phone = input(i18n[i18n_lang]["input_phone_num"]+": ")
self.captcha_data = {
"code": phone,
}
Expand All @@ -208,7 +208,7 @@ def phone_verify(self, token):
data=self.captcha_data,
).json()["data"]["is_valid"]
if not success:
logger.error("验证失败")
logger.error(i18n[i18n_lang]["input_verify_fail"])
if "phone" in self.config:
self.config.pop("phone")
return False
Expand All @@ -234,34 +234,34 @@ def confirm_info(self, token):
)
response = self.session.get(url, headers=self.headers)
if response.status_code == 412:
logger.error(i18n["zh"]["not_handled_412"])
logger.error(i18n[i18n_lang]["not_handled_412"])
if self.config["proxy"]:
if self.ip == self.client.tps_current_ip(sign_type="hmacsha1"):
logger.info(
i18n["zh"]["manual_change_ip"].format(
i18n[i18n_lang]["manual_change_ip"].format(
self.client.change_tps_ip(sign_type="hmacsha1")
)
)
self.session.close()
return self.confirm_info(token)
response = response.json()
logger.info("信息已确认")
logger.info(i18n[i18n_lang]["info_confirmed"])
logger.debug(response)
self.config["order_type"] = response["data"]["order_type"]
if response["data"]["act"] is not None:
logger.info("检测到优惠活动")
logger.info(i18n[i18n_lang]["info_discount"])
self.config["act_id"] = response["data"]["act"]["act_id"]
return

def get_token(self):
info = self.get_prepare()
if info == {}:
logger.warning("未开放购票或被风控,请检查配置问题,休息1s")
logger.warning(i18n[i18n_lang]["info_no_ticket"])
time.sleep(1)
self.get_token()
if info["token"]:
logger.success(
"成功准备订单"
i18n[i18n_lang]["info_bill_ok"]
+ "https://show.bilibili.com/platform/confirmOrder.html?token="
+ info["token"]
)
Expand All @@ -273,10 +273,10 @@ def get_token(self):
try:
self.confirm_info(info["token"])
except:
logger.error("确认订单失败")
logger.error(i18n[i18n_lang]["info_bill_fail"])
return info["token"]
else:
logger.warning("触发风控。")
logger.warning(i18n[i18n_lang]["info_wind_control"])
self.sdk.add_breadcrumb(
category="gaia",
message="Gaia found",
Expand Down Expand Up @@ -386,7 +386,7 @@ def create_order(self):
if self.config["proxy"]:
if self.ip == self.client.tps_current_ip(sign_type="hmacsha1"):
logger.info(
i18n["zh"]["manual_change_ip"].format(
i18n[i18n_lang]["manual_change_ip"].format(
self.client.change_tps_ip(sign_type="hmacsha1")
)
)
Expand All @@ -400,7 +400,7 @@ def create_order(self):
if self.config["proxy"]:
if self.ip == self.client.tps_current_ip(sign_type="hmacsha1"):
logger.info(
i18n["zh"]["manual_change_ip"].format(
i18n[i18n_lang]["manual_change_ip"].format(
self.client.change_tps_ip(sign_type="hmacsha1")
)
)
Expand All @@ -427,11 +427,11 @@ def fake_ticket(self, pay_token, order_id = None):
logger.debug(url)
response = self.session.get(url, headers=self.headers)
if response.status_code == 412:
logger.error(i18n["zh"]["not_handled_412"])
logger.error(i18n[i18n_lang]["not_handled_412"])
if self.config["proxy"]:
if self.ip == self.client.tps_current_ip(sign_type="hmacsha1"):
logger.info(
i18n["zh"]["manual_change_ip"].format(
i18n[i18n_lang]["manual_change_ip"].format(
self.client.change_tps_ip(sign_type="hmacsha1")
)
)
Expand Down Expand Up @@ -477,11 +477,11 @@ def order_status(self, order_id):
url = "https://show.bilibili.com/api/ticket/order/info?order_id=" + str(order_id)
response = self.session.get(url, headers=self.headers)
if response.status_code == 412:
logger.error(i18n["zh"]["not_handled_412"])
logger.error(i18n[i18n_lang]["not_handled_412"])
if self.config["proxy"]:
if self.ip == self.client.tps_current_ip(sign_type="hmacsha1"):
logger.info(
i18n["zh"]["manual_change_ip"].format(
i18n[i18n_lang]["manual_change_ip"].format(
self.client.change_tps_ip(sign_type="hmacsha1")
)
)
Expand Down
5 changes: 3 additions & 2 deletions geetest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2023-2024 ZianTT, FriendshipEnder
import json
import time

Expand All @@ -6,7 +7,7 @@
import bili_ticket_gt_python
from loguru import logger


from globals import *
# REF: https://github.com/mikumifa/biliTickerBuy
# REF: https://github.com/Amorter/biliTicker_gt
# LICENSE: GPL-3.0
Expand Down Expand Up @@ -45,7 +46,7 @@ def run(gt, challenge, token, mode="local_gt", key=None):
"appkey": key,
"gt": gt,
"challenge": challenge,
"referer": "https://show.bilibili.com"
"referer": "https://show.bilibili.com",
}
try:
response = requests.post("http://api.rrocr.com/api/recognize.html", data=param).json()
Expand Down
Loading

0 comments on commit 3c27ff0

Please sign in to comment.