2015-09-04 48 views
0

嘗試使用示例PHP代碼Requesting a signature via a template設置Docusign。我有我的所有賬戶的細節設置正確,並嘗試添加行:Docusign API調用錯誤PHP

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,false); 

,但我仍然不斷收到錯誤:

帳戶ID = XXXXXXX的baseUrl = https://demo.docusign.net/restapi/v2/accounts/1135802錯誤調用webservice的,狀態是:0錯誤文本是 - >

我也打開了防火牆,以防止任何錯誤有

任何想法的錯誤意味着

Docusign的代碼是:

<?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"; 
+0

您使用了什麼「提供的代碼」?請包括一個鏈接或將更多的sw放入問題中。 –

+0

這是Docusign給出的PHP代碼 – andyc209

+0

我已經在使用WAMP的Window 7系統上確認了問題。這個例子在Linux系統上正常工作(我剛測試過)。我正在繼續調查...... –

回答

1

是您的問題,您沒有安裝受信任的CA證書?

如何檢查

添加到示例代碼:

$curl = curl_init($url); 
curl_setopt($curl, CURLOPT_VERBOSE, true); #### Added 
curl_setopt($curl, CURLOPT_HEADER, false); 

,看看你會得到什麼。

在我的情況下,(在Windows上運行WAMP),詳細輸出包括:

SSL certificate problem: unable to get local issuer certificate

對此的解決辦法是安裝在本地受信任的證書。另一種方法是關閉證書檢查,非常不推薦!

安裝可信證書

  1. Download the certificates from the Curl website。本地存儲的文件,在同一目錄作爲您例如PHP軟件cacert.pem

  2. 添加以下兩個選項到這兩個捲曲操作:

搜索$捲曲= curl_init($ URL);並添加代碼的每個實例之後:

curl_setopt($curl, CURLOPT_CAINFO, "cacert.pem"); 
curl_setopt($curl, CURLOPT_CAPATH, "."); 

在PHP層

更妙的是,以解決您的PHP安裝安裝信任的CA列表,作爲一個整體,通過配置它使用CACERT。 pem默認。

+1

特別是在WAMP中,你將不得不將它添加到配置中。 文件: C:\瓦帕\ BIN \ PHP中\ PHPX \ php.ini中 添加以下內容: [捲曲] curl.cainfo = 「C:/wamp/cert/cacert.pem」 – Andrew