php调用模拟Simsimi (小黄鸡) API_PHP教程

php中文网
发布: 2016-07-14 10:09:26
原创
1479人浏览过

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('你好啊');
 
 
根据:Simsimi (小黄鸡) 非官方API接口:http://www.52its.net/articles/407.html
//curlSim.php
 
   
    /**
     *
     *作者:@Belin_love
     *来源:http://52its.sinaapp.com/
     *日期:2012.11.27
     *
     **/
      
    //function simsimi($keyword)
    //{
    //做成API接口的话,请发起GET请求,返回Josn
    //只自己用的话,封装成一个函数,返回JSON字段中的response
 
    if(isset($_GET['key'])){
        $keyword = trim($_GET['key']);
        $url = "http://www.simsimi.com/talk.htm?lc=ch";
      
        //这个curl是因为官方每次请求都有唯一的COOKIE,我们必须先把COOKIE拿出来,不然会一直返回“HI”
      
        $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("\r\n\r\n", $content);
        preg_match("/set\-cookie:([^\r\n]*)/i", $header, $matches);
        //curl_setopt($ch, CURLOPT_COOKIE, $cookie);
        $cookie = $matches[1];
      
      
        $urll = 'http://www.simsimi.com/func/req?msg=' .$keyword. '&lc=ch';
           
        // 这个CURL就是模拟发起请求咯,直接返回的就是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);
           
        //输出json
        //print_r($content);
        $json = json_decode($content,true);
        if (!empty($json) && $json['result']==100){
         echo $json['response'];
        }
        
          
        /*$reply = '你说的话太高深啦,我还听不懂,你可以教教我吗?[兔子]';
        $json = json_decode($json, 1);
        if (isset($json['response'])) {
            $reply = $json['response'];
        }
        echo $reply;
    }*/
    }
      
    ?>
 
php调用模拟Simsimi (小黄鸡) API - InSun - Minghacker is Insun
 
 
 
学习用js, ajax, php做一个简单的小黄鸡页面(调用simsimi API):http://www.verydemo.com/demo_c98_i8695.html
 
 
     
     
   
   
    function ajaxSimsimi(str){  
    var xmlhttp;  
    if (str.length==0){   
      document.getElementById("txtHint").innerHTML="";  
      return;  
      }  
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari  
      xmlhttp=new XMLHttpRequest();  
      } else {// code for IE6, IE5  
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  
      }  
    xmlhttp.onreadystatechange=function(){    //XMLHttpRequest对象的有效返回判别  
      if (xmlhttp.readyState==4 && xmlhttp.status==200) {  
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;  
        }  
      }  
    xmlhttp.open("GET","curlSim.php?key="+str,true);  
    xmlhttp.send();  
    }  
     
     
      
     
   

请在输入框中键入消息并回车:

 
   
  
    求调戏:  
     
     
     
     
   

小贱鸡: 大爷,来调戏我啊~~~

凹凸工坊-AI手写模拟器
凹凸工坊-AI手写模拟器

AI手写模拟器,一键生成手写文稿

凹凸工坊-AI手写模拟器 359
查看详情 凹凸工坊-AI手写模拟器
  
      
     
     
 
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:/...
相关标签:
php
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号