为了账号安全,请及时绑定邮箱和手机立即绑定

如何从拉拉维尔的迪亚维获得应用下载链接

如何从拉拉维尔的迪亚维获得应用下载链接

PHP
MMTTMM 2022-09-12 13:15:55
我如何在拉拉维尔获得上传的应用程序的可下载链接?我想将链接存储在 mysql 中。我使用curl上传应用程序。这是我的代码!$headers = array("Content-Type: multipart/form-data");     $postfields = array(        "token"             => 'IXWEsIpQBRUM4gSDu6f9aLB7W2AEPlsGb2kAJRVmRw',        "file"              => new \CurlFile( $filename ),        "find_by_udid"      => 0,        "wall_of_apps"      => 1        // "callback_email"    => ''        );    $ch = curl_init();    $options = array(        CURLOPT_URL => $url,        CURLOPT_HEADER => true,        CURLOPT_POST => 1,        CURLOPT_HTTPHEADER => $headers,        CURLOPT_POSTFIELDS => $postfields,        CURLOPT_USERAGENT => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36'    );    curl_setopt_array($ch, $options);    curl_exec($ch);    if(!curl_errno($ch))    {        $info = curl_getinfo($ch);                 if ($info['http_code'] == 200)            $curl_error = "File uploaded successfully";    }    else    {        $curl_error = curl_error($ch);    }    curl_close($ch);}else{    $curl_error = "Please select the file";}echo $curl_error;   
查看完整描述

1 回答

?
红颜莎娜

TA贡献1842条经验 获得超12个赞

这很简单,当您上传成功时,Diawi会返回一个作业ID,通过该ID,您可以创建跟踪器链接并对其发出GET请求。作为回应,您可以获得下载链接(如果文件未通过Diawi的检查,则会出现错误消息。


链接格式类似于


 https://upload.diawi.com/status?token={TOKEN}&job={JOB_ID}

试试这个


    $headers = array("Content-Type: multipart/form-data");

    $postfields = array(

        "token"             => 'IXWEsIpQBRUM4gSDu6f9aLB7W2AEPlsGb2kAJRVmRw',

        "file"              => new \CurlFile( $filename ),

        "find_by_udid"      => 0,

        "wall_of_apps"      => 1,

        //"callback_email"    => ''

        );

    $ch = curl_init();

    $options = array(

        CURLOPT_URL => $url,

        //CURLOPT_HEADER => true, <-- don't need this otherwise would mess the response body

        CURLOPT_POST => 1,

        CURLOPT_HTTPHEADER => $headers,

        CURLOPT_POSTFIELDS => $postfields,

        CURLOPT_USERAGENT => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36',

        CURLOPT_RETURNTRANSFER => 1 // we need to collect the diawi's json response

    ); // cURL options

    curl_setopt_array($ch, $options);

    $op = curl_exec($ch); //<-- $op contains the job details if success


    if(!curl_errno($ch))

    {

        $info = curl_getinfo($ch);

        if ($info['http_code'] == 200){

            $curl_error = "File uploaded successfully"; //<-- not really you can't be sure unless you check the tracker link response


            $job_details = json_decode($op); //the response is in json format

            $job_id = $job_details->job;


            //THE TRACKER LINK FORMAT

            //https://upload.diawi.com/status?token={TOKEN}&job={JOB_ID}


            $status_link = 'https://upload.diawi.com/status?token=IXWEsIpQBRUM4gSDu6f9aLB7W2AEPlsGb2kAJRVmRw&job='.$job_id;


            $ch2 = curl_init();

            curl_setopt($ch2, CURLOPT_URL, $status_link);

            curl_setopt($ch2, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));

            curl_setopt($ch2, CURLOPT_HEADER, 0);

            curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);

            $op2 = curl_exec($ch2);


            $upload_response = json_decode($op2);

            if($upload_response->status == 2000){

                echo '<br>File uploaded successfully : download link ' . $upload_response->link;

            }

            curl_close($ch2);


        }


    }

    else

    {

        $curl_error = curl_error($ch);

    }

    curl_close($ch);

PS:在Q / A平台上发布时,最好屏蔽API密钥


查看完整回答
反对 回复 2022-09-12
  • 1 回答
  • 0 关注
  • 61 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信