国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php實現的IMEI限制的短信驗證碼發送類

2024-05-04 23:34:53
字體:
來源:轉載
供稿:網友

本文給大家分享的是可以檢驗手機號碼與IMEI的短信驗證碼發送的php類,十分的實用,這里推薦給大家,有需要的小伙伴可以參考下。

php實現的IMEI限制的短信驗證碼發送類

 

 
  1. <?php 
  2. class Api_Sms{ 
  3. const EXPIRE_SEC = 1800; // 過期時間間隔 
  4. const RESEND_SEC = 60; // 重發時間間隔 
  5. const ONE_DAY_FREQ = 5; // 每日向同一個手機號發短信的次數 
  6. const ONE_DAY_IMEI_COUNT = 3; // 每日向同一個手機號發送短信的IMEI個數 
  7.  
  8. public $error = array(); 
  9.  
  10.  
  11. /** 
  12. * 向指定手機號發送驗證碼 
  13. * @param $mobile 
  14. * @param $imei 
  15. * @return bool 
  16. */ 
  17. public function sendVerifyCode($mobile$imei) { 
  18. if(!$this->isMobile($mobile)) { 
  19. $this->error = array('code' => -1, 'msg' => '這個手機號很奇葩哦,請正確輸入后重試'); 
  20. return false; 
  21.  
  22. $redis = Api_Common::redis(); 
  23. $vcKey = 'VC_'.$mobile
  24. $limitKey = 'VC_LIMIT_'.$mobile
  25.  
  26. // 驗證碼重發限制 
  27. $data = json_decode($redis->get($vcKey), true); 
  28. if($data && time() < $data['resend_expire']) { 
  29. $this->error = array('code' => -1, 'msg' => '短信已在1分鐘內發出,請耐心等待'); 
  30. return false; 
  31.  
  32. // 手機號及IMEI限制 
  33. $sendCnt = $redis->zScore($limitKey$imei); 
  34. if($sendCnt && $sendCnt >= self::ONE_DAY_FREQ) { 
  35. $this->error = array('code' => -1, 'msg' => '沒收到短信?請稍等或檢查短信是否被屏蔽'); 
  36. return false; 
  37. $imeiCnt = $redis->zCard($limitKey); 
  38. if($imeiCnt >= self::ONE_DAY_IMEI_COUNT && !$sendCnt) { 
  39. $this->error = array('code' => -1, 'msg' => '已超過驗證碼發送設備限制'); 
  40. return false; 
  41.  
  42. // 獲取驗證碼 
  43. if(!$data) { 
  44. $vc = strval(rand(100000, 999999)); 
  45. $data = array('vc' => $vc'resend_expire' => 0); 
  46. $redis->set($vcKey, json_encode($data)); 
  47. $redis->expire($vcKey, self::EXPIRE_SEC); // 設置驗證碼過期時間 
  48. $vc = $data['vc']; 
  49.  
  50. $content = '安全驗證碼:'.$vc
  51. $result = $this->send($mobile$content); 
  52. if($result) { 
  53. // 重設重發時限 
  54. $data['resend_expire'] = time() + self::RESEND_SEC; 
  55. $ttl = $redis->ttl($vcKey); 
  56. $redis->set($vcKey, json_encode($data)); 
  57. $redis->expire($vcKey$ttl); 
  58.  
  59. // 設置手機號與IMEI限制 
  60. $redis->zIncrBy($limitKey, 1, $imei); 
  61. $redis->expireAt($limitKeystrtotime(date('Y-m-d',strtotime('+1 day')))); 
  62. return $result
  63.  
  64. /** 
  65. * 向指定手機號發送短信 
  66. * @param $mobile 
  67. * @param $content 
  68. * @return bool 
  69. */ 
  70. public function send($mobile$content){ 
  71. // TODO 調用具體服務商API 
  72. return true; 
  73.  
  74. /** 
  75. * 判斷是否為合法手機號 
  76. * @param $mobile 
  77. * @return bool 
  78. */ 
  79. private function isMobile($mobile) { 
  80. if(preg_match('/^1/d{10}$/'$mobile)) 
  81. return true; 
  82. return false; 
  83.  
  84. /** 
  85. * 驗證短信驗證碼 
  86. * @param $mobile 
  87. * @param $vc 
  88. * @return bool 
  89. */ 
  90. public function checkVerifyCode($mobile$vc) { 
  91. $vcKey = 'VC_'.$mobile
  92. $vcData = json_decode(Api_Common::redis()->get($vcKey), true); 
  93. if($vcData && $vcData['vc'] === $vc) { 
  94. return true; 
  95. return false; 
  96.  
  97. /** 
  98. * 清除驗證碼 
  99. * @param $mobile 
  100. */ 
  101. public function cleanVerifyCode($mobile) { 
  102. $redis = Api_Common::redis(); 
  103. $vcKey = 'VC_'.$mobile
  104. $limitKey = 'VC_LIMIT_'.$mobile
  105. $redis->del($vcKey); 
  106. $redis->del($limitKey); 

另付其他網友實現的短信驗證碼代碼

 

 
  1. <? 
  2. /*-------------------------------- 
  3. 功能: 中國短信網PHP HTTP接口 發送短信 
  4. 修改日期: 2009-04-08 
  5. 說明: http://http.c123.com/tx/?uid=用戶賬號&pwd=MD5位32密碼&mobile=號碼&content=內容 
  6. 狀態: 
  7. 100 發送成功 
  8. 101 驗證失敗 
  9. 102 短信不足 
  10. 103 操作失敗 
  11. 104 非法字符 
  12. 105 內容過多 
  13. 106 號碼過多 
  14. 107 頻率過快 
  15. 108 號碼內容空 
  16. 109 賬號凍結 
  17. 110 禁止頻繁單條發送 
  18. 111 系統暫定發送 
  19. 112 號碼不正確 
  20. 120 系統升級 
  21. --------------------------------*/ 
  22. $uid = '9999'//用戶賬號 
  23. $pwd = '9999'//密碼 
  24. $mobile = '13912341234,13312341234,13512341234,02122334444'//號碼 
  25. $content = '中國短信網PHP HTTP接口'//內容 
  26. //即時發送 
  27. $res = sendSMS($uid,$pwd,$mobile,$content); 
  28. echo $res
  29.  
  30. //定時發送 
  31. /* 
  32. $time = '2010-05-27 12:11'; 
  33. $res = sendSMS($uid,$pwd,$mobile,$content,$time); 
  34. echo $res; 
  35. */ 
  36. function sendSMS($uid,$pwd,$mobile,$content,$time='',$mid=''
  37. $http = 'http://http.c123.com/tx/'
  38. $data = array 
  39. 'uid'=>$uid//用戶賬號 
  40. 'pwd'=>strtolower(md5($pwd)), //MD5位32密碼 
  41. 'mobile'=>$mobile//號碼 
  42. 'content'=>$content//內容 
  43. 'time'=>$time//定時發送 
  44. 'mid'=>$mid //子擴展號 
  45. ); 
  46. $re= postSMS($http,$data); //POST方式提交 
  47. if( trim($re) == '100' ) 
  48. return "發送成功!"
  49. else 
  50. return "發送失敗! 狀態:".$re
  51.  
  52. function postSMS($url,$data=''
  53. $row = parse_url($url); 
  54. $host = $row['host']; 
  55. $port = $row['port'] ? $row['port']:80; 
  56. $file = $row['path']; 
  57. while (list($k,$v) = each($data))  
  58. $post .= rawurlencode($k)."=".rawurlencode($v)."&"//轉URL標準碼 
  59. $post = substr$post , 0 , -1 ); 
  60. $len = strlen($post); 
  61. $fp = @fsockopen$host ,$port$errno$errstr, 10); 
  62. if (!$fp) { 
  63. return "$errstr ($errno)/n"
  64. else { 
  65. $receive = ''
  66. $out = "POST $file HTTP/1.1/r/n"
  67. $out .= "Host: $host/r/n"
  68. $out .= "Content-type: application/x-www-form-urlencoded/r/n"
  69. $out .= "Connection: Close/r/n"
  70. $out .= "Content-Length: $len/r/n/r/n"
  71. $out .= $post;  
  72. fwrite($fp$out); 
  73. while (!feof($fp)) { 
  74. $receive .= fgets($fp, 128); 
  75. fclose($fp); 
  76. $receive = explode("/r/n/r/n",$receive); 
  77. unset($receive[0]); 
  78. return implode("",$receive); 
  79. ?> 

以上所述就是本文的全部內容了,希望大家能夠喜歡。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 江西省| 来宾市| 金昌市| 建水县| 平凉市| 胶州市| 仙桃市| 鄂托克前旗| 射阳县| 嫩江县| 吴忠市| 即墨市| 揭阳市| 修水县| 丹巴县| 兴城市| 依兰县| 福建省| 福清市| 固安县| 乌恰县| 鞍山市| 新田县| 昆山市| 常德市| 武乡县| 廉江市| 墨脱县| 辽中县| 安达市| 和顺县| 牙克石市| 修武县| 苗栗县| 井冈山市| 连江县| 卓尼县| 延津县| 灵寿县| 政和县| 龙山县|