PHP code example of demokn / yii2-wework-bot
1. Go to this page and download the library: Download demokn/yii2-wework-bot 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/ */
demokn / yii2-wework-bot example snippets
'components' => [
// ...
// 注册组件
'weworkBot' => [
'class' => \demokn\weworkbot\Bot::class,
'webhook' => 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=YOUR_SECRET_KEY',
'testMode' => !YII_ENV_PROD,
],
// 注册多个实例
'anotherWeworkBot' => [
'class' => \demokn\weworkbot\Bot::class,
'webhook' => 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=YOUR_SECRET_KEY',
'testMode' => !YII_ENV_PROD,
],
// 配置日志Target, 使用企业微信群机器人上报日志
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => \yii\log\FileTarget::class,
'levels' => ['error', 'warning'],
],
[
'class' => \demokn\weworkbot\LogTarget::class,
'levels' => ['error', 'warning'],
'logVars' => [],
'bot' => 'weworkBot',
],
],
],
// ...
],
$bot = Yii::$app->weworkBot;
// 发送文本消息
$bot->send('这是一条文本消息');
// 发送复杂文本消息
$bot->send([
'msgtype' => 'text',
'text' => [
'content' => '广州今日天气:29度,大部分多云,降雨概率:60%',
'mentioned_list' => ['wangqing', '@all'],
'mentioned_mobile_list' => ['13800001111', '@all'],
],
]);
// 发送markdown消息
$bot->send([
'msgtype' => 'markdown',
'markdown' => [
'content' => "实时新增用户反馈<font color=\"warning\">132例</font>,请相关同事注意。\n
>类型:<font color=\"comment\">用户反馈</font>\n
>普通用户反馈:<font color=\"comment\">117例</font>\n
>VIP用户反馈:<font color=\"comment\">15例</font>",
],
]);
// ...