getClientIP(); $url=$this->goldpig_post($urlparams); return $url; } /** * 金猪支付post请求 * @param [type] $data [description] * @return [type] [description] */ public function goldpig_post($param){ $url='http://api.357p.com/'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//要求结果为字符串且输出到屏幕上 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);//设置等待时间 $url_str = curl_exec($ch); curl_close($ch); if(strpos($url_str,'http:')){ $url_str=str_replace('&','&',$url_str); $url_str=strstr($url_str,"http"); $url_arr=explode('"',$url_str); $url=$url_arr[0]; return ['msg'=>$url,'status'=>1]; }else{ return ['msg'=>'','status'=>0,'info'=>$url_str]; } } public function getClientIP(){ global $ip; if(getenv("HTTP_CLIENT_IP")){ $ip = getenv("HTTP_CLIENT_IP"); }else if(getenv("HTTP_X_FORWARDED_FOR")){ $ip = getenv("HTTP_X_FORWARDED_FOR"); }else if(getenv("REMOTE_ADDR")){ $ip = getenv("REMOTE_ADDR"); }else{ $ip = "NULL"; } return $ip; } }