注册 登录
编程论坛 Python论坛

python 怎么判断其token时效性

cwmlow 发布于 2019-03-06 18:58, 2404 次点击
getset_token.py文件(获取token):
程序代码:

import urllib.parse
import urllib.request
import json
import datetime

 

 
url='https://api.weixin.'
data={'appid':'*******************',
      'secret':'************************************'}
data=urllib.parse.urlencode(data).encode('utf-8')
request=urllib.request.urlopen(url,data)
html= request.read()
tokenandtime=json.loads(html)
access_token=tokenandtime['access_token']
expires_in=tokenandtime['expires_in'] #token时效=7200



selectmenu.py(查询菜单接口):
程序代码:

import urllib.request
import getset_token
import json

 
token = getset_token.access_token
url = 'https://api.weixin.' + token
request = urllib.request.urlopen(url)
html=request.read()
data_dict=json.loads(html)

微信的token令牌为7200秒,我怎么再调用接口的时候去验证token令牌是否过期? 具体怎么实现
1 回复
#2
俺是你大爷2019-03-12 11:36
很简单,比如用时间戳生成token,结果加上expire即可,expire是你想要延迟的时间。
判断时,直接时间戳比较,如果小于则说明token失效。
1