手机
当前位置:查字典教程网 >编程开发 >php教程 >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("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版小黄鸡simsimi聊天机器人接口分享】相关文章:

使用PHP维护文件系统

php实现每天自动变换随机问候语的方法

PHP巧获服务器端信息

如何使用动态共享对象的模式来安装PHP

php数组随机排序实现方法

用Flash图形化数据(一)

PHP动态图像的创建

php操作redis缓存方法分享

PHP处理密码的几种方式

编译问题

精品推荐
分类导航