Advertisement
Guest User

beu

a guest
Sep 21st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.45 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ERROR | E_PARSE);
  3. require 'client-php-master/autoload.php';
  4.  
  5. use SMSGatewayMe\Client\ApiClient;
  6. use SMSGatewayMe\Client\Configuration;
  7. use SMSGatewayMe\Client\Api\MessageApi;
  8. use SMSGatewayMe\Client\Model\SendMessageRequest;
  9.  
  10. // Configure client
  11. $config = Configuration::getDefaultConfiguration();
  12. $config->setApiKey('Authorization', 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhZG1pbiIsImlhdCI6MTUzNTEyNjI5OSwiZXhwIjo0MTAyNDQ0ODAwLCJ1aWQiOjQ1OTg4LCJyb2xlcyI6WyJST0xFX1VTRVIiXX0.L5X7H3kyLp94tkxZYRjAkhExfydsO9-jHgxSJEG0VKw');
  13. $apiClient = new ApiClient($config);
  14. $messageClient = new MessageApi($apiClient);
  15.  
  16. // Yii Libs
  17. $yii = dirname(__FILE__) . '/../framework/yii.php';
  18. $config = dirname(__FILE__) . '/../gym/protected/config/main.php';
  19.  
  20. require_once($yii);
  21. Yii::createWebApplication($config);
  22.  
  23.  
  24.  
  25.  
  26. header('Content-Type: text/html; charset=utf-8');
  27. $servername = "localhost";
  28. $username = "root";
  29. $password = "";
  30. $dbname = "gym";
  31.  
  32. // Ligação BD
  33. $conn = new mysqli($servername, $username, $password, $dbname);
  34. if ($conn->connect_error) {
  35.     die("Connection failed: " . $conn->connect_error);
  36. }
  37. mysqli_set_charset($conn,"utf8");
  38.  
  39. // Data sistema formado mes-dia
  40. $data = date("m-d");
  41.  
  42. // query bd
  43. $sql = "SELECT * FROM clientes WHERE DATE_FORMAT(data_nascimento,'%m-%d') = \"$data\"";
  44. $result = $conn->query($sql);
  45.  
  46. // log file
  47. $logfile = 'log.txt';
  48.  
  49. // verifica para quem vai enviar sms
  50. if ($result->num_rows > 0) {
  51.     $data = array();
  52.    
  53.     $requests = [];
  54.     // output de cada linha
  55.     while($row = $result->fetch_assoc()) {
  56.        
  57.     $id = $row["id"];  
  58.        
  59.         if ($array_response['status'] == 'ok') {
  60.         $partes_nome = explode(" ", $array_response['nome']);
  61.         $nome = $partes_nome[0] . " ";
  62.         if (count($partes_nome)-1 > 0)
  63.             $nome .= $partes_nome[count($partes_nome)-1];
  64.         echo 'Olá '.$nome.'<br>';
  65.         if (isset($array_response['parabens'])) {
  66.             echo $array_response['parabens'] . "<br>";
  67.         }  
  68.         if (isset($array_response['pagamento'])) {
  69.             echo $array_response['pagamento'] . "<br>";
  70.         }
  71.         if (isset($array_response['n_dias'])) {
  72.             echo $array_response['n_dias'] . "<br>";
  73.         }  
  74.         if (isset($array_response['seguro'])) {
  75.             echo $array_response['seguro'] . "<br>";
  76.         }
  77.        
  78.             echo 'OK !';
  79.         } else {   
  80.             echo 'Xupa!';
  81.         }  
  82.    
  83.        
  84.         // ISTO TA A MAIS
  85.         //$id = isset($_POST['rfidtag']) ? (int)str_replace(" ", "",$_POST['rfidtag']) : 0;
  86.        
  87.        
  88.         // mensagem de parabens
  89.         $nome_cliente = '';
  90.         echo $birthday_msg = 'Bom dia ' .strtok($row["nome"], " "). ', sabemos que hoje e o teu aniversario e como tal um dia muito especial. Fica a saber que para nos nao es apenas mais um cliente, mas sim alguem muito importante a quem gostariamos de felicitar com um enorme PARABENS. A equipa do Ginasio Bestshape';
  91.         $telefone = '+351'.$row["telefone"];
  92.  
  93.        
  94.         //dados para envio de sms      
  95.        
  96.         $requests[] = new SendMessageRequest([
  97.             'phoneNumber' => $telefone,
  98.             'message' => $birthday_msg,
  99.             'deviceId' => 99867
  100.         ]);
  101.            
  102.             //log para ficheiro
  103.             $data_envio = date("Y-m-d H:i:s");
  104.             file_put_contents($logfile, '('.$data_envio.' - '.$telefone.') '.$birthday_msg."\n", FILE_APPEND);
  105.     }
  106.        
  107.         // envia as sms
  108.         //$sendMessages = $messageClient->sendMessages($requests);
  109.  
  110.    
  111. } else {
  112.     $data_envio = date("Y-m-d H:i:s");
  113.     file_put_contents($logfile, '('.$data_envio.') '."Sem mensagens para enviar!"."\n", FILE_APPEND);
  114. }
  115.  
  116. var_dump($sendMessages);
  117.  
  118.  
  119. // fecha a ligação a bd
  120. $conn->close();
  121. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement