Beispiel #1
1
 function send_to_ios($apnsHost, $apnsCertPath, $device_token, $data)
 {
     header('Content-Type: text/html; charset=UTF-8');
     $deviceToken = $device_token;
     /*
      * $apnsHost
      * development : gateway.sandbox.push.apple.com
      * deployment : gateway.push.apple.com
      */
     $apnsPort = 2195;
     $alert = '';
     if (array_key_exists('ios_alert', $data)) {
         $alert = $data['ios_alert'];
     }
     $payload = array('aps' => array('alert' => $alert, 'badge' => 0, 'sound' => 'default'));
     if (array_key_exists('ios_custom', $data)) {
         $payload['ios_custom'] = $data['ios_custom'];
     }
     $payload = json_encode($payload);
     $streamContext = stream_context_create();
     stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCertPath);
     $apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
     if ($apns) {
         $apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;
         fwrite($apns, $apnsMessage);
         fclose($apns);
         return TRUE;
     }
     //middle.error.log
     MDI_Log::write('IOS_PUSH_ERROR-' . $this->input->ip_address() . '-' . $this->input->user_agent() . '-' . current_url());
     return FALSE;
 }
 function _remap($method, $args = array())
 {
     try {
         if (method_exists($this, $method)) {
             if ($this->_pre_execute($method, $args)) {
                 call_user_func_array(array(&$this, $method), $args);
             }
         } else {
             show_404(get_class($this) . '/' . $method);
         }
     } catch (Exception $e) {
         MDI_Log::write($e->getMessage());
         mdi::error(json_encode(array('error' => $e->getMessage(), 'code' => ERROR_CODE_DEFAULT)));
     }
 }
Beispiel #3
0
 public function send($name, $from, $to, $subject, $content)
 {
     $ci = $this->getCI();
     $ci->email->set_newline("\r\n");
     $ci->email->clear();
     $ci->email->from($from, $name);
     $ci->email->to($to);
     $ci->email->subject($subject);
     $ci->email->message($content);
     if ($ci->email->send()) {
         return TRUE;
     } else {
         MDI_Log::write($ci->email->print_debugger());
         return FALSE;
     }
 }
Beispiel #4
0
 public static function write($text)
 {
     $log = new MDI_Log();
     $log->text = $text;
     $log->save();
 }