-
调用
$webhook = '机器人地址'; //推送地址 $webhookdata = array( 'msgtype' => 'text', //文本类型 'content' => '测试消息', // 文本内容 'mentioned_list' => '', //@某个人 "@all"为全员 'mentioned_mobile_list' => '' //@手机号 "@all"为全员 ); $this->WorkRoboot($webhook,$webhookdata);
-
推送
public function WorkRoboot($webhook,$webhookdata){ $postdata['msgtype'] = $webhookdata['msgtype']; //接收类型 $postdata[$postdata['msgtype']]['content'] = $webhookdata['content']; //接收内容 if (!empty($webhookdata['mentioned_list'])) { $postdata[$postdata['msgtype']]['mentioned_list'] = $webhookdata['mentioned_list']; } if (!empty($webhookdata['mentioned_mobile_list'])) { $postdata[$postdata['msgtype']]['mentioned_mobile_list'] = $webhookdata['mentioned_mobile_list']; } // 初始化 $curl = curl_init(); // 设置url curl_setopt($curl, CURLOPT_URL, $webhook); // 设置头文件的信息作为数据流输出 curl_setopt($curl, CURLOPT_HEADER, true); // 设置获取的信息以文件流的形式返回,而不是直接输出。 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 设置提交方式是utf8编码 curl_setopt($curl, CURLOPT_HTTPHEADER,array('Content-Type: application/json;charset=utf-8')); // 设置post方式提交 curl_setopt($curl, CURLOPT_POST, true); // 设置允许 cURL 函数执行的最长秒数 curl_setopt($curl, CURLOPT_TIMEOUT, 500); // 设置post数据 curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($postdata)); // 关闭就行 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 执行命令 $data = curl_exec($curl); // 关闭URL请求 curl_close($curl); }