protected static function _create($params = null) { self::_validateParams($params); $url = static::classUrl(); list($response) = static::_staticRequest('post', $url, $params); return Util\Util::convertToDeviceToolObject($response); }
public function testIsList() { $list = array(5, 'nstaoush', array()); $this->assertTrue(Util\Util::isList($list)); $notlist = array(5, 'nstaoush', array(), 'bar' => 'baz'); $this->assertFalse(Util\Util::isList($notlist)); }
/** * @return null|string The instance URL for this resource. It needs to be special * cased because it doesn't fit into the standard resource pattern. * * @throws Error\InvalidRequest */ public function instanceUrl() { $id = $this['id']; if (!$id) { $class = get_class($this); $msg = "Could not determine which URL to request: {$class} instance " . "has invalid ID: {$id}"; throw new Error\InvalidRequest($msg, null); } if ($this['customer']) { $parent = $this['customer']; $base = Customer::classUrl(); $path = 'sources'; } elseif ($this['account']) { $parent = $this['account']; $base = Account::classUrl(); $path = 'external_accounts'; } elseif ($this['recipient']) { $parent = $this['recipient']; $base = Recipient::classUrl(); $path = 'cards'; } else { return; } $parent = Util\Util::utf8($parent); $id = Util\Util::utf8($id); $parentExtn = urlencode($parent); $extn = urlencode($id); return "{$base}/{$parentExtn}/{$path}/{$extn}"; }
public function retrieve($id, $params = null, $opts = null) { list($url, $params) = $this->extractPathAndUpdateParams($params); $id = Util\Util::utf8($id); $extn = urlencode($id); list($response, $opts) = $this->_request('get', "{$url}/{$extn}", $params, $opts); return Util\Util::convertToStripeObject($response, $opts); }
public function testRetrieve() { self::authorizeFromEnv(); $d = Balance::retrieve(); $this->assertSame($d->object, "balance"); $this->assertTrue(Util\Util::isList($d->available)); $this->assertTrue(Util\Util::isList($d->pending)); }
/** * @param array|null $params * @param array|string|null $opts * * @return Invoice The upcoming invoice. */ public static function upcoming($params = null, $opts = null) { $url = static::classUrl() . '/upcoming'; list($response, $opts) = static::_staticRequest('get', $url, $params, $opts); $obj = Util\Util::convertToStripeObject($response->json, $opts); $obj->setLastResponse($response); return $obj; }
/** * @return string The instance URL for this resource. It needs to be special * cased because it doesn't fit into the standard resource pattern. */ public function instanceUrl() { if ($result = parent::instanceUrl()) { return $result; } $id = $this['id']; $id = Util\Util::utf8($id); $extn = urlencode($id); $base = self::classUrl(); return "{$base}/{$extn}"; }
public function testUtf8() { // UTF-8 string $x = "é"; $this->assertSame(Util\Util::utf8($x), $x); // Latin-1 string $x = "é"; $this->assertSame(Util\Util::utf8($x), "é"); // Not a string $x = true; $this->assertSame(Util\Util::utf8($x), $x); }
/** * @return string The instance URL for this resource. It needs to be special * cased because it doesn't fit into the standard resource pattern. */ public function instanceUrl() { $result = parent::instanceUrl(); if ($result) { return $result; } else { $id = $this['id']; $id = Util\Util::utf8($id); $extn = urlencode($id); $base = BitcoinReceiver::classUrl(); return "{$base}/{$extn}"; } }
/** * {@inheritdoc} */ public function instanceUrl() { $id = $this['id']; $customer = $this['customer']; if (!$id) { throw new Error\InvalidRequest('Could not determine which URL to request: ' . "class instance has invalid ID: {$id}", null); } $id = Util\Util::utf8($id); $customer = Util\Util::utf8($customer); $base = Customer::classUrl(); $customerExtn = urlencode($customer); $extn = urlencode($id); return "{$base}/{$customerExtn}/subscriptions/{$extn}"; }
/** * @return string The API URL for this Stripe transfer reversal. */ public function instanceUrl() { $id = $this['id']; $transfer = $this['transfer']; if (!$id) { throw new Error\InvalidRequest("Could not determine which URL to request: " . "class instance has invalid ID: {$id}", null); } $id = Util\Util::utf8($id); $transfer = Util\Util::utf8($transfer); $base = Transfer::classUrl(); $transferExtn = urlencode($transfer); $extn = urlencode($id); return "{$base}/{$transferExtn}/reversals/{$extn}"; }
/** * @return string The API URL for this Pingpp refund. */ public function instanceUrl() { $id = $this['id']; $charge = $this['charge']; if (!$id) { throw new Error\InvalidRequest("Could not determine which URL to request: " . "class instance has invalid ID: {$id}", null); } $id = Util\Util::utf8($id); $charge = Util\Util::utf8($charge); $base = Charge::classUrl(); $chargeExtn = urlencode($charge); $extn = urlencode($id); return "{$base}/{$chargeExtn}/refunds/{$extn}"; }
private static function _encodeObjects($d) { if ($d instanceof ApiResource) { return Util\Util::utf8($d->id); } elseif ($d === true) { return 'true'; } elseif ($d === false) { return 'false'; } elseif (is_array($d)) { $res = array(); foreach ($d as $k => $v) { $res[$k] = self::_encodeObjects($v); } return $res; } else { return Util\Util::utf8($d); } }
/** * @return string The instance URL for this resource. It needs to be special * cased because it doesn't fit into the standard resource pattern. */ public function instanceUrl() { $id = $this['id']; if (!$id) { $class = get_class($this); $msg = "Could not determine which URL to request: {$class} instance " . "has invalid ID: {$id}"; throw new Error\InvalidRequest($msg, null); } $id = Util\Util::utf8($id); $extn = urlencode($id); if (!$this['customer']) { $base = BitcoinReceiver::classUrl(); return "{$base}/{$extn}"; } else { $base = Customer::classUrl(); $parent = Util\Util::utf8($this['customer']); $parentExtn = urlencode($parent); return "{$base}/{$parentExtn}/sources/{$extn}"; } }
/** * @since 1.0 * @uses Util::pack() * * @return binary */ public function toBinary() { return Util\Util::pack(0x4d, 0x54, 0x68, 0x64) . Util\Util::pack(0x0, 0x0, 0x0, 0x6) . Util\Util::pack(0x0, $this->midiFormat) . Util\Util::pack($this->numTracks >> 8, $this->numTracks & 0xff) . Util\Util::pack($this->timeDivision >> 8, $this->timeDivision & 0xff); }
/** * @param array|null $params * @param array|string|null $opts * * @return Invoice The upcoming invoice. */ public static function upcoming($params = null, $opts = null) { $url = static::classUrl() . '/upcoming'; list($response, $opts) = static::_staticRequest('get', $url, $params, $opts); return Util\Util::convertToStripeObject($response, $opts); }
private function _curlRequest($method, $absUrl, $headers, $params) { $curl = curl_init(); $method = strtolower($method); $opts = array(); $requestSignature = NULL; if ($method == 'get') { $opts[CURLOPT_HTTPGET] = 1; if (count($params) > 0) { $encoded = self::encode($params); $absUrl = "{$absUrl}?{$encoded}"; } } elseif ($method == 'post' || $method == 'put') { if ($method == 'post') { $opts[CURLOPT_POST] = 1; } else { $opts[CURLOPT_CUSTOMREQUEST] = 'PUT'; } $rawRequestBody = json_encode($params); $opts[CURLOPT_POSTFIELDS] = $rawRequestBody; if ($this->privateKey()) { $signResult = openssl_sign($rawRequestBody, $requestSignature, $this->privateKey(), 'sha256'); if (!$signResult) { throw new Error\Api("Generate signature failed"); } } } elseif ($method == 'delete') { $opts[CURLOPT_CUSTOMREQUEST] = 'DELETE'; if (count($params) > 0) { $encoded = self::encode($params); $absUrl = "{$absUrl}?{$encoded}"; } } else { throw new Error\Api("Unrecognized method {$method}"); } if ($requestSignature) { $headers[] = 'Pingplusplus-Signature: ' . base64_encode($requestSignature); } $absUrl = Util\Util::utf8($absUrl); $opts[CURLOPT_URL] = $absUrl; $opts[CURLOPT_RETURNTRANSFER] = true; $opts[CURLOPT_CONNECTTIMEOUT] = 30; $opts[CURLOPT_TIMEOUT] = 80; $opts[CURLOPT_HTTPHEADER] = $headers; if (!Pingpp::$verifySslCerts) { $opts[CURLOPT_SSL_VERIFYPEER] = false; } curl_setopt_array($curl, $opts); $rbody = curl_exec($curl); if (!defined('CURLE_SSL_CACERT_BADFILE')) { define('CURLE_SSL_CACERT_BADFILE', 77); // constant not defined in PHP } $errno = curl_errno($curl); if ($errno == CURLE_SSL_CACERT || $errno == CURLE_SSL_PEER_CERTIFICATE || $errno == CURLE_SSL_CACERT_BADFILE) { array_push($headers, 'X-Pingpp-Client-Info: {"ca":"using Pingpp-supplied CA bundle"}'); $cert = $this->caBundle(); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_CAINFO, $cert); $rbody = curl_exec($curl); } if ($rbody === false) { $errno = curl_errno($curl); $message = curl_error($curl); curl_close($curl); $this->handleCurlError($errno, $message); } $rcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); return array($rbody, $rcode); }
/** * @since 1.0 * @uses Util::pack() * * @return binary */ public function toBinary() { return Util\Util::pack(0x4d, 0x54, 0x72, 0x6b) . Util\Util::pack($this->size >> 24) . Util\Util::pack($this->size >> 16 & 0xff) . Util\Util::pack($this->size >> 8 & 0xff) . Util\Util::pack($this->size & 0xff); }
protected static function _create($params = null, $options = null) { self::_validateParams($params); $base = static::baseUrl(); $url = static::classUrl(); list($response, $opts) = static::_staticRequest('post', $url, $params, $options); return Util\Util::convertToPingppObject($response, $opts); }
/** * Find a document's attachments. * * @link http://docs.couchdb.org/en/1.5.1/api/document/common.html#attachments * @param bool $attEncInfo * @param array $attsSince * @return array */ public function findAttachments($attEncInfo = false, array $attsSince = null) { $query = []; $query['attachments'] = true; $query['att_encoding_info'] = $attEncInfo; // include revisions if (!empty($attsSince)) { $attsSinceArray = []; foreach ($attsSince as $attsSinceValue) { $attsSinceArray[] = sprintf('"%s"', Util\Util::quote($attsSinceValue)); } $query['atts_since'] = sprintf('[%s]', join(',', $attsSinceArray)); } $data = $this->find($query); if (isset($data['_attachments'])) { return $data['_attachments']; } }
/** * @since 1.0 * @uses Util::getDeltaByteSequence() * * @return Util */ public function toBinary() { return Util\Util::getDeltaByteSequence($this->ticks); }
public function __toArray($recursive = false) { if ($recursive) { return Util\Util::convertStripeObjectToArray($this->_values); } else { return $this->_values; } }
protected static function _create($params = null, $options = null) { self::_validateParams($params); $base = static::baseUrl(); $url = static::classUrl(); list($response, $opts) = static::_staticRequest('post', $url, $params, $options); $obj = Util\Util::convertToStripeObject($response->json, $opts); $obj->setLastResponse($response); return $obj; }
protected function _delete($params = null, $options = null) { self::_validateParams($params); $url = $this->instanceUrl(); list($response, $opts) = $this->_request('delete', $url, $params, $options); $result = Util\Util::convertToUbivarObject($response, $opts); return $result[0]; }
/** * @param array $answers The answers to pass. * * @return QuestionSet The scored QuestionSet. */ protected function _score($answers) { $url = static::instanceUrl() . '/score'; // Weird request requires us to build the cURL request manually $params = ''; foreach ($answers as $key => $value) { $params = $params . 'answers[][{$key}]={$value}&'; } rtrim($params, '&'); $response = static::_makeRequest('post', $url, $params); return Util\Util::convertToBlockScoreObject($response); }
private function _requestRaw($method, $url, $params, $headers) { if (!array_key_exists($this->_apiBase, self::$_preFlight) || !self::$_preFlight[$this->_apiBase]) { self::$_preFlight[$this->_apiBase] = $this->checkSslCert($this->_apiBase); } $myApiKey = $this->_apiKey; if (!$myApiKey) { $myApiKey = Pingpp::$apiKey; } if (!$myApiKey) { $msg = 'No API key provided. (HINT: set your API key using ' . '"Pingpp::setApiKey(<API-KEY>)". You can generate API keys from ' . 'the Pingpp web interface. See https://pingxx.com/document/api for ' . 'details, or email support@pingxx.com if you have any questions.'; throw new Error\Authentication($msg); } $absUrl = $this->_apiBase . $url; $params = self::_encodeObjects($params, $method == 'post'); $langVersion = phpversion(); $uname = php_uname(); $ua = array('bindings_version' => Pingpp::VERSION, 'lang' => 'php', 'lang_version' => $langVersion, 'publisher' => 'pingplusplus', 'uname' => $uname); $defaultHeaders = array('X-Pingpp-Client-User-Agent' => json_encode($ua), 'User-Agent' => 'Pingpp/v1 PhpBindings/' . Pingpp::VERSION, 'Authorization' => 'Bearer ' . $myApiKey); if (Pingpp::$apiVersion) { $defaultHeaders['Pingplusplus-Version'] = Pingpp::$apiVersion; } if ($method == 'post') { $defaultHeaders['Content-type'] = 'application/json;charset=UTF-8'; } $requestHeaders = Util\Util::getRequestHeaders(); if (isset($requestHeaders['Pingpp-Sdk-Version'])) { $defaultHeaders['Pingpp-Sdk-Version'] = $requestHeaders['Pingpp-Sdk-Version']; } if (isset($requestHeaders['Pingpp-One-Version'])) { $defaultHeaders['Pingpp-One-Version'] = $requestHeaders['Pingpp-One-Version']; } $combinedHeaders = array_merge($defaultHeaders, $headers); $rawHeaders = array(); foreach ($combinedHeaders as $header => $value) { $rawHeaders[] = $header . ': ' . $value; } list($rbody, $rcode) = $this->_curlRequest($method, $absUrl, $rawHeaders, $params); return array($rbody, $rcode, $myApiKey); }
/** * @return OrderReturn The newly created return. */ public function returnOrder($params = null, $opts = null) { $url = $this->instanceUrl() . '/returns'; list($response, $opts) = $this->_request('post', $url, $params, $opts); return Util\Util::convertToStripeObject($response, $opts); }
<?php $start = microtime(true); //开启会话 session_start(); // 定义系统常量 define("DOCROOT", __DIR__ . DIRECTORY_SEPARATOR); define("SYSPATH", DOCROOT . "system" . DIRECTORY_SEPARATOR); define("APPPATH", DOCROOT . "app" . DIRECTORY_SEPARATOR); define("MODEL", SYSPATH); define("LIBPATH", SYSPATH . 'libs' . DIRECTORY_SEPARATOR); define("CONFILE", SYSPATH . "config.php"); //加载库 PHPActiveRecord TODO: 按需加载库 require_once LIBPATH . 'PHPActiveRecord' . DIRECTORY_SEPARATOR . 'ActiveRecord.php'; //自动加载类 require_once SYSPATH . 'Autoload.php'; spl_autoload_register('loadClassFile'); //获取配置 $GLOBALS['config'] = (include CONFILE); //根据配置文件进行设置 Util\Util::$env = $GLOBALS['config']['env']; //PHPActiveRecord 配置 ActiveRecord\Config::initialize(function ($cfg) { $cfg->set_model_directory($GLOBALS['config']['moddir']); $cfg->set_connections($GLOBALS['config']['dbconfig']); $cfg->set_default_connection(!isset($_SERVER['HTTP_APPNAME']) ? 'local' : 'sae'); }); // CURRENT_YIKE 为当前用户的 id define('CURRENT_YIKE', isset($_SESSION['yike_id']) ? intval($_SESSION['yike_id']) : null);
/** * @param array $answers The answers to pass. * * @return QuestionSet The scored QuestionSet. */ protected function _score($answers) { $url = static::instanceUrl() . '/score'; // Weird request requires us to build the cURL request manually $params = array(); foreach ($answers as $key => $value) { $params[] = "answers[][question_id]={$value['question_id']}"; $params[] = "answers[][answer_id]={$value['answer_id']}"; } $response = static::_makeRequest('post', $url, implode('&', $params)); return Util\Util::convertToBlockScoreObject($response); }