Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Curl响应无法解码_Php_Json_Curl - Fatal编程技术网

Php Curl响应无法解码

Php Curl响应无法解码,php,json,curl,Php,Json,Curl,不确定为什么我的响应返回字符串而不是JSON。我正在测试服务器上没有编写器的authorize.net集成过程。有人能帮我吗 $API_LOGIN_ID = 'xxxxxxxxxxxxxxx'; $API_TRANSACTION_KEY = 'xxxxxxxxxxxxxxx'; $secure_headers = 'xxxxxxxxxxxxxxx'; $merchantAuthentication = array( 'name' => $API_LOGIN_ID,

不确定为什么我的响应返回字符串而不是JSON。我正在测试服务器上没有编写器的authorize.net集成过程。有人能帮我吗

$API_LOGIN_ID = 'xxxxxxxxxxxxxxx';
$API_TRANSACTION_KEY = 'xxxxxxxxxxxxxxx';
$secure_headers = 'xxxxxxxxxxxxxxx';




$merchantAuthentication = array(
    'name' => $API_LOGIN_ID,
    'transactionKey' => $API_TRANSACTION_KEY
);



$billTo = array(
    'firstName'=>$firstName,
    'lastName'=>$lastName,
    'company'=>$company,
    'address'=>$address,
    'city'=>$city,
    'state'=>$state,
    'zip'=>$zip,
    'country'=>'USA'
);
$amount = '123.99';
$customer = array('email'=>'ferdieserrano@yahoo.com');
$transactionRequest = array(
    'transactionType' => 'authCaptureTransaction',
    'amount'=> $amount,
    'customer'=>$customer, 
    'billTo'=>$billTo
);




$hostedPaymentBillingAddressValue = '{"show": true, "required":true}';

$hostedPaymentBillingAddressOptions = array(
    'settingName'=>'hostedPaymentBillingAddressOptions',
    'settingValue'=> $hostedPaymentBillingAddressValue
);

$hostedPaymentButtonValue = '{"text" : "Pay Now"}';

$hostedPaymentButtonOptions = array(
    'settingName'=>'hostedPaymentButtonOptions',
    'settingValue'=> $hostedPaymentButtonValue
);

$hostedPaymentCustomerValue = '{"showEmail":true, "requiredEmail":true}';

$hostedPaymentCustomerOptions = array(
    'settingName'=>'hostedPaymentCustomerOptions',
    'settingValue'=> $hostedPaymentCustomerValue
);
$hostedPaymentPaymentValue = '{"cardCodeRequired" : true}';

$hostedPaymentPaymentOptions = array(
    'settingName'=>'hostedPaymentPaymentOptions',
    'settingValue'=> $hostedPaymentPaymentValue
);

$hostedPaymentReturnOptionsValue = '{"url":"https://www.example.com/continue","urlText":"Continue","cancelUrl":"https://example.com/cancel","cancelUrlText":"Cancel"}';
$hostedPaymentReturnOptions = array(
    'settingName'=>'hostedPaymentReturnOptions',
    'settingValue'=> $hostedPaymentReturnOptionsValue
);

$hostedPaymentSecurityOptionsValue = '{"captcha" : true}';
$hostedPaymentSecurityOptions = array(
    'settingName'=>'hostedPaymentSecurityOptions',
    'settingValue'=> $hostedPaymentSecurityOptionsValue
);


$setting = array($hostedPaymentBillingAddressOptions, $hostedPaymentButtonOptions, $hostedPaymentCustomerOptions, $hostedPaymentPaymentOptions, $hostedPaymentReturnOptions, $hostedPaymentSecurityOptions);
$hostedPaymentSettings = array('setting'=>$setting);
$getHostedPaymentPageRequest = array(
    'merchantAuthentication' => $merchantAuthentication,
    'transactionRequest' =>$transactionRequest,
    'hostedPaymentSettings' =>$hostedPaymentSettings
);
$options = array('getHostedPaymentPageRequest'=>$getHostedPaymentPageRequest);


$url = "https://apitest.authorize.net/xml/v1/request.api";

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($options));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Accept: application/json'
    )
); 




