示例#1
0
 */
// send the first enquire_link if start_enquire is set
if ($tx->start_enquire) {
    $tx->sendPDU(0x15, "", $tx->sequence_number++);
}
while (true) {
    $sms = $tx->readSMS();
    //check sms data
    if ($sms && isset($sms['source_addr']) && isset($sms['destination_addr'])) {
        $from = strlen($sms['source_addr']) == 11 ? substr($sms['source_addr'], 1) : $sms['source_addr'];
        $short_code = $sms['destination_addr'];
        // check where the message is stored in short_messsage or message_payload
        if (!isset($sms['short_message']) || $sms['sm_length'] != strlen($sms['short_message']) || $sms['sm_length'] == 0) {
            if (isset($sms['sar_total_segments']) && isset($sms['sar_segment_seqnum'])) {
                if ($sms['sar_total_segments'] - $sms['sar_segment_seqnum'] == 0) {
                    //if it's the last part of payload, accumlate
                    $text = $sms['user_defined_payload'];
                    unset($sms['user_defined_payload']);
                } else {
                    continue;
                }
            } else {
                $text = $sms['message_payload'];
            }
        } else {
            $text = $sms['short_message'];
        }
    }
}
$tx->close();
unset($tx);
function sendSMS($to, $message)
{
    //SMSC Configuration
    $server = "127.0.0.1";
    $port = 2775;
    $system_id = 1;
    $system_type = 1;
    $login = "******";
    $pass = "******";
    $to_ok = "";
    $from = "1234";
    //Declare $lang global in order to access it outside the function
    global $lang;
    //Pase phone number
    //Remove spaces from number
    $to = preg_replace('/\\s+/', '', $to);
    //Match number 12345678
    if (preg_match("/^(\\d{8})\$/", trim($to), $matches)) {
        $to_ok = "+45" . $matches[1];
    }
    //Match number +4512345678
    if (preg_match("/^(\\+\\d+)/", trim($to), $matches)) {
        $to_ok = str_replace(' ', '', $matches[1]);
    }
    //If we could not match number - fail:
    if (!$to_ok) {
        print "<div class=\"alert alert-danger\" role=\"alert\">\n";
        print $lang['PAGE2_SMS_ERROR1'] . " {$to}...<br/>";
        print "<a href=\"javascript:history.back()\">" . $lang['RETRY'] . "</a>";
        print "</div>";
        die;
    }
    //Save the mobile phone no for later use
    $_SESSION['portal-mobile'] = $to_ok;
    print "<div class=\"alert alert-success\" role=\"alert\">\n";
    print $lang['PAGE2_SMS_ACK'] . " " . $to_ok . "<br/>";
    print "</div>";
    try {
        #require_once "smpp.php";
        $tx = new SMPP($server, $port);
        #$tx->debug=true;
        $tx->system_type = $system_type;
        $tx->addr_npi = 1;
        #print "### open status: ".$tx->state."\n";
        $tx->bindTransmitter($system_id, $login);
        $tx->sms_source_addr_npi = 1;
        $tx->sms_source_addr_ton = 1;
        $tx->sms_dest_addr_ton = 1;
        $tx->sms_dest_addr_npi = 1;
        #Send as FLASH SMS
        #$tx->$sms_data_coding=240;
        $ret = $tx->sendSMS($from, $to_ok, $message);
        $tx->close();
        unset($tx);
    } catch (ErrorException $e) {
        print "ERROR: {$e}";
    }
    return $ret;
}