本文主要介绍如何通过签名方式实现钉钉机器人报警功能:1.关于签名生成:/***签名实现*/list($s1,$s2)=explode('',microtime());$timestamp=(float)sprintf('%.0f',(floatval($s1)+floatval($s2))*1000);$秘密='****';$数据=$时间戳。"\n"。$秘密;$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());变量转储($res);
