初学者

【更新】PHP获取158盘分享直链

158Pan API

说明

1.解析158Pan直链下载
2.解决158Pan烦人的下载器和各种广告
3.有能力的可以自己适当进行更改
4.转载或使用请保留版权!!!

用法

id:外链URL上面的数字ID
https://api.iiwl.cc/158/?id=251892

原理解释

利用curl提交POST数据包提取真实链接

文档

https://api.iiwl.cc/158/api.php

更新内容

2019.12.4
修复失效问题

注意事项

可能随时失效,欢迎留言
其他问题看文档

安全限制,直接放源代码

<?php
/**
 * @package 158Pan
 * @author Andy
 * @version 1.2.0
 * @link https://lsland.cn
 */
// 指定允许其他域名访问  
header('Access-Control-Allow-Origin:*');
header('content-type:application/json;charset:utf-8');
    function object_array($array) {  
        if(is_object($array)) {  
            $array = (array)$array;  
        } if(is_array($array)) {  
            foreach($array as $key=>$value) {  
                $array[$key] = object_array($value);  
            }  
        }  
        return $array;  
    }
    function Curl_Post($id){
      $data = 'js={"appid":307,"avs":2,"bdb":0,"getlist":{"avs":2,"bdb":0,"c1":1,"inslog":"","proc":[{"id":"1"},{"id":"3"}],"reg":[{"id":714},{"id":848},{"id":894}],"reg2":[441,459,26282,29600,33143,18920,33144],"vm":0},"id":2052,"md5":"67b7a4442c20658c67819f5fda9559ba","msoft":"IU-斑马,斑马@307_251892.exe","sid":'.$id.',"st":0,"uid":"1aeccea753321c903309ee4943657276","ver":"4.0.0.1126","vm":0,"zn":8}';
      $UserAgent = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)';#设置UserAgent
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL, "https://x.93ne.com/qy/gi");
      //关闭SSL 表示不检查证书
      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
      curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
      curl_setopt($curl, CURLOPT_HEADER, 0);          //启用时会将头文件的信息作为数据流输出。这里不启用
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);  //如果成功只将结果返回,不自动输出任何内容。如果失败返回FALSE
      curl_setopt($curl, CURLOPT_POST, 1);            //如果你想PHP去做一个正规的HTTP POST,设置这个选项为一个非零值。这个POST是普通的 application/x-www-from-urlencoded 类型,多数被HTML表单使用。
      curl_setopt($curl, CURLOPT_POSTFIELDS, $data);  //需要POST的数据
      curl_setopt($curl, CURLOPT_HTTPHEADER, array("application/x-www-form-urlencoded", "Content-length: ".strlen($data)));
      $rtn = curl_exec($curl);
      if(!curl_errno($curl)){
        return $rtn;
      } else {
        echo 'Curl error: ' . curl_error($curl);
      }
      curl_close($curl);
    }

    $type = isset($_GET['type']) ? $_GET['type'] : "";
    if (!empty($_GET['id'])) {
        $id = $_GET['id'];
          $result = json_decode(Curl_Post($id));
        $result = object_array($result);
        $downUrl = $result["main"]["descr_downurl"];
        if ($type != "down") {
          die(
            json_encode(
              array(
                'code' => 200,
                'msg' => '此API仅供于学习!',
                'name' => $result["main"]["descr_name"],
                'downUrl' => $downUrl
              )
              , JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
          );
        } else {
          header("Location:$downUrl");
          die;
        }
    }else{
        $result_url = str_replace("index.php","",$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?id=251892");
        echo '演示:'.$result_url;
    }
?>

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »