此篇可参考企业微信官方文档--如何配置机器人
<?php
/**
* Created by PhpStorm.
* Date: 4/28/2018
* Time: 16:17
*/
namespace App\Console\Commands\Temp;
use App\Console\Command;
use App\Models\Device\Tachograph;
use Carbon\Carbon;
class robot extends Command
{
CONST COMMANDER = "command:temp:robot";
const TAG = "-robot:robot-";
/**
* The console command description
* @var string
*/
protected $description = '企业微信-机器人推送行车记录仪信息相关';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$nowTime = date('Y年m月d日'); //获取当前年月日
$weekMap = [
0 => '星期日',
1 => '星期一',
2 => '星期二',
3 => '星期三',
4 => '星期四',
5 => '星期五',
6 => '星期六',
];
$dayOfTheWeek = Carbon::now()->dayOfWeek;
$weekday = $weekMap[$dayOfTheWeek]; //获取当前星期
$total = Tachograph::count();
$yT = Tachograph::where('created_at', "<=", Carbon::now()->subDays(2)->format('Y-m-d 23:59:59'))->count(); //计算前一日的数据 Carbon::now()->subDays(2)
$totalD = $total - $yT;
$maiC = Tachograph::where('types', '2')->count();//迈卡盾
$mai = Tachograph::where('created_at', "<=", Carbon::now()->subDays(2)->format('Y-m-d 23:59:59'))->where('types', '2')->count();//迈卡盾
$maid = $maiC - $mai;
$ceC = Tachograph::where('types', '1')->count();//车世杰
$ce = Tachograph::where('created_at', "<=", Carbon::now()->subDays(2)->format('Y-m-d 23:59:59'))->where('types', '1')->count();//车世杰
$ceD = $ceC - $ce;
$otherC = Tachograph::where('types', '0')->count();//其他
$other = Tachograph::where('created_at', "<=", Carbon::now()->subDays(2)->format('Y-m-d 23:59:59'))->where('types', '0')->count();//其他
$otherD = $otherC - $other;
$anC = Tachograph::where('types', '3')->count();//安至尊
$ann = Tachograph::where('created_at', "<=", Carbon::now()->subDays(2)->format('Y-m-d 23:59:59'))->where('types', '3')->count();//安至尊
$anD = $anC - $ann;
$data = [
'msgtype' => 'markdown',
'markdown' => [
'content' => "截止到{$nowTime}({$weekday})\n >xxApp绑定**行车记录仪**:\n >用户总数量为<font color='warning'>{$total}</font>,比前一日增加<font color='info'>{$totalD}</font> \n >其中:\n >**车视杰**设备用户数为<font color='warning'>{$ceC}</font>,比前一日增加<font color='info'>{$ceD}</font> \n >**迈卡盾**设备用户数为<font color='warning'>$maiC</font>,比前一日增加<font color='info'>{$maid}</font> \n >**安至尊**设备用户数为<font color='warning'>{$anC}</font>,比前一日增加<font color='info'>{$anD}</font> \n >**其他**设备用户数为<font color='warning'>{$otherC}</font>,比前一日增加<font color='info'>{$otherD}</font> \n [点击查看详情]()\n >",
],
];
$data = json_encode($data);
//1.初始化curl
$curl = curl_init();
//2.设置curl的参数
curl_setopt($curl, CURLOPT_URL, '此为url地址(注意要将url替换成你的机器人webhook地址,content必须是utf8编码)');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //禁止 cURL 验证对等证书
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); //是否检测服务器的域名与证书上的是否一致
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'X-Requested-With: XMLHttpRequest',
'Content-Length:' . strlen($data)
));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
//3.采集
$output = curl_exec($curl);
//4.关闭
curl_close($curl);
return json_decode($output, true);
}
}
企业微信--配置机器人
于 2020-08-31 11:58:36 首次发布