PackageUtilImportOrg.apache.commons.httpclient.HttpClient;ImportOrg.apache.commons.httpclient.HttpStatus;ImportOrg.apache.commons.httpclient.SimpleHttpConnectionManager;ImportOrg.apache.commons.httpclient.methods.PostMethod;ImportOrg.apache.commons.httpclient.params.HttpMethodParams;ImportOrg.apache.log4j.Logger; Public class sendsmsutil {String Smsurl ="Http://115.239.133.245:8080/YL_sms/http/sendSMS";/** * Send SMS * * @param URL * @param phone * @param content * @p Aram NetType * @param gwtyep * @return * * PublicStringsendsms(String phone, string content) {Postmethod Postmethod =NULL; HttpClient HttpClient =NULL; String returnvalue =""; String NetType ="1"; String Gwtype ="8";if(ischinatelecom (phone)) {nettype="0"; Gwtype=" the"; }Try{Postmethod =NewPostmethod (Smsurl);//Notification interfacePostmethod.getparams (). Setparameter (Httpmethodparams.http_content_charset,"GBK"); Postmethod.setparameter ("USERID","File"); Postmethod.setparameter ("PASSWORD","123456"); Postmethod.setparameter ("Phoneno", phone); Postmethod.setparameter ("Smstext", content); Postmethod.setparameter ("NETTYPE", NetType); Postmethod.setparameter ("Ecpno", phone); Postmethod.setparameter ("SENDERECP",""); Postmethod.setparameter ("SenderName",""); Postmethod.setparameter ("PR","5"); Postmethod.setparameter ("FLAG","1"); Postmethod.setparameter ("Gwtype", Gwtype); HttpClient =NewHttpClient ();//Set timeout time 10 secondsHttpclient.gethttpconnectionmanager (). Getparams (). Setconnectiontimeout (10000);//Set return timeout 10 secondsHttpclient.gethttpconnectionmanager (). Getparams (). Setsotimeout (10000);intStatusCode = Httpclient.executemethod (Postmethod);if(StatusCode! = HTTPSTATUS.SC_OK) {Log.info ("Channel processing failed:"+ Postmethod.getstatusline ()); ReturnValue ="Fail"; }Else{Log.info ("Call Channel processing interface successful!" "); ReturnValue ="Success"; } }Catch(Exception e) {Log.error ("Send SMS Exception:", e); ReturnValue ="Fail"; }finally{if(Postmethod! =NULL) {postmethod.releaseconnection (); Postmethod =NULL; } ((Simplehttpconnectionmanager) httpClient. Gethttpconnectionmanager ()). Shutdown (); }returnreturnvalue; }/** * Determine if the carrier number * * @param Mobile * @return */ Public Boolean ischinatelecom(String Mobile) {Booleanresult =false;Try{if(Mobile.trim (). StartsWith ("133") || Mobile.trim (). StartsWith ("153") || Mobile.trim (). StartsWith ("189") || Mobile.trim (). StartsWith (" the") {result =true; } }Catch(Exception e) {result =false; Log.error ("Determine if the telco number is abnormal:", e); }returnResult }}
Java Send SMS