Prehistory
The authorities set the task to organize SMS-newsletter for the structural units of the organization. The sms-sending company provides the smpp protocol. It was necessary to organize the sending of short text messages via smpp, to receive delivery reports. Kannel was selected as the SMS gateway.
The article is a “quick start” by Kannel and contains the basic settings of the gateway and code examples, on the basis of which you can write your own SMS-sending system.
Installation and configuration will be exemplified by Fedora.
Remark
This article is not a clone of this
http://habrahabr.ru/post/124302 and this
http://habrahabr.ru/post/123380 articles.
I am familiar with them and used them in the process of work, my and these articles will have much in common, but I wanted to somehow systematize all the information accumulated in the process of work for further use in work.
Installation and Setup
Install the
kannel
package:
yum install kannel
Create user kannel
useradd kannel
Editing the /etc/kannel.conf file
group = core admin-port = 13000 smsbox-port = 13001 admin-password = 1 log-file = "/var/log/kannel/kannel.log" log-level = 0 dlr-storage = internal store-file = "/home/kannel/kannel.store" group = smsbox bearerbox-host = "127.0.0.1" sendsms-port = 13003 group = sendsms-user username = foo password = bar concatenation = true max-messages = 20 group = smsc smsc = smpp smsc-id = id host = domain.com port = 3700 transceiver-mode = 1 smsc-username = "login" smsc-password = "password" system-type = "VMA" address-range = "" log-file = "/var/log/kannel/smsc-operator.log" log-level = 0
')
We start kannel
/etc/init.d/kannel start
In order to make sure that everything works go to the address:
mydomain.com:13000/status
SMS sending
In order to send SMS in the simplest case, you need to type in the address bar:
domain.com:13003/cgi-bin/sendsms?user=foo&pass=bar&from=Test&coding=0&to=38050000000000&text=Test1
This technique can be used for the test, but in a real situation it is not suitable. Yes, and I want to send SMS not in transliteration, but in Russian. In this case, the following code will do:
function send_sms($from, $to, $mytext) { $mytext=urlencode(iconv("utf-8","ucs-2be",$mytext)); $url = "http://domain.com:13003/cgi-bin/sendsms?user=foo&pass=bar&from=$from&coding=2&to=$to&text=$mytext"; file_get_contents($url); }
If you want to send in transliteration (or just completely in English), then there is no need to re-code the text and the coding = 0 parameter is used in the address bar.
function send_sms_translit ($from, $to, $mytext) { $mytext=urlencode($mytext); $url = "http://domain.com:13003/cgi-bin/sendsms?user=foo&pass=bar&from=$from&coding=0&to=$to&text=$mytext"; file_get_contents($url); }
It should be noted that long SMS messages are sent correctly, absolutely no problems arise.
Delivery Reports
In order to receive delivery reports, we need to assign the id of each SMS and give Kannel the address that he should call when receiving the delivery report.
To begin, I will give the code
function send_sms($from, $to, $mytext, $smd_id) { $mytext=urlencode(iconv("utf-8","ucs-2be",$mytext)); $dlrurl=urlencode("http://domain.com/smsdeliv.php?smsid=$sms_id&type=%d"); $url = "http://domain.com:13003/cgi-bin/sendsms?user=foo&pass=bar&from=$from&coding=2&to=$to&dlr-mask=1&dlr-url=$dlrurl&text=$mytext"; file_get_contents($url); }
In the
dlr-url
parameter we give the address that will be called when the delivery report is received.
The
dlr-mask
parameter determines which types of delivery messages we want to receive.
The mechanism of this scheme is described in detail on the page.
www.kannel.org/download/kannel-userguide-snapshot/userguide.html#DELIVERY-REPORTS .
It also shows the types of delivery messages and their numeric values.
I do not see the point in bringing them here in addition.
That's all, thank you for your attention.