哈哈哈哈,小黄鸡接口,可以拿来自娱自乐一下。。。
php端代码如下<?php <br />
$msg = $_GET['text'];<br>
//URL中的参数:<br>
// sandbox.api.simsimi.com/request.p 是试用账号的API<br>
// key : 用户秘钥,这里是试用秘钥100次请求/天<br>
// ft : 是否过滤骂人的词汇<br>
// lc : 语言设置<br>
// text : 发送信息<br>
$url = 'http://sandbox.api.simsimi.com/request.p?key=df3c679b-f20a-4bdc-9592-c8730169fa32&ft=0.0&lc=ch&text='.$msg;<br>
<br>
$ch = curl_init();<br>
curl_setopt($ch, CURLOPT_URL, $url); <br>
curl_setopt($ch,CURLOPT_HEADER,0);<br>
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20120101 Firefox/17.0');<br>
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); <br>
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ;<br>
$res = curl_exec($ch);<br>
curl_close($ch);<br>
echo $res;<br>
?>
前端代码nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"<br>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br>
<br>
<br>
<meta>
<br>
<title>Simsimi</title>
<br>
<script></script><br>
<style><br />
* {margin:0px;padding:0px;}<br />
#body {width:500px;}<br />
#talkbox {border:1px olive solid; width:500px; min-height:100px; float:left; padding:10px;}<br />
#input {float:right; margin-top:20px}<br />
#in {height:24px; width:300px}<br />
#send {background:rgb(51,153,255); border:0; border-radius:5px; height:24px; width:60px; color:white; font-size:14px; font-family:微软雅黑;}<br />
.left {float:left; clear:both}<br />
.right {float:right; clear:both}<br />
.msg {min-height:30px; max-width:300px; line-height:30px; margin-left:20px; margin-bottom:10px; border-radius:6px; border:1px solid #383838; padding:5px; float:left}<br />
.pic {min-height:40px; width:40px; border:0;float:left}<br />
</style>
<br>
<br>
<br>
<div>
<br>
<div>
<br>
<br>
</div>
<br>
<div>
<br>
<input><br>
<button>发送</button><br>
</div>
<br>
</div>
<br>
<script><br />
document.onkeydown = function (e) { //回车发送信息<br />
var theEvent = window.event || e; <br />
var code = theEvent.keyCode || theEvent.which; <br />
if (code == 13) { <br />
send();<br />
} <br />
}<br />
function send(){<br />
msg = $("#in").val(); //获得输入框中的值<br />
if(!msg){<br />
return false;<br />
}<br />
$('#in').val(''); //点击发送后清除表单中的值<br />
d = $("#talkbox");<br />
ele = '<div class="left"><div class="pic"><img src="./mi.png" style="max-width:90%" style="max-width:90%" / alt="一个有趣的接口--小黄鸡聊天机器人" ><div class="msg">你:'+msg+'';<br />
var simsimi = '';<br />
d.append(ele); //将输入框中的值放入聊天框<br />
$.get("./request.php",{text:msg},function(data){ //将要发的信息ajax提交到php页面<br />
var obj = eval('('+data+')'); //php段请求接口,返回来json数据 obj.response是小黄鸡回复的<br />
if(obj.result != 100){<br />
alert('运行错误');<br />
}else{<br />
simsimi = '<div class="right"><div class="pic"><img src="./sim.png" style="max-width:90%" style="max-width:90%" / alt="一个有趣的接口--小黄鸡聊天机器人" ><div class="msg">小黄鸡:'+obj.response+'';<br />
d.append(simsimi);<br />
}<br />
})<br />
}<br />
</script><br>
<br>
因为存在跨域问题,这里用的ajax+后台请求接口实现
聊天机器人.rar ( 56.27 KB 下载:256 次 )
AD:真正免费,域名+虚机+企业邮箱=0元