custom-d/webhook-registry 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

custom-d/webhook-registry

Composer 安装命令:

composer require custom-d/webhook-registry

包简介

A webhook registry to manage webhooks in laravel projects

README 文档

README

Build Status styleci Scrutinizer Code Quality SensioLabsInsight Coverage Status

Packagist Packagist Packagist

A wrapper for spatie/laravel-webhook-server that provides a simple & flexible webhook registry, allows you to expose any Laravel Event as a webhook, and provides out-of-the-box logging of webhook results.

Installation

Install via composer

composer require custom-d/webhook-registry

Publish Configuration File

php artisan vendor:publish --provider="CustomD\WebhookRegistry\ServiceProvider" --tag="config"

Usage

1. Trigger registered webhooks via events

Implement the CustomD\WebhookRegistry\Contracts\ShouldDeliverWebhooks contract on any Laravel Event, and you'll be able to register webhooks that will be fired on this event.

This contract defines several methods that need to be defined on your event, which will help provide the payload details.

Method Purpose
getWebhookPayload Returns the payload to send to the Spatie Webhook call. Useful if you want to completely override the payload.
getWebhookContext Returns the payload context field. Useful if you want to set a different property. Defaults to returning the ->context property from the event. If this property is Arrayable, we'll call ->toArray(). You can overload this method on your event if you want to customise this behaviour.
getWebhookEventName Returns the event name you want to expose in the payload. Useful for endpoints who recieve multiple different types of event to determine how to handle calls. By default, this is the value of the ->webhookEventName property from the event, otherwise we fall back to the event class name.
shouldDeliverWebhook Whether to deliver webhooks for this event. Defaults to true.

Your payload must define a body, but can also define tags and meta information for passing to Spatie\WebhookServer\WebhookCall.

    /**
     * Get the payload for this webhook event
     */
    public function getWebhookPayload(): array
    {
        return [
            'body' => [
                'status' => $this->status,
            ]
        ];
    }

2. Register webooks

Create webhook endpoints direction using the CustomD\WebhookRegistry\Models\WebhookEndpoint model, or use the facade WebhookRegistry::registerEndpoint.

$endpoint = WebhookRegistry::registerEndpoint(
  'https://webhook.site/custom/endpoint',
  'My webhook endpoint name'
);

By default, we'll verify SSL certificates on outgoing webhook connections. If you want to disable SSL verification, you can pass false to the registerEndpoint function.

$endpoint = WebhookRegistry::registerEndpoint(
  'https://localhost/webhook-test',
  'My insecure endpoint',
  false
);

3. Bind events to an endpoint

Associate a webhook event to an endpoint with the CustomD\WebhookRegistry\Model\WebhookEvent model, or using the facade WebhookRegistry::registerEvent.

$event = WebhookRegistry::registerEvent($webhook->id, 'App\Events\MyEvent');

Models

Customise the WebhookEvent model in order to add logic about when events should fire. In config/webhook-registry.php you will see the models being used in models -> events. You can make your own models by implementing the appropriate contract, and updating the config file.

WebhookEndpoint extends Model implements CustomD\WebhookRegistry\Models\Contracts\WebhookEndpointContract
WebhookEvent extends Model implements CustomD\WebhookRegistry\Models\Contracts\WebhookEventContract

If you need to modify the WebhookRequest logging table, note that it doesn't need a contract and can be overridden as needed, but ensure the original fields exist, or define appropriate attribute mappings.

Custom 'dispatchable' logic

To determine which events are dispatchable in a given execution, you must set a scopeWhereDispatchable on the WebhookEvent model. This scope will be used when finding events that should be fired.

By default this scope doesn't do any filtering.

Security

If you discover any security related issues, please email instead of using the issue tracker.

Credits

This package is bootstrapped with the help of melihovv/laravel-package-generator.

custom-d/webhook-registry 适用场景与选型建议

custom-d/webhook-registry 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.28k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「registry」 「webhook」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 custom-d/webhook-registry 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 custom-d/webhook-registry 我们能提供哪些服务?
定制开发 / 二次开发

基于 custom-d/webhook-registry 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.28k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-12-06