PHP calls simulation Simsimi (Little Yellow Chicken) API_PHP tutorial

WBOY
Release: 2016-07-14 10:09:26
Original
1255 people have browsed it

php调用模拟Simsimi (小黄鸡) API - InSun - Minghacker is Insun
http://developer.simsimi.com/api

SimSimi AICR APIs
 
1. Conversation API
 
Conversation API enables you to get SimSimi's response data. Use the Conversation REST API
 
Request URL:
 
http://api.simsimi.com/request.p
Request parameters:
 
Parameter Value Required Default Description
key String Y Your key value
text String Y Query message
lc String Y Language code(List)
ft Double(0.0 ~ 1.0) 0.0 You can set a filter
Sample request URL:
 
http://api.simsimi.com/request.p?key=your key&lc=en&ft=1.0&text=hi
Response elements:
 
Element Value Description
result Integer 100-OK.
400-Bad Request.
401-Unauthorized.
404-Not found.
500-Server Error.
id Integer Response id. (you can get only if returning result is 100)
response String Response message(you can get only if returning result is 100)
msg String Result msg(Description of result code)
Sample response:
 
{ "result": 100, "response": "Who are you?!", "id": 13185569, "msg": "OK." } 
小黄鸡自己公布的API需要email他,然后得到一个key,而且有90天free的限制
以前的代码已经不能用了 
Unauthorized access错误!
function simsimi($q){
 //simsimi 非官方API接口
 //2012年07月18日修订:修正小黄鸡更新接口导致返回失败。
 //by.oott123  http://best33.com
 //参数:$q(欲获取的问题) 返回:(mixed)返回结果,为false则失败
 $json=file_get_contents('http://www.simsimi.com/func/req?lc=zh&msg='.urlencode($q));
 $json=json_decode($json,1);
 if(isset($json['response'])){
  $reply=$json['response'];
  return $reply;
 }
 return false;
}
 
//Unauthorized access!. In this program(site, app), the SimSimi API is being used illegally.
//Please contact us. http://developer.simsimi.com
echo simsimi('你好啊');
 
 
Based on: Simsimi (Little Yellow Chicken) Unofficial API interface: http://www.52its.net/articles/407.html
//curlSim.php
/**
*
*Author: @Belin_love
*Source: http://52its.sinaapp.com/
*Date: 2012.11.27
*
**/
//function simsimi($keyword)
//{
//If it is an API interface, please initiate a GET request and return Josn
//If you only use it yourself, encapsulate it into a function and return the response in the JSON field
if(isset($_GET['key'])){
$keyword = trim($_GET['key']);
$url = "http://www.simsimi.com/talk.htm?lc=ch";
//This curl is because each official request has a unique COOKIE. We must take out the COOKIE first, otherwise "HI" will always be returned
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($ch);
curl_close($ch);
list($header, $body) = explode("rnrn", $content);
preg_match("/set-cookie:([^rn]*)/i", $header, $matches);
//curl_setopt($ch, CURLOPT_COOKIE, $cookie);
$cookie = $matches[1];
$urll = 'http://www.simsimi.com/func/req?msg=' .$keyword. '&lc=ch';
                                                                     
// This CURL simulates a request, and the direct return is JSON
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urll);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_REFERER, "http://www.simsimi.com/talk.htm?lc=ch");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
$content = curl_exec($ch);
curl_close($ch);
                                                                     
//Output json
//print_r($content);
$json = json_decode($content,true);
if (!empty($json) && $json['result']==100){
echo $json['response'];
}
/*$reply = 'What you said is too profound and I still don't understand it. Can you teach me? [Rabbit]';
$json = json_decode($json, 1);
if (isset($json['response'])) {
$reply = $json['response'];
}
echo $reply;
}*/
}
?>
php调用模拟Simsimi (小黄鸡) API - InSun - Minghacker is Insun
Learn to use js, ajax, php to make a simple little yellow chicken page (calling simsimi API): http://www.verydemo.com/demo_c98_i8695.html

Please type the message in the input box and press Enter:

Requesting for teasing:

Little bitch: Uncle, come and tease me~~~

php调用模拟Simsimi (小黄鸡) API - InSun - Minghacker is Insun

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477669.htmlTechArticlehttp://developer.simsimi.com/api SimSimi AICR APIs 1. Conversation API Conversation API enables you to get SimSimis response data. Use the Conversation REST API Request URL: http://...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template