Advertisement
Guest User

ddsds

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