|
復(fù)制代碼 代碼如下:
<?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);
//----------- 抓 取 回 復(fù) ----------//
$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 '我還不會(huì)回答這個(gè)問題...';
}
}
?>
php技術(shù):php版小黃雞simsimi聊天機(jī)器人接口分享,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。