Mobile Internet (i) SMS and MMS Interface Development Kit

Source: Internet
Author: User

Participate in this project, SMS and MMS feature. It is considered to be an important part of the project and how to develop this function was previously thought. For example, there are many orders of our Yonghe system, how to let users know their own card in time consumption situation? How to let users have a sense of security, think of your bank card every time you spend or transfer, turn out every paragraph when there is a text message prompt, you inadvertently added a sense of security?

Everyone is thinking about the various types of portals, and we often use the csdn and other forums are provided with SMS login, as well as SMS verification code, text message, such as SMS note to the business content, all of these are a thought to improve system flexibility, ease-of-use, security, user-friendly for users to consider. Serve the whole heart wholeheartedly. If embedded in the project SMS function undoubtedly added the system credit rating, but also to our system to add users. Learn to think for others everywhere will make their own benefit, as the saying goes, "self-interest, the people of the constant." It means that doing everything assumes that you are only thinking of yourself and that you are good for yourself, that you can live, but that others will benefit you for a long time.

Start saying: I am responsible for this part is to encapsulate the third-party interface, the various configuration of these interfaces and other tools are written as jar file, in our project which part of the use of sending SMS MMS and other functions only need to introduce my jar package to achieve these functions is very convenient.

In turn think of our university platform inside can also increase the text message function. Student information in the student's cell phone number, and so on the results of the exam to send a message to the students. This will not be very easy to change, of course, SMS fees need to let students themselves buckle, so many students send a lot of information.

Project manager gave me a text messaging service provider to provide a text API document, which is the bottom of a variety of methods from the site looking for these documents from the Internet is able to search, this piece of author to is not difficult. The emphasis is on logic and nothing bugs, because the underlying stuff needs to be very discreet. These are written so that they are provided for use and invocation by others in the project and are not subject to any problems. I also pay extra attention to the process of adding a lot of inferences and null pointers when writing.

Design ideas, the spirit of reliable, flexible for the use of others for the purpose of convenience.

Invocation mode

WebService

Server and cross-platform, cross-language calls.

Https

This project is used in this way to use the URLConnection object to communicate between the two servers, which is interesting to check.

Again, the experience and considerations for designing the underlying interface:

1. SMS Serverserver address can be configured

The interface address of the service provider may change. Development test an interface system is on-line and there is an interface. In the development of this need to design a variable can not be written in the code, the first design I uninstalled the code inside the show this is not flexible, in fact, not only this. No matter what you're writing, the assumptions are easy and variable, and the amount of variation you need to write in the configuration file avoids unnecessary trouble in the future. It is not necessary to modify the code after the maintenance convenience.


2. Interface with different parameters for the same method

This has been realized in the university platform. The bottom layer provides a variety of interfaces but an update provides a variety of parameters, almost the update operation can call this method, which is convenient usability, the bottom part of the hair is provided to others, in life is the same as everyone likes to use simple things. It's too complicated to learn. Take the user as a pig to treat.

3. Parameters and return values understand

The more the bottom the more strict, the more show the benefits. I wonder if you have any interest in researching open source frameworks, such as struts, SPRINGMVC, Hibernate, and so on, to see how the underlying methods of these frameworks are written. Stand on the shoulders of giants will learn fast, stand high talent to see far, they write is very specific such as the number of participants, to see what type of name know what, when you enter the number of illegal will be prompted, this is the advantages of their design, imagine you write your own method when others call, If the parameters are illegal, what information do you suggest to others? Think at least not now. Especially in the cooperative development of many people. Suppose you don't do it. Our cooperative version of the computer room system, our cooperation in the project. How to cooperate? There is no way to continue development. There's just something wrong with you. In person to find that write interface, writing methods of the people to solve the face to face the ability to continue, this is obviously a bit against the cooperative development, contrary to the idea of OOP.

4. When the number of parameters is not normalized, return immediately to the following operation

The underlying method call frequency may be quite high, do not cause unnecessary waste of content, when a method runs to each position in the middle, suddenly encountered a problem, it is necessary to immediately return the problem to the caller, no longer run to the following, which is also a principle of the underlying programming very many frameworks also do so. We have all learned the principle of dealing with anomalies.

This principle is also the exception handling principle, when encountering the exception to remember processing and to the first level is called the method of the part thrown, there is an exception to be handled. Do timely and efficient solutions.

Just like in life, it is inevitable to encounter problems like this or that. You are choosing to let the problem accumulate more or timely processing, the truth is interlinked. Problems accumulate more than just can bring a lot of other trouble, let small problem become big problem most regret not solve, there are any problems need to solve at first. I also thought of the Flat magpie cure. Why is it that the flat magpie is famous at that time because he can treat serious illness, we all feel that the flat Magpie medicine is very clever. I wonder if you still know who is better than a flat magpie. At that time his elder brother, his elder brother cures at the beginning. When the disease is not serious when the other people cured this is a great wisdom. Solve the problem before it gets bigger, so we may have to solve the problem in the first place and solve it in time.

