无法通过yii app

时间:2015-11-13 00:01:28

标签: php curl yii webhooks slack

我希望从我的yii应用程序发布一个简单的Slack传入WebHook,但我似乎无法将任何内容传递给Slack。我相信我已经在我的php.ini中启用了curl,我一直在使用yii扩展中的curl包装器(https://github.com/hackerone/curl

这是我的代码;

$ url = Options :: getSlackWebhookUrl();

        $json_data = json_encode(array(
            "text"=>"I'm a notification from yiiapp to Slack channel <" . Options::getSlackChannel() . ">", 
            "username"=> "yiiapptest",
            "channel"=> Options::getSlackChannel()
        ));
        $post_data['json_data'] = $json_data;

        $output = Yii::app()->curl->post($url, $post_data);

        // Just for debug: to see response
        echo "<pre>" . $url . " + " . $output . " (" . $json_data . ")</pre>";

这是我要查看的输出;

https://hooks.slack.com/services/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 + No payload received ({"text":"I'm a notification from yiiapp to Slack channel <#digital>","username":"yiiapptest","channel":"#digital"})

我的$ output只给了我一个“没有收到有效载荷”。如果我在我的网址上使用urlenode(),我会收到'错误500 - 未定义索引:方案'

谁能看到我出错的地方?

1 个答案:

答案 0 :(得分:1)

你需要改变

    $post_data['json_data'] = $json_data;

    $post_data['payload'] = $json_data;

它正在等待名为'payload'的post变量