-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetDikti.php
54 lines (44 loc) · 1.46 KB
/
getDikti.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "OPTIONS") {
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: access');
header('Access-Control-Allow-Methods: POST');
header('Content-Type: application/json');
header('Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With');
header('HTTP/1.1 200 OK');
die();
}
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: access');
header('Access-Control-Allow-Methods: POST');
header('Content-Type: application/json');
header('Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With');
require_once __DIR__ . '/src/jsonHandler.php';
$data = json_decode(file_get_contents('php://input'));
function callPddikti($data)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://api-frontend.kemdikbud.go.id/hit_mhs/$data");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
if (!$output) {
die("Gagal menghubungkan ke API PDDIKTI");
}
curl_close($curl);
return $output;
}
$data = json_decode(file_get_contents('php://input'));
if (
!isset($data->data) ||
empty(trim($data->data))
) :
jsonHandler(
422,
'Masukkan data mahasiswa.',
['required_fields' => ['data']]
);
endif;
$data = trim($data->data);
$result = callPddikti($data);
echo $result;