docusign嵌入式签名中的两个签名者问题一个接一个

时间:2019-07-27 02:47:26

标签: docusignapi

我正在尝试让2个用户使用docusign嵌入式符号签名。我正在使用Docusign / github给出的示例代码。我想要第二个用户,看到第一个用户已经对文档进行了签名,因此,根据此处的一些解释,当第一个签名者对文档进行签名时,我尝试获取信封ID,但是我得到了一个错误。似乎第二个收件人有问题。有人会帮助吗?

$username_docusign=$config['username_docusign'];
$password_docusign=$config['password_docusign'];
$integrator_key_docusign=$config['integrator_key_docusign'];
$host_docusign=$config['host_docusign'];
// create a new DocuSign configuration and assign host and header(s)
$config = new DocuSign\eSign\Configuration();
$config->setSSLVerification(false);
$config->setHost($host_docusign);
$config->addDefaultHeader("X-DocuSign-Authentication", "{\"Username\":\"" . $username_docusign . "\",\"Password\":\"" . $password_docusign . "\",\"IntegratorKey\":\"" . $integrator_key_docusign . "\"}");
/////////////////////////////////////////////////////////////////////////
// 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 "Account ID = $accountId\n";
    }
}
}
/////////////////////////////////////////////////////////////////////////
// STEP 2:  Create & Send Envelope with Embedded Recipient
/////////////////////////////////////////////////////////////////////////
// set recipient information
$recipientName = "user1";
$recipientEmail = "sanjaydas2390@gmail.com";
// configure the document we want signed



$recipientName2 = "user2";
$recipientEmail2 = "dassanjay5313@gmail.com";

$documentFileName = "hhhh.pdf";
$documentName = "hhhh.pdf";

$demo_docs_path      = __DIR__ . '/demo_documents/';


// 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($demo_docs_path . 'World_Wide_Corp_fields.pdf')));
$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->setAnchorString("Sign here user1");//here my text in html
$signHere->setAnchorXOffset("3");
$signHere->setAnchorYOffset("0");
$signHere->setAnchorUnits("inches");
$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('12345');

$signHere2 = new \DocuSign\eSign\Model\SignHere();

$signHere2->setAnchorString("Sign here user2");//here my text in html
$signHere2->setAnchorXOffset("3");
$signHere2->setAnchorYOffset("0");
$signHere2->setAnchorUnits("inches");
$signHere2->setPageNumber("1");
$signHere2->setRecipientId("2");
// add the signature tab to the envelope's list of tabs
$tabs2 = new DocuSign\eSign\Model\Tabs();
$tabs2->setSignHereTabs(array($signHere2));
// add a signer to the envelope
$signer2 = new \DocuSign\eSign\Model\Signer();
$signer2->setEmail($recipientEmail2);
$signer2->setName($recipientName2);
$signer2->setRecipientId("2");
$signer2->setTabs($tabs2);
$signer2->setClientUserId('123456');





// must set this to embed the recipient!
// Add a recipient to sign the document
$recipients = new DocuSign\eSign\Model\Recipients();
$recipients->setSigners(array($signer),array($signer2) );
$envelop_definition = new DocuSign\eSign\Model\EnvelopeDefinition();
$envelop_definition->setEmailSubject("oggetto mail");
// 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);

/////////////////////////////////////////////////////////////////////////
// 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("http://localhost/docusign/index.php?enevelope=".$envelop_summary->getEnvelopeId());
// configure the embedded signer 
if ($_GET['enevelope']=="") {

$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('12345');
// 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);
$signurl= $signingView->getUrl();

} else {


$recipient_view_request1 = new \DocuSign\eSign\Model\RecipientViewRequest();
// set where the recipient is re-directed once they are done signing
$recipient_view_request1->setReturnUrl("http://localhost/docusign/index.php?enevelope=100");

 $recipient_view_request1->setUserName($recipientName2);
$recipient_view_request1->setEmail($recipientEmail2);
// must reference the same clientUserId that was set for the recipient when they 
// were added to the envelope in step 2
$recipient_view_request1->setClientUserId('123456');
// used to indicate on the certificate of completion how the user authenticated
$recipient_view_request1->setAuthenticationMethod("email");
// generate the recipient view! (aka embedded signing URL)

$signingView = $envelopeApi->createRecipientView($accountId, $_GET['enevelope'], $recipient_view_request1);
$signurl= $signingView->getUrl();

}
header('Location: '.$signurl);

