如何在php中使用crocdoc

时间:2013-05-22 11:09:47

标签: documentviewer document-view crocodoc

我在php中使用了crocdoc https://github.com/crocodoc/crocodoc-php

我在我的本地下载了文件我有我的API TOKEN所以我把它粘贴在那里但它似乎没有工作并抛出所有15个例子的错误如下所示

任何人都可以帮助我

这是我在上面使用我的令牌

上面的github代码时出现的错误
Example #1 - Upload Form W4 from the IRS by URL.
  Uploading... failed :(
  Error Code: curl_exception
  Error Message: Crocodoc: [curl_exception] Crocodoc::_request

{"curl_errno":60,"curl_error":"SSL certificate problem, verify that the CA cert is OK. Details:\nerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed"}



Example #15 - Delete the second file we uploaded.
  Deleting... failed :(
  Error Code: curl_exception
  Error Message: Crocodoc: [curl_exception] Crocodoc::_request

{"curl_errno":60,"curl_error":"SSL certificate problem, verify that the CA cert is OK. Details:\nerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed"}

要检查我正在使用crocodoc API,我编写了自己的代码

这是我在自己的代码中得到的错误

::::OUTPUT::::
{"uuid": "300dc39d-e82b-4d92-a701-b1f376600b96"}
checking status of : {"uuid": "300dc39d-e82b-4d92-a701-b1f376600b96"}

Curl error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Curl error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Curl error no: 60
out put for docurlGet is : 
bool(false) status is : 
Viewing the Document : {"uuid": "300dc39d-e82b-4d92-a701-b1f376600b96"}

这是我的代码(我很抱歉,如果我不想粘贴整个代码但无法理解整个问题,那么我只是提供完整的代码)

<?php

$myToken='gSqV0PpEZhvJfLxQTcuMmoty';
$frameUrl='https://crocodoc.com/api/v2/document/upload';
 $api_url = 'https://crocodoc.com/api/v2/';
//curl "https://crocodoc.com/api/v2/document/upload" --data "token=${API_TOKEN}&url=http://web.crocodoc.com/files/test-simple.pdf"
$param='token='.$myToken.'&url=http://web.crocodoc.com/files/test-simple.pdf';

 //curl command 

    $ch = curl_init(); 
                @curl_setopt($ch, CURLOPT_HEADER, 0);
                @curl_setopt($ch, CURLOPT_HTTPHEADER,  array('Accept: application/json', 'X-HTTP-Method-Override: POST'));
                @curl_setopt($ch, CURLOPT_POST, 1);
                @curl_setopt($ch, CURLOPT_URL, $frameUrl);   
                @curl_setopt($ch, CURLOPT_POSTFIELDS,$param);

                @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
                curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
                curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
                $uuids = curl_exec($ch);
 echo $uuids;
 echo "<br>";
 echo " checking status of : ", $uuids."<br>";
$status =getStatus($uuids,$api_url,$myToken);
//curl 'https://crocodoc.com/api/v2/document/status?token=F6JOdArWGKmDRlfPQcZna71x&uuids=d5ea0542-baaf-46a1-835c-685a86e70e14'
echo " status is : ", $status."<br>";


echo " Viewing the Document  : ", $uuids."<br>";

function getStatus($uuids,$api_url,$myToken){


            $isSingleUuid = is_string($uuids);

                $obj  = json_decode($uuids);
                $my_uuid= $obj->uuid;

                $url = $api_url.'document/status';

        $token = $myToken;

        $dataStr = '?token='.$token.'&uuids='.$my_uuid;

        $output = my_doCurlGet($url, $dataStr);
               var_dump($output); 
        return $output;


}




        function my_doCurlGet($url, $dataStr) {
        //var_dump($url.$dataStr);
        //  var_dump($dataStr);exit;

        //
        $ch1 = curl_init();

        @curl_setopt($ch1, CURLOPT_HEADER, 0);
        @curl_setopt($ch1, CURLOPT_HTTPHEADER,  array('Accept: application/json', 'X-HTTP-Method-Override: POST'));
        @curl_setopt($ch1, CURLOPT_POST, 1);
        @curl_setopt($ch1, CURLOPT_URL, $url.$dataStr);
        @curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch1);

        if(curl_exec($ch1) === false)
        {
        echo "<br>".'Curl error: ' . curl_error($ch1);
        }
        else
        {
        echo "<br>".'Operation completed without any errors'."<br>";
        }
        //var err_no=curl_errno()
        if(curl_errno($ch1))
        {
        echo "<br>".'Curl error: ' . curl_error($ch1);
        echo "<br>".'Curl error no: ' . curl_errno($ch1);
        }


        echo "<br>". "out put for docurlGet is : $output"."<br>";


        return $output;
        }


  if (curl_errno($ch)) {    
    print 'An curl error has occurred.';
 exit;
  }
  //var_dump($uuids);
  curl_close($ch);        
  return $uuids;
?> 

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

Curl可能未正确配置CA捆绑包,或者配置的CA捆绑包不包含Crocodoc的CA证书。

查看this answer了解详情。

答案 1 :(得分:0)

找到答案

首先,我确实启用了curl和SSL,但它无法正常工作

我甚至将我的Localhost名称更改为myHost,但它仍无法正常工作

所以我在从crocodoc api库下载的crocodoc.php文件中做了一些更改

CROCODOC PHP LIBRARY

我添加了这些行并且IT WORKED :) :) :)谢谢大家,希望这对其他人也有帮助。

if(($_SERVER['SERVER_NAME'] == 'myHost') && ($_SERVER['SERVER_ADDR'] == '127.0.0.1') && ($_SERVER['HTTP_HOST'] == 'myHost')) {
            $options[CURLOPT_SSL_VERIFYPEER]=false;
        }