欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

Thinkphp+聚合接口制作的聊天小黄鸡,附源码下载

程序员文章站 2022-04-02 15:47:51
...
如果你下载下来了,你一定要善待这只鸡。下载下来打开就可以聊天!我放到了我的服务器上,国庆期间我无聊就找鸡。
http://www.wbaobao.top/talkJJ/
代码核心就是调用接口跟前台的输出js的使用方法。
它可能没有你想象的那么黄,最黄的在韩国。 namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
public function index(){
$this->display();
}
public function data(){
if (IS_POST) {
$appkey = "5e70fea5553d2deea473c13b516a564a";
$url = "http://op.juhe.cn/robot/index";
$metock=I("post.txt","haha");
$params = array(
"key" => $appkey,//您申请到的本接口专用的APPKEY
"info" => $metock,//要发送给机器人的内容,不要超过30个字符
"dtype" => "",//返回的数据的格式,json或xml,默认为json
"loc" => "",//地点,如北京中关村
"lon" => "",//经度,东经116.234632(小数点后保留6位),需要写为116234632
"lat" => "",//纬度,北纬40.234632(小数点后保留6位),需要写为40234632
"userid" => "",//1~32位,此userid针对您自己的每一个用户,用于上下文的关联
);
$params=http_build_query($params);
$ispost=0;
$httpInfo = array();
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
$response = curl_exec( $ch );
if ($response === FALSE) {
return false;
}
$httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
$httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
curl_close( $ch );
$data=json_decode($response,ture)["result"]["text"];
$return=[
"text"=>$data,
];
$this->ajaxReturn($return);
}
}
}

Thinkphp+聚合接口制作的聊天小黄鸡,附源码下载 talkJJ.rar ( 1.25 MB 下载:63 次 )