$result = curl_exec($ch);
curl_close($ch);
print '<pre>';
print_r(json_decode($result));
print '</pre>';
var_dump($result);
$API_LOGIN_ID='xxxxxxxxxxxxx';
$API_交易_密钥='XXXXXXXXXXXXX';
$secure_headers='xxxxxxxxxxxxx';
$merchantAuthentication=数组(
'name'=>$API\u登录\u ID,
“transactionKey”=>$API\u事务\u密钥
);
$billTo=数组(
“firstName”=>$firstName,
“lastName”=>$lastName,
“公司”=>$company,
“地址”=>$address,
“城市”=>$city,
'state'=>$state,
“zip”=>$zip,
“国家”=>“美国”
);
$amount='123.99';
$customer=array('email'=>'ferdieserrano@yahoo.com');
$transactionRequest=数组(
'transactionType'=>'AuthCaptureTransation',
“金额”=>美元金额,
“客户”=>$customer,
“billTo”=>$billTo
);
$hostedPaymentBillingAddressValue='{“show”:true,“required”:true}';
$hostedPaymentBillingAddressOptions=数组(
'settingName'=>'hostedPaymentBillingAddressOptions',
“settingValue”=>$hostedPaymentBillingAddressValue
);
$hostedPaymentButtonValue='{“文本”:“立即付款”}';
$hostedPaymentButtonOptions=数组(
'settingName'=>'hostedPaymentButtonOptions',
“设置值”=>$hostedPaymentButtonValue
);
$hostedPaymentCustomerValue='{“showEmail”:true,“requiredEmail”:true}';
$hostedPaymentCustomerOptions=数组(
'settingName'=>'hostedPaymentCustomerOptions',
“settingValue”=>$hostedPaymentCustomerValue
);
$hostedPaymentPaymentValue='{“cardCodeRequired”:true}';
$hostedPaymentPaymentOptions=数组(
'settingName'=>'hostedPaymentPaymentOptions',
“settingValue”=>$hostedPaymentPaymentValue
);
$HostedPaymentReturnOptions值=“{”url:”https://www.example.com/continue,“URL文本”:“继续”,“取消URL”:https://example.com/cancel“,“cancelUrlText”:“Cancel”}”;
$hostedPaymentReturnOptions=数组(
'settingName'=>'hostedPaymentReturnOptions',
“设置值”=>$HostedPaymentReturnOptions值
);
$hostedPaymentSecurityOptionsValue='{“验证码”:true}';
$hostedPaymentSecurityOptions=数组(
'settingName'=>'hostedPaymentSecurityOptions',
“settingValue”=>$HostedPaymentSecurityOptions值
);
$setting=数组($hostedPaymentBillingAddressOptions、$hostedPaymentButtonOptions、$hostedPaymentCustomerOptions、$HostedPaymentPaymentPaymentOptions、$hostedPaymentReturnOptions、$hostedPaymentSecurityOptions);
$hostedPaymentSettings=array('setting'=>$setting);
$getHostedPaymentPageRequest=数组(
'merchantAuthentication'=>$merchantAuthentication,
“transactionRequest”=>$transactionRequest,
'hostedPaymentSettings'=>$hostedPaymentSettings
);
$options=数组('getHostedPaymentPageRequest'=>$getHostedPaymentPageRequest);
$url=”https://apitest.authorize.net/xml/v1/request.api";
$ch=curl_init();
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($ch,CURLOPT_VERBOSE,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($options));
curl_setopt($ch,CURLOPT_HTTPHEADER,数组(
'内容类型:application/json',
'接受:应用程序/json'
)
); 
$result=curl\u exec($ch);
卷曲关闭($ch);
打印“”;
打印(json解码($result));
打印“”;
var_dump($结果);
我已经玩了一段时间,但我没有得到JSON。提前感谢

替换这些行:

$options = json_encode($options);
curl_setopt($ch, CURLOPT_POSTFIELDS, $options);
curl_setopt($ch, CURLOPT_HTTPHEADER, array (
        'Content-Type: application/json',
        'Content-Length: ' . strlen($options)
    )
); 
与:


更新:- 嗯,在检查了你的代码之后

我得到了一个错误,在它自身的响应中,返回了一个

这意味着你需要移除这个

我有一个很好的方法从你的字符串中删除BOM

function removeBOM($data) {
    if (0 === strpos(bin2hex($data), 'efbbbf')) {
       return substr($data, 3);
    }
}

$result = curl_exec($ch);
curl_close($ch);
$result = json_decode(removeBOM($result));
print '<pre>';
print_r($result);
print '</pre>';
因此,您的最终代码可能如下所示:

$result = json_decode(removeBOM($result), true);
函数删除BOM($data){
如果(0==strpos(bin2hex($data),'efbbbf')){
返回substr($data,3);
}
}
$result=curl\u exec($ch);
卷曲关闭($ch);
$result=json_解码(removeBOM($result));
打印“”;
打印(结果);
打印“”;
替换这些行:

$options = json_encode($options);
curl_setopt($ch, CURLOPT_POSTFIELDS, $options);
curl_setopt($ch, CURLOPT_HTTPHEADER, array (
        'Content-Type: application/json',
        'Content-Length: ' . strlen($options)
    )
); 
与:


更新:- 嗯,在检查了你的代码之后

我得到了一个错误,在它自身的响应中,返回了一个

这意味着你需要移除这个

我有一个很好的方法从你的字符串中删除BOM

function removeBOM($data) {
    if (0 === strpos(bin2hex($data), 'efbbbf')) {
       return substr($data, 3);
    }
}

$result = curl_exec($ch);
curl_close($ch);
$result = json_decode(removeBOM($result));
print '<pre>';
print_r($result);
print '</pre>';
因此,您的最终代码可能如下所示:

$result = json_decode(removeBOM($result), true);
函数删除BOM($data){
如果(0==strpos(bin2hex($data),'efbbbf')){
返回substr($data,3);
}
}
$result=curl\u exec($ch);
卷曲关闭($ch);
$result=json_解码(removeBOM($result));
打印“”;
打印(结果);
打印“”;

感谢您的代码添加了一小部分:


再次感谢

谢谢,您的代码只添加了一小部分:


再次感谢

反应在哪里?反应在哪里?嗨,我也有同样的结果。它仍然是一个字符串。返回的字符串是什么?只有var_dump()返回字符串。太长,无法粘贴到此处。对不起,这是我第一次。不,不是。这快把我逼疯了。如果我复制粘贴它,我可以解码它,但是$response本身无法解码。嗨,我得到了相同的结果。它仍然是一个字符串。返回的字符串是什么?只有var_dump()返回字符串。太长,无法粘贴到此处。对不起,这是我第一次。不,不是。这快把我逼疯了。如果我复制粘贴它,我可以解码它,但$response本身无法解码。