Skip to content

Instantly share code, notes, and snippets.

@littlecodersh
Created December 5, 2016 01:22
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save littlecodersh/da5ad98728627c25963da67b0180453d to your computer and use it in GitHub Desktop.
Save littlecodersh/da5ad98728627c25963da67b0180453d to your computer and use it in GitHub Desktop.
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
Copy link

jjuu commented May 27, 2018

感谢贡献代码

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