Nonsense not much to say, directly on the code.
<Divclass= "Form-group has-feedback"> <Divclass= "Input-group"> <inputtype= "text"class= "Form-control input-large"name= "Phone"ID= "Phone"placeholder= "Please enter your phone number"> <spanclass= "Input-group-btn"> <Buttonclass= "Btn btn-info"style=""type= "button"onclick= "SendMessage ()">Send Verification Code</Button> </span> </Div> </Div> <Divclass= "Form-group has-feedback"> <Divclass= "Input-append"> <inputtype= "text"class= "Form-control span2"placeholder= "Verification Code"name= "Code"onfocus= "Checkphone ()" /> <spanclass= "Add-on"ID= "MSG"></span> </Div> </Div>
varIntervalobj;//timer variable, control time varCount = 60;//interval function, 1 second execution varCurcount;//current number of seconds remaining varCode = "";//Verification Code varCodelength = 6;//Verification Code Length functionSendMessage () {if(Checkinput ()) {Curcount=count; for(vari = 0; i < codelength; i++) {Code+ = parseint (Math.random () * 9). toString (); } //Set button effect to start timing$ ("#btnSendCode"). attr ("Disabled", "true"); $("#btnSendCode"). Val ("Please enter the verification code in" + Curcount + "seconds)); Intervalobj= Window.setinterval (setremaintime, 1000);//start Timer, execute once in 1 seconds //send processing data to the background varPostData ={code:code, Phone: $ ("#phone"). Val ()} $.ajax ({type:"POST",//transfer by postDataType: "Text",//data format: JSONURL: '/account/yanzheng ',//Destination Addressdata:postdata, Error:function(XMLHttpRequest, Textstatus, Errorthrown) {}, Success:function(msg) {if(msg = = "0") {layer.msg ("Verification code sent successfully!" "); } Else if(msg = = "-1") {layer.msg ("Verification code failed to send!" "); Window.clearinterval (intervalobj);//Stop Timer$ ("#btnSendCode"). Removeattr ("Disabled");//Enable button$ ("#btnSendCode"). Val ("Resend Verification Code")); Code= "";//clear the verification code. If you do not clear, after the time, the input received the verification code is still valid } } }); } } //Timer handler function functionSetremaintime () {if(Curcount = = 0) {window.clearinterval (intervalobj);//Stop Timer$ ("#btnSendCode"). Removeattr ("Disabled");//Enable button$ ("#btnSendCode"). Val ("Resend Verification Code")); Code= "";//clear the verification code. If you do not clear, after the time, the input received the verification code is still valid}Else{Curcount--; $("#btnSendCode"). Val ("Please enter the verification code in" + Curcount + "seconds)); } }
PublicActionResult Yanzheng () {stringPhone = request["Phone"]; stringCode = request["Code"]; StringBuilder SMS=NewStringBuilder (); Sms. AppendFormat ("name={0}","");//User AccountSms. AppendFormat ("&pwd={0}","");//Landing Platform, Management center-basic Information-Interface password (28-bit ciphertext), copy and use. Sms. AppendFormat ("&content={0}","Hello, thank you for logging in, you get the verification code is:"+ Code);//Send contentSms. AppendFormat ("&mobile={0}", Phone);//Mobile phone Number (multiple use, separate)Sms. AppendFormat ("&sign={0}","");//the abbreviation of the company or the abbreviation of the product can be (user signature: can be omitted)Sms. Append ("&type=pt"); stringRESP = pc. Pushtoweb ("http://.com/asmx/smsservice.aspx", SMS. ToString (), Encoding.UTF8); string[] msg = resp. Split (','); if(msg[0] =="0") {session["Phonecode"] =Code; //return Content ("Submit success: Sendid=" + msg[1]); returnContent ("0"); } Else { //return Content ("Commit failed: Error message =" + msg[1]); returnContent ("-1"); } }
---------------------------------------------------------------------------------------------------------
Reprint please remember the author and source Oh-.-
Kingdudu
Original source: http://www.cnblogs.com/kingdudu/p/4946878.html
---------------------------------------------------------------------------------------------------------
"18th" mobile phone verification Code