有没有办法将curl命令转换成php curl
我是一名服务器管理员,对PHP一无所知 有人能帮我把下面的curl命令转换成php curl吗有没有办法将curl命令转换成php curl,php,json,api,curl,Php,Json,Api,Curl,我是一名服务器管理员,对PHP一无所知 有人能帮我把下面的curl命令转换成php curl吗 curl -H "Content-Type: application/json" -X POST -d '{"SystemsTraceAuditNumber":"455690","RetrievalReferenceNumber":"405060908072","AcquiringBin":"409999","AcquirerCountryCode":"101","PrimaryAccountNumb
curl -H "Content-Type: application/json" -X POST -d '{"SystemsTraceAuditNumber":"455690","RetrievalReferenceNumber":"405060908072","AcquiringBin":"409999","AcquirerCountryCode":"101","PrimaryAccountNumber":"4895070000008881"}'
-v --ciphers RC4-SHA:RC4-MD5 https://sandbox.visa.com/rsrv_vpp/v1/acnl -u 72cdcdd2-9ccd-4adc-8827-0324324523423414a:f42342317-b62340-42343e-8234-e2342342341357b0
--cacert ./SMCAroot.crt --cert /home/sourcecode/sandbox_cert.pem -k
我尝试过转换代码,但把一切都搞糟了,我得到了http 500响应,使用php
但是当我在linux shell上执行curl命令时,它工作得很好
下面是我用php转换的代码
<?php
$data = array(
'SystemsTraceAuditNumber' => '455690',
'RetrievalReferenceNumber' => '405060908072',
'AcquiringBin' => '409999',
'AcquirerCountryCode' => '101',
'PrimaryAccountNumber' => '4895070000008881',
);
//echo $data;
$data_string = json_encode($data);
$handle=curl_init('https://sandbox.visa.com/rsrv_vpp/v1/acnl');
curl_setopt($handle, CURLOPT_VERBOSE, true);
curl_setopt($handle, CURLOPT_SSL_CIPHER_LIST, 'RC4-SHA:RC4-MD5');
curl_setopt($handle, CURLOPT_USERPWD, 'xxxxxxxxx:xxxxxxxxxxxxxxxxxxx');
curl_setopt($handle, CURLOPT_SSLCERT, 'sandbox_cert.pem');
curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($handle, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json')
);
$handle;
$content = curl_exec($handle);
if(!curl_errno($handle))
{
$info = curl_getinfo($handle);
echo "<pre>";
print_r($info);
echo "</pre>";
//echo '<br/> Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
}
else
{
'Curl error: ' . curl_error($handle);
}
$content;
?>
这样设置可能更容易: 选项
curl\u setopt($handle,CURLOPT\u SSLCERT,'sandbox\u cert.pem')代码>应该有相同的路径,我相信:/home/sourcecode/sandbox\u cert.pem
,所以它的内容是:`curl\u setopt($handle,CURLOPT\u SSLCERT,'/home/sourcecode/sandbox\u cert.pem');
$defaults = array(
CURLOPT_VERBOSE => 1,
CURLOPT_SSL_CIPHER_LIST => 'RC4-SHA:RC4-MD5',
CURLOPT_USERPWD => 'xxxxxxxxx:xxxxxxxxxxxxxxxxxxx',
CURLOPT_SSLCERT => '/home/sourcecode/sandbox_cert.pem',
CURLOPT_URL => 'https://sandbox.visa.com/rsrv_vpp/v1/acnl',
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_POST => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => array('Content-Type: application/json')
);
$handle = curl_init();
curl_setopt_array($handle, ($options + $defaults));
if( ! $content = curl_exec($handle)){
trigger_error(curl_error($handle));
}
curl_close($ch);
echo $content;