php版小黄鸡simsimi聊天机器人接口分享
程序员文章站
2022-06-30 09:23:03
复制代码 代码如下:
<?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);
复制代码 代码如下:
<?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 '我还不会回答这个问题...';
}
}
?>