/**
  * @param $username
  * @param $password
  * @return array Success {
  *  @var string AccessId
  *  @var string SecretKey
  *  @var string UserId
  *  @var string EmployeeId
  * }
  * @throws MPAuthException
  */
 public function authenticate($username, $password)
 {
     $data = ['Login' => $username, 'Password' => md5($password)];
     $this->prepareRequest($data);
     try {
         $response = $this->curl->post($this->url . $this->authRelativeUrl, true);
         try {
             $decodedResponse = Json::decode($response, true);
             switch ($decodedResponse['status']['code']) {
                 case 'ok':
                     break;
                 case 'error':
                     throw new MPAuthException('Invalid username or password.');
                     break;
                 default:
                     throw new MPAuthException('Unknown response status.');
             }
             return $decodedResponse['data'];
         } catch (InvalidParamException $e) {
             throw new MPAuthException('Error decoding server response. Raw response: ' . var_export($response, true));
         }
     } catch (Exception $e) {
         throw new MPAuthException('Error requesting host:' . $e->getMessage() . $e->getCode());
     }
 }
 public function actionSend()
 {
     if (Yii::$app->request->post("recipient_id")) {
         $recipient_id = Yii::$app->request->post("recipient_id");
         $text = Yii::$app->request->post("message");
         $sender_id = Yii::$app->request->post("sender_id");
         $recipientUser = Salamiuser::find()->where(['id' => $recipient_id])->one();
         $senderUser = Salamiuser::find()->where(['id' => $sender_id])->one();
         $message = new Messages();
         $message->sender_id = $senderUser->id;
         $message->recipient_id = $recipientUser->id;
         $message->text = $text;
         $message->state = "new";
         $saved = $message->save();
         $data = array('user_ids' => array($recipientUser->facebook_id), 'notification' => array("alert" => $text, "android" => array('payload' => array("sender" => $senderUser->facebook_id))));
         $ionicAppId = "70f2a984";
         $ionicApiSecret = "ec4839bfb9ea2daa2271b0149a0c18003a3672178f4e6485";
         $url = "https://push.ionic.io/api/v1/push";
         $content = json_encode($data);
         $curl = new curl\Curl();
         $curl->setOption(CURLOPT_SSL_VERIFYPEER, false);
         $curl->setOption(CURLOPT_POSTFIELDS, $content);
         $curl->setOption(CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'X-Ionic-Application-Id: ' . $ionicAppId, 'Content-Length: ' . strlen($content), 'Authorization: Basic ' . base64_encode($ionicApiSecret)));
         $response = $curl->post('https://push.ionic.io/api/v1/push');
         return $response;
     }
     return '{"error": "Invalid request parameters"}';
 }
Example #3
2
 /**
  * cURL advanced GET example with HTTP status codes
  */
 public function actionGetAdvancedExample()
 {
     //Init curl
     $curl = new curl\Curl();
     //get http://example.com/
     $response = $curl->post('http://example.com/');
     // List of status codes here http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
     switch ($curl->responseCode) {
         case 200:
             //success logic here
             break;
         case 404:
             //404 Error logic here
             break;
     }
 }
Example #4
1
 public function subscribe()
 {
     $url = Yii::$app->params['getdrip']['apiUrl'] . Yii::$app->params['getdrip']['accountId'] . '/' . 'campaigns/' . Yii::$app->params['getdrip']['signup_campaignId'] . '/subscribers';
     $subscribe = json_encode(['subscribers' => [["email" => $this->email, "utc_offset" => 660, "double_optin" => true, "starting_email_index" => 0]]]);
     $curl = new curl\Curl();
     $curl->reset();
     $curl->setOption(CURLOPT_FRESH_CONNECT, true);
     $curl->setOption(CURLOPT_FORBID_REUSE, true);
     $curl->setOption(CURLOPT_RETURNTRANSFER, true);
     $curl->setOption(CURLOPT_FOLLOWLOCATION, true);
     $curl->setOption(CURLOPT_SSL_VERIFYPEER, false);
     $curl->setOption(CURLOPT_SSL_VERIFYHOST, false);
     $curl->setOption(CURLOPT_USERPWD, Yii::$app->params['getdrip']['apiToken'] . ":" . '');
     $curl->setOption(CURLOPT_POSTFIELDS, $subscribe);
     $curl->setOption(CURLOPT_CUSTOMREQUEST, "POST");
     $curl->setOption(CURLOPT_HTTPHEADER, array('Accept:application/json, text/javascript, */*; q=0.01', 'Content-Type: application/vnd.api+json'));
     $response = $curl->post($url);
 }
