python学习笔记(2):生成小程序码

在之前处理使用php 和go 语法生成对应的二维码。今天尝试了一下python,发现生成小程序代码极其简练。同时也非常适合做一些小工具。下面贴上几行代码。

import requests,json

bodyinfo = requests.get("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}".format('APPID','APPSECRET'))
res = requests.post("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={0}".format(json.loads(bodyinfo.text)["access_token"]),
                    json={"path": "pages/index/index", "width": 430, "scene": "aa,bb"})
with open('qrcode.png', 'wb') as f:
    f.write(res.content)

将APPID 和 APPSECRET 修改对应的小程序appid和密钥即可。剩下的就执行相应的代码。可以说这样的代码非常简练。对于这样一个小小需求,修改相应的小程序参数即可满足到日常的维护需求。

{"path": "pages/index/index", "width": 430, "scene": "aa,bb"}
发布了1410 篇原创文章 · 获赞 64 · 访问量 236万+

猜你喜欢

转载自blog.csdn.net/hero82748274/article/details/103194706