86 lines
2.5 KiB
PHP
86 lines
2.5 KiB
PHP
<?php
|
|
class Meshbio_gen_token extends MY_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
function do()
|
|
{
|
|
$username = "bisone-hs-id-pramita";
|
|
$password = "5LHBXPFx7KgRkHM";
|
|
$curl = curl_init();
|
|
curl_setopt_array($curl, array(
|
|
CURLOPT_URL => 'https://hs.id.meshbio.com/api/v1/token',
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_ENCODING => '',
|
|
CURLOPT_MAXREDIRS => 10,
|
|
CURLOPT_TIMEOUT => 0,
|
|
CURLOPT_FOLLOWLOCATION => true,
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
CURLOPT_CUSTOMREQUEST => 'POST',
|
|
CURLOPT_POSTFIELDS => "{
|
|
\"organization\": \"Pramita\",
|
|
\"username\": \"$username\",
|
|
\"password\": \"$password\"
|
|
}",
|
|
CURLOPT_HTTPHEADER => array(
|
|
'Content-Type: application/json'
|
|
),
|
|
));
|
|
$response = curl_exec($curl);
|
|
$message = curl_error($curl);
|
|
if ($message != "") {
|
|
echo json_encode(["status" => "ERR", "message" => $message]);
|
|
curl_close($curl);
|
|
exit;
|
|
}
|
|
curl_close($curl);
|
|
$arr = json_decode($response, true);
|
|
$this->print_table_style();
|
|
$rows = [];
|
|
$rows[]= [
|
|
"access_token" => $arr["data"]["access_token"],
|
|
"refresh_token" => $arr["data"]["refresh_token"],
|
|
"id_token" => $arr["data"]["id_token"],
|
|
"expires_in" => $arr["data"]["expires_in"],
|
|
"token_type" => $arr["data"]["token_type"],
|
|
];
|
|
print_r($rows);
|
|
$this->print_table($rows,array_keys($rows[0]));
|
|
}
|
|
public function print_table_style()
|
|
{
|
|
echo "
|
|
<style>
|
|
th, td {
|
|
padding: 15px;
|
|
text-align: left;
|
|
}
|
|
tr:nth-child(even) {background-color: #f2f2f2;}
|
|
table {
|
|
border: solid 1px ;
|
|
min-width:600px;
|
|
}
|
|
</style>
|
|
";
|
|
}
|
|
public function print_table($rows, $keys)
|
|
{
|
|
echo "<table>";
|
|
echo "<tr>";
|
|
foreach ($keys as $k) {
|
|
echo "<td>$k</td>";
|
|
}
|
|
echo "</tr>\n";
|
|
foreach ($rows as $r) {
|
|
echo "<tr>";
|
|
foreach ($keys as $k) {
|
|
echo "<td>" . $r[$k] . "</td>";
|
|
}
|
|
echo "</tr>";
|
|
}
|
|
echo "</table>";
|
|
}
|
|
}
|