PHP code example of huo-zi / work-wechat-robot
1. Go to this page and download the library: Download huo-zi/work-wechat-robot 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/ */
huo-zi / work-wechat-robot example snippets
$robot = new WorkWechatRobot($robotKey);
$robot->text($content); // 文本消息
$robot->markdown($content); // markdown消息
$robot->image($filename); // 图片消息 支持本地图片和网络图片
$robot->news($title, $url, $desc, $picurl); // 图文消息
$robot->file($filename); // 发送上传文件
$messsage = new Text(); // new Markdwon(); new Image()...
$messsage->content('文本消息');
$messsage->send($robotKey); // 或使用 $robot->message($messsage);
'wxwork_robot' => [
'driver' => 'monolog',
'level' => 'notice',
'handler' => \Huozi\WorkWechat\Monolog\Handler\RobotHandler::class,
'handler_with' => [
'robotKey' => 'your_wxwork_robot_key',
],
],
'stack' => [
'driver' => 'stack',
'channels' => ['single', ... , 'wxwork_robot'],
'ignore_exceptions' => false,
],
$logger = new \Monolog\Logger($name);
$logger->pushHandler(new RobotHandler($robotKey));
'wxwork_robot' => [
'driver' => 'monolog',
'level' => 'notice',
'handler' => \Huozi\WorkWechat\Monolog\Handler\RobotHandler::class,
'handler_with' => [
'robotKey' => 'your_wxwork_robot_key',
],
'formatter' => \Huozi\WorkWechat\Monolog\Formatter\MarkdownFormatter::class,
'formatter' => \Huozi\WorkWechat\Monolog\Formatter\TextFormatter::class,
'formatter_with' => [
'messageFormat' => '{level_name}:{message} \n {extra.file}:{extra.line}'</b>
]
$messageFormat = '{level_name}:{message} \n {extra.file}:{extra.line}';
$formatter = new TextFormatter($messageFormat);
$logger->pushHandler((new RobotHandler($robotKey))->setFormatter($formatter));