leisurely enterprise SMS delivery service, is a relatively simple and easy to operate SMS delivery service, the use of post, the request for the corresponding address can be sent to the message function
1 /// <summary>2 ///SMS Sending service3 /// </summary>4 Public classShortmsghelper5 {6 /// <summary>7 ///SMS Service Account8 /// </summary>9 Private Static stringUID = configurationmanager.appsettings["Shortmsguid"];Ten /// <summary> One ///SMS Service Password A /// </summary> - Private Static stringPWD = configurationmanager.appsettings["shortmsgpwd"]; - /// <summary> the ///Customer Service phone number string - /// </summary> - Private Static stringCustomerservicephonelist = configurationmanager.appsettings["customerservicephonelist"]; - /// <summary> + ///SMS Service signature (this signature will be appended to the SMS content to send success!) The form is: "Signature content") if not added, the sending is invalid - /// </summary> + Private Static stringShortmsgsignature = configurationmanager.appsettings["shortmsgsignature"]; A /// <summary> at ///SMS Service Switch - ///Open: Turn on close: Close - /// </summary> - Private Static stringShortmsgswitch = configurationmanager.appsettings["Shortmsgswitch"]; - - /// <summary> in ///Send SMS Open method - /// </summary> to /// <param name= "msgcontent" ></param> + /// <returns></returns> - Public Static BOOLSend (stringmsgcontent,list<string>pList) the { * //based on the SMS service switch $ if(shortmsgswitch=="Close")Panax Notoginseng { - return false; the } +list<string> phonelist =Newlist<string>(); A if(plist==NULL|| plist.count==0) the { +Phonelist = Customerservicephonelist.split (New Char[] {','}, Stringsplitoptions.removeemptyentries). ToList (); - } $ Else $ { -Phonelist =pList; - } the - returnsendmobilemsg (uid, pwd, msgcontent, phonelist);Wuyi } the /// <summary> - ///Send SMS Wu /// </summary> - /// <param name= "UID" >U-Yat Enterprise SMS ID</param> About /// <param name= "pwd" >U-Yat Enterprise sms password</param> $ /// <param name= "Msgcontent" >SMS Content</param> - /// <param name= "Destlistphones" >Mobile phone Number list</param> - /// <returns></returns> - Private Static BOOLSendmobilemsg (stringUidstringPwdstringMsgcontent, list<string>destlistphones) A { + Try the { - BOOLresult =false; $ stringStrphones =string. Join (";", Destlistphones.toarray ()); theStrphones + =";"; the varencoding = System.Text.Encoding.GetEncoding ("GB2312"); the the stringPostData =string. Format ("uid={0}&pwd={1}&mobile={2};&msg={3}&dtime=", UID, pwd, strphones, Msgcontent +shortmsgsignature); - in byte[] data =encoding. GetBytes (postdata); the the //define WebRequest AboutHttpWebRequest Myrequest = the(HttpWebRequest) WebRequest.Create ("http://www.smsadmin.cn/smsmarketing/wwwroot/api/post_send/"); the theMyrequest.method ="POST"; +Myrequest.contenttype ="application/x-www-form-urlencoded"; -Myrequest.contentlength =data. Length; the BayiStream newstream =Myrequest.getrequeststream (); the the //Send Data -Newstream.write (data,0, data. Length); - newstream.close (); the the //Get Response theHttpWebResponse Myresponse =(HttpWebResponse) myrequest.getresponse (); theStreamReader reader =NewStreamReader (Myresponse.getresponsestream (), encoding.default); - stringContent =Reader. ReadToEnd (); the the if(content. Substring (0,1) =="0") theresult =true;94 Else the { the if(content. Substring (0,1) =="2")//Insufficient Balance the {98 //"Short-message balance of mobile phone"; About //TODO - }101 Else102 {103 //for other reasons why SMS fails, see the official API104 } theresult =false;106 }107 108 returnresult;109 } the Catch111 { the return false;113 } the the } the}
C # Easy-to-use SMS messaging service-e-mail service