请问有哪位大佬有Python调用腾讯会议Api的demo吗?签名校验一直没法通过,提示{'error_info': {'error_code': 190303, 'new_error_code': 200190303, 'message': '鉴权失败:请检查请求头公共参数里字段AppId和X-TC-Key内容是否正确,字段SdkId如未分配不要携带。'}},以下我的代码
# -- coding:utf-8 --
import requests
import hmac
import base64
import time
import random
########test ############
# AppId = '21dd1xx10'
# SdkId = '1111140xx326'
# SecretID = '5vE111111x11111RnBK83'
# SecretKey = 'HkQa111111111111111qFNx9gETo'
#########pro ##############
AppId = '23xxxxxx12'
# SdkId = '18xxxxxxx147'
SecretID = '61k5ExxxxxxxxxxxxxxxxxxxxxxxqD'
SecretKey = 'yv1pgTTwsxxxxxxxxxxxxxxxxxxxxxxxeFd7Ds'
def sign(secretId, secretKey, httpMethod, headerNonce, headerTimestamp, requestUri, requestBody):
tobeSig = "{0}\nX-TC-Key={1}&X-TC-Nonce={2}&X-TC-Timestamp={3}\n{4}\n{5}".format(
httpMethod, secretId, headerNonce, headerTimestamp, requestUri, requestBody)
signature = hmac.new(secretKey.encode(
'utf-8'), tobeSig.encode('utf-8'), digestmod='sha256').hexdigest()
return base64.b64encode(signature.encode('utf-8'))
# room list
# def GetRoomList(pagev, page_sizev, meeting_room_namev):
def GetRoomList():
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"
}
print(Headers)
uri = "/v1/meeting-rooms"
Signature = sign(secretId=SecretID, secretKey=SecretKey, httpMethod="GET", headerNonce=Nonce,
headerTimestamp=TodyTime, requestUri=uri, requestBody="{}")
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']
if __name__ == "__main__":
GetRoomList()
相似问题