PHP AdobeSign API :: transientDocuments with OAuth2.0



我正在使用PHP OAuth2.0 Adobesign API向用户发送pdf以进行电子签名。

我按照基本的 OAuth2 步骤成功生成身份验证令牌和刷新令牌。

现在我在尝试使用 curl 代码发送 pdf 瞬态文档时遇到问题。 下面是我的示例代码:

define("CALLBACK_URL", "https://www.getdadstrong.com/vipin/test.php");
define("AUTH_URL", "https://api.in1.echosign.com/api/rest/v6/transientDocuments");
define("ACCESS_TOKEN_URL", "http://api.in1.echosign.com/oauth/token");
define("CLIENT_ID", "MY_CLIENT_ID");
define("CLIENT_SECRET", "MY_CLIENT_SECRET");
define("SCOPE", "agreement_send:account"); // optional

function getToken(){
 $curlFILE = curl_init();
 $params = array(
    CURLOPT_URL =>  AUTH_URL,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_NOBODY => false, 
    CURLOPT_HTTPHEADER => array(
    "Authorization: Bearer MY_SECURE_TOKEN", 
      "cache-control: no-cache",
      "content-type: multipart/form-data",
      "Content-Disposition: form-data; name='file'; filename='MyPDF.pdf'",
    ),
    CURLOPT_POSTFIELDS => array (
                // 'filename' => new CURLFile('./MyPDF.pdf') 
                'filename' => new CURLFile('./MyPDF.pdf','application/pdf','MyFile') 
        ),
    CURLOPT_SSL_VERIFYPEER => FALSE,
    CURLOPT_SSL_VERIFYHOST => FALSE 
  );
    curl_setopt_array($curlFILE, $params);
    $response = curl_exec($curlFILE);

    curl_close($curlFILE);
    $err = curl_error($curlFILE);
    if ($err) {
        echo "<br/> cURL Error #01: " . $err;
    } 
    echo '<pre>';
    var_dump($err);  
    var_dump($response);  
    echo '<pre>';
  }
getToken();

输出:

{
    "code": "NO_FILE_CONTENT",
    "message": "Must provide file body"
}
最后,

我知道 Adobe Esign 与 V6 对这种方法有一些问题。 所以我切换到 V5 并在代码中进行一些小修改。 它正在为我工作。

<?php
define("AUTH_URL", "https://api.na2.echosign.com/api/rest/v5/transientDocuments");
$url = AUTH_URL;
$header =array(
        "Authorization: Bearer 3AAAB6hBTt666543359kgBzroaNxqyezwBRdsdsdssssssssss6767gGy7CNdERHxqz1r5lOzmyxI7hfQ22zsyCDvnG_HRc8m9B7UBRJuGy", 
        "cache-control: no-cache",
        "content-type: multipart/form-data",
        "Content-Disposition: form-data; name='File'; filename='MyPDF.pdf'",
    );
$filePath= '@'.file_get_contents('MyPDF.pdf');
$fields = array('File' => $filePath,'Mime-Type' => 'application/pdf', 'File-Name' => 'MyPDF.pdf');
$resource = curl_init();
curl_setopt_array($resource, array(
  CURLOPT_URL => $url,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => $fields,
  CURLOPT_HTTPHEADER => $header
));

$res = curl_exec($resource);
$result = json_decode($res,true);
echo "<pre>";
print_r($result);
echo "</pre>";
curl_close($resource);
?>

输出:

Array
(
    [transientDocumentId] => 3AA777777777777gwxctQX8kTYj2e3Esgc5_HbvKgKK_oaIccNqr2JwWJK8bUXn779OMvyFMJG2VONbbbMqO-bo_GoKJP-wfYszcQtg7tbJ8sc8YxTwQPm3kV77777ThgQy5ZoeHb_km-zmitgdSkf7sLYp0vCO8CAbvYQVzd3OpU6zJ-Mv54VoVKvsYUFsfhfhgK]epKpCHnvKWvn37fghfg777876rV2QYyh9bkApotXvSzxndXNQbUTmAcpP1Jq-WlXsVdGleKjHoEMoDgfhfghIOYQFxy5eeOtctqwtxC9MUWjioGV6FW6ZtoGm0ijqGU*
)

我在一些空闲时间玩了一点,以下内容似乎适用于我的测试系统。该函数针对非常简单的 php 端点,而不是远程 url/api 端点。

$file=sprintf('%s%slamb_vindaloo.pdf', __DIR__, DIRECTORY_SEPARATOR );

define( 'BEARER_TOKEN', '74e793ea86b6e06d5d971454a955c48012a422d7694d3463c23f69ef758f62db' );
define( 'AUTH_URL', 'https://sentinel/demo/stack/pdf-receiver.php' );
define( 'CA_CERTIFICATE', 'c:/wwwroot/cacert.pem' );

function getToken( $file=false ){
    if( !$file )return;
    $curl = curl_init();
    $params = array(
        CURLOPT_URL =>  AUTH_URL,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_POST => true,
        CURLOPT_NOBODY => false, 
        CURLOPT_HTTPHEADER => array(
            sprintf( "Authorization: Bearer %s", BEARER_TOKEN ), 
            "Cache-Control: no-cache",
            "Content-Type: application/octet-stream",   #   <----- set the content-type
            sprintf("Content-Disposition: form-data; name='file'; filename='%s'", $file ),
        ),
        CURLOPT_POSTFIELDS => array (
            'filename'  =>  new CURLFile( $file, mime_content_type( $file ), pathinfo( $file, PATHINFO_FILENAME ) ) 
        ),
        CURLOPT_CAINFO  =>  CA_CERTIFICATE,     #   <------ if the endpoint is SSL it is advisable to use a valid cacert.pem file!!
        CURLOPT_SSL_VERIFYPEER => false,        #   <------ if possible set this to true
        CURLOPT_SSL_VERIFYHOST => 2             #   <------ true/false are not options for this
    );
    curl_setopt_array( $curl, $params );
    /*
        Return an object with the various return values
        rather than doing any printing from within the 
        function
    */
    $res=(object)array(
        'response'  =>  curl_exec( $curl ),
        'info'      =>  (object)curl_getinfo( $curl ),
        'errors'    =>  curl_error( $curl )
    );
    curl_close( $curl );
    return $res;
}   
/* call the function */
$results=getToken( $file );
/* process the response accordingly */
if( $results->info->http_code==200 ){
    printf('<pre>%s</pre>', $results->response );
}

简单的 PHP 端点是:

<?php
    #
    #   PDF File Receiver for curlFile Tests....
    #
    $data=file_get_contents( 'php://input' );
    echo base64_encode( $data );
?>

为突出成功,回应如下:

LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS02NGQ5ZGYyYTE3ZmE1MGNkDQpDb250ZW50LURpc3Bvc...etc etc

相关内容

  • 没有找到相关文章

最新更新