sms.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * 发送短信验证码
  4. * @author yuanjiang 932625974#qq.com
  5. * @date 9.16.2012
  6. */
  7. define('IN_T',true);
  8. require './source/include/init.php';
  9. $act_legal = array(
  10. 'reg' => '注册新用户',
  11. 'find' => '找回密码',
  12. );
  13. $act = Common::sfilter($_REQUEST['act']);
  14. $re['status'] = 0;
  15. //非法请求
  16. if(!in_array($act,array_keys($act_legal))){
  17. $re['msg'] = '非法请求';
  18. }
  19. else{
  20. if($act=='reg' || $act=='find'){
  21. $phone = Common::sfilter($_REQUEST['phone']);
  22. }
  23. //不是注册和找回密码时,自动提取手机号
  24. else{
  25. $phone = $Db->query("select phone from ".$Base->table('user')." where id = ".$user['pk_user_main']."","One");
  26. }
  27. //图片验证码
  28. $captcha = Common::sfilter($_REQUEST['captcha']);
  29. if($_SESSION['captcha'][$act]!=md5(strtolower($captcha))){
  30. $re['msg'] = '请先输入正确的图片验证码';
  31. }
  32. else if(!Common::is_mobile($phone)){
  33. $re['msg'] = '请输入正确的手机号';
  34. }
  35. //1个手机号60秒内只能发送一次
  36. else if($_SESSION['sms'][$act]['phone']==$phone && Common::gmtime() - $_SESSION['sms'][$act]['send_time'] < 60){
  37. $re['msg'] = '1个手机号1分钟内只能发送1次验证码';
  38. }
  39. else{
  40. $sms_captcha = Common::get_rand_number();
  41. //云通讯发送短信
  42. if($_lang['global_sms']=='yuntongxun'){
  43. require './source/include/cls_sms.php';
  44. $Sms_yuntongxun = new Sms_yuntongxun($_lang['yuntongxun_config']['accountSid'],$_lang['yuntongxun_config']['accountToken'],$_lang['yuntongxun_config']['appId'],$_lang['yuntongxun_config']['templateId']);
  45. $Sms_yuntongxun->sendMsg($phone,array($sms_captcha,$act_legal[$act],15),$_lang['yuntongxun_config']['templateid']);
  46. }
  47. //阿里大鱼发送短信
  48. if($_lang['global_sms']=='alidayu'){
  49. require './source/alidayu/TopSdk.php';
  50. sendSMS($_lang['alidayu_config']['appkey'],$_lang['alidayu_config']['secretkey'],$_lang['alidayu_config']['freesignname'],$_lang['alidayu_config']['templatecode'],$phone,$sms_captcha);
  51. }
  52. $_SESSION['sms'][$act]['send_time'] = Common::gmtime();
  53. $_SESSION['sms'][$act]['phone'] = $phone;
  54. $_SESSION['sms'][$act]['captcha'] = Common::encrypt($sms_captcha);
  55. $re['status'] = 1;
  56. }
  57. }
  58. echo $Json->encode($re);
  59. exit;
  60. ?>