Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Jpush Laravel Package

phpvital/laravel-jpush

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require phpvital/laravel-jpush
    

    Publish the config file:

    php artisan vendor:publish --provider="Vital\Jpush\JpushServiceProvider"
    
  2. Configuration Edit .env with your JPush credentials:

    JPUSH_APP_KEY=your_app_key
    JPUSH_MASTER_SECRET=your_master_secret
    
  3. First Use Case Send a push notification to all devices:

    use Vital\Jpush\Jpush;
    
    $jpush = app(Jpush::class);
    $result = $jpush->push()
        ->platform('all')
        ->notification([
            'alert' => 'Hello from Laravel!',
            'title' => 'Notification Title',
        ])
        ->send();
    

Implementation Patterns

Common Workflows

  1. Targeted Pushes Use registration IDs or tags for granular targeting:

    $jpush->push()
        ->platform('android')
        ->registrationId('device_reg_id_123')
        ->notification(['alert' => 'Custom message'])
        ->send();
    
  2. Message vs. Notification

    • Notification (visible in status bar):
      ->notification(['alert' => 'Text', 'title' => 'Title'])
      
    • Message (silent push):
      ->message(['msg_content' => 'Silent data'])
      
  3. Custom Payload Extend with custom extras:

    ->notification(['alert' => 'Hello'])
    ->extras(['key' => 'value'])
    
  4. Batch Operations Use queues for high-volume pushes:

    $jpush->push()
        ->platform('ios')
        ->alias('user_alias_123')
        ->notification(['alert' => 'Batch message'])
        ->queue(); // Dispatches to queue
    

Integration Tips

  • Laravel Events: Trigger pushes on user actions:
    event(new UserLoggedIn($user));
    // In listener:
    $jpush->push()->alias($user->alias)->notification(['alert' => 'Welcome back!'])->send();
    
  • API Responses: Attach push status to API responses:
    return response()->json(['success' => true, 'push_status' => $result]);
    
  • Logging: Log push results for debugging:
    \Log::info('JPush result', $result);
    

Gotchas and Tips

Pitfalls

  1. Platform-Specific Quirks

    • Android: Requires registration_id or alias for targeting.
    • iOS: Uses alias or tag; ensure APNs certificates are valid.
    • Test Mode: Use isProduction(false) in config for sandbox testing.
  2. Rate Limits JPush imposes rate limits. Batch pushes or queue them to avoid throttling.

  3. Deprecated Methods Avoid pushAll() (deprecated in newer JPush SDKs). Use platform('all') instead.

  4. Environment Mismatch Ensure .env values match your JPush console settings (e.g., JPUSH_APP_KEY for the correct app).

Debugging

  • Response Codes: Check $result['response_code'] for errors (e.g., 200 = success, 401 = auth failure).
  • Logs: Enable JPush debug mode in config:
    'debug' => env('JPUSH_DEBUG', false),
    
  • Payload Validation: Use JPush’s API docs to validate payload structure.

Extension Points

  1. Custom Responses Override the default response handler in app/Providers/JpushServiceProvider.php:

    $jpush->extend('response', function ($result) {
        return collect($result)->only(['msg_id', 'is_success']);
    });
    
  2. Queue Drivers Configure the queue driver in config/jpush.php:

    'queue' => [
        'driver' => 'database', // or 'redis', 'beanstalkd'
    ],
    
  3. Event Listeners Extend the package by listening to jpush.sent events:

    Event::listen('jpush.sent', function ($result) {
        // Custom logic (e.g., analytics)
    });
    
  4. Testing Use Laravel’s HTTP tests to mock JPush responses:

    $this->mock(Jpush::class, function ($mock) {
        $mock->shouldReceive('send')->andReturn(['response_code' => 200]);
    });
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui