我正在尝试使用付款处理器设置一个API.以下是他们提供的代码. $result变量中有一些信息,我不明白是什么类型的变量是’$result’,如何从它获取某些数据.打印$结果显示“事务ID为:xxxx状态为ACCEPTED”.我基本想要的只是使用事务ID并将其存储在一个变量中.
foreach($_POST as $k=>$v) $$k=urldecode($v); $urladdress = "https://solidtrustpay.com/accapi/process.PHP"; $api_id = "dddd"; $api_pwd = "yyyyy"; $api_pwd = md5($api_pwd.'s+E_a*'); $data = "user=".$user. "&testmode=".$testmode."&api_id=".$api_id. "&api_pwd=".$api_pwd."&amount=".$amount."&paycurrency=".$currency."&comments=".$comments."&fee=".$fee."&udf1=".$udf1; // Call STP API $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,"$urladdress"); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,$data); curl_setopt($ch,CURLOPT_RETURNTRANSFER,CURLOPT_HEADER,0); //use this to suppress output curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);// tell cURL to gracIoUsly accept an SSL certificate $result = curl_exec ($ch) or die(curl_error($ch)); echo $result; echo curl_error($ch); curl_close ($ch);
感谢您的帮助
从
manual:
Returns TRUE on success or FALSE on failure. However,if the CURLOPT_RETURNTRANSFER option is set,it will return the result on success,FALSE on failure.
由于您的代码实际上包含以下行:
curl_setopt($ch,1);
什么意思是CURLOPT_RETURNTRANSFER选项isset,它会返回一个字符串或错误的错误.您的错误检查代码应该如下所示:
$result = curl_exec ($ch); if($result === FALSE) { die(curl_error($ch)); }