快活林资源网 Design By www.csstdc.com

本文主要讲述的是如何通过签名方式实现钉钉机器人报警的功能:

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"&timestamp=$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);
快活林资源网 Design By www.csstdc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
快活林资源网 Design By www.csstdc.com