建站学院

当前位置:

微信小程序中用Python生成二维码的两种方式

浏览量:1724次

本篇文章给大家带来的内容是关于微信小程序中用Python生成二维码的两种方式 ,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

微信小程序生成二维码:

所用语言python,有两种方式:

1: 后端传一段字符串给前端, 前端显示

2: 后端直接生成图片

1: 后端传一段字符串给前端, 前端显示

def get_wxCode(Request, UserInfo):
    try:
        scene = Request["scene"]
        access_token = get_wxCode_token()
        if not access_token:
            return False
        textmod = {"scene": scene, "page": "pages/index/main", "width": 430, "auto_color": True, "is_hyaline": False}
        textmod = json.dumps(textmod).encode(encoding='utf-8')
        header_dict = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko',
                       "Content-Type": "application/json"}
        url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' + access_token
        req = request.Request(url=url, data=textmod, headers=header_dict)
        res = request.urlopen(req)
        res = res.read()
        b64str = base64.b64encode(res)
        return b64str
    except Exception as e:
        print(e)
        return False

[声明]本网转载网络媒体稿件是为了传播更多的信息,此类稿件不代表本网观点,本网不承担此类稿件侵权行为的连带责任。故此,如果您发现本网站的内容侵犯了您的版权,请您的相关内容发至此邮箱【915688610@qq.com】,我们在确认后,会立即删除,保证您的版权。