2015-01-28 2 views
0

2 개의 API 연습 예제를 결합하려고하지만 아래 코드에서 authorization_invalid_request 오류가 발생합니다.Docusign 결합 PDF 및 포함 된보기 및 사용자 지정 봉투

왜 그런지 이해할 수 있습니까?

또한 이것이 최적의 흐름인지 알고 싶지만 사용자가 내 로컬 데이터베이스에 해당 사용자를 위해 저장된 PDF를 기반으로 다른 문서에 서명하고 사용자가 템플릿을 동적으로 만들도록해야합니다. 그것을 docusign에 미리 정의 해두기보다는. 그 달성의 더 좋은 방법이 있습니까?

내 코드는 다음과 같습니다

<?php 

class DocusignView { 


    public static function getEmbeddedSignView($signerName, $templateId, $templateRoleName, $clientUserId) 
    {   
     // Input your info: 
    $email    = "***";    // your account email 
    $password   = "***";         // your account password 
    $integratorKey  = "***"; // your account integrator key, found on (Preferences -> API page) 
    $recipientName  = '***';     // provide a recipient (signer) name 
    $templateId   = '***';  // provide a valid templateId of a template in your account 
    $templateRoleName = 'Employee';         // use same role name that exists on the template in the console 
    $clientUserId  = '1';           // to add an embedded recipient you must set their clientUserId property in addition to 
                      // the recipient name and email. Whatever you set the clientUserId to you must use the same 
                      // value when requesting the signing URL 
     // construct the authentication header: 
    $header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>"; 

    ///////////////////////////////////////////////////////////////////////////////////////////////// 
    // STEP 1 - Login (retrieves baseUrl and accountId) 
    ///////////////////////////////////////////////////////////////////////////////////////////////// 
    $url = "https://demo.docusign.net/restapi/v2/login_information"; 
    $curl = curl_init($url); 
    curl_setopt($curl, CURLOPT_HEADER, false); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header")); 

    $json_response = curl_exec($curl); 
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 

    if ($status != 200) { 
     echo "error calling webservice, status is:" . $status; 
     exit(-1); 
    } 

    $response = json_decode($json_response, true); 
    $accountId = $response["loginAccounts"][0]["accountId"]; 
    $baseUrl = $response["loginAccounts"][0]["baseUrl"]; 
    curl_close($curl); 




    $envelopeId = DocusignView::requestSignByDoc($clientUserId);//$response["envelopeId"]; 

    ///////////////////////////////////////////////////////////////////////////////////////////////// 
    // STEP 2 - Get the Embedded Singing View 
    ///////////////////////////////////////////////////////////////////////////////////////////////// 
    $data = array("returnUrl" => "http://www.docusign.com/devcenter", 
     "authenticationMethod" => "None", "email" => $email, 
     "userName" => $recipientName, "clientUserId" => $clientUserId 
    );                  

    $data_string = json_encode($data);  
    $curl = curl_init($baseUrl . "/envelopes/$envelopeId/views/recipient"); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_POST, true); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);                 
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(                   
     'Content-Type: application/json',                     
     'Content-Length: ' . strlen($data_string), 
     "X-DocuSign-Authentication: $header")                  
    ); 

    $json_response = curl_exec($curl); 
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 
    if ($status != 201) { 
     echo "error calling webservice, status is:" . $status . "\nerror text is --> "; 
     print_r($json_response); echo "\n"; 
     exit(-1); 
    } 

    $response = json_decode($json_response, true); 
    $url = $response["url"]; 

    //--- display results 
    return $url; 
    } 




    public static function requestSignByDoc($clientUserId){   

    // Input your info here: 
    $email = "***";   // your account email 
    $password = "***";  // your account password 
    $integratorKey = "***";  // your account integrator key, found on (Preferences -> API page) 
    $recipientName = "***";  // provide a recipient (signer) name 
    $documentName = "***.pdf";  // copy document with same name into this directory! 

    // construct the authentication header: 
    $header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>"; 

    ///////////////////////////////////////////////////////////////////////////////////////////////// 
    // STEP 1 - Login (to retrieve baseUrl and accountId) 
    ///////////////////////////////////////////////////////////////////////////////////////////////// 
    $url = "https://demo.docusign.net/restapi/v2/login_information"; 
    $curl = curl_init($url); 
    curl_setopt($curl, CURLOPT_HEADER, false); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header")); 

    $json_response = curl_exec($curl); 
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 

    if ($status != 200) { 
     echo "error calling webservice, status is:" . $status; 
     exit(-1); 
    } 

    $response = json_decode($json_response, true); 
    $accountId = $response["loginAccounts"][0]["accountId"]; 
    $baseUrl = $response["loginAccounts"][0]["baseUrl"]; 
    curl_close($curl); 

    //--- display results 
// echo "\naccountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n"; 

    ///////////////////////////////////////////////////////////////////////////////////////////////// 
    // STEP 2 - Create an envelope with one recipient, one tab, and one document and send 
    ///////////////////////////////////////////////////////////////////////////////////////////////// 

    // the following request body will place 1 signature tab on the document you supply, located 
    // 100 pixels to the right and 100 pixels down from the top left of the document 
    $data = array (
      "emailSubject" => "DocuSign API - Signature Request on Document", 
      "documents" => array(array("documentId" => "1", "name" => $documentName)), 
      "recipients" => array("signers" => array(
       array( "email" => $email, 
         "name" => $recipientName, 
         "recipientId"=> '1', 
         "clientUserId" => $clientUserId, 
         "tabs" => array(
          "signHereTabs" => array(
           array( "anchorString"   => "Signed .....................................................", 
             "anchorXOffset"   => "0", 
             "anchorYOffset"   => "1", 
             "anchorIgnoreIfNotPresent"=> "false", 
             "anchorUnits"    => "inches") 
          )) 
       )) 
      ), 
     "status" => "created" 
    ); 
    $data_string = json_encode($data); 
    $temp = __DIR__.'/***.pdf'; 
    $file_contents = file_get_contents($temp); 

    $requestBody = "\r\n" 
    ."\r\n" 
    ."--myboundary\r\n" 
    ."Content-Type: application/json\r\n" 
    ."Content-Disposition: form-data\r\n" 
    ."\r\n" 
    ."$data_string\r\n" 
    ."--myboundary\r\n" 
    ."Content-Type:application/pdf\r\n" 
    ."Content-Disposition: file; filename=\"$documentName\"; documentid=1 \r\n" 
    ."\r\n" 
    ."$file_contents\r\n" 
    ."--myboundary--\r\n" 
    ."\r\n"; 

    // *** append "/envelopes" to baseUrl and as signature request endpoint 
    $curl = curl_init($baseUrl . "/envelopes"); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_POST, true); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);                 
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(                   
     'Content-Type: multipart/form-data;boundary=myboundary', 
     'Content-Length: ' . strlen($requestBody), 
     "X-DocuSign-Authentication: $header")                  
    ); 

    $json_response = curl_exec($curl); 
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 
    if ($status != 201) { 
     echo "error calling webservice, status is:" . $status . "\nerror text is --> "; 
     print_r($json_response); echo "\n"; 
     exit(-1); 
    } 

    $response = json_decode($json_response, true); 
    $envelopeId = $response["envelopeId"]; 

     return $envelopeId; 
    } 
} 

