当前位置: 首页 > 后端技术 > Python

Python获取access_token(获取小程序的access_token)

时间:2023-03-25 20:00:08 Python

本文使用Python调用微信小程序获取access_token接口获取请求凭证。为了方便操作,这里结合了Python自带的GUI库Tkinter。importrequestsimporttkinterdefGetAccessToken():url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=你的APPID&secret=你的APPSECRET"res=requests.get(url)access_token=res.textprint('Acquired:'+access_token)#写入JSON文件,缓存到本地JSON文件withopen('access_token.json','w',encoding='utf-8')asf:f.write(access_token)#GUI操作界面root=tkinter.Tk()root.geometry("500x300")root.title("TANKING")button=tkinter.Button(text="Getaccess_token",command=GetAccessToken)button.pack()button.mainloop()作者:TANKING日期??:2021-8-1微信:sansure2016