我不断收到错误代码400:“不受支持的REST API”。我的hmac246 base64编码签名是正确的,因为我已经用php中的另一个工作代码示例对其进行了测试。有人可以帮我解决问题吗?我正在使用python。
这是最终的输出.
这是输出http标头.
{'Content-Length': '0', 'Accept-Encoding': 'gzip, deflate', 'X-TC-Timestamp': '1589787785', 'X-TC-Nonce': '243222', 'User-Agent': 'python-requests/2.23.0', 'X-TC-Key': 'xxx', 'Connection': 'keep-alive', 'Accept': 'application/json', 'AppId': '200000164', 'content-type': 'application/json', 'X-TC-Signature': 'ZmUzYjg4ZjRlNTIwYTRiYTlhZGY3YTVhMzBiZGU4YjM3MDBhYWRmMmQ4OGJkYWE1NWQ2NmIzMjQ2ODQyNDkyNQ=='}
这是创建会议的发帖请求。
def add(start,end):
uri = '/v1/meetings'
userid = User.id
settings = {
"mute_enable_join" : True,
"allow_unmute_self" : True,
"mute_all" : False,
"host_video" : False,
"participant_video" : False,
"enable_record" : False,
"play_ivr_on_leave" : False,
"play_ivr_on_join" : False,
"live_url" : False
}
params = {'userid':userid,'instanceid': 5,
'subject':'consultation','type':0,
'start_time':str(start),
'end_time':str(end),
'settings':str(settings)}
headers = generateHeaders('POST',params,uri)
response = requests.post("https://api.meeting.qq.com/v1/meetings",headers=headers,params=params)
print(response.request.headers)
print(response.url)
return response.json()
这是标题生成
def generateHeaders(method,params,uri):
nonce = generate_nonce()
timeStamp = int(time.time())
headerString = "X-TC-Key=" + SecretId + "&X-TC-Nonce=" + str(nonce) + "&X-TC-Timestamp=" + str(timeStamp)
stringSign= method+"\n"+str(headerString)+"\n"+uri+"\n"+str(params)
b64 = create_sign(SecretKey,stringSign)
print('final=',b64)
return {'X-TC-Key': SecretId,
'X-TC-Timestamp': str(timeStamp),
'X-TC-Nonce': str(nonce),
'AppId': str(appID),
'X-TC-Signature': str(b64),
'content-type':'application/json',
'Accept': 'application/json'}
这是签名计算功能.
def create_sign(key,toSign):
h = hmac.new(key,msg=toSign.encode('utf-8'),digestmod=hashlib.sha256).hexdigest()
print(type(h))
print(h)
base = base64.b64encode(h.encode('utf-8'))
hash = base.decode('utf-8')
return hash
相似问题