标题:python 怎么判断其token时效性
只看楼主
cwmlow
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2019-3-6
结帖率:0
已结贴  问题点数:20 回复次数:1 
python 怎么判断其token时效性
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令牌是否过期? 具体怎么实现
搜索更多相关主题的帖子: token import url request data 
2019-03-06 18:58
俺是你大爷
Rank: 2
等 级:论坛游民
帖 子:57
专家分:35
注 册:2019-3-12
得分:20 
很简单,比如用时间戳生成token,结果加上expire即可,expire是你想要延迟的时间。
判断时,直接时间戳比较,如果小于则说明token失效。
2019-03-12 11:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-493446-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.723674 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved