|
11 | 11 | import itchat
|
12 | 12 | import magic
|
13 | 13 | import xmltodict
|
| 14 | +from pyqrcode import QRCode |
14 | 15 | from PIL import Image
|
15 | 16 |
|
16 | 17 | import config
|
@@ -145,16 +146,8 @@ def console_qr_code(self, uuid, status, qrcode):
|
145 | 146 | if status == 408:
|
146 | 147 | QR += "Previous code expired. Please scan the new one.\n"
|
147 | 148 | QR += "\n"
|
148 |
| - time.sleep(0.5) |
149 |
| - img = Image.open(io.BytesIO(qrcode)).convert("1") |
150 |
| - img = img.resize((img.size[0] // 10, img.size[1] // 10)) |
151 |
| - for i in range(img.size[0]): |
152 |
| - for j in range(img.size[1]): |
153 |
| - if img.getpixel((i, j)) > 0: |
154 |
| - QR += "\x1b[7m \x1b[0m" |
155 |
| - else: |
156 |
| - QR += "\x1b[49m \x1b[0m" |
157 |
| - QR += "\n" |
| 149 | + qr_url = "https://login.weixin.qq.com/l/" + uuid |
| 150 | + QR += QRCode(qr_url).terminal() |
158 | 151 | QR += "\nIf you cannot read the QR code above, " \
|
159 | 152 | "please visit the following URL:\n" \
|
160 | 153 | "https://login.weixin.qq.com/qrcode/" + uuid
|
@@ -184,8 +177,8 @@ def master_qr_code(self, uuid, status, qrcode):
|
184 | 177 | os.makedirs(path)
|
185 | 178 | path = os.path.join(path, 'QR-%s.jpg' % int(time.time()))
|
186 | 179 | self.logger.debug("master_qr_code file path: %s", path)
|
187 |
| - with open(path, 'wb') as f: |
188 |
| - f.write(qrcode) |
| 180 | + qr_url = "https://login.weixin.qq.com/l/" + uuid |
| 181 | + QRCode(qr_url).png(path, scale=10) |
189 | 182 | msg.text = 'Scan this QR Code with WeChat to continue.'
|
190 | 183 | msg.path = path
|
191 | 184 | msg.file = open(path, 'rb')
|
|
0 commit comments