本章节为您介绍了阿里云语音服务语音通知的功能介绍和实现方法,您可以通过调用QueryCallDetailByCallId查询通话记录详情。

功能介绍

当您调用接口成功实现语音通知、语音验证码、语音IVR、点击拨号、智能外呼功能,您可以调用QueryCallDetailByCallId根据接口返回的CallId查询某个时间点的通话记录。

实现方法

在调用API实现该功能前,您需要完成以下操作:

  • 购买语音号码并审核通过语音模板或语音文件,具体操作请参见快速入门
  • 获取AccessKey信息,详情请参见获取AccessKey
  • 完成本地SDK环境搭建,详情请参见Java SDK

本章节调用接口详情,请参见QueryCallDetailByCallId

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

public class QueryCallDetailByCallId {
    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dyvmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("QueryCallDetailByCallId");
        request.putQueryParameter("CallId", "100625930001^10019107xx");
        request.putQueryParameter("ProdId", "11000000300004");
        request.putQueryParameter("QueryDate", "1577255564");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

正常返回结果如下所示:

{       
    "Data":{"caller":"1876713xx","startDate":"","stateDesc":"502","duration":0,"callerShowNumber":"0534475xx","gmtCreate":"2019-12-24 20:09:06","state":"502","endDate":"","calleeShowNumber":"0534475xx","callee":"1373546xx"}
    "Message": "OK",
    "RequestId": "A5291B00-1036-4CA2-8BFD-1238B784C9BA",
    "Code": "OK"
}

调用SDK返回错误码,详情请参见错误码列表