我正在使用Converge API将资金从信用卡转移到系统中的商家帐户。
这是我正在使用的API URL: https://api.convergepay.com/VirtualMerchant/process.do
有时我遇到与API的连接问题,结果是出现黑屏或类似错误。
在进行CCSALE交易之前,是否可以检查API是否可用?这是我设置的简单代码,以尝试完成此任务。
$url = 'https://api.convergepay.com/VirtualMerchant/process.do';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$result = curl_exec($ch);
//$result will be false if the CURL request fails.
curl_close($ch);
答案 0 :(得分:0)
尝试获取错误信息,然后重定向用户。使用以下代码从CURL获取详细的响应
$url = 'https://api.convergepay.com/VirtualMerchant/process.do';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_VERBOSE, true);
//Tell cURL that it should only spend 10 seconds
//trying to connect to the URL.
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
//A given cURL operation should only take
//30 seconds max.
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
$httpCode = curl_getinfo($curl , CURLINFO_HTTP_CODE);
$response = curl_exec($curl);
if ($response === false)
$response = curl_error($curl);
echo stripslashes($response);
curl_close($curl);