当前位置 : 主页 > 网络编程 > PHP >

php百小度机器人聊天接口

来源:互联网 收集:自由互联 发布时间:2021-06-28
?php$msg=urlencode('你几岁了?');//内容 $url = "https://sp0.baidu.com/yLsHczq6KgQFm2e88IuM_a/s?sample_name=bear_brainrequest_query='.$msg.'bear_type=1";$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HE
 
<?php
$msg=urlencode('你几岁了?');//内容
  
$url = "https://sp0.baidu.com/yLsHczq6KgQFm2e88IuM_a/s?sample_name=bear_brain&request_query='.$msg.'&bear_type=1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIE, 'BDUSS=你的bduss');
$content = curl_exec($ch);
curl_close($ch);
$content=json_decode($content);
//print_r($content);
  
$content=$content->result_list[0]->result_content;
//print_r($content);
$content=json_decode($content);
//print_r($content);
$content=$content=$content->answer;
$content=str_replace("小度","滑小稽",$content);
$content=str_replace("<AGE>","21",$content);
echo $content;

网友评论