thinkphp SMS registration

<div class="controls"> 
   <input type="text" id="phone" name="phone" placeholder="Please enter your mobile phone number" class="input-xfat input-xlarge"> <span class 
   = "error"></span> 
</div>

//Define a method to generate verification code

public function sendcode($phone) 
{ 
//Define a random four-digit number 
    $check = rand(1000,9999); 
//Storage verification code 
    cache('code',$check); 
    echo $check; 
    $statusStr = array ( 
        "0" => "SMS message sent successfully", 
        "-1" => "Incomplete parameters", 
        "-2" => "The server space does not support it. Please confirm that it supports curl or fsocket. Contact your space provider to solve or replace it. Space!", 
        "30" => "Wrong password", 
        "40" => "Account does not exist", 
        "41" => "Insufficient balance", 
        "42" => "Account has expired", 
        "43" = > "IP address restriction",
        "50" => "Content contains sensitive words" 
    ); 
    $smsapi = "http://api.smsbao.com/"; 
    $user = "suiyuqi"; //SMS platform account 
    $pass = md5("syq112233") ; //SMS platform password 
    $content="$check";//SMS content to be sent 
    $phone = "$phone"; //Mobile phone number to send text messages to
    $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
    $result =file_get_contents($sendurl) ;
    echo $statusStr[$result];
}

public function doregister()
{
    $user = request()->post();
    $yzm = cache('code');
    if ($user['code'] == $yzm){
        unset($user['code'],$user['repassword']);
        $addRes = Db::name('user')->insert($user); 
   $( '#dyMobileButton').click(function (){
}
    }
        return 'Verification code error';
    }else{
        }
            return 'Registration failed';
        }else{
            return 'Registration successful';
        if ($addRes){




 
<script >
      var phone = $('#phone').val();

      $.ajax({
         url:'sendcode',
         type:'get',
         data:{
            phone:phone
         },
         success:function (res){

         }
      })

   })
</script>

Guess you like

Origin blog.csdn.net/QiZong__BK/article/details/123316234