企业微信--配置机器人

此篇可参考企业微信官方文档--如何配置机器人

<?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);

    }


}
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值