Home  >  Article  >  php教程  >  PHP与TextMagic短信功能实现

PHP与TextMagic短信功能实现

WBOY
WBOYOriginal
2016-06-06 19:33:531044browse

如何使用PHP和一个简单的调用一样简单的邮件(),TextMagic提供了一个API,用于各种语言(Java、PHP、Perl、Python、Ruby等等),很容易配置。 无 几个月前我写了一个令人震惊的公开发短信如何使用PHP和一个简单的调用一样简单的邮件()。使用邮件方法唯一的缺点是,

如何使用PHP和一个简单的调用一样简单的邮件(),TextMagic提供了一个API,用于各种语言(Java、PHP、Perl、Python、Ruby等等),很容易配置。
几个月前我写了一个令人震惊的公开发短信如何使用PHP和一个简单的调用一样简单的邮件()。使用邮件方法唯一的缺点是,你需要知道承运人对于一个给定的电话号码——一个丢脸的问题要问任何你打算做广告。幸运的是有一个简单有效的web服务可以称为TextMagic。TextMagic提供了一个API,用于各种语言(Java、PHP、Perl、Python、Ruby等等),很容易配置。

                        
PHP
一旦你TextMagic帐户和你下载提供的API辅助TextMagic,所有您需要做的是创建一个自定义代码来发送你的短信:

    // Include the TextMagic PHP lib
    require('textmagic-sms-api-php/TextMagicAPI.php');

    // Set the username and password information
    $username = 'myusername';
    $password = 'mypassword';

    // Create a new instance of TM
    $router = new TextMagicAPI(array(
            'username' => $username,
            'password' => $password
    ));

    // Send a text message to '999-123-4567'
    $result = $router->send('Wake up!', array(9991234567), true);

    // result:  Result is: Array ( [messages] => Array ( [19896128] => 9991234567 ) [sent_text] => Wake up! [parts_count] => 1 )

复制代码
send调用的结果是一个数组的信息发送你的信息。检查发送状态之后,你只需要调用messageStatus方法:

    // Get the message send status by received ID
    $result = $router->messageStatus(array(19896128));

    // result:  Array ( [19896128] => Array ( [text] => Wake up! [status] => d [created_time] => 1325261093 [reply_number] => 447624800500 [completed_time] => 1325261120 [credits_cost] => 1 ) )

复制代码
如果你想检查一个电话号码的状态和信贷成本发送短信的号码,你可以打电话checkNumber:

    // Get the message number information
    $result = $router->checkNumber(array(9991234567));

    // result:  Array ( [16083359316] => Array ( [price] => 1 [country] => US ) )

复制代码

                        
TextMagic真是一个了不起的服务。账户很容易创建、API很简单,和最重要的是,不需要知道收件人的载体!

来源:PHP站中文网


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn