您的位置:首页 > 编程语言 > PHP开发

php版小黄鸡simsimi聊天机器人接口分享

2014-01-26 00:00 513 查看
<?php
function simsimi($keyword) {
 $keyword = urlencode(urlencode($keyword));
 //----------- 获取COOKIE ----------//
 $url = "http://www.simsimi.com/";
 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_HEADER,1);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
 $content = curl_exec($ch);
 list($header, $body) = explode("\r\n\r\n", $content);
 preg_match("/set\-cookie:([^\r\n]*);/iU", $header, $matches);
 $cookie = $matches[1];
 curl_close($ch);

 //----------- 抓 取 回 复 ----------//
 $url = "http://www.simsimi.com/func/req?lc=ch&msg=$keyword&ft=0.0";
 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_REFERER, "http://www.simsimi.com/talk.htm?lc=ch");
 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
 curl_setopt($ch, CURLOPT_COOKIE, $cookie);
 $content = json_decode(curl_exec($ch),1);
 curl_close($ch);

 if($content['result']=='100') {
  $content['response'];
  return $content['response'];
 } else {
  return '我还不会回答这个问题...';
 }
}
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: