2016-03-02 16 views
0

我將值傳遞給salesforce api,並且只想顯示驗證錯誤,該錯誤顯示在此響應的最後一行中。我已經嘗試了下面的代碼,但它顯示空白。我怎麼能只顯示所有這個響應的驗證錯誤?

echo $json_response->{'message'}; 
echo $json_response['message']; 

我得到的回覆如下。我想只顯示 「」 錯誤代碼001,驗證錯誤:無效的PAN

HTTP/1.1 200 OK Date: Wed, 02 Mar 2016 06:45:08 GMT Set-Cookie: BrowserId=2fIw353WRuq31pLHIKvYEA;Path=/;Domain=.salesforce.com;Expires=Sun, 01-May-2016 06:45:08 GMT Expires: Thu, 01 Jan 1970 00:00:00 GMT Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked " message - ErrorCode 001,validation error : Invalid PAN" 

我的代碼如下

<?php session_start(); 
$json=$_SESSION['json']; 
$details=json_decode($json); 
//var_dump($details); 
$name='LoanCreationService'; 
$instance_url='https://cs31.salesforce.com/services/apexrest/CreateLoan/'; 
$access_token = $details->{'access_token'}; 
create_account($name, $instance_url, $access_token); 
//echo $message->{'message'}; 
function create_account($name, $instance_url, $access_token) { 
    $url = $instance_url; 
    //$content = json_encode(array("Name" => $name)); 
    $content=$_SESSION['content'];; 
    //echo $content; 
    $curl = curl_init($url); 
    curl_setopt($curl, CURLOPT_HEADER, true); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, 
      array("Authorization: OAuth $access_token", 
       "Content-type: application/json")); 
    curl_setopt($curl, CURLOPT_POST, true); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $content); 

    $json_response = curl_exec($curl); 
    //echo $json_response; 
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 


    if ($output === false || $status != 200) { 
     $output = "No cURL data returned for $url [". $status . "]"; 
     if (curl_error($curl)) 
     $output .= "\n". curl_error($curl); 
     } 

    //echo "HTTP status $status creating account<br/><br/>"; 
    echo $json_response; 

    curl_close($curl); 

    $response = json_decode($json_response, true); 

    echo $id = $response["id"]; 

    return $id; 
} 
?> 
+0

響應身體似乎並不JSON .. –

回答

0
<?php 
$str='Error: call to URL https://cs31.salesforce.com/services/apexrest/CreateLoan/ failed with status 200, response HTTP/1.1 200 OK Date: Tue, 01 Mar 2016 12:29:37 GMT Set-Cookie: BrowserId=uWnPGUbLTo6CEe_X-k8ttA;Path=/;Domain=.salesforce.com;Expires=Sat, 30-Apr-2016 12:29:37 GMT Expires: Thu, 01 Jan 1970 00:00:00 GMT Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked "success: Loan Application Number - 804326964", curl_error , curl_errno 0'; 
$del="Loan Application Number"; 
$pos=(string)strpos($str, $del); 
if($pos==NULL){ 
    //echo $important=substr($str, $pos+strlen($del)+3, 9); 
    echo "You have some error"; 
    } 

else{ 
    echo $important=substr($str, $pos+strlen($del)+3, 9); 
    } 
?>