本教程织梦短信接口插件代码基于微米短信平台(www.weimi.cc)的一个织梦短信接口。织梦58分享给大家。
具体代码
1、存储验证码到数据库,需要新建建一个数据表。 后台 ---- 系统 ---- sql命令行工具,运行以下代码:(注意表前缀)
| 1 2 3 4 5 6 7 8 9 | DROp TABLE IF EXISTS `dede_sms`; CREATE TABLE `dede_sms` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `phone` varchar(15) NOT NULL DEFAULT '', `code` varchar(8) NOT NULL DEFAULT '', `created_at` int(10) NOT NULL DEFAULT '0', `expire_at` int(10) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; |
2、新建 WMsendSms.PHP 文件,放在 /include 目录下。具体代码如下:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | "0123456789", 2 => "abcdefghijklmnopqrstuvwxyz", 3 => "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 4 => "~@#$%^&*(){}[]|"); if ($type == 0) { array_pop($arr); $string = implode("", $arr); } elseif ($type == "-1") { $string = implode("", $arr); } else { $string = $arr[$type]; } $count = strlen($string) - 1; $code = ''; for ($i = 0; $i < $len; $i++) { $code .= $string[rand(0, $count)]; } return $code; } //保存验证码 function saveCode($phone,$code,$time = 5) { global $dsql; $created_at = time(); $expire_at = time() + ($time * 60); $code = strtolower($code); $sql = "INSERT INTO `dede_sms`(`phone`,`code`,`created_at`,`expire_at`) VALUES ('$phone','$code','$created_at','$expire_at')"; return $dsql->ExecuteNoneQuery($sql); } //检查手机号,验证码 function validateCode($phone,$code) { global $dsql; $code = strtolower($code); $current = time(); $sql = "SELECT `id` FROM `dede_sms` WHERe `phone` LIKE '$phone' AND `code` LIKE '$code' AND `expire_at` > '$current' "; $row = $dsql->GetOne($sql); if(is_array($row)){ return true; }else{ return false; } } //检查是否发送:防止恶意刷短信 //$phone 手机号 www.dede58.com织梦模板下载 //$time 有效时间 (分钟) function validatePremise($phone,$time = '1') { global $dsql; $row = $dsql->GetOne("SELECt `id`,`expire_at` FROM `dede_sms` WHERe `phone` LIKE '$phone' "); if(is_array($row)){ if( time() < $row['expire_at'] ){ return false; }else{ $dsql->ExecuteNoneQuery("DELETe FROM `dede_sms` WHERe id=".$row['id']); } } return true; } |
提示:表的前缀改为你的表前缀,这样就完成了织梦短信接口。



