- /**
- * 发送钉钉报警消息
- */
- public function ddMsg($content, $atMobiles = [], $isAtAll = false, $webhook = '')
- {
- $atMobiles = is_array($atMobiles) ? $atMobiles : [$atMobiles];
- (!is_string($content) || !is_numeric($content)) && $content = var_export($content, TRUE);
- $data = [
- 'msgtype' => 'text',
- 'text' => ['content' => $content],
- 'at' => [
- 'atMobiles' => $atMobiles,
- 'isAtAll' => $isAtAll,
- ],
- ];
- $data_string = json_encode($data);
- $ch = curl_init();
- $dd_access_token = config('myapp.dd_access_token');
- $webhook = !empty($webhook) ? $webhook:"https://oapi.dingtalk.com/robot/send?access_token={$dd_access_token}";
- curl_setopt($ch, CURLOPT_URL, $webhook);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json;charset=utf-8'));
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- $data = curl_exec($ch);
- curl_close($ch);
- $data = json_decode($data, true);
- if (isset($data['errmsg']) && $data['errmsg'] == 'ok' && isset($data['errcode']) && $data['errcode'] == 0) {
- return $data;
- }
- return $data;
- }