Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Api {
- /**
- * Токен устройства iPhone
- * @var string
- */
- private $token = '';
- /**
- * Секретная фраза привязанная к .pem файлу
- * @var string
- */
- private $secret = '';
- /**
- * Отправляемое сообщение
- * @var string
- */
- private $message = '';
- /**
- * Путь и имя файла сертификата (.pem)
- * @var string
- */
- private $cert = '';
- /**
- * Массив тела запроса к серверу
- * @var array
- */
- private $body = [];
- /**
- * Токен устройства iPhone
- * @var MySQLi object
- */
- private $mysqli = false;
- public function __construct($token, $secret, $cert) {
- $this->token = $token;
- $this->secret = $secret;
- $this->cert = $cert;
- $this->mysqli = $this->connectDB();
- }
- public function setMessage($message) {
- $this->message = $message;
- }
- public function setBody($body) {
- if(is_array($body)&&isset($body['aps'])) {
- $this->body = $body;
- }
- }
- public function makeRequest() {
- $ctx = stream_context_create();
- stream_context_set_option($ctx, 'ssl', 'local_cert', $this->cert);
- stream_context_set_option($ctx, 'ssl', 'passphrase', $this->secret);
- $fp = stream_socket_client(
- 'ssl://gateway.sandbox.push.apple.com:2195', $err,
- $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ct
- );
- }
- private function connectDB() {
- if(!$this->mysqli) {
- $mysqli = new mysqli('localhost', 'meatoff', '95934355', 'namaz_time');
- $mysqli->set_charset("utf8");
- return $mysqli;
- } else {
- return $this->mysqli;
- }
- }
- public function checkDate() {
- $res = $mysqli->query("SELECT `first`, `secont`, `third`, `fourth`, `fifth`, `sixth` FROM `namaz` WHERE `date` = '".date('Y-m-d')."'");
- $message = '';
- while($rows = $res->fetch_assoc()) {
- foreach($rows as $row) {
- $diff = diff($row);
- if($diff->h==0&&$diff->i < 40) {
- $message = "Намаз случится через: ".$diff->i." минут";
- }
- }
- }
- return $message;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment