飞书中飞书捷径的webhook示例

这个是我应用在项目中的一些代码,用来在飞书捷径中发送和接收请求的例子。

发起请求,向飞书发送带参数的POST请求:

<?php
$url = '飞书捷径链接';
$data = array(
'data' => array(
"name" => "kkk",
"time" => time(),
)
);
function json_post($url, $data = NULL){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
if(!$data){
return 'data is null';
}
if(is_array($data))
{
$data = json_encode($data,320);
}
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER,array(
'Content-Type: application/json; charset=utf-8',
'Content-Length:' . strlen($data),
'Cache-Control: no-cache',
'Pragma: no-cache'
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($curl);
$errorno = curl_errno($curl);
if ($errorno) {
return $errorno;
}
curl_close($curl);
return $res;
}
$result = json_post($url,$data);
var_dump($result);
?>
<?php
$url = '飞书捷径链接';
$data = array(
    'data' => array(
        "name" => "kkk",
        "time" => time(),
        )
);


function json_post($url, $data = NULL){
    $curl = curl_init();

    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    if(!$data){
        return 'data is null';
    }
    if(is_array($data))
    {
        $data = json_encode($data,320);
    }
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_HTTPHEADER,array(
            'Content-Type: application/json; charset=utf-8',
            'Content-Length:' . strlen($data),
            'Cache-Control: no-cache',
            'Pragma: no-cache'
    ));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $res = curl_exec($curl);
    $errorno = curl_errno($curl);
    if ($errorno) {
        return $errorno;
    }
    curl_close($curl);
    return $res;

}

$result = json_post($url,$data);
var_dump($result);
?>
<?php $url = '飞书捷径链接'; $data = array( 'data' => array( "name" => "kkk", "time" => time(), ) ); function json_post($url, $data = NULL){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); if(!$data){ return 'data is null'; } if(is_array($data)) { $data = json_encode($data,320); } curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_HTTPHEADER,array( 'Content-Type: application/json; charset=utf-8', 'Content-Length:' . strlen($data), 'Cache-Control: no-cache', 'Pragma: no-cache' )); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($curl); $errorno = curl_errno($curl); if ($errorno) { return $errorno; } curl_close($curl); return $res; } $result = json_post($url,$data); var_dump($result); ?>

接收请求,接收来自飞书捷径的请求:

<?php
$data = file_get_contents("php://input");
?>
<?php
$data = file_get_contents("php://input");
?>
<?php $data = file_get_contents("php://input"); ?>
© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享
Nothing in the world is difficult if you put your heart into it.
世上无难事,只怕有心人
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片快捷回复

    暂无评论内容