# -- coding:utf-8 --
import requests
import hmac
import base64
import hashlib
import time
import random
import json
########test ############
# AppId = '21dd1xx10'
# SdkId = '1111140xx326'
# SecretID = '5vE111111x11111RnBK83'
# SecretKey = 'HkQa111111111111111qFNx9gETo'
#########pro ##############
AppId = '210x111x1119'
SdkId = '1811111x1147'
SecretID = 'qxF1111xxxxxxxxx9OUfxxxxxxg'
SecretKey = 'xxxpFxxxwInDpVRxxxxxxXVQRbTN477'
def get_sign(method, uri, Params, Nonce1, Time1):
headerString = "X-TC-Key=" + SecretID + "&X-TC-Nonce=" + Nonce1 + "&X-TC-Timestamp=" + Time1
data = method + "\n" + headerString + "\n" + uri + "\n" + Params
data = bytes(data.encode('utf-8'))
key = SecretKey.encode('utf-8')
return (base64.b64encode((hmac.new(key, data, digestmod=hashlib.sha256).hexdigest()).encode('utf-8'))).decode(
'utf-8')
def CrateWrok():
uri = '/v1/meetings'
Params = json.dumps({
"userid": "liyao",
"instanceid": 1,
"subject": "tester's meeting",
"type": 0,
"start_time": "1646200421",
"end_time": "1646204021"
})
Signature = get_sign('POST', uri, Params)
Headers['X-TC-Signature'] = Signature
GetData = requests.post("https://api.meeting.qq.com" + uri, headers=Headers, data=Params)
print(GetData.json())
print(Headers)
# 获取开课列表
def GetWorkList():
uri = "/v1/meetings?userid=admin&instanceid=1"
Signature = get_sign('GET', uri, Params='')
Headers['X-TC-Signature'] = Signature
GetData = requests.get("https://api.meeting.qq.com" + uri, headers=Headers)
print(GetData.json())
#user list
def GetuserList1(pagev, page_sizev):
TodyTime = str(int(time.time()))
Nonce = str(int(random.random() * 10000))
Headers = {
"X-TC-Key": SecretID,
"X-TC-Timestamp": TodyTime,
"X-TC-Nonce": Nonce,
"X-TC-Signature": '',
"AppId": AppId,
"SdkId": SdkId,
"X-TC-Registered": "1"
}
uri = "/v1/users/list?page={tpagev}&page_size={tpage_sizev}".format(tpage_sizev=page_sizev, tpagev=pagev)
Signature = get_sign('GET', uri, Params='', Nonce1=Nonce, Time1=TodyTime)
Headers['X-TC-Signature'] = Signature
GetData = requests.get("https://api.meeting.qq.com" + uri, headers=Headers)
#print(GetData.json())
data_count = GetData.json()
return data_count['total_count']
#room list
def GetRoomList(pagev, page_sizev, meeting_room_namev):
TodyTime = str(int(time.time()))
Nonce = str(int(random.random() * 10000))
Headers = {
"X-TC-Key": SecretID,
"X-TC-Timestamp": TodyTime,
"X-TC-Nonce": Nonce,
"X-TC-Signature": '',
"AppId": AppId,
"SdkId": SdkId,
"X-TC-Registered": "1"
}
uri = "/v1/meeting-rooms?page={page}&page_size={page_size}&meeting_room_name={meeting_room_name}".format(
meeting_room_name=meeting_room_namev, page_size=page_sizev, page=pagev)
Signature = get_sign('GET', uri, Params='', Nonce1=Nonce, Time1=TodyTime)
Headers['X-TC-Signature'] = Signature
GetData = requests.get("https://api.meeting.qq.com" + uri, headers=Headers)
#print(GetData.json())
data_count = GetData.json()
return data_count['total_count']
#查询账户下 Rooms 资源
def GetRoominventory():
TodyTime = str(int(time.time()))
Nonce = str(int(random.random() * 10000))
Headers = {
"X-TC-Key": SecretID,
"X-TC-Timestamp": TodyTime,
"X-TC-Nonce": Nonce,
"X-TC-Signature": '',
"AppId": AppId,
"SdkId": SdkId,
"X-TC-Registered": "1"
}
uri = "/v1/rooms-inventory"
Signature = get_sign('GET', uri, Params='', Nonce1=Nonce, Time1=TodyTime)
Headers['X-TC-Signature'] = Signature
GetData = requests.get("https://api.meeting.qq.com" + uri, headers=Headers)
#print(GetData.json())
return GetData.json()