Now, no matter what project is used, if the SMS verification function is used, a limit on the number of times a SMS verification code is designed on the program, which mainly prevents the SMS verification code interface from being brushed.
The previous paragraph happened to be the login function of a user SMS verification code for a project, so I studied the following and posted it below to share it.
The SMS interface involved here uses the third-party SMS interface - Dynamic Thinking Thinking (http://www.lx598.com/). If you want to know about SMS interface access, you can go to their official website and check the SMS interface API documentation description. You should understand it by referring to the code below.
The user registration part, the main code is as follows:
//Main js method: //Get mobile verification code: function getRegCode() { if($.trim($('#inputCaptcha').val()) == ''){ $('#imgRs').html("Graphic 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 your mobile phone number after registration'; $.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">This mobile phone number has been registered</font>'; refreshYzm(); } else { document.getElementById('phoneReInfo').innerHTML = '<font color="green">This mobile phone number is 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] == 'Send successfully!') { canCaptcha = true; document.getElementById('phoneReInfo').innerHTML = '<font color="green">Verification code has been sent, please be careful to check it! </font> accountFID = myArray[1]; }else if(data == 'Restricted Application'){ document.getElementById('phoneReInfo').innerHTML = '<font color="red">A mobile number can only be applied for up to 3 times a day! </font>'; refreshYzm(); }else if(data == 'Verification code error'){ document.getElementById('phoneReInfo').innerHTML = '<font color="red">Verification code error! </font>'; refreshYzm(); } }, error : function() { alert('Exception, internal verification error!'+data); } }); } }, error : function() { alert('Exception, verification error!'); } }); } var smsCount=parseInt($('#smsCount').val()); smsCount=smsCount<3?smsCount+1:3; $('#smsCount').val(smsCount); } // Register a new user// account is user class @Action(value = "reAimcodeGetVeCode") public void reAimcodeGetVeCode() { PrintWriter out; String result = "Verification code application 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 usage status: String verificationCode is not used = 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 the verification code expiration time to 24 hours account.setFREGISTERSOURCE(fromSource);//Set the registration source// Determine whether the mobile phone has obtained the verification code AccountCriteria accountCriteria = new AccountCriteria(); accountCriteria.createCriteria().andACCMOBEqualTo( account.getACCMOB()); List<Account> accs = accountService .selectByExample(accountCriteria); //Number of verification code requests int re = 0; Integer cishu = 0; //If the user does not exist (accs == null || accs.isEmpty()) { cishu = 1; account.setSDKURL("1"); account.setFSECURITYOUTTIME(c.getTime()); //Set the validity time of the verification code 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()); Date date = new Date(); // Determine the number of verification codes by time//If it is a new day, change the number of uses to 1 if (date.getDate() >= ac.getFSECURITYOUTTIME().getDate()) { account.setSDKURL("1"); } else { Integer count = Integer.parseInt(ac.getSDKURL()); account.setSDKURL(count + 1 + "");//If it is not a new day, the number of times +1 } cishu = Integer.parseInt(account.getSDKURL()); account.setFSECURITYOUTTIME(c.getTime()); if (cishu <= 3) re = accountService .updateByPrimaryKeySelective(account); //Save the verification code to send information} 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) { // Send String content here to execute SMS message here = "Your verification code is:" + verifyCode+", the code is valid for 24 hours, the code can only be used once! [SMS Signature]"; SendSmsReply sendSmsReply = smsUnit.sendSms(accName,accPwd ,account.getACCMOB(),content,""); //Calling a third-party interface to send SMS result = sendSmsReply.getReplyMsg() + "&" + acList.get(0).getFID() + "&" + acList.get(0).getSDKURL(); } } else if (cishu > 3) { result = "Restricted Application"; } } } catch (Exception e) { logger.error("Failed to obtain verification code", 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); } } } //This is the reference code for sending SMS functions of the third-party SMS interface of Power Thinking Lexin: /** * Send SMS* @param accName Lexin account username* @param accPwd Lexin account password* @param seed Current time format: YYYYMMDD HHMISS For example: 20130806102030 * @param aimcodes Mobile phone number The English half-width comma is separated between multiple mobile phone numbers* @param content Add signature after the content* @param schTime Time format: 2010-01-01 08:00:00 * @return The result returned by the server: business id or error code*/ public static String sendSms(String accName,String accPwd,String mobies,String content,String schTime){ StringBuffer sb = new StringBuffer("http://sdk.lx198.com/sdk/send2?"); try { String seed=new SimpleDateFormat(dateFormatStr).format(new Date()); sb.append("&accName="+accName); sb.append("&seed="+seed); sb.append("&accPwd="+MD5.getMd5String(MD5.getMd5String(accPwd)+seed)); sb.append("&aimcodes="+mobies); sb.append("&schTime="+URLEncoder.encode(schTime,"UTF-8")); //Encode conversion in space punctuation sb.append("&content="+URLEncoder.encode(content,"UTF-8")); //Encode conversion in Chinese URL url = new URL(sb.toString()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); return in.readLine(); } catch (Exception e) { e.printStackTrace(); } return null; }The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.