コード例 #1
0
            $queryTokenGCM->bindParam(":group", $group);
            $queryTokenAPN = $handler->prepare("SELECT `deviceToken` FROM `user` WHERE length(trim(`deviceToken`))=64 and`group`=:group");
            $queryTokenAPN->bindParam(":group", $group);
        }
        if ($queryTokenGCM->execute()) {
            $countTokenGCM = $queryTokenGCM->rowCount();
            if ($countTokenGCM > 0) {
                //$gcmResults = $queryTokenGCM->fetchAll(PDO::FETCH_ASSOC);
                $gcmTokens = $queryTokenGCM->fetchAll(PDO::FETCH_COLUMN, 0);
                //echo "new line " . $gcmResults . 'deviceToken';
                //print_r(array_values($gcmResults));
                //$gcmTokens = array_column($gcmResults, 'deviceToken');
                //echo "find error1";
                //$gcmTokens = array_column($gcmResults, 'deviceToken');
                //echo "find error2";
                send_gcm_notify($gcmTokens, $message);
            }
        }
        if ($queryTokenAPN->execute()) {
            $countTokenAPN = $queryTokenAPN->rowCount();
            if ($countTokenAPN > 0) {
                //$apnResults = $queryTokenAPN->fetchAll(PDO::FETCH_ASSOC);
                //$apnTokens = array_column($apnResults, 'deviceToken');
                $apnTokens = $queryTokenAPN->fetchAll(PDO::FETCH_COLUMN, 0);
                send_apn_notify($apnTokens, $message);
            }
        }
    }
} catch (Exception $e) {
    respf("ERROR", "NULL", $e);
}
コード例 #2
0
    // pass varialbe $instantSpeed to SQL parameter ":InstantSpeed"
    if ($query->execute()) {
        //echo "it has been inserted id=" . $handler->lastInsertId();
        $results = "it has been inserted: id=" . $handler->lastInsertId();
        respf("SUCCESS", $results, "");
        //get device tokens from group
        $queryToken = $handler->prepare("SELECT `deviceToken` FROM `user` WHERE `group`=:group");
        $queryToken->bindParam(":group", $group);
        if ($queryToken->execute()) {
            //$countToken = $queryToken->rowCount();
            if ($countToken > 0) {
                while ($row = $queryToken->fetch(PDO::FETCH_ASSOC)) {
                    if (strlen($row['deviceToken']) == 140) {
                        send_gcm_notify($row['deviceToken'], $message);
                    } elseif (strlen($row['deviceToken']) == 64) {
                        send_apn_notify($row['deviceToken'], $message);
                    } else {
                        echo "no push for " . ${$row}['deviceToken'];
                    }
                }
            }
        }
        //$deviceTokens = ["APA91bEwH6Oc9s4BO1OWHutah-rB9KefrH4m-6gCoTiquxJ15Ji12b0GetHbBwp6F2PIgbHZKfREssgif6HSDqaz-Xp-eQ9sIQ56bp4pM644tgRmHn5AVwWq4D6vNx5hMqBoXRTcqjGH", "APA91bHlR9ZzGXFRzqfe4pZ-JHBLwz78vD8ftJTEf-UsoEO8dKyconSYGKouT6JGmWI9oAuqRDUsKlujwdJPuRBwFEw2ZVSke1Ech5zSWqpA5YL4rCj63TOVodLuZNuQCnRwKwfHDnGV"];
        //sendMessage($deviceTokens, $handler->lastInsertId(), "2");
    }
    //$reg_id = "APA91bGVFQzwDmP0Eb2FVf6lYKKpchcp_3Y-lnn4fq87D_d_64vBqG_XBk4qy2tihyAiBwX9Bg8Owv8xAQgELtvqIjv9TVIu96sKZCXCdAWVM4YBmOJBAJ_9OkZfFz9jGGFWx7ijMQX5";
    //$msg = "Google Cloud Messaging working well";
    //send_gcm_notify($reg_id, $msg);
} catch (Exception $e) {
    //echo $e->getMessage();
    respf("ERROR", "NULL", $e);