php封装实现钉钉机器人报警接口的示例代码
本文主要讲述的是如何通过签名方式实现钉钉机器人报警的功能:
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);
相关推荐
quyunfei 2020-11-19
机器人智力研究 2020-11-18
聊天终结者机器人 2020-11-18
txq0 2020-11-20
zCSDN 2020-11-09
机器人智力研究 2020-11-05
ARMOTO机器人 2020-11-06
txq0 2020-11-06
遇见人工智能 2020-11-03
聊天终结者机器人 2020-11-02
clliuhust 2020-10-30
yatou0 2020-10-29
雨燕 2020-10-29
nodid 2020-10-29
yatou0 2020-10-29
zCSDN 2020-10-27
dhyddy 2020-10-27
聊天终结者机器人 2020-10-26