PHP code example of tourze / jiguang-push-bundle
1. Go to this page and download the library: Download tourze/jiguang-push-bundle library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tourze / jiguang-push-bundle example snippets
// config/bundles.php
return [
// ...
JiguangPushBundle\JiguangPushBundle::class => ['all' => true],
];
use JiguangPushBundle\Entity\Account;
$account = new Account();
$account->setTitle('My App Push Account');
$account->setAppKey('your-app-key-from-jiguang');
$account->setMasterSecret('your-master-secret-from-jiguang');
$account->setValid(true);
$entityManager->persist($account);
$entityManager->flush();
use JiguangPushBundle\Entity\Device;
$device = new Device();
$device->setAccount($account);
$device->setRegistrationId('device-registration-id');
$device->setAlias('user-alias');
$device->setMobile('13800138000');
$entityManager->persist($device);
$entityManager->flush();
use JiguangPushBundle\Entity\Push;
use JiguangPushBundle\Entity\Embedded\Audience;
use JiguangPushBundle\Entity\Embedded\Notification;
use JiguangPushBundle\Enum\PlatformEnum;
use JiguangPushBundle\Request\PushRequest;
use JiguangPushBundle\Service\JiguangService;
// Create push entity
$push = new Push();
$push->setAccount($account);
$push->setPlatform(PlatformEnum::ALL);
// Configure audience
$audience = new Audience();
$audience->setAll(true);
$push->setAudience($audience);
// Configure notification
$notification = new Notification();
$notification->setAlert('Hello from Jiguang!');
$notification->setTitle('Welcome');
$push->setNotification($notification);
// Send push
$request = new PushRequest();
$request->setAccount($account);
$request->setMessage($push);
$service = $container->get(JiguangService::class);
$result = $service->request($request);
use JiguangPushBundle\Entity\Embedded\Audience;
use JiguangPushBundle\Entity\Embedded\AndroidNotification;
use JiguangPushBundle\Entity\Embedded\IosNotification;
// Create audience with tags
$audience = new Audience();
$audience->setTag(['vip', 'premium']);
$push->setAudience($audience);
// Platform-specific notifications
$androidNotification = new AndroidNotification();
$androidNotification->setTitle('Android Title');
$androidNotification->setBuilderId(1);
$iosNotification = new IosNotification();
$iosNotification->setSound('default');
$iosNotification->setBadge(1);
$notification = new Notification();
$notification->setAlert('Cross-platform notification');
$notification->setAndroid($androidNotification);
$notification->setIos($iosNotification);
$push->setNotification($notification);
bash
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate