更新 'api/wechat3.py'

master
newrain001 1 year ago
parent d798718d8e
commit 377b6e4571
  1. 24
      api/wechat3.py

@ -37,10 +37,26 @@ class Tencent(object):
# 获取tokent
def get_token(self):
token_url = '%s/cgi-bin/gettoken?corpid=%s&corpsecret=%s' % (self.url, CorpID, Secret)
r = requests.get(token_url)
r = r.json()
token = r['access_token']
return token
if not os.path.isfile('./token.json'):
r = requests.get(token_url)
r = r.json()
token = r['access_token']
with open('./token.json', 'w') as f:
json.dump({'timestamp': time.time(), 'token': token}, f)
return token
else:
with open('./token.json', 'r') as f:
token_data = json.load(f)
print(time.time() - int(token_data.get('timestamp')))
if time.time() - int(token_data.get('timestamp')) > 7000:
r = requests.get(token_url)
r = r.json()
token = r['access_token']
with open('./token.json', 'w') as f:
json.dump({'timestamp': time.time(), 'token': token}, f)
return token
else:
return token_data['token']
# 发送信息
def send_message(self):

Loading…
Cancel
Save