package com.smartor.config;
|
|
import com.ruoyi.common.utils.HttpUtil;
|
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.http.HttpEntity;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Component;
|
|
import javax.mail.Multipart;
|
import java.io.UnsupportedEncodingException;
|
import java.nio.charset.StandardCharsets;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
@Component
|
public class PhoneUtils {
|
|
@Value("${phoneIP}")
|
private String phoneIP;
|
|
@Value("${phonePort}")
|
private String phonePort;
|
|
/**
|
* 添加分机add_user
|
*/
|
public String addUser(String user, String pwd) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("user", user);
|
map.put("password", pwd);
|
return sendReq(map, "/tel/ai_api/add_user");
|
}
|
|
/**
|
* 删除分机delete_user
|
*
|
* @return
|
*/
|
public String delUser(String user) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("user", user);
|
return sendReq(map, "/tel/ai_api/delete_user");
|
}
|
|
/**
|
* 3、检查分机是否存在check_user
|
*
|
* @return
|
*/
|
public String checkUser(String user) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("user", user);
|
return sendReq(map, "/tel/ai_api/check_user");
|
}
|
|
|
/**
|
* 列出全部坐席或者指定坐席 list_agent
|
*
|
* @param name
|
* @return
|
*/
|
public String listAgent(String name) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("name", name);
|
return sendReq(map, "/tel/ai_api/list_agent");
|
}
|
|
/**
|
* 添加坐席add_agent
|
* 向系统中添加一个坐席,后续需要set_agent_state,set_agent_status,set_agent_contact, tier_add 设置坐席状体,sip_uri和把坐席加入/绑定一个呼叫队列
|
*
|
* @param name
|
* @return
|
*/
|
public String addAgent(String name, String type) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("name", name);
|
if (StringUtils.isEmpty(type)) map.put("type", "callback");
|
|
return sendReq(map, "/tel/ai_api/add_agent");
|
}
|
|
/**
|
* 删除坐席del_agent
|
* 从呼叫队列删除坐席
|
*
|
* @param name
|
* @return
|
*/
|
public String delAgent(String name) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("name", name);
|
return sendReq(map, "/tel/ai_api/del_agent");
|
}
|
|
/**
|
* 获取坐席当前所在通话的uuid
|
*
|
* @param name
|
* @return
|
*/
|
public String getAgentUUID(String name) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("name", name);
|
return sendReq(map, "/tel/ai_api/get_agent_uuid");
|
}
|
|
/**
|
* 添加坐席后(add_agent),需要设置坐席地址(sip uri),坐席才可以被访问到
|
*
|
* @param name
|
* @param contact
|
* @return
|
*/
|
public String setAgentUUID(String name, String contact) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("name", name);
|
map.put("contact", contact);
|
return sendReq(map, "/tel/ai_api/set_agent_contact");
|
}
|
|
/**
|
* 设置坐席的status,有固定几个状态
|
*
|
* @param name
|
* @param status
|
* @return
|
*/
|
public String setAgentStatus(String name, String status) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("name", name);
|
map.put("status", status);
|
return sendReq(map, "/tel/ai_api/set_agent_status");
|
}
|
|
/**
|
* 获取坐席状态
|
*
|
* @param name
|
* @return
|
*/
|
public String getAgentStatus(String name) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("name", name);
|
return sendReq(map, "/tel/ai_api/get_agent_status");
|
}
|
|
|
/**
|
* 设设置坐席
|
*
|
* @param name
|
* @param state
|
* @return
|
*/
|
public String setAgentState(String name, String state) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("name", name);
|
map.put("state", state);
|
return sendReq(map, "/tel/ai_api/set_agent_state");
|
}
|
|
/**
|
* 获取坐席状态
|
*
|
* @param name
|
* @return
|
*/
|
public String getAgentState(String name) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("name", name);
|
return sendReq(map, "/tel/ai_api/get_agent_state");
|
}
|
|
/**
|
* 手动外呼
|
*
|
* @return
|
*/
|
public String manualOutbound(String kg_uuid, String kg_file, String data, String app_id, String ani, String special_ch, String sign, String extension, String dnis, Boolean force_call) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("kg_uuid", kg_uuid);
|
map.put("kg_file", kg_file);
|
map.put("data", data);
|
map.put("app_id", app_id);
|
map.put("ani", ani);
|
map.put("special_ch", special_ch);
|
map.put("sign", sign);
|
map.put("extension", extension);
|
map.put("dnis", dnis);
|
map.put("force_call", force_call);
|
if (force_call == null) map.put("force_call", true);
|
return sendReq(map, "/tel/ai_api/manual_outbound");
|
}
|
|
/**
|
* tts合成和播放
|
*
|
* @param fileText
|
* @param uuid
|
* @return
|
*/
|
public String ttsPlayback(String fileText, String uuid) {
|
System.out.println("=====================问题内容:" + fileText + "UUID ; " + uuid);
|
Map<String, Object> map = new HashMap<>();
|
map.put("text", fileText);
|
map.put("uuid", uuid);
|
|
return sendReq(map, "/tel/ai_api/tts_playback");
|
}
|
|
/**
|
* wav文件播放接口
|
*
|
* @param wav_file
|
* @param uuid
|
* @return
|
*/
|
public String manualOutbound(Multipart wav_file, String uuid) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("wav_file", wav_file);
|
map.put("uuid", uuid);
|
|
return sendReq(map, "/tel/ai_api/playback");
|
}
|
|
/**
|
* 机器人外呼 ob
|
*
|
* @return
|
*/
|
public String ob(String kg_uuid, String kg_file, String data, String app_id, String ani, String special_ch, String sign, String dnis, String call_uuid, Boolean force_call) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("kg_uuid", kg_uuid);
|
map.put("kg_file", kg_file);
|
map.put("data", data);
|
map.put("app_id", app_id);
|
map.put("ani", ani);
|
map.put("special_ch", special_ch);
|
map.put("sign", sign);
|
map.put("dnis", dnis);
|
map.put("call_uuid", call_uuid);
|
map.put("force_call", force_call);
|
map.put("fs_node_id", 8021);
|
if (force_call == null) map.put("force_call", true);
|
return sendReq(map, "/tel/ai_api/outbound");
|
}
|
|
/**
|
* 挂断通话
|
*
|
* @return
|
*/
|
public String hangup(String kg_uuid, String dnis, String data, String app_id, String ani, String special_ch, String sign, String call_uuid) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("kg_uuid", kg_uuid);
|
map.put("kg_file", kg_uuid);
|
map.put("dnis", dnis);
|
map.put("data", data);
|
map.put("app_id", app_id);
|
map.put("ani", ani);
|
map.put("special_ch", special_ch);
|
map.put("sign", sign);
|
map.put("call_uuid", call_uuid);
|
map.put("fs_node_id", "");
|
|
|
// map.put("app_id", app_id);
|
// map.put("kg_uuid", kg_uuid);
|
// map.put("ani", ani);
|
// map.put("dnis", dnis);
|
// map.put("call_direction", call_direction_str);
|
// map.put("hangup_cause", hangup_cause);
|
// map.put("endpoint_disposition", endpoint_disposition);
|
// map.put("wait_msec", wait_msec);
|
// map.put("duration_msec", duration_msec);
|
// map.put("answer_msec", answer_msec);
|
// map.put("bill_msec", bill_msec);
|
// map.put("start_stamp", start_stamp);
|
// map.put("answered_stamp", answered_stamp);
|
// map.put("end_stamp", end_stamp);
|
// map.put("vad_total_talk_time_msec", vad_total_talk_time_msec);
|
// map.put("time_stamp", time_stamp);
|
return sendReq(map, "/tel/ai_api/hangup");
|
}
|
|
private String sendReq(Map<String, Object> map, String path) {
|
HttpEntity<Map<String, Object>> req = new HttpEntity<>(getHead(), map);
|
if (StringUtils.isEmpty(phoneIP)) {
|
phoneIP = "http://124.220.50.51";
|
phonePort = "8001";
|
}
|
HttpEntity<String> stringHttpEntity = HttpUtil.postJsonRequestV2(phoneIP + ":" + phonePort + path, req, String.class);
|
String responseBody = null;
|
try {
|
responseBody = new String(stringHttpEntity.getBody().getBytes("ISO-8859-1"), "UTF-8");
|
System.out.println("电话信息返回 : " + responseBody);
|
} catch (UnsupportedEncodingException e) {
|
e.printStackTrace();
|
}
|
return new String(stringHttpEntity.getBody().getBytes(StandardCharsets.UTF_8));
|
}
|
|
private Map<String, String> getHead() {
|
HashMap<String, String> header = new HashMap<>();
|
header.put("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko");
|
header.put("Content-Type", "application/json");
|
return header;
|
}
|
}
|