{"id":33970230,"url":"https://github.com/huozi1024/work-wechat-robot","last_synced_at":"2026-04-04T12:58:57.864Z","repository":{"id":43002306,"uuid":"318447324","full_name":"huozi1024/work-wechat-robot","owner":"huozi1024","description":"企业微信机器人sdk 支持作为monolog的通道来发送日志","archived":false,"fork":false,"pushed_at":"2022-08-22T09:02:42.000Z","size":54,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-02T21:18:14.675Z","etag":null,"topics":["monolog","monolog-handler","robot","wechat-robot","wxwork"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/huozi1024.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-04T08:09:05.000Z","updated_at":"2022-09-05T08:03:51.000Z","dependencies_parsed_at":"2022-08-21T09:40:24.040Z","dependency_job_id":null,"html_url":"https://github.com/huozi1024/work-wechat-robot","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/huozi1024/work-wechat-robot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huozi1024%2Fwork-wechat-robot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huozi1024%2Fwork-wechat-robot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huozi1024%2Fwork-wechat-robot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huozi1024%2Fwork-wechat-robot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huozi1024","download_url":"https://codeload.github.com/huozi1024/work-wechat-robot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huozi1024%2Fwork-wechat-robot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31400460,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T10:20:44.708Z","status":"ssl_error","status_checked_at":"2026-04-04T10:20:06.846Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["monolog","monolog-handler","robot","wechat-robot","wxwork"],"created_at":"2025-12-13T00:16:34.953Z","updated_at":"2026-04-04T12:58:57.859Z","avatar_url":"https://github.com/huozi1024.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# work-wechat-robot\n\n企业微信机器人sdk\n\n### 0.安装\n```\ncomposer require huo-zi/work-wechat-robot\n```\nphp \u003c 8 || laravel \u003c 9\n```\ncomposer require huo-zi/work-wechat-robot:~2.0\n```\n\n### 1.使用\n#### 1.1 直接使用\n\n```php\n$robot = new WorkWechatRobot($robotKey);\n$robot-\u003etext($content); // 文本消息\n$robot-\u003emarkdown($content); // markdown消息\n$robot-\u003eimage($filename); // 图片消息 支持本地图片和网络图片\n$robot-\u003enews($title, $url, $desc, $picurl); // 图文消息\n$robot-\u003efile($filename); // 发送上传文件\n```\n\n#### 1.2 v2.1.0之后支持创建消息对象发送消息：\n```php\n$messsage = new Text();     // new Markdwon(); new Image()...\n$messsage-\u003econtent('文本消息');\n$messsage-\u003esend($robotKey); // 或使用 $robot-\u003emessage($messsage);\n```\n\n### 2.作为Monolog的通道使用\n#### 2.1 配置通道\n* laravel框架\n在配置文件`logging.php`的`channels`数组中增加：\n\n```php\n'wxwork_robot' =\u003e [  \n    'driver' =\u003e 'monolog',  \n    'level' =\u003e 'notice',  \n    'handler' =\u003e \\Huozi\\WorkWechat\\Monolog\\Handler\\RobotHandler::class,  \n    'handler_with' =\u003e [  \n        'robotKey' =\u003e 'your_wxwork_robot_key',  \n    ],  \n],\n```\n \n然后修改`channels`节点`stack`，在`channels`中增加`wxwork_robot`\n\n```php\n'stack' =\u003e [\n    'driver' =\u003e 'stack',\n    'channels' =\u003e ['single', ... , 'wxwork_robot'],\n    'ignore_exceptions' =\u003e false,\n],\n```\n\n详见[laravel高度自定义Monolog通道](https://learnku.com/docs/laravel/8.x/logging/9376#advanced-monolog-channel-customization)\n* 其他框架\n\n```php\n$logger = new \\Monolog\\Logger($name);\n$logger-\u003epushHandler(new RobotHandler($robotKey));\n```\n\n#### 2.2 日志格式化\n提供了`TextFormatter`和`MarkdownFormatter`格式化原始日志，使日志内容方便阅读\n* laravel框架,修改`logging.php`, 增加`formatter`：\n\n```php\n'wxwork_robot' =\u003e [\n    'driver' =\u003e 'monolog',\n    'level' =\u003e 'notice',\n    'handler' =\u003e \\Huozi\\WorkWechat\\Monolog\\Handler\\RobotHandler::class,\n    'handler_with' =\u003e [\n        'robotKey' =\u003e 'your_wxwork_robot_key',\n    ],\n    'formatter' =\u003e \\Huozi\\WorkWechat\\Monolog\\Formatter\\MarkdownFormatter::class,```\n ],\n ```\n\n`TextFormatter`和`MarkdownFormatter`都提供了默认的格式化结构，如果需要自定义可以：\n\n```php\n    'formatter' =\u003e \\Huozi\\WorkWechat\\Monolog\\Formatter\\TextFormatter::class,\n    'formatter_with' =\u003e [\n        'messageFormat' =\u003e '{level_name}:{message} \\n {extra.file}:{extra.line}'\u003c/b\u003e\n    ]\n```\n\n* 其他框架\n\n```php\n$messageFormat = '{level_name}:{message} \\n {extra.file}:{extra.line}';\n$formatter = new TextFormatter($messageFormat);\n$logger-\u003epushHandler((new RobotHandler($robotKey))-\u003esetFormatter($formatter));\n```\n\nLicense\n------------\nLicensed under [The MIT License (MIT)](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuozi1024%2Fwork-wechat-robot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuozi1024%2Fwork-wechat-robot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuozi1024%2Fwork-wechat-robot/lists"}