douzhi1919 2014-07-07 13:01
浏览 8

如何从一个页面到另一个页面获得基于api和curl的输出数据?

How to get api output data like $transactionid, $status etc from one page to another page.i am getting all $_post data but not getting api output data.Below is sample code based on curl and api.So how to pass api output data to another page.

//sample php code

//this will collect data from form
$operator = $_POST['operator']; 
$servicenumber = $_POST['servicenumber'];
$amount = $_POST['amount'];
//end of data collection from form


//check whether user enter some data or not
if(empty($operator)){
echo"select operator";
exit;
}
if(empty($servicenumber)){  
echo"enter mobile number";
exit;
}
if(empty($amount)){
echo"enter amount";
exit;
}
//end of data input checking


//common settings
$myappkey = ""; //your api appkey
$mode = "1"; //set 1 for live recharge, set 0 for demo recharge
$myorderid = ""; // It is your website generated unique transaction id

//doing recharge now by hitting jolo api
$ch = curl_init();
$timeout = 160; // set to zero for no timeout
$myurl = "http://www.web.in/api/recharge_advance.php?       mode=$mode&key=$myappkey&operator=$operator&service=$servicenumber&amount=$amount&orderid=$    myorderid";
curl_setopt ($ch, CURLOPT_URL, $myurl);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
//echo"$file_contents";

//capture the response from  api
//splitting each data as single
$maindata = explode(",", $file_contents);

$transactionid = $maindata[0]; //it is jolo generated transaction id
$jolostatus = $maindata[1]; //it is status of recharge SUCCESS,PENDING OR FAILED
$operator= $maindata[2]; //operator code
$service= $maindata[3]; //mobile number or dth number
$amount= $maindata[4]; //amount
$mywebsiteid= $maindata[5]; //client website order id
$errorcode= $maindata[6]; // api error code when txn fails
$operatorid= $maindata[7]; //original operator transaction id

//cases
if($jolostatus=='SUCCESS'){
//YOUR REST QUERY HERE
} 
if($jolostatus=='PENDING'){
//YOUR REST QUERY HERE
}
if($jolostatus=='FAILED'){
//YOUR REST QUERY HERE
}

//TIME OUT CASE OR EMPY REPONSE
if(empty($status)){
//YOUR REST QUERY HERE
//consider as pending
}


//display the result to customer
echo"Transaction ID: $transactionid ";
echo"<br/>";
echo"Recharge Status: $status";
echo"<br/>";
echo"Operator: $operator";
echo"<br/>";
echo"Service Number: $service";
echo"<br/>";
echo"Amount: $amount";
echo"<br/>";
echo"Client order id: $myorderid";
echo"<br/>";
echo"Operator Txn ID: $operatorid";
echo"<br/>";
echo"Error No.: $errorcode";
echo"<br/>";

?>
  • 写回答

2条回答 默认 最新

  • dsndm82062 2014-07-07 13:16
    关注

    you can pass the main data array through the url

    header('Location: http://example.com/ex.php?arr=<?PHP echo serialize($arr); ?>');
    

    in the another page you get through

    <?PHP 
     $arr = unserialize($_GET["arr"]); 
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line