Use "Happy letter" SMS Verification Code interface to achieve site user registration

Source: Internet
Author: User

Before reading the following, first understand the next letter SMS Interface Access guide: http://www.lx598.com/jrzn.html.
Next is the need to read the SMS Interface API description document: Http://www.lx598.com/apitext.html.

Here to share with you, the PHP development language, the website access to SMS authentication code interface to achieve user registration SMS verification function.

So also need to read the next letter php SMS Interface Demo (http://www.lx598.com/javaCode.html), in order to better understand the following examples.


First, the front-end:


① Registration Interface Basic information has the following points (direct): Picture verification Code, mobile phone number, password, verification code a few basic information


② on the phone number, whether registered, mobile phone number format is correct

③ Get SMS Verification Code


Second, the front-end registration page code



<div id= "Con2" height:370px; ><table width= "92%" border= "0" align= "center" cellspacing= "0" style= "padding:0px; margin:0px; " ><tbody style= "padding:0px; margin:0px; " > <tr height= "><td class=" Reg_left "> Picture check code </td><td width=" 260px "><input name=" Inputcaptcha "id=" Inputcaptcha "type=" text "size=" 4 "class=" Reg_input "/></td><td><span id=" Imgrs "style=" color:red; " > Click on the image to refresh </span></td></tr><tr><td class= "Reg_left" > Mobile phone number </td><td width= " 260px "><input type=" text "name=" Phonere "id=" Phonere "class=" Reg_input "onchange=" Resetcount () "/><input Type= "hidden" name= "Smscount" id= "Smscount" value= "1"/></td><td class= "reg_xxts" ><span id= " Phonereinfo "></span></td></tr><tr height=" "><td class=" Reg_left "></td> &LT;TD colspan= "2" ><a href= "Javascript:geTregcode (); " class= "Reg_phone" > Free Verification Code </a></td></tr><tr height= "><td class=" Reg_left "> Verification Code &LT;/TD&GT;&LT;TD width= "260px" ><input type= "text" name= "RegNum" id= "RegNum" class= "Reg_input" onblur= " Lostinput () "/></td><td class=" reg_xxts "><span id=" Regnuminfo "></span></td></ Tr><tr height= "><td class=" reg_left "> Password </td><td><input type=" password "name=" Pass2 "id=" Pass2 "class=" Reg_input "maxlength=" "onkeyup=" PwStrength2 (this.value) "onkeydown=" PwStrength2 ( This.value) "/><br/><table width=" "border=" 0 "cellspacing=" 1 "cellpadding=" 1 "bordercolor=" #cccccc " height= "style=" Display:inline "><tr align=" center "bgcolor=" #eeeeee "><td width=" 84px "id=" strength_ L2 "> Weak </td><td width=" 84px "id=" strength_m2 "> </td><td width=" 84px "id=" STRENGTH_H2 "> Strong &LT;/TD&GT;&LT;/TR&GT;&LT;/TABLE&GT;&LT;/TD&GT;&LT;TD class= "reg_xxts" ><span id= "Pass1Info2" &Gt;</span></td></tr><tr height= "><td class=" reg_left "> Confirm password </td><td> <input type= "Password" name= "PassRe2" id= "PassRe2" class= "Reg_input" maxlength= "+" onkeyup= "Regipass (1)" Onkeydown= "Regipass (1)"/></td><td class= "reg_xxts" ><span id= "Pass2info2" ></span></ Td></tr><tr height= "><td>&nbsp;</td><td class=" REG_FWTK "><input type=" CheckBox "Name=" AgreeCheck2 "id=" AgreeCheck2 "checked/> I have read and agree to <ahref=" ${webrootpath}/lxfwtk.html "target=" _blank "> Service terms </a> </td><td class=" REG_FWTK ">&nbsp;</td></tr><tr height=" "><td>&nbsp;</td><td><a href=" # "target=" _self "class=" Reg_sub "onclick=" Registerbyaimcode () "> Register now </a></td><td>&nbsp;</td></tr></tbody></ Table></div>
Threehere is the implementation of picture verification and sending SMSJSCode:



Cell phone number format verification function isphonenum (str) {var reg =/^0? 13[0-9]|15[012356789]|18[012356789]|14[57]|17[0-9]|199) [0-9]{8}$/;return reg.test (str);} Determine if the graphics verification code is filled in correctly var Cancaptcha = False;function Getregcode () {if ($.trim (' #inputCaptcha '). val ()) = = ") {$ (' #imgRs ').  HTML ("Graphics verification code cannot be empty");  $ (' #inputCaptcha '). Select ();  Return }if (!isphonenum ($ (' #phoneRe '). Val ())) {document.getElementById (' Phonereinfo '). InnerHTML = ' <font color= ' red ' > Please fill in a valid 11-digit mobile phone number </font> ';} else {document.getElementById (' Phonereinfo '). InnerHTML = ' Login with mobile number after registration ';//Determine if the mobile number is registered and send the verification code $.ajax ({URL: "${path}/ Account/checkmob ", type:" POST ", Data:" Account. " Accmob= "+ $ (' #phoneRe '). Val (), ContentType:" Application/x-www-form-urlencoded;charset=utf-8 ", async:false,success : function (data) {res = data;if (data = = 1) {document.getElementById (' Phonereinfo '). InnerHTML = ' <font color= ' red ' > The mobile number has been registered </font> '; Refreshyzm ();} else {document.getElementById (' Phonereinfo '). InnerHTML = ' <font color= ' green ' > The phone number available </font>'; $.ajax ({url: "${path}/account/reaimcodegetvecode", type: "POST", Data: "Account. Accmob= "+ $ (' #phoneRe '). Val () +" &fromsource=4&smscount= "+$ (' #smsCount '). Val () +" &searchname= "+$.trim ( $ (' #inputCaptcha '). Val ()), ContentType: "Application/x-www-form-urlencoded;charset=utf-8", Async:false,success: function (data) {MyArray = Data.split ("&"); if (myarray[0] = = ' sent successfully! ') {Cancaptcha = True;document.getelementbyid (' Phonereinfo '). InnerHTML = ' <font color= ' green ' > Verification Code has been sent, please pay attention to check! </font> '; accountfid = myarray[1];} else if (data = = ' Limit request ') {document.getElementById (' Phonereinfo '). InnerHTML = ' <font color= ' red ' > A mobile phone number can be applied up to 3 times a day! </font> '; Refreshyzm ();} else if (data = = ' Authenticode error ') {document.getElementById (' Phonereinfo '). InnerHTML = ' <font color= ' red ' > CAPTCHA Error! </font> '; Refreshyzm ();}},error:function () {alert (' exception, internal validation error! ' +data}});}},error:function () {alert (' exception, validation error! ’);}});} Number of verification code requests VAR Smscount=parseint ($ (' #smsCount '). Val ());smscount=smscount<3?smscount+1:3;$ (' #smsCount '). Val (Smscount);} Reset the number of requests function Resetcount () {$ (' #smsCount '). val (1);} Click Refresh Image Captcha function Refreshyzm () {$ (' #inputCaptcha '). Val ('); $ (' #validImg '). attr (' src ', ' ${path}/sys/logincaptcha ? tm= ' +math.random ());} Password Strength detection function Charmode (in) {if (in >= && in <= 57)//Digital return 1;if (in >= + && in <= 90 )//Capital Letter return 2;if (in >= && in <= 122)//lowercase return 4;elsereturn 8; The special character}//calculates how many modes function bittotal (num) {modes = 0;for (var i = 0; i < 4; i++) {if (num & 1) Modes++;num and Gt;>>= 1;} return modes;} Checkstrong function//return password strength level function Checkstrong (SPW) {if (Spw.length <= 4) return 0;//password Too short modes = 0;for (var i = 0; I & Lt Spw.length; i++) {//test the category of each character and count the number of modes modes |= Charmode (Spw.charcodeat (i));} Return Bittotal (Modes);} Pwstrength function//When the user releases the keyboard or the Password input box loses focus, different color function pwstrength (pwd) {checkpasslong (0) is displayed according to different levels, var o_color = "#eeeeee" var l_color = "#FF0000", var m_color = "#FF9900"; var h_color = "#33CC00"; if (pwd = = NULL | | PWD = = ") {lcolor = Mcolor = Hcolor = O_color;} else {var s_level = Checkstrong (pwd); switch (s_level) {Case 0:lcolor = Mc Olor = Hcolor = O_color;case 1:lcolor = L_color; Mcolor = Hcolor = O_color;break;case 2:lcolor = Mcolor = M_color; Hcolor = O_color;break;default:lcolor = Mcolor = Hcolor = H_color;}} document.getElementById ("strength_l"). Style.background = Lcolor;document.getelementbyid ("Strength_M"). Style.background = Mcolor;document.getelementbyid ("Strength_h"). Style.background = Hcolor;return;} function PwStrength2 (pwd) {Checkpasslong (1), var o_color = "#eeeeee", var l_color = "#FF0000"; var m_color = "#FF9900"; var h_ color = "#33CC00", if (pwd = = NULL | | pwd = = ") {lcolor = Mcolor = Hcolor = O_color;} else {var s_level = Checkstrong (pwd) Switch (s_level) {case 0:lcolor = Mcolor = Hcolor = O_color;case 1:lcolor = L_color; Mcolor = Hcolor = O_color;break;case 2:lcolor = Mcolor = M_color; Hcolor = O_color;break;default:lcolor = Mcolor = Hcolor = H_color;}} document.getElementById("Strength_l2"). Style.background = Lcolor;document.getelementbyid ("strength_m2"). Style.background = Mcolor; document.getElementById ("Strength_h2"). Style.background = Hcolor;return;} function Checkpasslong (flag) {var passstr = $ (' #pass '). Val (); if (flag = = 1) {passstr = $ (' #pass2 '). Val (); PASSSTR = Passstr.replace (/(\s*$)/g, ""); if (passstr.length = = 0 | | Passstr.length < 6) {if (flag = = 0) {document.getElementById (' Pass1info '). InnerHTML = ' <font color= ' red ' > Password length greater than 6 bits, cannot be a space </font> ';} else {document.getElementById (' Pass1info2 '). InnerHTML = ' <font color= ' red ' > Password length greater than 6 bits, cannot be a space </font> ';} return true;} else {if (flag = = 0) {document.getElementById (' Pass1info '). InnerHTML = ' consists of 6-16-bit characters, please use English letters, symbols, or numbers. ’;} else {document.getElementById (' Pass1info2 '). InnerHTML = ' consists of 6-16-bit characters, please use English letters, symbols or numbers. ’;} return false;}} Password strength verification End5, background Action method, account for user class//Register new user @action (value = "Reaimcodegetvecode") public void Reaimcodegetvecode () { PrintWriter out; String result = "Verification code request failed!" Please try again! "; try {smsunit = New Smsunit (Confutil.getproperty ("Sys_sms_server")); if (null! = Account.getaccmob () &&!account.getaccmob (). Equals ("")) {Account.setaccstatus (new BigDecimal (1));//set using state not with String Verifycode = string.valueof (new Random (). Nextint (899999) + 100000);//Generate SMS Verification Code account.setfsecuritycode (Verifycode); Account.setacccreatedate (new Date ()); Calendar C = calendar.getinstance (); C.add (Calendar.day_of_month, 1); Set verification code expiration time is 24 hours account.setfregistersource (fromsource);//Determine if the phone has obtained a verification code accountcriteria Accountcriteria = new Accountcriteria (); Accountcriteria.createcriteria (). Andaccmobequalto (Account.getaccmob ()); List<account> ACCs = accountservice.selectbyexample (accountcriteria); int re = 0;integer Cishu = 0;if (ACCs = = NULL | | Accs.isempty ()) {Cishu = 1;account.setsdkurl ("1"); Account.setfsecurityouttime (C.gettime ()); BigDecimal Accid=accountservice.getprimarykey (); Account.setfid (accid); re = accountservice.insertselective (account , Iputil.getrealip (request)); Cookie Cookie=new Cookie ("id", accid.tOstring ()); Cookie.setmaxage (Integer.max_value); Response.addcookie (cookie);} else {Account AC = accs.get (0), Account.setfid (Ac.getfid ());D ate date = new Date (),//If it is a new day, the number of uses is modified to 1if (date.getdate () = = Ac.getfsecurityouttime (). GetDate ()) {Account.setsdkurl ("1");} else {Integer count = Integer.parseint (Ac.getsdkurl () ); Account.setsdkurl (count + 1 + "");} Cishu = Integer.parseint (Account.getsdkurl ()); Account.setfsecurityouttime (C.gettime ()); if (Cishu <= 3) Re = Accountservice.updatebyprimarykeyselective (account);} if (Re > 0 && cishu <= 3) {request.getsession (). removeattribute (Constvalues.web_session_promote); Accountcriteria ac = new Accountcriteria (); Ac.createcriteria (). Andaccmobequalto (Account.getaccmob ()); list<account> aclist = new arraylist<account> (); aclist = Accountservice.selectbyexample (AC); if (acList! = Null && aclist.size () > 0) {//Here Execute SMS send dateformat DF = new SimpleDateFormat ("Yyyymmddhhmmss"); String Bizid = Df.format (New Date ()); Sendsmsreply sendsmsreply = Smsunit.sendsms ("", "", "Your Verification code is:" + verifycode+ ", the code is valid for 24 hours, the code can only be used once!) "SMS Signature" ", Bizid,account.getaccmob ()," ", 1 +" ", 1 +" "," "," "," "," "," "," "," "," T.get (0). Getfid () + "&" + aclist.get (0). Getsdkurl ();} else if (Cishu > 3) {result = "limit Request";}}} catch (Exception e) {logger.error ("Get Verification Code failed", e);} finally {try {response.setcontenttype ("text/html;charset=utf-8"); Response.setcharacterencoding ("UTF-8"); out = Response.getwriter (); Out.write (result);} catch (IOException e) {logger.error ("", E);}}} Smsunit SMS Send Class Code://Send SMS Public sendsmsreply sendsms (string acname, String acpwdmd5,string smscontent, String batchnumber, String mobiles,string schtime, String serialpkgnumber, String countpkgnum,string sendtype,string pid,string Reno) { HttpPost = new HttpPost ("Www.lx198.com/lxDlsms/sms/sendSms"); list<namevaluepair> formparams = new arraylist<namevaluepair> (); Formparams.add (New BasicNameValuePair (" Sendsms.acname ", acname));//user name FORMPArams.add (New Basicnamevaluepair ("Sendsms.pwd", ACPWDMD5));//Password Formparams.add (new Basicnamevaluepair (" Sendsms.smscontent ", smscontent));//SMS Content Formparams.add (new Basicnamevaluepair (" Sendsms.mobiles ", mobiles));// Phone number Formparams.add (new Basicnamevaluepair ("Sendsms.schtime", Schtime)), Formparams.add (New Basicnamevaluepair (" Sendsms.batchnum ", BatchNumber)); Formparams.add (New Basicnamevaluepair (" Sendsms.pkgnum ", Serialpkgnumber)); Formparams.add (New Basicnamevaluepair ("Sendsms.pkgcount", Countpkgnum)), Formparams.add (New Basicnamevaluepair (" Sendsms.sendtype ", Sendtype)), Formparams.add (New Basicnamevaluepair (" Sendsms.pid ", PID)); Formparams.add (new Basicnamevaluepair ("Sendsms.reno", Reno));//private string reno= ""; try {string replystring = DoPost (formparams); Return (sendsmsreply) xmlreplyunit.fromxml (replystring,new sendsmsreply ());} catch (ParseException e) {logger.error ("", e);} catch (Exception e) {logger.error ("", e);} return null;}

Use "Happy letter" SMS Verification Code interface to achieve site user registration

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.