共计 714 个字符,预计需要花费 2 分钟才能阅读完成。
本文次要讲述的是如何通过签名形式实现钉钉机器人报警的性能:
1、对于签名的生成:
/**
* 签名实现
*/
list($s1, $s2) = explode(' ', microtime());
$timestamp = (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
$secret = '****';
$data = $timestamp . "\n" . $secret;
$signStr = base64_encode(hash_hmac('sha256', $data, $secret,true));
$signStr = utf8_encode(urlencode($signStr));
$webhook = 'https://oapi.dingtalk.com/robot/send?access_token=****';
$webhook .= "×tamp=$timestamp&sign=$signStr";
2:应用 guzzle 申请接口,发送钉钉音讯
/**
* 发送钉钉报警
*/
$guzzleClent = new \GuzzleHttp\Client();
$data = [
'msgtype' => 'text',
'text' => ['content' => $msg,]
];
$res = $guzzleClent->request('POST', $webhook,[
'headers' => ['content-type' => 'application/json'],
'body' => json_encode($data),
]);
$res = json_decode($res->getBody());
var_dump($res);
正文完