企业微信--配置机器人

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

 '星期日',
            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 >用户总数量为{$total},比前一日增加{$totalD} \n >其中:\n >**车视杰**设备用户数为{$ceC},比前一日增加{$ceD} \n >**迈卡盾**设备用户数为$maiC,比前一日增加{$maid} \n >**安至尊**设备用户数为{$anC},比前一日增加{$anD} \n >**其他**设备用户数为{$otherC},比前一日增加{$otherD} \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);

    }


}

你可能感兴趣的:(php)