当前位置:网站首页>laravel throws the error to Dingding

laravel throws the error to Dingding

2022-08-10 13:53:00 nerd peak

Reference API: Message Types Supported by Internal Robots - Dingding Open Platform

Project error thrown: app/Exceptions/Handler.php

1. Preparations

Dingding creates a group, and then intelligent group assistant

2. Add a custom robot

3. Set security settings and record Webhook

4. Code: [package as needed]

public function report(Exception $exception){if ($this->shouldReport($exception)) {$msg = $exception->getMessage();$url = 'webhook';// The first step is to use the timestamp+"\n"+ key as the signature string, use the HmacSHA256 algorithm to calculate the signature, then perform Base64 encode, and finally urlEncode the signature parameters to get the final signature (UTF-8 required)character set).$time = time() * 1000;//Millisecond timestamp, for convenience, I directly set the time * 1000$secret = 'Secret key';$sign = hash_hmac('sha256', $time . "\n" . $secret, $secret, true);$sign = base64_encode($sign);$sign = urlencode($sign);$msg = ['msgtype' => 'text',//This is the file sending type, which can be adjusted according to needs'text' => [ // Send the information received by the DingTalk group'content' => ['url' => Request::url(),'params' => Request::getRequestUri(),'msg' => $msg],],];$url = "{$url}×tamp={$time}&sign={$sign}";$curl = curl_init();curl_setopt($curl, CURLOPT_URL, $url);curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);curl_setopt($curl, CURLOPT_POST, 1);curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($msg));curl_setopt($curl, CURLOPT_HEADER, 0);curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);$res = curl_exec($curl);curl_close($curl);// Log::info('Exception Happen', [// 'url' => Request::url(),// 'params' => Request::getRequestUri(),// ]);}parent::report($exception);}

原网站

版权声明
本文为[nerd peak]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/222/202208101327026540.html