2 个答案:

答案 0 :(得分:0)

首先,不确定您使用的是什么示例代码,但是您在此处粘贴的此代码使用的是旧/旧式身份验证。我强烈建议您使用我们的现代/新版oauth。您可以在此页面-https://developers.docusign.com/esign-rest-api/code-examples中找到有关示例。 就让两个收件人顺序签名而言,您必须使用我们所谓的“路由顺序”。如果您在收件人上指定routingOrder参数,DocuSign将基于该数字(从低到高)路由信封。因此,如果您的第一个收件人是“ 1”,第二个收件人是“ 2”,则第二个收件人只有在第一个收件人签名后才能看到信封。

答案 1 :(得分:0)

    /**
     * Creates envelope definition
     * Document 1: An HTML document.
     * Document 2: A Word .docx document.
     * Document 3: A PDF document.
     * DocuSign will convert all of the documents to the PDF format.
     * The recipients' field tags are placed using <b>anchor</b> strings.
     * @param $args parameters for the envelope:
     *              signer_email, signer_name, signer_client_id
     * @return mixed -- returns an envelope definition
     */
    private function make_envelope($args)
    {
        # document 1 (html) has sign here anchor tag **signature_1**
        # document 2 (docx) has sign here anchor tag /sn1/
        # document 3 (pdf)  has sign here anchor tag /sn1/
        #
        # The envelope has two recipients.
        # recipient 1 - signer
        # recipient 2 - cc
        # The envelope will be sent first to the signer.
        # After it is signed, a copy is sent to the cc person.
        #
        # create the envelope definition
        $envelope_definition = new \DocuSign\eSign\Model\EnvelopeDefinition([
           'email_subject' => 'Please sign this document set'
        ]);
        $doc1_b64 = base64_encode($this->create_document1($args));
        # read files 2 and 3 from a local directory
        # The reads could raise an exception if the file is not available!
        $demo_docs_path = __DIR__ . '/../public/demo_documents/';
        $content_bytes = file_get_contents($demo_docs_path . $GLOBALS['DS_CONFIG']['doc_docx']);
        $doc2_b64 = base64_encode($content_bytes);
        $content_bytes = file_get_contents($demo_docs_path . $GLOBALS['DS_CONFIG']['doc_pdf']);
        $doc3_b64 = base64_encode($content_bytes);
        # Create the document models
        $document1 = new \DocuSign\eSign\Model\Document([  # create the DocuSign document object
            'document_base64' => $doc1_b64,
            'name' => 'Order acknowledgement',  # can be different from actual file name
            'file_extension' => 'html',  # many different document types are accepted
            'document_id' => '1'  # a label used to reference the doc
        ]);
        $document2 = new \DocuSign\eSign\Model\Document([  # create the DocuSign document object
            'document_base64' => $doc2_b64,
            'name' => 'Battle Plan',  # can be different from actual file name
            'file_extension' => 'docx',  # many different document types are accepted
            'document_id' => '2'  # a label used to reference the doc
        ]);
        $document3 = new \DocuSign\eSign\Model\Document([  # create the DocuSign document object
            'document_base64' => $doc3_b64,
            'name' => 'Lorem Ipsum',  # can be different from actual file name
            'file_extension' => 'pdf',  # many different document types are accepted
            'document_id' => '3'  # a label used to reference the doc
        ]);
        # The order in the docs array determines the order in the envelope
        $envelope_definition->setDocuments([$document1, $document2, $document3]);
        # Create the signer recipient model
        $signer1 = new \DocuSign\eSign\Model\Signer([
            'email' => $args['signer_email'], 'name' => $args['signer_name'],
            'recipient_id' => "1", 'routing_order' => "1"]);
        # routingOrder (lower means earlier) determines the order of deliveries
        # to the recipients. Parallel routing order is supported by using the
        # same integer as the order for two or more recipients.
        # create a cc recipient to receive a copy of the documents
        $cc1 = new \DocuSign\eSign\Model\CarbonCopy([
            'email' => $args['cc_email'], 'name' => $args['cc_name'],
            'recipient_id' => "2", 'routing_order' => "2"]);
        # Create signHere fields (also known as tabs) on the documents,
        # We're using anchor (autoPlace) positioning
        #
        # The DocuSign platform searches throughout your envelope's
        # documents for matching anchor strings. So the
        # signHere2 tab will be used in both document 2 and 3 since they
        #  use the same anchor string for their "signer 1" tabs.
        $sign_here1 = new \DocuSign\eSign\Model\SignHere([
            'anchor_string' => '**signature_1**', 'anchor_units' => 'pixels',
            'anchor_y_offset' => '10', 'anchor_x_offset' => '20']);
        $sign_here2 = new \DocuSign\eSign\Model\SignHere([
            'anchor_string' => '/sn1/', 'anchor_units' =>  'pixels',
            'anchor_y_offset' => '10', 'anchor_x_offset' => '20']);
        # Add the tabs model (including the sign_here tabs) to the signer
        # The Tabs object wants arrays of the different field/tab types
        $signer1->setTabs(new \DocuSign\eSign\Model\Tabs([
            'sign_here_tabs' => [$sign_here1, $sign_here2]]));
        # Add the recipients to the envelope object
        $recipients = new \DocuSign\eSign\Model\Recipients([
            'signers' => [$signer1], 'carbon_copies' => [$cc1]]);
        $envelope_definition->setRecipients($recipients);
        # Request that the envelope be sent by setting |status| to "sent".
        # To request that the envelope be created as a draft, set to "created"
        $envelope_definition->setStatus($args["status"]);
        return $envelope_definition;
    }
    /**
     * Creates a customized html document for the envelope
     * @param args $
     * @return string -- the html document
     */
    private function create_document1($args)
    {
        return <<< heredoc
    <!DOCTYPE html>
    <html>
        <head>
          <meta charset="UTF-8">
        </head>
        <body style="font-family:sans-serif;margin-left:2em;">
        <h1 style="font-family: 'Trebuchet MS', Helvetica, sans-serif;
color: darkblue;margin-bottom: 0;">World Wide Corp</h1>
        <h2 style="font-family: 'Trebuchet MS', Helvetica, sans-serif;
margin-top: 0px;margin-bottom: 3.5em;font-size: 1em;
color: darkblue;">Order Processing Division</h2>
        <h4>Ordered by {$args['signer_name']}</h4>
        <p style="margin-top:0em; margin-bottom:0em;">Email: {$args['signer_email']}</p>
        <p style="margin-top:0em; margin-bottom:0em;">Copy to: {$args['cc_name']}, {$args['cc_email']}</p>
        <p style="margin-top:3em;">
  Candy bonbon pastry jujubes lollipop wafer biscuit biscuit. Topping brownie sesame snaps sweet roll pie. Croissant danish biscuit soufflé caramels jujubes jelly. Dragée danish caramels lemon drops dragée. Gummi bears cupcake biscuit tiramisu sugar plum pastry. Dragée gummies applicake pudding liquorice. Donut jujubes oat cake jelly-o. Dessert bear claw chocolate cake gummies lollipop sugar plum ice cream gummies cheesecake.
        </p>
        <!-- Note the anchor tag for the signature field is in white. -->
        <h3 style="margin-top:3em;">Agreed: <span style="color:white;">**signature_1**/</span></h3>
        </body>
    </html>
heredoc;
    }
相关问题