如何为miscrosoft团队创建webhook

时间:2018-04-20 13:08:55

标签: php curl post microsoft-teams

我尝试向团队频道发送一条简单的消息,这就是我所做的:

$link = 'My-Link-Goes-Here';
$curl = curl_init($link);

$postfields = array(
    'text' => 'HELLO',
);
$postfields = json_encode($postfields);

curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($curl);
var_dump($result);
curl_close($curl);

我做错了什么?

1 个答案:

答案 0 :(得分:2)

我回答自己,如果它可以帮助任何人:

function Webhook($Name){
    $url = 'My Url Goes Here';

    $ch = curl_init();

    $jsonData = array(
        'text' => 'Hello '.$Name.' !!'
    );
    $jsonDataEncoded = json_encode($jsonData, true);


    $header = array();
    $header[] = 'Content-type: application/json';


    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

    $result = curl_exec($ch);
    curl_close($ch);

    var_dump($result);
}