<?php /** ┃ ┃ code is far away from bug with the animal protecting ┃ ┃ 神兽保佑,代码无bug ┃ ┗━━━┓ ┃ ┣┓ ┃ ┏┛ ┗┓┓┏━┳┓┏┛ ┃┫┫ ┃┫┫ ┗┻┛ ┗┻┛ * @author 邹颢 zouhao619@gmail.com
2014-06-12 */ class Fetion{ private $_url='http://quanapi.sinaapp.com/fetion.php'; private $_username;//发送者 飞信账号 private $_password; //发送者 飞信密码 /** * 发送短信 * @param string $other * @param string $msg */ public function sendMessage($other,$msg){ //因为飞信不能发送带有空格,所以特意用|符号来代替空格 $msg=urlencode($msg); $data['u']=$this->_username; $data['p']=$this->_password; $data['to']=$other; $data['m']=$msg; return $this->_curl_get($this->_url,$data); } /** * curl模拟http get请求 * @param string $url 请求网址 * @param string|array $data 请求参数 * @return string 网址内容 */ private function _curl_get($url,$data=array()){ $url=rtrim($url,'/'); if(!empty($data)){ if(is_array($data)){ $first=true; foreach($data as $k=>$v){ if($first){ $url.='?'; $first=false; }else{ $url.='&'; } $url.="{$k}={$v}"; } }else{ $data=ltrim('?',$data); $url.='?'.$data; } } $ch = curl_init($url); curl_setopt($ch,CURLOPT_HEADER,false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 获取数据返回 if(substr($url,0,5)=='https'){ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); } $content = curl_exec($ch); curl_close($ch); return $content; } public function __set($name,$value){ $this->$name=$value; } } //使用实例 $f=new Fetion(); $f->_username='111';//设置发送飞信者 账户 $f->_password='222'; //设置发送飞信者 密码 $result=$f->sendMessage('333','111'); //发送飞信 333是接收者飞信账户 111是发送内容 $result=json_decode($result,true); if($result['result']===0){//发送成功 echo $result['message']; }else{ echo $result['message']; }
飞信php接口 web service,布布扣,bubuko.com
原文:http://blog.csdn.net/zouhao619/article/details/30229947