Friday, January 20, 2006

SMS and misc. bar code reading...

Introduction
SMS (also known as text-messaging) has grown into a very popular method of communication. It has been around in Europe and Asia since the early nineties and its use is steadily increasing in the US as well.
SMS stands for "Short Message Service" and uses mobile phones to transmit (surprise, surprise) short messages to and from mobile phones and whilst many of us might not know this, it is also possible to send SMS messages from a website or a piece of software.
There are an infinite number of reasons why you might want to use your website to send SMS. You might want to add a "send by SMS" option to your headlines, for example, or you might want to provide 24/7 support in which your technician is alerted by SMS or you might simply want to provide your viewers with Free SMS to drive traffic to your site.
Although it is also possible to send SMS via e-mail, this tutorial will teach you how to send SMS using GET and POST HTTP methods in PHP (since it's the language I know).
For those of us that many not know this, using HTTP basically means the use of forms, just like a contact form, except that these will be submitted automatically as opposed to manually.
Although this tutorial can be used for any gateway that provides access via HTTP, it is based on TM4B's SMS Gateway because A) they are the only gateway I know that have a simulation mode for tweaking your scripts, B) they don't have any set-up fees, C) their prices are low, D) they are reliable and E) I use them.

Understanding the Requirements of the Gateway
Full details about connecting to TM4B are provided on their SMS API page. They basically require us to provide six mandatory pieces of data:
username: our username
password: our password
msg: our SMS message(s)
to: the recipient(s) of our message
from: our sender id
route: the route of the message (i.e. first class or business class)
And we will add a seventh, which is "sim". This identifies that our message is only a simulation and so credits won't be removed from our account and messages won't actually be delivered.

Now the actual message-delivery process is handled by the gateway. All they want us to do is pass them the details of the message(s) in the form of an HTTP request, similar to this one:
http://www.tm4b.com/client/api/send.php?username
=abcdef&password=12345&msg=This+is+sample+message.&to =447768254545%7C447956219273%7C447771514662&from
=MyCompany&route=frst&sim=yes
You can test the above example (which uses GET) by pasting it into your browser's address bar. You should get a response saying that the username is invalid, which is normal because this is just to demonstrate.
The first step is to save our data as variables and then convert them into a URL request. There are different ways of doing this, but this is a very innovative and useful way:
$val) //traverse through each member of the param array{ $request.= $key."=".urlencode($val); //we have to urlencode the values $request.= "&"; //append the ampersand (&) sign after each paramter/value pair}$request = substr($request, 0, strlen($request)-1); //remove the final ampersand sign from the request?>

We assign our credentials and routing information in the $param array. You'll notice that multiple recipients can be defined by separating them with the pipe-character. Each parameter value needs to be urlencoded and multiple key/value pairs are separated by ampersands. A final ampersand probably would not cause any problems but substr is still used to produce a tidy request.
The script will produce the following request that can be sent to the SMS gateway: username=abcdef&password=12345&msg
=This+is+sample+message.&to
=447768254545%7C447956219273%7C447771514662&from
=MyCompany&route=frst&sim=yes

Sending the request with CURL
Previously we saw that the request could be executed by pasting it into the browser window. But what we really want is for this to take place behind the scenes. The following code does exactly that using CURL.
CURL is a very impressive library that allows you to connect and communicate to many different types of servers with many different types of protocols. You can find more info in the PHP Manual.
This code opens up a connection with the gateway, sends the SMS message(s) and collects their message IDs which are presented within the response header.


First, we initialize a new CURL session. Then we set our desired options; this includes setting CURLOPT_POST because TM4B's SMS API requires us to send multiple messages using POST. Finally we execute the call and then close the handle.

Sending the Request with Sockets
CURL functions depend on an external library and PHP must have been compiled with the --with-curl flag. So while CURL is very flexible and useful, it may not be available with your PHP installation. If this is the case, you can still communicate with the SMS gateway using sockets.


First we layout the information we'll need to send our SMS and use it construct the HTTP header. A socket connection is established to our gateway using fsockopen. Information is sent and received in the same manner PHP would read and write to a file. After our transfer is complete we close the socket using fclose.

Conclusion
That's It! Although it took me a long time to find CURL, I think it is the best, neatest and quickest option assuming your version of PHP supports it. Furthermore, whilst both fsockopen and CURL can send thousands of messages in one go, fsockopen might give you difficulties when parsing responses for large requests as the responses are transferred in chunks.

The above took me ages; I hope it saves you time.

About the Author

