app-vise/laravel-google-server-notifications

处理 Google Play 服务器之间的通知

dev-development 2019-11-20 09:39 UTC

This package is auto-updated.

Last update: 2024-09-21 22:22:29 UTC


README

Latest Version on Packagist Build Status StyleCI Scrutinizer Code Quality Total Downloads

安装

您可以通过 composer 安装此包

composer require app-vise/laravel-google-server-notifications 

服务提供者会自动注册。您需要使用以下命令发布配置文件:

php artisan vendor:publish --provider="Appvise\GooglePlayNotifications\NotificationsServiceProvider" --tag="config" 

这是将被发布的配置。

return [
    /*
     * 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.android.com.cn/google/play/billing/realtime_developer_notifications
     */
    'jobs' => [
        // 'subscription_recovered' => \App\Jobs\PlayStore\HandleRecovered::class,
        // 'subscription_renewed' => \App\Jobs\PlayStore\HandleRenewed::class,
        // 'subscription_canceled' =>  \App\Jobs\PlayStore\HandleCanceled::class,
        // 'subscription_purchased' => \App\Jobs\PlayStore\HandlePurchased::class,
        // 'subscription_on_hold' => \App\Jobs\PlayStore\HandleOnHold::class,
        // 'subscription_in_grace_period' => \App\Jobs\PlayStore\HandleInGracePeriod::class,
        // 'subscription_restarted' => \App\Jobs\PlayStore\HandleRestarted::class,
        // 'subscription_price_change_confirmed' => \App\Jobs\PlayStore\HandlePriceChangeConfirmed::class,
        // 'subscription_deferred' => \App\Jobs\PlayStore\HandleDeferred::class,
        // 'subscription_paused' => \App\Jobs\PlayStore\HandlePaused::class,
        // 'subscription_pause_schedule_changed' => \App\Jobs\PlayStore\HandlePauseScheduleChanged::class,
        // 'subscription_revoked' => \App\Jobs\PlayStore\HandleRevoked::class,
        // 'subscription_expired' => \App\Jobs\PlayStore\HandleExpired::class
    ],
];

此包会将所有传入的请求记录到数据库中,因此以下步骤是强制性的

php artisan vendor:publish --provider="Appvise\GooglePlayNotifications\NotificationsServiceProvider" --tag="migrations"

您应该运行迁移以创建 google_notifications 表

php artisan migrate

此包将注册一个 POST 路由 (/google/server/notifications) 到此包的 Webhookscontroller

用法

当订阅中发生更改时,Google 将通过 POST 请求向配置的端点发送实时通知。 遵循此指南设置 Pub/Sub:

如果您为正确的通知类型配置了正确的作业,此包将发送 200 响应;否则,它将向 Google 发送 500 响应。Google 将重试几次。传入的有效负载存储在 google_notifications 表中。

通过作业处理传入的通知

<?php

namespace App\Jobs\GooglePlayNotifications;

use App\Jobs\Job;

class HandleRecovered extends Job
{
    public $notification;

    public function __construct(array $notification)
    {
        $this->notification = $notification;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        // Do something that matches your business logic with $this->payload
    }
}

变更日志

请参阅变更日志以获取有关最近更改的更多信息。

测试

composer test

安全性

如果您发现任何安全相关的问题,请通过电子邮件daan@app-vise.nl 而不是使用问题跟踪器。

致谢

感谢 Spatie's laravel-stripe-webhooks,它为这个包提供了巨大的灵感和起点。

许可证

MIT 许可证 (MIT)。请参阅 许可证文件 以获取更多信息。