Reflection of text messages by API smsc



  • API text message should be implemented введите сюда описание изображения

    The second to each type of mailing shall be affixed to its character. communication

    введите сюда описание изображения

    There's a general idea, but it's very embarrassing and it's not true.

    Choose. login We'll check on some condition. Type of mailing for that logic. If included, let's say alert. Approximate payment period - send a message of this type to Number A subscriber.

    I sent a hand message like this:

    <script language=javascript>
        window.parent.location.href = "https://smsc.ru/sys/send.php?login=login&psw=psw&phones=$telephone&mes=$message";                             
    </script>
    

    There is a need to set up phone numbers and messages for them. But because of my scarce knowledge, I can't figure out how to do it yet. I hope so.

    UPD:

    So I add the data to the first table:

    $table = $system_site_prefix . 'erps_services_sms'; 
    database_insert("INSERT INTO `$table` VALUES 
      (\"$index\", \"$abon_login\", \"$telephone\", \"$pay\", \"$orders\", \"$news\", \"$other\")");
    

    So in the second:

    $table = $system_site_prefix . 'erps_messages_sms'; 
    database_insert("INSERT INTO `$table` VALUES (\"$index\", \"$group\", \"$title\", \"$message\")");
    

    UPD2:

    Table structure:

    введите сюда описание изображения

    введите сюда описание изображения

    введите сюда описание изображения

    введите сюда описание изображения



  • They have a PHP class to work with their service, you can use it.
    Login and password add yours.

    <?php    
    

    class Sms
    {
    const login = "";
    const pass = "";
    const post = 1;
    const https = 1;
    const charset = "utf-8";
    const from = "support@example.com";
    const debug = 1;

    public function SendSmsWorld($phones, $message, $translit = 0, $time = 0, $id = 0, $format = 0, $sender = "example.com"", $query = "")
    {
        static $formats = array(1 =&gt; "flash=1", "push=1", "hlr=1", "bin=1", "bin=2", "ping=1");
        $m = $this-&gt;SmsSendCmd("send","cost=3&amp;phones=".urlencode($phones)."&amp;mes=".urlencode($message)."&amp;translit=$translit&amp;id=$id".
            ($format &gt; 0 ? "&amp;".$formats[$format] : "").
            ($sender === false ? "" : "&amp;sender=".urlencode($sender)).
            ($time ? "&amp;time=".urlencode($time) : "").($query ? "&amp;$query" : ""));
    
        if (self::debug) {
            if ($m[1] &gt; 0)
                echo "Сообщение отправлено успешно. ID: $m[0], всего SMS: $m[1], стоимость: $m[2], баланс: $m[3].\n";
            else
                echo "Ошибка №", -$m[1], $m[0] ? ", ID: ".$m[0] : "", "\n";
        }
        return $m;
    }
    
    
    public function GetSmsCost($phones, $message, $translit = 0, $format = 0, $sender = false, $query = "")
    {
        static $formats = array(1 =&gt; "flash=1", "push=1", "hlr=1", "bin=1", "bin=2", "ping=1");
        $m = $this-&gt;SmsSendCmd("send", "cost=1&amp;phones=".urlencode($phones)."&amp;mes=".urlencode($message).
            ($sender === false ? "" : "&amp;sender=".urlencode($sender)).
            "&amp;translit=$translit".($format &gt; 0 ? "&amp;".$formats[$format] : "").($query ? "&amp;$query" : ""));
    
        // (cost, cnt) или (0, -error)
    
        if (self::debug) {
            if ($m[1] &gt; 0)
                echo "Стоимость рассылки: $m[0]. Всего SMS: $m[1]\n";
            else
                echo "Ошибка №", -$m[1], "\n";
        }
    
        return $m;
    }
    
    private function SmsSendCmd($cmd, $arg = "")
    {
        $url = (self::https ? "https" : "http")."://smsc.ru/sys/$cmd.php?login=".urlencode(self::login)."&amp;psw=".urlencode(self::pass)."&amp;fmt=1&amp;charset=".self::charset."&amp;".$arg;
        $i = 0;
        do {
            if ($i)
                sleep(2);
            $ret = $this-&gt;SmsReadUrl($url);
        }
        while ($ret == "" &amp;&amp; ++$i &lt; 3);
        if ($ret == "")
        {
            if (self::debug)
                echo "Ошибка чтения адреса: $url\n";
            $ret = ","; // фиктивный ответ
        }
        return explode(",", $ret);
    }
    
    private function SmsReadUrl($url)
    {
        $ret = "";
        $post = self::post || strlen($url) &gt; 2000;
        if (function_exists("curl_init"))
        {
            static $c = 0;
            if (!$c) {
                $c = curl_init();
                curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 10);
                curl_setopt($c, CURLOPT_TIMEOUT, 60);
                curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
            }
    
            if ($post) {
                list($url, $post) = explode('?', $url, 2);
                curl_setopt($c, CURLOPT_POST, true);
                curl_setopt($c, CURLOPT_POSTFIELDS, $post);
            }
    
            curl_setopt($c, CURLOPT_URL, $url);
            $ret = curl_exec($c);
        }
        elseif (!self::https &amp;&amp; function_exists("fsockopen"))
        {
            $m = parse_url($url);
            $fp = fsockopen($m["host"], 80, $errno, $errstr, 10);
    
            if ($fp) {
                fwrite($fp, ($post ? "POST $m[path]" : "GET $m[path]?$m[query]")." HTTP/1.1\r\nHost: smsc.ru\r\nUser-Agent: PHP".($post ? "\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: ".strlen($m['query']) : "")."\r\nConnection: Close\r\n\r\n".($post ? $m['query'] : ""));
                while (!feof($fp))
                    $ret .= fgets($fp, 1024);
                list(, $ret) = explode("\r\n\r\n", $ret, 2);
                fclose($fp);
            }
        }
        else
            $ret = file_get_contents($url);
        return $ret;
    }
    

    }

    Once you get the data, you can be sent out in the cycle by issuing a method. SendSmsWorld

    $sms = new Sms();
    foreach ($arrListPhone as $r)
    {
    $sms->SendSmsWorld($r['telephone'], $r['message'], 0);
    }

    For a large number of numbers, it's better to use a mass mailing request with one request, I'm not sure if they have this opportunity or not, but at all, they should be looking for some documentation. If you ask me about the support, they'll say and the reference will be dropped.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2