AIDE技术官网
AIDEZY.COM

PHP垃圾分类API接口源码

AIDE技术网-aidezy.com
PHP垃圾分类API接口源码

PHP垃圾分类API接口源码

前言:

个PHP垃圾API口源码,你有助就看吧

PHP分类API接源码

PHP垃圾分类API接口源码

 

正文:

代码实例:

<?php
header('Access-Control-Allow-Origin:*');
header('Content-type:application/json; charset=utf-8');
error_reporting(0);
function myCurl($url){
    $ch = curl_init();     // Curl 初始化
    $timeout = 30;     // 超时时间:30s
    $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
    if($ip != ""){
        $arr = explode(",",$ip);
        $ip = $arr[0];
    }else{
        $ip = $_SERVER["REMOTE_ADDR"];
    }
    $ua='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36';
    $header = array('X-FORWARDED-FOR:'.$ip, 'CLIENT-IP:'.$ip);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_ENCODING, "");
    curl_setopt($ch, CURLOPT_REFERER, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_USERAGENT, $ua);
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    $content = curl_exec($ch);
    curl_close($ch);
    return $content;
}
!empty($_GET['keyword']) ? $_GET['keyword'] : exit(json_encode([
    "code"=>-1,
    "msg"=>"请输入垃圾名字!"
],JSON_UNESCAPED_UNICODE));
$json = json_decode(myCurl("https://quark.sm.cn/api/rest?method=sc.operation_sorting_category&app_chain_name=waste_classify&q=".$_GET['keyword']));

if ($json->data->waste_type == "" || $json->data->category==null){
    $output = [
        "code"=>-1,
        "msg"=>"该垃圾暂未识别!"
    ];
} else{
    $output = [
        "code"=>1,
        "msg"=>"查询成功!",
        "data"=>$json->data->waste_type
    ];
}
exit(json_encode($output,JSON_UNESCAPED_UNICODE));

搜一下

赞(0) 打赏
AIDE技术网-aidezy.com 广告
AIDE技术网-aidezy.com 广告

来都来了!评论一下呗! 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址 (选填)
AIDE技术网–技术综合类博客|AIDEZY.COM

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

切换注册

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

Q Q 登 录
切换登录

注册