54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?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();
|
|
}
|
|
}
|