First we need to go here http://sms.webchinese.cn/apply for an account and SMS interface key, there are many languages under the demo introduction, below I mainly for everyone to paste a C # helper class:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Security.Cryptography;usingSystem.Text;usingSystem.Net;usingSystem.IO;namespacestudyprogram.leiku{ Public classMessagehelper {Private stringURL =@"http://utf8.api.smschinese.cn/"; Private stringUserID =""; Private stringKey ="";//secret key Private stringSmsmob; Private stringSmstext; /// <summary> ///with parameter constructors/// </summary> /// <param name= "isMD5" >whether MD5 encryption is required</param> /// <param name= "userid" >user name of the application</param> /// <param name= "key" >the secret key for the application</param> /// <param name= "mob" >Send the phone (multiple need to ', ' Connect)</param> /// <param name= "text" >Information Content (note the signature format "XX net")</param> PublicMessagehelper (BOOLIsMD5,stringUseridstringKeystringMobstringtext) { This. UserID ="/? Uid="+userid; This. Key = IsMD5?"&keymd5="+ GETMD5STR (Key):"&key="+key; This. Smsmob ="&smsmob="+Mob; This. Smstext ="&smstext="+text; } //MD5 Encryption Private stringGETMD5STR (stringstr) {MD5 MD5=NewMD5CryptoServiceProvider (); StringBuilder Sbstr=NewStringBuilder (); byte[] buffer =Encoding.Default.GetBytes (str); byte[] Databuff = md5.computehash (buffer);//computes the hash value of the specified character array foreach(byteDinchdatabuff) sbstr.append (d.tostring ("X2")); return(Sbstr +""). ToUpper (); } Private stringGetResponse () {varTargetUrl = URL + userid + key + Smsmob +Smstext; varres =""; Try{HttpWebRequest hr=(HttpWebRequest) webrequest.create (TargetUrl); hr. Method="GET"; hr. Timeout= -* -* +;//30 minutes TimeoutWebResponse HS =HR. GetResponse (); Stream SR=HS. GetResponseStream (); StreamReader ser=NewStreamReader (SR, Encoding.default); Res=ser. ReadToEnd (); } Catch(Exception ex) {res=Ex. Message; Throwex; } returnRes; } Private enumResult {No user account= -1, the interface key is incorrect= -2, the MD5 interface key is not encrypted correctly= - +, the number of SMS is insufficient= -3, the user is disabled= - One, text message content appears illegal characters= - -, the phone number is not formatted correctly= -4, the phone number is empty= - A, SMS content is empty= - the, the SMS signature format is incorrect= -Wuyi, IP restrictions= -6 } Public stringGetsendstr () {varres =""; varResponse =GetResponse (); if(Response! ="") { inttemp; if(Int32.TryParse (Response, outtemp)) { if(Temp >0) Res=string. Format ("{0} message sent successfully", temp); ElseRes= Enum.getname (typeof(Result), temp); } Elseres ="Send failed:"+response; } Elseres ="Send failed"; returnRes; } }}
Call Method:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceshortmessage{classProgram {Static voidMain (string[] args) {StudyProgram.LeiKu.MessageHelper MSH=NewStudyProgram.LeiKu.MessageHelper (true,"apply for User name","the secret key for the application","1234567890","Verification Code: Invincible "Brother Wah""); varres =MSH. Getsendstr (); Console.WriteLine (RES); Console.ReadLine (); } }}
C # Call SMS SMS interface, easy to handle the task of sending SMS ....