Example #5
0
 public function getSprint()
 {
     $curl = new curl\Curl();
     $curl->setOption(CURLOPT_COOKIEJAR, $_SERVER['DOCUMENT_ROOT'] . '/infoboard/frontend/web/cookie.txt')->setOption(CURLOPT_USERPWD, 'sga:sytuacja!generacja')->setOption(CURLOPT_COOKIEFILE, $_SERVER['DOCUMENT_ROOT'] . '/infoboard/frontend/web/cookie.txt')->get('http://192.168.1.253/raporty_etl/login');
     if ($curl->responseCode == 200) {
         $response = $curl->setOption(CURLOPT_POSTFIELDS, array('nick' => 'AFR', 'password' => 'afr123'))->setOption(CURLOPT_COOKIEFILE, $_SERVER['DOCUMENT_ROOT'] . '/infoboard/frontend/web/cookie.txt')->post('http://192.168.1.253/raporty_etl/login/login_do');
     }
     $response = $curl->setOption(CURLOPT_POSTFIELDS, array('getJSON' => 1))->setOption(CURLOPT_COOKIEFILE, $_SERVER['DOCUMENT_ROOT'] . '/infoboard/frontend/web/cookie.txt')->post('http://192.168.1.253/raporty_etl/sprint/stats');
     $sprintData = json_decode($response, true);
     $this->data->users = [];
     $this->data->userRealization = [];
     $this->data->userRemains = [];
     $this->data->colors = [];
     $this->data->now = $sprintData['dzis'];
     $this->data->dates = $sprintData['daty'];
     $this->data->plan = $sprintData['plan'];
     $this->data->realization = $sprintData['realizacja'];
     $this->data->sprint = $sprintData['nr'];
     foreach ($sprintData['uzyt'] as $user => $data) {
         $percent = ($data['godz_wyk'] + $data['prod_godz_wyk']) / ($data['work_time'] - $data['nieobecnosci']) * 100;
         array_push($this->data->users, strtoupper($user));
         array_push($this->data->userRealization, number_format($percent, 2, '.', ''));
         array_push($this->data->userRemains, number_format(100 - $percent, 2, '.', ''));
         array_push($this->data->colors, 100 - $percent > $this->data->now + 20 ? '"#ff5555"' : '"#000000"');
     }
     return $this;
 }
 public function actionSay()
 {
     $url = 'http://yii.com/users';
     $curl = new Curl();
     $rs = $curl->get($url);
     p($rs);
     p($curl);
     exit;
     //        exit;
     //        $curl->head( 'http://yii.com/users' );
     /*$curl->setOption(
                 CURLOPT_POSTFIELDS,
                 http_build_query(array(
     
                     )
                 ));
             $rs = $curl->post($url);
     
             p($rs);
     
     
             $options = $curl->setOption(CURLOPT_POSTFIELDS, 'category_name')->get($url);
     
     
             p($options);*/
 }
Example #7
0
 public function actionAddtax()
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $curl = new curl\Curl();
     //post https://accounts.zoho.com/apiauthtoken/create?SCOPE=ZohoInvoice/invoiceapi
     $response = $curl->setOption(CURLOPT_POSTFIELDS, http_build_query(array('JSONString' => '{ "tax_name": "Verhuuren1",  "tax_percentage": 23,  "tax_type": "tax"}')))->post('https://invoice.zoho.com/api/v3/settings/taxes?authtoken=90545fa01029567ccd0ad3447cbf843c');
     return $response;
 }
