Docusign API调用错误PHP [英] Docusign API call errors PHP
问题描述
尝试使用示例PHP代码为通过模板请求签名来设置Docusign.我已经正确设置了所有帐户详细信息,并尝试添加以下行:
Trying to set up Docusign using the example PHP code for Requesting a signature via a template. I have all my account details set up correctly and have tried adding the lines:
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,false);
但是我仍然不断收到错误消息:
but i still keep getting errors :
accountId = xxxxxxx baseUrl = https://demo.docusign.net/restapi/v2/accounts/1135802 调用网络服务时发生错误,状态为:0,错误文本为->
accountId = xxxxxxx baseUrl = https://demo.docusign.net/restapi/v2/accounts/1135802 error calling webservice, status is:0 error text is -->
我还打开了防火墙,以防止在那里出现任何错误
I have also opened up the firewall to prevent any errors there
任何想法,错误是什么意思
Any ideas what the error means
Docusign的代码是:
the code from Docusign is:
<?php
// Input your info here:
$email = "#######"; // your account email (also where this signature request will be sent)
$password = "#######"; // your account password
$integratorKey = "########"; // your account integrator key, found on (Preferences -> API page)
$recipientName = "#####"; // provide a recipient (signer) name
$templateId = "#######"; // provide a valid templateId of a template in your account
$templateRoleName = "Owner"; // use same role name that exists on the template in the console
// 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"));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,false);
$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 and envelope using one template role (called "Signer1") and one recipient
/////////////////////////////////////////////////////////////////////////////////////////////////
$data = array("accountId" => $accountId,
"emailSubject" => "DocuSign API - Signature Request from Template",
"templateId" => $templateId,
"templateRoles" => array(
array( "email" => $email, "name" => $recipientName, "roleName" => $templateRoleName )),
"status" => "sent");
$data_string = json_encode($data);
$curl = curl_init($baseUrl . "/envelopes" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
"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 . "\n\n";
推荐答案
您的问题是您没有安装受信任的CA证书吗?
Is your problem that you don't have trusted CA certificates installed?
如何检查
添加到示例代码:
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_VERBOSE, true); #### Added
curl_setopt($curl, CURLOPT_HEADER, false);
看看你能得到什么.
就我而言(在Windows上使用WAMP运行),详细输出包括:
In my case, (running on Windows with WAMP), the verbose output included:
SSL证书问题:无法获取本地颁发者证书
此问题的解决方法是在本地安装受信任的证书.替代方法是关闭非常不推荐的证书检查!
The fix for this is to install the trusted certificates locally. The alternative is to turn off cert checking which extremely NOT recommended!!
安装受信任的证书
-
从Curl网站下载证书.将文件存储在本地,与cacert.pem示例PHP软件位于同一目录
Download the certificates from the Curl website. Store the file locally, in the same directory as your example php software as cacert.pem
在两个curl操作中添加以下两个选项:
Add the following two options to both of your curl operations:
搜索$ curl = curl_init($ url);并在每个实例之后添加代码:
Search for $curl = curl_init($url); and add the code after each instance:
curl_setopt($curl, CURLOPT_CAINFO, "cacert.pem");
curl_setopt($curl, CURLOPT_CAPATH, ".");
在PHP级别安装受信任的CA列表
更好的方法是通过将PHP配置为默认情况下使用cacert.pem来整体上修复您的PHP安装.
Even better is to fix your PHP installation, as a whole, by configuring it to use the cacert.pem by default.
这篇关于Docusign API调用错误PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!