下载带有curl的信封pdf

时间:2019-05-17 10:09:22

标签: docusignapi

我正在尝试下载一个卷曲的文件信封。我正在访问信封,但无法显示pdf。我看到一个带有符号的网页,无法保存信封的pdf。任何帮助表示赞赏。

require_once('rest/autoload.php');


$url = "https://demo.docusign.net/restapi/v2/login_information";
$header = "<DocuSignCredentials><Username>" . 
$config['username_docusign'] . "</Username><Password>" . 
$config['password_docusign'] . "</Password><IntegratorKey>" . 
$config['api_firmadoc'] . "</IntegratorKey></DocuSignCredentials>";



$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);



$curl = curl_init("https://demo.docusign.net/restapi/v2/accounts/1319127/envelopes/cc4aa62f-506c-4ee4-b6a3-dc9ae3e5fa14/documents/combined" );


curl_setopt($curl, CURLOPT_HTTPHEADER, array(                                                                          

'Content-Type: application/pdf',
'X-DocuSign-Authentication: { "Username":"****", "Password":"****", 
 "IntegratorKey":"*****" }' )                                                                       
 );
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);


echo $json_response;

我希望得到一个pdf文件,但是我收到了一个带符号的网页

1 个答案:

答案 0 :(得分:0)

  1. 您正在使用过时的旧式身份验证。更好的主意是使用OAuth。
  2. 您不是在设置php页面的Content-Type,而是在将您的请求的Content-Type设置为DocuSign。 (这也是错误的,您应该将Accept标头设置为application/pdf
  3. 要设置页面的内容类型,请在php脚本的顶部中添加以下内容:header("Content-type:application/pdf");请参见this SO answer

查看PHP JWTAuthorization Code Grant示例以获取更多信息。

感谢您与DocuSign集成!