php 发送手机短信
来源:互联网 发布:一起团购网软件 编辑:程序博客网 时间:2024/05/07 09:01
原理:使用别的提过的接口发送手机短信
第一步. 在http://www.ihuyi.com/申请一个账号密码
第二步, 上代码
<?phpclass NMobile{private $_user;private $_pwd;private $_type;private $_url = "http://106.ihuyi.cn/webservice/sms.php?method=Submit";/*** 初始化用户密码* @access public* @param string $user 用户名* @param string $pwd 密码* @param int $type 0:post ,非0:get*/public function __construct($user, $pwd, $type = 0){$this->_user = $user;$this->_pwd = $pwd;$this->_type = $type;}/*** 说明及描述* @access public* @param int $mobile 手机号码* @param string,int $msg 消息 跟模板对应* @return string 操作结果*/public function send($mobile, $msg){if(!function_exists('curl_init')){return '请先开启curl扩展';}$url = $this->_url;$mobile = ceil($mobile);$user = $this->_user;$pwd = $this->_pwd;$curl = curl_init();curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);curl_setopt($curl, CURLOPT_HEADER, false);$data = "account={$user}&password={$pwd}&mobile=".$mobile."&content=".rawurlencode("您的验证码是:".$msg."。请不要把验证码泄露给其他人。");;//--------------post方式---if(!$this->_type){curl_setopt($curl, CURLOPT_NOBODY, true);curl_setopt($curl, CURLOPT_POST, true);curl_setopt($curl, CURLOPT_POSTFIELDS, $data);}else{ //---------get方式$url .= '&'.$data;}curl_setopt($curl, CURLOPT_URL, $url);$xml = curl_exec($curl);curl_close($curl);var_dump($xml);$result = $this->xml_to_array($xml);return $result['SubmitResult']['msg'];}/*** 官方xml解析* @access public* @param string $xml xml数据* @return string 结果*/private function xml_to_array($xml){$reg = "/<(\w+)[^>]*>([\\x00-\\xFF]*)<\\/\\1>/";if(preg_match_all($reg, $xml, $matches)){$count = count($matches[0]);for($i = 0; $i < $count; $i++){$subxml= $matches[2][$i];$key = $matches[1][$i];if(preg_match( $reg, $subxml )){$arr[$key] = $this->xml_to_array( $subxml );}else{$arr[$key] = $subxml;}}}return $arr;}}header('Content-type:text/html; charset=utf-8');$obj = new NMobile('你的账号', '你的密码'); //设置网站账户密码echo $obj->send(13004868899, 1000, 1);//发送消息?>
0 0
- php 发送手机短信
- 用php发送手机短信
- php 发送手机短信
- php手机短信接口发送验证码
- php手机短信接口发送验证码类
- 手机短信发送
- 通过ICQ网关发送手机短信的PHP源程序
- 通过PC发送手机短信
- 使用J2ME发送手机短信
- C#发送手机短信
- 通过at发送手机短信
- 超级终端发送手机短信
- 简单手机短信发送软件
- 手机短信发送简单讲义
- JAVA发送手机短信
- java发送手机短信
- JAVA发送手机短信
- java发送手机短信
- Android 高级UI
- JavaScript中json对象和string对象之间相互转化
- 基于SSD的数据库性能优化
- apktool基本命令
- 本地安装magento1.9 后台无法登陆问题解决
- php 发送手机短信
- Linux内核源代码分析——fork()原理&多进程网络模型
- CPU特权环ring
- ios 嵌套json解析
- JAVA中的静态类
- 二叉树的非递归遍历
- 如何取得Spring管理的bean
- POJ 1236 Network of School(强联通缩点)
- ecpilse中properties文件中文乱码问题,ASCII码