嗯哼,做为一个好的程序猿,一定要给顾客爸爸剁手的时候,充分的告诉他,你剁完手了,所以不只有邮件通知还要有手机短信的通知,今天就来写一下php发送验证码

1、首先我就写了几个个方法,因为配置在后台,直接取就好了,有的需要表单提交过来,只需要接收一下,把对应的值写一下就好了,这个函数或许麻烦一点,但是仔细看,不麻烦的

get_captcha()函数,直接访问,就能发送验证码

//发送验证码
function get_captcha1(){
$phone="";
if(!preg_match("/^1[3456789]{1}\d{9}$/",$phone)){
exit("手机号格式不正确");
}
if(time()-$_SESSION['last_send_time']<){
exit("短信发送太频繁了!");
}
if($phone ){
$r = rand(,);
$content = '本次验证码为:'.$r.",十分钟内有效.【新华好房】";
$rs = sendSms($phone,$content);//调用函数sendSms()
if($rs==true){
$_SESSION['last_send_time'] = time();//将时间存进session
echo 'ok';exit("");
}
}
}
sendSms()函数
function sendSms($mobile,$msg){
if(!$mobile && !$msg){
return false;
}
$post="action=send&userid=376&account=zyjtz&password=kk123321yy&mobile=$mobile&content=$msg&sendTime=&extno=";
  //组成链接,把对应的userid和account写对,其实不同的短信接口有不同的方式,有的话根据供应商给的接口来写
$xml=http_post('http://115.29.242.32:8888/sms.aspx', $post);//调用http_post()函数
$res = @simplexml_load_string($xml,NULL,LIBXML_NOCDATA);
$res = json_decode(json_encode($res),true);
if($res['returnstatus']=='Success'){
return true;
}
return false;
//print_test($res);
}
http_post()函数
function http_post($url, $post = '', $timeout = , $times = ) {
$stream = stream_context_create(array('http' => array('header' => 'Content-type: application/x-www-form-urlencoded', 'method' => 'POST', 'content' => $post, 'timeout' => $timeout)));
while($times-- > ) {
$s = file_get_contents($url, NULL, $stream, , );
if($s !== FALSE) return $s;
}
return FALSE;
}
 先到这里,我们今天下班了,劳动节快乐,回来如果我还能记得,写的详细一点,这样只能发送验证码,里面很多东西没加,比如不能多次发送,防止注册机注册等,所以呢,回来再更新。
 

 

最新文章

  1. Sql Server之旅——第七站 为什么都说状态少的字段不能建索引
  2. 值得订阅的Android 开发者博客
  3. 【无聊放个模板系列】HDU 3068 MANACHER
  4. 关于 RecastNavigation 寻路结果异常的问题。
  5. libevent使用之安装(一)
  6. C/C++语言学习——内存分配管理
  7. hunnu11543:小明的烦恼——分糖果
  8. CAN总线基础
  9. [tableView dequeueReusableCellWithIdentifier:CellIdentifier] 后面forIndexPath:indexPath参数的解释
  10. [LeetCode] Serialize and Deserialize N-ary Tree N叉搜索树的序列化和去序列化
  11. 【leetcode】427. Construct Quad Tree
  12. 关于js中的时间——计算时间差等
  13. 22.纯 CSS 创作出美丽的彩虹条纹文字
  14. Jmeter JDBC的使用
  15. 接收一条音频(系统音频)彩信,点菜单键选择View slideshow,不能播放,提示是否导入vCard
  16. (1)I/O流 (2)线程
  17. php之快速入门学习-5(常量)
  18. 随机数Math.random()公式
  19. Python学习---面向对象的学习[深入]
  20. SaltStack自动化安装zabbix-server

热门文章

  1. memcached和redis对比
  2. WPF MVVM 键盘按键事件绑定
  3. webrtc vp8与h264 sdp文件解读
  4. mssql 数据库 基本知识
  5. rancher布控集群启动失败
  6. maven web报错:org.apache.jasper.JasperException: Unable to compile class for JSP
  7. Educational Codeforces Round 82 (Rated for Div. 2)D(模拟)
  8. Pandas数据结构(一)——Pandas Series
  9. mediasoup-demo安装记录
  10. C++ split分割字符串函数