Mas2.0 Java SMS/MMS development interface

Source: Internet
Author: User

Recently, a new text message development tool has been used in the project. The following is the test code.

Smsapiclient = NULL; long mobile = 12312312312l; string content = "send api sms"; // SMS content string xcode = ""; // SMS extension code string appid = ""; // API plug-in ID string apppwd = ""; // API plug-in password int masapiport = 61616; string Masip = ""; // listener is self-implemented smsapiclienthandler smshandler = new listener (); try {smsapiclient = new smsapiclientimpl (smshandler, Masip, masapiport, appid, apppwd); // The setting is Whether to automatically reconnect to the server (you do not need to set it) smsapiclient. setautoconnect (true); // sets the time interval between automatically reconnecting servers (unit: seconds). The default value is 30 seconds (you do not need to set it) smsapiclient. setreconnectinterval (60); // set the timeout time for connecting to the service. The unit is Millisecond (which can be left empty) smsapiclient. setconnecttimeout (100000); // set the sending timeout time. Unit: Millisecond (which can be left empty) smsapiclient. setsendtimeout (1000000); smsapiclient. start (); // get the limit of the number of messages submitted by Group Sending: int ret = smsapiclient. getdestaddrslimit (); // get the gateway connection status (CONNECT: the connection is normal, discon Nect: disconnected, notconnect: no connection, other: Others) connectstatus = smsapiclient. getconnstatusiagw (); If (! Connectstatus. connect. equals (connectstatus) {system. out. println ("gateway not connected"); return;} // calculate the number of messages and the number of words smscount = smsapiclient. getsmscount (content, msgfmt. gb2312, smstype. normal); // get the Extension Service Code (plug-in SMS extension number + serial number) length int xcodelength = smsapiclient. getxcodelength (); List <string> List = new arraylist <string> (); // The maximum number of groups per time cannot exceed the limit (INT I = 0; I <ret; I ++) {Long Address = Mobile + I; List. add (string. valueof (Address) ;}//// * // send SMS //====== construct the start of sending the SMS object, the following code demonstrates the main attributes of the text message object. Other attributes can be left unspecified. If you want to set them, refer to the parameter smssendrequest = apismssendrequest smssendrequest = new apismssendrequest () in the sendsms method (); smssendrequest. setappid (appid); smssendrequest. setdestaddrs (list); smssendrequest. setxcode (xcode); smssendrequest. setmessage (content); smssendrequest. setmsgformat (msgfmt. gb2312); smssendrequest. settype (smstype. normal); smssendrequest. setvalidtime (10000); smssendrequest. setneedreport (true); smssendrequest. setpriority (0); // ====== construct the end of the text message object ====== apismssendresponse smssendresponse = smsapiclient. sendsms (smssendrequest); system. out. println ("submitted successfully, requestid:" + smssendresponse. getrequestid () + ", errcode" + smssendresponse. geterrcode () + ", DESC" + smssendresponse. getdesc ();} catch (exception e) {e. printstacktrace (); system. out. println ("api sms client call failed:" + E. getmessage (); // smsapiclient. loginout (); return ;}

 

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.