美好的一天,我是通过 PHP curl 进行此文档签名API集成的新手,我想尝试这种集成。我从 http://iodocs.docusign.com/APIWalkthrough/requestSignatureFromDocument 复制了下面的代码,希望我可以轻松测试和理解集成的工作原理。但不幸的是,总是发生错误"调用网络服务时出错,状态为:0"。我已经尝试了其他解决方法,例如将标头格式从XML更改为JSON,但仍然显示错误。请帮忙。
// Input your info here:
$integratorKey = 'XXXX-9999X9XX-X999-9999-99X9-9X9999X9XX9X';
$email = 'name@domain.com';
$password = 'samplepassword';
$name = 'Sender Full Name';
// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 1 - Login (to retrieve 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"));
print_r(curl_getinfo($curl));
echo "<br/>";
$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 "naccountId = " . $accountId . "nbaseUrl = " . $baseUrl . "n";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 2 - Create an envelope with one recipient, one tab, and one document and send
/////////////////////////////////////////////////////////////////////////////////////////////////
$data = array (
"emailBlurb" => "This comes from PHP",
"emailSubject" => "API Signature Request",
"documents" => array(array( "documentId" => "1", "name" => "testDS.pdf")),
"recipients" => array( "signers" => array(
array( "email" => $email,
"name" => $name,
"recipientId" => "1",
"tabs" => array(
"signHereTabs" => array(
array(
"xPosition" => "100",
"yPosition" => "100",
"documentId" => "1",
"pageNumber" => "1"
)
)
)
)
)
),
"status" => "sent");
$data_string = json_encode($data);
$file_contents = file_get_contents("testDS.pdf");
$requestBody = "rn"
."rn"
."--myboundaryrn"
."Content-Type: application/jsonrn"
."Content-Disposition: form-datarn"
."rn"
."$data_stringrn"
."--myboundaryrn"
."Content-Type:application/pdfrn"
."Content-Disposition: file; filename=”testDS.pdf"; documentid=1 rn"
."rn"
."$file_contentsrn"
."--myboundary--rn"
."rn";
// *** append "/envelopes" to baseUrl and as signature request endpoint
$curl = curl_init($baseUrl . "/envelopes" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: multipart/form-data;boundary=myboundary',
'Content-Length: ' . strlen($requestBody),
"X-DocuSign-Authentication: $header" )
);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
echo "error calling webservice, status is:" . $status . "nerror text is --> ";
print_r($json_response); echo "n";
exit(-1);
}
$response = json_decode($json_response, true);
$envelopeId = $response["envelopeId"];
//--- display results
echo "Document is sent! Envelope ID = " . $envelopeId . "nn";
我的集成商密钥是否有可能无效? 如果是,我有什么方法可以检查我的集成商密钥是否有效?在创建我的集成器密钥时,我只是按照此链接中的过程进行操作 http://www.docusign.com/developer-center/quick-start/first-api-call
我马上看不出代码有什么问题。 每当根本没有返回任何状态时,通常是可能导致此问题的三种原因之一:
- 阻止您的请求通过的安全软件。
- 阻止您的请求通过的防火墙。
- 端口 443 因其他原因(2 或 3 除外)而关闭。
您是否有任何日志可以检查以查看您的请求是否在软件级别或硬件级别(如果您有硬件防火墙)被拦截? 我会从检查这样的事情开始。