SMS verification code api

Project recently encountered require random SMS verification code to achieve registered users

Choices are the "cloud messenger" because there are 15 free SMS test can verify if the code calls the correct SMS api

address

First, the real-name authentication + SMS templates

After user authentication is completed, create a verification code text message template

 

 Moderated

Second, download the SDK sample document

pull down

MessageLogController.java introduced in the project 

 

 Analysis MessageLogController.java code, you can find that in fact is to send an http request

 

 

We can also write your own java http request. . May request registration page for the phone number and a random number by the asynchronous ajax jsp page, incoming phone number and a random number to be sent to, and then call the jsp java http requests to send

Official SDK:

 

 

The following is a 6-digit codes generated by the file login.jsp ajax request to sedMess.jsp + countdown prompted to resend + verify and validate entered is the same code transmitted

[Reserved global variable generated by the random number codes and user input for the relative ratio]

<script>var number = "";
                function shortMessagraxc() {
                    var xx = document.getElementById("newphone").value;
                    if(xx == ""){
                        alert("请输入手机号码!");
                    }else{
                        var num ="";
                         for(var i = 0;i < 6;i++){
                              num += Math.floor(Math.random()*10);
                         alert(xx+"" Surely);

    
                         }
                         
                        var XMLHTTP = new new the XMLHttpRequest (); 
                        xmlhttp.open ( "POST", "? sedMess.jsp Number The =" + NUM + "& Phone =" + xx, to true ); 
                        xmlhttp.send (); 
                        
                        // modify the global variable 
                        $ .ajax ({ 
                            the async: to false , 
                            Success: function () { 
                                Number = NUM; 
                            } 
                        }) 
                        
                       // Alert (Number); // detecting whether a global variable is modified
                         var COUNT = 10 ;
                         var countdown = setInterval(CountDown, 1000);
                        function CountDown() {
                            $(".btn_yzm").attr("disabled", true);
                            $(".btn_yzm").val("" + count + "s");
                            if (count == 0) {
                                $(".btn_yzm").val("重新获取").removeAttr("disabled");
                                clearInterval(countdown);
                            }
                            count--;
                        } 
                    } 
                    
            
            }; 
            
            Function checkM () {
                 // Alert (Number); // detecting whether a global variable is modified 
                var YXY = document.getElementById ( "yanZM" ) .Value;
                 IF (YXY == null ) { 
                    Alert ( "Please enter the code " );
                     return  to false ; 
                } the else  IF ! (YXY = Number) { 
                    Alert ( " Please enter the correct code " ); 
                    document.getElementById ( " yanZM. ") value =" " ;
                     return  to false ; 
                } the else{
                    return true;
                }
            }
            
</script>

 

Guess you like

Origin www.cnblogs.com/expedition/p/11410002.html