阿里云语音电话的sdk的调用实例

/**
     * 语音呼叫
     *
     * @return
     * @throws ClientException /http/RealTimeInfo/Call.json
     */
    public RetObj doCall() throws ClientException {
        RetObj retObj = new RetObj();
        //设置访问超时时间
        System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
        System.setProperty("sun.net.client.defaultReadTimeout", "10000");
        //云通信产品-语音API服务产品名称(产品名固定,无需修改)
        final String product = "Dyvmsapi";
        //产品域名(接口地址固定,无需修改)
        final String domain = "dyvmsapi.aliyuncs.com";
        //AK信息
        final String accessKeyId = 语音服务的id;
        final String accessKeySecret = 密钥;
        //初始化acsClient 暂时不支持多region
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
        DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
        IAcsClient acsClient = new DefaultAcsClient(profile);
        SingleCallByTtsRequest request = new SingleCallByTtsRequest();
        //必填-被叫显号,可在语音控制台中找到所购买的显号
        request.setCalledShowNumber("123456");
        //必填-被叫号码
        request.setCalledNumber("123456");
        //必填-Tts模板ID
        request.setTtsCode(模板id);
        //可选-当模板中存在变量时需要设置此值(传的是json字符串))
        request.setTtsParam("{\n" +
                "\"number\":\"1223456\",\n" +
                "\"time\":\"2020年6月10日9点21分\",\n" +
                "\"alarm\":\"超出区域报警\"\n" +
                "}");
        //可选-音量 取值范围 0--200
        request.setVolume(100);
        //可选-播放次数
        request.setPlayTimes(3);
        //可选-外部扩展字段,此ID将在回执消息中带回给调用方
        request.setOutId("yourOutId");
        //hint 此处可能会抛出异常,注意catch
        SingleCallByTtsResponse singleCallByTtsResponse = acsClient.getAcsResponse(request);
        //使用sdk返回的提示语(集体可以查看阿里云的文档)
        String code = singleCallByTtsResponse.getCode();
        String code1 = singleCallByTtsResponse.getCode();
        if (code != null && code1.equals("OK")) {
            //请求成功
            System.out.println("语音文本外呼---------------");
            System.out.println("RequestId=" + singleCallByTtsResponse.getRequestId());
            System.out.println("Code=" + singleCallByTtsResponse.getCode());
            System.out.println("Message=" + singleCallByTtsResponse.getMessage());
            System.out.println("CallId=" + singleCallByTtsResponse.getCallId());
        }else{
            logger.error("code="+code+";code1="+code1);
        }
        return retObj;
    }

你可能感兴趣的:(阿里云语音电话的sdk的调用实例)