Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function doReq(){
- $custid = $this->input->post("custid");
- $produk = $this->input->post("produk");
- $data['res'] = true;
- $data['req'] =$this->getApi($custid,$produk);
- echo json_encode($data);
- }
- function reqApi($url,$post_data){
- $ch = curl_init();
- curl_setopt( $ch, CURLOPT_URL, $url );
- curl_setopt( $ch, CURLOPT_POST, true );
- curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=GB2312'));
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_data );
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
- $data = curl_exec($ch);
- curl_close($ch);
- return $data;
- }
- function getApi($custid='',$produk=''){
- $trxid=time();
- $url = "202.129.187.230/devcon/dev_transconnect";
- $post_data = "<?xml version='1.0'?>
- <TRANS_DATA>
- <UID>".base64_encode('TRX.FHMDEV.L301')."</UID>
- <PASSWORD>".md5('FHMBDG01')."</PASSWORD>
- <PRODUCT>".$produk."</PRODUCT>
- <CUSTID>".$custid."</CUSTID>
- <TRXID>".$trxid."</TRXID>
- </TRANS_DATA>";
- $stats = false;
- $x = explode('.', $produk);
- $reqins = new stdclass();
- $reqins->userid = $this->session->userdata('id_user');
- $reqins->code_produk = $x[0];
- $reqins->denom = (($x[1] == 'PAY' || $x[1] == 'INQ') ? '': $x[1]);
- $reqins->req_stat = (($x[1] == 'PAY' || $x[1] == 'INQ') ? $x[1]:"Voucher");
- $reqins->billreff = (isset($x[2]) == true?$x[2]:"");
- $reqins->custid =$custid;
- $reqins->trxid = $trxid;
- $reqins->active = ((isset($x[2]) == false)?'1':($x[1] == 'PAY' || $x[1] == 'INQ') ? '0': '1');
- $this->db->insert('trans_req',$reqins);
- $isi = $this->reqApi($url,$post_data);
- /**
- error bagian ini
- */
- $xml=json_decode(json_encode(simplexml_load_string($isi)), true) ;
- if ($xml === false) {
- echo "Failed loading XML: ";
- foreach(libxml_get_errors() as $error) {
- echo "<br>", $error->message;
- }
- } else {
- $y = explode('.', $xml['TRX']);
- $reqinst = new stdclass();
- $reqinst->userid = $this->session->userdata('id_user');
- $reqinst->code_produk = $y[0];
- $reqinst->denom = (($y[1] == 'PAY' || $y[1] == 'INQ') ? '': $y[1]);
- $reqinst->req_stat = (($y[1] == 'PAY' || $y[1] == 'INQ') ? $y[1]:"Voucher");
- $reqinst->billreff = $xml['BILLREFF'];
- $reqinst->custid =$xml['CUSTNO'];
- $reqinst->id_res_code =$xml['RC'];
- $reqinst->trxid = $xml['TRXID'];
- $reqinst->debit = $xml['DEBET'];
- $reqinst->message = $xml['MESSAGE'];
- $reqinst->active = ($xml['DEBET'] > 0 ? "1" : "0");
- $this->db->insert('trans_result',$reqinst);
- $datas = array(
- 'userid'=> $this->ci->session->userdata('id_user'),
- 'code_produk' => $y[0],
- 'denom' => (($y[1] == 'PAY' || $y[1] == 'INQ') ? '': $y[1]),
- 'req_stat' => (($y[1] == 'PAY' || $y[1] == 'INQ') ? $y[1]:"Voucher"),
- 'billreff' => $xml['BILLREFF'],
- 'custid' =>$xml['CUSTNO'],
- 'id_res_code' =>$xml['RC'],
- 'trxid' => $xml['TRXID'],
- 'debit' => $xml['DEBET'],
- 'message' => $xml['MESSAGE'],
- 'active' => ($xml['DEBET'] > 0 ? "1" : "0"),
- );
- return $xml;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement