2019-12-19 17:58:19 +08:00
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html lang="en">
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
<title>map</title>
|
|
|
|
|
<script src="./js/jQuery-1.8.3.min.js"></script>
|
|
|
|
|
<link href="./css/machine.css" rel="stylesheet">
|
|
|
|
|
<link href="./css/demo.css" rel="stylesheet">
|
|
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<div class="ai_content">
|
|
|
|
|
<p class="ai_title">对话机器人</p>
|
|
|
|
|
<div id="box">
|
|
|
|
|
<div class="b-head">
|
|
|
|
|
<span class="h_span">AI对话</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="b_body">
|
|
|
|
|
<div class="rotWord">
|
|
|
|
|
<span></span>
|
|
|
|
|
<p id="member">我们聊聊吧!</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
<div class="b-footer">
|
|
|
|
|
<input type="text" name="text" id="f-left">
|
|
|
|
|
<div id="btn">发送</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<script>
|
|
|
|
|
var params = window.location.href.split('?');
|
|
|
|
|
console.log(params);
|
|
|
|
|
$(function(){
|
|
|
|
|
if(params.length>1){
|
|
|
|
|
action('中印边境包含哪几段');
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
var array = [
|
|
|
|
|
{
|
|
|
|
|
input:'中印边境包含哪几段',
|
|
|
|
|
output:'中印边境包含东段、中段、西段以及锡金段。'
|
|
|
|
|
},{
|
|
|
|
|
input:'中印边境问题引发了哪些对峙事件?',
|
|
|
|
|
output:'中印边境问题引发了桑多河谷对峙、洞朗对峙、班公湖对峙。'
|
|
|
|
|
},{
|
|
|
|
|
input:'班公湖对峙发生于哪里',
|
|
|
|
|
output:'发生在拉达克地区的班公湖北岸。'
|
|
|
|
|
},{
|
|
|
|
|
input:'班公湖近况如何?',
|
|
|
|
|
output:'2019年9月14日印军逼近拉达克地区的班公湖。'
|
|
|
|
|
},{
|
|
|
|
|
input:'印军近期在班公湖的活动?',
|
|
|
|
|
output:'印军在拉达克地区举行联合军演、印度北部军区司令到班公湖巡视。'
|
|
|
|
|
},{
|
|
|
|
|
input:'哟',
|
|
|
|
|
output:'耶~'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
var text = $("#f-left");
|
|
|
|
|
text.focus();
|
|
|
|
|
function action(value)
|
|
|
|
|
{
|
|
|
|
|
if(value==null||value=="")
|
|
|
|
|
{
|
|
|
|
|
text.focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var html = '<div class="mWord"><span></span><p>'+value+'</p></div>';
|
|
|
|
|
$(".b_body").append(html);
|
|
|
|
|
|
2019-12-19 18:24:00 +08:00
|
|
|
|
var args= {
|
|
|
|
|
type : "get",
|
|
|
|
|
url:"https://api.ownthink.com/bot",
|
|
|
|
|
data : {"appid" : "xiaosi", "spoken" : value},
|
|
|
|
|
success : function(redata)//回调函数
|
|
|
|
|
{
|
|
|
|
|
var my_data = $.parseJSON(redata)
|
|
|
|
|
|
|
|
|
|
var array= [my_data.data.info.text];
|
|
|
|
|
|
|
|
|
|
if(my_data.data.info.hasOwnProperty("heuristic"))
|
|
|
|
|
{
|
|
|
|
|
for (var i=0; i < my_data.data.info.heuristic.length; i++)
|
|
|
|
|
{
|
|
|
|
|
array.push(my_data.data.info.heuristic[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var i=0; i < array.length; i++)
|
|
|
|
|
{
|
|
|
|
|
var result = array[i];
|
|
|
|
|
$(".b_body").append("<div class='rotWord'><span></span> <p id='member'>" + result + "</p></div>");
|
|
|
|
|
$(".b_body").scrollTop(10000000);
|
|
|
|
|
}
|
2019-12-19 17:58:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-19 18:24:00 +08:00
|
|
|
|
ajax(args);
|
2019-12-19 17:58:19 +08:00
|
|
|
|
$(".b_body").scrollTop(10000000);
|
|
|
|
|
text.val('');
|
|
|
|
|
}
|
|
|
|
|
$("#btn").click(function()//鼠标点击
|
|
|
|
|
{
|
|
|
|
|
action(text.val());
|
|
|
|
|
});
|
|
|
|
|
$(document).keydown(function(event)//回车
|
|
|
|
|
{
|
|
|
|
|
if(event.keyCode==13)
|
|
|
|
|
{
|
|
|
|
|
action(text.val());
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-12-19 18:24:00 +08:00
|
|
|
|
|
|
|
|
|
function ajax(mJson)
|
|
|
|
|
{
|
|
|
|
|
var type=mJson.type||'get';
|
|
|
|
|
var url=mJson.url;
|
|
|
|
|
var data=mJson.data;
|
|
|
|
|
var success=mJson.success;
|
|
|
|
|
var error=mJson.error;
|
|
|
|
|
var dataStr='';
|
|
|
|
|
|
|
|
|
|
//console.log(data);
|
|
|
|
|
|
|
|
|
|
//请求数据封装
|
|
|
|
|
if(data)
|
|
|
|
|
{
|
|
|
|
|
var arr = Object.keys(data);//获取key,数组以便获取长度
|
|
|
|
|
var len = arr.length;
|
|
|
|
|
var i = 0;
|
|
|
|
|
|
|
|
|
|
for (var key in data)
|
|
|
|
|
{
|
|
|
|
|
dataStr+=key+'='+data[key];
|
|
|
|
|
|
|
|
|
|
if (++i<len)
|
|
|
|
|
{
|
|
|
|
|
dataStr+='&';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(type.toLowerCase()=='get')
|
|
|
|
|
{
|
|
|
|
|
url+='?'+dataStr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// dataStr+=new Date().getTime();//设计时需要发送时间。。。
|
|
|
|
|
// if(type.toLowerCase()=='get')
|
|
|
|
|
// {
|
|
|
|
|
// url+='?'+dataStr;
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//console.log(url);
|
|
|
|
|
|
|
|
|
|
var xhr=new XMLHttpRequest();
|
|
|
|
|
xhr.open(type,url,true);
|
|
|
|
|
xhr.setRequestHeader('content-type' , 'application/x-www-form-urlencoded');
|
|
|
|
|
xhr.send(null);
|
|
|
|
|
|
|
|
|
|
xhr.onreadystatechange=function()
|
|
|
|
|
{
|
|
|
|
|
if(xhr.readyState==4)
|
|
|
|
|
{
|
|
|
|
|
if(xhr.status>=200&&xhr.status<300)
|
|
|
|
|
{
|
|
|
|
|
success&&success(xhr.responseText);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
error&&error(xhr.status);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-19 17:58:19 +08:00
|
|
|
|
</script>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|