sess = $this->getSession(); } function getSession() { if($this->debug){echo "\nget session---------------------- get session \n";} $array = file("session.php", FILE_IGNORE_NEW_LINES); if(count($array)==3 && strlen($array[1])==36){ return $array[1]; }else{ $this->login(); $array = file("session.php", FILE_IGNORE_NEW_LINES); if(count($array)==3 && strlen($array[1])==36){ return $array[1]; }else{ return false; } } } function getpost_pre($url, $method, $data, $session_required){ if($this->debug){echo "\ngetpost_pre---------------------- getpost_pre\n";} $x = $this->getpost($url, $method, $data, $session_required); if($x !=""){ return $x; } if($this->debug){echo "\ngetpost_pre----------- EMPTY RES 1 \n";} $this->login(); $x = $this->getpost($url, $method, $data, $session_required); if($x !=""){ return $x; }else{ if($this->debug){echo "\ngetpost_pre----------- EMPTY RES 2 \n";} return false; } } function getpost($url, $method, $data, $session_required) { if($this->debug){echo "\ngetpost---------------------- getpost\n";} $curl = curl_init(); $ca = array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => $method, CURLOPT_HTTPHEADER => array('Content-Type: application/json' ) ); if ($method == "POST") { $ca[CURLOPT_POSTFIELDS] = $data; } if($session_required!=0){ $ca[CURLOPT_HTTPHEADER] = array('Content-Type: application/json','Access-Token: '.$this->sess); } if($this->debug){print_r($ca); echo " ";} curl_setopt_array($curl, $ca); $r = curl_exec($curl); if($this->debug){echo $r;} if ($r === false) { echo 'Curl error: ' . curl_error($curl); } else{ /* echo 'Operation completed without any errors'; */ } curl_close($curl); return $r; } function login() { if($this->debug){echo "\nlogin---------------------- login\n";} $response = json_decode($this->getpost("https://eipo.nseindia.com/eipo/v1/login", "POST", '{"member": "'.$this->member.'","loginId": "'.$this->loginId.'","password": "'.$this->password.'"}', 0)); if ($response->status == "success") { $myfile = fopen("session.php", "w") or die("Unable to open file!"); $txt = "token . ""; $txt .= "\n */ ?>"; fwrite($myfile, $txt); fclose($myfile); $this->sess = $response->token; return $response->token; } else { return false; } } function ipomaster(){ if($this->debug){echo "\nipomaster---------------------- ipomaster\n";} if(!file_exists("ipomaster.json") || ((time()-filemtime("ipomaster.json"))>1800) ){ $response = json_decode($this->getpost_pre("https://eipo.nseindia.com/eipo/v1/ipomaster", "GET", '', 1)); $myfile = fopen("ipomaster.json", "w"); fwrite($myfile, json_encode($response)); fclose($myfile); return $response ; }else{ return json_decode(file_get_contents("ipomaster.json")); } } function new_eform($symbol,$depository,$dpId,$clientBenId,$pan,$clientName,$upi,$bids){ $q = '{"symbol":"'.$symbol.'","depository":"'.$depository.'","dpId":"'.$dpId.'","clientBenId":"'.$clientBenId.'","pan":"'.$pan.'","category":"IND","bankReferenceNo":"","bankAccountNo":"","bankNameBranch":"","clientName":"'.$clientName.'","clientAddress":"","clientEmail":"","clientTelephone":"","formType":1,"paymentType":"FULL","nonASBA":false,"upiFlag":"Y","upi":"'.$upi.'","bankCode":"","locationCode":"","chequeNumber":"","syndMemCode":"","brokerCode":"","subBrokerCode":"","bids":'.$bids.'}'; $response = json_decode($this->getpost_pre("https://eipo.nseindia.com/eipo/v1/eforms/add", "POST", $q, 1)); if(isset($response->applicationNumber) && strlen($response->applicationNumber)>3){ return $response->applicationNumber; }else{ return false; } } function processIPO($symbol,$depository,$dpId,$clientBenId,$pan,$clientName,$upi,$bids,$ref=""){ $eform = $this->new_eform($symbol,$depository,$dpId,$clientBenId,$pan,$clientName,$upi,$bids); if($eform){ $q = '{"symbol":"'.$symbol.'","applicationNumber":"'.$eform.'","category":"IND","clientName":"'.$clientName.'","depository":"'.$depository.'","dpId":"'.$dpId.'","clientBenId":"'.$clientBenId.'","nonASBA":false,"chequeNumber":"","pan":"'.$pan.'","referenceNumber":"'.$ref.'","allotmentMode":"demat","upiFlag":"Y","upi":"'.$upi.'","bankCode":"","locationCode":"","bankAccount":"","ifsc":"","subBrokerCode":"","timestamp":"","bids":'.$bids.'}'; $response = json_decode($this->getpost_pre("https://eipo.nseindia.com/eipo/v1/transactions/add", "POST", $q, 1)); if(isset($response->status) && $response->status=="success"){ return $eform; }else{ echo '{"status": "failed","reason": "ER2"}'; return false; } }else{ echo '{"status": "failed","reason": "ER1"}'; exit(); } } function editIPO($json){ $q = $json; $response = json_decode($this->getpost_pre("https://eipo.nseindia.com/eipo/v1/transactions/add", "POST", $q, 1)); if(isset($response->status) && $response->status=="success"){ return '{"status": "failed","reason": "ER2"}'; }else{ echo '{"status": "failed","reason": "ER2"}'; return false; } } function getApplication($symbol,$eform){ $q='{"symbol": "'.$symbol.'","applicationNumber": "'.$eform.'"}'; $response = json_decode($this->getpost_pre("https://eipo.nseindia.com/eipo/v1/transactions/fetch", "POST", $q, 1)); if(isset($response->status) && $response->status=="success" && count($response->transactions)==1 && $response->transactions[0]->applicationNumber==$eform){ return json_encode($response); }else{ echo '{"status": "failed","reason": "ER3"}'; return false; }} } //$eipo = new eipo(); //$eipo->debug = true; //print_r($eipo->ipomaster()); //$eipo->processIPO("RUCHISOYA","CDSL","","1209320000002086","AJZPJ9559M","ARUN KUMAR JAISWAL","9830844002@ybl",'[{"activityType":"new","remark":"noremark5","quantity":21,"atCutOff":false,"price":616,"amount":12936}]'); //echo $eipo->login(); //echo $eipo->getSession(); //echo $eipo->getApplication("RUCHISOYA","800181069"); ?>