Example #8
0
 private function post($params)
 {
     $curl = new Curl();
     $curl->setOption(CURLOPT_POSTFIELDS, 'force=1&order[is_test]=1&order[dispatch_type]=3&order[dispatch_time]=1&order[dispatch_at]=2015-09-12&order[person]=%D0%96%D0%B5%D0%BD%D1%8F+%D0%9B%D1%83%D0%BA%D0%B0%D1%88%D0%B8%D0%BD&order[comment]=%D0%B7%D0%B0%D0%BF%D1%87%D0%B0%D1%81%D1%82%D0%B8+%D0%B4%D0%BB%D1%8F+%D0%98%D0%BF%D0%BF%D0%BE%D0%BB%D0%B8%D1%82%D0%B0&order[shipment_address]=%D0%9C%D0%BE%D1%81%D0%BA%D0%B2%D0%B0%2C+3-%D1%8F+%D1%83%D0%BB%D0%B8%D1%86%D0%B0+%D0%A1%D1%82%D1%80%D0%BE%D0%B8%D1%82%D0%B5%D0%BB%D0%B5%D0%B9%2C+%D0%B4%D0%BE%D0%BC+25%2C+%D0%BA%D0%B2%D0%B0%D1%80%D1%82%D0%B8%D1%80%D0%B0+12&order[items][1][resource_id]=703&order[items][1][warehouse_id]=46&order[items][1][quantity]=1&order[items][1][comment]=%D0%BF%D1%80%D0%BE%D0%B8%D0%B7%D0%B2%D0%BE%D0%BB%D1%8C%D0%BD%D1%8B%D0%B9+%D0%BA%D0%BE%D0%BC%D0%BC%D0%B5%D0%BD%D1%82%D0%B0%D1%80%D0%B8%D0%B9+1&order[items][2][resource_id]=50716&order[items][2][warehouse_id]=46&order[items][2][quantity]=1&order[items][2][comment]=%D0%BF%D1%80%D0%BE%D0%B8%D0%B7%D0%B2%D0%BE%D0%BB%D1%8C%D0%BD%D1%8B%D0%B9+%D0%BA%D0%BE%D0%BC%D0%BC%D0%B5%D0%BD%D1%82%D0%B0%D1%80%D0%B8%D0%B9+2&&order[items][3][resource_id]=50716&order[items][3][warehouse_id]=6&order[items][3][quantity]=1&order[items][3][comment]=%D0%BF%D1%80%D0%BE%D0%B8%D0%B7%D0%B2%D0%BE%D0%BB%D1%8C%D0%BD%D1%8B%D0%B9+%D0%BA%D0%BE%D0%BC%D0%BC%D0%B5%D0%BD%D1%82%D0%B0%D1%80%D0%B8%D0%B9+3')->post($this->uri . '?key=' . $params['key'], false);
     //        var_dump($curl);
     //        var_dump($curl);die;
     // .'?key='.$params['key']  <- КОСТЫЛЬ
     //        return $curl;
 }
 public function actionPerform()
 {
     $request = Yii::$app->request;
     $request = $request->post();
     return print_r($request['message']['chat']['id']);
     //Init curl
     $curl = new curl\Curl();
     //post http://example.com/
     $response = $curl->setOption(CURLOPT_POSTFIELDS, http_build_query(array('myPostField' => 'value')))->post('http://example.com/');
 }
Example #10
0
 /**
  * Returned IP address of visitor if successful.
  * @return string|false
  */
 public function getIp()
 {
     $curl = new Curl();
     if ($curl->get(self::URL_API . 'jsonip')) {
         if (empty($curl->response['ip'])) {
             return false;
         }
         return $curl->response['ip'];
     }
     return false;
 }
