Advertisement
ezcode

Untitled

Sep 20th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.31 KB | None | 0 0
  1. <?php
  2.  final class Rest{
  3.             public  $url = 'https://solosmartpedia.com/api/';
  4.             public  $apikey = 'YOUR API KEY';
  5.            
  6.             public function get_method($method,$data){
  7.                 return json_decode($this->curl($method,$this->url.'/user?'.http_build_query($data)));
  8.             }
  9.            
  10.             public function order_sosmed($method,$data){
  11.                 return json_decode($this->curl($method,$this->url.'/sosmed',array_merge(array('X-API-KEY'=>trim($this->apikey)),$data)));
  12.             }
  13.            
  14.             public function order_pulsa($method,$data){
  15.                 return json_decode($this->curl($method,$this->url.'/pulsa',array_merge(array('X-API-KEY'=>trim($this->apikey)),$data)));
  16.             }
  17.        
  18.            
  19.             private function curl($method,$end_point,$data=''){
  20.                 //inisialisasi;
  21.                 $ch = curl_init($end_point);
  22.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  23.                 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
  24.                 curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
  25.                 curl_setopt($ch, CURLOPT_HEADER,0);
  26.                 curl_setopt($ch, CURLOPT_CUSTOMREQUEST,$method);
  27.                 curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT x.y; Win64; x64; rv:10.0) Gecko/20100101 Firefox/10.0');
  28.                 switch($method){
  29.                     case 'POST':
  30.                     curl_setopt($ch,CURLOPT_POST,1);
  31.                     curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($data));
  32.                     break;
  33.                     case 'GET':
  34.                     curl_setopt($ch, CURLOPT_HTTPHEADER,array('X-API-KEY:'.$this->apikey));
  35.                     break;
  36.                 }
  37.                 $result = curl_exec($ch);
  38.                 curl_close($ch);
  39.                 return $result;
  40.             }
  41.         }
  42.        
  43.        
  44.         $api = new Rest();
  45.         $json_result = $api->order_sosmed('POST',array('type'=>'order','service'=>$providerid,'target'=>$link,'quantity'=>$quantity)); #@Param $service,$target,$quantity
  46.             print_r($json_result);
  47.             if($json_result->status == 'false') {
  48.     echo '<script>
  49.    swal("Error!", "Server mengalami gangguan.", "error");
  50.    </script>';
  51.             } else {
  52.             $oid = $json_result->id_order;
  53.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement