rajchotaliya/apple-push-notification-service
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
-
Configuration :
-
Environment Variables (Required)
Add the following entries to your
.envfile: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.phpfile into your Laravel project'sconfigdirectory. 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')), ];
-
-
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
-
Configuration (Required) :
Manually create a configuration file at
config/apns.phpin your project root directory:<?php return [ 'bundle_id' => 'com.example.app', 'key_id' => 'ABC123DEF456', 'team_id' => 'XYZ789', 'private_key_path' => __DIR__ . '/AuthKey.p8', ];
-
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:
rajchotaliya/apple-push-notification-service 适用场景与选型建议
rajchotaliya/apple-push-notification-service 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 5, 最近一次更新时间为 2025 年 02 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 rajchotaliya/apple-push-notification-service 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rajchotaliya/apple-push-notification-service 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-01