赞
踩
from PIL import Image
from io import BytesIO
# 用来生成一个图片实例,其中imgBuffer 为 图片的 buffer
img = Image.open(BytesIO(imgBuffer))
# 把图片保存在一个路径底下
img.save('/home/sku/111.jpg')
appid = '小程序的appid' appsecret = '小程序的appsecret ' token_url = 'https://api.weixin.qq.com/cgi-bin/token' code_url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit' def GetToken(): params = { 'appid': appid, 'secret': appsecret, 'grant_type': 'client_credential' } res = requests.get(url=token_url, params=params) result = json.loads(res.content) return result['access_token'] def GetCode(token, shopid): data = { 'page': 'pages/index/index', 'scene': shopid } headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE', 'Content-Type': "application/json;charset=UTF-8" } res = requests.post( url = code_url + '?access_token=' + token , data = json.dumps(data), headers = headers ) return res.content # 外部调用的函数 def CreateEntrance(shopid): # 获取token token = GetToken() # 根据token和shopid获取指定的小程序码图片 buffer imgBuffer = GetCode(token, shopid) #保存图片 img = Image.open(BytesIO(imgBuffer)) imgPath = '/home/sku/'+ shopid +'.jpg' img.save(imgPath)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。