GlisWeb framework
_skebby.tools.php
Vai alla documentazione di questo file.
1 <?php
2 
23  function skebbySend( $testo, $to, $user = NULL, $pasw = NULL, $from = NULL, $type = 'TI', $url = 'https://api.skebby.it/API/v1.0/REST/' ) {
24 
25  // risultato
26  $result = false;
27 
28  // autenticazione
29  $auth = restCall(
30  $url . 'login?username=' . $user . '&password=' . $pasw,
31  METHOD_GET,
32  NULL,
33  'application/json',
34  'text/plain',
35  $status
36  );
37 
38  // ricavo i parametri per l'autenticazione
39  $auths = explode( ';', $auth );
40 
41  // debug
42  // var_dump( $status );
43  // echo $url . PHP_EOL;
44  // print_r( $auths );
45 
46  // se ho l'autenticazione
47  if( $status == 200 ) {
48 
49  // log
50  logWrite( 'autenticazione su Skebby effettuata con successo: ' . $auth, 'skebby', LOG_NOTICE );
51 
52  // dati
53  $dati = array(
54  'returnCredits' => true,
55  'recipient' => $to,
56  'message' => $testo,
57  'message_type' => $type,
58  'sender' => $from
59  );
60 
61  // headers
62  $headers = array(
63  'user_key' => $auths[0],
64  'Session_key' => $auths[1]
65  );
66 
67  // invio
68  $result = restCall(
69  $url . 'sms',
71  $dati,
72  'application/json',
73  'application/json',
74  $status,
75  $headers
76  );
77 
78  // log
79  logWrite( 'esito invio: ' . print_r( $result, true ), 'skebby', LOG_NOTICE );
80 
81  // debug
82  // var_dump( json_decode( $status, true ) );
83 
84  // risultato
85  if( $result['result'] == 'OK' ) {
86  return true;
87  } else {
88  logWrite( 'fallito invio: ' . print_r( $result, true ), 'skebby', LOG_CRIT );
89  return false;
90  }
91 
92  } else {
93 
94  // log
95  logWrite( 'errore di autenticazione su Skebby: ' . $auth, 'skebby', LOG_CRIT );
96 
97  // risultato
98  return false;
99 
100  }
101 
102  // risultato
103  return $result;
104 
105  }
106 
107 ?>
logWrite( $m, $f='site', $l=LOG_NOTICE, $d=DIRECTORY_LOG, $t=CURRENT_LOG_LEVEL, $s=SITE_STATUS)
scrive un messaggio nei log del sito
Definition: _log.utils.php:48
restCall( $url, $method=METHOD_GET, $data=NULL, $datatype=MIME_APPLICATION_JSON, $answertype=MIME_APPLICATION_JSON, &$status=NULL, $headers=array(), $user=NULL, $pasw=NULL, &$error=NULL)
esegue una chiamata REST
Definition: _rest.tools.php:23
const METHOD_POST
Definition: _config.php:282
skebbySend( $testo, $to, $user=NULL, $pasw=NULL, $from=NULL, $type='TI', $url='https://api.skebby.it/API/v1.0/REST/')
const METHOD_GET
Definition: _config.php:280