tmdan / laravel-appstore-server-notifications
处理 Appstore 服务器之间的通知
0.0.3
2021-02-09 09:21 UTC
Requires
- php: ^7.1
- bensampo/laravel-enum: ^1.0
- illuminate/support: ^5.5|^6.0|^7.0|^8.0
Requires (Dev)
- orchestra/testbench: ~3.7.0|^4.0
- phpunit/phpunit: ^8.2
This package is auto-updated.
Last update: 2024-09-17 12:49:00 UTC
README
安装
您可以通过 composer 安装此包
composer require tmdan/laravel-appstore-server-notifications
服务提供者将自动注册。您需要使用以下命令发布配置文件:
php artisan vendor:publish --provider="Appvise\AppStoreNotifications\NotificationsServiceProvider" --tag="config"
这是将要发布的配置:
return [ /* * Apple will send the shared secret with the request that should match * the one you use when validating receipts. * https://developer.apple.com/documentation/storekit/in-app_purchase/enabling_server-to-server_notifications?language=objc#overview */ 'shared_secret' => env('APPLE_SHARED_SECRET'), /* * All the events that should be handeled by your application. * Typically you should uncomment all jobs * * You can find a list of all notification types here: * https://developer.apple.com/documentation/storekit/in-app_purchase/enabling_server-to-server_notifications?language=objc#3162176 */ 'jobs' => [ // 'initial_buy' => \App\Jobs\AppstoreNotifications\HandleInitialBuy::class, // 'cancel' => \App\Jobs\AppstoreNotifications\HandleCancellation::class, // 'renewal' => \App\Jobs\AppstoreNotifications\HandleRenewal::class, // 'interactive_renewal' => \App\Jobs\AppstoreNotifications\HandleInteractiveRenewal::class, // 'did_change_renewal_pref' => \App\Jobs\AppstoreNotifications\HandleDidChangeRenewalPreferences::class, // 'did_change_renewal_status' => \App\Jobs\AppstoreNotifications\HandleDidChangeRenewalStatus::class, ], ];
共享密钥应该与您发送给商店以验证收据的密钥匹配
此包会将所有传入请求记录到数据库中,因此这些步骤是强制性的
php artisan vendor:publish --provider="Appvise\AppStoreNotifications\NotificationsServiceProvider" --tag="migrations"
您应该运行迁移来创建 apple_notifications 表
php artisan migrate
此包将注册一个 POST 路由 (/apple/server/notifications) 到此包的 Webhookscontroller
使用
当苹果订阅中发生变更时,苹果将向配置的端点发送 POST 请求。请按照以下指南配置端点:配置端点指南
如果您配置了正确的作业和通知类型,此包将发送 200 响应;否则,它将向苹果发送 500 响应。苹果将重试几次。传入的有效负载将存储在 apple_notifications 表中。
通过作业处理传入的通知
<?php namespace App\Jobs\AppstoreNotifications; use App\Jobs\Job; use Appvise\AppStoreNotifications\Model\NotificationPayload; class HandleInitialBuy extends Job { public $payload; public function __construct(NotificationPayload $payload) { $this->payload = $payload; } /** * Execute the job. * * @return void */ public function handle() { // Do something that matches your business logic with $this->payload } }
变更日志
请参阅 CHANGELOG 获取有关最近更改的更多信息。
测试
composer test
安全
如果您发现任何安全问题,请通过电子邮件 daan@app-vise.nl 联系我们,而不是使用问题跟踪器。
致谢
衷心感谢 Spatie's 的 laravel-stripe-webhooks,它是此包的巨大灵感和起点
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。