0277419db67fa1850d056e5b3f769a7d9621501e
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

1) <?php
2) 
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

3) require_once("config.php");
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

4) 
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

5) $jwt_token = null;
6) $jwt_refresh_token = null;
Bernd Wurst besserer Debug-Modus, Handh...

Bernd Wurst authored 3 years ago

7) 
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

8) # init API
9) $base_url = $config['api_url'];
10) $url = $base_url . 'login';
11) $data = [
12)     "username" => $config['api_username'],
13)     "password" => $config['api_password']
14) ];
15) $options = array(
16)   'http' => array(
17)     'method'  => 'POST',
18)     'content' => json_encode( $data ),
19)     'header'=>  "Content-Type: application/json\r\n" .
20)                 "Accept: application/json\r\n"
21)     )
22) );
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

23) 
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

24) $context  = stream_context_create( $options );
25) $result = file_get_contents( $url, false, $context );
26) $response = json_decode( $result, true);
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

27) 
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

28) $jwt_token = $response["token"];
29) $jwt_refresh_token = $response["refresh_token"];
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

30) 
31) 
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

32) function api_call($method, $url, $content = []) {
33)     global $jwt_token;
34)     global $base_url;
35)     $url = $base_url . $url;
36)     $options = array(
37)       'http' => array(
38)         'method'  => strtoupper($method),
39)         'content' => json_encode( $content ),
40)         'header'=>  "Content-Type: application/json\r\n" .
41)                     "Accept: application/json\r\n" .
42)                     "Authorization: Bearer ".$jwt_token."\r\n"
43)         )
44)     );
Bernd Wurst besserer Debug-Modus, Handh...

Bernd Wurst authored 3 years ago

45) 
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

46)     $context  = stream_context_create( $options );
47)     $result = file_get_contents( $url, false, $context );
48)     $response = json_decode( $result, true );
49)     return $response;
50) }
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

51) 
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

52) require_once('vendor/autoload.php');
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

53) 
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

54) function format_number_api($number) {
55)     $phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance();
56)     try {
57)         $phoneNumber = $phoneNumberUtil->parse($number, 'DE');
58)     } catch (Exception $e) {
59)         return NULL;
Bernd Wurst besserer Debug-Modus, Handh...

Bernd Wurst authored 3 years ago

60)     }
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

61)     if ($phoneNumberUtil->isValidNumber($phoneNumber)) {
62)         return $phoneNumberUtil->format($phoneNumber, \libphonenumber\PhoneNumberFormat::E164);
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

63)     }
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

64)     return NULL;