douzai1074 2013-05-09 00:55
浏览 80
已采纳

PHP,CURL。 curl_exec返回什么?

I'm trying to set an API with a payment processor. Below is the code they provided me. There are some information in the $result variable that I want, what I don't understand is what type of variable is '$result' and how can I take certain data from it. printing the $result shows "Transaction ID is : xxxx status is ACCEPTED". What I basicly want is to take only the transaction ID and store it in a variable.

foreach($_POST as $k=>$v) $$k=urldecode($v); 
$urladdress = "https://example.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, 1); 
curl_setopt($ch, 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);

Thank you for your help

  • 写回答

1条回答 默认 最新

  • drecy22400 2013-05-09 00:57
    关注

    From the 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.

    Your code already contains this line (which is good):

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    

    The 1 means you will receive an explanatory result back from $result = curl_exec ($ch) instead of just true or false.

    Your error checking code could therefore look like:

    $result = curl_exec ($ch);
    if($result === FALSE) {
        die(curl_error($ch));
    }
    

    You can also check they type of variable returned via var_dump: var_dump($result).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP