通通锁官方文档:https://open.ttlock.com/document
1、获取访问令牌示例代码:
- import datetime as dt
- import http.client
- import time
- import json
- import requests
- import urllib3
- import os
- from hashlib import md5
- urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
-
- def getToken(comp_id, shop_id,phone,password):
-
- url = r'https://api.ttlock.com/oauth2/token'
- headers = {'Content-Type': "application/x-www-form-urlencoded"}
- data = {'client_id': '*****',
- 'client_secret': '****',
- 'username':'+86'+str(phone),
- 'password': md5Lower(password)
- }
-
- res = requests.post(url,headers = headers,data = data,verify=False)
-
- data = res.json()
- print(data)
-
2、调用开锁API示例代码:
- def unLock(comp_id, shop_id,client_id,accessToken,lockId):
-
- url = r'https://api.ttlock.com/v3/lock/unlock'
- headers = {'Content-Type': "application/x-www-form-urlencoded"}
- nowTime = time.time()
- nowTime = int(round(nowTime * 1000))
- data = {'clientId': client_id,
- 'accessToken': accessToken,
- 'lockId': lockId,
- 'date': nowTime
- }
-
- res = requests.post(url, headers=headers, data=data, verify=False)
- print(res)
- data = res.json()
- print(data)
3、访问开锁API时,

