zhitou_trade/voice_notification.py
2025-05-22 16:47:45 +08:00

82 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
#reset
import sys
from aliyunsdkdyvmsapi.request.v20170525 import SingleCallByTtsRequest
from aliyunsdkdyvmsapi.request.v20170525 import SingleCallByVoiceRequest
from aliyunsdkcore.client import AcsClient
import uuid
from aliyunsdkcore.profile import region_provider
"""
语音业务调用接口示例版本号v20170525
Created on 2017-06-12
"""
#reload(sys)
#sys.setdefaultencoding('utf8')
# 注意:不要更改
REGION = "cn-hangzhou"
PRODUCT_NAME = "Dyvmsapi"
DOMAIN = "dyvmsapi.aliyuncs.com"
# ACCESS_KEY_ID/ACCESS_KEY_SECRET 根据实际申请的账号信息进行替换
ACCESS_KEY_ID = "LTAI4FnKS7B9tSx2o7n6soym"
ACCESS_KEY_SECRET = "L2dTEP5NsUydpBb8PJ0h2Hw3Irbc5L"
acs_client = AcsClient(ACCESS_KEY_ID, ACCESS_KEY_SECRET, REGION)
region_provider.add_endpoint(PRODUCT_NAME,REGION,DOMAIN)
def tts_call(business_id, called_number, called_show_number, tts_code, tts_param=None):
ttsRequest = SingleCallByTtsRequest.SingleCallByTtsRequest()
# 申请的语音通知tts模板编码,必填
ttsRequest.set_TtsCode(tts_code)
# 设置业务请求流水号,必填。后端服务基于此标识区分是否重复请求的判断
ttsRequest.set_OutId(business_id)
# 语音通知的被叫号码,必填。
ttsRequest.set_CalledNumber(called_number)
# 语音通知显示号码,必填。
ttsRequest.set_CalledShowNumber(called_show_number)
# tts模板变量参数
if tts_param is not None:
ttsRequest.set_TtsParam(tts_param)
# 调用tts文本呼叫接口返回json
ttsResponse = acs_client.do_action_with_exception(ttsRequest)
# TODO 业务处理
return ttsResponse
def voice_call(business_id, called_number, called_show_number, voice_code):
voiceRequest = SingleCallByVoiceRequest.SingleCallByVoiceRequest()
# 语音通知的媒体文件编码,必填
voiceRequest.set_VoiceCode(voice_code)
# 设置业务请求流水号,必填。
voiceRequest.set_OutId(business_id)
# 语音通知的被叫号码,必填。
voiceRequest.set_CalledNumber(called_number)
# 语音通知显示号码,必填。
voiceRequest.set_CalledShowNumber(called_show_number)
# 调用语音文件呼叫接口返回json
voiceResponse = acs_client.do_action_with_exception(voiceRequest)
# TODO 业务处理
return voiceResponse
def call_user(phonenum:str = "18242094506",server_describe: str='new strategy'):
__business_id = uuid.uuid1()
print (__business_id)
params = {
"servers":server_describe,
}
print (tts_call(__business_id, phonenum, "", "TTS_202815632", params))
if __name__=="__main__":
call_user()