curl  登陆

class CurlInterface {
     public static function Get($url, $q ,$rs) {
         if($rs) $q .= '&wt=jsonWithCondition';
         else $q .= '&wt=json&facet=false';
//        echo $url.$q;
//        echo '
';
         $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_POST, 1);    //指定post方式提交数据        
        curl_setopt($ch, CURLOPT_POSTFIELDS, $q);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //将curl_exec()获取的信息以文件流的形式返回,而不是直接输出
        $output = curl_exec($ch);
        curl_close($ch);
        if($output){
            $output = json_decode($output,true);
            //print_r($output);
            if(!$rs) $output = $output['response'];
        }
        return $output;
     }
}


     $url=ERA_AGENT;
     $q="q=id:$maxjjid&fl=id,alId,pinYin,mobile,photoPath";
     $info=CurlInterface::Get($url,$q);     
       if(($info['numFound']==0)){
         return false;
       }
       return  $info['docs'][0];



posted @ 2013-01-17 16:03  张三_zhangsan  阅读(148)  评论(0编辑  收藏  举报