隐私保护通话 PrivateNumber-AXB模式:获取录音文件下载地址接口

时间:2025-02-12 14:52:30

获取录音文件下载地址接口

 1 2 3 4 5 6 7 8 91011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
# -*- coding: utf-8 -*-import timeimport uuidimport hashlibimport base64import urllibimport requests #需要先使用pip install requests命令安装依赖import hmacfrom hashlib import sha256# 必填,请参考"开发准备"获取如下数据,替换为实际值realUrl = 'https://rtcpns.cn-north-1.myhuaweicloud.com/rest/provision/voice/record/v1.0' #APP接入地址+接口访问URIAPP_KEY = "a1********" #APP_KeyAPP_SECRET = "cfc8********" #APP_Secret# 必填,通过"话单通知接口"获取recordDomain = '****.com' #录音文件存储的服务器 域名 fileName = '****.wav' #录音文件名def buildAKSKHeader(appKey, appSecret):    now = time.strftime('%Y-%m-%dT%H:%M:%SZ') #Created    nonce = str(uuid.uuid4()).replace('-','') #Nonce    digist = hmac.new(appSecret.encode(), (nonce + now).encode(), digestmod=sha256).digest()    digestBase64 = base64.b64encode(digist).decode() #PasswordDigest    return 'UsernameToken Username="{}",PasswordDigest="{}",Nonce="{}",Created="{}"'.format(appKey, digestBase64, nonce, now);def main():    # 请求URL参数    formData = urllib.parse.urlencode({        'recordDomain':recordDomain,        'fileName':fileName    })    #完整请求地址    fullUrl = realUrl + '?' + formData    # 请求Headers参数    header = {        'Authorization': 'AKSK realm="SDP",profile="UsernameToken",type="Appkey"',        'X-AKSK': buildAKSKHeader(appKey, appSecret),        'Content-Type': 'application/json;charset=UTF-8'    }    try:        fo = open('bind_data.txt', 'a', encoding='utf-8') #打开本地文件        r = requests.get(fullUrl, headers=header, allow_redirects=False, verify=False) #发送请求        if(301 == r.status_code):            print(r.status_code) #打印响应结果            print(r.headers['Location'])            fo.write('获取录音文件下载地址:' + r.headers['Location'] + '\n')        else:            print(r.status_code) #打印响应结果            print(r.text)    except urllib.error.HTTPError as e:        print(e.code)        print(e.read().decode('utf-8')) #打印错误信息    except urllib.error.URLError as e:        print(e.reason)    finally:        fo.close() #关闭文件if __name__ == '__main__':    main()
support.huaweicloud.com/devg-PrivateNumber/privatenumber_01_0004.html