<?php
	$consID 	= "9972";
	$secretKey 	= "9cB59E421A";
	$pcareUname = "01480001";
	$pcarePWD 	= "Pancaarga-4510"; //password pcare
	$kdAplikasi	= "095";
	
	date_default_timezone_set('UTC');
	$stamp		= strval(time()-strtotime('1970-01-01 00:00:00'));
	
	$signature = hash_hmac('sha256',$consID.'&'.$stamp,$secretKey, true);
	$encodedSignature	=base64_encode($signature);	
	$encodedAuthorization = base64_encode($pcareUname.':'.$pcarePWD.':'.$kdAplikasi);	
	
	$payload=  <<<EOT
	{
  "noKunjungan": null,
  "noKartu": "0001109440978",
  "tglDaftar": "11-08-2019",
  "kdPoli": "001",
  "keluhan": "keluhan",
  "kdSadar": "01",
  "sistole": 20,
  "diastole": 30,
  "beratBadan": 17,
  "tinggiBadan": 158,
  "respRate": 12,
  "heartRate": null,
  "terapi": "catatan",
  "kdStatusPulang": "3",
  "tglPulang": "11-08-2019",
  "kdDokter": "135435",
  "kdDiag1": "K04.1",
  "kdDiag2": null,
  "kdDiag3": null,
  "kdPoliRujukInternal": null,
  "rujukLanjut": {	
  	"tglEstRujuk":null,
    "kdppk": null,
    "subSpesialis": null,
    "khusus": {
      "kdKhusus": null,
      "kdSubSpesialis": null,
      "catatan": null
    }
  },
  "kdTacc": null,
  "alasanTacc": null
	}        
EOT;

	$URL="https://new-api.bpjs-kesehatan.go.id/pcare-rest-v3.0/kunjungan";
	$ch = curl_init($URL);
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_HTTPHEADER, array( 
            "Content-Type: application/json", 
            "X-Cons-id: ".$consID, 
            "X-Timestamp: ".$stamp, 
            "X-Signature: ".$encodedSignature, 
            "X-Authorization: Basic " .$encodedAuthorization 
        ));  

    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 10);
	$result = curl_exec($ch);

	
echo "X-cons-id: ".$consID; ?></br><?php
echo "X-Timestamp: ".$stamp; ?></br><?php
echo "X-Signature: ".$encodedSignature; ?> </br> <?php
echo "X-Authorization: Basic ".$encodedAuthorization; ?></br><?php
echo $payload; ?></br></br><?php
echo $result; ?></br></br>