| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 | 
							- <?php
 
- /* 
 
-  * Desc : Action base class
 
-  * 
 
-  * Author: xuchang.zhang
 
-  */
 
- class BaseAction{
 
- 	
 
- 	
 
- 	public function __construct(){}
 
- 	
 
- 	protected function getDbEntity(){
 
- 		
 
- 		global  $_ONU_CONFIG;
 
- 		$db = new MysqlHandler($_ONU_CONFIG['_db_conf']);
 
- 		return $db;
 
- 	}
 
- 	
 
- 	public static function getResponse($status,$value){
 
- 		$rsp = array();
 
- 		if($status==0){
 
- 			$rsp['status']='ok';
 
- 			$rsp['val']=$value;
 
- 	
 
- 		}else{
 
- 			$rsp['status']= 'fail';
 
- 			$rsp['err_code']= $status;
 
- 			$rsp['err_msg']   = $value;
 
- 		}
 
- 		
 
- 		$jsonRes = json_encode($rsp);
 
- 		$cbPara  = $_REQUEST['callback'];
 
- 		
 
- 		if(!empty($cbPara)){
 
- 			return  "$cbPara($jsonRes)";
 
- 		}
 
- 		else{
 
- 			return $jsonRes;
 
- 		}
 
- 	}
 
- 	
 
- 	public static function makeRequest($url, $params,$timeout=3,$post=true) {
 
- 	    $ch = curl_init();
 
- 	    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 
- 	    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));
 
- 	    curl_setopt($ch, CURLOPT_URL, $url);
 
- 	    curl_setopt($ch, CURLOPT_POST, $post);
 
- 	    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
 
- 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
 
- 		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
 
- 		curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));  
 
- 	    $result = curl_exec($ch);
 
- 	    curl_close($ch);
 
- 	    return $result;
 
- 	}
 
- }
 
 
  |