python:微信支付链接转化成图片(data格式、PNG格式)
程序员文章站
2022-03-31 10:21:45
...
微信支付的链接基本格式如下:
weixin://wxpay/bizpayurl?pr=szIyqLmzz
拿到链接后,需要把它转成图片二维码,用来手机可扫描。
import base64
import qrcode
import io
def to_image( url):
img = qrcode.make(url)
img = img.get_image()
in_mem_file = io.BytesIO()
img.save(in_mem_file, format="PNG")
in_mem_file.seek(0)
img_bytes = in_mem_file.read()
base64_encoded_result_bytes = base64.b64encode(img_bytes)
base64_encoded_result_str = base64_encoded_result_bytes.decode('ascii')
# print(base64_encoded_result_str)
full_pr_code = 'data:image/png;base64,' +base64_encoded_result_str # 这里的png或其他格式可自定义
print(full_pr_code)
return full_pr_code
# to_image('weixin://wxpay/bizpayurl?pr=szIyqLmzz')
上面得到的是data格式的图片,如:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAXkElEQVR4Xu2d0Xbbug5E2///6Nyl01unqSSS2AIQyd15FUECg8EQpBz7548fPz5+PPjv44O5//Pnz9tHPYqtwv9uLLPjo/5TIlTkgPpC7bYqYBVEV0y2o0l/QvKyC2QGfTeW2fFR/2e4nD1/AodmsSkAM4S+8Xl2gcxCoQVECyE7Pur/DBcFgCLUYEeTTknbENJriewCmfnejWV2fNT/GS4KAEWowY4mXQHYJ6cbSwWgoUAmS3gE+P4cnHqQXSCzUBWAGUJfnz9hE5lFdCoAlAyzBcnzEdAVftL1CCGo/2Qtgn2lDYmd5qYijjv5Mopv5KcCcIAcTSwpSlIEm8tkrYoiuDIniZ3m5oqf5A6AxFbh44wrCoACUMW76bykSBSAKay7AXYAQcwoyciuTIpgpurBcL9tOImd5qYiyDv54hEgMcM0sQpALAkKQAwvOtoOIIicAhAEDA5XACBwQTMFIBGw7FdzpAg8AhwnlGIZpMdrON0o6HrULl0ASKs7c54WVoUdPU91E5DcTo9i6/a/gkdn8VXwhApARdw0PvQW4E4B0MAp2WnSZwKY+Zzmh2JCfad+kvUqeEK5UBE3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