定制 rajchotaliya/apple-push-notification-service 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rajchotaliya/apple-push-notification-service

最新稳定版本:1.4.0

Composer 安装命令:

composer require rajchotaliya/apple-push-notification-service

包简介

A PHP package to send push notifications using Apple's APNs.

README 文档

README

A PHP library to send push notifications to Apple devices using the APNs service.

Installation

Install the library using Composer:

composer require rajchotaliya/apple-push-notification-service

Usage

Laravel

  1. Configuration :

    • Environment Variables (Required)

      Add the following entries to your .env file:

      APNS_BUNDLE_ID=your_bundle_id
      APNS_KEY_ID=your_key_id
      APNS_TEAM_ID=your_team_id
      APNS_PRIVATE_KEY_PATH=/path/to/your/AuthKey.p8
    • Publish Config File (Optional)

      After installing the package, publish the configuration file using the following Artisan command:

      php artisan vendor:publish --provider="RajChotaliya\ApplePushNotificationService\ApplePushNotificationServiceProvider"

      This will publish the apns.php file into your Laravel project's config directory. You can then customize it to fit your needs.

      Example configuration in config/apns.php:

      return  [
         'bundle_id' => env('APNS_BUNDLE_ID', ''),
         'key_id' => env('APNS_KEY_ID', ''),
         'team_id' => env('APNS_TEAM_ID', ''),
         'private_key_path' => env('APNS_PRIVATE_KEY_PATH', storage_path('AuthKey.p8')),
      ];
  2. Using the Library:

    You can use the library in your Laravel application as follows:

    use RajChotaliya\ApplePushNotificationService\ApplePushNotificationService;
    
    $deviceToken = 'your_device_token';
    $title = 'Hello from APNs!';
    $body = 'This is a test push notification.';
    
    $apns = new ApplePushNotificationService($deviceToken, $title, $body);
    $response = $apns->sendNotification();

Core PHP

  1. Configuration (Required) :

    Manually create a configuration file at config/apns.php in your project root directory:

    <?php
    
    return [
        'bundle_id' => 'com.example.app',
        'key_id' => 'ABC123DEF456',
        'team_id' => 'XYZ789',
        'private_key_path' => __DIR__ . '/AuthKey.p8',
    ];
  2. Using the Library:

    You can use the library in a Core PHP project as follows:

    require 'vendor/autoload.php';
    
    use RajChotaliya\ApplePushNotificationService\ApplePushNotificationService;
    
    $deviceToken = 'your_device_token';
    $title = 'Hello from APNs!';
    $body = 'This is a test push notification.';
    
    $apns = new ApplePushNotificationService($deviceToken, $title, $body);
    $response = $apns->sendNotification();
    
    echo $response['message'];

Fetch JWT for Authentication (Separate Token Fetch)

  • Fetch JWT for Authentication (Separate Token Fetch)

    To fetch the JWT (JSON Web Token) for authentication with Apple's APNs service, you can use the following method. This token is used for making authenticated requests to the APNs service.

    Example:

    $jwt = $apns->fetchJWT();

    The fetchJWT() method retrieves the token needed for authenticating requests, ensuring that your notifications are sent securely to the APNs service.

Features

  • Laravel Support: Includes a service provider and configuration publishing for seamless integration.
  • Core PHP Compatibility: Easily load configuration and use the library without a framework.
  • Cross-Platform: Compatible with all PHP versions >= 8.0.

Support

Feel free to contribute or raise issues in the GitHub repository.

Show Your Appreciation

You can show your appreciation by buying me a tea through the following link:

Buy me a tea

统计信息

  • 总下载量: 18
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-01