本文主要講述的是如何通過簽名方式實現(xiàn)釘釘機器人報警的功能:
1、關于簽名的生成:
/** * 簽名實現(xiàn) */ 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 .= "timestamp=$timestampsign=$signStr";
2:使用guzzle請求接口,發(fā)送釘釘消息
/** * 發(fā)送釘釘報警 */ $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);
到此這篇關于php封裝實現(xiàn)釘釘機器人報警接口的示例代碼的文章就介紹到這了,更多相關php 釘釘機器人報警接口內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!