knocklabs/knock-php
Composer 安装命令:
composer require knocklabs/knock-php
包简介
Knock PHP SDK
README 文档
README
Documentation
See the documentation for PHP usage examples.
Installation
composer require knocklabs/knock-php php-http/guzzle7-adapter
Configuration
To use the library you must provide a secret API key, provided in the Knock dashboard.
use Knock\KnockSdk\Client; $client = new Client('sk_12345');
Usage
Identifying users
$client->users()->identify('jhammond', [ 'name' => 'John Hammond', 'email' => 'jhammond@ingen.net', ]);
Sending notifies (triggering workflows)
$client->workflows()->trigger('dinosaurs-loose', [ // user id of who performed the action 'actor' => 'dnedry', // list of user ids for who should receive the notification 'recipients' => ['jhammond', 'agrant', 'imalcolm', 'esattler'], // data payload to send through 'data' => [ 'type' => 'trex', 'priority' => 1, ], // an optional identifier for the tenant that the notifications belong to 'tenant' => 'jurassic-park', // an optional key to provide to cancel a notify 'cancellation_key' => '21e958bb-2517-40bb-aaaa-d40acc26dac3', ]);
Retrieving users
$client->users()->get('jhammond');
Deleting users
$client->users()->delete('jhammond');
Preferences
$client->users()->setPreferences('jhammond', [ 'channel_types' => [ 'email' => true, 'sms' => false, ], 'workflows' => [ 'dinosaurs-loose' => [ 'email' => false, 'in_app_feed': true, ] ] ]);
Getting and setting channel data
$knock->users()->setChannelData('jhammond', '5a88728a-3ecb-400d-ba6f-9c0956ab252f', [ 'tokens' => [ $apnsToken ], }); $knock->users()->getChannelData('jhammond', '5a88728a-3ecb-400d-ba6f-9c0956ab252f');
Canceling workflows
$client->workflows()->cancel('dinosaurs-loose', [ 'cancellation_key' => '21e958bb-2517-40bb-aaaa-d40acc26dac3' // optionally you can specify recipients here 'recipients' => ['jhammond'], ]);
Signing JWTs
You can use the firebase/php-jwt package to sign JWTs easily.
You will need to generate an environment specific signing key, which you can find in the Knock dashboard.
If you're using a signing token you will need to pass this to your client to perform authentication. You can read more about client-side authentication here.
use Firebase\JWT\JWT; $privateKey = env('KNOCK_SIGNING_KEY'); $encoded = JWT::encode(['sub' => 'jhammond'], $privateKey, 'RS256');
Test
To run tests, first run composer in the terminal. Once compiled, you can run phpunit tests/ to run the suite.
knocklabs/knock-php 适用场景与选型建议
knocklabs/knock-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 179.25k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2022 年 05 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 knocklabs/knock-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 knocklabs/knock-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 179.25k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-05-27