我正在使用docusign API和PHP构建应用程序。除无法弄清楚如何下载文档外,我已经完成了大部分工作。我一直在该网站和Docusign网站上进行搜索。Docusign 在此处有一个示例,该示例显示了如何获取PHP中的文档列表,但下载没有PHP示例。在Docusign REST API文档中,他们在此处解释了该方法。但这表示响应为“ PDF文件”。
在下面的示例代码中,我尝试将内容放入文件中,但是会创建一个空文件。如果我print_r($ data),我得到这个:
SplFileObject Object
(
[pathName:SplFileInfo:private] => /tmp/419ULk
[fileName:SplFileInfo:private] => 419ULk
[openMode:SplFileObject:private] => w
[delimiter:SplFileObject:private] => ,
[enclosure:SplFileObject:private] => "
)
Run Code Online (Sandbox Code Playgroud)
它确实在/ tmp中创建了文件,但是我想将文档保留在字符串中,所以我将其发送或保存到DB。
这是我的控制器功能:
public function get_document($envelopeId, $cert = FALSE)
{
$save_dir = BASEPATH."../documents/";
if ($envelopeId) {
$this->load->model('docusign_model');
$data = $this->docusign_model->get_document($envelopeId, $cert);
}
file_put_contents($save_dir.$envelopeId.".pdf", $data);
//print_r($data);
die("116");
}
Run Code Online (Sandbox Code Playgroud)
这在docusign_model中:
public function get_document($envelopeId, $cert)
{
$docuSignAuth = $this->auth();
if ($docuSignAuth) {
$envelopeApi = new EnvelopesApi($docuSignAuth->apiClient);
$options = new GetDocumentOptions();
if($cert) {
$options->setCertificate(TRUE);
} else {
$options->setCertificate(FALSE);
}
return $envelopeApi->getDocument($docuSignAuth->accountId, 1, $envelopeId, $options);
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
如何获取此文档并将其保存在字符串中?
任何帮助都将不胜感激!
内容以文件形式返回,您必须阅读临时文件并将其保存到所需文件
使用file_get_contents和的快速摘要file_put_contents
$docStream = $envelopeApi->getDocument($accountId, 1, $envelopeId);
file_put_contents("my_document.pdf", file_get_contents($docStream->getPathname()));
Run Code Online (Sandbox Code Playgroud)
更多信息DocuSign REST API :: EnvelopeDocuments:在“ 获取单个文档作为PDF文件”下