Example #11
0
 /**
  * Create an item in teh UPCDatabase.org
  * 
  * @return array ('success' => true/false, 'errorText' => 'string')
  */
 public function createItem($itemDetails)
 {
     $ch = new curl\Curl();
     $response = $ch->setOption(CURLOPT_POSTFIELDS, http_build_query(['upc' => $itemDetails['upc'], 'mrsp' => $itemDetails['msrp'], 'apikey' => Yii::$app->params['apiKey'], 'title' => $itemDetails['title'], 'alias' => $itemDetails['alias'], 'description' => $itemDetails['description'], 'unit' => 'each']))->post(Yii::$app->params['apiUrl'] . '/submit/curl.php');
     if ($response == 'OK') {
         $result = ['success' => true, 'errorText' => ''];
     } else {
         $result = ['success' => false, 'errorText' => $response];
     }
     return $result;
 }
 /**
  * This command echoes what you have entered as the message.
  * @param string $message the message to be echoed.
  */
 public function actionIndex()
 {
     foreach (self::$ticks as $tick) {
         //Pide la ultima de todas
         $curl = new curl\Curl();
         $response = json_decode($curl->get('https://cex.io/api/trade_history/' . $tick), true);
         $lastCex = $response[0]['tid'];
         $lastSaved = -1;
         do {
             if ($lastSaved == -1) {
                 $lastTid = new Query();
                 $lastTid = $lastTid->select('max(tid) as tid')->from('trades')->where(['tick' => $tick])->one();
                 $lastTid = $lastTid['tid'];
                 if (!is_null($lastTid)) {
                     $since = $lastTid + 1;
                 } else {
                     $since = 1;
                 }
             } else {
                 $since = $lastSaved + 1;
             }
             $response = json_decode($curl->get('https://cex.io/api/trade_history/' . $tick . '/?since=' . $since), true);
             $index = count($response);
             $nine = $index - 1;
             echo 'Since:' . $since . ', Res:' . $response[$nine]['tid'] . '\\r\\n';
             if ($response[$nine]['tid'] < $since) {
                 if ($since - $response[$nine]['tid'] < 1000) {
                     $index = $nine - ($since - $response[$nine]['tid']);
                 } else {
                     $since += $since - $response[$nine]['tid'];
                     $response = json_decode($curl->get('https://cex.io/api/trade_history/' . $tick . '/?since=' . $since), true);
                 }
             }
             while ($index) {
                 $trade = $response[--$index];
                 $tradeModel = new Trades();
                 $tradeModel->tick = $tick;
                 $tradeModel->type = $trade['type'];
                 $tradeModel->date = $trade['date'];
                 $tradeModel->amount = $trade['amount'];
                 $tradeModel->price = $trade['price'];
                 $tradeModel->tid = $trade['tid'];
                 if ($tradeModel->save() && $tradeModel->tid > $lastSaved) {
                     $lastSaved = $tradeModel->tid;
                 } else {
                     var_dump($tradeModel->errors);
                 }
                 unset($tradeModel);
             }
         } while ($lastSaved < $lastCex);
     }
 }
 /**
  * This command echoes what you have entered as the message.
  * @param string $message the message to be echoed.
  */
 public function actionIndex()
 {
     foreach (self::$ticks as $tick) {
         $curl = new curl\Curl();
         //get http://example.com/
         $response = json_decode($curl->get('https://cex.io/api/order_book/' . $tick . '/?depth=10'), true);
         $orderbook = new Orderbook();
         $orderbook->oid = $response['id'];
         $orderbook->tick = $tick;
         $orderbook->timestamp = $response['timestamp'];
         $orderbook->bids = json_encode($response['bids']);
         $orderbook->asks = json_encode($response['asks']);
         $orderbook->pair = $response['pair'];
         $orderbook->save();
     }
 }
Example #14
0
 /**
  * Expands an URL
  * @param string $url URL to be expanded
  * @return string|boolean  The expanded URL if the longUrl is set in the response, FALSE otherwise.
  * @throws Exception if the request fails
  */
 public function expand($url)
 {
     $curl = new Curl();
     $resp = $curl->setOption(CURLOPT_SSL_VERIFYHOST, false)->setOption(CURLOPT_SSL_VERIFYPEER, false)->get($this->apiEndpoint . 'shortUrl=' . $url);
     if ($curl->responseCode !== 200) {
         if ($resp = json_decode($curl->response)) {
             throw new Exception(sprintf('Error: %s - Response: %s', $resp->error->message, $curl->response), $resp->error->code);
         } else {
             throw new Exception('Unknown Error. Response: ' . $curl->response, $curl->responseCode);
         }
     } else {
         $resp = json_decode($resp);
         if (!empty($resp->longUrl)) {
             return $resp->longUrl;
         }
     }
     return false;
 }
Example #15
0
 /**
  * Authorizes and returns authorization code
  * @author Adegoke Obasa <*****@*****.**>
  * @return mixed code
  * @throws Oauth2ClientException
  * @throws InvalidParamException
  */
 public function authorize()
 {
     $this->validateAuthParams();
     try {
         $response = $this->curl->setOption(CURLOPT_POSTFIELDS, http_build_query(array('grant_type' => self::GRANT_TYPE_AUTHORIZATION_CODE, 'client_id' => $this->clientId, 'client_secret' => $this->clientSecret, 'response_type' => self::RESPONSE_TYPE_CODE, 'state' => self::STATE_ALIVE)))->post($this->authUrl, false);
     } catch (InvalidParamException $invalidParamException) {
         throw new Oauth2ClientException($invalidParamException->getMessage());
     }
     return $this->handleAuthorizeResponse($response);
 }
