Guest User

Untitled

a guest
Mar 25th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.05 KB | None | 0 0
  1. <?php
  2. class Api {
  3.     /**
  4.     * Токен устройства iPhone
  5.     * @var string
  6.     */
  7.     private $token = '';
  8.     /**
  9.     * Секретная фраза привязанная к .pem файлу
  10.     * @var string
  11.     */
  12.     private $secret = '';
  13.     /**
  14.     * Отправляемое сообщение
  15.     * @var string
  16.     */
  17.     private $message = '';
  18.     /**
  19.     * Путь и имя файла сертификата (.pem)
  20.     * @var string
  21.     */
  22.     private $cert = '';
  23.     /**
  24.     * Массив тела запроса к серверу
  25.     * @var array
  26.     */
  27.     private $body = [];
  28.     /**
  29.     * Токен устройства iPhone
  30.     * @var MySQLi object
  31.     */
  32.     private $mysqli = false;
  33.  
  34.     public function __construct($token, $secret, $cert) {
  35.         $this->token = $token;
  36.         $this->secret = $secret;
  37.         $this->cert = $cert;
  38.         $this->mysqli = $this->connectDB();
  39.     }
  40.     public function setMessage($message) {
  41.         $this->message = $message;
  42.     }
  43.     public function setBody($body) {
  44.         if(is_array($body)&&isset($body['aps'])) {
  45.             $this->body = $body;
  46.         }
  47.     }
  48.     public function makeRequest() {
  49.         $ctx = stream_context_create();
  50.         stream_context_set_option($ctx, 'ssl', 'local_cert', $this->cert);
  51.         stream_context_set_option($ctx, 'ssl', 'passphrase', $this->secret);
  52.         $fp = stream_socket_client(
  53.             'ssl://gateway.sandbox.push.apple.com:2195', $err,
  54.             $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ct
  55.         );
  56.     }
  57.     private function connectDB() {
  58.         if(!$this->mysqli) {
  59.             $mysqli = new mysqli('localhost', 'meatoff', '95934355', 'namaz_time');
  60.             $mysqli->set_charset("utf8");
  61.             return $mysqli;
  62.         } else {
  63.             return $this->mysqli;
  64.         }
  65.     }
  66.     public function checkDate() {
  67.         $res = $mysqli->query("SELECT `first`, `secont`, `third`, `fourth`, `fifth`, `sixth` FROM `namaz` WHERE `date` = '".date('Y-m-d')."'");
  68.         $message = '';
  69.         while($rows = $res->fetch_assoc()) {
  70.             foreach($rows as $row) {
  71.                 $diff = diff($row);
  72.                 if($diff->h==0&&$diff->i < 40) {
  73.                     $message = "Намаз случится через: ".$diff->i." минут";
  74.                 }
  75.             }
  76.         }
  77.         return $message;
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment