@ 2017-07-11T10:29:40Z <?php
/**
* Набор методов для запроса к API uCoz. Версия для uCoz PHP сервера
* @author Sergey Driver86 Pugovkin <sergey@pugovk.in> – разработчик методов для запроса (php версия)
* @author Dmitry Kiselev <api@ucoz.net> – модификация и адаптация под uAPI + images. api.ucoz.net
* @version 2.2 от 15 августа 2016 – fixed POST for category
*/
/**
Ссылка на ваш сайт в юкозе, для обращения к uAPI
Обратите внимание, что нужно вводить с / на конце.
Если у сайта есть прикрепленный домен – необходимо указывать его.
Если же сайт доступен по wwww – сайт необходимо указывать вместе с www. Например: http://www.mywebsite.ucoz.ru/ или http://www.mywebsite.com/
*/
$myWebsite = 'https://utemplate.pro/';
/**
Закончили формировать ссылку
*/
class Request {
/**
* Настройки
* @var array
*/
public $config;
/**
* Обязательные параметры, передаваемые через URL при запросе к API
* @var array
*/
private $params;
/**
* Конструктор класса
* @param array $config Настройки
*/
function __construct($config = array()) {
$this->config = $config;
$this->params = array(
'oauth_version' => '1.0',
'oauth_timestamp' => time(),
'oauth_nonce' => md5(microtime() . mt_rand()),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_consumer_key' => $this->config['oauth_consumer_key'],
'oauth_token' => $this->config['oauth_token'],
);
}
/**
* Создание подписи запроса
* @param string $method Метод запроса, например GET
* @param string $url URL запроса, например /blog
* @param string $params Все параметры, передаваемые через URL при запросе к API
* @return string
*/
private function getSignature($method, $url, $params) {
ksort($params);
$baseString = strtoupper($method) . '&' . urlencode($url) . '&' . urlencode(strtr(http_build_query($params), array ('+' => '%20')));
return urlencode(base64_encode(hash_hmac('sha1', $baseString, $this->config['oauth_consumer_secret'] . '&' . $this->config['oauth_token_secret'], true)));
}
/**
* Возвращает базовое имя файла для использования в подписи запроса
* @param array $match Совпадения при поиске по регулярному выражению preg_replace_callback
* @return string
*/
private function getBaseName($match) {
return basename($match[1]);
}
/**
* Запрос к API методом GET
* @param string $url URL запроса, например /blog
* @param array $data Массив данных
* @return array
*/
public function get($url, $data = array()) {
global $myWebsite;
$this->params['oauth_nonce'] = md5(microtime() . mt_rand());
$url = $myWebsite.'uapi' . trim(strtolower($url), '').'';
$queryString = http_build_query($this->params + $data + array('oauth_signature' => $this->getSignature('GET', $url, $this->params + $data)));
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_URL, $url . '?' . $queryString);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
/**
* Запрос к API методом POST
* @param string $url URL запроса, например /blog
* @param array $data Массив данных
* @return array
*/
public function post($url, $data) {
global $myWebsite;
$this->params['oauth_nonce'] = md5(microtime() . mt_rand());
/**
Делаем так, чтобы изображения при отправке отправлялись,
а не валились в инвалид сигнутаре
*/
$x=1;
while ($x<50) {
if(empty($data['file'.$x])) break;
$getfile1others = basename($data['file'.$x]);
$findme = '@';
$pos = strpos($getfile1others, $findme);
if ($pos === false) {
$getfile1shop_array = array(
'file'.$x => '@'.$getfile1others
);
} else {
$getfile1shop_array = array(
'file'.$x => ''.$getfile1others
);
}
unset($data['file'.$x]);
$data = array_merge($getfile1shop_array, $data);
$x++;
}
if(!empty($data['file_add_cnt'])) {
$allcountfilesshop = $data['file_add_cnt'];
}
if ($url == '/shop/editgoods') {
$i= $allcountfilesshop;
while ($i<50) {
if(empty($data['file_add_'.$i]) && $data['file_add_'.$i] != 'file_add_cnt') break;
$getfile1shop = basename($data['file_add_'.$i]);
$findme = '@';
$pos = strpos($getfile1shop, $findme);
if ($pos === false) {
$getfile1shop_array = array(
'file_add_'.$i => '@'.$getfile1shop
);
} else {
$getfile1shop_array = array(
'file_add_'.$i => ''.$getfile1shop
);
}
unset($data['file_add_'.$i]);
$data = array_merge($getfile1shop_array, $data);
$i++;
}
}
$url = $myWebsite.'uapi' . trim(strtolower($url), '').'/';
$sign = array('oauth_signature' => $this->getSignature('POST', $url, $this->params + preg_replace_callback('/^@(.+)$/', array($this, 'getBaseName'), $data)));
$queryString = http_build_query($sign);
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_URL, $url . '?' . $forcurlpost);
curl_setopt($curl, CURLOPT_POST, true);
$forcurlpost = array_merge($this->params + $data, $sign);
curl_setopt($curl, CURLOPT_POSTFIELDS, $forcurlpost);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
/**
* Запрос к API методом PUT
* @param string $url URL запроса, например /blog
* @param array $data Массив данных
* @return array
*/
public function put($url, $data) {
global $myWebsite;
$this->params['oauth_nonce'] = md5(microtime() . mt_rand());
/**
Делаем так, чтобы изображения при отправке отправлялись,
а не валились в инвалид сигнутаре
*/
$x=1;
while ($x<50) {
if(empty($data['file'.$x])) break;
$getfile1others = basename($data['file'.$x]);
$findme = '@';
$pos = strpos($getfile1others, $findme);
if ($pos === false) {
$getfile1shop_array = array(
'file'.$x => '@'.$getfile1others
);
} else {
$getfile1shop_array = array(
'file'.$x => ''.$getfile1others
);
}
unset($data['file'.$x]);
$data = array_merge($getfile1shop_array, $data);
$x++;
}
if(!empty($data['file_add_cnt'])) {
$allcountfilesshop = $data['file_add_cnt'];
}
if ($url == '/shop/editgoods') {
$i= $allcountfilesshop;
while ($i<50) {
if(empty($data['file_add_'.$i]) && $data['file_add_'.$i] != 'file_add_cnt') break;
$getfile1shop = basename($data['file_add_'.$i]);
$findme = '@';
$pos = strpos($getfile1shop, $findme);
if ($pos === false) {
$getfile1shop_array = array(
'file_add_'.$i => '@'.$getfile1shop
);
} else {
$getfile1shop_array = array(
'file_add_'.$i => ''.$getfile1shop
);
}
unset($data['file_add_'.$i]);
$data = array_merge($getfile1shop_array, $data);
$i++;
}
}
$url = $myWebsite.'uapi' . trim(strtolower($url), '').'/';
$sign = array('oauth_signature' => $this->getSignature('PUT', $url, $this->params + preg_replace_callback('/^@(.+)$/', array($this, 'getBaseName'), $data)));
$queryString = http_build_query($sign);
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_URL, $url . '?' . $queryString);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
$forcurlpost = array_merge($this->params + $data, $sign);
curl_setopt($curl, CURLOPT_POSTFIELDS, $forcurlpost);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
/**
* Запрос к API методом DELETE
* @param string $url URL запроса, например /blog
* @param array $data Массив данных
* @return array
*/
public function delete($url, $data) {
global $myWebsite;
$this->params['oauth_nonce'] = md5(microtime() . mt_rand());
$url = $myWebsite.'uapi' . trim(strtolower($url), '').'/';
$queryString = http_build_query($this->params + $data + array('oauth_signature' => $this->getSignature('DELETE', $url, $this->params + $data)));
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_URL, $url . '?' . $queryString);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
$result = json_decode(curl_exec($curl), true);
curl_close($curl);
return $result;
}
}
// ==============================================================
// до сюда нельзя удалять
error_reporting(E_ERROR) ;
/**
* Набор методов для запроса к API uCoz
* @author Dmitry Kiselev <api@ucoz.net> – Демонстрация обращения к uAPImodule.php
* @version 2.0 от 24 марта 2016
*/
$request = new Request(array(
'oauth_consumer_key' => 'edl92g42SHm84bnRbZDW',
'oauth_consumer_secret' => 'wUClCAtSsjvCDs6nDR46zOYItvjKwn',
'oauth_token' => 'A9PL.uc1uujmmzFXmf13Gbeyx2BT1AEiVLiiOkLz',
'oauth_token_secret' => 'CWDmh4QfXOqzIXoEVfpPV9EUoSlEKjNEldItCgiD'
));
// Используем
// phpinfo(32);
$x = '0';
$response = $request->get('/shop/invoices/', array(
'page' => 0,
'id' => '49938,49937,49936,49935,49934,49933,49932,49931,49918,49915,49905,49904,49893,49867,49866,49865,49864,49861,49853,49852,49846,49845,49842,49833,49832,49831,49815,49814,49813,49801,49800,49799,49798,49797,49796,49795,49769,49768,49767,49766,49759,49744,49737,49736,49735,49720,49719,49718,49717,49716,49715,49687,49686,49675,49674,49673,49672,49660,49659,49658,49657,49652,49645,49644,49643,49642,49633,49632,49619,49618,49617,49616,49600,49599,49598,49586,49585,49583,49580,49576,49575,49574,49559,49555,49554,49553,49552,49551,49550,49549,49548,49547,49546,49545,49544,49543,49542,49541,49540,49539,49538,49536,49535,49534,49533'
));
$response = json_decode($response, true);
//echo '<pre>';
//print_r($response);
//echo '</pre>';
while ($x<21) //2090
{
$response2 = $request->get('/shop/order/', array(
'order' => $response['success']['orders'][$x]['order_hash']
));
$response2 = json_decode($response2, true);
// $response = $request->get('/shop/invoices/', array(
// 'page' => $x,
// 'id' => '40359,40360,40361,40366,40367,40368,40369,40394,40395,40396,40399,40400,40401,40402,40403,40406,40412,40413,40414,40415,40416,40432,40433,40434,40435,40448,40449,40453,40454,40455,40465,40466,40467,40471,40472,40473,40474,40475,40476,40483,40484,40485,40486,40487,40509,40510,40511,40535,40536,40537,40538,40539,40577,40578,40579,40581,40582,40583,40605,40606,40607,40608,40609,40610,40625,40626,40627,40646,40647,40648,40649,40650,40662,40663,40664,40665,40666,40667,40690,40691,40693,40694,40707,40708,40709,40710,40711,40712,40713,40714,40715,40727,40728,40729,40730,40731,40732,40744,40747,40748,40759,40760,40761,40768,40769,40782,40785,40786,40787,40806,40821,40822,40823,40826,40827,40855,40858,40859,40860,40861,40862,40863,40878,40879,40882,40883,40884,40885,40886,40891,40893,40911,40912,40913,40914,40915,40916,40928,40929,40930,40931,40963,40964,40965,40966,40967,40968,40969,40974,40975,40976'
// ));
// echo '<pre>';
// print_r(json_decode($response, true));
// echo '</pre>';
// нам нужны profit, id,
// echo '<br />'.$response['success']['orders'][$page]['order_hash'].'<br />';
// echo '<pre>';
// print_r(json_decode($response2, true));
// echo '</pre>';
$goods_id = $response2['success']['order_digital_goods']['goods'][0]['id'];
$name = $response2['success']['order_goods']['goods'][$goods_id]['added_user'];
$price = $response2['success']['order_goods']['goods'][$goods_id]['price']['price_raw'];
$num = $response2['success']['order_nom'];
$howmusch = '0';
echo ' <table>
<tr>
<td>'.$num.'</td>
<td>'.$name.'</td>
<td>'.$price.'</td>
</tr>
</table> ';
$x++;
}
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.4.1 0.003 0.012 15.23 7.4.0 0.007 0.011 15.06 7.3.13 0.003 0.016 15.03 7.3.12 0.011 0.006 15.10 7.3.11 0.006 0.010 15.03 7.3.10 0.006 0.009 14.98 7.3.9 0.005 0.012 15.06 7.3.8 0.005 0.011 14.93 7.3.7 0.006 0.009 14.93 7.3.6 0.005 0.009 14.91 7.3.5 0.004 0.009 14.98 7.3.4 0.005 0.008 14.98 7.3.3 0.003 0.011 15.01 7.3.2 0.006 0.010 16.67 7.3.1 0.005 0.010 16.61 7.3.0 0.005 0.008 16.74 7.2.26 0.008 0.011 15.22 7.2.25 0.009 0.008 15.16 7.2.24 0.010 0.007 15.17 7.2.23 0.008 0.008 15.22 7.2.22 0.006 0.008 15.20 7.2.21 0.009 0.007 15.22 7.2.20 0.003 0.010 15.14 7.2.19 0.010 0.008 15.21 7.2.18 0.005 0.011 15.14 7.2.17 0.010 0.005 15.22 7.2.16 0.005 0.011 15.12 7.2.15 0.009 0.007 16.97 7.2.14 0.009 0.006 17.01 7.2.13 0.010 0.006 16.94 7.2.12 0.008 0.007 16.95 7.2.11 0.009 0.008 16.97 7.2.10 0.001 0.013 17.00 7.2.9 0.005 0.011 17.03 7.2.8 0.010 0.006 16.92 7.2.7 0.003 0.011 17.00 7.2.6 0.005 0.010 16.86 7.2.5 0.004 0.010 16.81 7.2.4 0.009 0.007 17.01 7.2.3 0.007 0.006 16.91 7.2.2 0.008 0.007 16.99 7.2.1 0.007 0.009 17.00 7.2.0 0.003 0.012 17.51 7.1.33 0.008 0.007 15.82 7.1.32 0.003 0.010 15.82 7.1.31 0.004 0.010 15.86 7.1.30 0.009 0.005 15.70 7.1.29 0.004 0.009 15.77 7.1.28 0.007 0.009 15.80 7.1.27 0.002 0.013 15.77 7.1.26 0.007 0.009 15.78 7.1.25 0.004 0.011 15.82 7.1.24 0.005 0.011 15.87 7.1.23 0.007 0.009 15.78 7.1.22 0.006 0.008 15.80 7.1.21 0.010 0.003 15.79 7.1.20 0.002 0.010 15.76 7.1.19 0.003 0.008 15.81 7.1.18 0.008 0.006 15.88 7.1.17 0.006 0.009 15.63 7.1.16 0.007 0.008 15.78 7.1.15 0.004 0.011 15.91 7.1.14 0.004 0.010 15.48 7.1.13 0.005 0.009 15.88 7.1.12 0.007 0.004 15.89 7.1.11 0.007 0.007 15.72 7.1.10 0.008 0.008 16.56 7.1.9 0.003 0.009 16.00 7.1.8 0.006 0.007 15.86 7.1.7 0.006 0.007 16.33 7.1.6 0.012 0.008 22.25 7.1.5 0.007 0.012 22.16 7.1.4 0.011 0.011 22.00 7.1.3 0.010 0.008 22.05 7.1.2 0.014 0.006 22.04 7.1.1 0.009 0.008 16.08 7.1.0 0.008 0.008 15.96 7.0.33 0.006 0.008 15.49 7.0.32 0.005 0.009 15.52 7.0.31 0.006 0.011 15.34 7.0.30 0.004 0.006 15.59 7.0.29 0.007 0.008 15.33 7.0.28 0.005 0.010 15.46 7.0.27 0.004 0.011 15.45 7.0.26 0.005 0.007 15.40 7.0.25 0.002 0.010 15.32 7.0.24 0.003 0.008 15.35 7.0.23 0.009 0.007 15.55 7.0.22 0.009 0.004 15.44 7.0.21 0.005 0.009 15.27 7.0.20 0.003 0.010 16.04 7.0.19 0.005 0.007 15.78 7.0.18 0.008 0.005 15.74 7.0.17 0.007 0.007 15.69 7.0.16 0.005 0.012 15.73 7.0.15 0.003 0.010 15.74 7.0.14 0.006 0.007 15.75 7.0.13 0.006 0.011 15.82 7.0.12 0.006 0.008 15.87 7.0.11 0.006 0.007 15.59 7.0.10 0.001 0.011 15.77 7.0.9 0.004 0.010 15.87 7.0.8 0.004 0.009 15.77 7.0.7 0.006 0.008 15.71 7.0.6 0.002 0.012 15.58 7.0.5 0.007 0.007 15.83 7.0.4 0.009 0.006 14.47 7.0.3 0.007 0.007 14.49 7.0.2 0.007 0.007 14.32 7.0.1 0.005 0.008 14.42 7.0.0 0.004 0.010 14.35 5.6.40 0.003 0.011 14.56 5.6.39 0.004 0.009 14.73 5.6.38 0.006 0.006 14.64 5.6.37 0.006 0.009 14.65 5.6.36 0.010 0.003 14.62 5.6.35 0.007 0.004 14.65 5.6.34 0.006 0.011 14.68 5.6.33 0.005 0.009 14.44 5.6.32 0.005 0.006 14.49 5.6.31 0.009 0.007 14.51 5.6.30 0.003 0.012 14.66 5.6.29 0.005 0.008 14.55 5.6.28 0.006 0.012 14.81 5.6.27 0.009 0.006 14.68 5.6.26 0.005 0.008 14.47 5.6.25 0.009 0.006 14.53 5.6.24 0.004 0.009 14.68 5.6.23 0.010 0.005 14.49 5.6.22 0.005 0.009 14.46 5.6.21 0.005 0.010 14.51 5.6.20 0.010 0.006 14.63 5.6.19 0.005 0.005 14.47 5.6.18 0.005 0.010 14.69 5.6.17 0.006 0.009 14.53 5.6.16 0.005 0.007 14.48 5.6.15 0.009 0.004 14.78 5.6.14 0.006 0.005 14.76 5.6.13 0.006 0.008 14.62 5.6.12 0.006 0.008 14.69 5.6.11 0.005 0.007 14.69 5.6.10 0.002 0.011 14.56 5.6.9 0.005 0.007 14.71 5.6.8 0.007 0.005 14.66 5.6.7 0.009 0.003 14.50 5.6.6 0.005 0.010 14.55 5.6.5 0.007 0.006 14.42 5.6.4 0.007 0.007 14.29 5.6.3 0.006 0.008 14.55 5.6.2 0.005 0.007 14.51 5.6.1 0.003 0.007 14.53 5.6.0 0.000 0.012 14.53
preferences:dark mode live preview
35.74 ms | 400 KiB | 5 Q