简体   繁体   English

PHP Adob​​eSign API ::具有OAuth2.0的transientDocuments

[英]PHP AdobeSign API :: transientDocuments with OAuth2.0

I am using PHP OAuth2.0 Adobesign API for sending pdf to user for e-signature purpose. 我正在使用PHP OAuth2.0 Adobesign API将pdf发送给用户以进行电子签名。

I successfully generate auth token and refresh token by following basic OAuth2 steps. 我遵循以下基本OAuth2步骤成功生成了身份验证令牌并刷新了令牌。

Now I am facing issue while trying to send pdf transientDocuments using curl code. 现在,我在尝试使用卷曲代码发送pdftransientDocuments时遇到问题。 Below is my sample code: 下面是我的示例代码:

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();

Output: 输出:

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

I had a little play in some free time and the following seemed to work on my test system. 我在空闲时间玩了一点游戏,以下内容似乎可以在我的测试系统上正常工作。 The function targets a very simple php endpoint rather than a remote url/api endpoint. 该函数的目标是非常简单的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 );
}

The simple PHP endpoint is: 简单的PHP端点是:

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

The response, to highlight success was as follows: 为了突出成功,答复如下:

LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS02NGQ5ZGYyYTE3ZmE1MGNkDQpDb250ZW50LURpc3Bvc...etc etc

Finally I come to know Adobe Esign with V6 having some issue with this method. 最终,我知道使用V6的Adobe Esign在此方法上存在一些问题。 So I switch to V5 and make some little modification in my code. 因此,我切换到V5并在代码中进行了一些小的修改。 It is working for me. 它为我工作。

<?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);
?>

Output: 输出:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 (PHP)Oauth2.0-错误401 Google通讯录API - (PHP) Oauth2.0 - Error 401 Google Contacts API Twinfield API OAuth2.0 getaccessToken php-twinfield/twinfield - Twinfield API OAuth2.0 getaccessToken php-twinfield/twinfield 使用 OAuth2.0 在 PHP 中包含 Google Sitemap Api - Including Google Sitemap Api in PHP with OAuth2.0 Linkedin REST API:使用CRON作业中的php更新OAuth2.0访问令牌吗? - Linkedin REST API: Update OAuth2.0 Access token using php from a CRON job? 带有 PHP API oauth2.0 的 Google 日历服务帐户 - 如何访问未共享的日历 - Google Calendar Service Account with PHP API oauth2.0 - How to access calendars that are not shared 在后端使用 PHP 和 curl 为 Spotify 进行中央 OAuth2.0 授权 WebA ZDB9742CE18718Z - Central OAuth2.0 Authorization on the Backend-Side using PHP and curl for Spotify Web API 谁能为我提供用于salesforce oauth2.0 REST API的PHP库? - Can anyone provide me the PHP library for salesforce oauth2.0 REST API? JSON POST请求 - Pocket API / OAuth2.0 - JSON POST request - Pocket API / OAuth2.0 …API调用oAuth2.0刷新令牌问题PandaDocs - … API Call oAuth2.0 Refresh Token issue PandaDocs 使用OAuth2.0使用PHP的C2DM(不推荐使用ClientLogin!) - C2DM with PHP using OAuth2.0 (ClientLogin is deprecated!)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM