0

有人可以帮助我通过 HTTP 为 PHP 发送 SMS 吗?我正在使用 OneWaySMS 菲律宾,它似乎不起作用。

这是他们提供的 API 代码示例:

function gw_send_sms($user, $pass, $sms_from, $sms_to, $sms_msg)
{
    $query_string = "api.aspx?apiusername=" . $user . "&apipassword=" . $pass;
    $query_string .= "&senderid=" . rawurlencode($sms_from) . "&mobileno=" . rawurlencode($sms_to);
    $query_string .= "&message=" . rawurlencode(stripslashes($sms_msg)) . "&languagetype=1";
    $url = "http://gateway.onewaysms.com.au:10001/" . $query_string;
    $fd = @implode('', file($url));

    if ($fd) {
        if ($fd > 0) {
            Print("MT ID : " . $fd);
            $ok = "success";
        } else {
            print("Please refer to API on Error : " . $fd);
            $ok = "fail";
        }
    } else {
        // no contact with gateway
        $ok = "fail";
    }

    return $ok;
}

Print("Sending to one way sms " . gw_send_sms("apiusername", "apipassword", "senderid", "61412345678", "test message"));

这是我的代码(由于简单的代码不起作用,我对其进行了很大的更改):

function gw_send_sms($user, $pass, $sms_from, $sms_to, $sms_msg)
{
    $query_string = "api.aspx?apiusername=" . $user . "&apipassword=" . $pass;
    $query_string .= "&senderid=" . rawurlencode($sms_from) . "&mobileno=" . rawurlencode($sms_to);
    $query_string .= "&message=" . rawurlencode(stripslashes($sms_msg)) . "&languagetype=1";
    $url = "http://gateway.onewaysms.com.ph:10001/" . $query_string;
    $arr = array($url);
    $fd = implode(',', $arr);

    if ($fd) {
        if ($fd > 0) {
            Print("MT ID : " . $fd);
            $ok = "success";
        } else {
            print("Please refer to API on Error : " . $fd);
            $ok = "fail";
        }
    } else {
        // no contact with gateway                      
        $ok = "fail";
    }

    return $ok;
}

Print("Sending to one way sms " . gw_send_sms("sampleusername", "samplepassword", "Sender", "SampleNumber", "Testing SMS"));

请参阅有关错误的 API: http ://gateway.onewaysms.com.ph:10001/api.aspx?apiusername=sample&apipassword=sample&senderid=sample&mobileno=sample&message=Testing%20omg&languagetype= 1 发送到单向短信失败

我也尝试直接访问 URL,但没有成功。

4

1 回答 1

0

您使用了错误的域,它应该是 gateway.onewaysms.ph 而不是 gateway.onewaysms.com.ph。

于 2013-10-12T15:57:56.243 回答