Advertisement
Guest User

parabens

a guest
Sep 21st, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.44 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.  
  17.  
  18.  
  19.  
  20.  
  21. header('Content-Type: text/html; charset=utf-8');
  22. $servername = "localhost";
  23. $username = "root";
  24. $password = "";
  25. $dbname = "gym";
  26.  
  27. // Ligação BD
  28. $conn = new mysqli($servername, $username, $password, $dbname);
  29. if ($conn->connect_error) {
  30.     die("Connection failed: " . $conn->connect_error);
  31. }
  32. mysqli_set_charset($conn,"utf8");
  33.  
  34. // Data sistema formado mes-dia
  35. $data = date("m-d");
  36.  
  37. // query bd
  38. $sql = "SELECT * FROM clientes WHERE DATE_FORMAT(data_nascimento,'%m-%d') = \"$data\"";
  39. $result = $conn->query($sql);
  40.  
  41. // log file
  42. $logfile = 'log.txt';
  43.  
  44. // verifica para quem vai enviar sms
  45. if ($result->num_rows > 0) {
  46.     $data = array();
  47.    
  48.     $requests = [];
  49.     // output de cada linha
  50.     while($row = $result->fetch_assoc()) {
  51.        
  52.         // mensagem de parabens
  53.         $nome_cliente = '';
  54.         $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';
  55.         $telefone = '+351'.$row["telefone"];
  56.        
  57.         //dados para envio de sms      
  58.        
  59.         $requests[] = new SendMessageRequest([
  60.             'phoneNumber' => $telefone,
  61.             'message' => $birthday_msg,
  62.             'deviceId' => 99867
  63.         ]);
  64.            
  65.             //log para ficheiro
  66.             $data_envio = date("Y-m-d H:i:s");
  67.             file_put_contents($logfile, '('.$data_envio.' - '.$telefone.') '.$birthday_msg."\n", FILE_APPEND);
  68.     }
  69.        
  70.         // envia as sms
  71.         $sendMessages = $messageClient->sendMessages($requests);
  72.  
  73.    
  74. } else {
  75.     $data_envio = date("Y-m-d H:i:s");
  76.     file_put_contents($logfile, '('.$data_envio.') '."Sem mensagens para enviar!"."\n", FILE_APPEND);
  77. }
  78.  
  79. var_dump($sendMessages);
  80.  
  81.  
  82. // fecha a ligação a bd
  83. $conn->close();
  84. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement