【问题标题】:using kannel post-url but empty php $_POST使用 kannel post-url 但空 php $_POST
【发布时间】:2015-08-17 16:22:54
【问题描述】:

我正在使用 kannel 1.4.3 并使用如下所示的短信服务

group = sms-service
keyword = default
# keyword-regex = .*
catch-all = yes
max-messages = 0
post-url = "http://127.0.0.1/sms.php?phone=%p&text=%a&first_keyword=%k&second_keyword=%s&words=%r&binary_message=%b&time=%t&unix_time=%T&sms_id=%I&dr=%d&dr_url=%R&meta_data=%D&dr_smsc_reply=%A&message_coding=%c&message_class=%m&message_waiting_indicator=%m&message_charset=%C&udh=%u&xser0cfield=%B&account_identifier=%o&data_coding_schema=%O&smsc_originating_message=%f"

这里是 sms.php 脚本

<?php
    require_once dirname(__FILE__)."/send.php";
    echo "Ting..\n";
    $phone = isset($_POST['phone']) ? ($_POST['phone']."\n"):"??";
    $text = isset($_POST['text']) ? ($_POST['text']."\n"):"??";

    $username = "tester";
    $password = "foobar";
    $to = $_POST['phone'];
    //$text = "Nomor anda adalah : $to";
    //$url = "http://127.0.0.1:13013/cgi-bin/sendsms?username=".$username."&password=".$password."&to=".$to."&text=".urlencode($text);
    //
    //$result = getCURL($url);

    $fh = fopen(dirname(__FILE__)."/debug.txt","a");

    fwrite($fh,
        print_r(array(
            'method'=>$_SERVER['REQUEST_METHOD'],
            'data'=>print_r($_REQUEST,true),
            'header'=>print_r(getallheaders(), 1)
        ),true)
    );
    fclose($fh);
?>

问题是当我发送消息时,所有参数都接收为 $_GET,而不是 $_POST,甚至 request_method 的值都是 POST

如何使用 $_POST 检索电话、文本、关键字等所有参数?不是 $_GET?

输出示例:

Array
(
    [method] => POST
    [data] => Array
(
    [phone] => +6281210*****628
    [text] => babi pake manjat pohon
    [first_keyword] => babi
    [second_keyword] => pake
    [words] => manjat pohon
    [binary_message] => babi pake manjat pohon
    [time] => 2012-10-09 10:05:49
    [unix_time] => 1349777149
    [sms_id] => 2f3e12ed-5031-4d5f-b1f2-55e3c41063a4
    [dr] => -1
    [dr_url] => %R
    [meta_data] => %D
    [dr_smsc_reply] => babi pake manjat pohon
    [message_coding] => 0
    [message_class] => -1
    [message_waiting_indicator] => -1
    [message_charset] => UTF-8
    [udh] => 
    [xser0cfield] => 
    [account_identifier] => 
    [data_coding_schema] => 00
    [smsc_originating_message] => +628*****0000
)

    [header] => Array
(
    [Host] => 127.0.0.1
    [Connection] => keep-alive
    [User-Agent] => Kannel/1.4.3
    [Content-Type] => text/plain
    [X-Kannel-To] => 13013
    [X-Kannel-Time] => 2012-10-09 10:05:49
    [Date] => 2012-10-09 03:05:56
    [X-Kannel-SMSC] => at-modem
    [X-Kannel-PID] => 0
    [X-Kannel-Alt-DCS] => 0
    [X-Kannel-Coding] => 0
    [X-Kannel-Compress] => 0
    [X-Kannel-Service] => default
    [Content-Length] => 22
)

)

【问题讨论】:

    标签: php kannel


    【解决方案1】:

    在您的示例中,您在查询字符串中设置参数而不是发布数据,这就是您在 $_GET 中看到它们的原因。

    $_POST 为空,因为 Kannel 在 X-Kannel-* HTTP 标头中提交数据,而不是在 post 字段中。

    请参阅 gw/smsbox.c 第 1306-1431 行 (v1.4.4)...它们仅在 userguide.xml 的用户指南中,因此阅读源代码将显示使用了哪些标题名称。

    您无法选择与 post-url 一起使用的名称,也无法选择哪些参数 - 它们都在每次请求时发送。

    【讨论】:

      【解决方案2】:

      遇到了同样的问题...我只使用了 PHP $_REQUEST 来代替...所以不管是 $_GET 还是 $_POST 都可以处理信息。

      如果你想要一个 POST 请求,你可以试试post-xml 选项

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-12-11
        • 1970-01-01
        • 1970-01-01
        • 2016-10-07
        • 2013-04-27
        • 1970-01-01
        • 1970-01-01
        • 2012-11-11
        相关资源
        最近更新 更多