如何正确发送JSON CURL到Slack?

I have a CURL code that I use to integrate with GetResponse and I thought ill go ahead and copy/paste it for slack too. For some reason there are no errors at all yet slack is empty of requests (a POST to this URL with Postman works just fine). What am I missing? I couldn't find a solution the whole night.

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

function slackReporting($data)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://hooks.slack.com/services/XXXX/XXXX/XXXXXX');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_exec($ch);
}

$slackReporting_data = array(
    'text' => "`New Lead` `+34 today`.",
    'username' => "Leads",
    'mrkdwn' => true
);

$slackReporting_res = json_decode(slackReporting($slackReporting_data));

$slackReporting_error = "";
if(empty($slackReporting_res->error)){
    echo "OK";
} else {
    $slackReporting_error = $slackReporting_res->error->message;
}
echo $slackReporting_error;
?>

I always get an OK.

查看全部
dongnao2048
dongnao2048
2017/05/30 08:37
  • curl
  • json
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复