broken commit dont use, only to remove .env
This commit is contained in:
parent
fe8a4dc61c
commit
7bfd0f999c
82
.env
82
.env
@ -1,82 +0,0 @@
|
||||
#--------------------------------------------------------------------
|
||||
# Example Environment Configuration file
|
||||
#
|
||||
# This file can be used as a starting point for your own
|
||||
# custom .env files, and contains most of the possible settings
|
||||
# available in a default install.
|
||||
#
|
||||
# By default, all of the settings are commented out. If you want
|
||||
# to override the setting, you must un-comment it by removing the '#'
|
||||
# at the beginning of the line.
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# ENVIRONMENT
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
#CI_ENVIRONMENT = production
|
||||
CI_ENVIRONMENT = development
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# APP
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
# app.baseURL = ''
|
||||
app.baseURL = 'http://rest.local/'
|
||||
#app.baseURL = 'http://pbmc-dev.services-summit.my.id/'
|
||||
# If you have trouble with `.`, you could also use `_`.
|
||||
# app_baseURL = ''
|
||||
# app.forceGlobalSecureRequests = false
|
||||
# app.CSPEnabled = false
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# DATABASE
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
# database.default.hostname = localhost
|
||||
# database.default.database = ci4
|
||||
# database.default.username = root
|
||||
# database.default.password = root
|
||||
# database.default.DBDriver = MySQLi
|
||||
# database.default.DBPrefix =
|
||||
# database.default.port = 3306
|
||||
|
||||
# If you use MySQLi as tests, first update the values of Config\Database::$tests.
|
||||
# database.tests.hostname = localhost
|
||||
# database.tests.database = ci4_test
|
||||
# database.tests.username = root
|
||||
# database.tests.password = root
|
||||
# database.tests.DBDriver = MySQLi
|
||||
# database.tests.DBPrefix =
|
||||
# database.tests.charset = utf8mb4
|
||||
# database.tests.DBCollat = utf8mb4_general_ci
|
||||
# database.tests.port = 3306
|
||||
|
||||
database.default.hostname = localhost
|
||||
database.default.database = PADMA
|
||||
database.default.username = sa
|
||||
database.default.password = SQLadmin2024
|
||||
database.default.DBDriver = SQLSRV
|
||||
database.default.encrypt = false
|
||||
#database.default.DBPrefix =
|
||||
database.default.pconnect = false
|
||||
database.default.port = 1433
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# ENCRYPTION
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
# encryption.key =
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# SESSION
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
# session.driver = 'CodeIgniter\Session\Handlers\FileHandler'
|
||||
# session.savePath = null
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# LOGGER
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
# logger.threshold = 4
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@ -41,7 +41,7 @@ $RECYCLE.BIN/
|
||||
#-------------------------
|
||||
# These should never be under version control,
|
||||
# as it poses a security risk.
|
||||
#.env
|
||||
.env
|
||||
.vagrant
|
||||
Vagrantfile
|
||||
|
||||
|
||||
79
README.md
79
README.md
@ -1,68 +1,11 @@
|
||||
# CodeIgniter 4 Application Starter
|
||||
|
||||
## What is CodeIgniter?
|
||||
|
||||
CodeIgniter is a PHP full-stack web framework that is light, fast, flexible and secure.
|
||||
More information can be found at the [official site](https://codeigniter.com).
|
||||
|
||||
This repository holds a composer-installable app starter.
|
||||
It has been built from the
|
||||
[development repository](https://github.com/codeigniter4/CodeIgniter4).
|
||||
|
||||
More information about the plans for version 4 can be found in [CodeIgniter 4](https://forum.codeigniter.com/forumdisplay.php?fid=28) on the forums.
|
||||
|
||||
You can read the [user guide](https://codeigniter.com/user_guide/)
|
||||
corresponding to the latest version of the framework.
|
||||
|
||||
## Installation & updates
|
||||
|
||||
`composer create-project codeigniter4/appstarter` then `composer update` whenever
|
||||
there is a new release of the framework.
|
||||
|
||||
When updating, check the release notes to see if there are any changes you might need to apply
|
||||
to your `app` folder. The affected files can be copied or merged from
|
||||
`vendor/codeigniter4/framework/app`.
|
||||
|
||||
## Setup
|
||||
|
||||
Copy `env` to `.env` and tailor for your app, specifically the baseURL
|
||||
and any database settings.
|
||||
|
||||
## Important Change with index.php
|
||||
|
||||
`index.php` is no longer in the root of the project! It has been moved inside the *public* folder,
|
||||
for better security and separation of components.
|
||||
|
||||
This means that you should configure your web server to "point" to your project's *public* folder, and
|
||||
not to the project root. A better practice would be to configure a virtual host to point there. A poor practice would be to point your web server to the project root and expect to enter *public/...*, as the rest of your logic and the
|
||||
framework are exposed.
|
||||
|
||||
**Please** read the user guide for a better explanation of how CI4 works!
|
||||
|
||||
## Repository Management
|
||||
|
||||
We use GitHub issues, in our main repository, to track **BUGS** and to track approved **DEVELOPMENT** work packages.
|
||||
We use our [forum](http://forum.codeigniter.com) to provide SUPPORT and to discuss
|
||||
FEATURE REQUESTS.
|
||||
|
||||
This repository is a "distribution" one, built by our release preparation script.
|
||||
Problems with it can be raised on our forum, or as issues in the main repository.
|
||||
|
||||
## Server Requirements
|
||||
|
||||
PHP version 8.1 or higher is required, with the following extensions installed:
|
||||
|
||||
- [intl](http://php.net/manual/en/intl.requirements.php)
|
||||
- [mbstring](http://php.net/manual/en/mbstring.installation.php)
|
||||
|
||||
> [!WARNING]
|
||||
> - The end of life date for PHP 7.4 was November 28, 2022.
|
||||
> - The end of life date for PHP 8.0 was November 26, 2023.
|
||||
> - If you are still using PHP 7.4 or 8.0, you should upgrade immediately.
|
||||
> - The end of life date for PHP 8.1 will be December 31, 2025.
|
||||
|
||||
Additionally, make sure that the following extensions are enabled in your PHP:
|
||||
|
||||
- json (enabled by default - don't turn it off)
|
||||
- [mysqlnd](http://php.net/manual/en/mysqlnd.install.php) if you plan to use MySQL
|
||||
- [libcurl](http://php.net/manual/en/curl.requirements.php) if you plan to use the HTTP\CURLRequest library
|
||||
buat rule cmod-rest
|
||||
-order baru
|
||||
-klo ref baru > ok
|
||||
-klo ref dan mr+nama sama -> ok
|
||||
-klo ref sama cek mr dan nama beda di lis -> (kirim error balik)
|
||||
-order tambahan
|
||||
-ref sama , cek mr dan nama pasien harus sama + status receive di lis = 0 > ok
|
||||
-kalo mr dan nama beda atau receive = 1 -> tolak (kirim error balik)
|
||||
-order cancel
|
||||
-klo ref sama status cancel=1 dan status receive di lis = 0 - ok
|
||||
-klo ref sama sattus cancel=1 dan status receive di lis = 1 - tolak (kirim error balik
|
||||
@ -6,8 +6,8 @@ use CodeIgniter\Router\RouteCollection;
|
||||
* @var RouteCollection $routes
|
||||
*/
|
||||
$routes->get('/', 'Pages::home');
|
||||
$routes->get('/loginsby', 'Auths::loginSBY');
|
||||
$routes->get('/logindps', 'Auths::loginDPS');
|
||||
//$routes->get('/loginsby', 'Auths::loginSBY');
|
||||
//$routes->get('/logindps', 'Auths::loginDPS');
|
||||
//$routes->get('/tests', 'Auths::tests');
|
||||
$routes->post('/api/requests/', 'API_TM::requests');
|
||||
$routes->post('/api/requests1/', 'API_TM::requests1');
|
||||
|
||||
@ -76,8 +76,8 @@ class API_TM extends ResourceController {
|
||||
|
||||
// log to cm_tm_logs
|
||||
$data = str_replace("'","''",json_encode($raw));
|
||||
$sql = "INSERT INTO cmod.dbo.CM_TM_LOGS (URL, METHOD, BODY, LOGDATE) VALUES ('API/REQUESTS', 'POST', '$data', GETDATE())";
|
||||
$db->query($sql);
|
||||
//$sql = "INSERT INTO cmod.dbo.CM_TM_LOGS (URL, METHOD, BODY, LOGDATE) VALUES ('API/REQUESTS', 'POST', '$data', GETDATE())";
|
||||
//$db->query($sql);
|
||||
|
||||
$data = array();
|
||||
$qdata = (array)$raw;
|
||||
@ -113,10 +113,49 @@ class API_TM extends ResourceController {
|
||||
$qant = (array)$qpat['anthropometry'];
|
||||
$bw = $qant['weight'];
|
||||
$bh = $qant['height'];
|
||||
|
||||
|
||||
$sql = "select PATID from cmod.dbo.CM_TM_PATIENTS where PATNUMBER='$rm'";
|
||||
$query = $db->query($sql);
|
||||
$results = $query->getResultArray();
|
||||
$result = $query->getResultArray();
|
||||
if(isset($result[0])) { $patid = $result[0]['PATID']; }
|
||||
else { $patid = ''; }
|
||||
|
||||
$sql = "select REQID, PATID from cmod.dbo.CM_TM_REQUESTS where REFFID='$reffid'";
|
||||
$query = $db->query($sql);
|
||||
$result = $query->getResultArray();
|
||||
if(isset($result[0])) { $reqid = $result[0]['REQID']; $rpatid = $result[0]['PATID']; }
|
||||
else { $reqid = ''; $rpatid = ''; }
|
||||
|
||||
echo "$patid<br/>$reqid - $rpatid";
|
||||
|
||||
// check data patient
|
||||
if($patid == '') { // new patient
|
||||
$sql = "INSERT INTO cmod.dbo.CM_TM_PATIENTS (PATNUMBER, FIRSTNAME, LASTNAME, BIRTHDATE, SEX, PHONE ) VALUES ('$rm', '$firstname', '$lastname', '$dob', '$sex', '$phone' )";
|
||||
//$db->query($sql); $patid = $db->insertID();
|
||||
} else { // existing patient
|
||||
if($rpatid == $patid ) { // if patient is the same
|
||||
$sql = "UPDATE cmod.dbo.CM_TM_PATIENTS SET FIRSTNAME='$firstname', LASTNAME='$lastname', BIRTHDATE='$dob', SEX='$sex', PHONE='$phone' where PATID='$patid'";
|
||||
//$db->query($sql);
|
||||
} else {
|
||||
return $this->failForbidden('Error. Invalid patient data.');
|
||||
}
|
||||
}
|
||||
|
||||
if($reqstatus != 1) { // reqstatus = order
|
||||
if( $reqid == '' ) { // new request
|
||||
$sql = "INSERT INTO cmod.dbo.CM_TM_REQUESTS (REFFID, REQNUMBER, REQDATE, AGENT, DOC, LOC, PATID, COMPANY, LOGDATE, BW, BH, VISITDESC, VISITTYPE, REQSTATUS)
|
||||
VALUES ('$reffid', '$visitnum', '$visitdt', '$agentname', '$doc', '$loc', '$patid', '$company', '$createdt', '$bw', '$bh', '$visitdesc', '$visittype', '$reqstatus' )";
|
||||
//$db->query($sql); $reqid = $db->insertID();
|
||||
echo "$sql";
|
||||
} else { // existing request
|
||||
$sql = "UPDATE cmod.dbo.CM_TM_REQUESTS SET REQNUMBER='$visitnum', REQDATE='$visitdt', AGENT='$agentname', DOC='$doc', LOC='$loc', PATID='$patid',
|
||||
COMPANY='$company',LOGDATE='$createdt', BW='$bw', BH='$bh', VISITDESC='$visitdesc', VISITTYPE='$visittype', REQSTATUS='$reqstatus'
|
||||
where REQID='$reqid'";
|
||||
//$db->query($sql);
|
||||
echo "$sql";
|
||||
}
|
||||
}
|
||||
/*
|
||||
if(!isset($results[0])) {
|
||||
$sql = "INSERT INTO cmod.dbo.CM_TM_PATIENTS (PATNUMBER, FIRSTNAME, LASTNAME, BIRTHDATE, SEX, PHONE ) VALUES ('$rm', '$firstname', '$lastname', '$dob', '$sex', '$phone' )";
|
||||
$db->query($sql);
|
||||
@ -126,7 +165,6 @@ class API_TM extends ResourceController {
|
||||
$sql = "UPDATE cmod.dbo.CM_TM_PATIENTS SET FIRSTNAME='$firstname', LASTNAME='$lastname', BIRTHDATE='$dob', SEX='$sex', PHONE='$phone' where PATID='$patid'";
|
||||
$db->query($sql);
|
||||
}
|
||||
//echo "$reffid";
|
||||
|
||||
$sql = "select REQID from cmod.dbo.CM_TM_REQUESTS where REFFID='$reffid'";
|
||||
$query = $db->query($sql);
|
||||
@ -173,6 +211,7 @@ class API_TM extends ResourceController {
|
||||
$this->orm($reqid);
|
||||
|
||||
return $this->respond(201);
|
||||
*/
|
||||
}
|
||||
|
||||
public function orm($reqid) {
|
||||
@ -252,12 +291,12 @@ class API_TM extends ResourceController {
|
||||
public function create_result_json($accessnumber) {
|
||||
$db = \Config\Database::connect();
|
||||
$sql = "select r.HOSTORDERNUMBER, r.SP_HOSPNUMBER, cr.REQNUMBER, cr.LOC, cr.COMPANY, cr.AGENT, cr.VISITDESC, cr.VISITTYPE,
|
||||
p.PATNUMBER, cp.LASTNAME, cp.FIRSTNAME, p.BIRTHDATE, p.SEX, p.TELEPHON, r.COLLECTIONDATE, cr.AGENT, cr.DOC, cr.BW, cr.BH
|
||||
from SP_REQUESTS r
|
||||
left join cmod.dbo.CM_TM_REQUESTS cr on cr.REFFID=r.HOSTORDERNUMBER
|
||||
left join PATIENTS p on p.PATID=r.PATID
|
||||
left join cmod.dbo.CM_TM_PATIENTS cp on cp.PATNUMBER=right(p.PATNUMBER,8)
|
||||
where r.SP_ACCESSNUMBER='$accessnumber'";
|
||||
p.PATNUMBER, cp.LASTNAME, cp.FIRSTNAME, p.BIRTHDATE, p.SEX, p.TELEPHON, r.COLLECTIONDATE, cr.AGENT, cr.DOC, cr.BW, cr.BH
|
||||
from SP_REQUESTS r
|
||||
left join cmod.dbo.CM_TM_REQUESTS cr on cr.REFFID=r.HOSTORDERNUMBER
|
||||
left join PATIENTS p on p.PATID=r.PATID
|
||||
left join cmod.dbo.CM_TM_PATIENTS cp on cp.PATNUMBER=right(p.PATNUMBER,8)
|
||||
where r.SP_ACCESSNUMBER='$accessnumber'";
|
||||
$query = $db->query($sql);
|
||||
$results = $query->getResultArray();
|
||||
|
||||
@ -315,25 +354,25 @@ where r.SP_ACCESSNUMBER='$accessnumber'";
|
||||
];
|
||||
|
||||
$sql = "select dc.CHAPID, t.DEPTH as depth_test, dc.FULLTEXT as chap_eng, dc.FULLTEXT as chap_ind, st.FULLTEXT as serum_type,
|
||||
cdt.TEXT1 as test_eng, cdt.TEXT2 as test_ind, cdt.UNIT as UNITTEXT, cdt.REFFTEXT, t.NOTPRINTABLE, cr.RESSTATUS,
|
||||
t.TESTORDER, t.RESTYPE as code_type, t.VALIDATIONINITIALS as validator, dt.SHORTTEXT,
|
||||
RESULT = case when t.RESVALUE is null then tx.FULLTEXT else t.RESVALUE end, ct.REFFTESTID, m.HISCODE, m.LISCODE,
|
||||
tub.TUBENAME, cr.REFRANGE, dt.TESTCODE, t.TESTORDER, dt.UNITS, cr.RESDATE, cr.USERVAL, u.USERNAME
|
||||
from REQUESTS r
|
||||
left join TESTS t on t.REQUESTID = r.REQUESTID
|
||||
left join DICT_TESTS dt on dt.ENDVALIDDATE is null and t.TESTID=dt.TESTID
|
||||
left join DICT_TEXTS tx on tx.TEXTID=t.CODEDRESULTID
|
||||
left join DICT_CHAPTERS dc on dc.CHAPID=dt.CHAPID and dc.ENDVALIDDATE is null
|
||||
left join DICT_TEST_SAMPLES ts on ts.TESTID=t.TESTID and dt.TESTID=ts.TESTID
|
||||
left join DICT_SAMPLES_TYPES st on st.SAMPTYPEID=ts.SAMPTYPEID
|
||||
left join cmod.dbo.CM_DICT_TESTS cdt on dt.TESTCODE=cdt.TESTCODE
|
||||
left join cmod.dbo.CM_RESULTS cr on cr.ACCESSNUMBER=r.ACCESSNUMBER and cr.TESTCODE=cdt.TESTCODE and cr.TESTCODE=dt.TESTCODE and t.RESUPDDATE=cr.RESDATE
|
||||
left join cmod.dbo.CM_TM_REQUESTS cq on cq.REFFID=r.EXTERNALORDERNUMBER
|
||||
left join cmod.dbo.CM_TM_TESTS ct on ct.REQID=cq.REQID
|
||||
left join cmod.dbo.CM_DICT_MAPPINGS m on m.LISCODE=cr.TESTCODE and m.HISCODE=ct.HISCODE
|
||||
left join cmod.dbo.CM_DICT_TUBES tub on tub.TUBEID=m.TUBEID
|
||||
left join USERS u on u.USERINITIALS=cr.USERVAL
|
||||
where r.ACCESSNUMBER='$accessnumber' and t.NOTPRINTABLE is null ORDER BY t.TESTORDER";
|
||||
cdt.TEXT1 as test_eng, cdt.TEXT2 as test_ind, cdt.UNIT as UNITTEXT, cdt.REFFTEXT, t.NOTPRINTABLE, cr.RESSTATUS,
|
||||
t.TESTORDER, t.RESTYPE as code_type, t.VALIDATIONINITIALS as validator, dt.SHORTTEXT,
|
||||
RESULT = case when t.RESVALUE is null then tx.FULLTEXT else t.RESVALUE end, ct.REFFTESTID, m.HISCODE, m.LISCODE,
|
||||
tub.TUBENAME, cr.REFRANGE, dt.TESTCODE, t.TESTORDER, dt.UNITS, cr.RESDATE, cr.USERVAL, u.USERNAME
|
||||
from REQUESTS r
|
||||
left join TESTS t on t.REQUESTID = r.REQUESTID
|
||||
left join DICT_TESTS dt on dt.ENDVALIDDATE is null and t.TESTID=dt.TESTID
|
||||
left join DICT_TEXTS tx on tx.TEXTID=t.CODEDRESULTID
|
||||
left join DICT_CHAPTERS dc on dc.CHAPID=dt.CHAPID and dc.ENDVALIDDATE is null
|
||||
left join DICT_TEST_SAMPLES ts on ts.TESTID=t.TESTID and dt.TESTID=ts.TESTID
|
||||
left join DICT_SAMPLES_TYPES st on st.SAMPTYPEID=ts.SAMPTYPEID
|
||||
left join cmod.dbo.CM_DICT_TESTS cdt on dt.TESTCODE=cdt.TESTCODE
|
||||
left join cmod.dbo.CM_RESULTS cr on cr.ACCESSNUMBER=r.ACCESSNUMBER and cr.TESTCODE=cdt.TESTCODE and cr.TESTCODE=dt.TESTCODE and t.RESUPDDATE=cr.RESDATE
|
||||
left join cmod.dbo.CM_TM_REQUESTS cq on cq.REFFID=r.EXTERNALORDERNUMBER
|
||||
left join cmod.dbo.CM_TM_TESTS ct on ct.REQID=cq.REQID
|
||||
left join cmod.dbo.CM_DICT_MAPPINGS m on m.LISCODE=cr.TESTCODE and m.HISCODE=ct.HISCODE
|
||||
left join cmod.dbo.CM_DICT_TUBES tub on tub.TUBEID=m.TUBEID
|
||||
left join USERS u on u.USERINITIALS=cr.USERVAL
|
||||
where r.ACCESSNUMBER='$accessnumber' and t.NOTPRINTABLE is null ORDER BY t.TESTORDER";
|
||||
$query = $db->query($sql);
|
||||
$test_results = $query->getResultArray();
|
||||
$d0=-1; $d1=-1; $d2=-1; $d3=-1;
|
||||
@ -399,14 +438,14 @@ where r.ACCESSNUMBER='$accessnumber' and t.NOTPRINTABLE is null ORDER BY t.TESTO
|
||||
}
|
||||
|
||||
$sql = "SELECT ds.SHORTTEXT,
|
||||
FORMAT(tu.COLLECTIONDATE, 'dd-MM-yyyy') AS RECVDATE,
|
||||
FORMAT(tu.COLLECTIONDATE, 'HH:mm') AS RECVTIME,
|
||||
FORMAT(ct.COLLECTIONDATE, 'dd-MM-yyyy') AS COLLDATE,
|
||||
FORMAT(ct.COLLECTIONDATE, 'HH:mm') AS COLLTIME
|
||||
FROM SP_TUBES tu
|
||||
LEFT JOIN DICT_SAMPLES_TYPES ds ON ds.SAMPCODE = tu.SAMPLETYPE
|
||||
LEFT JOIN cmod.dbo.CM_TUBES ct ON ct.SAMPLETYPE = tu.SAMPLETYPE AND ct.ACCESSNUMBER = tu.SP_ACCESSNUMBER
|
||||
WHERE tu.SP_ACCESSNUMBER = '$accessnumber';";
|
||||
FORMAT(tu.COLLECTIONDATE, 'dd-MM-yyyy') AS RECVDATE,
|
||||
FORMAT(tu.COLLECTIONDATE, 'HH:mm') AS RECVTIME,
|
||||
FORMAT(ct.COLLECTIONDATE, 'dd-MM-yyyy') AS COLLDATE,
|
||||
FORMAT(ct.COLLECTIONDATE, 'HH:mm') AS COLLTIME
|
||||
FROM SP_TUBES tu
|
||||
LEFT JOIN DICT_SAMPLES_TYPES ds ON ds.SAMPCODE = tu.SAMPLETYPE
|
||||
LEFT JOIN cmod.dbo.CM_TUBES ct ON ct.SAMPLETYPE = tu.SAMPLETYPE AND ct.ACCESSNUMBER = tu.SP_ACCESSNUMBER
|
||||
WHERE tu.SP_ACCESSNUMBER = '$accessnumber';";
|
||||
$query = $db->query($sql);
|
||||
$samples = $query->getResultArray();
|
||||
foreach ($samples as $data) {
|
||||
|
||||
@ -1,83 +0,0 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
class Auths extends BaseController {
|
||||
|
||||
public function loginDPS() {
|
||||
$file = "tokens/pbmc_dps.txt";
|
||||
//$TM_url = "https://staging-eklinik.pbmcgroup.com/api/token/create";
|
||||
$TM_url = "http://10.10.12.90:8001/api/token/create";
|
||||
$secret = "o7lf5DUxSuPKtDjlbqc2VuZD9WjQ5qAZ";
|
||||
$header = [ 'typ' => 'JWT', 'alg' => 'HS256' ];
|
||||
$payload = [
|
||||
'iat' => time(),
|
||||
'data'=> [
|
||||
'username'=>"pbmc_bali",
|
||||
'password'=>"J8e29XjLmDCFuQnk"
|
||||
]
|
||||
];
|
||||
$jwt = $this->createJWT($header, $payload, $secret);
|
||||
$this->token2file($TM_url, $jwt, $file);
|
||||
}
|
||||
|
||||
public function loginSBY() {
|
||||
$TM_url = "http://10.10.4.123:8001/api/token/create";
|
||||
$file = "tokens/pbmc_sby.txt";
|
||||
$secret = "o7lf5DUxSuPKtDjlbqc2VuZD9WjQ5qAZ";
|
||||
$header = [ 'typ' => 'JWT', 'alg' => 'HS256' ];
|
||||
$payload = [
|
||||
'iat' => time(),
|
||||
'data'=> [
|
||||
'username'=>"pbmc_surabaya",
|
||||
'password'=>"pgcWfdwX3qEt9zaC"
|
||||
]
|
||||
];
|
||||
$jwt = $this->createJWT($header, $payload, $secret);
|
||||
$this->token2file($TM_url, $jwt, $file);
|
||||
}
|
||||
|
||||
private function base64UrlEncode($data) {
|
||||
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
|
||||
}
|
||||
|
||||
private function createJWT($header, $payload, $secret) {
|
||||
$encodedHeader = $this->base64UrlEncode(json_encode($header));
|
||||
$encodedPayload = $this->base64UrlEncode(json_encode($payload));
|
||||
|
||||
$signature = hash_hmac('sha256', "$encodedHeader.$encodedPayload", $secret, true);
|
||||
$encodedSignature = $this->base64UrlEncode($signature);
|
||||
|
||||
// Combine to create the JWT
|
||||
$jwt = "$encodedHeader.$encodedPayload.$encodedSignature";
|
||||
return $jwt;
|
||||
}
|
||||
|
||||
private function token2file($TM_url, $jwt, $file ) {
|
||||
$client = \Config\Services::curlrequest();
|
||||
try {
|
||||
$response = $client->request('GET', $TM_url, [
|
||||
"headers" => [
|
||||
"AppCode" => "2",
|
||||
"Accept" => "application/json",
|
||||
"Authorization" => "Bearer $jwt"
|
||||
],
|
||||
"body" => '',
|
||||
"verify" => false
|
||||
]);
|
||||
|
||||
if ($response->getStatusCode() == 200) {
|
||||
$body = $response->getBody();
|
||||
$data = json_decode($body, true);
|
||||
$token = $data['data']['token'];
|
||||
if (file_put_contents($file, $token) !== false) {
|
||||
echo "Response saved to: " . $file . "<br/>";
|
||||
}
|
||||
} else {
|
||||
print_r($response);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
echo "Error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user