Farheen Rehman is the editor of BestKeptSimple, a very popular blog about SMS. She is very well versed with the commercial use of SMS and provides consultancy for organizations that want to add it to their communications mix.
-------------------
(SMS short message service) PHAI HOI VINA VA MOBILE co dich vu sau day. Con phan web thi xem phan code.
KHong don gian fai su lien he giua website and wireless network. 2 cach:
- sms getaway can hoi Vinaphone hay Mobile co dich vu do la mot address nhu thuong vi du 8367888@vnn.com (sms getaway)
tat ca sms goi qua address minh co the setup address forward qua mot email cua minh nhu sales@vinetcom.com (website)
sms getaway cung cap su ket noi giua het thong wireless va cho phep goi qua mot dia chi thong nhat. sms getaway cung giong
nhu mua card dien thoai tra tien truoc. Luc truoc ICQ co dich vu nay bay gio goi sms thi phai ton tien o ICQ.
Basically, the "gateway" would be the provider that connects to telecom network with authorisation to send sms.
- hay tim mot dich vu nao o VN cho phep send sms duoi dang email
thi code nhu thuong le thi dich vu nay se chuyen qua sms va vice versa (goi tu mobile thi chuyen qua email) nhu vay website
ho tro nhu binh thuong. Tuy Mobile and Vina co cho dia chi nhu 6137425788@mobile.att.net moi so dien thoai co mot email nhu vay neu email goi qua dia chi nay thanh sms o dia thoai so 6137425788

Tom lai la minh chi can co mot dia chi ma VINA va MOBILE biet de goi den tu he thong wireless cua ho.

Viet code
1 - sms getaway
VIet php tu website cung nhu viet form goi mail nhu http://xxxx/ ma ho da define cho minh
connect form contact action to the script of service provider (cung giong nhu tra tien tren mang)


2- 2025551212@mobile.att.net
Khach hang se goi qua dia chi nay thi no se forward dia chi minh va nguoc lai khi goi tra cho khach hang thi minh doi
$cusmess .= "contact@vinetcom.com "; -->2025551212@mobile.att.net $headers = getheaders("Vinetcom",$emailadmin); $headers1 = getheaders("$email",$email); mail($email,$cussub,$cusmess,$headers);
Note: to have 2025551212@mobile.att.net or something like that to receive the reply from mobile phone, the monthly charge is $20/month.
For send SMS under form mail, need to buy SMS msg or credits. 1000 credits could
cost between $7.00 to $10.00. Both can be purchased at
http://www.clickatell.com

Format cua SMS cung nhu email
Header: identifies the type of message.
Service Center Timestamp
Originator Address: the phone number of the sender
Protocol Identifier
Data Coding Scheme
User Data Length: tells how long the message is
User Data: the message itself (140 bytes: 160 7-bit characters, or 140 8-bit characters)
How SMS worksSMS works on a store-and-forward basis. Instead of being sent directly to the recipient, SMS messages travel through several important nodes before reaching the recipient (skip this part if you find it boring; there's more good stuff below).
The SMS message is submitted to your wireless service provider's SMS Center.
After the message is processed internally, the SMS Center sends a request to the Home Location Register (HLR) and receives the routing information for the recipient.
The SMS Center sends the message to the Mobile Switching Center (MSC).
The MSC collects the recipient's information from the Visitor Location Register (VLR) and, sometimes, proceeds with an authentication operation.
The MSC forwards the message to a Mobile Server.
If the recipient has a Treo or VisorPhone, the SMS is placed on the SIM card until the handheld picks up the message and transfers it to the internal memory on the unit.
This is how Treos and VisorPhones can store hundreds of SMS messages, unlike ordinary GSM mobile phones that store only a few SMS messages.
Treo or VisorPhone owners may encounter the error message "Your SIM contains at least one SMS message. Do you want to move the message to your Visor?" See the related SMS article in our knowledgebase for details.
The MSC returns the outcome of the Forward Short operation to the SMS Center.
The SMS Center reports delivery status of the short message back to the sender
-----
Dau co can quyen gi dau vao cpanel roi mysql tao, anh tao thu 1 database dau co can quyen gi. Chi can log
vao cpanel with username and pwd da goi. Ve barcode thi anh khong biet dau. Can mot interface run pcapplications
voi scan reader doc vao PC roi upload len website. Khong biet em co lam duoc khong. PHP khong co lam duoc
ma C/C++ hay Visual Basic. Em biet chu ? PHP la web language. Nen muon hay cong tac mot nguoi kha kha mot chuc
lam giup ve nhung ky thuat.
scan bar code ---rs232/usb --> data to pc ----upload data to database---> website hinh thuc
c/c++/vb php ngon ngu lap trinh
Thu 4 tuan sau anh di cong chuyen 3 ngay neu khong reply you will know.
-----------------------


No comments: