Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
simpmw
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alfiro Pratama
simpmw
Commits
479fcc68
Commit
479fcc68
authored
Apr 18, 2025
by
Alfiro Pratama
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix API Mhs
parent
d03e980b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
11 deletions
+47
-11
app/Http/Controllers/GetDataApiController.php
+47
-11
No files found.
app/Http/Controllers/GetDataApiController.php
View file @
479fcc68
...
...
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use
Exception
;
use
Illuminate\Http\Request
;
use
GuzzleHttp\Client
;
use
Illuminate\Support\Facades\Log
;
class
GetDataApiController
extends
Controller
{
...
...
@@ -28,20 +29,55 @@ class GetDataApiController extends Controller
public
static
function
getAccount
(
$nim
)
{
$client
=
new
Client
();
//
$client = new Client();
$apiRequest
=
$client
->
request
(
'POST'
,
GetDataApiController
::
URL
,
[
'form_params'
=>
[
'username'
=>
$nim
,
'kondisi'
=>
'cekhakakses'
]
]);
// $apiRequest = $client->request('POST', GetDataApiController::URL, [
// 'form_params' =>
// [
// 'username' => $nim,
// 'kondisi' => 'cekhakakses'
// ]
// ]);
// $gcon = utf8_encode($apiRequest->getBody()->getContents());
// $data = unserialize($gcon);
$gcon
=
utf8_encode
(
$apiRequest
->
getBody
()
->
getContents
());
$data
=
unserialize
(
$gcon
);
// return $data;
return
$data
;
try
{
$client
=
new
Client
();
$apiRequest
=
$client
->
request
(
'POST'
,
GetDataApiController
::
URL
,
[
'form_params'
=>
[
'username'
=>
$nim
,
'kondisi'
=>
'cekhakakses'
]
]);
$response
=
$apiRequest
->
getBody
()
->
getContents
();
// Coba unserialize langsung tanpa utf8_encode
$data
=
@
unserialize
(
$response
);
if
(
$data
!==
false
)
{
return
$data
;
}
// Kalau unserialize gagal, coba cek apakah data berupa JSON
$json
=
json_decode
(
$response
,
true
);
if
(
$json
!==
null
)
{
return
$json
;
}
// Log jika data tidak bisa di-unserialize dan bukan JSON
Log
::
error
(
"Gagal memproses response API untuk NIM:
$nim
\n
Response:
\n
$response
"
);
return
null
;
}
catch
(
\Exception
$e
)
{
// Log exception jika gagal request
Log
::
error
(
"Exception saat memanggil API untuk NIM:
$nim
\n
"
.
$e
->
getMessage
());
return
null
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment