close() public method

Close
public close ( )
Esempio n. 1
0
 /**
  * Execute a request against the url.
  *
  * @param string $url
  * @param array  $params
  *
  * @return mixed
  */
 public function request($url, array $params = [])
 {
     $this->curl->get($url, $params);
     $this->curl->setOpt(CURLOPT_RETURNTRANSFER, true);
     $response = $this->curl->response;
     $this->curl->close();
     return $response;
 }
Esempio n. 2
0
 /**
  * HTTP GET wrapper for Curl.
  * For requests with additional query parameters.
  *
  * @param string $url URL to GET request to.
  * @return mixed Response data.
  */
 public function getWithParams($url)
 {
     $curl = new Curl();
     $curl->get($this->endpoint . $url . '&api_token=' . $this->token);
     $curl->close();
     return json_decode($curl->response);
 }
Esempio n. 3
0
 public static function run($method, $params = [])
 {
     self::$defaultParam = ['method' => $method, 'module' => 'API', 'token_auth' => STAT_API_TOKEN, 'format' => 'JSON', 'expanded ' => true, 'idSite' => 1, 'filter_offset' => \yii::$app->request->get('filter_offset', 0), 'filter_limit' => \yii::$app->request->get('filter_limit', 50)];
     $params['formatDate'] = isset($params['formatDate']) ? $params['formatDate'] : null;
     if ($params['formatDate'] !== false) {
         self::formatDate();
     }
     unset($params['formatDate']);
     $params = array_merge(self::$defaultParam, $params);
     $params = array_filter($params);
     $curl = new Curl();
     $curl->setJsonDecoder(function ($response) {
         $json_obj = json_decode($response, true);
         if (!($json_obj === null)) {
             $response = $json_obj;
         }
         return $response;
     });
     $curl->get(STAT_API_URL, $params);
     $curl->close();
     if ($curl->error) {
         echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
     } else {
         return $curl->response;
     }
 }
Esempio n. 4
0
 /**
  * Create user cache.
  *
  * @param string $user Twitter screen name
  * @return bool If successful true
  * @throws CacheException Any errors
  */
 public function create($user)
 {
     try {
         $path = config("cache.path") . "/{$user}";
         $json_file = "{$path}/data.json";
         if (!$this->exists($user)) {
             mkdir($path);
         }
         if (!file_exists($json_file)) {
             touch($json_file);
         }
         $response = $this->twistOAuth->get("users/show", ["id" => $user]);
         $image_url = str_replace("_normal", "", $response->profile_image_url_https);
         $info = new SplFileInfo($image_url);
         $curl = new Curl();
         $curl->setUserAgent(SaveTweet::APP_NAME . "/" . SaveTweet::APP_VERSION . " with PHP/" . PHP_VERSION);
         $curl->download($image_url, "{$path}/icon.{$info->getExtension()}");
         $curl->close();
         $data = ["name" => $response->name, "screen_name" => $response->screen_name, "id" => $response->id_str, "icon" => config("cache.http_path") . "/{$response->id_str}/icon.{$info->getExtension()}", "org_icon" => $image_url, "update_at" => time()];
         $json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
         (new SplFileObject($json_file, "w"))->fwrite($json);
         return true;
     } catch (RuntimeException $e) {
         $this->_catch($e);
     }
 }
Esempio n. 5
0
 /**
  * API Call.
  *
  * @param string $path
  *
  * @throws Exception HTTP Error
  *
  * @return string
  */
 private static function apiCall($path)
 {
     $curl = new Curl();
     $curl->get(self::API_URL . $path);
     $curl->close();
     if ($curl->error) {
         throw new Exception('HTTP Error: ' . $curl->error_code . ': ' . $curl->error_message);
     }
     return $curl->response;
 }
