用户签名后,docusign下载文档

时间:2018-07-16 10:33:33

标签: php docusignapi

我正在使用docusign-rest-recipes github link在用户签名后下载DOC。

尝试此代码时遇到以下错误:

“ PARTNER_AUTHENTICATION_FAILED。找不到或禁用了指定的集成商密钥。未指定集成商密钥。”

我已经正确分配了所有值,但是仍然无法摆脱这个错误。任何帮助都可以申请

<?php
  // Input your info here:
$email = "***";         // your account email
$password = "***";      // your account password
$integratorKey = "***";     // your account integrator key, found on (Preferences -> API page)
// copy the envelopeId from an existing envelope in your account that you want
// to download documents from
$envelopeId = "***";
// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 1 - Login (retrieves baseUrl and accountId)
/////////////////////////////////////////////////////////////////////////////////////////////////
$url = "https://demo.docusign.net/restapi/v2/login_information";
$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);
//--- display results
echo "accountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 2 - Get document information
/////////////////////////////////////////////////////////////////////////////////////////////////                                                                                  
$curl = curl_init($baseUrl . "/envelopes/" . $envelopeId . "/documents" );
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);
curl_close($curl);
//--- display results
echo "Envelope has following document(s) information...\n";
print_r($response); echo "\n";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 3 - Download the envelope's documents
/////////////////////////////////////////////////////////////////////////////////////////////////
foreach( $response["envelopeDocuments"] as $document ) {
    $docUri = $document["uri"];

    $curl = curl_init($baseUrl . $docUri );
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);  
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(                                                                          
        "X-DocuSign-Authentication: $header" )                                                                       
    );

    $data = curl_exec($curl);
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    if ( $status != 200 ) {
        echo "error calling webservice, status is:" . $status;
        exit(-1);
    }
    file_put_contents($envelopeId . "-" . $document["name"], $data);
    curl_close($curl);

    //*** Documents should now be downloaded in the same folder as you ran this program
}
//--- display results
echo "Envelope document(s) have been downloaded, check your local directory.\n";

1 个答案:

答案 0 :(得分:0)

我再次重新生成了$integratorKey并赋予了必须保存图像的文件夹777权限。那个$integratorKey是个问题,创建一个新的就解决了这个问题。

注意:您还可以通过信封ID获取DOC的状态,因此,如果状态已完成,则可以下载DOC。