Created
December 5, 2016 01:22
-
-
Save littlecodersh/da5ad98728627c25963da67b0180453d to your computer and use it in GitHub Desktop.
A demo of how to show itchat qrcode through website.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
感谢贡献代码