Esempio n. 6
0
	private function request($url, $data) {
		$curl = new Curl();
		$curl->get($url, $data);
		$response = $curl->response;
		$http_response_header = $curl->httpStatusCode;
		$curl->close();
		if ($http_response_header == 200) {
			return $response;
		}
		return null;
	}
 /**
  * @return boolean
  */
 public function execute()
 {
     $this->curl = new Curl();
     $this->curl->setOpt(CURLOPT_ENCODING, 'gzip');
     $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $this->curl->setOpt(CURLOPT_HTTPHEADER, array('Accept: application/xml'));
     $this->prepareRequest();
     if (!$this->xmlRequest) {
         $this->lastError = new Exception('Request XML is not defined.');
         return false;
     }
     if (!isset(static::$API_METHOD) || !static::$API_METHOD) {
         $this->lastError = new Exception('API method is not defined.');
         return false;
     }
     $url = rtrim(static::ENDPOINT, '/') . '/' . static::ENDPOINT_VERSION . '/' . static::$API_METHOD;
     $data = array();
     if (static::$HTTP_METHOD === EANFacade::HTTP_METHOD_POST) {
         $data['xml'] = XMLUtils::SXEasXML($this->xmlRequest);
         $url .= '?' . Utils::httpBuildQuery3986($this->params);
     } else {
         $data = array_merge($this->params, array('xml' => XMLUtils::SXEasXML($this->xmlRequest)));
     }
     if (static::$HTTP_METHOD === EANFacade::HTTP_METHOD_GET) {
         $this->curl->get($url, $data);
         $this->curl->close();
     } else {
         if (static::$HTTP_METHOD === EANFacade::HTTP_METHOD_POST) {
             $this->curl->post($url, $data);
             $this->curl->close();
         } else {
             $this->lastError = new Exception('Invalid method for API call.');
             return false;
         }
     }
     if ($this->curl->error) {
         $this->lastError = new Exception($this->curl->errorMessage);
         return false;
     }
     try {
         if ($this->curl->response instanceof SimpleXMLElement) {
             $this->xmlResponse = $this->curl->response;
         } else {
             $this->xmlResponse = new SimpleXMLElement($this->curl->response);
         }
     } catch (Exception $e) {
         $this->lastError = $e;
         return false;
     }
     $this->lastError = null;
     $this->prepareResponse();
     return true;
 }
Esempio n. 8
0
 public function prim_address($token, $acc_id)
 {
     $curl = new Curl();
     $curl->setopt(CURLOPT_URL, "https://v2.api.xapo.com/accounts/{$acc_id}/primary_address/");
     $curl->setopt(CURLOPT_RETURNTRANSFER, true);
     $curl->setopt(CURLOPT_HEADER, false);
     $curl->setopt(CURLOPT_HTTPHEADER, ["Authorization: Bearer {$token}"]);
     $curl->_exec();
     $curl->close();
     $response = $curl->response;
     return json_decode($response);
 }
Esempio n. 9
0
 private function post($json, $headers)
 {
     $curl = new Curl();
     $curl->setHeader('Content-Type', 'application/json');
     $curl->setHeader('apikey', strval($this->apiKey));
     $curl->setHeader('token', strval($this->merchantToken));
     $curl->setHeader('Authorization', $headers['authorization']);
     $curl->setHeader('nonce', $headers['nonce']);
     $curl->setHeader('timestamp', $headers['timestamp']);
     $curl->post($this->uri, $json);
     $curl->close();
     return $curl->response;
 }
Esempio n. 10
0
 public static function ip($ip)
 {
     $url = 'http://apis.baidu.com/rtbasia/ip_type/ip_type?ip=' . $ip;
     $curl = new Curl();
     $curl->setHeader("apikey", "58d0d55af6ee8cda005ec2d674ff0db2");
     $curl->get($url);
     $curl->close();
     if ($curl->error) {
         echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
     } else {
         return $curl->response;
     }
 }
Esempio n. 11
0
 public function disable($token, $id)
 {
     $curl = new Curl();
     $curl->setopt(CURLOPT_URL, "https://v2.api.xapo.com/webhooks/{$id}/disable");
     $curl->setopt(CURLOPT_RETURNTRANSFER, true);
     $curl->setopt(CURLOPT_HEADER, false);
     $curl->setopt(CURLOPT_POST, true);
     $curl->setopt(CURLOPT_HTTPHEADER, ["Authorization: Bearer {$token}"]);
     $curl->_exec();
     $response = $curl->response;
     $curl->close();
     return $response;
 }
