Python3
# -- 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()
GO
package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
"io"
"math/rand"
"net/http"
"strconv"
"strings"
"time"
)
const AppId string = "2xxxxxxxx"
const SdkId string = "1xxxxx"
const SecretID string = "qJxxxxxgxxx"
const SecretKey string = "9xxx7x
///**
// * 生成签名
// *
// * @param secretId 邮件下发的secret_id
// * @param secretKey 邮件下发的secret_key
// * @param httpMethod http请求方法 GET/POST/PUT等
// * @param headerNonce X-TC-Nonce请求头,随机数
// * @param headerTimestamp X-TC-Timestamp请求头,当前时间的秒级时间戳
// * @param requestUri 请求uri,eg:/v1/meetings
// * @param requestBody 请求体,没有的设为空串
// * @return 签名,需要设置在请求头X-TC-Signature中
// */
func DoSignature(secretId string, secretKey string, httpMethod string, headerNonce string, headerTimestamp string, requestUri string, requestBody string) string {
headSignStr := fmt.Sprintf("X-TC-Key=%s&X-TC-Nonce=%s&X-TC-Timestamp=%s",
secretId, headerNonce, headerTimestamp)
signStr := fmt.Sprintf("%s\n%s\n%s\n%s", httpMethod, headSignStr, requestUri, requestBody)
h := hmac.New(sha256.New, []byte(secretKey))
h.Write([]byte(signStr))
sha := hex.EncodeToString(h.Sum([]byte{}))
signBase64 := base64.StdEncoding.EncodeToString([]byte(sha))
return signBase64
}
func GetRoomList(meeting_room_namev string, page_sizev string, pagev string) (string, error) {
nonce := fmt.Sprintf("%02v", rand.New(rand.NewSource(time.Now().UnixNano())).Int63n(100))
time1 := time.Now()
headers := fmt.Sprintf("{\"X-TC-Key\": %v, \"X-TC-Timestamp\": %v, \"X-TC-Nonce\": %v, \"X-TC-Signature\": \"\", \"AppId\": %v, \"SdkId\": %v, \"X-TC-Registered\": \"1\"}", SecretID, strconv.FormatInt(time1.Unix(), 10), nonce, AppId, SdkId)
//headers := fmt.Sprintf("{\"X-TC-Key\": \"%s\", \"X-TC-Timestamp\": \"%s\", \"X-TC-Nonce\": \"%s\", \"X-TC-Signature\": \"\", \"AppId\": \"%s\", \"SdkId\": \"%s\", \"X-TC-Registered\": \"1\"}", SecretID, strconv.FormatInt(time1.Unix(), 10), nonce, AppId, SdkId)
uri := fmt.Sprintf("/v1/meeting-rooms?page=%s&page_size=%s&meeting_room_name=%s", pagev, page_sizev, meeting_room_namev)
signature := DoSignature(SecretID, SecretKey, "GET", nonce, strconv.FormatInt(time1.Unix(), 10), uri, "")
headers2 := strings.Replace(headers, "\"\"", signature, -1)
fmt.Println(headers2)
//headers2 := strings.Replace(headers, "\"\"", "\"" + signature + "\"", -1)
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.meeting.qq.com" + uri, nil)
req.Header.Add("X-TC-Key", SecretID)
req.Header.Add("X-TC-Timestamp", strconv.FormatInt(time1.Unix(), 10))
req.Header.Add("X-TC-Nonce", nonce)
req.Header.Add("X-TC-Signature", signature)
req.Header.Add("AppId", AppId)
req.Header.Add("SdkId", SdkId)
req.Header.Add("X-TC-Registered", "1")
resp, err := client.Do(req)
fmt.Println("https://api.meeting.qq.com" + uri)
if err != nil {
fmt.Println(headers2, "https://api.meeting.qq.com" + uri)
fmt.Println("##client.Do(req)")
return "", err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("###io.ReadAll(resp.Body)")
return "", err
}
fmt.Println(string(body))
return string(body), nil
}
func main() {
//time1 := time.Now()
//s := fmt.Sprintf("%02v", rand.New(rand.NewSource(time.Now().UnixNano())).Int63n(100))
//fmt.Println(s)
//fmt.Printf("type, %T %v", strconv.FormatInt(time1.Unix(), 10),strconv.FormatInt(time1.Unix(), 10))
GetRoomList("","1","1")
}