Example #1
0
function convert_to_unicode($unicode, $message)
{
    if ($unicode == 1) {
        if (function_exists('mb_convert_encoding')) {
            $message = mb_convert_encoding($message, "UCS-2BE", "auto");
            // $sms_msg = utf8ToUnicode($sms_msg);
        }
        $message = core_str2hex($message);
    }
    return $message;
}
Example #2
0
function clickatell_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "clickatell_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    if ($plugin_config['clickatell']['module_sender']) {
        $sms_sender = $plugin_config['clickatell']['module_sender'];
    }
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg);
    $sms_from = $sms_sender;
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    switch ($sms_type) {
        case "flash":
            $sms_type = "SMS_FLASH";
            break;
        case "logo":
            $sms_type = "SMS_NOKIA_OLOGO";
            break;
        case "picture":
            $sms_type = "SMS_NOKIA_PICTURE";
            break;
        case "ringtone":
        case "rtttl":
            $sms_type = "SMS_NOKIA_RTTTL";
            break;
        case "text":
        default:
            $sms_type = "SMS_TEXT";
    }
    // Automatically setting the unicode flag if necessary
    if (!$unicode) {
        $unicode = core_detect_unicode($sms_msg);
    }
    if ($unicode) {
        if (function_exists('mb_convert_encoding')) {
            $sms_msg = mb_convert_encoding($sms_msg, "UCS-2BE", "auto");
        }
        $sms_msg = core_str2hex($sms_msg);
        $unicode = 1;
    }
    // fixme anton - if sms_from is not set in gateway_number and global number, we cannot pass it to clickatell
    $set_sms_from = $sms_from ? "&from=" . urlencode($sms_from) : '';
    // fixme anton - temporary solution #385 Unable to send messages when clickatell password contains &
    $password = urlencode(htmlspecialchars_decode($plugin_config['clickatell']['password']));
    $query_string = "sendmsg?api_id=" . $plugin_config['clickatell']['api_id'] . "&user="******"&password="******"&to=" . urlencode($sms_to) . "&msg_type={$sms_type}&text=" . urlencode($sms_msg) . "&unicode=" . $unicode . $set_sms_from;
    $url = $plugin_config['clickatell']['send_url'] . "/" . $query_string;
    if ($additional_param = $plugin_config['clickatell']['additional_param']) {
        $additional_param = "&" . htmlspecialchars_decode($additional_param);
    } else {
        $additional_param = "&deliv_ack=1&callback=3";
    }
    $url .= $additional_param;
    $url = str_replace("&&", "&", $url);
    logger_print("url:" . $url, 3, "clickatell outgoing");
    $fd = @implode('', file($url));
    $ok = false;
    // failed
    $p_status = 2;
    if ($fd) {
        $response = explode(":", $fd);
        $err_code = trim($response[1]);
        if (strtoupper($response[0]) == "ID") {
            if ($apimsgid = trim($response[1])) {
                clickatell_setsmsapimsgid($smslog_id, $apimsgid);
                list($c_sms_credit, $c_sms_status) = clickatell_getsmsstatus($smslog_id);
                // pending
                $p_status = 0;
                if ($c_sms_status) {
                    $p_status = $c_sms_status;
                }
            } else {
                // sent
                $p_status = 1;
            }
            logger_print("smslog_id:" . $smslog_id . " charge:" . $c_sms_credit . " sms_status:" . $p_status . " response:" . $response[0] . " " . $response[1], 2, "clickatell outgoing");
        } else {
            // even when the response is not what we expected we still print it out for debug purposes
            $fd = str_replace("\n", " ", $fd);
            $fd = str_replace("\r", " ", $fd);
            logger_print("smslog_id:" . $smslog_id . " response:" . $fd, 2, "clickatell outgoing");
        }
        $ok = true;
    }
    dlr($smslog_id, $uid, $p_status);
    return $ok;
}
Example #3
0
function infobip_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    $ok = false;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "infobip_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    if ($plugin_config['infobip']['module_sender']) {
        $sms_sender = $plugin_config['infobip']['module_sender'];
    }
    $sms_from = $sms_sender;
    $smsType = "&SMSText";
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    switch ($sms_type) {
        case "flash":
            $sms_type = 1;
            break;
        case "text":
        default:
            $sms_type = 0;
    }
    if ($unicode) {
        if (function_exists('mb_convert_encoding')) {
            $sms_msg = mb_convert_encoding($sms_msg, "UCS-2BE", "auto");
        }
        $sms_msg = core_str2hex($sms_msg);
        $unicode = 8;
        $smsType = "&binary";
    }
    // fixme anton - if sms_from is not set in gateway_number and global number, we cannot pass it to infobip
    $set_sms_from = $sms_from == $sms_sender ? '' : urlencode($sms_from);
    // query_string = "sendmsg?api_id=".$plugin_config['infobip']['api_id']."&user="******"&password="******"&to=".urlencode($sms_to)."&msg_type=$sms_type&text=".urlencode($sms_msg)."&unicode=".$unicode.$set_sms_from;
    $query_string = "sendsms/plain?user="******"&password="******"&GSM=" . urlencode($sms_to) . $smsType . "=" . urlencode($sms_msg) . "&sender=" . $sms_from;
    $query_string .= "&IsFlash=" . $sms_type . "&DataCoding=" . $unicode;
    $url = $plugin_config['infobip']['send_url'] . "/" . $query_string;
    $dlr_nopush = $plugin_config['infobip']['dlr_nopush'];
    if ($dlr_nopush == '0') {
        $additional_param = "&nopush=0";
    } elseif ($dlr_nopush == '1') {
        $additional_param = "&nopush=1";
    }
    if ($additional_param = $plugin_config['infobip']['additional_param']) {
        $additional_param .= "&" . $additional_param;
    }
    $url .= $additional_param;
    $url = str_replace("&&", "&", $url);
    logger_print("url:" . $url, 3, "infobip outgoing");
    $xml = file_get_contents($url);
    $response = core_xml_to_array($xml);
    if ($response) {
        if ($response['result']['status'] == 0) {
            if ($apimsgid = trim($response['result']['messageid'])) {
                infobip_setsmsapimsgid($smslog_id, $apimsgid);
                list($c_sms_credit, $c_sms_status) = infobip_getsmsstatus($smslog_id);
                // pending
                $p_status = 0;
                if ($c_sms_status) {
                    $p_status = $c_sms_status;
                }
            } else {
                // sent
                $p_status = 1;
            }
            logger_print("smslog_id:" . $smslog_id . " charge:" . $c_sms_credit . " p_status:" . $p_status . " response:" . $response['result']['status'], 2, "infobip outgoing");
        } elseif ($response['result']['status'] == -2) {
            logger_print("smslog_id:" . $smslog_id . " response:" . $response['result']['status'] . " NOT_ENOUGH_CREDIT", 2, "infobip outgoing");
        } else {
            // even when the response is not what we expected we still print it out for debug purposes
            $fd = str_replace("\n", " ", $fd);
            $fd = str_replace("\r", " ", $fd);
            logger_print("smslog_id:" . $smslog_id . " response:" . $response['result']['status'] . " UNKNOWN_CODE", 2, "infobip outgoing");
        }
        $ok = true;
    } else {
        logger_print("no response smslog_id:" . $smslog_id, 3, "infobip outgoing");
    }
    if (!$ok) {
        $p_status = 2;
    }
    dlr($smslog_id, $uid, $p_status);
    return $ok;
}