Esempio n. 12
0
 public function new($redirect_uri)
 {
     $curl = new Curl();
     $curl->setopt(CURLOPT_RETURNTRANSFER, true);
     $curl->setopt(CURLOPT_HEADER, false);
     $curl->setopt(CURLOPT_URL, 'https://v2.api.xapo.com/oauth2/token');
     $curl->setopt(CURLOPT_POST, true);
     $curl->setopt(CURLOPT_POSTFIELDS, "grant_type=client_credentials&redirect_uri={$redirect_uri}");
     $curl->setopt(CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded', "Authorization: Basic {$this->hash}"]);
     $curl->_exec();
     $curl->close();
     return json_decode($curl->response)->access_token;
 }
Esempio n. 13
0
 public function update($token, $addr, $amount)
 {
     $curl = new Curl();
     $curl->setopt(CURLOPT_URL, "https://v2.api.xapo.com/addresses/{$addr}?payment_threshold={$amount}");
     $curl->setopt(CURLOPT_RETURNTRANSFER, true);
     $curl->setopt(CURLOPT_HEADER, false);
     $curl->setopt(CURLOPT_CUSTOMREQUEST, 'PATCH');
     $curl->setopt(CURLOPT_POSTFIELDS, ['payment_threshold' => $amount]);
     $curl->setopt(CURLOPT_HTTPHEADER, ["Authorization: Bearer {$token}"]);
     $curl->_exec();
     $response = $curl->response;
     $curl->close();
     return json_decode($response);
 }
Esempio n. 14
0
 protected function _register()
 {
     $user = new User(array("name" => RequestMethods::post("name"), "email" => RequestMethods::post("email"), "gender" => RequestMethods::post("gender", ""), "fbid" => RequestMethods::post("fbid", ""), "live" => 1, "admin" => 0));
     $fb = new Curl();
     $access_token = RequestMethods::post("access_token");
     $fb->get('https://graph.facebook.com/me', ['access_token' => $access_token, 'fields' => 'name,email,gender,id']);
     $response = $fb->response;
     $fb->close();
     if ($response->error || $response->id != $user->fbid) {
         throw new \Exception("Error Processing Request");
     } else {
         $user->save();
     }
     return $user;
 }
Esempio n. 15
0
 /**
  * Send SMS from specified account
  *
  * @param string $recipient : recipient mobile number
  * @param string $message : message to be sent
  * @param string $mode : account to send the SMS from
  * @param string $format : content type
  * @return string containing cURL response
  */
 public function send($recipient, $message, $mode = '', $format = '')
 {
     /* make sure credit is available before proceed */
     $balance = $this->balance(empty($mode) ? $this->mode : $mode);
     if ($balance == 0) {
         return false;
     }
     $curl = new Curl\Curl();
     $curl->setopt(CURLOPT_RETURNTRANSFER, true);
     $curl->get($this->url . 'index.php/api/bulk_mt', array('api_key' => $this->token, 'action' => 'send', 'to' => $recipient, 'msg' => $message, 'sender_id' => $this->sender, 'content_type' => empty($format) ? $this->format : $format, 'mode' => empty($mode) ? $this->mode : $mode));
     $curl->close();
     if ($curl->error) {
         return false;
     } else {
         return $curl->response;
     }
 }
Esempio n. 16
0
 public function run($params)
 {
     $params = array_merge(self::$default, $params);
     $curl = new Curl();
     $curl->setJsonDecoder(function ($response) {
         $json_obj = json_decode($response, true);
         if (!($json_obj === null)) {
             $response = $json_obj;
         }
         return $response;
     });
     $curl->get(self::STAT_API_URL, $params);
     $curl->close();
     if ($curl->error) {
         echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
     } else {
         return $curl->response;
     }
 }
Esempio n. 17
0
 /**
  *
  * @param $uri
  * @param $method
  * @param array $params
  * @return mixed
  */
 protected function fetch_from_url($uri, $method, $params = array())
 {
     $method = strtolower($method);
     if (!in_array($method, array('post', 'get', 'put', 'delete'))) {
         throw new Exception('HTTP Method is not allowed.');
     }
     $url = $this->api_prefix . $uri;
     foreach ($params as $key => $value) {
         if (is_bool($value)) {
             $params[$key] = $value ? 'true' : 'false';
         }
     }
     $curl = new Curl();
     $curl->setOpt(CURLOPT_CONNECTTIMEOUT, 10);
     $curl->setHeader('Host', $this->headers['Host']);
     $curl->setHeader('Authorization', $this->headers['Authorization']);
     $curl->setHeader('User-Agent', $this->headers['User-Agent']);
     $curl->{$method}($url, $params);
     $result = $curl->response;
     $curl->close();
     $array = json_decode(json_encode($result), true);
     return $array;
 }
Esempio n. 18
0
 /**
  * 登录
  *
  * @param $user
  * @param $pwd
  * @param $refresh_token
  */
 public function login($user = null, $pwd = null, $refresh_token = null)
 {
     $request = array('client_id' => $this->oauth_client_id, 'client_secret' => $this->oauth_client_secret);
     if ($user != null && $pwd != null) {
         $request = array_merge($request, array('username' => $user, 'password' => $pwd, 'grant_type' => 'password'));
     } elseif ($refresh_token != null || $this->refresh_token != null) {
         $request = array_merge($request, array('grant_type' => 'refresh_token', 'refresh_token' => $refresh_token || $this->refresh_token));
     } else {
         throw new Exception('login params error.');
     }
     $curl = new Curl();
     $curl->setOpt(CURLOPT_CONNECTTIMEOUT, 10);
     $curl->setHeader('Authorization', $this->headers['Authorization']);
     $curl->post($this->oauth_url, $request);
     $result = $curl->response;
     $curl->close();
     if (isset($result->has_error)) {
         throw new Exception('Login error: ' . $result->errors->system->message);
     }
     $this->setAuthorizationResponse($result->response);
     $this->setAccessToken($result->response->access_token);
     $this->setRefreshToken($result->response->refresh_token);
 }
Esempio n. 19
0
 public static function get($users, $type, $ref)
 {
     $url = 'http://' . self::$referrerType[$ref] . '.gallary.work/api/user/GetUserData';
     $params = ['userName' => $users, 'userDataType' => $type, 'signKey' => self::SIGN_KEY, 'lastLoginStartTime' => '', 'lastLoginEndTime' => '', 'datatype' => 'json'];
     $curl = new Curl();
     $curl->setJsonDecoder(function ($response) {
         $json_obj = json_decode($response, true);
         if (!($json_obj === null)) {
             $response = $json_obj;
         }
         return $response;
     });
     $curl->get($url, $params);
     $curl->setConnectTimeout(10);
     $curl->close();
     if ($curl->error) {
         return false;
     } else {
         if ($curl->response === false) {
             return false;
         }
         return $curl->response;
     }
 }
 public function __destruct()
 {
     $this->curl->close();
 }
 public function testMemoryLeak()
 {
     ob_start();
     echo '[';
     for ($i = 0; $i < 10; $i++) {
         if ($i >= 1) {
             echo ',';
         }
         echo '{"before":' . memory_get_usage() . ',';
         $curl = new Curl();
         $curl->close();
         echo '"after":' . memory_get_usage() . '}';
         sleep(1);
     }
     echo ']';
     $html = ob_get_contents();
     ob_end_clean();
     $results = json_decode($html, true);
     // Ensure memory does not leak excessively after instantiating a new
     // Curl instance and cleaning up. Memory diffs in the 2000-6000+ range
     // have indicated a memory leak.
     $max_memory_diff = 1000;
     foreach ($results as $i => $result) {
         $memory_diff = $result['after'] - $result['before'];
         echo 'diff:   ' . $memory_diff . "\n";
         // Skip the first test to allow memory usage to settle.
         if ($i >= 1) {
             $this->assertLessThan($max_memory_diff, $memory_diff);
         }
     }
 }
Esempio n. 22
0
 /**
  *
  * Execute the Request
  *
  * @return Response The Response
  * @throws \Exception
  */
 public function execute()
 {
     $data = null;
     $curl = new Curl();
     try {
         $curl->setOpt(CURLOPT_SSL_VERIFYPEER, $this->verifyPeer);
         if ($this->proxy != null) {
             $curl->setOpt(CURLOPT_PROXY, $this->proxy);
             if ($this->proxyCredentials != null) {
                 $curl->setOpt(CURLOPT_PROXYUSERPWD, $this->proxyCredentials);
             }
         }
         foreach ($this->getHeaders() as $key => $value) {
             $curl->setHeader($key, $value);
         }
         foreach ($this->getCookies() as $key => $value) {
             $curl->setCookie($key, $value);
         }
         $error_format = "Instagram Request failed: [%s] [%s] %s";
         switch ($this->getMethod()) {
             case self::GET:
                 $data = $curl->get($this->getUrl(), $this->getParams());
                 if ($curl->curlError) {
                     throw new InstagramException(sprintf($error_format, "GET", $this->getUrl(), $curl->errorMessage));
                 }
                 break;
             case self::POST:
                 $data = $curl->post($this->getUrl(), $this->getParams());
                 if ($curl->curlError) {
                     throw new InstagramException(sprintf($error_format, "POST", $this->getUrl(), $curl->errorMessage));
                 }
                 break;
             default:
                 throw new InstagramException(sprintf($error_format, "UNKNOWN", $this->getUrl(), "Unsupported Request Method"));
         }
         return new Response($curl, $data);
     } finally {
         //Release cURL resources after return or exception
         $curl->close();
     }
 }
Esempio n. 23
0
 /**
  * Close.
  *
  * @param Curl $curl
  */
 protected static function closeCurl(&$curl)
 {
     $curl->close();
 }
Esempio n. 24
0
 public function appGetMaintianWorkFormAct()
 {
     $nhservers = Nhserver::all();
     $curl = new Curl();
     foreach ($nhservers as $nhserver) {
         $p = 0;
         $retCount = 1;
         while ($retCount != 0) {
             $curl->get('http://' . $nhserver->host . ':' . $nhserver->port . '/WebSite/appGetMaintianWorkFormAct.ebf', array('MaintianComTel' => '400335', 'PageIndex' => $p++));
             $result = $curl->response;
             $result = mb_convert_encoding($result, "UTF-8", "gb2312");
             $json_result = json_decode($result);
             $retCount = count($json_result->Ret);
             foreach ($json_result->Ret as $ret) {
                 $historyTicket = Ticket::current()->wformid($ret->WFormId)->find();
                 if (empty($historyTicket)) {
                     //step 1 save record
                     $millisecond = microtime(true) * 1000;
                     $time = explode(".", $millisecond);
                     $millisecond = $time[0];
                     $api_id = 'ABC' . $millisecond;
                     $ticket = new Ticket();
                     $ticket->current = 1;
                     $ticket->location_id = $nhserver->id;
                     $ticket->time_log = date('Y-m-d H:i:s');
                     $ticket->data_content = $result;
                     $ticket->WFormId = $ret->WFormId;
                     $ticket->Identifier = $ret->Identifier;
                     $ticket->WFormSetTime = $ret->WFormSetTime;
                     $ticket->ReplyDue = $ret->ReplyDue;
                     $ticket->IsChecked = $ret->IsChecked;
                     $ticket->ArriveDue = $ret->ArriveDue;
                     $ticket->WFormContent = $ret->WFormContent;
                     $ticket->OrgName = $ret->OrgName;
                     $ticket->InstallAddress = $ret->InstallAddress;
                     $ticket->ModelId = $ret->ModelId;
                     $ticket->BrandId = $ret->BrandId;
                     $ticket->RepairInfo = json_encode($ret->RepairInfo);
                     $ticket->Engineer = $ret->RepairInfo->Engineer;
                     $ticket->RepairCreateTime = $ret->RepairInfo->RepairCreateTime;
                     $ticket->RespTime = $ret->RepairInfo->RespTime;
                     $ticket->ArrivalTime = $ret->RepairInfo->ArrivalTime;
                     $ticket->RepairformSts = $ret->RepairInfo->RepairformSts;
                     $ticket->MaintianComTel = $ret->RepairInfo->MaintianComTel;
                     $ticket->GivenArrivalTime = $ret->RepairInfo->GivenArrivalTime;
                     $ticket->Mobile = $ret->RepairInfo->Mobile;
                     $ticket->api_id = $api_id;
                     $ticket->save();
                     //step 2 send email
                     //step 3 call ebs api
                 } else {
                     //check update
                     if ($historyTicket->Identifier != $ret->Identifier || $historyTicket->WFormSetTime != $ret->WFormSetTime || $historyTicket->ReplyDue != $ret->ReplyDue || $historyTicket->IsChecked != $ret->IsChecked || $historyTicket->ArriveDue != $ret->ArriveDue || $historyTicket->WFormContent != $ret->WFormContent || $historyTicket->OrgName != $ret->OrgName || $historyTicket->InstallAddress != $ret->InstallAddress || $historyTicket->ModelId != $ret->ModelId || $historyTicket->BrandId != $ret->BrandId || $historyTicket->Engineer != $ret->RepairInfo->Engineer || $historyTicket->RepairCreateTime != $ret->RepairInfo->RepairCreateTime || $historyTicket->RespTime != $ret->RepairInfo->RespTime || $historyTicket->ArrivalTime != $ret->RepairInfo->ArrivalTime || $historyTicket->RepairformSts != $ret->RepairInfo->RepairformSts || $historyTicket->MaintianComTel != $ret->RepairInfo->MaintianComTel || $historyTicket->GivenArrivalTime != $ret->RepairInfo->GivenArrivalTime || $historyTicket->Mobile != $ret->RepairInfo->Mobile) {
                         $ticket = new Ticket();
                         $ticket->current = 1;
                         $ticket->location_id = $historyTicket->location_id;
                         $ticket->time_log = date('Y-m-d H:i:s');
                         $ticket->data_content = $result;
                         $ticket->WFormId = $ret->WFormId;
                         $ticket->Identifier = $ret->Identifier;
                         $ticket->WFormSetTime = $ret->WFormSetTime;
                         $ticket->ReplyDue = $ret->ReplyDue;
                         $ticket->IsChecked = $ret->IsChecked;
                         $ticket->ArriveDue = $ret->ArriveDue;
                         $ticket->WFormContent = $ret->WFormContent;
                         $ticket->OrgName = $ret->OrgName;
                         $ticket->InstallAddress = $ret->InstallAddress;
                         $ticket->ModelId = $ret->ModelId;
                         $ticket->BrandId = $ret->BrandId;
                         $ticket->RepairInfo = json_encode($ret->RepairInfo);
                         $ticket->Engineer = $ret->RepairInfo->Engineer;
                         $ticket->RepairCreateTime = $ret->RepairInfo->RepairCreateTime;
                         $ticket->RespTime = $ret->RepairInfo->RespTime;
                         $ticket->ArrivalTime = $ret->RepairInfo->ArrivalTime;
                         $ticket->RepairformSts = $ret->RepairInfo->RepairformSts;
                         $ticket->MaintianComTel = $ret->RepairInfo->MaintianComTel;
                         $ticket->GivenArrivalTime = $ret->RepairInfo->GivenArrivalTime;
                         $ticket->Mobile = $ret->RepairInfo->Mobile;
                         $ticket->api_id = $historyTicket->api_id;
                         $ticket->ebs_id = $historyTicket->ebs_id;
                         $ticket->ebs_content = $historyTicket->ebs_content;
                         $ticket->flag1 = $historyTicket->flag1;
                         $ticket->flag2 = $historyTicket->flag2;
                         $ticket->flag3 = $historyTicket->flag3;
                         $ticket->flag4 = $historyTicket->flag4;
                         $ticket->flag5 = $historyTicket->flag5;
                         $ticket->save();
                         $historyTicket->current = 0;
                         $historyTicket->save();
                     }
                 }
             }
         }
         //Timeout not responding (Select * from tb_ticket where current=1 and repairformset=1 and flag1=0 and repaircreatetime is not null and datediff(mi,repaircreatetime,now)>20)
         $timeout_tickets = DB::select('select * from tickets where current=1 and RepairformSts=1 and flag1=0 and RepairCreateTime is not null and datediff(mi,RepairCreateTime,now)>20');
         foreach ($timeout_tickets as $t) {
             //send email to user
         }
         //update flag1 = 1;
         DB::update('update tickets set flag1 = 1 where current=1 and RepairformSts=1 and flag1=0 and RepairCreateTime is not null and datediff(mi,RepairCreateTime,now)>20');
         //Timeout is not present (Select * from tb_ticket where current=1 and repairformset=2 and flag2=0 and resptime is not null and datediff(mi,resptime,now)>20)
         $timeout_tickets = DB::select('select * from tickets where current=1 and RepairformSts=2 and flag2=0 and RespTime is not null and datediff(mi,RespTime,now)>20');
         foreach ($timeout_tickets as $t) {
             //send email to user
         }
         //update flag2 = 1;
         DB::update('update tickets set flag2 = 1 where current=1 and RepairformSts=2 and flag2=0 and RespTime is not null and datediff(mi,RespTime,now)>20');
         //Timeout not repaired (Select * from tb_ticket where current=1 and repairformset=3 and flag3=0 and arrivaltime is not null and datediff(mi,arrivaltime,now)>20)
         $timeout_tickets = DB::select('select * from tickets where current=1 and RepairformSts=3 and flag3=0 and ArrivalTime is not null and datediff(mi,ArrivalTime,now)>20');
         foreach ($timeout_tickets as $t) {
             //send email to user
         }
         //update flag3 = 1;
         DB::update('update tickets set flag3 = 1 where current=1 and RepairformSts=3 and flag3=0 and ArrivalTime is not null and datediff(mi,ArrivalTime,now)>20');
     }
     $curl->close();
 }
Esempio n. 25
0
 /**
  * 向环信请求
  * @param $url
  * @param string $params
  * @param string $type POST|GET
  * @return mixed
  * @throws \ErrorException
  */
 private function contact($url, $params = '', $type = 'POST')
 {
     $postData = '';
     if (is_array($params)) {
         $postData = json_encode($params);
     }
     $curl = new Curl();
     $curl->setUserAgent('Jasonwx/Easemob SDK; Jason Wang<*****@*****.**>');
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $curl->setOpt(CURLOPT_SSL_VERIFYHOST, false);
     $curl->setHeader('Content-Type', 'application/json');
     $token = "";
     if ($url !== $this->url . '/token') {
         $token = $this->getToken();
         $curl->setHeader('Authorization', 'Bearer ' . $token);
     }
     switch ($type) {
         case 'POST':
             $curl->post($url, $postData);
             break;
         case 'GET':
             $curl->get($url);
             break;
         case 'DELETE':
             $curl->delete($url);
             break;
     }
     $curl->close();
     if ($this->debug) {
         echo "URL: {$url}\n Header: {$token} \nBody: \"{$postData}\"\n";
     }
     if ($curl->error) {
         throw new \ErrorException('CURL Error: ' . $curl->error_message, $curl->error_code);
     }
     if ($this->debug) {
         //            echo "return: {$curl->raw_response} \n";
     }
     return json_decode($curl->raw_response, true);
 }
Esempio n. 26
0
 public function testMemoryLeak()
 {
     // Skip memory leak test failing for PHP 7.
     // "Failed asserting that 8192 is less than 1000."
     if (getenv('TRAVIS_PHP_VERSION') === '7.0') {
         return;
     }
     ob_start();
     echo '[';
     for ($i = 0; $i < 10; $i++) {
         if ($i >= 1) {
             echo ',';
         }
         echo '{"before":' . memory_get_usage() . ',';
         $curl = new Curl();
         $curl->close();
         echo '"after":' . memory_get_usage() . '}';
         sleep(1);
     }
     echo ']';
     $html = ob_get_contents();
     ob_end_clean();
     $results = json_decode($html, true);
     // Ensure memory does not leak excessively after instantiating a new
     // Curl instance and cleaning up. Memory diffs in the 2000-6000+ range
     // indicate a memory leak.
     $max_memory_diff = 1000;
     foreach ($results as $i => $result) {
         $memory_diff = $result['after'] - $result['before'];
         // Skip the first test to allow memory usage to settle.
         if ($i >= 1) {
             $this->assertLessThan($max_memory_diff, $memory_diff);
         }
     }
 }
Esempio n. 27
0
    $optionsframework_settings = get_option('optionsframework');
    // Gets the unique option id
    $option_name = $optionsframework_settings['id'];
    if (get_option($option_name)) {
        $options = get_option($option_name);
    }
    if (isset($options[$name])) {
        return $options[$name];
    } else {
        return $default;
    }
}
$environment = of_get_option('sforce_instance');
if ($environment == 'sandbox') {
    $sf_instance_url = 'https://test.salesforce.com/services/oauth2/token';
} else {
    $sf_instance_url = 'https://login.salesforce.com/services/oauth2/token';
}
$curl = new Curl();
$response = $curl->post($sf_instance_url, array('grant_type' => 'password', 'client_id' => SFORCE_CLIENT_ID, 'client_secret' => SFORCE_CLIENT_SECRET, 'username' => $environment == 'sandbox' ? SFORCE_STAGING_USER : SFORCE_PRODUCTION_USER, 'password' => $environment == 'sandbox' ? SFORCE_STAGING_PASSWORD : SFORCE_PRODUCTION_PASSWORD));
$curl->close();
if (isset($response->access_token) && isset($response->instance_url)) {
    update_option('sforce_instance', $environment);
    update_option('sforce_oauth_token', $response->access_token);
    update_option('sforce_instance_url', $response->instance_url);
} else {
    delete_option('sforce_instance');
    delete_option('sforce_oauth_token');
    delete_option('sforce_instance_url');
}
ShareFile::authenticate();
Esempio n. 28
0
 /**
  * @before _secure
  */
 public function play()
 {
     $this->seo(array("title" => "Play Game", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $session = Registry::get("session");
     $campaign = $session->get('Game\\Authorize:$campaign');
     if (!$campaign) {
         $this->redirect("/index.html");
     }
     $session->erase('Game\\Authorize:$campaign');
     $model = $campaign->type;
     $game = $model::first(array("id = ?" => $campaign->type_id));
     switch ($model) {
         case 'imagetext':
             $img = $this->_imagetextprocess($game, $campaign);
             break;
         case 'image':
             $img = $this->_imageprocess($game, $campaign);
             break;
         case 'text':
             $img = $this->_textprocess($game, $campaign);
             break;
         case 'shuffle':
             $img = $this->_shuffleprocess($game, $campaign);
             break;
     }
     $participant = Participant::first(array("user_id = ?" => $this->user->id, "campaign_id = ?" => $campaign->id));
     $facebook = new Curl();
     $facebook->post('https://graph.facebook.com/?id=' . "http://" . $_SERVER["HTTP_HOST"] . "/game/result/" . $participant->id . '&scrape=true');
     $facebook->close();
     $domain = Meta::first(array("property = ?" => "domain", "live = ?" => true));
     $items = Participant::all(array(), array("DISTINCT campaign_id"), "created", "desc", 3, 1);
     $view->set("items", $items);
     $view->set("img", $img);
     $view->set("participant", $participant);
     $view->set("campaign", $campaign)->set("domain", $domain);
 }
Esempio n. 29
0
 public function update($c_id, $fname = '', $mname = '', $lname = '', $gen = '', $avatar = '', $addl1 = '', $addl2 = '', $city = '', $state = '', $country = '', $zip = '', $dob = '')
 {
     $curl = new Curl();
     $curl->setopt(CURLOPT_URL, "https://v2.api.xapo.com/customers/{$c_id}/?first_name={$fname}middle_name={$mname}&last_name={$lname}&gender={$gen}&avatar={$avatar}&address_line_1={$addl1}&address_line_2={$addl2}&city={$city}&state={$state}&country_iso3={$country}&zip_code={$zip}&date_of_birth={$dob}");
     $curl->setopt(CURLOPT_RETURNTRANSFER, true);
     $curl->setopt(CURLOPT_HEADER, false);
     $curl->setopt(CURLOPT_CUSTOMREQUEST, 'PATCH');
     $curl->_exec();
     $response = $curl->response;
     $curl->close();
     return json_decode($response);
 }
Esempio n. 30
0
 public function curl_post($sUrl, $aPOSTParam, $timeout = 5)
 {
     $curl = new Curl();
     if ($timeout) {
         $curl->setopt(CURLOPT_CONNECTTIMEOUT, $timeout);
     }
     $curl->post($sUrl, $aPOSTParam);
     $curl->close();
     return $curl->error ? false : $curl->response;
 }