{"id":21018678,"url":"https://github.com/tal-tech/alarm-dog-noticer","last_synced_at":"2025-05-15T06:31:41.183Z","repository":{"id":56954231,"uuid":"307708087","full_name":"tal-tech/alarm-dog-noticer","owner":"tal-tech","description":"哮天犬告警平台通知组件","archived":false,"fork":false,"pushed_at":"2020-10-27T13:29:08.000Z","size":23,"stargazers_count":2,"open_issues_count":0,"forks_count":8,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-18T11:43:45.965Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tal-tech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-27T13:25:10.000Z","updated_at":"2021-10-19T03:30:21.000Z","dependencies_parsed_at":"2022-08-21T08:50:07.787Z","dependency_job_id":null,"html_url":"https://github.com/tal-tech/alarm-dog-noticer","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tal-tech%2Falarm-dog-noticer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tal-tech%2Falarm-dog-noticer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tal-tech%2Falarm-dog-noticer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tal-tech%2Falarm-dog-noticer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tal-tech","download_url":"https://codeload.github.com/tal-tech/alarm-dog-noticer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254288212,"owners_count":22045862,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T10:27:03.222Z","updated_at":"2025-05-15T06:31:38.480Z","avatar_url":"https://github.com/tal-tech.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 哮天犬通知组件\n\n适配Hyperf框架的通知组件，支持短信、电话、邮件、钉钉工作通知、钉钉机器人等通知渠道\n\n\n# 安装\n\n```shell\n# composer安装依赖\ncomposer require alarm-dog/noticer\n```\n\n# 配置\n\n使用Hyperf框架工具生成默认配置：\n\n```shell\nphp bin/hyperf.php vendor:publish alarm-dog/noticer\n```\n\n默认配置文件将会被拷贝到框架根目录 `config/autoload/noticer.php`\n\n注意修改配置文件中的 env 环境变量配置\n\n# 使用\n\n## 邮件通知\n\n```php\nuse Dog\\Noticer\\Channel\\Email;\nuse Dog\\Noticer\\Exception\\NoticeException;\n\n/**\n * @var Email\n */\n$mail = make(Email::class);\n// $mail = $this-\u003econtainer-\u003emake(Email::class); // 效果一样\n\ntry {\n    // 发送纯文本\n    $mail-\u003eto('yourname@foo.bar', '你的名字')\n        -\u003esubject('test')\n        -\u003etext('\u003ch1\u003etitle1\u003c/h1\u003e')\n        -\u003esend();\n} catch (NoticeException $e) {\n    // do something for exception\n}\n\n// 发送html\n$mail-\u003einit()\n    // -\u003eto('yourname@foo.bar', '你的名字')\n    -\u003eto('yourname@foo.bar') // 第二个参数可以省略\n    -\u003esubject('test')\n    -\u003ehtml('\u003ch1\u003etitle1\u003c/h1\u003e')\n    -\u003esend();\n\n// 一行一行文本发送\n$mail-\u003einit()\n    // -\u003eto('yourname@foo.bar', '你的名字')\n    -\u003eto(['yourname@foo.bar' =\u003e '你的名字']) // 可以通过数组格式给多个人发\n    -\u003esubject('test')\n    -\u003eline('\u003ch1\u003etitle1\u003c/h1\u003e')\n    -\u003eline('\u003ch1\u003etitle2\u003c/h1\u003e')\n    -\u003eline('\u003ch1\u003etitle3\u003c/h1\u003e')\n    -\u003esend();\n\n// 发送视图\n$mail-\u003einit()\n    -\u003eto('yourname@foo.bar', '你的名字')\n    -\u003esubject('test')\n    -\u003eview('mail', ['name' =\u003e '参数值'])\n    -\u003esend();\n// 视图配置\n/*\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003ctitle\u003eHyperf\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\nHello, {{ $name }}. You are using blade template now.\n\u003c/body\u003e\n\u003c/html\u003e\n*/\n\n// 指定blade模板引擎发送视图\n$mail-\u003einit()\n    -\u003eto('yourname@foo.bar', '你的名字')\n    -\u003esubject('test')\n    -\u003eblade('mail', ['name' =\u003e '参数值'])\n    -\u003esend();\n\n// 给多个人发送\n// 指定blade模板引擎发送视图\n$mail-\u003einit()\n    -\u003eto([\n        'yourname@foo.bar' =\u003e '你的名字1',\n        'yourname2@foo.bar' =\u003e '你的名字2',\n    ])\n    -\u003esubject('test')\n    -\u003eview('mail', ['name' =\u003e '参数值'])\n    -\u003esend();\n\n// 每次发送之后如果仍使用同一个实例，务必重置，否则可能出现问题\n$mail-\u003einit()\n    -\u003eto('yourname@foo.bar', '你的名字')\n    -\u003esubject('test')\n    -\u003ehtml('\u003ch1\u003e重置完成\u003c/h1\u003e')\n    -\u003esend();\n\n// 更多功能请扒源码\n```\n\n## 短信通知\n\n```php\nuse Dog\\Noticer\\Channel\\Sms;\n\n/**\n * @var Sms\n */\n$sms = make(Sms::class);\n// $sms = $this-\u003econtainer-\u003emake(Sms::class); // 效果一样\n\ntry {\n    $tplId = '111111111';\n    $param = ['name' =\u003e '张三'];\n    $receivers = ['131xxxxxxxx', '132xxxxxxxx'];\n    $sms-\u003esend($tplId, $param, $receivers);\n} catch (NoticeException $e) {\n    // do something for exception\n}\n```\n\n\n## 电话通知\n\n```php\nuse Dog\\Noticer\\Channel\\Phone;\n\n/**\n * @var Phone\n */\n$phone = make(Phone::class);\n// $phone = $this-\u003econtainer-\u003emake(Phone::class); // 效果一样\n\ntry {\n    $content = '您的验证码为：123456';\n    $receiver = '131xxxxxxxx'; // 只能单个发送\n    $phone-\u003esend($content, $receiver);\n} catch (NoticeException $e) {\n    // do something for exception\n}\n```\n\n\n## 钉钉工作通知\n\n```php\nuse Dog\\Noticer\\Channel\\DingWorker;\nuse Dog\\Noticer\\Channel\\DingWorker\\MsgType\\Text;\nuse Dog\\Noticer\\Channel\\DingWorker\\MsgType\\Markdown;\nuse Dog\\Noticer\\Channel\\DingWorker\\MsgType\\ActionCard;\n\n/**\n * @var DingWorker\n */\n$dingworker = make(DingWorker::class);\n// $dingworker = $this-\u003econtainer-\u003emake(DingWorker::class); // 效果一样\n\n// 发送文本\ntry {\n    // 注意：工作通知相同内容只能一天给一个人发一次，每个人最多一天收到50条消息，为了让通知内容不会因为相同被拦截，可以加上当前发送的时间\n    // 其他所有格式都一样，相同会被拦截，建议都加上时间，包括markdown、actionCard\n    // $text = new Text('通知内容' . \"\\n\" . date('Y-m-d H:i:s'));\n    $text = new Text('通知内容');\n    $options = [\n        'emails' =\u003e 'yourname@foo.bar', // 多一个以|分隔，例如 'emails' =\u003e 'yourname@foo.bar|yourname2@foo.bar',\n        // 'workcodes' =\u003e '1', // 多一个以|分隔，必须带前面0，与邮箱填一个即可\n    ];\n    $dingworker-\u003esend($text, $options);\n} catch (NoticeException $e) {\n    // do something for exception\n}\n\n// 发送markdown，仅支持markdown子集，具体请参考：https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq/9e91d73c\n$markdown = new Markdown('标题', \"\n# title1\n# title2\n---\n\n**加粗** 不加粗\n\");\n$options = [\n    'emails' =\u003e 'yourname@foo.bar', // 多一个以|分隔，例如 'emails' =\u003e 'yourname@foo.bar|yourname2@foo.bar',\n    // 'workcodes' =\u003e '1', // 多一个以|分隔，必须带前面0，与邮箱填一个即可\n];\n$dingworker-\u003esend($markdown, $options);\n\n// 发送ActionCard\n$actionCard = new ActionCard('标题', \"\n# markdown文本，主体内容\n# ---\n\");\n// 单个button\n$actionCard-\u003esingle('button标题', 'button跳转url');\n// 或者多个button\n$actionCard-\u003ebtn('button标题1', 'button跳转url1')\n    \u003ebtn('button标题2', 'button跳转url2')\n    \u003ebtn('button标题3', 'button跳转url3');\n// 或者通过数组设置多个button\n$actionCard-\u003ebtns([\n    ['title' =\u003e 'button标题1', 'action_url' =\u003e 'button跳转url1'],\n    ['title' =\u003e 'button标题2', 'action_url' =\u003e 'button跳转url2'],\n]);\n// 默认button为横向排列，如果需要竖向，可设置：\n$actionCard-\u003esetVertical(true);\n$dingworker-\u003esend($actionCard, $options);\n\n// 更多消息类型请扒源码\n```\n\n\n## 钉钉机器人（钉钉群）通知\n\n```php\nuse Dog\\Noticer\\Channel\\DingGroup;\nuse Dog\\Noticer\\Channel\\DingGroup\\MsgType\\Text;\nuse Dog\\Noticer\\Channel\\DingGroup\\MsgType\\Markdown;\nuse Dog\\Noticer\\Channel\\DingGroup\\MsgType\\ActionCard;\n\n/**\n * @var DingGroup\n */\n$dinggroup = make(DingGroup::class);\n// $dinggroup = $this-\u003econtainer-\u003emake(DingGroup::class); // 效果一样\n\n$robots = [\n    ['webhook' =\u003e '钉钉机器人webhook中的access_token的值', 'secret' =\u003e '此参数非必填'],\n    ['webhook' =\u003e '另外一个机器人'],\n];\n$options = [\n\n]\n// 发送文本\ntry {\n    $text = new Text('通知内容');\n    $dinggroup-\u003esend($text, $robots, $options);\n} catch (NoticeException $e) {\n    // do something for exception\n}\n\n// 发送markdown，仅支持markdown子集，具体请参考：https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq/9e91d73c\n$markdown = new Markdown('标题', \"\n# title1\n# title2\n---\n\n**加粗** 不加粗\n\");\n$dinggroup-\u003esend($markdown, $robots, $options);\n\n// 发送ActionCard\n$actionCard = new ActionCard('标题', \"\n# markdown文本，主体内容\n# ---\n\");\n// 单个button\n$actionCard-\u003esingle('button标题', 'button跳转url');\n// 或者多个button\n$actionCard-\u003ebtn('button标题1', 'button跳转url1')\n    \u003ebtn('button标题2', 'button跳转url2')\n    \u003ebtn('button标题3', 'button跳转url3');\n// 或者通过数组设置多个button\n$actionCard-\u003ebtns([\n    ['title' =\u003e 'button标题1', 'action_url' =\u003e 'button跳转url1'],\n    ['title' =\u003e 'button标题2', 'action_url' =\u003e 'button跳转url2'],\n]);\n// 默认button为横向排列，如果需要竖向，可设置：\n$actionCard-\u003esetVertical(true);\n$dinggroup-\u003esend($actionCard, $robots, $options);\n\n// 更多消息类型请扒源码\n```\n\n\n## Yach机器人（Yach群）通知\n\n```php\nuse Dog\\Noticer\\Channel\\YachGroup;\nuse Dog\\Noticer\\Channel\\YachGroup\\MsgType\\Text;\nuse Dog\\Noticer\\Channel\\YachGroup\\MsgType\\Markdown;\nuse Dog\\Noticer\\Channel\\YachGroup\\MsgType\\ActionCard;\n\n/**\n * @var YachGroup\n */\n$yachgroup = make(YachGroup::class);\n// $yachgroup = $this-\u003econtainer-\u003emake(YachGroup::class); // 效果一样\n\n$robots = [\n    ['webhook' =\u003e 'yach机器人webhook中的access_token的值', 'secret' =\u003e '此参数必填'],\n];\n// 发送文本\ntry {\n    $text = new Text('通知内容');\n    $yachgroup-\u003esend($text, $robots);\n} catch (NoticeException $e) {\n    // do something for exception\n}\n\n// 发送markdown，仅支持markdown子集，具体请参考（Yach和钉钉差不多）：https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq/9e91d73c\n$markdown = new Markdown('标题', \"\n# title1\n# title2\n---\n\n**加粗** 不加粗\n\");\n$yachgroup-\u003esend($markdown, $robots);\n\n// 发送markdown，并带图片地址\n$markdown = new Markdown('标题', \"\n# title1\n# title2\n---\n\n**加粗** 不加粗\n\", 'http://bpit-public.oss-cn-beijing.aliyuncs.com/note_1_1572593268.jpg');\n$yachgroup-\u003esend($markdown, $robots);\n\n// 发送ActionCard\n$actionCard = new ActionCard('标题', \"\n# markdown文本，主体内容\n# ---\n\", $image = '', $contentTitle = ''); // 此处可以填下image和contentTitle的参数\n// 单个button\n$actionCard-\u003esingle('button标题', 'button跳转url');\n// 或者多个button\n$actionCard-\u003ebtn('button标题1', 'button跳转url1')\n    \u003ebtn('button标题2', 'button跳转url2')\n    \u003ebtn('button标题3', 'button跳转url3');\n// 或者通过数组设置多个button\n$actionCard-\u003ebtns([\n    ['title' =\u003e 'button标题1', 'action_url' =\u003e 'button跳转url1'],\n    ['title' =\u003e 'button标题2', 'action_url' =\u003e 'button跳转url2'],\n]);\n// 默认button为横向排列，如果需要竖向，可设置：\n$actionCard-\u003esetVertical(true);\n$yachgroup-\u003esend($actionCard, $robots);\n\n// 更多消息类型请扒源码\n```\n\n\n## Yach工作通知\n\n```php\nuse Dog\\Noticer\\Channel\\YachWorker;\nuse Dog\\Noticer\\Channel\\YachWorker\\MsgType\\Text;\nuse Dog\\Noticer\\Channel\\YachWorker\\MsgType\\Markdown;\nuse Dog\\Noticer\\Channel\\YachWorker\\MsgType\\ActionCard;\n\n/**\n * @var YachWorker\n */\n$yachworker = make(YachWorker::class);\n// $yachworker = $this-\u003econtainer-\u003emake(YachWorker::class); // 效果一样\n\n$options = [\n    // 通过邮箱发送（推荐）\n    'user_type' =\u003e 'email',\n    // 多个以|分隔\n    'userid_list' =\u003e 'tianpian@foo.bar|xxxxxxxxxx@foo.bar',\n    // // 通过工号发送\n    // 'user_type' =\u003e 'workcode',\n    // // 多个以|分隔\n    // 'userid_list' =\u003e '1|999999',\n];\n// 发送文本\ntry {\n    $text = new Text('通知内容');\n    $yachworker-\u003esend($text, $options);\n} catch (NoticeException $e) {\n    // do something for exception\n}\n\n// 发送markdown，仅支持markdown子集，具体请参考（Yach和钉钉差不多）：https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq/9e91d73c\n$markdown = new Markdown('标题', \"\n# title1\n# title2\n---\n\n**加粗** 不加粗\n\");\n$yachworker-\u003esend($markdown, $options);\n\n// 发送markdown，并带图片地址\n$markdown = new Markdown('标题', \"\n# title1\n# title2\n---\n\n**加粗** 不加粗\n\", 'http://bpit-public.oss-cn-beijing.aliyuncs.com/note_1_1572593268.jpg');\n$yachworker-\u003esend($markdown, $options);\n\n// 发送ActionCard\n$actionCard = new ActionCard('标题', \"\n# markdown文本，主体内容\n# ---\n\", $image = '', $contentTitle = ''); // 此处可以填下image和contentTitle的参数\n// 单个button\n$actionCard-\u003esingle('button标题', 'button跳转url');\n// 或者多个button\n$actionCard-\u003ebtn('button标题1', 'button跳转url1')\n    \u003ebtn('button标题2', 'button跳转url2')\n    \u003ebtn('button标题3', 'button跳转url3');\n// 或者通过数组设置多个button\n$actionCard-\u003ebtns([\n    ['title' =\u003e 'button标题1', 'action_url' =\u003e 'button跳转url1'],\n    ['title' =\u003e 'button标题2', 'action_url' =\u003e 'button跳转url2'],\n]);\n// 默认button为横向排列，如果需要竖向，可设置：\n$actionCard-\u003esetVertical(true);\n$yachworker-\u003esend($actionCard, $options);\n\n// 更多消息类型请扒源码\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftal-tech%2Falarm-dog-noticer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftal-tech%2Falarm-dog-noticer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftal-tech%2Falarm-dog-noticer/lists"}