今天是 :

钉钉消息推送

 public function senddingtalk($talkMsg, $type = 0)
    {
        $secret = '1IGg8Ik4XlhwY_G0wGRDZigx7h2oSAF8zv8puW9t4Fa_Tm9xX_oNM4QduVRyZQ-P';
        $webhook = "https://oapi.dingtalk.com/robot/send?access_token=ad74604e3dcfbbdd614fd7d42e601ec93a1b733fce66ae509bc7b754465e94f3";
        //研发群关键字
        $keywords = "[发现问题] ";
        $url = $webhook;
        // 第一步,把timestamp+"\n"+密钥当做签名字符串,使用HmacSHA256算法计算签名,然后进行Base64 encode,最后再把签名参数再进行urlEncode,得到最终的签名(需要使用UTF-8字符集)。
        $time = time() * 1000;//毫秒级时间戳,我这里为了方便,直接把时间*1000了
        $sign = hash_hmac('sha256', $time . "\n" . $secret, $secret, true);
        $sign = base64_encode($sign);
        $sign = urlencode($sign);
        $waring = print_r(json_decode(json_encode($talkMsg)), true);
        $msg = [
            'msgtype' => 'text',//这是文件发送类型,可以根据需求调整
            'text' => [
                'content' => $keywords . date("Y-m-d H:i:s") . "  -> " . $waring,
            ],
        ];
        $url = "{$url}&timestamp={$time}&sign={$sign}";
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($msg));
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }

公告:

  本站采用 gin作为后台服务
前端使用 sematicui 框架搭建(拼凑)。
有喜欢本站的同学。欢迎到聊天室留言

评论: