def access_token(): p1="data/dingtalk/token.txt" b1=True#是否请求token re="" if os.path.exists(p1): r=txtread(p1) a1=json.loads(r) t1=a1["time"] tk=a1["access_token"] if t1<int(time.time()): b1=True else: b1=False re=tk #b1为true 请求更新token if b1: print("正在获取token")
# app_key="####"
# app_secret="###"
# url="https://oapi.dingtalk.com/gettoken?appkey={0}&appsecret={1}".format(app_key,app_secret) r=requests.get(url) a1=json.loads(r.text) tk=a1["access_token"] t1=int(time.time())+7000 a2={"access_token":tk,"time":t1} txtwrite(p1,json.dumps(a2)) re=tk return re