Home >php教程 >php手册 >thinkphp结合云之讯做短信验证码

thinkphp结合云之讯做短信验证码

WBOY
WBOYOriginal
2016-06-07 11:39:221669browse

thinkphp结合云之讯做短信验证码
先去云之讯注册账号 网址http://www.ucpaas.com/

注册云之讯平台账号,即可免费获得10元测试费用测试够用啦

解压附件到 ThinkPHP\Library\Org 文件中
新建方法public function send(){<br>         //初始化必填<br>         $options['accountsid']='******'; //填写自己的<br>         $options['token']='*****'; //填写自己的<br> <br> <br>         //初始化 $options必填<br>         $ucpass = new \Org\Com\Ucpaas($options);<br>                 <br>                 //随机生成6位验证码<br>         srand((double)microtime()*1000000);//create a random number feed.<br>         $ychar="0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";<br>         $list=explode(",",$ychar);<br>         for($i=0;$i         $randnum=rand(0,35); // 10+26;<br>         $authnum.=$list[$randnum];<br>         }<br> <br>         //短信验证码(模板短信),默认以65个汉字(同65个英文)为一条(可容纳字数受您应用名称占用字符影响),超过长度短信平台将会自动分割为多条发送。分割后的多条短信将按照具体占用条数计费。<br>         $appId = "****";  //填写自己的<br>         $to = $_POST['to'];<br>         $templateId = "1";<br>         $param=$authnum;<br> <br> <br>         $arr=$ucpass->templateSMS($appId,$to,$templateId,$param);<br>         if (substr($arr,21,6) == 000000) {<br>             //如果成功就,这里只是测试样式,可根据自己的需求进行调节<br>             echo "短信验证码已发送成功,请注意查收短信";<br>             <br>         }else{<br>             //如果不成功<br>             echo "短信验证码发送失败,请联系客服";<br>             <br>         }<br>         <br> <br>         <br> <br>     }前台页面<form> <br>     <input><br>     <button>获取验证码</button> <br> <br> </form> <br> <br> <br>  <script><br /> $(function(){<br /> $("#submit").click(function(){<br /> var tourl = $("#form").attr("action");<br /> $.post("__URL__/send",{to:$("#to").val()},function(data,textStatus){<br /> alert(data);<br /> });<br /> })<br /> })<br /> </script>测试时只能给注册手机号和添加白名单手机号码发送

附件 Ucpaas.class.rar ( 2.97 KB 下载:635 次 )

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn