php版小黄鸡simsimi聊天机器人接口分享_php教程-查字典教程网
php版小黄鸡simsimi聊天机器人接口分享
php版小黄鸡simsimi聊天机器人接口分享
发布时间:2016-12-29 来源:查字典编辑
摘要:复制代码代码如下:

复制代码 代码如下:

<?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("rnrn", $content);

preg_match("/set-cookie:([^rn]*);/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 '我还不会回答这个问题...';

}

}

?>

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新php教程学习
    热门php教程学习
    编程开发子分类