小黃雞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 '我還不會回答這個問題...'; } } ?>