zoukankan      html  css  js  c++  java
  • 飞信php接口 web service

    <?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'];
    }

  • 相关阅读:
    4月22日:毕业设计计划
    4月21日:毕业设计计划
    4月11日:毕业设计计划
    4月9日:毕业设计计划
    4月8日:毕业设计计划
    4月2日:毕业设计计划
    4月1日:毕业设计计划
    3月31日:毕业设计计划
    3月30日:毕业设计计划
    3月28日:毕业设计计划
  • 原文地址:https://www.cnblogs.com/blfbuaa/p/6877981.html
Copyright © 2011-2022 走看看