PHP code example of banguncode / php-icare
1. Go to this page and download the library: Download banguncode/php-icare library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
banguncode / php-icare example snippets
PHPIcare\Icare;
// Set your BPJS API credentials
defined("JKN_API_CONSID") or define("JKN_API_CONSID", "your_consid");
defined("JKN_API_SECRET") or define("JKN_API_SECRET", "your_secret");
defined("JKN_API_USERKEY") or define("JKN_API_USERKEY", "your_userkey");
// Initialize
$icare = (new Icare())->init(JKN_API_CONSID, JKN_API_SECRET, JKN_API_USERKEY);
// Example data
$data = [
['param' => '1234567890000000', 'kodedokter' => '12345'],
['param' => '0000012345678', 'kodedokter' => '67890'],
];
$total = count($data);
echo "Total data: {$total}\n";
// Log file setup
$logDir = __DIR__ . '/logs';
if (!is_dir($logDir)) {
mkdir($logDir, 0777, true);
}
$logFile = $logDir . '/' . date('Y-m-d') . '.log';
foreach ($data as $key => $row) {
printf("%d/%d\n", $key + 1, $total);
$param = !empty($row['param']) && preg_match('/^\d+$/', $row['param']) ? $row['param'] : null;
$kodedokter = isset($row['kodedokter']) ? $row['kodedokter'] : null;
$response = $icare->getIcareHistory($param, $kodedokter);
$logMsg = '';
if ($response) {
if (is_int($response)) {
$time = $response;
while ($time > 0) {
echo "Retry in {$time} s\n";
sleep(1);
$time--;
}
$response = $icare->getIcareHistory($param, $kodedokter);
}
$verif = $icare->getCekVerifikasi3($response);
$approval = $icare->postApprovalIC($response);
$logMsg .= "Request {$param} - {$kodedokter} success!\n";
$logMsg .= "[REFERER] {$response}\n";
$logMsg .= "[VERIF] {$verif}\n";
$logMsg .= "[APPROVAL] {$approval}\n";
} else {
$logMsg .= "Request {$param} - {$kodedokter} failed!\n";
}
$logMsg .= "\n";
echo $logMsg;
file_put_contents($logFile, $logMsg, FILE_APPEND);
sleep(5);
}
echo "Done!";
bash
composer