Advertisement
dimitri21

Untitled

Jan 16th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.05 KB | None | 0 0
  1.     public function postDJKSertifikasi(Request $req){
  2.  
  3.         $ch = curl_init();
  4.         $consumerId = "";
  5.         $secretKey = "";
  6.         date_default_timezone_set('UTC');
  7.         $tStamp = strval(time()-strtotime('1970-01-01 00:00:00'));
  8.         $signature = hash_hmac('sha256', $consumerId."&".$tStamp, $secretKey, true);
  9.  
  10.         // Base64 Encode
  11.         $encodedSignature = base64_encode($signature);
  12.  
  13.         $postUrl = 'http://103.87.161.97/slo/api/tm/permohonan/create';
  14.  
  15.         $data = [
  16.             "tanggal" => $req->$tanggal,
  17.             "pemilik" => [
  18.                 "nama" => $req->$namapemilik,
  19.                 "alamat" => $req->$alamatpemilik,
  20.                 "kota_id" => $req->$kotaidpemilik
  21.             ],
  22.             "instalasi" => [
  23.                 "nama" => $req->namainstalasi,
  24.                 "lokasi"=> $req->lokasiinstalasi,
  25.                 "kota_id"=> $req->kotaidinstalasi,
  26.                 "jenis"=> $req->jenis,
  27.                 "kapasitas"=> $kapasitas,
  28.                 "panjang_saluran"=> $panjangsaluran,
  29.  
  30.             ]
  31.             ];
  32.         $postDataJson = json_encode($data);
  33.      
  34.  
  35.         try{
  36.             curl_setopt($ch, CURLOPT_URL, $postUrl);
  37.             $headers[] = 'Accept: application/json';
  38.             $headers[] = 'Content-Type: application/json';
  39.             $headers[] = 'X-cons-id: '.$consumerId.' ';
  40.             $headers[] = 'X-timestamp: '.$tStamp.' ';
  41.             $headers[] = 'X-signature: '.$encodedSignature;
  42.             curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  43.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  44.             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  45.             curl_setopt($ch, CURLOPT_POST, 1);
  46.             curl_setopt($ch, CURLOPT_POSTFIELDS, $postDataJson);
  47.  
  48.             $response = curl_exec($ch);
  49.             curl_close($ch);
  50.             $responseBody = json_encode($response, true);
  51.  
  52.            
  53.  
  54.         }catch(\Exception $e){
  55.             $responseBody = $e->getMessage();
  56.         }
  57.  
  58.         return response()->json($responseBody);
  59.  
  60.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement