SMSGATEWAY.ME - 如何使用PHP API?

时间:2016-03-21 17:24:45

标签: php android api sms gateway

我想使用SMS Gateway PHP API,但我没有成功使用它。我在手机上下载了来自SMSGATEWAY.ME的android软件,我创建了一个帐户。我还有一个免费的网络服务器,我上传了两个文件:

他们的PHP API库“smsGateway.php”,人们可以在这里找到: https://smsgateway.me/sms-api-libraries/sms-gateway-me-php.zip

我的文件“test.php”:

<?php
include "smsGateway.php";
$smsGateway = new SmsGateway('my_email_on_their_website', 'my_password_for_this_account');

$deviceID = 111111; //the number of my device, displayed on their website or on the software installed on my phone
$number = '+1234567891'; //the number I want to SMS
$message = 'Hello World!'; //my message

$options = [
    'send_at' => strtotime('+10 minutes'), // Send the message in 10 minutes
    'expires_at' => strtotime('+1 hour') // Cancel the message in 1 hour if the message is not yet sent
];

//Please note options is no required and can be left out
$result = $smsGateway->sendMessageToNumber($number, $message, $deviceID, $options);
?>

但是当我使用我的浏览器http://mywwebsite.com/test.php访问时,它不会发送短信,你知道为什么会这样吗?你能帮我解决这个问题吗? (我手机上的网关仍处于活动状态。)

提前谢谢!

祝你好运

1 个答案:

答案 0 :(得分:0)

您的代码是正确的。如果要显示结果,请在$result变量

之后写下以下行
echo json_encode($result);

所以你的代码看起来像这样

    <?php
    include "smsGateway.php";
    $smsGateway = new SmsGateway('my_email_on_their_website', 'my_password_for_this_account');

    $deviceID = 111111; //the number of my device, displayed on their website or on the software installed on my phone
    $number = '+1234567891'; //the number I want to SMS
    $message = 'Hello World!'; //my message

    $options = [
        'send_at' => strtotime('+10 minutes'), // Send the message in 10 minutes
        'expires_at' => strtotime('+1 hour') // Cancel the message in 1 hour if the message is not yet sent
    ];

    //Please note options is no required and can be left out
    $result = $smsGateway->sendMessageToNumber($number, $message, $deviceID, $options);
echo json_encode($result);
    ?>