服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服务器之家 - 编程语言 - PHP教程 - php版小黄鸡simsimi聊天机器人接口分享

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

2020-06-07 14:21PHP教程网 PHP教程

小黄鸡SimSimi是一个可爱的智能聊天机器人,他能和用户进行有趣的对话,本文主要介绍了php版小黄鸡simsimi接口使用的示例,大家参考使用吧

复制代码 代码如下:


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

 

延伸 · 阅读

精彩推荐