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

Judith ·
更新时间:2024-09-20
· 814 次阅读

代码如下:
<?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 '我还不会回答这个问题...';
 }
}
?>

您可能感兴趣的文章:Websocket IM聊天教程 教你用GoEasy快速实现IM聊天使用Python AIML搭建聊天机器人的方法示例Android中基于XMPP协议实现IM聊天程序与多人聊天室基于Python如何使用AIML搭建聊天机器人JavaScript/jQuery、HTML、CSS 构建 Web IM 远程及时聊天通信程序IM聊天教程之发送图片/视频/语音/表情



机器人 接口 PHP

需要 登录 后方可回复, 如果你还没有账号请 注册新账号