|
|
|
|
<html>
|
|
|
|
|
<meta charset="UTF-8"/>
|
|
|
|
|
<head>
|
|
|
|
|
<title>卡尔话机WebSocket测试页</title>
|
|
|
|
|
</head>
|
|
|
|
|
<body onLoad="wsInit()">
|
|
|
|
|
<h1>卡尔话机WebSocket测试页</h1><h2>请使用支持webSocket的浏览器</h2>
|
|
|
|
|
输入server的ip和port,例如:ws://127.0.0.1:8800/<br/>
|
|
|
|
|
<input id="serverInfo" type="text" value="ws://127.0.0.1:8800/" size="40"/>
|
|
|
|
|
<input type="button" id="btn" value="重新连接" onClick="wsInit('reConn')" />
|
|
|
|
|
<br>
|
|
|
|
|
<div id="txt-e" style=" color: red; font-size: 18px; display: none;"></div>
|
|
|
|
|
<div id="txt-ok" style=" color: green; font-size: 18px; display: none;"></div>
|
|
|
|
|
<p>
|
|
|
|
|
发送报文:<input id="sendMsg" type="text" value='{"cmd":"LINK"}' style="width: 500px;">
|
|
|
|
|
<br><br>
|
|
|
|
|
接收报文:
|
|
|
|
|
|
|
|
|
|
<textarea style="width:500px;"id="recMsg" name="" cols="" rows="10"></textarea></p>
|
|
|
|
|
<p><input type="button" onClick="sendMsg('link')" value="发起link连接"></p>
|
|
|
|
|
<p><input type="button" onClick="sendMsg('ATD')" value="拨号">
|
|
|
|
|
<span style="border:2px solid #6C3;font-size:12px; color:#1a1a1a; margin-left:10px;padding:5px">
|
|
|
|
|
<label><input type="radio" name="sendhaoma" value="1" checked="true">隐藏号码</label>
|
|
|
|
|
<label><input type="radio" name="sendhaoma" value="0" >显示号码</label>
|
|
|
|
|
</span>
|
|
|
|
|
<input type="tel" id="tel" value="10010" style="margin-left:10px;"/>
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<p><input type="button" onClick="sendMsg('ATH')" value="挂断"></p>
|
|
|
|
|
<p><input type="button" onClick="sendMsg('ATA')" value="接听"></p>
|
|
|
|
|
<p><input type="button" onClick="sendMsg('READIMEI')" value="读取话机imei"></p>
|
|
|
|
|
<p><input type="button" onClick="sendMsg('READVER')" value="读取话机版本号"></p>
|
|
|
|
|
<p><input type="button" onClick="sendMsg('startrecord')" value="开启录音"></p>
|
|
|
|
|
<p><input type="button" onClick="sendMsg('stoprecord')" value="停止录音"></p>
|
|
|
|
|
<p><input type="button" onClick="sendMsg('READSTATUS')" value="查询话机状态"><span style="font-size:12px; color:#333; margin-left:10px">备注:status:0挂机,1来电,2呼叫,3接通
|
|
|
|
|
挂机状态时,number号码为空。</span></p>
|
|
|
|
|
<p><input type="button" onClick="sendMsg('HIDENUMBER')" value="隐藏或显示号码">
|
|
|
|
|
<span style="border:2px solid #6C6;font-size:12px; color:#1a1a1a; margin-left:10px; padding:5px">
|
|
|
|
|
<label><input type="radio" name="laidian" value="0" >来电</label> <label><input type="radio" name="laidian" value="1" >去电</label>
|
|
|
|
|
</span>
|
|
|
|
|
<span style="border:2px solid #6C3;font-size:12px; color:#1a1a1a; margin-left:10px;padding:5px">
|
|
|
|
|
<label><input type="radio" name="haoma" value="1" >隐藏号码</label>
|
|
|
|
|
<label><input type="radio" name="haoma" value="0" >显示号码</label>
|
|
|
|
|
</span>
|
|
|
|
|
</p>
|
|
|
|
|
<p><input type="button" onClick="sendMsg('GETNUMBERHIDEN')" value="读取话机号码隐藏状态">
|
|
|
|
|
<span style="border:2px solid #6C6;font-size:12px; color:#1a1a1a; margin-left:10px; padding:5px">
|
|
|
|
|
<label><input name="duqvhj" type="radio" value="0" checked >来电</label>
|
|
|
|
|
<label><input type="radio" name="duqvhj" value="1">去电</label>
|
|
|
|
|
</span>
|
|
|
|
|
</p>
|
|
|
|
|
<p><input type="button" onClick="sendMsg('SETRECORDVOICE')" value="设置录音音量">
|
|
|
|
|
<input type="voice" id="voice" value=""/><span style="font-size:12px; color:#333; margin-left:10px">备注:声音范围 1~100。</span>
|
|
|
|
|
</p>
|
|
|
|
|
<p><input type="button" onClick="sendMsg('SETMODE')" value="设置话机通话模式">
|
|
|
|
|
<span style="border:2px solid #6C6;font-size:12px; color:#1a1a1a; margin-left:10px; padding:5px">
|
|
|
|
|
<label><input name="headsetProfile" type="radio" value="0" checked >关闭耳机模式</label>
|
|
|
|
|
<label><input name="headsetProfile" type="radio" value="1">开耳机模式</label>
|
|
|
|
|
</span>
|
|
|
|
|
</p>
|
|
|
|
|
<p><input type="button" onClick="sendMsg('GETMODE')" value="获取话机通话模式">
|
|
|
|
|
<span style="font-size:12px; color:#333; margin-left:10px">备注:0 关闭耳机模式,1 开耳机模式。</span>
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<p><input type="button" onClick="sendMsg('SETUOC')" value="设置远端播放">
|
|
|
|
|
<span style="border:2px solid #6C6;font-size:12px; color:#1a1a1a; margin-left:10px; padding:5px">
|
|
|
|
|
<label><input name="headsetProfileRadio" type="radio" value="0" checked >关闭远端播放</label>
|
|
|
|
|
<label><input name="headsetProfileRadio" type="radio" value="1">开启远端播放</label>
|
|
|
|
|
</span>
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<p><input type="button" onClick="sendMsg('GETUOC')" value="获取远端播放">
|
|
|
|
|
<span style="font-size:12px; color:#333; margin-left:10px">备注:0 关闭远端播放,1 开启远端播放。</span>
|
|
|
|
|
</p>
|
|
|
|
|
<p>
|
|
|
|
|
<input type="button" onClick="sendMsg('UPPARAM')" value="设置通话记录传平台的参数">
|
|
|
|
|
|
|
|
|
|
<span style="font-size:12px; color:#1a1a1a; margin-left:10px; padding:5px">
|
|
|
|
|
url:<input type="upparamurl" id="upparamurl" value="http://apis.7moor.com/sim/cdr_ytx/insertCdr/" style="margin-left:10px;"/>
|
|
|
|
|
坐席工号:<input type="agent" id="agent" value="100001" style="margin-left:10px;"/>
|
|
|
|
|
计费账号:<input type="company" id="company" value="psytest" style="margin-left:10px;"/>
|
|
|
|
|
本机号码:<input type="thismobile" id="thismobile" value="13212345678" style="margin-left:10px;"/>
|
|
|
|
|
</span>
|
|
|
|
|
</p>
|
|
|
|
|
</body>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
var ws;
|
|
|
|
|
function wsInit(val){
|
|
|
|
|
//重连先关闭
|
|
|
|
|
if(val=='reConn'){
|
|
|
|
|
ws.close();
|
|
|
|
|
}
|
|
|
|
|
document.getElementById("txt-ok").innerText="";
|
|
|
|
|
document.getElementById("txt-e").innerText="";
|
|
|
|
|
if("WebSocket" in window) {
|
|
|
|
|
var serverInfo = document.getElementById("serverInfo").value;
|
|
|
|
|
// 打开一个 web socket,全局共用一个
|
|
|
|
|
ws = new WebSocket(serverInfo);
|
|
|
|
|
//console.log("已连接"+serverInfo);
|
|
|
|
|
ws.onopen = function() {
|
|
|
|
|
setTimeout(function(){
|
|
|
|
|
sendMsg('link')
|
|
|
|
|
},100);
|
|
|
|
|
showResult('ok');
|
|
|
|
|
};
|
|
|
|
|
ws.onmessage = function(evt) {
|
|
|
|
|
document.getElementById("recMsg").value=evt.data;
|
|
|
|
|
var data = JSON.parse(evt.data);
|
|
|
|
|
//console.log(data);
|
|
|
|
|
switch(data['cmd']) {
|
|
|
|
|
// 服务端ping客户端
|
|
|
|
|
case 'USB':
|
|
|
|
|
ws.send('{"cmd":"USB","connected":"true","success":"true","message":"成功"}');
|
|
|
|
|
break;
|
|
|
|
|
case 'CORG':
|
|
|
|
|
ws.send('{"cmd":"CORG","number":"10010","success":"true","message":"成功"}');
|
|
|
|
|
break;
|
|
|
|
|
case 'CALLING':
|
|
|
|
|
ws.send('{"cmd":"CALLING","number":"10010","success":"true","message":"成功"}');
|
|
|
|
|
break;
|
|
|
|
|
case 'CBEGIN':
|
|
|
|
|
ws.send('{"cmd":"CBEGIN","success":"true","message":"成功"}');
|
|
|
|
|
break;
|
|
|
|
|
case 'ALERT':
|
|
|
|
|
ws.send('{"cmd":"ALERT","success":"true","message":"成功"}');
|
|
|
|
|
break;
|
|
|
|
|
case 'CEND':
|
|
|
|
|
ws.send('{"cmd":"CEND","success":"true","message":"成功"}');
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
//出现错误
|
|
|
|
|
ws.onerror = function(evt){
|
|
|
|
|
//console.log(evt);
|
|
|
|
|
}
|
|
|
|
|
//连接断开
|
|
|
|
|
ws.onclose = function(evt){
|
|
|
|
|
//console.log(evt)
|
|
|
|
|
showResult('error');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 浏览器不支持 WebSocket
|
|
|
|
|
alert("您的浏览器不支持 WebSocket!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showResult(val){
|
|
|
|
|
var serverInfo = document.getElementById("serverInfo").value;
|
|
|
|
|
var okText = serverInfo + "连接成功";
|
|
|
|
|
var errText = serverInfo + "连接失败,请检查window服务、IP和端口安装并配置正确";
|
|
|
|
|
if(val=='ok'){
|
|
|
|
|
document.getElementById("txt-ok").innerText = okText;
|
|
|
|
|
document.getElementById("txt-ok").style.display="block";
|
|
|
|
|
document.getElementById("txt-e").style.display="none";
|
|
|
|
|
}else{
|
|
|
|
|
//console.log(errText)
|
|
|
|
|
document.getElementById("txt-e").innerText = errText;
|
|
|
|
|
document.getElementById("txt-ok").style.display="none";
|
|
|
|
|
document.getElementById("txt-e").style.display="block";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function reConn(){
|
|
|
|
|
ws = new WebSocket(serverInfo);
|
|
|
|
|
}
|
|
|
|
|
function sendMsg(val){
|
|
|
|
|
// Web Socket 已连接上,使用 send() 方法发送数据
|
|
|
|
|
var state=ws.readyState;
|
|
|
|
|
|
|
|
|
|
console.log("readyState:"+state);
|
|
|
|
|
if(state!=1){
|
|
|
|
|
document.getElementById("txt-e").style.display="block";
|
|
|
|
|
//location.reload();
|
|
|
|
|
return;
|
|
|
|
|
}else{
|
|
|
|
|
document.getElementById("txt-e").style.display="none";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(val=="link"){
|
|
|
|
|
val = '{"cmd":"LINK"}';
|
|
|
|
|
}
|
|
|
|
|
/*if(val=="USB"){
|
|
|
|
|
val = '{"cmd":"USB","connected":"true","success":"true","message":"成功"}';
|
|
|
|
|
}*/
|
|
|
|
|
if(val=="ATD"){
|
|
|
|
|
function getRadioLValue(haoma){
|
|
|
|
|
var obj = document.getElementsByName(haoma);
|
|
|
|
|
for(i = 0;i<obj.length;i++){
|
|
|
|
|
if(obj[i].checked){
|
|
|
|
|
return obj[i].value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "undefined";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var sendhaoma = getRadioLValue("sendhaoma");
|
|
|
|
|
var number = document.getElementById("tel").value;
|
|
|
|
|
val = '{"cmd":"ATD","number":"'+number+'","hidden":"'+sendhaoma+'"}';
|
|
|
|
|
}
|
|
|
|
|
if(val=="ATH"){
|
|
|
|
|
val = '{"cmd":"ATH"}';
|
|
|
|
|
}
|
|
|
|
|
if(val=="ATA"){
|
|
|
|
|
val = '{"cmd":"ATA"}';
|
|
|
|
|
}
|
|
|
|
|
if(val=="READIMEI"){
|
|
|
|
|
val = '{"cmd":"READIMEI"}';
|
|
|
|
|
}
|
|
|
|
|
if(val=="READVER"){
|
|
|
|
|
val = '{"cmd":"READVER"}';
|
|
|
|
|
}
|
|
|
|
|
if(val=="READSTATUS"){
|
|
|
|
|
val = '{"cmd":"READSTATUS"}';
|
|
|
|
|
}
|
|
|
|
|
if(val=="startrecord"){
|
|
|
|
|
function getLocalTime(nS) {
|
|
|
|
|
return new Date(parseInt(nS) * 1000).Format("yyyyMMddhhmmss");
|
|
|
|
|
}
|
|
|
|
|
Date.prototype.Format = function(fmt) {//author: meizz
|
|
|
|
|
var o = {
|
|
|
|
|
"M+" : this.getMonth() + 1, //月份
|
|
|
|
|
"d+" : this.getDate(), //日
|
|
|
|
|
"h+" : this.getHours(), //小时
|
|
|
|
|
"m+" : this.getMinutes(), //分
|
|
|
|
|
"s+" : this.getSeconds(), //秒
|
|
|
|
|
"q+" : Math.floor((this.getMonth() + 3) / 3), //季度
|
|
|
|
|
"S" : this.getMilliseconds() //毫秒
|
|
|
|
|
};
|
|
|
|
|
if (/(y+)/.test(fmt))
|
|
|
|
|
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
|
|
|
|
|
for (var k in o)
|
|
|
|
|
if (new RegExp("(" + k + ")").test(fmt))
|
|
|
|
|
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
|
|
|
|
|
return fmt;
|
|
|
|
|
}
|
|
|
|
|
//E:\\qtproject\\PhoneService\\kaerHjSDK\\recordfile\\20180514.mp3
|
|
|
|
|
var time= Math.round(new Date() / 1000) ;
|
|
|
|
|
var times =(getLocalTime(time));
|
|
|
|
|
console.log(time);
|
|
|
|
|
var filename= "E:/qtproject/PhoneService/kaerHjSDK/recordfile/"+times+".mp3";
|
|
|
|
|
val = '{"cmd":"startrecord","filename":"'+filename+'"}';
|
|
|
|
|
//alert(filename);
|
|
|
|
|
}
|
|
|
|
|
if(val=="stoprecord"){
|
|
|
|
|
val = '{"cmd":"stoprecord"}';
|
|
|
|
|
}
|
|
|
|
|
if(val=="HIDENUMBER"){
|
|
|
|
|
function getRadioValue(laidian){
|
|
|
|
|
var obj = document.getElementsByName(laidian);
|
|
|
|
|
for(i = 0;i<obj.length;i++){
|
|
|
|
|
if(obj[i].checked){
|
|
|
|
|
return obj[i].value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "undefined";
|
|
|
|
|
}
|
|
|
|
|
function getRadioLValue(haoma){
|
|
|
|
|
var obj = document.getElementsByName(haoma);
|
|
|
|
|
for(i = 0;i<obj.length;i++){
|
|
|
|
|
if(obj[i].checked){
|
|
|
|
|
return obj[i].value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "undefined";
|
|
|
|
|
}
|
|
|
|
|
var type=getRadioValue('laidian');
|
|
|
|
|
var hidden=getRadioLValue('haoma');
|
|
|
|
|
//console.log(type);
|
|
|
|
|
//console.log('号码'+hidden);
|
|
|
|
|
val = '{"cmd":"HIDENUMBER","type":"'+type+'","hidden":"'+hidden+'"}';
|
|
|
|
|
}
|
|
|
|
|
if(val=="GETNUMBERHIDEN"){
|
|
|
|
|
function getRadioDqValue(duqvhj){
|
|
|
|
|
var obj = document.getElementsByName(duqvhj);
|
|
|
|
|
for(i = 0;i<obj.length;i++){
|
|
|
|
|
if(obj[i].checked){
|
|
|
|
|
return obj[i].value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "undefined";
|
|
|
|
|
}
|
|
|
|
|
var type=getRadioDqValue('duqvhj');
|
|
|
|
|
val = '{"cmd":"GETNUMBERHIDEN","type":"'+type+'"}';
|
|
|
|
|
}
|
|
|
|
|
if(val=="SETRECORDVOICE"){
|
|
|
|
|
var voice= document.getElementById("voice").value;
|
|
|
|
|
val = '{"cmd":"SETRECORDVOICE","voice":"'+voice+'"}';
|
|
|
|
|
}
|
|
|
|
|
if(val=="SETMODE"){
|
|
|
|
|
function getRadioHpValue(headsetProfile){
|
|
|
|
|
var obj = document.getElementsByName(headsetProfile);
|
|
|
|
|
for(i = 0;i<obj.length;i++){
|
|
|
|
|
if(obj[i].checked){
|
|
|
|
|
return obj[i].value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "undefined";
|
|
|
|
|
}
|
|
|
|
|
var mode=getRadioHpValue('headsetProfile');
|
|
|
|
|
val = '{"cmd":"SETMODE","mode":"'+mode+'"}';
|
|
|
|
|
}
|
|
|
|
|
if(val=="GETMODE"){
|
|
|
|
|
val = '{"cmd":"GETMODE"}';
|
|
|
|
|
}
|
|
|
|
|
if(val=="SETUOC"){
|
|
|
|
|
function getRadioHpValue(headsetProfileRadio){
|
|
|
|
|
var obj = document.getElementsByName(headsetProfileRadio);
|
|
|
|
|
for(i = 0;i<obj.length;i++){
|
|
|
|
|
if(obj[i].checked){
|
|
|
|
|
return obj[i].value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "undefined";
|
|
|
|
|
}
|
|
|
|
|
var mode=getRadioHpValue('headsetProfileRadio');
|
|
|
|
|
val = '{"cmd":"SETUOC","UOC":"'+mode+'"}';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(val=="GETUOC"){
|
|
|
|
|
val = '{"cmd":"GETUOC"}';
|
|
|
|
|
}
|
|
|
|
|
if(val=="UPPARAM"){//设置通话记录传平台的参数
|
|
|
|
|
var upparamurl = document.getElementById("upparamurl").value;//坐席工号
|
|
|
|
|
var agent = document.getElementById("agent").value;//坐席工号
|
|
|
|
|
var company =document.getElementById("company").value;//计费账号
|
|
|
|
|
var thismobile =document.getElementById("thismobile").value;//本机号码
|
|
|
|
|
val = '{"cmd":"UPPARAM","url":"'+upparamurl+'","agent":"'+agent+'","company":"'+company+'","thismobile":"'+thismobile+'"}';
|
|
|
|
|
}
|
|
|
|
|
document.getElementById("sendMsg").value=val;
|
|
|
|
|
ws.send(val);
|
|
|
|
|
console.log("数据已发送");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
</html>
|
|
|
|
|
|