public function check($service) { if ($this->isFreeService($service)) { return true; } $url = $this->buildUrl(); $messageData = $this->buildMessage(); $method = strtoupper($this->authMethod); switch ($method) { case 'GET': $result = NetworkHelper::doPOST($url, $messageData); break; case 'POST': default: $result = NetworkHelper::doGET($url, $messageData); break; } return $this->processResponseData($result); }
function invokeService($message, $product = null) { $messageData = "json=" . json_encode($message); $content = $message->content; $account = $content["args"]["account"]; $serviceUrl = $account->ws_uri; $result = NetworkHelper::doPOST($serviceUrl, $messageData); $result = $this->getJsonObject($result); if ($result === false) { //jaucRaiseMessage("Responding an error from Web Service", true); return false; } else { if (!empty($result->error)) { jaucRaiseMessage($result->error, true); return false; //throw new Exception('Invoking service ['.$message->content->service.'] error '.$result->error); } else { return $result->response; } } }
/** * * @param $url * @param $savePath * @param $options * * @return {array("savePath"=>$savePath, "error"=>curl_error(), "info"=>curl_getinfo())} */ public static function downloadFile($savePath, $url, $data, $options = null) { if (substr($savePath, -1) == '/' || JFolder::exists($savePath)) { $targetDir = $savePath; $savePath = jaTempnam(ja_sys_get_temp_dir(), 'c_'); } /*if (($fh = fopen($savePath, "wb")) === false) { jaucRaiseMessage("Can not open file: {$savePath}", true); //throw new Exception("CURL ERROR:: Can not open file: $savePath"); return false; }*/ $result = NetworkHelper::doPOST($url, $data, $options); if (!empty($result["error"])) { return false; } $test = JFile::write($savePath, $result["content"]); if (!$test) { return false; } $result["savePath"] = $savePath; return $result; }
/** * * @param $url * @param $savePath * @param $options * * @return {array("savePath"=>$savePath, "error"=>curl_error(), "info"=>curl_getinfo())} */ function downloadFile($savePath, $url, $data, $options = null) { if (substr($savePath, -1) == '/' || is_dir($savePath)) { $targetDir = $savePath; $savePath = tempnam(sys_get_temp_dir(), 'c_'); } if (($fh = fopen($savePath, "wb")) === false) { jaucRaiseMessage("Can not open file: {$savePath}", true); //throw new Exception("CURL ERROR:: Can not open file: $savePath"); return false; } $result = NetworkHelper::doPOST($url, $data, $options); if (!empty($result["error"])) { return false; } if (($fp = fopen($savePath, 'wb')) !== false) { fwrite($fp, $result["content"]); fclose($fp); } else { return false; } $result["savePath"] = $savePath; return $result; }