Python小程序开发:获取access_token

2021-08-1907:44:54APP与小程序开发Comments2,042 views字数 603阅读模式

使用Python调用微信小程序获取access_token接口进行获取请求凭据。为了便于操作,这边结合了Python自带的GUI库Tkinter。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/xcx/22165.html

import requests
import tkinter

def GetAccessToken():
    url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=你的APPID&secret=你的APPSECRET"
    res = requests.get(url)
    access_token = res.text
    print('已获得:'+access_token)

    # 写入JSON文件,缓存到本地JSON文件
    with open('access_token.json','w',encoding='utf-8') as f:
        f.write(access_token)
        
# GUI操作界面
root = tkinter.Tk()
root.geometry("500x300")
root.title("TANKING")
button = tkinter.Button(text="获取access_token",command=GetAccessToken)
button.pack()
button.mainloop()

Python小程序开发:获取access_token文章源自菜鸟学院-https://www.cainiaoxueyuan.com/xcx/22165.html

Author:TANKING
Date:2021-8-1
WeChat:sansure2016文章源自菜鸟学院-https://www.cainiaoxueyuan.com/xcx/22165.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/xcx/22165.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定