<?php
namespace App\Helpers;
use DateTime;
class Helper {
public static function checkNumberWa($phoneNumber){
$key = "7e10303d8e75d503ef83ab381ac95f692a476a9766c51090";
$url='http://116.203.191.58/api/check_number';
$data = array(
"phone_no" => $phoneNumber,
"key" => $key,
"skip_link" => True, // This optional for skip snapshot of link in message
"flag_retry" => "on", // This optional for retry on failed send message
"pendingTime" => 3 // This optional for delay before send message
);
$data_string = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 360);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$res=curl_exec($ch);
curl_close($ch);
return $res;
}
public static function sendMessageWa($phoneNumber, $otp){
$key = "7e10303d8e75d503ef83ab381ac95f692a476a9766c51090";
$url='http://116.203.191.58/api/send_message';
$data = array(
"phone_no" => $phoneNumber,
"key" => $key,
"message" => 'Hi.. Gunakan Kode OTP berikut untuk menyelesaikan prosedur pendaftaran : '.$otp.' \n \n Kode OTP berlaku selama 10 menit. Untuk Keamanan, Jangan membagikan kode ini kepada orang lain untuk menjaga kerahasiaannya. \n \n Salam, \n Tim Support',
"skip_link" => True, // This optional for skip snapshot of link in message
"flag_retry" => "on", // This optional for retry on failed send message
"pendingTime" => 3 // This optional for delay before send message
);
$data_string = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 360);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$res=curl_exec($ch);
curl_close($ch);
return $res;
}
public static function generateBreadcrumb($breadcrumbs){
$html = '<nav class="mt-3" aria-label="breadcrumb">';
$html .= '<ol class="breadcrumb">';
foreach ($breadcrumbs as $key => $breadcrumb) {
$active = ($key === count($breadcrumbs) - 1) ? 'active' : '';
$html .= '<li class="breadcrumb-item ' . $active . '"><a href="' . $breadcrumb['url'] . '">' . $breadcrumb['title'] . '</a></li>';
}
$html .= '</ol>';
$html .= '</nav>';
return $html;
}
public static function calculateDistance($lat1, $lon1, $lat2, $lon2) {
// Radius bumi dalam kilometer
$R = 6371;
// Konversi sudut dari derajat ke radian
$lat1 = deg2rad($lat1);
$lon1 = deg2rad($lon1);
$lat2 = deg2rad($lat2);
$lon2 = deg2rad($lon2);
// Selisih sudut lintang dan bujur
$dLat = $lat2 - $lat1;
$dLon = $lon2 - $lon1;
// Rumus Haversine
$a = sin($dLat / 2) * sin($dLat / 2) + cos($lat1) * cos($lat2) * sin($dLon / 2) * sin($dLon / 2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
$distance = $R * $c;
return number_format($distance, 2);
}
public static function calculateAge($birthdate) {
// Convert birthdate to a DateTime object
$birthDate = new DateTime($birthdate);
// Get the current date
$currentDate = new DateTime();
// Calculate the difference between the current date and the birthdate
$interval = $currentDate->diff($birthDate);
// Return the years from the interval
return $interval->y;
}
public static function generateNoPendaftaran(){
$tanggal = now()->format('Ymd');
$angka_acak = mt_rand(100000, 999999); // Generate random number between 1000 and 9999
return "NO" . $tanggal . $angka_acak;
}
public static function calculateUmur($birthdate) {
// Convert birthdate to a DateTime object
$birthDate = new DateTime(date("Y-m-d", strtotime($birthdate)));
// Get the current date
$currentDate = new DateTime();
// Calculate the difference between the current date and the birthdate
$interval = $currentDate->diff($birthDate);
// Return the years from the interval
//format Y tahun, m bulan, d hari
return $interval->format('%Y tahun, %m bulan, %d hari');
}
}
Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]