git.schokokeks.org
Repositories
Help
Report an Issue
bibweb.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
0277419
Branches
Tags
master
bibweb.git
lib
api.php
Neue API 2023
Bernd Wurst
commited
0277419
at 2023-08-05 10:58:24
api.php
Blame
History
Raw
<?php require_once("config.php"); $jwt_token = null; $jwt_refresh_token = null; # init API $base_url = $config['api_url']; $url = $base_url . 'login'; $data = [ "username" => $config['api_username'], "password" => $config['api_password'] ]; $options = array( 'http' => array( 'method' => 'POST', 'content' => json_encode( $data ), 'header'=> "Content-Type: application/json\r\n" . "Accept: application/json\r\n" ) ); $context = stream_context_create( $options ); $result = file_get_contents( $url, false, $context ); $response = json_decode( $result, true); $jwt_token = $response["token"]; $jwt_refresh_token = $response["refresh_token"]; function api_call($method, $url, $content = []) { global $jwt_token; global $base_url; $url = $base_url . $url; $options = array( 'http' => array( 'method' => strtoupper($method), 'content' => json_encode( $content ), 'header'=> "Content-Type: application/json\r\n" . "Accept: application/json\r\n" . "Authorization: Bearer ".$jwt_token."\r\n" ) ); $context = stream_context_create( $options ); $result = file_get_contents( $url, false, $context ); $response = json_decode( $result, true ); return $response; } require_once('vendor/autoload.php'); function format_number_api($number) { $phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance(); try { $phoneNumber = $phoneNumberUtil->parse($number, 'DE'); } catch (Exception $e) { return NULL; } if ($phoneNumberUtil->isValidNumber($phoneNumber)) { return $phoneNumberUtil->format($phoneNumber, \libphonenumber\PhoneNumberFormat::E164); } return NULL; }