Skip to content

Commit

Permalink
Merge pull request #74 from ipid/main
Browse files Browse the repository at this point in the history
fix: 二维码接口使用 getPayParam;二维码显示尺寸限定为 300x300 且避免说明挡住二维码图片
  • Loading branch information
mikumifa authored Jun 1, 2024
2 parents ac1478d + ebde106 commit 2554af1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
10 changes: 9 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@
<script src="https://static.geetest.com/static/js/gt.0.4.9.js"></script>
"""

custom_css = """
.pay_qrcode img {
width: 300px !important;
height: 300px !important;
margin-top: 20px; /* 避免二维码头部的说明文字挡住二维码 */
}
"""

if __name__ == "__main__":
logger.add("app.log")

with gr.Blocks(head=short_js) as demo:
with gr.Blocks(head=short_js, css=custom_css) as demo:
gr.Markdown(header)
with gr.Tab("配置"):
setting_tab()
Expand Down
4 changes: 1 addition & 3 deletions tab/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ def start_go(tickets_info_str, time_start, interval, mode, total_attempts):
if errno == 0:
qrcode_url = get_qrcode_url(
_request,
request_result["data"]["token"],
tickets_info["project_id"],
request_result["data"]["orderId"],
)
qr_gen = qrcode.QRCode()
Expand Down Expand Up @@ -263,7 +261,7 @@ def go_tab():
max_lines=10,

)
qr_image = gr.Image(label="使用微信或者支付宝扫码支付", visible=False)
qr_image = gr.Image(label="使用微信或者支付宝扫码支付", visible=False, elem_classes="pay_qrcode")

with gr.Row(visible=False) as gt_row:
gt_html_btn = gr.Button("点击打开抢票验证码(请勿多点!!)")
Expand Down
15 changes: 8 additions & 7 deletions util/order_qrcode.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import time


def get_qrcode_url(_request, token, project_id, order_id):
url = f"https://show.bilibili.com/api/ticket/order/createstatus?token={token}"
f"&timestamp={int(round(time.time() * 1000))}"
f"&project_id={project_id}&orderId={order_id}"
def get_qrcode_url(_request, order_id):
url = f"https://show.bilibili.com/api/ticket/order/getPayParam?order_id={order_id}"
data = _request.get(url).json()
if data["errno"] == 0:
return data["data"]["payParam"]["code_url"]
else:
try:
if data["errno"] == 0:
return data["data"]["code_url"]
else:
raise Exception
except Exception:
return None

0 comments on commit 2554af1

Please sign in to comment.