Beispiel #1
0
function sendMessageNotificationToIOS($breakerID, $breaker_name, $toUserBreakerID, $message, $deviceToken)
{
    //print_r($deviceToken);
    /*$payload ='{
                     "aps":
                         { "alert" : "'.$message.'",
                          "badge" : 1,
                          "sound" : "default"
                         }
                 }';
      */
    $apple_identifier = "gateway.push.apple.com";
    $body = array();
    $body['aps'] = array('alert' => 'This is push message');
    $body['aps']['badge'] = 2;
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', dirname(__FILE__) . '/ck.pem');
    stream_context_set_option($ctx, 'ssl', 'passphrase', 'raju');
    $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
    //$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
    if ($fp) {
        print "Notification sent  >>>  ";
        $payload = json_encode($body);
        // Enhanced Notification
        $msg = pack("C", 1) . pack("n", 32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n", strlen($payload)) . $payload;
        // SEND PUSH
        $result = fwrite($fp, $msg);
        if (!$result) {
            echo 'Message not delivered !';
        } else {
            echo 'Message successfully delivered ';
        }
        //$result = fwrite($fp, $msg, strlen($msg));
        // We can check if an error has been returned while we are sending, but we also need to
        // check once more after we are done sending in case there was a delay with error response.
        checkAppleErrorResponse($fp);
    } else {
        print "Failed to connect {$err} {$errstr}";
        return;
    }
    //checkAppleErrorResponse($fp);
    echo 'Completed';
    fclose($fp);
}
Beispiel #2
0
        $sql = 'SELECT PUSH_ID FROM op_users WHERE STATUS=1 AND PUSH_ID!="" ' . $where_string;
        $result = $db_user->query($sql);
        $apnsHost = 'gateway.push.apple.com';
        $apnsCert = dirname(__FILE__) . '/purple_production.pem';
        $apnsPort = 2195;
        $payload = array('aps' => array('alert' => $message, 'badge' => 0, 'sound' => 'default'));
        $payload = json_encode($payload);
        $streamContext = stream_context_create();
        stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
        $apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
        stream_set_blocking($apns, 0);
        while ($row =& $result->fetchRow()) {
            if ($apns) {
                $apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace('%', '', $row['PUSH_ID'])) . chr(0) . chr(strlen($payload)) . $payload;
                fwrite($apns, $apnsMessage);
                if (checkAppleErrorResponse($apns) == false) {
                    $success_count++;
                } else {
                    $fail_count++;
                }
            } else {
                $fail_count++;
            }
            $count++;
        }
        $db_user->disconnect();
    }
    $sql = 'UPDATE op_push_messages SET
		IS_PROCESSED=1,
                FINISH_DATE=NOW(),
                TOTAL_USER_COUNT=' . $count . ',
Beispiel #3
0
function sendAPNSMessage($xid, $push_token, $message, $badge_count, $payload)
{
    $sound = 'default';
    // 개발용 서버 설정
    $apnsHost = 'gateway.push.apple.com';
    $apnsCert = get_instance()->config->item('apns_key_path');
    //$apnsCert = '/Users/doogoon/Documents/Work/DOOGOON/nrj/apns_key/cf.pem';
    //$apnsCert = 'cert.pem';
    //$apnsCert = 'apns-dev.pem';
    // 실서비스용 서버 설정
    //$apnsHost = 'gateway.push.apple.com';
    //$apnsCert = 'apns-prod.pem';
    $apnsPort = 2195;
    $msgBody = array();
    $msgBody['aps'] = array('alert' => $message);
    $msgBody['aps']['badge'] = $badge_count ? $badge_count : 1;
    $msgBody['aps']['sound'] = $sound ? $sound : 'default';
    $msgBody['aps']['payload'] = $payload;
    //$msgBody['aps']['payload'] = $payload;
    // APNS서버와 SSL 소켓 통신
    $streamCtxt = stream_context_create();
    stream_context_set_option($streamCtxt, 'ssl', 'local_cert', $apnsCert);
    //stream_context_set_option($streamCtxt, 'ssl', 'passphrase', 'cf1234');
    $fp = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $err, $errstr, 30, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT, $streamCtxt);
    stream_set_blocking($fp, 0);
    if (!$fp) {
        log_message('error', "APNS Fail Connection!!!");
        log_message('error', "[{$err}]{$errstr} \n");
        exit;
    } else {
        // 보낼 내용을 json 포맷으로 인코딩
        $payload = json_encode($msgBody);
        $apple_expiry = time() + 90 * 24 * 60 * 60;
        //$apnsMsg = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $push_token)) .chr(0) . chr(strlen($payload)) . $payload;
        $apnsMsg = pack("C", 1) . pack("N", $xid) . pack("N", $xid) . pack("n", 32) . pack('H*', str_replace(' ', '', $push_token)) . pack("n", strlen($payload)) . $payload;
        //Enhanced Notification
        $fwrite = fwrite($fp, $apnsMsg);
        log_message('info', 'APNS Push Send!! ///////////////////////////////');
        log_message('info', 'XID :: ' . $xid);
        log_message('info', 'TOKEN :: ' . $push_token);
        log_message('info', 'DATA :: ' . $payload);
        log_message('info', 'RESULT :: ' . checkAppleErrorResponse($fp));
    }
    fclose($fp);
}