示例#1
0
/**
 * textmagic API来发送消息
 *
 * 发送一些短信到客户手机
 * @url http://davidwalsh.name/php-text-messaging
 */
<?php 
// Include the TextMagic PHP lib
require 'textmagic-sms-api-php/TextMagicAPI.php';
// Set the username and password information
$username = '******';
$password = '******';
// 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 )
<?php

if (isset($_REQUEST['sendMessage'])) {
    include _PATH . "/TextMagic/TextMagicAPI.php";
    $api = new TextMagicAPI(array("username" => "davejay", "password" => "uUXgZoOkpG"));
    $text = _escape($_REQUEST['txtMessage']);
    $phones = array($_REQUEST['ddlPhone']);
    $results = $api->send($text, $phones, true);
    $messageId = '';
    $phone = '';
    if (isset($results['messages'])) {
        foreach ($results['messages'] as $key => $value) {
            $messageId = $key;
            $phone = $value;
        }
        $conv_fields = array();
        $conv_fields['deal_id'] = $_REQUEST['hidDealId'];
        $conv_fields['message_id'] = $messageId;
        $conv_fields['receiver'] = $phone;
        $conv_fields['receiver_last10'] = last10Char($phone);
        $conv_fields['type'] = 'SENT';
        $conv_fields['text'] = $results['sent_text'];
        $conv_fields['messageTime'] = _mysqlDate();
        $text_conv_list = q("select id from text_conversation where message_id='{$messageId}'");
        if (count($text_conv_list) == 0) {
            qi("text_conversation", $conv_fields);
        } else {
            qu("text_conversation", $conv_fields, "message_id='{$messageId}'");
        }
    }
    echo "success";