내 JSON 요청 :

"{ 
"returnUrl":"http:\/\/www.docusign.com\/devcenter", 
"authenticationMethod":"None", 
"email":"***", 
"userName":"***", 
"clientUserId":"1" 
}" 

내 JSON 응답 :

내 인증 방법은 null로 설정하지만 난 아무런 문제가 실행이 없었다됩니다
"{ 
    "errorCode": "AUTHORIZATION_INVALID_REQUEST", 
    "message": "The authorization request is malformed." 
}" 

사용자 정의 봉투를 사용하지 않을 때의 임베디드 뷰 예제 (즉, 문서 별 요청 기호).

그리고

은을 heres이 하나를 사용하여 API 같은 문제를 사용하여 시도 :

$docuSignClient   = new DocuSign_Client(); 
$docuService   = new DocuSign_ViewsService($docuSignClient); 
$viewResource   = new DocuSign_ViewsResource($docuService);     
$signatureResource  = new DocuSign_RequestSignatureResource($docuService); 

$temp = __DIR__.'/test.pdf'; 
$file_contents = file_get_contents($temp); 
$document[]    = new DocuSign_Document('test.pdf', '1', $file_contents); 

$recipient[]    = new DocuSign_Recipient('1', '1', 'Signer1', '[email protected]', '1', 'signers'); 

$envelopeId = $signatureResource->createEnvelopeFromDocument('TEST EMAIL SUBJECT', "PLease sign this", "created", $document, $recipient)->envelopeId;     
$returnUrl = $request->getUri(); 
$url   = $viewResource->getRecipientView($returnUrl, $envelopeId, 'Signer1', '[email protected]', '1'); 

나는 무엇을 놓치고?

+0

실제로 JSON 요청/응답을 게시 할 수 있습니까 (사용자 이름/비밀번호/통합 자 제거와 함께)? – Andrew

+0

@AndrewWilson JSON 요청 및 응답으로 편집 – mixkat

+0

모든 것이 코드와 JSON에서 올바르게 보입니다. 오류를 재현 할 수있는 유일한 시간은 email/userName/clientUserId에 유효하지 않은 데이터가있을 때입니다. 나는 거기서 파고 들겠다. 그리고 그 변수들이 100 % 정확하다는 것을 확인하자. – Andrew

답변

2

그래서 봉투가 초안/작성된 상태이며 전송되지 않았기 때문에 버그가 발생했습니다. 의미가 있지만 나이를 알아내는 것이 었습니다.

+0

아! ''status "=>"created "'는 그것을 할 것입니다! 오류 메시지는 아마도 개선되어야합니다. – Andrew

+0

@AndrewWilson 그래, 오류 메시지는별로 도움이되지 않았다. 나머지 API 가이드의 167 페이지는 다음과 같다 : "보내진 봉투에 대해 DocuSign UI의 수신자보기를 시작하는 URL을 제공합니다.이 호출은 일 수 없습니다. 봉투가 보내지지 않았기 때문에 초안 봉투를 보는 데 사용됩니다. " – mixkat

관련 문제