Advertisement
fahmihilmansyah

api

Sep 11th, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.09 KB | None | 0 0
  1. function doReq(){
  2.         $custid = $this->input->post("custid");
  3.         $produk = $this->input->post("produk");
  4.         $data['res'] = true;
  5.         $data['req'] =$this->getApi($custid,$produk);
  6.         echo json_encode($data);
  7.     }
  8.     function reqApi($url,$post_data){
  9.         $ch = curl_init();
  10.         curl_setopt( $ch, CURLOPT_URL, $url );
  11.         curl_setopt( $ch, CURLOPT_POST, true );
  12.         curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=GB2312'));
  13.         curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  14.         curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_data );
  15.         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
  16.         $data = curl_exec($ch);
  17.         curl_close($ch);
  18.         return $data;
  19.     }
  20.  
  21.     function getApi($custid='',$produk=''){
  22.         $trxid=time();
  23.         $url = "202.129.187.230/devcon/dev_transconnect";
  24.         $post_data = "<?xml version='1.0'?>
  25.         <TRANS_DATA>
  26.         <UID>".base64_encode('TRX.FHMDEV.L301')."</UID>
  27.         <PASSWORD>".md5('FHMBDG01')."</PASSWORD>
  28.         <PRODUCT>".$produk."</PRODUCT>
  29.         <CUSTID>".$custid."</CUSTID>
  30.         <TRXID>".$trxid."</TRXID>
  31.         </TRANS_DATA>";
  32.         $stats = false;
  33.         $x = explode('.', $produk);
  34.         $reqins = new stdclass();
  35.             $reqins->userid = $this->session->userdata('id_user');
  36.             $reqins->code_produk = $x[0];
  37.             $reqins->denom = (($x[1] == 'PAY' || $x[1] == 'INQ') ? '': $x[1]);
  38.             $reqins->req_stat = (($x[1] == 'PAY' || $x[1] == 'INQ') ? $x[1]:"Voucher");
  39.             $reqins->billreff = (isset($x[2]) == true?$x[2]:"");
  40.             $reqins->custid =$custid;
  41.             $reqins->trxid = $trxid;
  42.             $reqins->active = ((isset($x[2]) == false)?'1':($x[1] == 'PAY' || $x[1] == 'INQ') ? '0': '1');
  43.         $this->db->insert('trans_req',$reqins);
  44.        
  45.        
  46.         $isi = $this->reqApi($url,$post_data);
  47.         /**
  48.     error bagian ini
  49. */
  50.         $xml=json_decode(json_encode(simplexml_load_string($isi)), true) ;
  51.         if ($xml === false) {
  52.             echo "Failed loading XML: ";
  53.             foreach(libxml_get_errors() as $error) {
  54.                 echo "<br>", $error->message;
  55.             }
  56.         } else {
  57.             $y = explode('.', $xml['TRX']);
  58.             $reqinst = new stdclass();
  59.             $reqinst->userid = $this->session->userdata('id_user');
  60.             $reqinst->code_produk = $y[0];
  61.             $reqinst->denom = (($y[1] == 'PAY' || $y[1] == 'INQ') ? '': $y[1]);
  62.             $reqinst->req_stat = (($y[1] == 'PAY' || $y[1] == 'INQ') ? $y[1]:"Voucher");
  63.             $reqinst->billreff = $xml['BILLREFF'];
  64.             $reqinst->custid =$xml['CUSTNO'];
  65.             $reqinst->id_res_code =$xml['RC'];
  66.             $reqinst->trxid = $xml['TRXID'];
  67.             $reqinst->debit = $xml['DEBET'];
  68.             $reqinst->message = $xml['MESSAGE'];
  69.             $reqinst->active = ($xml['DEBET'] > 0 ? "1" : "0");
  70.             $this->db->insert('trans_result',$reqinst);
  71.             $datas = array(
  72.                 'userid'=> $this->ci->session->userdata('id_user'),
  73.             'code_produk' => $y[0],
  74.             'denom' => (($y[1] == 'PAY' || $y[1] == 'INQ') ? '': $y[1]),
  75.             'req_stat' => (($y[1] == 'PAY' || $y[1] == 'INQ') ? $y[1]:"Voucher"),
  76.             'billreff' => $xml['BILLREFF'],
  77.             'custid' =>$xml['CUSTNO'],
  78.             'id_res_code' =>$xml['RC'],
  79.             'trxid' => $xml['TRXID'],
  80.             'debit' => $xml['DEBET'],
  81.             'message' => $xml['MESSAGE'],
  82.             'active' => ($xml['DEBET'] > 0 ? "1" : "0"),
  83.                 );
  84.            
  85.             return $xml;
  86.         }
  87.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement