Пример #1
0
 private function insert(array $data)
 {
     $id = $data['id'];
     foreach ($data as $k => $v) {
         if ($k == 'id') {
             continue;
         }
         $motor = 'string';
         if (fnmatch('*_id', $k)) {
             $motor = 'int';
             $v = (int) $v;
         } elseif (is_numeric($v)) {
             if (fnmatch('*.*', $v) || fnmatch('*.*', $v)) {
                 $motor = 'float';
                 $v = (double) $v;
             } else {
                 $motor = 'int';
                 $v = (int) $v;
             }
         } else {
             if (!is_string($v)) {
                 throw new Exception("An error occured to save this model. Please check the values.");
             }
             $length = Inflector::length($v);
             $motor = 255 < $length ? 'text' : 'string';
         }
         $fieldRow = $motor . '_value';
         $row = lib('mysql', 'kvdatas')->where('object_database', '=', $this->db)->where('object_table', '=', $this->table)->where('object_field', '=', $k)->where('object_id', '=', $id)->first();
         if ($row) {
             $row->{$fieldRow} = $v;
             $row->save();
         } else {
             lib('mysql', 'kvdatas')->create(['object_database' => $this->db, 'object_table' => $this->table, 'object_field' => $k, 'object_id' => $id, $fieldRow => $v]);
         }
     }
 }
Пример #2
0
 public static function getToken($clientId, $clientSecret, $environment = 'development')
 {
     $url = 'development' == $environment ? 'https://api.sandbox.paypal.com/v1/oauth2/token' : 'https://api.paypal.com/v1/oauth2/token';
     $auth = $clientId . ':' . $clientSecret;
     $ch = curl_init();
     $postData = "grant_type=client_credentials";
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_PORT, 443);
     curl_setopt($ch, CURLOPT_VERBOSE, 0);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json", "Accept-Language: en_US", "Content-length: " . Inflector::length($postData)));
     curl_setopt($ch, CURLOPT_USERPWD, $auth);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
     $data = json_decode(curl_exec($ch), true);
     curl_close($ch);
     return $data['access_token'];
 }