1.背景
最近公司做的项目需要在线支持拨打虚拟电话给联系人,就对阿里云呼叫服务(云联络中心)进行调研测试。本文主要针对“双呼A”这一功能后端对接进行简单说明,有问题欢迎一起交流
2.准备工作
- 阿里云账号(个人/企业)
- 开通云联络中心->进入云联络中心管理控制台
- 个人账号: 创建实例
- 企业账号: 可先创建体验版演示实例
具体开通参考:如何开通和使用云联络中心_云联络中心(Cloud Contact Center)-阿里云帮助中心
3.双呼A接口
双呼和传统的双方通话不同,主叫并不直接呼叫对方,而是通过一个背靠背代理(Back to Back Agent),背靠背代理首先呼叫主叫方,接通后,再呼叫被叫方,然后把二者拉进一个会场。在这种方式下,由于每个呼叫的所有消息流经背靠背代理,因此服务提供商可以据此提供增值服务,比如计时、录音、隐藏真实号码等等。
4.JAR包
<!-- AliYun 阿里云联络中心--> <dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.21</version> </dependency> <dependency><groupId>com.aliyun</groupId><artifactId>ccc20200701</artifactId><version>2.27.1</version> </dependency>
5.代码
5.1 对接接口
package com.service;import com.alibaba.fastjson.JSONObject;
import com.aliyun.tea.TeaModel;import javax.servlet.http.HttpServletRequest;public class AliYunCallService extends CommonService{private static final String ALIYUN_ACCESS_KEY = Config.get("aliyun.access.key");private static final String ALIYUN_ACCESS_SECRET = Config.get("aliyun.access.secret");private static final String ALIYUN_CALL_INSTANCE_ID = Config.get("aliyun.call.instance.id");private static final String ALIYUN_CALL_END_POINT = Config.get("aliyun.call.end.point");private static String instanceId ;private HttpServletRequest request;private static com.aliyun.ccc20200701.Client aliYunCallClient;static {init();instanceId = ALIYUN_CALL_INSTANCE_ID;}public String getInstance() {return instanceId;}public static void init(){try{com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config().setAccessKeyId(ALIYUN_ACCESS_KEY).setAccessKeySecret(ALIYUN_ACCESS_SECRET);config.endpoint = ALIYUN_CALL_END_POINT;aliYunCallClient = new com.aliyun.ccc20200701.Client(config);}catch (Exception e){e.printStackTrace();}}public TeaModel startBack2BackCall (String caller,String callee,String broker) throws Exception {com.aliyun.ccc20200701.models.StartBack2BackCallRequest StartBack2BackCallRequest = new com.aliyun.ccc20200701.models.StartBack2BackCallRequest().setInstanceId(instanceId).setCaller(caller).setCallee(callee).setBroker(broker).setTimeoutSeconds(60);com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();return aliYunCallClient.startBack2BackCallWithOptions(StartBack2BackCallRequest, runtime).getBody();}public TeaModel getCallDetailRecord (String contactId) throws Exception {com.aliyun.ccc20200701.models.GetCallDetailRecordRequest request = new com.aliyun.ccc20200701.models.GetCallDetailRecordRequest().setInstanceId(instanceId).setContactId(contactId);return aliYunCallClient.getCallDetailRecord(request).getBody();}}
5.2 测试代码
@Testpublic void call() {AliYunCallService aliYunCallService = new AliYunCallService();try {System.out.println("StartBack2BackCall"+aliYunCallService.startBack2BackCall("131********","151********","0102157****").toMap()); System.out.println("GetCallDetailRecord"+aliYunCallService.getCallDetailRecord("job-57********").toMap());} catch (Exception e) {throw new RuntimeException(e);}}