PHP code example of wangchengtao / exception-notify

1. Go to this page and download the library: Download wangchengtao/exception-notify library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wangchengtao / exception-notify example snippets


$channel = new Dingtalk([
    'access_token' => 'xxxxxxxxxxxxx',
    'auth_type' => 'sign', // 安全设置类型: keyword | sign
    'keyword' => '异常', // 当 auth_type 为 keyword 时,必填
    'secret' => 'xxxxxxxxxxxxxxxxxxxx', // 当 auth_type 为 sign 时,必填
    'at' => [], // 当 message 对象未指定@人员时,此为默认值
]);

$client = new Client($channel);

// 文本格式
$text = new DingtalkText();
$text->setTitle('测试');
$text->setContent('异常测试');
$text->setAt([
    '187*****897',
]);

$client->send($text);

// markdown 格式
$markdown = new DingtalkMarkdown();
$markdown->setTitle('Markdown消息标题');
$markdown->setContent("#### 这是Markdown消息内容 \n ![图片](https://example.com/image.png)");
$markdown->atAll();

$client->send($markdown);

use Summer\MessageNotify\Channel\AbstractChannel;
use Summer\MessageNotify\Message\AbstractMessage;

class CustomChannel extends AbstractChannel
{
    public function handleResponse(ResponseInterface $response): void
    {
        // 
    }
    
    public function notify(AbstractMessage $message): ResponseInterface
    {
        // 
    }
}

class CustomMessage extends AbstractMessage
{
    public function getBody() : array
    {
        //
    }
}

$message = new CustomMessage();
$message->setTitle('自定义标题');
$message->setContent('自定义消息');

$channel = new CustomChannel([
    'access_token' => 'xxxxxxxxxxxxx',
]);

$client = new Client($channel);

$client->send($text);