Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A demo of how to show itchat qrcode through website.
import threading
from flask import Flask, make_response
import itchat
qrSource = ''
def start_flask():
flaskApp = Flask('itchat')
@flaskApp.route('/')
def return_qr():
if len(qrSource) < 100:
return qrSource
else:
response = make_response(qrSource)
response.headers['Content-Type'] = 'image/jpeg'
return response
flaskApp.run()
flaskThread = threading.Thread(target=start_flask)
flaskThread.setDaemon(True)
flaskThread.start()
def qrCallback(uuid, status, qrcode):
if status == '0':
global qrSource
qrSource = qrcode
elif status == '200':
qrSource = 'Logged in!'
elif status == '201':
qrSource = 'Confirm'
itchat.auto_login(True, qrCallback=qrCallback)
@itchat.msg_register(itchat.content.TEXT)
def reply_text(msg):
return msg['Text']
itchat.run()
@jjuu

This comment has been minimized.

Copy link

@jjuu jjuu commented May 27, 2018

感谢贡献代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment