使用以下方法可以通过 PHP 发送 message 到 slack
- 创建 Incoming Webhooks
- 下载类库
- 发送消息
Creating incoming webhook
打开 Slack API 管理页面
https://api.slack.com
点击右上角的 Your Apps
Installing the package
类库的地址:
https://packagist.org/packages/alek13/slack
可以通过以下命令直接下载
composer require alek13/slack
Sending a message with PHP
<?php
require __DIR__ . '/vendor/autoload.php';
// send message to slack easeware group
$hookUrl = 'https://hooks.slack.com/services/Txxxxxxxx/Bxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxx';
$settings = [
'username' => 'Developer',
'channel' => '#Channel',
];
$client = new Maknz\Slack\Client($hookUrl, $settings);
$client->send("Hello world!");
More Info
有关发送消息的更多信息可以查看以下链接
https://github.com/php-slack/slack#sending-messages
参考资料:
https://api.slack.com/incoming-webhooks
https://dev.to/phpprofi/slack-send-simple-message–3pj7