dt1888
2017-03-09 17:37
浏览 42
已采纳

卷曲响应无法解码

Not sure why my response returns as string as opposed to JSON. I'm testing an authorize.net intgration procedurally without composer on a server. Can someone help me please?

$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);

I've been playing around for a while but I'm not getting JSON. Thank you in advance

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题