neyric / yousign-bundle
Symfony 的 Yousign Bundle
v0.0.7
2021-10-16 21:02 UTC
Requires
- symfony/event-dispatcher: ^4.4 || ^5.0
- symfony/framework-bundle: ^4.4 || ^5.0
- symfony/http-client: ^4.4 || ^5.0
- symfony/yaml: ^4.4 || ^5.0
Requires (Dev)
- phpunit/phpunit: >=6.0
- symfony/browser-kit: ^4.4 || ^5.0
README
为 Yousign 提供的 Symfony Bundle。
- 提供服务以访问 API,以实现更好的 Symfony 集成
- Webhook 处理程序(HTTP 控制器)+ Webhook 事件
要求
- Php >= 7.1
- Symfony 4.4 或 5+
安装
$ composer require neyric/yousign-bundle
在您的应用程序中加载 Bundle
$bundles = [ // ... new \Neyric\YousignBundle\NeyricYousignBundle(), ];
配置
该 Bundle(特别是 YousignApiClient)期望定义以下 2 个环境变量
- YOUSIGN_BASE_URL(应该是 https://staging-app.yousign.com 或 https://api.yousign.com)
- YOUSIGN_API_KEY
使用 webhook 处理程序
首先,在您的 routes.yaml 文件中设置路由
neyric_yousign: path: /yousign_webook/hook_handler # Customizable url controller: Neyric\YousignBundle\Controller\YousignController::webhookHandlerAction
创建一个订阅者
use Neyric\YousignBundle\Event\WebhookEvent; class MySubscriber implements EventSubscriberInterface { public function onYousignWebhook(WebhookEvent $event) { $headers = $event->getHeaders(); if (array_key_exists('x-my-custom-header', $headers)) { // ... } // ... } public static function getSubscribedEvents() { return [ WebhookEvent::class => ['onYousignWebhook'], ]; } }
最终,使用 kernel.event_subscriber
标签声明服务
App\Subscriber\MySubscriber: class: App\Subscriber\MySubscriber tags: - { name: kernel.event_subscriber }
准备本地隧道
使用本地隧道可以节省您大量时间,因为您可以在本地进行测试。推荐选择 ngrok。Ngrok 是一种将我们的本地服务器隧道到网络上的工具,使我们的本地 webhook 处理程序可用于电子邮件提供商的 webhook。
许可证
neyric/yousign-bundle 采用 MIT 许可证发行,请参阅 LICENSE 文件。
联系方式
使用 GitHub 上的问题跟踪器报告错误或建议功能。