Skip to content

Commit e24d922

Browse files
committed
fix: update domain and security mechanism
1 parent 9512827 commit e24d922

2 files changed

Lines changed: 25 additions & 10 deletions

File tree

example.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
require __DIR__ . '/vendor/autoload.php';
66

77
try {
8-
$nim = new Nim('221351017');
8+
$nim = new Nim('211351143');
99

1010
var_dump($nim->dump());
1111
} catch (\Exception $e) {

src/PDDikti.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ class PDDikti
1010
private Client $http;
1111
private string $nim;
1212

13-
private array $headers = [
14-
'Accept' => 'application/json',
15-
'X-Api-Key' => '3ed297db-db1c-4266-8bf4-a89f21c01317',
16-
];
17-
1813
private ?string $id = null;
1914
private ?string $name = null;
2015
private ?string $gender = null;
@@ -23,16 +18,36 @@ class PDDikti
2318
public function __construct(string $nim)
2419
{
2520
$this->http = new Client([
26-
'base_uri' => 'https://pddikti.kemdikbud.go.id',
21+
'base_uri' => 'https://api-pddikti.kemdiktisaintek.go.id',
2722
'verify' => false,
2823
]);
2924
$this->nim = $nim;
3025
}
3126

3227
private function fetchData(string $endpoint): ?object
3328
{
29+
$ip = long2ip(rand(0, 4294967295));
30+
31+
try {
32+
$this->http->request('OPTIONS', $endpoint, [
33+
'headers' => [
34+
'X-User-Ip' => $ip,
35+
'Origin' => 'https://pddikti.kemdiktisaintek.go.id',
36+
'Access-Control-Request-Method' => 'GET',
37+
'Access-Control-Request-Headers' => 'X-User-Ip',
38+
],
39+
]);
40+
} catch (\Exception $e) {
41+
return null;
42+
}
43+
3444
try {
35-
$response = $this->http->request('GET', $endpoint, ['headers' => $this->headers]);
45+
$response = $this->http->request('GET', $endpoint, [
46+
'headers' => [
47+
'X-User-Ip' => $ip,
48+
'Origin' => 'https://pddikti.kemdiktisaintek.go.id',
49+
],
50+
]);
3651
return $this->parseResponse($response);
3752
} catch (\Exception $e) {
3853
return null;
@@ -51,7 +66,7 @@ private function prepareList(): void
5166
return;
5267
}
5368

54-
$data = $this->fetchData("api/pencarian/all/$this->nim");
69+
$data = $this->fetchData("pencarian/all/$this->nim");
5570

5671
if (!$data || empty($data->mahasiswa)) {
5772
return;
@@ -80,7 +95,7 @@ private function prepareDetail(): void
8095
return;
8196
}
8297

83-
$data = $this->fetchData("api/detail/mhs/$this->id");
98+
$data = $this->fetchData("detail/mhs/$this->id");
8499

85100
if (!$data) {
86101
return;

0 commit comments

Comments
 (0)