Example #16
0
 public static function get_curl($url, $params)
 {
     $url .= '?' . http_build_query($params);
     $curl = new Curl();
     //        var_dump($url);die;
     $curl->setOption('CURLOPT_COOKIESESSION', true);
     return $curl->get($url);
     //        return \Yii::$app->getResponse()->redirect($url);
     //        var_dump($url);die;
     //        $myCurl = curl_init($url);
     //
     //        curl_setopt_array($myCurl, array(
     //            CURLOPT_URL => $url,
     //            CURLOPT_RETURNTRANSFER => true,
     //            CURLOPT_HEADER=>false
     //        ));
     //        $response = curl_exec($myCurl);
     //        curl_close($myCurl);
     //        return $response;
 }
 public function executeCommand($commandType, $entity, $source, $params = [], $protocol = 'http://')
 {
     if (!class_exists('\\linslin\\yii2\\curl\\Curl')) {
         throw new Exception('linslin\\yii2\\curl\\Curl is needed.');
     }
     $curl = new curl\Curl();
     $url = $protocol . $this->endpoint . strtolower($source);
     $queryString = ['apiKey=' . $this->apiKey];
     foreach ($params['GET'] as $key => $param) {
         if (!empty($param)) {
             $queryString[] = "{$key}=" . urlencode($param);
         }
     }
     $queryString = implode('&', $queryString);
     $url .= '?' . $queryString;
     Yii::trace($url, __METHOD__);
     if (!empty($params['POST'])) {
         $raw_response = $curl->setOption(CURLOPT_POSTFIELDS, json_encode(array_filter($params['POST'])))->post($url);
     } else {
         $raw_response = $curl->get($url);
     }
     if ($raw_response !== false) {
         $response = json_decode($raw_response, true);
         if ($response['Status']['Code'] !== 0) {
             throw new Exception('Code: ' . $response['Status']['Code'] . '. ' . $response['Status']['Message']);
         }
         switch ($commandType) {
             case 'COUNT':
                 return ArrayHelper::getValue($response, $this->count_path);
             case 'ALL':
                 return $response[$entity];
             case 'ONE':
                 return $response[$entity];
             case 'SAVE':
                 return $response;
         }
     } else {
         throw new Exception('Request Error with the following url: ' . $url);
     }
 }
Example #18
0
 /**
  * get sscode
  * @author NamDD
  * @since 1.0.0
  * @param
  * @return array ss
  */
 protected static function _api($url, $params, $method = 'post')
 {
     $curl = new curl\Curl();
     $curl->setOption(CURLOPT_HTTPHEADER, ['Content-Type:application/json']);
     if (isset(static::$api['proxy'])) {
         $curl->set_option(CURLOPT_PROXY, static::$api['proxy']);
     }
     if ($method == 'post') {
         $curl->setOption(CURLOPT_POSTFIELDS, json_encode($params, JSON_UNESCAPED_UNICODE));
     } else {
         $url = $url . '?' . http_build_query($params);
     }
     $res = $curl->{$method}($url);
     $res = json_decode($res, true);
     $status = $curl->responseCode;
     if ($status == 200) {
         \Yii::info('Api result: ' . print_r($params, true) . print_r($res, true));
         return $res;
     }
     \Yii::info('Api error: ' . print_r($params, true) . print_r($res, true));
     return [];
 }
 /**
  * Connect to EconoSim registry websites
  */
 protected function connectToRegistries()
 {
     $AuthClients = Yii::$app->esAuthClients->getClients();
     foreach ($AuthClients as $AuthClient) {
         $parts = parse_url($AuthClient->tokenUrl);
         echo "Please provide your login details for the registry at " . $parts['host'] . "\n";
         $username = $this->prompt("Username:"******"Password:");
         $url = $AuthClient->buildAuthUrl(['redirect_uri' => null, 'display_response' => 1]);
         // Build authorization URL
         $curl = new Curl();
         $response = $curl->setOption(CURLOPT_POSTFIELDS, http_build_query(['LoginForm' => ['username' => $username, 'password' => $password]]))->post($url);
         $arr = Json::decode($response);
         $success = ArrayHelper::getValue($arr, 'success');
         if ($success) {
             $code = ArrayHelper::getValue($arr, 'data.code');
             $accessToken = $AuthClient->fetchAccessToken($code, ['redirect_uri' => null]);
             // Get access token
             $this->Server->addAuthClient($AuthClient);
         } else {
             echo ArrayHelper::getValue($arr, 'error.message');
         }
     }
 }
 /**
  * Performs an http query to catering server.
  *
  * @param string $url
  * @return array
  */
 private function send($url)
 {
     $response = ['status_code' => self::CURL_EXCEPTION, 'content' => null];
     $curl = new Curl();
     try {
         $content = $curl->get($url);
         $response['status_code'] = $curl->responseCode;
         if ($curl->responseCode === 200) {
             $response['content'] = $content;
         }
     } catch (Exception $e) {
         error_log($e->getMessage());
     }
     return $response;
 }
