您的位置:首頁技術文章
文章詳情頁

php封裝實現釘釘機器人報警接口的示例代碼

瀏覽:96日期:2022-06-01 18:25:15

本文主要講述的是如何通過簽名方式實現釘釘機器人報警的功能:

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 .= '&timestamp=$timestamp&sign=$signStr';

2:使用guzzle請求接口,發送釘釘消息

/** * 發送釘釘報警 */ $guzzleClent = new GuzzleHttpClient(); $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封裝實現釘釘機器人報警接口的示例代碼的文章就介紹到這了,更多相關php 釘釘機器人報警接口內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: 釘釘
相關文章:
国产综合久久一区二区三区