【问题标题】:How to decrypt QRcode in TelegramBotAPI如何在 Telegram Bot API 中解密 QR 码
【发布时间】:2022-01-05 15:22:56
【问题描述】:

我正在创建一个可以生成和解密二维码的电报机器人。我使用 BytesIO 实现了二维码的创建:

#bot creating a qrcode
@bot.message_handler(commands=['create'])
def creating_qr(message):
    bot.send_message(message.chat.id, 'Enter text and ill generate QRcode')
    @bot.message_handler(content_types=['text'])
    def creating_qr(message):
        qr_img = qrcode.make(message.text)
        bio = BytesIO()
        qr_img.save(bio, 'JPEG')
        bio.seek(0)
        bot.send_photo(message.chat.id, bio)

我尝试使用相同的方法解密 qrcode,但 ApiTelegramBot 文档说 photo 是一个列表,因此我无法将其保存在 BytesIO 中。如何保存photo然后解密?

我尝试过的方法:

def decrypting(message):
    detector = cv2.QRCodeDetector()
    qr_image = message.photo
    bio = BytesIO()
    qr_image.save(bio, 'JPEG')
    bio.seek(0)
    data = detector.detectAndDecode(bio)
    bot.send_message(message.chat.id, f'QR code data: \n\n{data}')

【问题讨论】:

  • 嗨 Valeriy,欢迎来到 stackoverflow!你不应该把编程语言之类的东西放在标题中,而是使用标签(就像你所做的那样)。

标签: python api qr-code py-telegram-bot-api


【解决方案1】:

我自己没有使用过 API,但是 Pyhton 和 Telegram :) 一条消息可以有多张照片。所以我猜你会得到一张照片列表。要选择第一张照片,请更改您的代码,如下所示:

qr_image = message.photo[0]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-07
    • 2020-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-10
    • 1970-01-01
    • 2021-11-26
    相关资源
    最近更新 更多