Example #21
0
 public function updateZoHoContact($user = null)
 {
     // \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $curl = new curl\Curl();
     $response = $curl->setOption(CURLOPT_POSTFIELDS, http_build_query(array('JSONString' => '{  
                         "contact_name":"' . $user->company->name . '",
                         "company_name": "' . $user->company->name . '",
                         "payment_terms": 10,
                         "payment_terms_label": "Binnen 10 dagen",
                         "currency_id": "638713000000008020",
                         "custom_fields": [
                             {
                               "index": 1,
                               "value": "' . $user->id . '"
                             },
                             {
                               "index": 2,
                               "value": "' . $user->abonnement->Abonnementtypename . '"
                             },
                          ],
                         "billing_address": {
                             "address": "' . $user->company->adress . '",
                             "city": "' . $user->company->city . '",
                             "state": "",
                             "zip": "' . $user->company->zip . '",
                             "country": "' . $user->company->country . '",
                             "fax": ""
                           },
                           "shipping_address": {
                             "address": "' . $user->company->adress . '",
                             "city": "' . $user->company->city . '",
                             "state": "",
                             "zip": "' . $user->company->zip . '",
                             "country": "' . $user->company->country . '",
                             "fax": ""
                           },
                         "contact_persons": [
                             {
                               "salutation": "",
                               "first_name": "' . $user->profile->firstname . '",
                               "last_name": "' . $user->profile->lastname . '",
                               "email": "' . $user->email . '",
                               "phone": "' . $user->company->telephone . '",
                               "mobile": "' . $user->company->telephone . '",
                               "is_primary_contact": true
                             },
                           ]
                         }')))->put('https://invoice.zoho.com/api/v3/contacts/' . $user->userinvoice->zoho_contact_id . '?authtoken=90545fa01029567ccd0ad3447cbf843c');
     return $response;
 }
Example #22
0
 public function actionTaxes()
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $curl = new curl\Curl();
     $response = $curl->get('https://invoice.zoho.com/api/v3/settings/taxes?authtoken=90545fa01029567ccd0ad3447cbf843c');
     return $response;
 }
Example #23
0
 /**
  * Creates the base cURL object with the headers data.
  *
  * @return {@link Curl} object with the headers.
  */
 protected function createBaseCurlObject()
 {
     $curl = new curl\Curl();
     //Set headers.
     $curl->setOption(CURLOPT_HTTPHEADER, $this->createHeaders());
     //Override verification of SSL.
     $curl->setOption(CURLOPT_SSL_VERIFYPEER, false);
     return $curl;
 }
 /**
  * @param integer $cpid = contactperson_id
  * @param integer $a = active_dagen
  * @param integer $m = monthName
  * @throws NotFoundHttpException if the model cannot be found
  * return respons from zoho invoice creating
  */
 public function actionInv($cpid, $a, $m)
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $UserInvoiceMdl = UserInvoice::findOne(['user_id' => $cpid]);
     $abonnementType = $query = UserActivities::find()->select("aktieve_dagen,full_name, monthName")->where("contactperson_id=" . $cpid . " and monthName =" . $m)->all();
     //print_r($query); exit;
     return \yii\helpers\Json::encode($query);
     exit;
     //haal contact persoon op
     $curl = new curl\Curl();
     $resp = $curl->setOption(CURLOPT_POSTFIELDS, http_build_query(array('')))->GET('https://invoice.zoho.com/api/v3/contacts/' . $UserInvoiceMdl->zoho_contact_id . '?authtoken=90545fa01029567ccd0ad3447cbf843c');
     $obj = json_decode($resp);
     // echo  $obj->contact->primary_contact_id; exit; //638713000000068053
     //echo $obj->contact_id; exit;
     $curl = new curl\Curl();
     $response = $curl->setOption(CURLOPT_POSTFIELDS, http_build_query(array('JSONString' => '{
                         "customer_id"="638713000000068045",
                         "template_id"="638713000000025001",
                         "line_items":[
                             {"item_id": "",
                             "name":"Jaar abonnement",
                             "item_name":"Jaar abonnement",
                             "status": "active",
                             "source": "user",
                             "is_linked_with_zohocrm": false,
                             "description": "Tarief voor P.adriaanse maand Juli 2015",
                             "rate": 0.41,
                             "quantity": 31.0,
                             "tax_id":"638713000000047019",
                             "tax_name": "BTW21","tax_percentage": 21
                             },
                             {"item_id": "",
                             "name":"Jaar abonnement",
                             "item_name":"Jaar abonnement",
                             "status": "active",
                             "source": "user",
                             "is_linked_with_zohocrm": false,
                             "description": "Tarief voor Arnord Zwagerman  Juli 2015",
                             "rate": 0.41,
                             "quantity": 28.0,
                             "tax_id":"638713000000047019",
                             "tax_name": "BTW21","tax_percentage": 21
                             }
                         ]
                         
                     }')))->POST('https://invoice.zoho.com/api/v3/invoices?authtoken=90545fa01029567ccd0ad3447cbf843c');
     return $response;
 }
Example #25
0
 public static function fetchData($url, $apiKey = null, $timeout = 30)
 {
     $curl = new curl\Curl();
     $headers = [];
     if ($apiKey !== null) {
         $headers[] = 'X-Api-Key: ' . addslashes($apiKey) . '';
     }
     $curl->setOption(CURLOPT_CONNECTTIMEOUT, $timeout);
     $curl->setOption(CURLOPT_TIMEOUT, $timeout);
     $curl->setOption(CURLOPT_HTTPHEADER, $headers);
     try {
         $response = $curl->get($url, false);
     } catch (\Exception $e) {
         $response = null;
     }
     if (empty($response) || !is_array($response)) {
         return ['data' => false, 'error' => true, 'responseCode' => (int) $curl->responseCode];
     }
     return ['data' => $response, 'error' => false, 'responseCode' => (int) $curl->responseCode];
 }
Example #26
0
 public function actionGeo()
 {
     $model = new models\GeoForm();
     $model->street = '1600 Amphitheatre Pkwy';
     $model->city = 'Mountain View';
     $model->state = 'CA';
     $model->zipcode = '94043';
     $model->country = 'USA';
     $googleGeo = new \stdClass();
     $mapQuest = new \stdClass();
     $bingMap = new \stdClass();
     $returnArray = [];
     $allDataArray = [];
     if ($model->load(Yii::$app->request->post())) {
         $curl = new Curl();
         //Start google operation
         $googleGeo->googleApiKey = 'AIzaSyB_BgHnfwBhEQVpy9l0y8OBYXvJamzTR9E';
         $googleGeo->queryString = str_replace(" ", "+", $model->street . ',' . $model->city . ',' . $model->state . ' ' . $model->zipcode . ',' . $model->country);
         $googleGeo->queryUrl = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . $googleGeo->queryString . '&key=' . $googleGeo->googleApiKey;
         $googleGeo->response = json_decode($curl->get($googleGeo->queryUrl));
         $returnArray['latLon']['google'] = $googleGeo->response->results ? $googleGeo->response->results[0]->geometry->location : false;
         $allDataArray['google'] = $googleGeo->response;
         //            var_dump($googleGeo->response->results[0]->geometry);
         //MapQuest operation
         $mapQuest->apiKey = 'Fmjtd%7Cluurn10b21%2C72%3Do5-9wyah4';
         $mapQuest->queryString = str_replace(" ", "%20", 'street=' . $model->street . '&city=' . $model->city . '&state=' . $model->state . '&postalcode=' . $model->zipcode . '&country=' . $model->country);
         $mapQuest->queryUrl = 'http://www.mapquestapi.com/geocoding/v1/address?key=' . $mapQuest->apiKey . '&' . $mapQuest->queryString;
         $mapQuest->response = json_decode($curl->get($mapQuest->queryUrl));
         $returnArray['latLon']['mapQuest'] = $googleGeo->response->results ? $mapQuest->response->results[0]->locations[0]->latLng : false;
         $allDataArray['mapQuest'] = $mapQuest->response;
         //Microsoft logic
         $bingMap->apiKey = 'AjC1HSirwHxS3uUD7es9zOd3D3mMuQPjpVmtyOy2YgYOlfonUOkKXZOPc_q0wQFp';
         $bingMap->queryUrl = str_replace(" ", "%20", 'http://dev.virtualearth.net/REST/v1/Locations?CountryRegion=' . $model->country . '&adminDistrict=' . $model->state . '&locality=' . $model->city . '&postalCode=' . $model->zipcode . '&addressLine=' . $model->street . '&key=' . $bingMap->apiKey);
         $bingMap->response = json_decode($curl->get($bingMap->queryUrl));
         $returnArray['latLon']['bingMap'] = $bingMap->response->resourceSets ? $bingMap->response->resourceSets[0]->resources[0]->point->coordinates : false;
         $allDataArray['bingMap'] = $bingMap->response;
     }
     return $this->render('geo', ['model' => $model, 'data' => $returnArray, 'allData' => $allDataArray]);
 }
Example #27
0
 /**
  * @param array $params [
  *  'type'=>'',         // optional parameter (see Http::ARUBA_CREDIT_TYPE_* const)
  * ]
  * @param array $return return data
  * @return bool
  */
 public function checkCredit($params = [], &$return)
 {
     $mandatoryParams = ['user', 'pass'];
     $staticParams = ['user' => $this->user, 'pass' => $this->pass];
     $params = array_merge($params, $staticParams);
     if (!array_key_exists('type', $params) && !empty($this->type)) {
         $params['type'] = $this->type;
     }
     $errors = $this->checkMandatoryParams($params, $mandatoryParams);
     if ($errors !== false) {
         $return = $errors;
         return false;
     }
     $post = http_build_query($params);
     $curl = new Curl();
     $result = $curl->setOption(CURLOPT_POSTFIELDS, $post)->post($this->urlCredit);
     Yii::info($result);
     if (preg_match($this->matchPattern, $result, $ret)) {
         if (count($ret) == 3) {
             $return = [$ret[2]];
             return $ret[1] == 'OK';
         }
     }
     return false;
 }
 /**
  * @param $url
  * @throws HttpException
  */
 public function checkUrl($url)
 {
     $curl = new curl\Curl();
     $curl->setOption(CURLOPT_SSL_VERIFYHOST, false);
     $curl->setOption(CURLOPT_FOLLOWLOCATION, true);
     $curl->setOption(CURLOPT_RETURNTRANSFER, true);
     $curl->setOption(CURLOPT_AUTOREFERER, true);
     $curl->setOption(CURLOPT_CONNECTTIMEOUT, 10);
     $curl->setOption(CURLOPT_TIMEOUT, 10);
     $curl->setOption(CURLOPT_MAXREDIRS, 10);
     $curl->setOption(CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36');
     $curl->get($url);
     if ($curl->responseCode != 200) {
         throw new HttpException(400, 'Something is wrong with your URL. Status code: ' . $curl->responseCode);
     }
 }
Example #29
0
 public function get($url)
 {
     $curl = new curl\Curl();
     return $curl->get($url);
 }
Example #30
0
 public function deleteZoHoContact($user = null)
 {
     // \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     if ($user->userInvoice) {
         $curl = new curl\Curl();
         $response = $curl->setOption(CURLOPT_POSTFIELDS, http_build_query(array()))->delete('https://invoice.zoho.com/api/v3/contacts/' . $user->userInvoice->zoho_contact_id . '?authtoken=90545fa01029567ccd0ad3447cbf843c');
         return $response;
     }
 }