cqwu-ehall/cqwu/methods/epay/gen_pay_qrcode.py
brian 60c32861ea
Support get score
Co-authored-by: brian <brian@xtaolabs.com>
2023-03-08 20:48:12 +08:00

32 lines
915 B
Python

import qrcode
from bs4 import BeautifulSoup
import cqwu
from cqwu.errors.auth import CookieError
class GenPayQrcode:
async def gen_pay_qrcode(
self: "cqwu.Client",
) -> None:
"""
生成支付二维码
"""
url = "http://218.194.176.214:8382/epay/thirdconsume/qrcode"
html = await self.oauth(url)
if not html:
raise CookieError()
if html.url != url:
raise CookieError()
soup = BeautifulSoup(html.text, "lxml")
try:
data = soup.find("input", attrs={"id": "myText"})["value"]
except (ValueError, TypeError, KeyError, IndexError):
return
qr = qrcode.QRCode()
qr.add_data(data)
qr.print_ascii(invert=True)
img = qrcode.make(data)
img.save("qrcode.png")
print("生成支付码到 qrcode.png 成功,请打开该文件查看")