官方文档
import cString
import requests
from tornado.web import authenticated, RequestHandler
URL = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode'
def fetch_qrcode_image(path, width=430):
params = {'access_token': 'access_token'}
json_data = {
'width': width,
'path': path
}
res = requests.post(URL, params=params, json=json_data, timeout=3, verify=False)
qrcode_image = cStringIO.StringIO(res.content)
return qrcode_image.getvalue()
# tornado
class QRCodeHandler(RequestHandler):
def get(self):
path = self.get_argument('path')
if not path:
self.set_status(404)
return
qr_code = fetch_qrcode_image(path)
if not qr_code:
self.set_status(404)
return
self.set_header('Content-Type', 'image/jpeg')
self.finish(qr_code)
|
请发表评论