PayHttpClient(); } function PayHttpClient() { $this->reqContent = array(); $this->resContent = ""; $this->errInfo = ""; $this->timeOut = 120; $this->responseCode = 0; } // 设置请求内容 function setReqContent($url, $data) { $this->reqContent['url'] = $url; $this->reqContent['data'] = $data; } // 获取结果内容 function getResContent() { return $this->resContent; } // 获取错误信息 function getErrInfo() { return $this->errInfo; } // 设置超时时间,单位秒 function setTimeOut($timeOut) { $this->timeOut = $timeOut; } // 执行http调用 function call() { // 启动一个CURL会话 $ch = curl_init(); // 设置curl允许执行的最长秒数 curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeOut); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 获取的信息以文件流的形式返回,而不是直接输出。 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 发送一个常规的POST请求。 curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $this->reqContent['url']); // 要传送的所有数据 curl_setopt($ch, CURLOPT_POSTFIELDS, $this->reqContent['data']); // 执行操作 $res = curl_exec($ch); $this->responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($res == null) { $this->errInfo = "call http err :".curl_errno($ch)." - ".curl_error($ch); curl_close($ch); return false; } else if ($this->responseCode != "200") { $this->errInfo = "call http err httpcode=".$this->responseCode; curl_close($ch); return false; } curl_close($ch); $this->resContent = $res; return true; } function getResponseCode() { return $this->responseCode; } } ?>