5. Be careful about static variables

Do you really understand his principles? Suppose a method uses a static method whose member variable is also a static variable, assuming that the member variable of the underlying method has a value to be extra careful (except for the tool function), and once in my test, I called several times the underlying method. I wonder why the results are always the same, careful examination of the underlying original is a static method of the disaster. It has a static member variable, static is not able to change in the future when the call is this value. Use static stuff and then use it when there are no member variables or member variables that are immutable. Otherwise, it will cause unnecessary trouble.


These are some of the things you need to be aware of when writing interfaces. Take a look at a send SMS interface

<span style= "FONT-SIZE:14PX;" >/** * @author Lilongsheng * @deprecated Send SMS method. Ability to send * @param mapcorpid: Account number, * pwd:password, * Mobile: Contact phone, * Cont ENT: Send Content, * Cell: Child number. Can be empty * sendtime: Timed send time, for example: 20060912152435 for September 12, 2006 15:24 35 seconds * is empty, means send immediately * * @return result string */public string Send ( String Userurl, String corpid, String Pwd, String mobile,string Content, String Cell, String sendtime) {//function returns the default value of string res ult= "SMS send Failed";//SMS Content size if (!isempty (Prosurl.getproperty ("Contentsize")) {Contentsize=integer.parseint ( Prosurl.getproperty ("Contentsize"));} Infer if the user has provided a URL address if ("". Equals (Userurl) | | Null==userurl) {userurl=prosurl.getproperty ("Sendurl");} Store the reference information map<string,object> map=new hashmap<string, object> ();//Infer if the account is empty if (!isempty (corpid)) {Map.put (" Corpid ", corpid);} else {return result= "account cannot be empty";} Infer if password is empty if (!isempty (pwd)) {map.put ("pwd", PWD);} else {return result= "password cannot be empty";} Infer if the phone format is correct if (!isempty(mobile) && Checkmobile (MOBILE) {Map.put ("mobile", mobile); else {return result= "the sending mobile phone number is empty or the format is not correct";} Infer if the text message content is empty, the size is appropriate if (!isempty) && content.length () < contentsize) {map.put ("content", content);} else {return result= "Send content is empty or content is too long";} The child number can be null if (!isempty (cell)) {Map.put ("cell", cell);} The send time can be null if (!isempty (sendtime)) {map.put ("Sendtime", Sendtime);}    try {//string strreg= ""; Call the underlying interface to send a text message//To spell the number after the URL address string url_str=getuserurl (Userurl, map); System.out.println ("url_str=" +url_str);    String Strreg=sendgetinfo (URL_STR);    System.out.println ("strresult=" +strreg); if (!isempty (Strreg)) {//is based on the underlying return value.    Returns the corresponding result if ("0". Equals (Strreg)) {return result= "sent successfully";    } if ("-1". Equals (Strreg)) {return result= "account not registered"; } ............}    catch (Exception e) {e.printstacktrace ();} return result;} </span>
Public methods for encapsulation

<span style= "FONT-SIZE:14PX;" >/** * @author Lilongsheng * @param userurl * @param maps * @return */private string Getuserurl (String userurl,map<s Tring, object> maps) {//Gets the number of references in the map. And stitching into the URL to the number of StringBuilder SB = new StringBuilder (); Sb.append (Userurl); set<string> keys = Maps.keyset (); for (final String key:keys) {Object value = Maps.get (key);//Infer if the parameters are empty if (! "". Equals (value) && null!=value) {sb.append (key);//cannot include special characters sb.append (' = '); Sb.append (value); Sb.append (' & ') );}} Sb.deletecharat (Sb.length ()-1); return sb.tostring ();} </span>

<span style= "FONT-SIZE:14PX;" >/** * @author Lilongsheng * @param url_str       Send interface * @return * @throws Exception */private string Sendgetinfo (string URL_STR) throws Exception{system.out.println (URL_STR);        url url =new url (url_str);        URLConnection connection=url.openconnection ();                Byte[] Buf=new byte[1024*4];        Bytearrayoutputstream Bos =new Bytearrayoutputstream ();        int n;        while ((N=connection.getinputstream (). Read (BUF)) >=0)                bos.write (buf,0,n);        Return bos.tostring ("GBK");} </span>
This is a simple interface to launch text messages, in addition to MMS and so on, MMS format for TMS, MMS, etc. also need MMS development package.

SMS, MMS development is not difficult, in fact, it is very simple to use other people's class library, in the development of the development side of the study, will inevitably encounter their own will not, just to take a good look, check the information, look at the understanding of others and the existing information can be resolved, In addition just went to because of the system or did not really write code, writing is not very rigorous. Recently the manager looked at my code and said it was much better than I ever wrote. Improved a lot, this is still a bit comfortable, writing code is important is the design ideas and flexibility, rigor.




Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

Mobile Internet (i) SMS and MMS Interface Development Kit

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.