Code前端首页关于Code前端联系我们

Python小程序开发:获取access_token

terry 2年前 (2023-09-22) 阅读数 72 #移动小程序

使用Python调用微信小程序获取access_token接口来获取请求凭证。为了方便操作,这里结合了Python自带的GUI库Tkinter。

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

Author:坦克
日期:2021-8-1
微信:sansure2016

版权声明

本文仅代表作者观点,不代表Code前端网立场。
本文系作者Code前端网发表,如需转载,请注明页面地址。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门