分享菜鸟级的PHP采集教程与视频解析,HTML代码模板免费资源分享平台

腾讯,葫芦侠、百度图床、京东图床接口源码案例分享

13 10月
作者:七哥| 分类:单页php| 发布时间:2020年10月13日 |标签:腾讯 葫芦侠 百度图床 京东 图床 接口源码 案例分享

我感觉不要太依赖图床,毕竟不是自己的,说不定什么时候就不能用了,我图片都是本地的,直接上代码,我写好以后是在本地测试的,不知道支持不支持临时文件上传,不支持的话你们改一下就行了

在线演示:http://mmkv.cn/img/


1.葫芦侠图床

 <?php
header('Access-Control-Allow-Origin:*');
header('Content-type:application/json; charset=utf-8');
error_reporting(0);
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
        
 ($_FILES["file"]["type"] == "image/jpeg")
        
 ($_FILES["file"]["type"] == "image/jpg")
        
 ($_FILES["file"]["type"] == "image/pjpeg")
        
 ($_FILES["file"]["type"] == "image/x-png")
        
 ($_FILES["file"]["type"] == "image/png"))
    && ($_FILES["file"]["size"] < 10*1024*1024)
    && in_array($extension, $allowedExts)) {
    if ($_FILES["file"]["error"] > 0) {
        error("文件错误");
    } else {
        $ImageCachePath='images/hulu/';
        if (!is_dir($ImageCachePath)){
            $res = mkdir($ImageCachePath, 0777, true);
        }
        move_uploaded_file($_FILES["file"]["tmp_name"], $ImageCachePath . $_FILES["file"]["name"]);
        $files = $ImageCachePath . $_FILES["file"]["name"];
        $data = json_decode(upload($files)) ;
        unlink($files);
        if ($data->status!==1){
            error("上传错误");
        }else{
            exit(json_encode([
                "code"=>1,
                "msg"=>"上传成功!",
                "imgurl"=>str_replace("http","https",$data->url),
                "fid"=>$data->fid,
                "size"=>$data->size,
            ],JSON_UNESCAPED_UNICODE));
        }
    }
}else {
    error("非法的文件格式");
}
function upload($file){
    $post = array(
        'file'=>new \CURLFile(realpath($file))
    );
    $ch = curl_init("http://upload.huluxia.com/upload/image/avatar?platform=2&gkey=000000&app_version=4.0.1.3.1&versioncode=275&market_id=tool_web&_key=这里的key自己去抓");
    curl_setopt_array($ch, array(
        CURLOPT_POST => true,
        CURLOPT_VERBOSE => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => array(),
        CURLOPT_POSTFIELDS => $post,
    ));
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}
function error($str){
    exit(json_encode([
        "code"=>-1,
        "msg"=>$str
    ],JSON_UNESCAPED_UNICODE));
}


2.百度图床

 <?php
header('Access-Control-Allow-Origin:*');
header('Content-type:application/json; charset=utf-8');
error_reporting(0);
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
        
 ($_FILES["file"]["type"] == "image/jpeg")
        
 ($_FILES["file"]["type"] == "image/jpg")
        
 ($_FILES["file"]["type"] == "image/pjpeg")
        
 ($_FILES["file"]["type"] == "image/x-png")
        
 ($_FILES["file"]["type"] == "image/png"))
    && ($_FILES["file"]["size"] < 10*1024*1024)
    && in_array($extension, $allowedExts)) {
    if ($_FILES["file"]["error"] > 0) {
        error("文件错误");
    } else {
        $post_data = [
            "image"=>new \CURLFile(realpath($_FILES['file']['tmp_name'])),
        ];
        $data = Curl_POST("https://graph.baidu.com/upload",$post_data);
        if ($data==""){
            error("上传失败");
        }elseif (json_decode($data)->msg!=="Success"){
            error("上传失败");
        }else{
            $pic = "https://graph.baidu.com/resource/".json_decode($data)->data->sign.".jpg";
            echo json_encode([
                "code"=>1,
                "imgurl"=>$pic
            ]);
        }
    }
}else {
    error("非法的文件格式");
}
function randIp()
{
    return mt_rand(0, 255) . '.' . mt_rand(0, 255) . '.' . mt_rand(0, 255) . '.' . mt_rand(0, 255);
}
function Curl_POST($url,$post_data){
    $header=[
        'X-FORWARDED-FOR:'.randIp(),
        'CLIENT-IP:'.randIp()
    ];
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_NOBODY, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");   // 伪造ua
    curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
    curl_setopt($ch, CURLOPT_ENCODING, '');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
function error($str){
    exit(json_encode([
        "code"=>-1,
        "msg"=>$str
    ],JSON_UNESCAPED_UNICODE));
}
3.京东图床

 <?php
header('Access-Control-Allow-Origin:*');
header('Content-type:application/json; charset=utf-8');
error_reporting(0);
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
        
 ($_FILES["file"]["type"] == "image/jpeg")
        
 ($_FILES["file"]["type"] == "image/jpg")
        
 ($_FILES["file"]["type"] == "image/pjpeg")
        
 ($_FILES["file"]["type"] == "image/x-png")
        
 ($_FILES["file"]["type"] == "image/png"))
    && ($_FILES["file"]["size"] < 10*1024*1024)
    && in_array($extension, $allowedExts)) {
    if ($_FILES["file"]["error"] > 0) {
        error("文件错误");
    } else {
        if (class_exists('CURLFile')) { // php 5.5
            $post_data = [
                "file"=>new \CURLFile(realpath($_FILES['file']['tmp_name']))
            ];
        } else {
            $post_data = [
                "file"=>'@'.realpath($_FILES['file']['tmp_name'])
            ];
        }
        $rel = Curl_POST('https://search.jd.com/image?op=upload',$post_data);
        preg_match('/callback(?:\(\")(.*)(?:\"\))/i',$rel,$matches);
        if (!@$matches[1]) {
            error("图片上传失败!");
        }
        $arr = array(
            'code'     =>1,
            'imgurl'=>'https://img'.rand(10,14).'.360buyimg.com/uba/'.$matches[1]
        );
        echo json_encode($arr);
    }
    }else {
    error("非法的文件格式");
}
function randIp()
{
    return mt_rand(0, 255) . '.' . mt_rand(0, 255) . '.' . mt_rand(0, 255) . '.' . mt_rand(0, 255);
}
function Curl_POST($url,$post_data){
    $header=[
        'X-FORWARDED-FOR:'.randIp(),
        'CLIENT-IP:'.randIp(),
        "Accept:application/json",
        "Accept-Encoding:gzip,deflate,sdch",
        "Accept-Language:zh-CN,zh;q=0.8",
        "Connection:close"
    ];
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_NOBODY, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f=');
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
    curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
    curl_setopt($ch, CURLOPT_ENCODING, '');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
function error($str){
    exit(json_encode([
        "code"=>-1,
        "msg"=>$str
    ],JSON_UNESCAPED_UNICODE));
}
更多Api地址


此处为隐藏内容,请评论后查看隐藏内容,谢谢!

浏览168 评论2
返回
目录
返回
首页
苹果cms10设置视频跳转指定的外链-苹果cms设置视频跳转 当CDN挂了的解决方法

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

  • 评论列表
  • 访客 于 2020-10-14 19:13:44  回复
  • 对方付电费

  • 访客 于 2021-03-29 22:20:53  回复
  • UI稳如阿文哥sad