龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

小黄鸡simsimi接口

时间:2014-07-22 14:48来源: 作者: 点击:
分享到:
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("\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 '我还不会回答这个问题...';
	}
}
?>
精彩图集

赞助商链接