Advertisement
fahmihilmansyah

jsonresponse

May 3rd, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. <?php
  2. class myclass
  3. {
  4.    
  5.     public function getme(){
  6.        
  7.         $product_id = 'HGS.10';
  8.         $cust_id = '08128646986';
  9.         // $cust_id = '081233483721';
  10.         $url = 'https://localhost/GATEWAY/DEV_LP_XML/';
  11.         $l_username = base64_encode('TRX.HASYBIEL.06LPTH1356');
  12.         $l_password = base64_encode('12345');
  13.         $trx_id = time();
  14.        
  15.         $data_input = array(
  16.             'UID' => $l_username,
  17.             'PASSWORD' => $l_password,
  18.             'PRODUCT' => $product_id,
  19.             'CUST_ID' =>$cust_id,
  20.             'TRX_ID' => $trx_id
  21.             );
  22.         $data_hasil = json_encode($data_input);
  23.  
  24.         $ch = curl_init();
  25.         curl_setopt($ch, CURLOPT_URL, $url);
  26.         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  27.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  28.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  29.         curl_setopt($ch, CURLOPT_TIMEOUT, 120);
  30.         curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
  31.         curl_setopt($ch, CURLOPT_POSTFIELDS, $data_hasil;
  32.        
  33.         $result = curl_exec($ch);
  34.        
  35.         if ( curl_errno($ch) ) {
  36.             $result = 'ERROR -> ' . curl_errno($ch) . ': ' . curl_error($ch);
  37.         } else {
  38.             $returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
  39.             switch($returnCode){
  40.                 case 404:
  41.                     $result = 'ERROR -> 404 Not Found';
  42.                     break;
  43.                 default:
  44.                     break;
  45.             }
  46.         }
  47.        
  48.         curl_close($ch);
  49.         $res = $result;  
  50.         return $res;
  51.     }
  52.  
  53. }
  54.  
  55.  
  56. $gets = new myclass();
  57. var_dump($gets->getme());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement