flask 生成二维码(qrcode)
生成方法
# -*- coding: utf-8 -*- import qrcode from io import BytesIO def gen_qr_code(data): # 实例化QRCode生成qr对象 qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_H, box_size=10, border=4 ) # 传入数据 qr.add_data(data) qr.make(fit=True) img = qr.make_image() byte_io = BytesIO() img.save(byte_io, ‘PNG‘) byte_io.seek(0) return byte_io
接口
@activity_api.route("/generate_qr_code/", methods=[‘GET‘]) @api_wrap def generate_qr_code(): """ 生成二维码。data是加密过的数据,后端加密,前端解密 :param data: :return: """ # data = cmd_ops.decode_data(data) # 解密数据 data = request.args.get(‘data‘) if not data: return APIResult(sc.E_PARAM) qr_code = gen_qr_code(data) if qr_code: return Response(qr_code, mimetype=‘image/jpeg‘) else: return APIResult(sc.E_PARAM)
相关推荐
MIKUScallion 2019-12-15
hell0kitty 2019-11-30
bertZuo 2019-07-01
JamesNan 2019-06-29
zhaidpjava 2019-06-26
83457317 2012-09-27
mayflowers 2019-06-20
梦秋雨 2016-10-26
jsjcaowei 2018-01-31
asanlr 2015-12-27
xiyanwushi 2017-01-07
BlueBuleSky 2017-07-11
taku 2019-04-26
89443062 2016-04-03
87941037 2019-04-22