小黄鸡simsimi聊天机器人接口分享

小黄鸡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 '我还不会回答这个问题...';
 }
}
?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值