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

我如何在拉拉维尔获得上传的应用程序的可下载链接?我想将链接存储在 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;   


MMTTMM
浏览 62回答 1
1回答

红颜莎娜

这很简单,当您上传成功时,Diawi会返回一个作业ID,通过该ID,您可以创建跟踪器链接并对其发出GET请求。作为回应,您可以获得下载链接(如果文件未通过Diawi的检查,则会出现错误消息。链接格式类似于&nbsp;https://upload.diawi.com/status?token={TOKEN}&job={JOB_ID}试试这个&nbsp; &nbsp; $headers = array("Content-Type: multipart/form-data");&nbsp; &nbsp; $postfields = array(&nbsp; &nbsp; &nbsp; &nbsp; "token"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=> 'IXWEsIpQBRUM4gSDu6f9aLB7W2AEPlsGb2kAJRVmRw',&nbsp; &nbsp; &nbsp; &nbsp; "file"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; => new \CurlFile( $filename ),&nbsp; &nbsp; &nbsp; &nbsp; "find_by_udid"&nbsp; &nbsp; &nbsp; => 0,&nbsp; &nbsp; &nbsp; &nbsp; "wall_of_apps"&nbsp; &nbsp; &nbsp; => 1,&nbsp; &nbsp; &nbsp; &nbsp; //"callback_email"&nbsp; &nbsp; => ''&nbsp; &nbsp; &nbsp; &nbsp; );&nbsp; &nbsp; $ch = curl_init();&nbsp; &nbsp; $options = array(&nbsp; &nbsp; &nbsp; &nbsp; CURLOPT_URL => $url,&nbsp; &nbsp; &nbsp; &nbsp; //CURLOPT_HEADER => true, <-- don't need this otherwise would mess the response body&nbsp; &nbsp; &nbsp; &nbsp; CURLOPT_POST => 1,&nbsp; &nbsp; &nbsp; &nbsp; CURLOPT_HTTPHEADER => $headers,&nbsp; &nbsp; &nbsp; &nbsp; CURLOPT_POSTFIELDS => $postfields,&nbsp; &nbsp; &nbsp; &nbsp; CURLOPT_USERAGENT => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36',&nbsp; &nbsp; &nbsp; &nbsp; CURLOPT_RETURNTRANSFER => 1 // we need to collect the diawi's json response&nbsp; &nbsp; ); // cURL options&nbsp; &nbsp; curl_setopt_array($ch, $options);&nbsp; &nbsp; $op = curl_exec($ch); //<-- $op contains the job details if success&nbsp; &nbsp; if(!curl_errno($ch))&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; $info = curl_getinfo($ch);&nbsp; &nbsp; &nbsp; &nbsp; if ($info['http_code'] == 200){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $curl_error = "File uploaded successfully"; //<-- not really you can't be sure unless you check the tracker link response&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $job_details = json_decode($op); //the response is in json format&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $job_id = $job_details->job;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //THE TRACKER LINK FORMAT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //https://upload.diawi.com/status?token={TOKEN}&job={JOB_ID}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $status_link = 'https://upload.diawi.com/status?token=IXWEsIpQBRUM4gSDu6f9aLB7W2AEPlsGb2kAJRVmRw&job='.$job_id;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ch2 = curl_init();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; curl_setopt($ch2, CURLOPT_URL, $status_link);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; curl_setopt($ch2, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; curl_setopt($ch2, CURLOPT_HEADER, 0);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $op2 = curl_exec($ch2);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $upload_response = json_decode($op2);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if($upload_response->status == 2000){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<br>File uploaded successfully : download link ' . $upload_response->link;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; curl_close($ch2);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; else&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; $curl_error = curl_error($ch);&nbsp; &nbsp; }&nbsp; &nbsp; curl_close($ch);PS:在Q / A平台上发布时,最好屏蔽API密钥
打开App,查看更多内容
随时随地看视频慕课网APP