我将值传递给salesforce api,并且只想显示在此响应的最后一行显示的验证错误。我已经尝试过如下代码但显示空白。
echo $json_response->{'message'};
echo $json_response['message'];
我得到的反应如下。我只想展示"" ErrorCode 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 :(得分: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);
}
?>