soft

soft

alist做IOS分发

<?php

    /**
     * 传入数组进行HTTP POST请求
     */
    function curlPost($url, $post_data = array(), $timeout = 5, $header = "", $data_type = "") {
        $header = empty($header) ? '' : $header;
        //支持json数据数据提交
        if($data_type == 'json'){
            $post_string = json_encode($post_data);
        }elseif($data_type == 'array') {
            $post_string = $post_data;
        }elseif(is_array($post_data)){
            $post_string = http_build_query($post_data, '', '&');
        }
       
        $ch = curl_init();    // 启动一个CURL会话
        curl_setopt($ch, CURLOPT_URL, $url);     // 要访问的地址
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  // 对认证证书来源的检查   // https请求 不验证证书和hosts
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);  // 从证书中检查SSL加密算法是否存在
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
        //curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
        //curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
        curl_setopt($ch, CURLOPT_POST, true); // 发送一个常规的Post请求
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);     // Post提交的数据包
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);     // 设置超时限制防止死循环
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        //curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);     // 获取的信息以文件流的形式返回 
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //模拟的header头
        $result = curl_exec($ch);
     
        // 打印请求的header信息
        //$a = curl_getinfo($ch);
        //var_dump($a);
        curl_close($ch);
        return $result;
    }
   
    function phpEncodeURIComponent($str){
       return  urlencode(iconv("UTF-8", "UTF-8", $str));
    }
   
    $path=$_GET['path'];
    $name=$_GET['name'];
    $id=$_GET['id'];
    if (!empty($path) && !empty($name) && !empty($id) ) {
        $url="https://alist.xxxxx.cn/api/fs/get";
        $body = array("path"=>$path, "password"=>"");
        $header = array("Content-Type:application/json; charset=utf-8");
        $result = curlPost($url, $body, 5, $header, 'json');
        //var_dump($result);
        $resultObj=json_decode($result,true);
        //var_dump($resultObj['data']['raw_url']);
        if(200==$resultObj['code']  && $resultObj['data']['raw_url'] ){
            $ipaUrl=$resultObj['data']['raw_url'];
            $ipaName=$resultObj['data']['name'];
            $ddomain="https://alist.xxxxx.cn";
            $u1=phpEncodeURIComponent($ipaUrl);//iconv('UTF-8','UTF-8',$ipaUrl);
            //$u2=base64_encode( $u1);
            $n1=phpEncodeURIComponent($ipaName);//iconv('UTF-8','UTF-8',$ipaName);
            //$n2=explode(".",$n1)[0];
            $n2=str_replace(".ipa","",$n1);
            //var_dump($n1);
            $urls2=base64_encode("{$u1}/$n2");
            $urls2=str_replace("=",".",$urls2);
            //return `itms-services://?action=download-manifest&url=${l}/i/${m( encodeURIComponent(t.raw_url) + "/" + c(encodeURIComponent(t.obj.name)))}.plist`
            $newIpaItms="itms-services://?action=download-manifest&url={$ddomain}/i/{$urls2}.plist";
            //exit($newIpaItms);
            Header("Location: {$newIpaItms}");
        }else{
            exit("<h1>error 2,not found file!</h1>");
        }
 
    }else {
        exit("<h1>error 1,param is error !</h1>");
    }


?>


发表评论:

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

联系我 331434376    15629529961