关于python:Python获取accesstoken获取小程序的accesstoken

8次阅读

共计 605 个字符,预计需要花费 2 分钟才能阅读完成。

本文应用 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()

Author:TANKING
Date:2021-8-1
WeChat:sansure2016

正文完
 0