如何使用docusign api

时间:2017-03-30 07:10:16

标签: docusignapi

我正在尝试将docusign嵌入式签名集成到我的混合应用程序中,我正在我的应用程序中的iframe中加载签名网址,但有没有办法使用该签名网址动态添加更多自定义字段并使其成为可能处于解锁状态,以便我可以将它们拖动到我想要的位置,然后在发送给发件人进行签名时锁定这些字段,以及如何在签名后获取该文档的URL以便我可以查看它以后。

由于我是新手,请帮助我。

这是我获取签名网址的代码

<?php
$min=100;
$max=300;
$random = rand($min,$max);
$recipientId=rand();
require_once('vendor/autoload.php');
//require_once('./docusign-php-client/autoload.php');
// DocuSign account credentials & Integrator Key
$username = "testmail@mail.com";
$password = "test1234";
$integrator_key = "[integrator-key]";
$host = "https://demo.docusign.net/restapi";
// create a new DocuSign configuration and assign host and header(s)
$config = new DocuSign\eSign\Configuration();
$config->setHost($host);
$config->addDefaultHeader("X-DocuSign-Authentication", "{\"Username\":\"" . $username . "\",\"Password\":\"" . $password . "\",\"IntegratorKey\":\"" . $integrator_key . "\"}");
/////////////////////////////////////////////////////////////////////////
// STEP 1:  Login() API
/////////////////////////////////////////////////////////////////////////
// instantiate a new docusign api client
$apiClient = new DocuSign\eSign\ApiClient($config);
// we will first make the Login() call which exists in the AuthenticationApi...
$authenticationApi = new DocuSign\eSign\Api\AuthenticationApi($apiClient);
// optional login parameters
$options = new \DocuSign\eSign\Api\AuthenticationApi\LoginOptions();
// call the login() API
$loginInformation = $authenticationApi->login($options);
// parse the login results
if(isset($loginInformation) && count($loginInformation) > 0)
{
    // note: defaulting to first account found, user might be a 
    // member of multiple accounts
    $loginAccount = $loginInformation->getLoginAccounts()[0];
    if(isset($loginInformation))
    {
        $accountId = $loginAccount->getAccountId();
        if(!empty($accountId))
        {
            echo "<b>Account ID</b> = $accountId</br>";
        }
    }
}
/////////////////////////////////////////////////////////////////////////
// STEP 2:  Create & Send Envelope with Embedded Recipient
/////////////////////////////////////////////////////////////////////////
// set recipient information
$recipientName = "username";
$recipientEmail = "Test@email.com";
// configure the document we want signed
$documentFileName = "/abcd_test_01.pdf";
$documentName = "abcd_test.pdf";
// instantiate a new envelopeApi object
$envelopeApi = new DocuSign\eSign\Api\EnvelopesApi($apiClient);
// Add a document to the envelope
$document = new DocuSign\eSign\Model\Document();
$document->setDocumentBase64(base64_encode(file_get_contents(__DIR__ . $documentFileName)));
$document->setName($documentName);
$document->setDocumentId("1");
// Create a |SignHere| tab somewhere on the document for the recipient to sign
$signHere = new \DocuSign\eSign\Model\SignHere();
$signHere->setXPosition($random);
$signHere->setYPosition($random);
$signHere->setDocumentId("1");
$signHere->setPageNumber("1");
$signHere->setRecipientId("1");
// add the signature tab to the envelope's list of tabs
$tabs = new DocuSign\eSign\Model\Tabs();
$tabs->setSignHereTabs(array($signHere));
// add a signer to the envelope
$signer = new \DocuSign\eSign\Model\Signer();
$signer->setEmail($recipientEmail);
$signer->setName($recipientName);
$signer->setRecipientId("1");
$signer->setTabs($tabs);
$signer->setClientUserId($recipientId);  // must set this to embed the recipient!
// Add a recipient to sign the document
$recipients = new DocuSign\eSign\Model\Recipients();
$recipients->setSigners(array($signer));
$envelop_definition = new DocuSign\eSign\Model\EnvelopeDefinition();
$envelop_definition->setEmailSubject("[DocuSign PHP SDK] - Please sign this doc");
// set envelope status to "sent" to immediately send the signature request
$envelop_definition->setStatus("sent");
$envelop_definition->setRecipients($recipients);
$envelop_definition->setDocuments(array($document));
// create and send the envelope! (aka signature request)
$envelop_summary = $envelopeApi->createEnvelope($accountId, $envelop_definition, null);
echo "<b>Envelope Details: </b><pre>".$envelop_summary ."</pre></br>";

/////////////////////////////////////////////////////////////////////////
// STEP 3:  Request Recipient View (aka signing URL)
/////////////////////////////////////////////////////////////////////////
// instantiate a RecipientViewRequest object
$recipient_view_request = new \DocuSign\eSign\Model\RecipientViewRequest();
// set where the recipient is re-directed once they are done signing
$recipient_view_request->setReturnUrl("https://www.docusign.com/develcenter");
// configure the embedded signer 
$recipient_view_request->setUserName($recipientName);
$recipient_view_request->setEmail($recipientEmail);
// must reference the same clientUserId that was set for the recipient when they 
// were added to the envelope in step 2
$recipient_view_request->setClientUserId($recipientId);
// used to indicate on the certificate of completion how the user authenticated
$recipient_view_request->setAuthenticationMethod("email");
// generate the recipient view! (aka embedded signing URL)
$signingView = $envelopeApi->createRecipientView($accountId, $envelop_summary->getEnvelopeId(), $recipient_view_request);
echo "</br> Signing URL = <a href='" . $signingView->getUrl() . "' target='_blank'>".$signingView->getUrl()."</a></br>";




//MEthod for embedded sending view
$return_url="https://www.docusign.com/devcenter";
$senderView = $envelopeApi->createSenderView($accountId, $envelopeId, 
$return_url);
var_dump($senderView->getUrl());

1 个答案:

答案 0 :(得分:1)

如果要将其他字段作为发件人放在文档上,则应使用Embedded Sending (or Sender View)

  

信封的嵌入式发送视图允许用户在发送信封之前编辑标签,文档,收件人和草稿信封的其他设置。与嵌入式签名类似,您的应用或网站可以使用重定向,Webview或iFrame生成发送网址并直接集成到您的工作流程中。

有关代码示例,请参阅here

问:如何在签署文件后获取该文件的网址,以便我以后查看。

请参阅此answer