在微信中实现app软件中账号注册的功能实现
利用写好的接口url地址访问
输入手机号,接收手机验证码
<span class="accept" >点击获取验证码</span> $(".accept").click(function(){ var s=$("#tellphone").val(); var patrn=/^1[3|4|5|8][0-9]\d{4,8}$/; ------------正则验证手机号码的合法性-------------------- if(!patrn.test(s)){ alert("请输入正确的手机号!"); }else{ $.post("api/accept.php",{"mobile":s},function(data){ if(data["res_code"]==0){ alert('您的手机号可以使用,请等待验证码发送'); }else{ alert('您的手机号已经被注册或者您输入的手机号有误'); } },"JSON"); } });
PHP中curl函数实现不跨域访问url地址
<?php function curl_post( $url='',$postdata='',$options=array()){ $ch=curl_init($url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); if(!empty($options)){ curl_setopt_array($ch, $options); } $data=curl_exec($ch); curl_close($ch); return $data; } $mobile=$_POST['mobile']; $arr=curl_post("http://test.tjnit.com/SpecialApp/register.php?m=home&c=Juhe&a=SendMsg","mobile=$mobile"); echo $arr; ?>
验证码输入以后实现验证功能
<button type="submit" class="sub" >确认</button> ajax请求调用 $(".sub").click(function(){ var m=$("#tellphone").val(); var c=$("#code").val(); $.post("api/submit.php",{"mobile":m,"code":c},function(data){ if(data["res_code"]==0){ window.location.href="password.php"+m; ---------------js跳转到php页面get方法传值-------------------------- }else{ alert("您的验证码输入有误,请重新输入"); } },"JSON"); });
PHP中curl函数实现不跨域访问url地址
<?php function curl_post( $url='',$postdata='',$options=array()){ $ch=curl_init($url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); if(!empty($options)){ curl_setopt_array($ch, $options); } $data=curl_exec($ch); curl_close($ch); return $data; } $mobile=$_POST['mobile']; $code=$_POST['code']; $arr=curl_post("http://test.tjnit.com/SpecialApp/register.php?m=home&c=Register&a=register","mobile=$mobile&&code=$code"); echo $arr; ?>
设置密码的实现
password.php页面
<?php $mobile=$_GET['mobile']; -------------注意$_GET[]方法接收传过来的值------------------------- ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>设置密码</title> <meta http-equiv="Cache-Control" content="no-transform"> <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/> <link href="static/css/bootstrap.min.css" rel="stylesheet"> <link href="static/css/password.css" rel="stylesheet"> <script src="static/js/jquery.js"></script> <script src="static/js/bootstrap.min.js"></script> </head> <body> <div class="bg"> <div class="content"> <div class="form-horizontal" > <div class="form-group"> <label class="col-xs-2 control-label">手机号</label> <div class="col-xs-10"> <div class="form-control" id="tellphone"><strong><?php echo $mobile ?></strong></div> -----php中echo输出传过来的值------- </div> </div> <div class="form-group"> <label for="inputPassword" class="col-xs-2 control-label">密码</label> <div class="col-xs-10"> <input type="password" class="form-control" id="password" name="password" placeholder="请输入密码(不少于6位)"> </div> </div> <div class="form-group"> <label for="inputPassword" class="col-xs-2 control-label">密码</label> <div class="col-xs-10"> <input type="password" class="form-control" id="password1" name="password1" placeholder="请再次输入密码"> </div> </div> <button type="submit" class="btn btn-success" id="tijiao">提交</button> </div> </div> </div> </body>
<script> $("#tijiao").click(function(){ var a=$("#password").val(); var b=$("#password1").val(); var c=$("#tellphone").text(); -------------------jquery中非表单元素的取值(省去了html代码<strong><strong>)----------------------if(a.length<6){ alert("您输入的密码不符合要求"); }else{ if(a==b){ $.post("api/password.php",{"mobile":c,"password":a},function(data){ if(data['res_code']==0){ alert("注册成功"); window.location.href="produce.html"; }else{ alert("注册失败,您的手机已被注册或者请检测您的手机号码是否有误"); window.location.href=window.location.href; } },"JSON"); }else{ alert("两次输入的密码不一致,请重新输入"); } } }); </script>
PHP中curl函数实现不跨域访问url地址
<?php function curl_post( $url='',$postdata='',$options=array()){ $ch=curl_init($url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); if(!empty($options)){ curl_setopt_array($ch, $options); } $data=curl_exec($ch); curl_close($ch); return $data; } $mobile=$_POST['mobile']; $password=$_POST['password']; $arr=curl_post("http://test.tjnit.com/SpecialApp/register.php?m=home&c=Register&a=inputPassword","mobile=$mobile&&password=$password"); echo $arr; ?>