本文为您介绍如何调用ClickToDial接口发起语音双呼。

功能介绍

语音双呼是指通过语音服务分配的号码分别向主叫、被叫发起呼叫,双方接通后建立起正常通话,通话双方显示的号码均为语音服务平台号码。常用于企业办公电话等,例如钉钉办公电话。通过调用ClickToDial接口可隐藏通话双方真实号码,同时平台可留存双方通话记录。

实现方法

在调用API接口发起语音双呼前,您需要完成以下操作: 接口详情,请参见发起语音双呼
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;
import com.alibaba.fastjson.JSON;

public class ClickToDial {
    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("ClickToDial");
        request.putQueryParameter("CallerShowNumber", "123xxxx");
        request.putQueryParameter("CallerNumber", "1575xxxx");
        request.putQueryParameter("CalledShowNumber", "12xxxx");
        request.putQueryParameter("CalledNumber", "1885xxxx");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(JSON.toJSONString(response.getData()));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

正常返回结果如下所示:

{
  "Message": "OK",
  "RequestId": "762104B0-D58A-4D04-8486-7C5171D0D756",
  "Code": "OK",
  "CallId": "118720797955^10551795xx"
}

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