DocuSign-发送不限数量的PDF信封

时间:2019-11-28 13:20:51

标签: php docusignapi

使用https://github.com/docusign/eg-01-php-jwt

我已经成功实现了上述存储库,以发送PDF进行签名。

我试图实现的功能是能够发送任意数量的PDF进行签名,但是该示例仅允许3个文档。

有问题的部分如下:

$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' => 'Conditions of Sale',  # 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' => 'Invoice e'.$S_invoiceID.'',  # 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
]);
         echo $document3;
# The order in the docs array determines the order in the envelope
//$envelope_definition->setDocuments([$document1, $document2, $document3]);
$envelope_definition->setDocuments([$document2, $document3]);

我尝试了以下操作,但无济于事:

$InvoiceIDArray = ["9329","9328"];

foreach ($InvoiceIDArray as $InvoiceID)  {

    $content_bytes = file_get_contents($demo_docs_path . "e".$InvoiceID."_invoice.pdf");
    $doc3_b64 = base64_encode($content_bytes);

    $document[$InvoiceID] = new \DocuSign\eSign\Model\Document([  # create the DocuSign document object
        'document_base64' => $doc3_b64,
        'name' => 'Invoice e'.$InvoiceID.'',  # can be different from actual file name
        'file_extension' => 'pdf',  # many different document types are accepted
        'document_id' => ''.$InvoiceID.''  # a label used to reference the doc
    ]);

    $this->newDocs = $document[$InvoiceID];

}

# The order in the docs array determines the order in the envelope
$envelope_definition->setDocuments([$documentA,$this->newDocs]);    

例如,我想从数组中提取ID,然后发送具有匹配ID的PDF。

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您的循环正在用$this->newDocs = $document[$InvoiceID];覆盖自己。

未经测试:

$InvoiceIDArray = ["9329","9328"];
$this->newDocs = [];

foreach ($InvoiceIDArray as $InvoiceID)  {

    $content_bytes = file_get_contents($demo_docs_path . "e".$InvoiceID."_invoice.pdf");

    if (empty($content_bytes)) { continue; } # prevent adding empty contents

    $this->newDocs[] = new \DocuSign\eSign\Model\Document([  # create the DocuSign document object
        'document_base64' => base64_encode($content_bytes),
        'name' => 'Invoice e'.$InvoiceID,  # can be different from actual file name
        'file_extension' => 'pdf',  # many different document types are accepted
        'document_id' => $InvoiceID  # a label used to reference the doc
    ]);
}

# The order in the docs array determines the order in the envelope
$envelope_definition->setDocuments(array_merge([$documentA], $this->newDocs));

或更简单

$invoice_ids = [9329, 9328];
$documents = [$documentA];

foreach ($invoice_ids as $invoice_id)  {
    $content_bytes = @file_get_contents("{$demo_docs_path}e{$invoice_id}_invoice.pdf");

    if (empty($content_bytes)) { continue; }

    $documents[] = new \DocuSign\eSign\Model\Document([
        'document_base64' => base64_encode($content_bytes),
        'name' => "Invoice e{$invoice_id}",
        'file_extension' => 'pdf',
        'document_id' => $invoice_id
    ]);
}

$envelope_definition->setDocuments($documents);