Ver3.0 ๐ฑ PHP์ Firebase Cloud Messaging์ผ๋ก ์๋ฒฝํ๊ฒ ๊ตฌํํ๋ ๋ชจ๋ฐ์ผ ํธ์ ์๋ฆผ ์์คํ

๐ฑ PHP์ Firebase Cloud Messaging์ผ๋ก ์๋ฒฝํ๊ฒ ๊ตฌํํ๋ ๋ชจ๋ฐ์ผ ํธ์ ์๋ฆผ ์์คํ
์ค์ ๊ฐ๋ฐ์๋ฅผ ์ํ ์๋ฒฝ ๊ฐ์ด๋
์๋
! ๐ ์ค๋์ ์ ๋ง ์ค์ฉ์ ์ด๊ณ ์ค์ํ ์ฃผ์ ๋ฅผ ๊ฐ์ง๊ณ ์์ด. ๋ฐ๋ก PHP์ Firebase Cloud Messaging(FCM)์ ํ์ฉํ ๋ชจ๋ฐ์ผ ํธ์ ์๋ฆผ ๊ตฌํ์ด์ผ!
์์ฆ ์ฑ ๊ฐ๋ฐ์์ ํธ์ ์๋ฆผ์ ์ ํ์ด ์๋๋ผ ํ์์์? ์ฌ์ฉ์์์ ์ํต, ์ฌ๋ฐฉ๋ฌธ ์ ๋, ์ค์ํ ์ ๋ณด ์ ๋ฌ... ์ด ๋ชจ๋ ๊ฒ ํธ์ ์๋ฆผ์ผ๋ก ์ด๋ฃจ์ด์ง๊ฑฐ๋ . ๊ทธ๋ฐ๋ฐ ๋ง์ ๊ตฌํํ๋ ค๊ณ ํ๋ฉด "์ด๋์๋ถํฐ ์์ํด์ผ ํ์ง?" ํ๋ ๋ง๋งํจ์ด ๋ฐ๋ ค์ค์ง ์์? ๐
๊ฑฑ์ ๋ง! ์ด ๊ธ์์๋ PHP ๋ฐฑ์๋์์ FCM์ ํ์ฉํด ๋ชจ๋ฐ์ผ ์ฑ์ผ๋ก ํธ์ ์๋ฆผ์ ๋ณด๋ด๋ ์ ๊ณผ์ ์ ์น๊ตฌ์ฒ๋ผ ์ฝ๊ณ ์ฌ๋ฏธ์๊ฒ ์ค๋ช
ํด์ค๊ฒ. ์ค์ ์ฝ๋๋ถํฐ ํธ๋ฌ๋ธ์ํ
๊น์ง ๋ชจ๋ ๋ด์์ผ๋๊น ๋๊น์ง ํจ๊ป ๊ฐ๋ณด์! ๐
๐ฏ ํธ์ ์๋ฆผ, ์ ์ค์ํ ๊น?
๋ณธ๊ฒฉ์ ์ผ๋ก ์์ํ๊ธฐ ์ ์, ํธ์ ์๋ฆผ์ด ์ ์ด๋ ๊ฒ ์ค์ํ์ง๋ถํฐ ์ง๊ณ ๋์ด๊ฐ์.
ํต๊ณ์ ๋ฐ๋ฅด๋ฉด ํธ์ ์๋ฆผ์ ํ์ฉํ๋ ์ฑ์ ๊ทธ๋ ์ง ์์ ์ฑ๋ณด๋ค ์ฌ์ฉ์ ์ฌ๋ฐฉ๋ฌธ์จ์ด 3๋ฐฐ ์ด์ ๋๋ค๊ณ ํด. ๋ํ ์ ์ ํ ํ์ด๋ฐ์ ๋ณด๋ด์ง ํธ์ ์๋ฆผ์ ์ ํ์จ์ ์ต๋ 88%๊น์ง ๋์ผ ์ ์๋ค๋ ์ฐ๊ตฌ ๊ฒฐ๊ณผ๋ ์์ด. ๐
์๊ฐํด๋ด. ์ผํ๋ชฐ ์ฑ์์ ์ฅ๋ฐ๊ตฌ๋์ ๋ด์๋ ์ํ์ด ํ ์ธํ๋ค๋ ์๋ฆผ์ ๋ฐ์ผ๋ฉด? ๋ฐฐ๋ฌ ์ฑ์์ ์ฃผ๋ฌธํ ์์์ด ๊ณง ๋์ฐฉํ๋ค๋ ์๋ฆผ์ ๋ฐ์ผ๋ฉด? ์ด๋ฐ ๊ฒ ๋ฐ๋ก ํธ์ ์๋ฆผ์ ํ์ด์ผ!
๐ฅ Firebase Cloud Messaging(FCM)์ด๋?
Firebase Cloud Messaging, ์ค์ฌ์ FCM์ ๊ตฌ๊ธ์ด ์ ๊ณตํ๋ ๋ฌด๋ฃ ํฌ๋ก์ค ํ๋ซํผ ๋ฉ์์ง ์๋ฃจ์
์ด์ผ. ์์ ์๋ GCM(Google Cloud Messaging)์ด๋ผ๊ณ ๋ถ๋ ธ๋๋ฐ, Firebase ์ํ๊ณ๋ก ํตํฉ๋๋ฉด์ ๋์ฑ ๊ฐ๋ ฅํด์ก์ง! ๐ช
FCM์ ๊ฐ์ฅ ํฐ ์ฅ์ ์ ๋ญ๊น?
โจ FCM์ ํต์ฌ ์ฅ์
1๏ธโฃ ์์ ๋ฌด๋ฃ
๋ฉ์์ง ์ ์ก์ ๋ํ ๋น์ฉ์ด ์ ํ ์์ด. ํ๋ฃจ์ ์๋ฐฑ๋ง ๊ฑด์ ๋ณด๋ด๋ ๋ฌด๋ฃ์ผ!
2๏ธโฃ ํฌ๋ก์ค ํ๋ซํผ ์ง์
iOS, Android, ์น๊น์ง ํ๋์ API๋ก ๋ชจ๋ ์ปค๋ฒํ ์ ์์ด. ํ๋ซํผ๋ณ๋ก ๋ฐ๋ก ๊ตฌํํ ํ์๊ฐ ์๋ค๋ ๊ฑฐ์ง.
3๏ธโฃ ๋์ ์ ๋ขฐ์ฑ
๊ตฌ๊ธ์ ์ธํ๋ผ๋ฅผ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ์์ ์ฑ๊ณผ ์ ์ก๋ฅ ์ด ๋งค์ฐ ๋์. 99.9% ์ด์์ ๊ฐ์ฉ์ฑ์ ์๋ํ์ง.
4๏ธโฃ ๋ค์ํ ๋ฉ์์ง ์ต์
๋จ์ ์๋ฆผ๋ถํฐ ๋ฐ์ดํฐ ๋ฉ์์ง, ํ ํฝ ๊ตฌ๋
, ์กฐ๊ฑด๋ถ ์ ์ก๊น์ง ๋ค์ํ ๋ฐฉ์์ ์ง์ํด.
5๏ธโฃ ๋ถ์ ๊ธฐ๋ฅ
Firebase Console์์ ๋ฉ์์ง ์ ์ก ํต๊ณ, ์คํ์จ ๋ฑ์ ์ค์๊ฐ์ผ๋ก ํ์ธํ ์ ์์ด.
๐ ๏ธ ์์ํ๊ธฐ ์ ์ค๋น์ฌํญ
์, ์ด์ ๋ณธ๊ฒฉ์ ์ผ๋ก ๊ตฌํ์ ๋ค์ด๊ฐ๊ธฐ ์ ์ ํ์ํ ๊ฒ๋ค์ ์ฒดํฌํด๋ณด์! ๐
๐ ํ์ ์ค๋น๋ฌผ ์ฒดํฌ๋ฆฌ์คํธ
โ
Firebase ํ๋ก์ ํธ
Firebase Console์์ ํ๋ก์ ํธ๋ฅผ ์์ฑํด์ผ ํด. ์์ง ์๋ค๋ฉด console.firebase.google.com์์ ๋ง๋ค ์ ์์ด.
โ
์๋น์ค ๊ณ์ ํค (JSON)
PHP ์๋ฒ์์ FCM API๋ฅผ ํธ์ถํ๋ ค๋ฉด ์ธ์ฆ ํค๊ฐ ํ์ํด. Firebase Console์ ํ๋ก์ ํธ ์ค์ ์์ ๋ค์ด๋ก๋ํ ์ ์์ง.
โ
PHP 7.4 ์ด์
์ต์ FCM API๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด PHP 7.4 ์ด์์ด ๊ถ์ฅ๋ผ. ๋ฌผ๋ก ๋ ๋์ ๋ฒ์ ์ด๋ฉด ๋ ์ข๊ณ !
โ
Composer
Firebase Admin SDK๋ฅผ ์ค์นํ๋ ค๋ฉด Composer๊ฐ ํ์ํด. PHP์ ํจํค์ง ๊ด๋ฆฌ์์ง.
โ
๋ชจ๋ฐ์ผ ์ฑ์ FCM ํ ํฐ
ํธ์๋ฅผ ๋ฐ์ ๊ธฐ๊ธฐ์ ๊ณ ์ ํ ํฐ์ด ํ์ํด. ์ด๊ฑด ๋ชจ๋ฐ์ผ ์ฑ์์ FCM SDK๋ฅผ ํตํด ์ป์ ์ ์์ด.
๐ง Firebase ํ๋ก์ ํธ ์ค์ ํ๊ธฐ
๊ฐ์ฅ ๋จผ์ ํด์ผ ํ ์ผ์ Firebase ํ๋ก์ ํธ๋ฅผ ๋ง๋ค๊ณ ์ค์ ํ๋ ๊ฑฐ์ผ. ๋จ๊ณ๋ณ๋ก ์ฐจ๊ทผ์ฐจ๊ทผ ๋ฐ๋ผ์๋ด! ๐
Step 1: Firebase ํ๋ก์ ํธ ์์ฑ
1. Firebase Console ์ ์
๋ธ๋ผ์ฐ์ ์์ console.firebase.google.com์ ์ ์ํด. ๊ตฌ๊ธ ๊ณ์ ์ผ๋ก ๋ก๊ทธ์ธํ๋ฉด ๋ผ.
2. ํ๋ก์ ํธ ์ถ๊ฐ
"ํ๋ก์ ํธ ์ถ๊ฐ" ๋ฒํผ์ ํด๋ฆญํ๊ณ ํ๋ก์ ํธ ์ด๋ฆ์ ์
๋ ฅํด. ์๋ฅผ ๋ค์ด "MyAwesomeApp" ๊ฐ์ ๊ฑฐ์ง.
3. Google Analytics ์ค์
์ ํ์ฌํญ์ด์ง๋ง ํ์ฑํํ๋ฉด ๋ ์์ธํ ๋ถ์์ด ๊ฐ๋ฅํด. ๋์ค์๋ ์ถ๊ฐํ ์ ์์ผ๋ ์ผ๋จ ๋์ด๊ฐ๋ ๊ด์ฐฎ์.
4. ํ๋ก์ ํธ ์์ฑ ์๋ฃ
๋ช ์ด ๊ธฐ๋ค๋ฆฌ๋ฉด ํ๋ก์ ํธ๊ฐ ์์ฑ๋ผ. ์ด์ Firebase์ ๋ค์ํ ์๋น์ค๋ฅผ ์ฌ์ฉํ ์ ์์ด! ๐
Step 2: ์ฑ ๋ฑ๋กํ๊ธฐ
Firebase ํ๋ก์ ํธ์ iOS ์ฑ์ด๋ Android ์ฑ์ ๋ฑ๋กํด์ผ ํด.
Android ์ฑ ๋ฑ๋ก:
- ํ๋ก์ ํธ ๊ฐ์์์ Android ์์ด์ฝ ํด๋ฆญ
- ํจํค์ง ์ด๋ฆ ์
๋ ฅ (์: com.mycompany.myapp)
- google-services.json ํ์ผ ๋ค์ด๋ก๋
- ์ฑ์ Firebase SDK ์ถ๊ฐ
iOS ์ฑ ๋ฑ๋ก:
- ํ๋ก์ ํธ ๊ฐ์์์ iOS ์์ด์ฝ ํด๋ฆญ
- ๋ฒ๋ค ID ์
๋ ฅ
- GoogleService-Info.plist ํ์ผ ๋ค์ด๋ก๋
- ์ฑ์ Firebase SDK ์ถ๊ฐ
์ด ํ์ผ๋ค์ ๋ชจ๋ฐ์ผ ์ฑ์์ Firebase์ ํต์ ํ๋ ๋ฐ ํ์ํ ์ค์ ์ ๋ณด๋ฅผ ๋ด๊ณ ์์ด.
Step 3: ์๋น์ค ๊ณ์ ํค ์์ฑ
์ด์ PHP ์๋ฒ์์ ์ฌ์ฉํ ์ธ์ฆ ํค๋ฅผ ๋ง๋ค์ด์ผ ํด. ์ด๊ฒ ์ ๋ง ์ค์ํ ๋ถ๋ถ์ด์ผ! ๐
1. Firebase Console์์ ํ๋ก์ ํธ ์ค์ (โ๏ธ ์์ด์ฝ) ํด๋ฆญ
2. ์๋น์ค ๊ณ์ ํญ์ผ๋ก ์ด๋
3. "์ ๋น๊ณต๊ฐ ํค ์์ฑ" ๋ฒํผ ํด๋ฆญ
4. JSON ํ์์ ํค ํ์ผ์ด ๋ค์ด๋ก๋๋ผ. ์ด ํ์ผ์ ์ ๋ ์ธ๋ถ์ ๋
ธ์ถ๋๋ฉด ์ ๋ผ!
5. ๋ค์ด๋ก๋ํ ํ์ผ ์ด๋ฆ์ ์๋ฅผ ๋ค์ด firebase-service-account.json์ผ๋ก ๋ณ๊ฒฝํ๊ณ ์์ ํ ๊ณณ์ ๋ณด๊ดํด.
๐ฆ PHP์์ Firebase Admin SDK ์ค์นํ๊ธฐ
์ด์ PHP ํ๋ก์ ํธ์ Firebase Admin SDK๋ฅผ ์ค์นํ ์ฐจ๋ก์ผ. Composer๋ฅผ ์ฌ์ฉํ๋ฉด ์ ๋ง ๊ฐ๋จํด! ๐
composer require kreait/firebase-php
์ด ๋ช
๋ น์ด ํ๋๋ฉด ๋์ด์ผ! kreait/firebase-php๋ Firebase Admin SDK์ PHP ๊ตฌํ์ฒด๋ก, ๊ฐ์ฅ ๋๋ฆฌ ์ฌ์ฉ๋๊ณ ์ ๊ด๋ฆฌ๋๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ผ.
์ค์น๊ฐ ์๋ฃ๋๋ฉด vendor ํด๋์ ํ์ํ ๋ชจ๋ ํ์ผ์ด ๋ค์ด๋ก๋๋ผ. ์ด์ PHP ์ฝ๋์์ Firebase๋ฅผ ์ฌ์ฉํ ์ค๋น๊ฐ ๋๋ฌ์ด! ๐
๐ป PHP์์ FCM ์ด๊ธฐํํ๊ธฐ
์, ์ด์ ์ค์ ์ฝ๋๋ฅผ ์์ฑํด๋ณผ ์๊ฐ์ด์ผ! ๋จผ์ Firebase๋ฅผ ์ด๊ธฐํํ๋ ๋ฐฉ๋ฒ๋ถํฐ ์์๋ณด์. ๐
<?php
require 'vendor/autoload.php';
use Kreait\Firebase\Factory;
// Firebase ์๋น์ค ๊ณ์ ํค ํ์ผ ๊ฒฝ๋ก
$serviceAccountPath = __DIR__ . '/firebase-service-account.json';
// Firebase ์ด๊ธฐํ
$factory = (new Factory)
->withServiceAccount($serviceAccountPath);
// Messaging ์ธ์คํด์ค ์์ฑ
$messaging = $factory->createMessaging();
echo "Firebase ์ด๊ธฐํ ์๋ฃ!";
?>
์ฝ๋๋ฅผ ํ๋์ฉ ๋ฏ์ด๋ณด์! ๐
1. Autoload ํฌํจ
require 'vendor/autoload.php';๋ Composer๊ฐ ์์ฑํ ์คํ ๋ก๋๋ฅผ ๋ถ๋ฌ์. ์ด๊ฑธ๋ก Firebase ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ชจ๋ ํด๋์ค๋ฅผ ์ฌ์ฉํ ์ ์๊ฒ ๋ผ.
2. Factory ํด๋์ค ์ฌ์ฉ
Factory ํด๋์ค๋ Firebase์ ๋ค์ํ ์๋น์ค๋ฅผ ์์ฑํ๋ ํฉํ ๋ฆฌ์ผ. ์ฌ๊ธฐ์๋ ์๋น์ค ๊ณ์ ํค๋ฅผ ์ฌ์ฉํด ์ธ์ฆ์ ์ค์ ํด.
3. Messaging ์ธ์คํด์ค
createMessaging() ๋ฉ์๋๋ก FCM ๋ฉ์์ง ์๋น์ค๋ฅผ ์ฌ์ฉํ ์ ์๋ ๊ฐ์ฒด๋ฅผ ๋ง๋ค์ด. ์ด ๊ฐ์ฒด๋ก ํธ์ ์๋ฆผ์ ๋ณด๋ผ ๊ฑฐ์ผ!
๐ ๋ณด์์ ๊ณ ๋ คํ ์ด๊ธฐํ ๋ฐฉ๋ฒ
์ค์ ํ๋ก๋์ ํ๊ฒฝ์์๋ ์๋น์ค ๊ณ์ ํค๋ฅผ ๋ ์์ ํ๊ฒ ๊ด๋ฆฌํด์ผ ํด. ํ๊ฒฝ ๋ณ์๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์ถ์ฒํด!
<?php
require 'vendor/autoload.php';
use Kreait\Firebase\Factory;
// ํ๊ฒฝ ๋ณ์์์ ํค ํ์ผ ๊ฒฝ๋ก ๊ฐ์ ธ์ค๊ธฐ
$serviceAccountPath = getenv('FIREBASE_SERVICE_ACCOUNT_PATH');
if (!$serviceAccountPath || !file_exists($serviceAccountPath)) {
throw new Exception('Firebase ์๋น์ค ๊ณ์ ํค๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.');
}
$factory = (new Factory)
->withServiceAccount($serviceAccountPath);
$messaging = $factory->createMessaging();
?>
์ด๋ ๊ฒ ํ๋ฉด ์ฝ๋์ ์ง์ ๊ฒฝ๋ก๋ฅผ ํ๋์ฝ๋ฉํ์ง ์์๋ ๋๊ณ , ์๋ฒ ํ๊ฒฝ์ ๋ฐ๋ผ ์ ์ฐํ๊ฒ ์ค์ ํ ์ ์์ด. ํจ์ฌ ์์ ํ์ง! ๐ก๏ธ
๐ค ์ฒซ ๋ฒ์งธ ํธ์ ์๋ฆผ ๋ณด๋ด๊ธฐ
๋๋์ด ์ค์ ๋ก ํธ์ ์๋ฆผ์ ๋ณด๋ผ ์๊ฐ์ด์ผ! ๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ํํ๋ถํฐ ์์ํด๋ณด์. ๐
<?php
require 'vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Firebase\Messaging\Notification;
// Firebase ์ด๊ธฐํ
$serviceAccountPath = __DIR__ . '/firebase-service-account.json';
$factory = (new Factory)->withServiceAccount($serviceAccountPath);
$messaging = $factory->createMessaging();
// ํธ์๋ฅผ ๋ฐ์ ๊ธฐ๊ธฐ์ FCM ํ ํฐ
$deviceToken = 'USER_DEVICE_FCM_TOKEN_HERE';
// ์๋ฆผ ๋ฉ์์ง ์์ฑ
$notification = Notification::create('์๋
ํ์ธ์!', '์ฒซ ๋ฒ์งธ ํธ์ ์๋ฆผ์
๋๋ค ๐');
// ํด๋ผ์ฐ๋ ๋ฉ์์ง ์์ฑ
$message = CloudMessage::withTarget('token', $deviceToken)
->withNotification($notification);
try {
// ๋ฉ์์ง ์ ์ก
$result = $messaging->send($message);
echo "ํธ์ ์๋ฆผ ์ ์ก ์ฑ๊ณต! ๐\n";
echo "๋ฉ์์ง ID: " . $result;
} catch (Exception $e) {
echo "ํธ์ ์๋ฆผ ์ ์ก ์คํจ: " . $e->getMessage();
}
?>
์! ์ด๊ฒ ์ ๋ถ์ผ! ์ ๋ง ๊ฐ๋จํ์ง? ๐
์ฝ๋๋ฅผ ๋ถ์ํด๋ณด๋ฉด:
1. Notification ๊ฐ์ฒด ์์ฑ
Notification::create()๋ก ์๋ฆผ์ ์ ๋ชฉ๊ณผ ๋ณธ๋ฌธ์ ์ค์ ํด. ์ด๋ชจ์ง๋ ์ฌ์ฉํ ์ ์์ด!
2. CloudMessage ์์ฑ
CloudMessage::withTarget()์ผ๋ก ๋ฉ์์ง๋ฅผ ๋ณด๋ผ ๋์์ ์ง์ ํด. 'token'์ ํน์ ๊ธฐ๊ธฐ๋ฅผ ์๋ฏธํ๊ณ , ๋ ๋ฒ์งธ ์ธ์๋ก FCM ํ ํฐ์ ์ ๋ฌํด.
3. ๋ฉ์์ง ์ ์ก
$messaging->send()๋ก ์ค์ ๋ก ๋ฉ์์ง๋ฅผ ์ ์กํด. ์ฑ๊ณตํ๋ฉด ๋ฉ์์ง ID๋ฅผ ๋ฐํํ์ง.
4. ์์ธ ์ฒ๋ฆฌ
๋คํธ์ํฌ ์ค๋ฅ๋ ์๋ชป๋ ํ ํฐ ๋ฑ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์ ์์ผ๋ try-catch๋ก ๊ฐ์ธ๋ ๊ฒ ์ข์.
๐จ ๊ณ ๊ธ ์๋ฆผ ์ต์ ํ์ฉํ๊ธฐ
๊ธฐ๋ณธ ์๋ฆผ๋ ์ข์ง๋ง, FCM์ ํจ์ฌ ๋ ๋ง์ ๊ธฐ๋ฅ์ ์ ๊ณตํด! ์ด๋ฏธ์ง, ์ฌ์ด๋, ๋ฐฐ์ง, ์ก์ ๋ฒํผ ๋ฑ ๋ค์ํ ์ต์ ์ ์ฌ์ฉํ ์ ์์ด. ๐จ
๐ผ๏ธ ์ด๋ฏธ์ง๊ฐ ํฌํจ๋ ์๋ฆผ
<?php
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Firebase\Messaging\Notification;
$notification = Notification::create('์๋ก์ด ์ํ ๋์ฐฉ!', '์ง๊ธ ํ์ธํด๋ณด์ธ์')
->withImageUrl('https://example.com/product-image.jpg');
$message = CloudMessage::withTarget('token', $deviceToken)
->withNotification($notification);
$messaging->send($message);
?>
withImageUrl() ๋ฉ์๋๋ก ์๋ฆผ์ ์ด๋ฏธ์ง๋ฅผ ์ถ๊ฐํ ์ ์์ด. ์ด๋ฏธ์ง๋ HTTPS URL์ด์ด์ผ ํ๊ณ , ์ฌ์ฉ์์ ๋๊ธธ์ ํ ๋ ์ ์์ง! ๐
๐ฑ ํ๋ซํผ๋ณ ์ปค์คํฐ๋ง์ด์ง
iOS์ Android๋ ์๋ฆผ์ ๋ค๋ฅด๊ฒ ์ฒ๋ฆฌํด. ๊ฐ ํ๋ซํผ์ ๋ง๋ ์ค์ ์ ์ถ๊ฐํ ์ ์์ด!
<?php
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Firebase\Messaging\Notification;
use Kreait\Firebase\Messaging\AndroidConfig;
use Kreait\Firebase\Messaging\ApnsConfig;
$notification = Notification::create('์ค์ ์๋ฆผ', '์ง๊ธ ํ์ธํ์ธ์!');
// Android ์ค์
$androidConfig = AndroidConfig::fromArray([
'priority' => 'high',
'notification' => [
'sound' => 'default',
'color' => '#667eea',
'channel_id' => 'important_notifications',
'click_action' => 'OPEN_ACTIVITY'
]
]);
// iOS ์ค์
$apnsConfig = ApnsConfig::fromArray([
'headers' => [
'apns-priority' => '10',
],
'payload' => [
'aps' => [
'sound' => 'default',
'badge' => 1,
'category' => 'IMPORTANT'
]
]
]);
$message = CloudMessage::withTarget('token', $deviceToken)
->withNotification($notification)
->withAndroidConfig($androidConfig)
->withApnsConfig($apnsConfig);
$messaging->send($message);
?>
์ด๋ ๊ฒ ํ๋ฉด ๊ฐ ํ๋ซํผ์ ํน์ฑ์ ๋ง๊ฒ ์๋ฆผ์ ์ต์ ํํ ์ ์์ด! ๐ฏ
Android ์ค์ ํฌ์ธํธ:
- priority: ์๋ฆผ ์ฐ์ ์์ (high/normal)
- sound: ์๋ฆผ์ ์ค์
- color: ์๋ฆผ ์์ด์ฝ ์์
- channel_id: Android 8.0 ์ด์์์ ํ์์ธ ์๋ฆผ ์ฑ๋
iOS ์ค์ ํฌ์ธํธ:
- apns-priority: ์ ์ก ์ฐ์ ์์ (10์ด ์ต๊ณ )
- sound: ์๋ฆผ์
- badge: ์ฑ ์์ด์ฝ ๋ฐฐ์ง ์ซ์
- category: ์๋ฆผ ์นดํ
๊ณ ๋ฆฌ (์ก์
๋ฒํผ ๋ฑ์ ์ฌ์ฉ)
๐ฆ ๋ฐ์ดํฐ ํ์ด๋ก๋ ์ถ๊ฐํ๊ธฐ
์๋ฆผ๊ณผ ํจ๊ป ์ถ๊ฐ ๋ฐ์ดํฐ๋ฅผ ๋ณด๋ผ ์ ์์ด. ์ฑ์์ ์ด ๋ฐ์ดํฐ๋ฅผ ๋ฐ์์ ํน์ ํ๋ฉด์ผ๋ก ์ด๋ํ๊ฑฐ๋ ํน๋ณํ ๋์์ ์ํํ ์ ์์ง!
<?php
$notification = Notification::create('์ ๋ฉ์์ง', '์น๊ตฌ๊ฐ ๋ฉ์์ง๋ฅผ ๋ณด๋์ต๋๋ค');
$data = [
'type' => 'chat_message',
'chat_id' => '12345',
'sender_id' => '67890',
'message_preview' => '์๋
ํ์ธ์!',
'timestamp' => time()
];
$message = CloudMessage::withTarget('token', $deviceToken)
->withNotification($notification)
->withData($data);
$messaging->send($message);
?>
withData() ๋ฉ์๋๋ก ํค-๊ฐ ์์ ๋ฐฐ์ด์ ์ ๋ฌํ ์ ์์ด. ์ฑ์์ ์ด ๋ฐ์ดํฐ๋ฅผ ํ์ฑํด์ ์ฌ์ฉํ๋ฉด ๋ผ. ์ ๋ง ์ ์ฉํ์ง! ๐
๐ฅ ์ฌ๋ฌ ๊ธฐ๊ธฐ์ ๋์์ ๋ณด๋ด๊ธฐ
ํ ๋ช ์ ์ฌ์ฉ์๊ฐ ์ฌ๋ฌ ๊ธฐ๊ธฐ๋ฅผ ์ฌ์ฉํ๊ฑฐ๋, ์ฌ๋ฌ ์ฌ์ฉ์์๊ฒ ๋์์ ์๋ฆผ์ ๋ณด๋ด์ผ ํ ๋๊ฐ ์์ง? ์ด๋ด ๋ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ๋ค์ ์์๋ณด์! ๐ฑ๐ฑ๐ฑ
๐ฏ ๋ฉํฐ์บ์คํธ ๋ฉ์์ง
์ต๋ 500๊ฐ์ ํ ํฐ์ ๋์์ ๋ฉ์์ง๋ฅผ ๋ณด๋ผ ์ ์์ด. ํจ์จ์ ์ด๊ณ ๋น ๋ฅด์ง!
<?php
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Firebase\Messaging\Notification;
use Kreait\Firebase\Messaging\MulticastSendReport;
$notification = Notification::create('๊ณต์ง์ฌํญ', '์ค์ํ ์
๋ฐ์ดํธ๊ฐ ์์ต๋๋ค!');
// ์ฌ๋ฌ ๊ธฐ๊ธฐ์ ํ ํฐ ๋ฐฐ์ด
$deviceTokens = [
'token1_here',
'token2_here',
'token3_here',
// ... ์ต๋ 500๊ฐ๊น์ง
];
$message = CloudMessage::new()
->withNotification($notification)
->withData(['type' => 'announcement']);
try {
$report = $messaging->sendMulticast($message, $deviceTokens);
echo "์ ์ก ์ฑ๊ณต: " . $report->successes()->count() . "๊ฑด\n";
echo "์ ์ก ์คํจ: " . $report->failures()->count() . "๊ฑด\n";
// ์คํจํ ํ ํฐ ํ์ธ
if ($report->hasFailures()) {
foreach ($report->failures()->getItems() as $failure) {
echo "์คํจํ ํ ํฐ: " . $failure->target()->value() . "\n";
echo "์คํจ ์ด์ : " . $failure->error()->getMessage() . "\n";
}
}
} catch (Exception $e) {
echo "๋ฉํฐ์บ์คํธ ์ ์ก ์ค๋ฅ: " . $e->getMessage();
}
?>
๋ฉํฐ์บ์คํธ๋ ์ ๋ง ๊ฐ๋ ฅํด! ํ ๋ฒ์ API ํธ์ถ๋ก ์๋ฐฑ ๋ช
์๊ฒ ๋์์ ์๋ฆผ์ ๋ณด๋ผ ์ ์๊ฑฐ๋ . ๐ช
MulticastSendReport ๊ฐ์ฒด๋ฅผ ํตํด ๊ฐ ํ ํฐ๋ณ ์ ์ก ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ ์ ์์ด. ์คํจํ ํ ํฐ์ ๋ฐ์ดํฐ๋ฒ ์ด์ค์์ ์ ๊ฑฐํ๊ฑฐ๋ ์ฌ์๋ ๋ก์ง์ ๊ตฌํํ ์ ์์ง.
๐ข ํ ํฝ ๋ฉ์์ง
ํ ํฝ(Topic)์ ํน์ ์ฃผ์ ์ ๊ด์ฌ ์๋ ์ฌ์ฉ์๋ค์ ๊ทธ๋ฃนํํ๋ ๋ฐฉ๋ฒ์ด์ผ. ์๋ฅผ ๋ค์ด "์คํฌ์ธ ", "๋ด์ค", "ํ ์ธ์ ๋ณด" ๊ฐ์ ํ ํฝ์ ๋ง๋ค ์ ์์ด.
<?php
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Firebase\Messaging\Notification;
$notification = Notification::create('์คํฌ์ธ ์๋ณด', 'โฝ ๊ฒฝ๊ธฐ ๊ฒฐ๊ณผ๊ฐ ๋์์ต๋๋ค!');
// 'sports' ํ ํฝ์ ๊ตฌ๋
ํ ๋ชจ๋ ์ฌ์ฉ์์๊ฒ ์ ์ก
$message = CloudMessage::withTarget('topic', 'sports')
->withNotification($notification)
->withData(['category' => 'sports', 'match_id' => '12345']);
$messaging->send($message);
?>
ํ ํฝ ๋ฉ์์ง์ ์ฅ์ ์ ์๋ฒ์์ ๊ฐ๋ณ ํ ํฐ์ ๊ด๋ฆฌํ ํ์๊ฐ ์๋ค๋ ๊ฑฐ์ผ! ์ฌ์ฉ์๊ฐ ์ฑ์์ ํ ํฝ์ ๊ตฌ๋
/๊ตฌ๋
์ทจ์ํ๋ฉด ์๋์ผ๋ก ๊ด๋ฆฌ๋ผ. ๐ฏ
ํ ํฝ ๊ตฌ๋
์ ๋ชจ๋ฐ์ผ ์ฑ์์ ์ฒ๋ฆฌํ์ง๋ง, PHP์์๋ ํ ์ ์์ด:
<?php
// ํ ํฐ์ ํ ํฝ์ ๊ตฌ๋
์ํค๊ธฐ
$tokens = ['token1', 'token2', 'token3'];
$topic = 'sports';
$result = $messaging->subscribeToTopic($topic, $tokens);
echo "๊ตฌ๋
์ฑ๊ณต: " . $result->successes()->count() . "๊ฑด\n";
echo "๊ตฌ๋
์คํจ: " . $result->failures()->count() . "๊ฑด\n";
// ํ ํฝ ๊ตฌ๋
์ทจ์
$result = $messaging->unsubscribeFromTopic($topic, $tokens);
?>
๐ฒ ์กฐ๊ฑด๋ถ ๋ฉ์์ง
์ฌ๋ฌ ํ ํฝ์ ์กฐํฉํด์ ๋ณต์กํ ์กฐ๊ฑด์ผ๋ก ๋ฉ์์ง๋ฅผ ๋ณด๋ผ ์๋ ์์ด! ์ ๋ง ๊ฐ๋ ฅํ ๊ธฐ๋ฅ์ด์ง. ๐ฅ
<?php
$notification = Notification::create('ํน๋ณ ํ ์ธ', '๋น์ ๋ง์ ์ํ ํน๊ฐ!');
// 'vip' ํ ํฝ์ ๊ตฌ๋
ํ๊ณ 'notifications' ํ ํฝ๋ ๊ตฌ๋
ํ ์ฌ์ฉ์์๊ฒ๋ง ์ ์ก
$condition = "'vip' in topics && 'notifications' in topics";
$message = CloudMessage::withTarget('condition', $condition)
->withNotification($notification);
$messaging->send($message);
?>
์กฐ๊ฑด์์๋ AND(&&), OR(||), NOT(!) ์ฐ์ฐ์๋ฅผ ์ฌ์ฉํ ์ ์์ด. ์ต๋ 5๊ฐ์ ํ ํฝ์ ์กฐํฉํ ์ ์์ง!
์์:
- 'sports' in topics || 'news' in topics: ์คํฌ์ธ ๋๋ ๋ด์ค ๊ตฌ๋
์
- 'premium' in topics && !('trial' in topics): ํ๋ฆฌ๋ฏธ์์ด์ง๋ง ์ฒดํํ์ด ์๋ ์ฌ์ฉ์
- 'ios' in topics && 'kr' in topics: iOS ํ๊ตญ ์ฌ์ฉ์
๐๏ธ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ฐ๋ํ๊ธฐ
์ค์ ์๋น์ค์์๋ ์ฌ์ฉ์์ FCM ํ ํฐ์ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ์ฅํ๊ณ ๊ด๋ฆฌํด์ผ ํด. ์ค์ฉ์ ์ธ ์์ ๋ฅผ ๋ง๋ค์ด๋ณด์! ๐พ
๐ ๋ฐ์ดํฐ๋ฒ ์ด์ค ํ ์ด๋ธ ์ค๊ณ
๋จผ์ FCM ํ ํฐ์ ์ ์ฅํ ํ ์ด๋ธ์ด ํ์ํด. MySQL ๊ธฐ์ค์ผ๋ก ์ค๊ณํด๋ณผ๊ฒ!
CREATE TABLE user_devices (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
device_token VARCHAR(255) NOT NULL,
device_type ENUM('ios', 'android', 'web') NOT NULL,
device_name VARCHAR(100),
is_active TINYINT(1) DEFAULT 1,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
last_used_at TIMESTAMP NULL,
UNIQUE KEY unique_token (device_token),
INDEX idx_user_id (user_id),
INDEX idx_active (is_active)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE push_notifications (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
title VARCHAR(255) NOT NULL,
body TEXT NOT NULL,
data JSON,
sent_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
status ENUM('pending', 'sent', 'failed') DEFAULT 'pending',
error_message TEXT,
INDEX idx_user_id (user_id),
INDEX idx_status (status),
INDEX idx_sent_at (sent_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
์ด ํ
์ด๋ธ ๊ตฌ์กฐ๋:
- ์ฌ์ฉ์๋ณ๋ก ์ฌ๋ฌ ๊ธฐ๊ธฐ๋ฅผ ๊ด๋ฆฌํ ์ ์์ด
- ๊ธฐ๊ธฐ ํ์
(iOS/Android/Web)์ ๊ตฌ๋ถํด
- ํ ํฐ์ ํ์ฑ ์ํ๋ฅผ ์ถ์ ํด
- ์ ์ก ์ด๋ ฅ์ ๊ธฐ๋กํด
์ค๋ฌด์์ ์ ๋ง ์ ์ฉํ ๊ตฌ์กฐ์ผ! ๐
๐ป ํ ํฐ ์ ์ฅ ๋ฐ ๊ด๋ฆฌ ํด๋์ค
์ด์ PHP ํด๋์ค๋ฅผ ๋ง๋ค์ด์ ํ ํฐ์ ๊ด๋ฆฌํด๋ณด์!
<?php
class PushNotificationManager {
private $pdo;
private $messaging;
public function __construct($pdo, $messaging) {
$this->pdo = $pdo;
$this->messaging = $messaging;
}
/**
* ๊ธฐ๊ธฐ ํ ํฐ ์ ์ฅ ๋๋ ์
๋ฐ์ดํธ
*/
public function saveDeviceToken($userId, $deviceToken, $deviceType, $deviceName = null) {
$sql = "INSERT INTO user_devices
(user_id, device_token, device_type, device_name, last_used_at)
VALUES (:user_id, :device_token, :device_type, :device_name, NOW())
ON DUPLICATE KEY UPDATE
user_id = :user_id,
device_type = :device_type,
device_name = :device_name,
is_active = 1,
last_used_at = NOW()";
$stmt = $this->pdo->prepare($sql);
return $stmt->execute([
':user_id' => $userId,
':device_token' => $deviceToken,
':device_type' => $deviceType,
':device_name' => $deviceName
]);
}
/**
* ํน์ ์ฌ์ฉ์์ ๋ชจ๋ ํ์ฑ ํ ํฐ ๊ฐ์ ธ์ค๊ธฐ
*/
public function getUserTokens($userId) {
$sql = "SELECT device_token FROM user_devices
WHERE user_id = :user_id AND is_active = 1";
$stmt = $this->pdo->prepare($sql);
$stmt->execute([':user_id' => $userId]);
return $stmt->fetchAll(PDO::FETCH_COLUMN);
}
/**
* ํ ํฐ ๋นํ์ฑํ (์๋ชป๋ ํ ํฐ ์ฒ๋ฆฌ)
*/
public function deactivateToken($deviceToken) {
$sql = "UPDATE user_devices SET is_active = 0
WHERE device_token = :device_token";
$stmt = $this->pdo->prepare($sql);
return $stmt->execute([':device_token' => $deviceToken]);
}
/**
* ํน์ ์ฌ์ฉ์์๊ฒ ํธ์ ์๋ฆผ ๋ณด๋ด๊ธฐ
*/
public function sendToUser($userId, $title, $body, $data = []) {
$tokens = $this->getUserTokens($userId);
if (empty($tokens)) {
return ['success' => false, 'message' => 'ํ์ฑ ํ ํฐ์ด ์์ต๋๋ค'];
}
$notification = Notification::create($title, $body);
$message = CloudMessage::new()
->withNotification($notification)
->withData($data);
try {
$report = $this->messaging->sendMulticast($message, $tokens);
// ์ ์ก ์ด๋ ฅ ์ ์ฅ
$this->logNotification($userId, $title, $body, $data, 'sent');
// ์คํจํ ํ ํฐ ์ฒ๋ฆฌ
if ($report->hasFailures()) {
foreach ($report->failures()->getItems() as $failure) {
$failedToken = $failure->target()->value();
$this->deactivateToken($failedToken);
}
}
return [
'success' => true,
'sent' => $report->successes()->count(),
'failed' => $report->failures()->count()
];
} catch (Exception $e) {
$this->logNotification($userId, $title, $body, $data, 'failed', $e->getMessage());
return ['success' => false, 'message' => $e->getMessage()];
}
}
/**
* ์๋ฆผ ์ ์ก ์ด๋ ฅ ์ ์ฅ
*/
private function logNotification($userId, $title, $body, $data, $status, $error = null) {
$sql = "INSERT INTO push_notifications
(user_id, title, body, data, status, error_message)
VALUES (:user_id, :title, :body, :data, :status, :error_message)";
$stmt = $this->pdo->prepare($sql);
$stmt->execute([
':user_id' => $userId,
':title' => $title,
':body' => $body,
':data' => json_encode($data),
':status' => $status,
':error_message' => $error
]);
}
}
?>
์ด ํด๋์ค๋ ์ค๋ฌด์์ ๋ฐ๋ก ์ฌ์ฉํ ์ ์๋ ์์ค์ด์ผ! ๐ฏ
์ฃผ์ ๊ธฐ๋ฅ:
- ํ ํฐ ์ ์ฅ ๋ฐ ์
๋ฐ์ดํธ (์ค๋ณต ์ฒ๋ฆฌ ํฌํจ)
- ์ฌ์ฉ์๋ณ ํ์ฑ ํ ํฐ ์กฐํ
- ์๋ชป๋ ํ ํฐ ์๋ ๋นํ์ฑํ
- ์ ์ก ์ด๋ ฅ ์๋ ๊ธฐ๋ก
- ๋ฉํฐ์บ์คํธ๋ก ํจ์จ์ ์ธ ์ ์ก
๐ ์ค์ ์ฌ์ฉ ์์
<?php
require 'vendor/autoload.php';
use Kreait\Firebase\Factory;
// ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ
$pdo = new PDO('mysql:host=localhost;dbname=myapp', 'username', 'password');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Firebase ์ด๊ธฐํ
$factory = (new Factory)->withServiceAccount('firebase-service-account.json');
$messaging = $factory->createMessaging();
// PushNotificationManager ์ธ์คํด์ค ์์ฑ
$pushManager = new PushNotificationManager($pdo, $messaging);
// ์์ 1: ์ ๊ธฐ๊ธฐ ํ ํฐ ์ ์ฅ
$pushManager->saveDeviceToken(
userId: 123,
deviceToken: 'fcm_token_from_mobile_app',
deviceType: 'android',
deviceName: 'Samsung Galaxy S21'
);
// ์์ 2: ํน์ ์ฌ์ฉ์์๊ฒ ์๋ฆผ ๋ณด๋ด๊ธฐ
$result = $pushManager->sendToUser(
userId: 123,
title: '์๋ก์ด ๋ฉ์์ง',
body: '์น๊ตฌ๊ฐ ๋ฉ์์ง๋ฅผ ๋ณด๋์ต๋๋ค',
data: [
'type' => 'chat',
'chat_id' => '456',
'sender_name' => 'ํ๊ธธ๋'
]
);
if ($result['success']) {
echo "์๋ฆผ ์ ์ก ์๋ฃ! ์ฑ๊ณต: {$result['sent']}๊ฑด, ์คํจ: {$result['failed']}๊ฑด";
} else {
echo "์๋ฆผ ์ ์ก ์คํจ: {$result['message']}";
}
?>
โก ๋๋ ์๋ฆผ ์ ์ก ์ต์ ํ
์์ฒ, ์๋ง ๋ช ์ ์ฌ์ฉ์์๊ฒ ์๋ฆผ์ ๋ณด๋ด์ผ ํ๋ค๋ฉด? ํจ์จ์ ์ธ ์ ๋ต์ด ํ์ํด! ๐
๐ฆ ๋ฐฐ์น ์ฒ๋ฆฌ ๊ตฌํ
FCM์ ํ ๋ฒ์ ์ต๋ 500๊ฐ์ ํ ํฐ์ ๋ฉํฐ์บ์คํธ๋ฅผ ๋ณด๋ผ ์ ์์ด. ๊ทธ ์ด์์ด๋ฉด ๋ฐฐ์น๋ก ๋๋ ์ ์ฒ๋ฆฌํด์ผ ํด!
<?php
class BatchPushSender {
private $messaging;
private $batchSize = 500;
public function __construct($messaging) {
$this->messaging = $messaging;
}
/**
* ๋๋ ํ ํฐ์ ์๋ฆผ ๋ณด๋ด๊ธฐ
*/
public function sendToMany($tokens, $notification, $data = []) {
$totalTokens = count($tokens);
$batches = array_chunk($tokens, $this->batchSize);
$totalSuccess = 0;
$totalFailure = 0;
$failedTokens = [];
echo "์ด {$totalTokens}๊ฐ ํ ํฐ์ " . count($batches) . "๊ฐ ๋ฐฐ์น๋ก ์ ์กํฉ๋๋ค...\n";
foreach ($batches as $index => $batch) {
echo "๋ฐฐ์น " . ($index + 1) . " ์ ์ก ์ค...\n";
$message = CloudMessage::new()
->withNotification($notification)
->withData($data);
try {
$report = $this->messaging->sendMulticast($message, $batch);
$successCount = $report->successes()->count();
$failureCount = $report->failures()->count();
$totalSuccess += $successCount;
$totalFailure += $failureCount;
// ์คํจํ ํ ํฐ ์์ง
if ($report->hasFailures()) {
foreach ($report->failures()->getItems() as $failure) {
$failedTokens[] = [
'token' => $failure->target()->value(),
'error' => $failure->error()->getMessage()
];
}
}
echo " ์ฑ๊ณต: {$successCount}, ์คํจ: {$failureCount}\n";
// API ์ ํ์ ํผํ๊ธฐ ์ํ ์งง์ ๋๊ธฐ
if ($index < count($batches) - 1) {
usleep(100000); // 0.1์ด ๋๊ธฐ
}
} catch (Exception $e) {
echo " ๋ฐฐ์น ์ ์ก ์ค๋ฅ: " . $e->getMessage() . "\n";
$totalFailure += count($batch);
}
}
return [
'total' => $totalTokens,
'success' => $totalSuccess,
'failure' => $totalFailure,
'failed_tokens' => $failedTokens
];
}
}
// ์ฌ์ฉ ์์
$batchSender = new BatchPushSender($messaging);
// ๋ฐ์ดํฐ๋ฒ ์ด์ค์์ ๋ชจ๋ ํ์ฑ ํ ํฐ ๊ฐ์ ธ์ค๊ธฐ
$sql = "SELECT device_token FROM user_devices WHERE is_active = 1";
$stmt = $pdo->query($sql);
$allTokens = $stmt->fetchAll(PDO::FETCH_COLUMN);
$notification = Notification::create(
'์ค์ ๊ณต์ง',
'์๋น์ค ์ ๊ฒ์ด ์์ ๋์ด ์์ต๋๋ค'
);
$result = $batchSender->sendToMany($allTokens, $notification, [
'type' => 'maintenance',
'scheduled_at' => '2024-01-15 02:00:00'
]);
echo "\n์ ์ก ์๋ฃ!\n";
echo "์ด: {$result['total']}๊ฑด\n";
echo "์ฑ๊ณต: {$result['success']}๊ฑด\n";
echo "์คํจ: {$result['failure']}๊ฑด\n";
?>
์ด ์ฝ๋๋ ๋๋ ์ ์ก์ ์์ ํ๊ณ ํจ์จ์ ์ผ๋ก ์ฒ๋ฆฌํด! ๐ช
ํต์ฌ ํฌ์ธํธ:
- 500๊ฐ์ฉ ๋ฐฐ์น๋ก ๋๋ ์ ์ฒ๋ฆฌ
- ๊ฐ ๋ฐฐ์น ์ฌ์ด์ ์งง์ ๋๊ธฐ ์๊ฐ (API ์ ํ ํํผ)
- ์คํจํ ํ ํฐ ์ถ์ ๋ฐ ๊ธฐ๋ก
- ์งํ ์ํฉ ์ค์๊ฐ ์ถ๋ ฅ
- ์์ธ ์ฒ๋ฆฌ๋ก ์์ ์ฑ ํ๋ณด
โฐ ํ ์์คํ ํ์ฉ
์ ๋ง ๋๊ท๋ชจ ์ ์ก์ด๋ผ๋ฉด ํ ์์คํ ์ ์ฌ์ฉํ๋ ๊ฒ ์ข์. Redis๋ RabbitMQ ๊ฐ์ ๋ฉ์์ง ํ๋ฅผ ํ์ฉํ๋ฉด ๋์ฑ ์์ ์ ์ด์ง!
<?php
// Redis๋ฅผ ์ฌ์ฉํ ํ ์์
class PushQueue {
private $redis;
private $queueName = 'push_notifications';
public function __construct() {
$this->redis = new Redis();
$this->redis->connect('127.0.0.1', 6379);
}
/**
* ์๋ฆผ์ ํ์ ์ถ๊ฐ
*/
public function enqueue($userId, $title, $body, $data = []) {
$job = json_encode([
'user_id' => $userId,
'title' => $title,
'body' => $body,
'data' => $data,
'created_at' => time()
]);
return $this->redis->rPush($this->queueName, $job);
}
/**
* ํ์์ ์์
๊ฐ์ ธ์ค๊ธฐ
*/
public function dequeue() {
$job = $this->redis->lPop($this->queueName);
return $job ? json_decode($job, true) : null;
}
/**
* ํ ํฌ๊ธฐ ํ์ธ
*/
public function size() {
return $this->redis->lLen($this->queueName);
}
}
// ์์ปค ํ๋ก์ธ์ค (๋ณ๋ ์คํฌ๋ฆฝํธ๋ก ์คํ)
class PushWorker {
private $queue;
private $pushManager;
public function __construct($queue, $pushManager) {
$this->queue = $queue;
$this->pushManager = $pushManager;
}
/**
* ์์ปค ์คํ
*/
public function run() {
echo "ํธ์ ์๋ฆผ ์์ปค ์์...\n";
while (true) {
$job = $this->queue->dequeue();
if ($job) {
echo "์์
์ฒ๋ฆฌ ์ค: User {$job['user_id']}\n";
$result = $this->pushManager->sendToUser(
$job['user_id'],
$job['title'],
$job['body'],
$job['data']
);
if ($result['success']) {
echo " ์ ์ก ์ฑ๊ณต!\n";
} else {
echo " ์ ์ก ์คํจ: {$result['message']}\n";
}
} else {
// ํ๊ฐ ๋น์ด์์ผ๋ฉด 1์ด ๋๊ธฐ
sleep(1);
}
}
}
}
// ์ฌ์ฉ ์์
$queue = new PushQueue();
// ์๋ฆผ์ ํ์ ์ถ๊ฐ (์น ์์ฒญ์์)
$queue->enqueue(
userId: 123,
title: '์ฃผ๋ฌธ ์๋ฃ',
body: '์ฃผ๋ฌธ์ด ์ฑ๊ณต์ ์ผ๋ก ์๋ฃ๋์์ต๋๋ค',
data: ['order_id' => '789']
);
echo "ํ์ ์ถ๊ฐ๋จ. ํ์ฌ ํ ํฌ๊ธฐ: " . $queue->size();
?>
ํ ์์คํ
์ ์ฅ์ :
- ์น ์์ฒญ๊ณผ ์๋ฆผ ์ ์ก์ ๋ถ๋ฆฌ (๋น ๋ฅธ ์๋ต)
- ๋๋ ์ ์ก ์ ์๋ฒ ๋ถํ ๋ถ์ฐ
- ์คํจํ ์์
์ฌ์๋ ๊ฐ๋ฅ
- ์ฌ๋ฌ ์์ปค๋ก ๋ณ๋ ฌ ์ฒ๋ฆฌ ๊ฐ๋ฅ
์ค์ ์๋น์ค์์๋ ์ด๋ฐ ์ํคํ
์ฒ๊ฐ ํ์์ผ! ๐๏ธ
๐ ํธ๋ฌ๋ธ์ํ ๊ฐ์ด๋
๊ฐ๋ฐํ๋ค ๋ณด๋ฉด ์ฌ๋ฌ ๋ฌธ์ ์ ๋ถ๋ชํ๊ฒ ๋ผ. ์์ฃผ ๋ฐ์ํ๋ ๋ฌธ์ ๋ค๊ณผ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์ ๋ฆฌํด๋ดค์ด! ๐ ๏ธ
โ ์์ฃผ ๋ฐ์ํ๋ ์ค๋ฅ๋ค
1. "Invalid registration token"
์์ธ ์๋ชป๋์๊ฑฐ๋ ๋ง๋ฃ๋ FCM ํ ํฐ
ํด๊ฒฐ ํด๋น ํ ํฐ์ ๋ฐ์ดํฐ๋ฒ ์ด์ค์์ ์ญ์ ํ๊ฑฐ๋ ๋นํ์ฑํํด์ผ ํด. ์ฌ์ฉ์๊ฐ ์ฑ์ ์ฌ์ค์นํ๊ฑฐ๋ ์ค๋ซ๋์ ์ฌ์ฉํ์ง ์์ผ๋ฉด ํ ํฐ์ด ๋ฌดํจํ๋ ์ ์์ด.
2. "Requested entity was not found"
์์ธ Firebase ํ๋ก์ ํธ ์ค์ ์ค๋ฅ ๋๋ ์๋ชป๋ ์๋น์ค ๊ณ์ ํค
ํด๊ฒฐ ์๋น์ค ๊ณ์ ํค ํ์ผ์ด ์ฌ๋ฐ๋ฅธ์ง, Firebase ํ๋ก์ ํธ ID๊ฐ ๋ง๋์ง ํ์ธํด๋ด.
3. "Authentication error"
์์ธ ์๋น์ค ๊ณ์ ํค ํ์ผ ๊ฒฝ๋ก๊ฐ ์๋ชป๋์๊ฑฐ๋ ๊ถํ ๋ฌธ์
ํด๊ฒฐ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์ ๋ ๊ฒฝ๋ก๋ก ์ง์ ํ๊ณ , ํ์ผ ์ฝ๊ธฐ ๊ถํ์ด ์๋์ง ํ์ธํด.
4. "Quota exceeded"
์์ธ FCM API ํธ์ถ ์ ํ ์ด๊ณผ
ํด๊ฒฐ ๋ฐฐ์น ์ฒ๋ฆฌ ์ฌ์ด์ ์ ์ ํ ๋๊ธฐ ์๊ฐ์ ์ถ๊ฐํ๊ณ , ๋ฉํฐ์บ์คํธ๋ฅผ ํ์ฉํด ํธ์ถ ํ์๋ฅผ ์ค์ฌ.
5. "MismatchSenderId"
์์ธ ์ฑ์ ๋ฑ๋ก๋ Firebase ํ๋ก์ ํธ์ ์๋ฒ์์ ์ฌ์ฉํ๋ ํ๋ก์ ํธ๊ฐ ๋ค๋ฆ
ํด๊ฒฐ ์ฑ๊ณผ ์๋ฒ๊ฐ ๊ฐ์ Firebase ํ๋ก์ ํธ๋ฅผ ์ฌ์ฉํ๋์ง ํ์ธํด. google-services.json(Android) ๋๋ GoogleService-Info.plist(iOS) ํ์ผ์ด ์ฌ๋ฐ๋ฅธ์ง ์ฒดํฌ!
๐ ๋๋ฒ๊น ํ
๋ฌธ์ ๋ฅผ ๋น ๋ฅด๊ฒ ์ฐพ๊ธฐ ์ํ ๋๋ฒ๊น ์ฝ๋๋ฅผ ์ถ๊ฐํด๋ณด์!
<?php
class PushDebugger {
/**
* ํ ํฐ ์ ํจ์ฑ ๊ฒ์ฆ
*/
public static function validateToken($messaging, $token) {
try {
$message = CloudMessage::withTarget('token', $token)
->withData(['test' => 'validation']);
// ์ค์ ๋ก ๋ณด๋ด์ง ์๊ณ ๊ฒ์ฆ๋ง ์ํ
$result = $messaging->validateRegistrationTokens([$token]);
if (isset($result['valid']) && in_array($token, $result['valid'])) {
echo "โ
ํ ํฐ์ด ์ ํจํฉ๋๋ค.\n";
return true;
} else {
echo "โ ํ ํฐ์ด ์ ํจํ์ง ์์ต๋๋ค.\n";
if (isset($result['invalid'])) {
echo "๋ฌดํจํ ํ ํฐ: " . implode(', ', $result['invalid']) . "\n";
}
return false;
}
} catch (Exception $e) {
echo "โ ๊ฒ์ฆ ์ค๋ฅ: " . $e->getMessage() . "\n";
return false;
}
}
/**
* ์์ธ ์ค๋ฅ ๋ก๊น
*/
public static function logDetailedError($exception) {
$logFile = __DIR__ . '/push_errors.log';
$errorInfo = [
'timestamp' => date('Y-m-d H:i:s'),
'message' => $exception->getMessage(),
'code' => $exception->getCode(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => $exception->getTraceAsString()
];
file_put_contents(
$logFile,
json_encode($errorInfo, JSON_PRETTY_PRINT) . "\n\n",
FILE_APPEND
);
echo "์ค๋ฅ๊ฐ ๋ก๊ทธ ํ์ผ์ ๊ธฐ๋ก๋์์ต๋๋ค: {$logFile}\n";
}
/**
* Firebase ์ฐ๊ฒฐ ํ
์คํธ
*/
public static function testConnection($factory) {
try {
$messaging = $factory->createMessaging();
echo "โ
Firebase ์ฐ๊ฒฐ ์ฑ๊ณต!\n";
// ํ๋ก์ ํธ ์ ๋ณด ํ์ธ
$projectId = $factory->getProjectId();
echo "ํ๋ก์ ํธ ID: {$projectId}\n";
return true;
} catch (Exception $e) {
echo "โ Firebase ์ฐ๊ฒฐ ์คํจ: " . $e->getMessage() . "\n";
return false;
}
}
}
// ์ฌ์ฉ ์์
try {
// ์ฐ๊ฒฐ ํ
์คํธ
PushDebugger::testConnection($factory);
// ํ ํฐ ๊ฒ์ฆ
$testToken = 'your_test_token_here';
PushDebugger::validateToken($messaging, $testToken);
} catch (Exception $e) {
PushDebugger::logDetailedError($e);
}
?>
์ด๋ฐ ๋๋ฒ๊น ๋๊ตฌ๋ฅผ ๋ง๋ค์ด๋๋ฉด ๋ฌธ์ ํด๊ฒฐ์ด ํจ์ฌ ์ฌ์์ ธ! ๐ฏ
๐ ์๋ฆผ ์ฑ๋ฅ ๋ชจ๋ํฐ๋ง
์๋ฆผ์ ๋ณด๋ด๋ ๊ฒ๋ ์ค์ํ์ง๋ง, ์ผ๋ง๋ ํจ๊ณผ์ ์ธ์ง ์ธก์ ํ๋ ๊ฒ๋ ์ค์ํด! ๐
๐ ํต๊ณ ์ถ์ ์์คํ
<?php
class PushAnalytics {
private $pdo;
public function __construct($pdo) {
$this->pdo = $pdo;
}
/**
* ์ ์ก ํต๊ณ ์กฐํ
*/
public function getStats($startDate, $endDate) {
$sql = "SELECT
DATE(sent_at) as date,
COUNT(*) as total_sent,
SUM(CASE WHEN status = 'sent' THEN 1 ELSE 0 END) as successful,
SUM(CASE WHEN status = 'failed' THEN 1 ELSE 0 END) as failed,
ROUND(SUM(CASE WHEN status = 'sent' THEN 1 ELSE 0 END) * 100.0 / COUNT(*), 2) as success_rate
FROM push_notifications
WHERE sent_at BETWEEN :start_date AND :end_date
GROUP BY DATE(sent_at)
ORDER BY date DESC";
$stmt = $this->pdo->prepare($sql);
$stmt->execute([
':start_date' => $startDate,
':end_date' => $endDate
]);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
/**
* ์ฌ์ฉ์๋ณ ์๋ฆผ ์์ ํต๊ณ
*/
public function getUserStats($userId) {
$sql = "SELECT
COUNT(*) as total_received,
COUNT(DISTINCT DATE(sent_at)) as active_days,
MAX(sent_at) as last_notification
FROM push_notifications
WHERE user_id = :user_id AND status = 'sent'";
$stmt = $this->pdo->prepare($sql);
$stmt->execute([':user_id' => $userId]);
return $stmt->fetch(PDO::FETCH_ASSOC);
}
/**
* ์ธ๊ธฐ ์๋ฆผ ํ์
๋ถ์
*/
public function getPopularTypes($limit = 10) {
$sql = "SELECT
JSON_EXTRACT(data, '$.type') as notification_type,
COUNT(*) as count
FROM push_notifications
WHERE status = 'sent' AND data IS NOT NULL
GROUP BY notification_type
ORDER BY count DESC
LIMIT :limit";
$stmt = $this->pdo->prepare($sql);
$stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
/**
* ์คํจ ์์ธ ๋ถ์
*/
public function getFailureReasons() {
$sql = "SELECT
error_message,
COUNT(*) as count
FROM push_notifications
WHERE status = 'failed' AND error_message IS NOT NULL
GROUP BY error_message
ORDER BY count DESC";
$stmt = $this->pdo->query($sql);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
/**
* ํต๊ณ ๋ฆฌํฌํธ ์์ฑ
*/
public function generateReport($startDate, $endDate) {
$stats = $this->getStats($startDate, $endDate);
$failures = $this->getFailureReasons();
$popularTypes = $this->getPopularTypes();
$report = "=== ํธ์ ์๋ฆผ ํต๊ณ ๋ฆฌํฌํธ ===\n";
$report .= "๊ธฐ๊ฐ: {$startDate} ~ {$endDate}\n\n";
$report .= "์ผ๋ณ ์ ์ก ํต๊ณ:\n";
foreach ($stats as $stat) {
$report .= sprintf(
"%s: ์ด %d๊ฑด (์ฑ๊ณต: %d, ์คํจ: %d, ์ฑ๊ณต๋ฅ : %s%%)\n",
$stat['date'],
$stat['total_sent'],
$stat['successful'],
$stat['failed'],
$stat['success_rate']
);
}
$report .= "\n์ธ๊ธฐ ์๋ฆผ ํ์
:\n";
foreach ($popularTypes as $type) {
$report .= sprintf(
"- %s: %d๊ฑด\n",
$type['notification_type'],
$type['count']
);
}
if (!empty($failures)) {
$report .= "\n์ฃผ์ ์คํจ ์์ธ:\n";
foreach ($failures as $failure) {
$report .= sprintf(
"- %s: %d๊ฑด\n",
$failure['error_message'],
$failure['count']
);
}
}
return $report;
}
}
// ์ฌ์ฉ ์์
$analytics = new PushAnalytics($pdo);
// ์ต๊ทผ 7์ผ ํต๊ณ
$report = $analytics->generateReport(
date('Y-m-d', strtotime('-7 days')),
date('Y-m-d')
);
echo $report;
// ํน์ ์ฌ์ฉ์ ํต๊ณ
$userStats = $analytics->getUserStats(123);
echo "\n์ฌ์ฉ์ ํต๊ณ:\n";
echo "์ด ์์ : {$userStats['total_received']}๊ฑด\n";
echo "ํ์ฑ ์ผ์: {$userStats['active_days']}์ผ\n";
echo "๋ง์ง๋ง ์๋ฆผ: {$userStats['last_notification']}\n";
?>
์ด๋ฐ ๋ถ์ ์์คํ
์ ๊ตฌ์ถํ๋ฉด:
- ์๋ฆผ ์ ์ก ์ฑ๊ณต๋ฅ ์ถ์
- ์ฌ์ฉ์ ์ฐธ์ฌ๋ ์ธก์
- ๋ฌธ์ ํจํด ์กฐ๊ธฐ ๋ฐ๊ฒฌ
- ๋ฐ์ดํฐ ๊ธฐ๋ฐ ์์ฌ๊ฒฐ์ ๊ฐ๋ฅ
์ ๋ง ์ ์ฉํ์ง? ๐
๐ฏ ์ค์ ํ์ฉ ์๋๋ฆฌ์ค
์ด์ ์ค์ ์๋น์ค์์ ์์ฃผ ์ฌ์ฉ๋๋ ์๋๋ฆฌ์ค๋ค์ ๊ตฌํํด๋ณด์! ๐ผ
๐ ์ ์์๊ฑฐ๋: ์ฅ๋ฐ๊ตฌ๋ ์๋ฆผ
์ฌ์ฉ์๊ฐ ์ฅ๋ฐ๊ตฌ๋์ ์ํ์ ๋ด๊ณ ๊ตฌ๋งคํ์ง ์์์ ๋ ๋ฆฌ๋ง์ธ๋ ์๋ฆผ์ ๋ณด๋ด๋ ๊ธฐ๋ฅ!
<?php
class CartReminderService {
private $pdo;
private $pushManager;
public function __construct($pdo, $pushManager) {
$this->pdo = $pdo;
$this->pushManager = $pushManager;
}
/**
* ์ฅ๋ฐ๊ตฌ๋ ๋ฐฉ์น ์ฌ์ฉ์ ์ฐพ๊ธฐ
*/
public function findAbandonedCarts($hoursAgo = 24) {
$sql = "SELECT
c.user_id,
u.name,
COUNT(ci.id) as item_count,
SUM(ci.price * ci.quantity) as total_amount,
MAX(c.updated_at) as last_updated
FROM carts c
JOIN cart_items ci ON c.id = ci.cart_id
JOIN users u ON c.user_id = u.id
WHERE c.updated_at < DATE_SUB(NOW(), INTERVAL :hours HOUR)
AND c.status = 'active'
AND NOT EXISTS (
SELECT 1 FROM orders o
WHERE o.user_id = c.user_id
AND o.created_at > c.updated_at
)
GROUP BY c.user_id
HAVING item_count > 0";
$stmt = $this->pdo->prepare($sql);
$stmt->execute([':hours' => $hoursAgo]);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
/**
* ์ฅ๋ฐ๊ตฌ๋ ๋ฆฌ๋ง์ธ๋ ์๋ฆผ ์ ์ก
*/
public function sendReminders() {
$abandonedCarts = $this->findAbandonedCarts(24);
echo "๋ฐฉ์น๋ ์ฅ๋ฐ๊ตฌ๋ " . count($abandonedCarts) . "๊ฑด ๋ฐ๊ฒฌ\n";
foreach ($abandonedCarts as $cart) {
$title = "์ฅ๋ฐ๊ตฌ๋๋ฅผ ํ์ธํด๋ณด์ธ์! ๐";
$body = sprintf(
"%s๋, %d๊ฐ ์ํ์ด ์ฅ๋ฐ๊ตฌ๋์์ ๊ธฐ๋ค๋ฆฌ๊ณ ์์ด์",
$cart['name'],
$cart['item_count']
);
$data = [
'type' => 'cart_reminder',
'item_count' => $cart['item_count'],
'total_amount' => $cart['total_amount'],
'action' => 'open_cart'
];
$result = $this->pushManager->sendToUser(
$cart['user_id'],
$title,
$body,
$data
);
if ($result['success']) {
echo "User {$cart['user_id']}: ์๋ฆผ ์ ์ก ์๋ฃ\n";
}
// API ์ ํ ๊ณ ๋ ค
usleep(100000);
}
}
}
// ํฌ๋ก ์ก์ผ๋ก ์คํ (๋งค์ผ ์ค์ 10์)
$cartReminder = new CartReminderService($pdo, $pushManager);
$cartReminder->sendReminders();
?>
๐ฆ ๋ฐฐ์ก ์ถ์ ์๋ฆผ
์ฃผ๋ฌธ ์ํ๊ฐ ๋ณ๊ฒฝ๋ ๋๋ง๋ค ์ค์๊ฐ์ผ๋ก ์๋ฆผ์ ๋ณด๋ด๋ ์์คํ !
<?php
class OrderNotificationService {
private $pushManager;
// ์ฃผ๋ฌธ ์ํ๋ณ ๋ฉ์์ง ํ
ํ๋ฆฟ
private $templates = [
'confirmed' => [
'title' => '์ฃผ๋ฌธ์ด ํ์ธ๋์์ต๋๋ค โ
',
'body' => '์ฃผ๋ฌธ๋ฒํธ {order_id}๊ฐ ํ์ธ๋์์ต๋๋ค. ๊ณง ๋ฐฐ์ก ์ค๋น์ ๋ค์ด๊ฐ๋๋ค.'
],
'preparing' => [
'title' => '์ํ ์ค๋น ์ค ๐ฆ',
'body' => '์ฃผ๋ฌธํ์ ์ํ์ ์ค๋นํ๊ณ ์์ต๋๋ค.'
],
'shipped' => [
'title' => '๋ฐฐ์ก์ด ์์๋์์ต๋๋ค ๐',
'body' => '์ด์ก์ฅ๋ฒํธ: {tracking_number}. ๊ณง ๋ฐ์๋ณด์ค ์ ์์ต๋๋ค!'
],
'delivered' => [
'title' => '๋ฐฐ์ก ์๋ฃ ๐',
'body' => '์ํ์ด ์์ ํ๊ฒ ๋ฐฐ์ก๋์์ต๋๋ค. ์ด์ฉํด์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค!'
]
];
public function __construct($pushManager) {
$this->pushManager = $pushManager;
}
/**
* ์ฃผ๋ฌธ ์ํ ๋ณ๊ฒฝ ์ ์๋ฆผ ์ ์ก
*/
public function notifyOrderStatus($orderId, $userId, $status, $additionalData = []) {
if (!isset($this->templates[$status])) {
return false;
}
$template = $this->templates[$status];
// ํ
ํ๋ฆฟ ๋ณ์ ์นํ
$title = $template['title'];
$body = $this->replaceVariables($template['body'], array_merge(
['order_id' => $orderId],
$additionalData
));
$data = [
'type' => 'order_status',
'order_id' => $orderId,
'status' => $status,
'action' => 'open_order_detail'
];
return $this->pushManager->sendToUser($userId, $title, $body, $data);
}
/**
* ํ
ํ๋ฆฟ ๋ณ์ ์นํ
*/
private function replaceVariables($text, $variables) {
foreach ($variables as $key => $value) {
$text = str_replace('{' . $key . '}', $value, $text);
}
return $text;
}
}
// ์ฌ์ฉ ์์ - ์ฃผ๋ฌธ ์ฒ๋ฆฌ ๋ก์ง์์ ํธ์ถ
$orderNotifier = new OrderNotificationService($pushManager);
// ์ฃผ๋ฌธ ํ์ธ
$orderNotifier->notifyOrderStatus(
orderId: 'ORD-12345',
userId: 123,
status: 'confirmed'
);
// ๋ฐฐ์ก ์์
$orderNotifier->notifyOrderStatus(
orderId: 'ORD-12345',
userId: 123,
status: 'shipped',
additionalData: ['tracking_number' => '1234567890']
);
?>
๐ฌ ์ฑํ ์๋ฆผ
์ค์๊ฐ ์ฑํ ์์ ์ ๋ฉ์์ง๊ฐ ๋์ฐฉํ์ ๋ ์๋ฆผ์ ๋ณด๋ด๋ ๊ธฐ๋ฅ!
<?php
class ChatNotificationService {
private $pdo;
private $pushManager;
public function __construct($pdo, $pushManager) {
$this->pdo = $pdo;
$this->pushManager = $pushManager;
}
/**
* ์ ๋ฉ์์ง ์๋ฆผ ์ ์ก
*/
public function notifyNewMessage($chatId, $senderId, $receiverId, $message) {
// ์์ ์๊ฐ ํ์ฌ ์ฑํ
๋ฐฉ์ ์๋์ง ํ์ธ
if ($this->isUserInChat($receiverId, $chatId)) {
return; // ์ด๋ฏธ ์ฑํ
๋ฐฉ์ ์์ผ๋ฉด ์๋ฆผ ๋ณด๋ด์ง ์์
}
// ๋ฐ์ ์ ์ ๋ณด ์กฐํ
$sender = $this->getUserInfo($senderId);
// ๋ฉ์์ง ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์์ฑ (์ต๋ 50์)
$preview = mb_substr($message, 0, 50);
if (mb_strlen($message) > 50) {
$preview .= '...';
}
$title = $sender['name'];
$body = $preview;
// ์ฝ์ง ์์ ๋ฉ์์ง ์ ์กฐํ
$unreadCount = $this->getUnreadCount($receiverId);
$data = [
'type' => 'chat_message',
'chat_id' => $chatId,
'sender_id' => $senderId,
'sender_name' => $sender['name'],
'sender_avatar' => $sender['avatar'],
'unread_count' => $unreadCount,
'action' => 'open_chat'
];
// iOS ๋ฐฐ์ง ์
๋ฐ์ดํธ๋ฅผ ์ํ ์ค์
$notification = Notification::create($title, $body)
->withImageUrl($sender['avatar']);
$message = CloudMessage::new()
->withNotification($notification)
->withData($data)
->withApnsConfig(ApnsConfig::fromArray([
'payload' => [
'aps' => [
'badge' => $unreadCount,
'sound' => 'message.wav'
]
]
]));
$tokens = $this->pushManager->getUserTokens($receiverId);
if (!empty($tokens)) {
return $this->pushManager->messaging->sendMulticast($message, $tokens);
}
}
/**
* ์ฌ์ฉ์๊ฐ ํ์ฌ ์ฑํ
๋ฐฉ์ ์๋์ง ํ์ธ
*/
private function isUserInChat($userId, $chatId) {
$sql = "SELECT COUNT(*) FROM active_chat_sessions
WHERE user_id = :user_id AND chat_id = :chat_id
AND last_activity > DATE_SUB(NOW(), INTERVAL 30 SECOND)";
$stmt = $this->pdo->prepare($sql);
$stmt->execute([
':user_id' => $userId,
':chat_id' => $chatId
]);
return $stmt->fetchColumn() > 0;
}
/**
* ์ฝ์ง ์์ ๋ฉ์์ง ์ ์กฐํ
*/
private function getUnreadCount($userId) {
$sql = "SELECT COUNT(*) FROM messages
WHERE receiver_id = :user_id AND is_read = 0";
$stmt = $this->pdo->prepare($sql);
$stmt->execute([':user_id' => $userId]);
return (int)$stmt->fetchColumn();
}
/**
* ์ฌ์ฉ์ ์ ๋ณด ์กฐํ
*/
private function getUserInfo($userId) {
$sql = "SELECT id, name, avatar FROM users WHERE id = :user_id";
$stmt = $this->pdo->prepare($sql);
$stmt->execute([':user_id' => $userId]);
return $stmt->fetch(PDO::FETCH_ASSOC);
}
}
// ์ฌ์ฉ ์์
$chatNotifier = new ChatNotificationService($pdo, $pushManager);
// ์ ๋ฉ์์ง ์ ์ก ์ ํธ์ถ
$chatNotifier->notifyNewMessage(
chatId: 'chat_789',
senderId: 123,
receiverId: 456,
message: '์๋
ํ์ธ์! ๋ฌธ์๋๋ฆด ๊ฒ ์์ด์์.'
);
?>
๐ ๋ณด์ ๋ฒ ์คํธ ํ๋ํฐ์ค
ํธ์ ์๋ฆผ ์์คํ ์ ์ฌ์ฉ์์ ๊ฐ์ธ์ ๋ณด์ ์ง๊ฒฐ๋์ด ์์ด์ ๋ณด์์ด ์ ๋ง ์ค์ํด! ๐
โ ๏ธ ๋ฐ๋์ ์ง์ผ์ผ ํ ๋ณด์ ์์น
1. ์๋น์ค ๊ณ์ ํค ๋ณดํธ
- ์ ๋ Git ์ ์ฅ์์ ์ปค๋ฐํ์ง ๋ง ๊ฒ
- .gitignore์ ๋ฐ๋์ ์ถ๊ฐ
- ์น ๋ฃจํธ ๋ฐ์ ์ ์ฅ
- ํ์ผ ๊ถํ์ 600์ผ๋ก ์ค์ (์ฝ๊ธฐ/์ฐ๊ธฐ ์์ ์๋ง)
2. FCM ํ ํฐ ๊ด๋ฆฌ
- ํ ํฐ์ ์ํธํํด์ ์ ์ฅ (์ ํ์ฌํญ์ด์ง๋ง ๊ถ์ฅ)
- ์ ๊ธฐ์ ์ผ๋ก ์ ํจํ์ง ์์ ํ ํฐ ์ ๋ฆฌ
- ์ฌ์ฉ์๊ฐ ๋ก๊ทธ์์ํ๋ฉด ํ ํฐ ๋นํ์ฑํ
3. ์๋ฆผ ๋ด์ฉ ๊ฒ์ฆ
- ์ฌ์ฉ์ ์
๋ ฅ์ ์๋ฆผ์ ํฌํจํ ๋๋ ๋ฐ๋์ ๊ฒ์ฆ ๋ฐ ์ด์ค์ผ์ดํ
- XSS ๊ณต๊ฒฉ ๋ฐฉ์ง๋ฅผ ์ํ HTML ํ๊ทธ ์ ๊ฑฐ
- ๋ฏผ๊ฐํ ์ ๋ณด(๋น๋ฐ๋ฒํธ, ์นด๋๋ฒํธ ๋ฑ)๋ ์ ๋ ์๋ฆผ์ ํฌํจํ์ง ๋ง ๊ฒ
4. Rate Limiting
- ๊ฐ์ ์ฌ์ฉ์์๊ฒ ๋๋ฌด ๋ง์ ์๋ฆผ์ ๋ณด๋ด์ง ์๋๋ก ์ ํ
- API ํธ์ถ ํ์ ์ ํ
- ์คํธ ๋ฐฉ์ง ๋ก์ง ๊ตฌํ
๐ก๏ธ ๋ณด์ ๊ฐํ ์ฝ๋ ์์
<?php
class SecurePushService {
private $pdo;
private $pushManager;
private $rateLimiter;
// ์ฌ์ฉ์๋น ์๊ฐ๋น ์ต๋ ์๋ฆผ ์
const MAX_NOTIFICATIONS_PER_HOUR = 10;
public function __construct($pdo, $pushManager) {
$this->pdo = $pdo;
$this->pushManager = $pushManager;
}
/**
* ์์ ํ ์๋ฆผ ์ ์ก
*/
public function sendSecure($userId, $title, $body, $data = []) {
// 1. Rate Limiting ์ฒดํฌ
if (!$this->checkRateLimit($userId)) {
throw new Exception('์๋ฆผ ์ ์ก ์ ํ์ ์ด๊ณผํ์ต๋๋ค.');
}
// 2. ์
๋ ฅ ๊ฒ์ฆ ๋ฐ ์ ์
$title = $this->sanitizeText($title);
$body = $this->sanitizeText($body);
$data = $this->sanitizeData($data);
// 3. ๋ฏผ๊ฐํ ์ ๋ณด ์ฒดํฌ
if ($this->containsSensitiveInfo($title . ' ' . $body)) {
throw new Exception('๋ฏผ๊ฐํ ์ ๋ณด๊ฐ ํฌํจ๋์ด ์์ต๋๋ค.');
}
// 4. ์๋ฆผ ์ ์ก
$result = $this->pushManager->sendToUser($userId, $title, $body, $data);
// 5. Rate Limit ์นด์ดํฐ ์ฆ๊ฐ
$this->incrementRateLimit($userId);
return $result;
}
/**
* Rate Limiting ์ฒดํฌ
*/
private function checkRateLimit($userId) {
$sql = "SELECT COUNT(*) FROM push_notifications
WHERE user_id = :user_id
AND sent_at > DATE_SUB(NOW(), INTERVAL 1 HOUR)";
$stmt = $this->pdo->prepare($sql);
$stmt->execute([':user_id' => $userId]);
$count = $stmt->fetchColumn();
return $count < self::MAX_NOTIFICATIONS_PER_HOUR;
}
/**
* Rate Limit ์นด์ดํฐ ์ฆ๊ฐ
*/
private function incrementRateLimit($userId) {
// Redis๋ฅผ ์ฌ์ฉํ๋ฉด ๋ ํจ์จ์
$key = "rate_limit:push:{$userId}";
// ๊ตฌํ์ ์บ์ ์์คํ
์ ๋ฐ๋ผ ๋ค๋ฆ
}
/**
* ํ
์คํธ ์ ์ (XSS ๋ฐฉ์ง)
*/
private function sanitizeText($text) {
// HTML ํ๊ทธ ์ ๊ฑฐ
$text = strip_tags($text);
// ํน์๋ฌธ์ ์ด์ค์ผ์ดํ
$text = htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
// ๊ธธ์ด ์ ํ
$text = mb_substr($text, 0, 200);
return trim($text);
}
/**
* ๋ฐ์ดํฐ ๋ฐฐ์ด ์ ์
*/
private function sanitizeData($data) {
$sanitized = [];
foreach ($data as $key => $value) {
// ํค ๊ฒ์ฆ
if (!preg_match('/^[a-zA-Z0-9_]+$/', $key)) {
continue;
}
// ๊ฐ ์ ์
if (is_string($value)) {
$sanitized[$key] = $this->sanitizeText($value);
} elseif (is_numeric($value)) {
$sanitized[$key] = $value;
} elseif (is_bool($value)) {
$sanitized[$key] = $value;
}
}
return $sanitized;
}
/**
* ๋ฏผ๊ฐํ ์ ๋ณด ํฌํจ ์ฌ๋ถ ์ฒดํฌ
*/
private function containsSensitiveInfo($text) {
$patterns = [
'/\b\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}\b/', // ์นด๋๋ฒํธ
'/\b\d{6}[-\s]?\d{7}\b/', // ์ฃผ๋ฏผ๋ฑ๋ก๋ฒํธ
'/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/', // ์ด๋ฉ์ผ (์ ํ์ )
'/\bpassword\b/i', // ๋น๋ฐ๋ฒํธ ํค์๋
'/\bsecret\b/i', // ์ํฌ๋ฆฟ ํค์๋
];
foreach ($patterns as $pattern) {
if (preg_match($pattern, $text)) {
return true;
}
}
return false;
}
/**
* FCM ํ ํฐ ์ํธํ ์ ์ฅ
*/
public function encryptToken($token) {
$key = getenv('ENCRYPTION_KEY'); // ํ๊ฒฝ ๋ณ์์์ ํค ๊ฐ์ ธ์ค๊ธฐ
$iv = openssl_random_pseudo_bytes(16);
$encrypted = openssl_encrypt($token, 'AES-256-CBC', $key, 0, $iv);
return base64_encode($iv . $encrypted);
}
/**
* FCM ํ ํฐ ๋ณตํธํ
*/
public function decryptToken($encryptedToken) {
$key = getenv('ENCRYPTION_KEY');
$data = base64_decode($encryptedToken);
$iv = substr($data, 0, 16);
$encrypted = substr($data, 16);
return openssl_decrypt($encrypted, 'AES-256-CBC', $key, 0, $iv);
}
}
// ์ฌ์ฉ ์์
$securePush = new SecurePushService($pdo, $pushManager);
try {
$result = $securePush->sendSecure(
userId: 123,
title: '์์ ํ ์๋ฆผ',
body: '๋ณด์์ด ๊ฐํ๋ ์๋ฆผ์
๋๋ค',
data: ['type' => 'secure_notification']
);
echo "์์ ํ๊ฒ ์ ์ก๋์์ต๋๋ค!";
} catch (Exception $e) {
echo "์ค๋ฅ: " . $e->getMessage();
}
?>
์ด๋ฐ ๋ณด์ ์กฐ์น๋ค์ ์ ์ฉํ๋ฉด ํจ์ฌ ์์ ํ ํธ์ ์๋ฆผ ์์คํ ์ ๊ตฌ์ถํ ์ ์์ด! ๐ก๏ธ
โก ์ฑ๋ฅ ์ต์ ํ ํ
๋ง์ง๋ง์ผ๋ก ํธ์ ์๋ฆผ ์์คํ ์ ์ฑ๋ฅ์ ๊ทน๋ํํ๋ ๋ฐฉ๋ฒ๋ค์ ์์๋ณด์! ๐
๐จ ์บ์ฑ ์ ๋ต
์์ฃผ ์ฌ์ฉ๋๋ ๋ฐ์ดํฐ๋ ์บ์์ ์ ์ฅํด์ ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ถํ๋ฅผ ์ค์ด์!
<?php
class CachedPushService {
private $redis;
private $pdo;
private $pushManager;
const CACHE_TTL = 3600; // 1์๊ฐ
public function __construct($redis, $pdo, $pushManager) {
$this->redis = $redis;
$this->pdo = $pdo;
$this->pushManager = $pushManager;
}
/**
* ์บ์๋ฅผ ํ์ฉํ ํ ํฐ ์กฐํ
*/
public function getUserTokensCached($userId) {
$cacheKey = "user_tokens:{$userId}";
// ์บ์์์ ๋จผ์ ํ์ธ
$cached = $this->redis->get($cacheKey);
if ($cached !== false) {
return json_decode($cached, true);
}
// ์บ์ ๋ฏธ์ค - DB์์ ์กฐํ
$tokens = $this->pushManager->getUserTokens($userId);
// ์บ์์ ์ ์ฅ
$this->redis->setex($cacheKey, self::CACHE_TTL, json_encode($tokens));
return $tokens;
}
/**
* ํ ํฐ ์บ์ ๋ฌดํจํ
*/
public function invalidateTokenCache($userId) {
$cacheKey = "user_tokens:{$userId}";
$this->redis->del($cacheKey);
}
/**
* ์ฌ์ฉ์ ์ ๋ณด ์บ์ฑ
*/
public function getUserInfoCached($userId) {
$cacheKey = "user_info:{$userId}";
$cached = $this->redis->get($cacheKey);
if ($cached !== false) {
return json_decode($cached, true);
}
$sql = "SELECT id, name, avatar FROM users WHERE id = :user_id";
$stmt = $this->pdo->prepare($sql);
$stmt->execute([':user_id' => $userId]);
$userInfo = $stmt->fetch(PDO::FETCH_ASSOC);
$this->redis->setex($cacheKey, self::CACHE_TTL, json_encode($userInfo));
return $userInfo;
}
}
?>
๐ ๋น๋๊ธฐ ์ฒ๋ฆฌ
์๋ฆผ ์ ์ก์ ๋น๋๊ธฐ๋ก ์ฒ๋ฆฌํด์ ์ฌ์ฉ์ ์์ฒญ์ ๋น ๋ฅด๊ฒ ์๋ตํ์!
<?php
// Guzzle์ ์ฌ์ฉํ ๋น๋๊ธฐ HTTP ์์ฒญ ์์
use GuzzleHttp\Client;
use GuzzleHttp\Promise;
class AsyncPushService {
private $client;
public function __construct() {
$this->client = new Client([
'timeout' => 10,
'connect_timeout' => 5
]);
}
/**
* ๋น๋๊ธฐ๋ก ์ฌ๋ฌ ์๋ฆผ ๋์ ์ ์ก
*/
public function sendAsync($notifications) {
$promises = [];
foreach ($notifications as $notification) {
$promises[] = $this->client->postAsync(
'https://your-api-endpoint.com/push',
[
'json' => $notification,
'headers' => [
'Content-Type' => 'application/json'
]
]
);
}
// ๋ชจ๋ ์์ฒญ์ด ์๋ฃ๋ ๋๊น์ง ๋๊ธฐ
$results = Promise\Utils::settle($promises)->wait();
return $results;
}
}
?>
๐ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ต์ ํ
์ธ๋ฑ์ค๋ฅผ ์ ์ ํ ํ์ฉํ๊ณ ์ฟผ๋ฆฌ๋ฅผ ์ต์ ํํ์!
-- ์์ฃผ ์ฌ์ฉ๋๋ ์ฟผ๋ฆฌ๋ฅผ ์ํ ์ธ๋ฑ์ค
CREATE INDEX idx_user_devices_user_active
ON user_devices(user_id, is_active);
CREATE INDEX idx_push_notifications_user_sent
ON push_notifications(user_id, sent_at);
CREATE INDEX idx_push_notifications_status_sent
ON push_notifications(status, sent_at);
-- ํํฐ์
๋์ผ๋ก ๋์ฉ๋ ๋ฐ์ดํฐ ๊ด๋ฆฌ
ALTER TABLE push_notifications
PARTITION BY RANGE (YEAR(sent_at)) (
PARTITION p2023 VALUES LESS THAN (2024),
PARTITION p2024 VALUES LESS THAN (2025),
PARTITION p2025 VALUES LESS THAN (2026),
PARTITION p_future VALUES LESS THAN MAXVALUE
);
๐ ๋ง๋ฌด๋ฆฌํ๋ฉฐ
์! ์ ๋ง ๊ธด ์ฌ์ ์ด์์ง? ๐
ํ์ง๋ง ์ด์ PHP์ Firebase Cloud Messaging์ ํ์ฉํด์ ์๋ฒฝํ ํธ์ ์๋ฆผ ์์คํ
์ ๊ตฌ์ถํ ์ ์๊ฒ ๋์์ด!
์ฐ๋ฆฌ๊ฐ ํจ๊ป ๋ฐฐ์ด ๋ด์ฉ์ ์ ๋ฆฌํด๋ณด๋ฉด:
๐ ํต์ฌ ์์ฝ
1. ๊ธฐ์ด ์ค์
- Firebase ํ๋ก์ ํธ ์์ฑ ๋ฐ ์ค์
- PHP์์ Firebase Admin SDK ์ค์น
- ์๋น์ค ๊ณ์ ํค๋ฅผ ํตํ ์ธ์ฆ
2. ๊ธฐ๋ณธ ๊ตฌํ
- ๋จ์ผ ๊ธฐ๊ธฐ์ ์๋ฆผ ์ ์ก
- ๋ฉํฐ์บ์คํธ๋ก ์ฌ๋ฌ ๊ธฐ๊ธฐ์ ๋์ ์ ์ก
- ํ ํฝ ๋ฉ์์ง๊ณผ ์กฐ๊ฑด๋ถ ๋ฉ์์ง
3. ๊ณ ๊ธ ๊ธฐ๋ฅ
- ํ๋ซํผ๋ณ ์ปค์คํฐ๋ง์ด์ง (iOS/Android)
- ์ด๋ฏธ์ง, ์ฌ์ด๋, ๋ฐฐ์ง ๋ฑ ๋ฆฌ์น ์๋ฆผ
- ๋ฐ์ดํฐ ํ์ด๋ก๋ ํ์ฉ
4. ์ค์ ํ์ฉ
- ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๋ ๋ฐ ํ ํฐ ๊ด๋ฆฌ
- ๋๋ ์ ์ก ์ต์ ํ (๋ฐฐ์น ์ฒ๋ฆฌ, ํ ์์คํ
)
- ์ค์ ์๋น์ค ์๋๋ฆฌ์ค ๊ตฌํ
5. ๋ณด์ ๋ฐ ์ต์ ํ
- ๋ณด์ ๋ฒ ์คํธ ํ๋ํฐ์ค
- ์ฑ๋ฅ ์ต์ ํ ์ ๋ต
- ๋ชจ๋ํฐ๋ง ๋ฐ ๋ถ์
๋งํ๋ ๋ถ๋ถ์ด ์๊ฑฐ๋ ๋ ๊น์ด ์๋ ํ์ต์ด ํ์ํ๋ค๋ฉด, ์ฌ๋ฅ๋ท์์ ์ ๋ฌธ๊ฐ๋ค์ ๋์์ ๋ฐ์ ์ ์์ด. ์ค๋ฌด ๊ฒฝํ์ด ํ๋ถํ ๊ฐ๋ฐ์๋ค์ด ์ฝ๋ ๋ฆฌ๋ทฐ๋ถํฐ ์ํคํ ์ฒ ์ค๊ณ๊น์ง ๋์์ค ์ ์๊ฑฐ๋ ! ๐
ํธ์ ์๋ฆผ์ ์ฌ์ฉ์ ๊ฒฝํ์ ํฌ๊ฒ ํฅ์์ํฌ ์ ์๋ ๊ฐ๋ ฅํ ๋๊ตฌ์ผ. ํ์ง๋ง ๋๋ฌด ๋ง์ด ๋ณด๋ด๋ฉด ์คํ๋ ค ์ญํจ๊ณผ๊ฐ ๋ ์ ์์ผ๋, ํญ์ ์ฌ์ฉ์ ์
์ฅ์์ ์๊ฐํ๋ฉด์ ์ ์ ํ๊ฒ ํ์ฉํ๋ ๊ฒ ์ค์ํด! ๐ฑ
์ด ๊ธ์ด ๋์์ด ๋์๊ธฐ๋ฅผ ๋ฐ๋ผ! ์ง๋ฌธ์ด๋ ํผ๋๋ฐฑ์ด ์๋ค๋ฉด ์ธ์ ๋ ์ง ํ์์ด์ผ. ํจ๊ป ์ฑ์ฅํ๋ ๊ฐ๋ฐ์๊ฐ ๋์! ๐ช
ํ๋ณตํ ์ฝ๋ฉ ๋๊ธธ! Happy Coding! ๐
๐ ์ด์ ๋น์ ์ ์ฑ์ ๊ฐ๋ ฅํ ํธ์ ์๋ฆผ์ ๊ตฌํํด๋ณด์ธ์!
PHP + Firebase FCM = ์๋ฒฝํ ์กฐํฉ โจ
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.