似乎是抄钉钉的。sign的生成方法删减了一点
飞书@的是user_id并不是手机号或者邮箱,user_id的获取方法可参考我的这个文章获取飞书的user_id_卖烤冷面的郭师傅的博客-CSDN博客飞书的user_id隐藏的极深。。。找了半天找不到,最后是询问客服后才知道的。1、点击头像——设置——关于飞书:连续点击飞书版本号五次2、点击头像——右键头像——点击copy_user_id即可获得自己的user_id...https://blog.csdn.net/qq_37172634/article/details/123996775
<?php
define('WEBHOOK_URL', "https://open.feishu.cn/open-apis/bot/v2/hook/");
class Feishu
{
private $config;
public function __construct($access_token = '', $secret = '')
{
if (!empty($access_token) && !empty($secret)) {
$this->config = array(
"token" => $access_token,
"secret" => $secret
);
} else {
$this->config = array(
"token" => "a259e46c-2c1b-45a2-985e-36f094356451",
"secret" => "FpB4tOaspHDpf4AnfZdljd"
);
}
}
public function send($msgtype = 'text', $msg = array(), $isAtAll = false, $atUids = array())
{
if (empty($msg)) {
return "msgtype can't be empty.";
}
if ($msgtype == 'text') {
$at = '';
if (!empty($atUids)) {
foreach ($atUids as $v) {
$at .= ('<at user_id="' . $v . '">test</at>');
}
}
//如果是atall就都重置掉
if ($isAtAll) {
$at = ('<at user_id="all">所有人</at>');
}
if(!empty($at)){
$msg = ($at . " " . $msg);
}
}
$post = array(
"msg_type" => $msgtype,
"content" => array(
$msgtype => $msg
)
);
$post['timestamp'] = time();
$str = $post['timestamp'] . "\n" . $this->config['secret'];
$post['sign'] = base64_encode(hash_hmac('sha256', '', $str, true));
$post_string = json_encode($post);
return $this->requestByCurl($post_string);
}
private function requestByCurl($post_string)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, WEBHOOK_URL . $this->config['token']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json;charset=utf-8'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$data = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) >= 400) {
return curl_getinfo($ch);
}
curl_close($ch);
return $data;
}
public function sendText($msg, $atAll = false, $atUids = array())
{
return $this->send("text", $msg, $atAll, $atUids);
}
}
和钉钉的机器人对比不能说一模一样,只能说完全一致😆😆
|