GlisWeb framework
_ehiweb.tools.php
Vai alla documentazione di questo file.
1 <?php
2 
23  function ehiwebSend( $testo, $to, $user = NULL, $pasw = NULL, $from = NULL, $id_api = NULL, $url = 'https://secure.apisms.it/http/send_sms' ) {
24 
25  // risultato
26  $result = NULL;
27 
28  // destinatari multipli
29  if( is_array( $to ) ) {
30 
31  // invio multiplo
32  foreach( $to as $ds ) {
33  $rs = ehiwebSend( $testo, $ds, $user, $pasw, $from, $id_api, $url );
34  if( $result !== false ) { $result = $rs; }
35  }
36 
37  } else {
38 
39  // se il mittente è un array
40  if( is_array( $from ) ) {
41  $sender = array_shift( array_keys( $from ) );
42  $from = array_shift( $from );
43  }
44 
45  // pulizia destinatario
46  $to = str_replace( '+', NULL, $to );
47  $to = str_replace( '.', NULL, $to );
48  $to = str_replace( '/', NULL, $to );
49  $to = str_replace( ' ', NULL, $to );
50  $to = ltrim( $to, '0' );
51 
52  // BRUTTISSIMO rendere più flessibile
53  if( substr( $to, 0, 2 ) != '39' ) { $to = '39' . $to; }
54 
55  // pulisco il body
56 # $testo = filter_var( $testo, FILTER_SANITIZE_FULL_SPECIAL_CHARS );
57  $testo = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $testo);
58 
59  // log
60  logWrite( 'invio a ' . $to . ' da ' . $from . ': ' . $testo, 'ehiweb', LOG_DEBUG );
61 
62  // invio
63  $result = restCall(
64  $url,
66  array(
67  'authlogin' => $user,
68  'authpasswd' => $pasw,
69  'body' => base64_encode( $testo ),
70  'destination' => $to,
71  'id_api' => $id_api,
72  'sender' => base64_encode( $from )
73  ),
74  'multipart/form-data',
75  'text/plain',
76  $status
77  );
78 
79  // debug
80  // var_dump( $status );
81  // var_dump( $result );
82 
83  // risultato
84  if( substr( $result, 0, 1 ) == '+' ) {
85  logWrite( 'SMS inviato: ' . $result, 'ehiweb', LOG_NOTICE );
86  return true;
87  } else {
88  logWrite( 'fallito invio: ' . $result, 'ehiweb', LOG_CRIT );
89  return false;
90  }
91 
92  }
93 
94  // risultato
95  return $result;
96 
97  }
98 
99 ?>
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
ehiwebSend( $testo, $to, $user=NULL, $pasw=NULL, $from=NULL, $id_api=NULL, $url='https://secure.apisms.it/http/send_sms')