Penambahan Sementara Pengajuan Presensi WhatsApp

This commit is contained in:
Ariyutta
2026-09-15 14:42:01 +07:00
parent 88d27ef207
commit ffcfdd3579
23 changed files with 1257 additions and 384 deletions
+8 -1
View File
@@ -56,6 +56,13 @@ class DawaiService
return $data;
}
public function isAtasanDari(string $nipAtasan, string $nipBawahan): bool
{
$bawahan = $this->getListBawahan($nipAtasan)['data']['bawahan'] ?? [];
return in_array($nipBawahan, array_column($bawahan, 'nip'), true);
}
public function isVerifikatorTriDharma(string $nip)
{
try {
@@ -88,7 +95,7 @@ class DawaiService
public function listPegawai(string $nip = '', string $jenisPegawai = '', string $email = ''): array
{
try {
$response = $this->client->get("api/v1/pegawai?jenis_pegawai=$jenisPegawai&nip=$nip&email=$email&asn=true&pensiun=0&wafat=0&mutkel=0&nonaktif=0");
$response = $this->client->get("api/v1/pegawai?jenis_pegawai=$jenisPegawai&nip=$nip&email=$email&asn=true&pensiun=0&wafat=0&mutkel=0&nonaktif=0&privasi=true");
$data = json_decode($response->getBody()->getContents(), true);
return $data;
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace App\Services;
use Illuminate\Support\Facades\Log;
use Throwable;
class GoogleDriveService
{
// TODO: isi path credentials service account (JSON) & folder ID tujuan setelah tersedia.
private string $credentialsPath = '';
private string $folderId = '';
public function uploadPdf(string $content, string $fileName): string|false
{
if (! $this->credentialsPath || ! $this->folderId) {
Log::error("GoogleDriveService: belum dikonfigurasi, upload '$fileName' dilewati.");
return false;
}
try {
// TODO: implementasi upload pakai google/apiclient setelah credentials tersedia.
} catch (Throwable $th) {
Log::error('GoogleDriveService uploadPdf : '.$th->getMessage());
return false;
}
return false;
}
}
+53
View File
@@ -0,0 +1,53 @@
<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Throwable;
class TteService
{
private string $baseUrl = 'http://118.98.229.146';
private string $username = '9702946';
private string $password = 'DsC1-G0cP-Pbk8-qYxE';
public function signDokumenUser(string $nik, string $passphrase, string $filePath, string $linkQr): string|false
{
try {
$query = http_build_query([
'nik' => $nik,
'passphrase' => $passphrase,
'tampilan' => 'invisible',
'halaman' => 'terakhir',
'image' => 'false',
'xAxis' => 43.63,
'yAxis' => 28.71,
'width' => 550.78,
'height' => 130.88,
'reason' => 'Dokumen ditandatangani secara elektronik Universitas Tanjungpura',
'location' => 'Universitas Tanjungpura',
'linkQR' => $linkQr,
]);
$response = Http::withBasicAuth($this->username, $this->password)
->timeout(60)
->attach('file', file_get_contents($filePath), basename($filePath))
->post("{$this->baseUrl}/api/sign/pdf?{$query}");
} catch (Throwable $th) {
Log::error('TTE signDokumenUser : '.$th->getMessage());
return false;
}
if (! $response->successful()) {
Log::error("TTE signDokumenUser gagal: HTTP {$response->status()} - {$response->body()}");
return false;
}
return $response->body();
}
}
@@ -0,0 +1,48 @@
<?php
namespace App\Services;
class VerifikasiAbsenLinkService
{
const TTL_MENIT_DEFAULT = 7200; // 5 hari, selaras dengan batas kadaluarsa pengajuan
public function generate(int $pengajuanId, string $nip, int $ttlMenit = self::TTL_MENIT_DEFAULT): array
{
$expires = now()->addMinutes($ttlMenit)->timestamp;
$signature = $this->hash($pengajuanId, $nip, $expires);
return [
'nip' => $nip,
'expires' => $expires,
'signature' => $signature,
'url' => route('verifikasi-absen.show', [
'id' => $pengajuanId,
'nip' => $nip,
'expires' => $expires,
'signature' => $signature,
]),
// Suffix untuk parameter tombol URL template WhatsApp (domain sudah baku di template).
'button_param' => "{$pengajuanId}?nip={$nip}&expires={$expires}&signature={$signature}",
];
}
public function verify(int $pengajuanId, ?string $nip, mixed $expires, ?string $signature): bool
{
if (! $nip || ! $expires || ! $signature) {
return false;
}
if ((int) $expires < now()->timestamp) {
return false;
}
$expected = $this->hash($pengajuanId, $nip, (int) $expires);
return hash_equals($expected, $signature);
}
private function hash(int $pengajuanId, string $nip, int $expires): string
{
return hash_hmac('sha256', "{$pengajuanId}|{$nip}|{$expires}", config('app.key'));
}
}
+73
View File
@@ -0,0 +1,73 @@
<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Throwable;
class WhatsAppService
{
private string $baseUrl = 'https://chat.api.co.id';
private string $token = 'apicoid_live_7J0vmW5Sbk2dBBAEIEDtdc4tG4fOswy3Seblz_nKZqk';
public function sendPengajuanAbsenNotification(
string $nomorTujuan,
string $namaAtasan,
string $namaPemohon,
string $nipPemohon,
int $jumlahHari,
string $tanggalMulai,
string $tanggalSelesai,
string $keterangan,
string $link
): bool {
try {
$response = Http::withToken($this->token)
->post("{$this->baseUrl}/api/v1/public/messages/send", [
'phone_number' => $nomorTujuan,
'channel' => 'whatsapp',
'message_type' => 'template',
'template' => [
'name' => 'pengajuan_absen',
'language' => ['code' => 'id'],
'components' => [
[
'type' => 'body',
'parameters' => [
['type' => 'text', 'text' => $namaAtasan],
['type' => 'text', 'text' => $namaPemohon],
['type' => 'text', 'text' => $nipPemohon],
['type' => 'text', 'text' => (string) $jumlahHari],
['type' => 'text', 'text' => $tanggalMulai],
['type' => 'text', 'text' => $tanggalSelesai],
['type' => 'text', 'text' => $keterangan],
],
],
[
'type' => 'button',
'sub_type' => 'url',
'index' => '0',
'parameters' => [
['type' => 'text', 'text' => $link],
],
],
],
],
]);
} catch (Throwable $th) {
Log::error('WhatsApp sendPengajuanAbsenNotification : '.$th->getMessage());
return false;
}
if (! $response->successful()) {
Log::error("WhatsApp sendPengajuanAbsenNotification gagal: HTTP {$response->status()} - {$response->body()}");
return false;
}
return true;
}
}