首页
导航
博客
电子书
算法
众创
代码
随贴
关于我们
您好,欢迎来到码863代码分享网! 请
[登录]
/
[注册]
搜 索
sms.cn发短信函数短信接口
编辑
注意 $uid = C('mobile_account');//用字符更换 $pwd = C('mobile_password');//用字符更换
代码正文
双击正文可选择全部
1[代码][php]
尝试一下
<?php /*-------------------------------- 功能: HTTP接口 发送短信 修改日期: 2011-03-04 说明: http://api.sms.cn/mt/?uid=用户账号&pwd=MD5位32密码&mobile=号码&mobileids=号码编号&content=内容 官网: ww.sms.cn 状态: sms&stat=101&message=验证失败*/ $res = sendSMS('17097580684','【UUI友爱】您的验证码是{**}感谢您对UUI友爱平台的信任!'); print_r($res); //定时发送 /* $time = '2010-05-27 12:11'; return 正确:1 错误:返回错误信息 */ function sendSMS($mobile,$content,$time='',$mid='',$http='http://api.sms.cn/mt/',$mobileids='')//,$uid='uui888',$pwd='238690') { $uid = C('mobile_account');//用字符更换 $pwd = C('mobile_password');//用字符更换 if(empty($mobileids)){ $mobileids=''.$mobile.sprintf("%.1f",microtime(true)); $mobileids=str_replace('.','',$mobileids); } $data = array ( 'uid'=>$uid, //用户账号 'pwd'=>md5($pwd.$uid), //MD5位32密码,密码和用户名拼接字符 'encode'=>'utf8', 'mobile'=>$mobile, //号码 'content'=>$content, //内容 'mobileids'=>$mobileids, //发送唯一编号 ); //echo json_encode(array('sf'=>0,'nr'=>print_r($data,true)));exit; $re= postSMS($http,$data); //POST方式提交 //$re = getSMS($url,$data=''); //GET方式提交 if( strstr($re,'stat=100')) { return "1"; } else if( strstr($re,'stat=101')) { return "验证失败! 状态:".$re; } else { return "发送失败! 状态:".$re; } } //POST方式 function postSMS($url,$data='') { $post=''; $row = parse_url($url); $host = $row['host']; $port = isset($row['port']) ? $row['port']:80; $file = $row['path']; while (list($k,$v) = each($data)) { $post .= rawurlencode($k)."=".rawurlencode($v)."&"; //转URL标准码 } $post = substr( $post , 0 , -1 ); $len = strlen($post); $fp = @fsockopen( $host ,$port, $errno, $errstr, 10); if (!$fp) { return "$errstr ($errno)\n"; } else { $receive = ''; $out = "POST $file HTTP/1.1\r\n"; $out .= "Host: $host\r\n"; $out .= "Content-type: application/x-www-form-urlencoded\r\n"; $out .= "Connection: Close\r\n"; $out .= "Content-Length: $len\r\n\r\n"; $out .= $post; fwrite($fp, $out); while (!feof($fp)) { $receive .= fgets($fp, 128); } fclose($fp); $receive = explode("\r\n\r\n",$receive); unset($receive[0]); return implode("",$receive); } } //GET方式 function getSMS($url,$data='') { $get=''; while (list($k,$v) = each($data)) { $get .= $k."=".urlencode($v)."&"; //转URL标准码 } return file_get_contents($url.'?'.$get); } /** * 获取随机数 * @param int $length 获取长度 * @param bool $numeric 是纯数字,还是数字加字母 * @return str 随机数串 */ function je_random($length, $numeric = 0) { $seed = base_convert(md5(microtime().$_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35); $seed = $numeric ? (str_replace('0', '', $seed).'012340567890') : ($seed.'zZ'.strtoupper($seed)); $hash = ''; $max = strlen($seed) - 1; for($i = 0; $i < $length; $i++) { $hash .= $seed{mt_rand(0, $max)}; } return $hash; } /** * 是否手机号码 * @param str $phone_number 手机号码 * @return boolean 1是 0否 */ function is_phone_number($phone_number){ if(preg_match("/^1[34578]{1}\d{9}$/",$phone_number)){ return true; }else{ return false; } }
文明上网理性发言,请遵守新闻评论服务协议
0 条评论
发布评论
全部评论
最新
/
最热
暂无评论
加载更多
CopyRight 2002~2023 精通2100网 联系邮箱:qqtxt@163.com
版权所有:精通2100网
湘ICP备2023018646号-1
MYSQl共执行 3 个查询,用时 0.0021300315856934 秒,PHP脚本用时 0.004298 秒,占用内存 0.508 MB,Gzip 已启用