Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- final class Rest{
- public $url = 'https://solosmartpedia.com/api/';
- public $apikey = 'YOUR API KEY';
- public function get_method($method,$data){
- return json_decode($this->curl($method,$this->url.'/user?'.http_build_query($data)));
- }
- public function order_sosmed($method,$data){
- return json_decode($this->curl($method,$this->url.'/sosmed',array_merge(array('X-API-KEY'=>trim($this->apikey)),$data)));
- }
- public function order_pulsa($method,$data){
- return json_decode($this->curl($method,$this->url.'/pulsa',array_merge(array('X-API-KEY'=>trim($this->apikey)),$data)));
- }
- private function curl($method,$end_point,$data=''){
- //inisialisasi;
- $ch = curl_init($end_point);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
- curl_setopt($ch, CURLOPT_HEADER,0);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST,$method);
- curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT x.y; Win64; x64; rv:10.0) Gecko/20100101 Firefox/10.0');
- switch($method){
- case 'POST':
- curl_setopt($ch,CURLOPT_POST,1);
- curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($data));
- break;
- case 'GET':
- curl_setopt($ch, CURLOPT_HTTPHEADER,array('X-API-KEY:'.$this->apikey));
- break;
- }
- $result = curl_exec($ch);
- curl_close($ch);
- return $result;
- }
- }
- $api = new Rest();
- $json_result = $api->order_sosmed('POST',array('type'=>'order','service'=>$providerid,'target'=>$link,'quantity'=>$quantity)); #@Param $service,$target,$quantity
- print_r($json_result);
- if($json_result->status == 'false') {
- echo '<script>
- swal("Error!", "Server mengalami gangguan.", "error");
- </script>';
- } else {
- $oid = $json_result->id_order;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement