Advertisement
Guest User

Untitled

a guest
Apr 6th, 2018
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. <?php
  2. $url = 'https://service.tradesoft.ru/3/';
  3. $user = 'victormek';
  4. $password = 'MEKSTER11';
  5. $eurotradeUrl = 'shop_eurotradeplus_pl';
  6. $eurotradeLogin = 'NORDIC';
  7. $eurotradePassword = 'NORDIC11';
  8.  
  9. $request = getRequest('GetPriceList', getContainer('1069','A.B.S.'));
  10.  
  11. function getContainer($code, $producer, $itemHash = null) {
  12. return array(
  13. 'container' => array(
  14. array(
  15. 'provider' => $GLOBALS['eurotradeUrl'],
  16. 'login' => $GLOBALS['eurotradeLogin'],
  17. 'password' => $GLOBALS['eurotradePassword'],
  18. 'code' => $code,
  19. 'producer' => $producer,
  20. 'itemHash' => $itemHash
  21. )
  22. ));
  23. }
  24.  
  25. function getRequest($action, $extra = array()) {
  26. $params = array(
  27. 'service' => 'provider',
  28. 'action' => $action,
  29. 'user' => $GLOBALS['user'],
  30. 'password' => $GLOBALS['password'],
  31. ) + $extra;
  32. return $params;
  33. }
  34.  
  35. $response = getResponse($request);
  36. $response = current($response['container']);
  37. $response = $response['data'];
  38. $responce = parseResponseByProducer($response, 'A.B.S.');
  39. $chepestKey = findCheapestByPrice($responce);
  40. $itemHash = $responce[$chepestKey]['itemHash'];
  41. print_r($responce[$chepestKey]);
  42.  
  43. $preOrderSearch = getRequest('PreOrderSearch', getContainer('1069','A.B.S.','e0c99bf30838b1a742c62aaafdf60446'));
  44.  
  45. $preOrderSearch1 = array(
  46. 'service' => 'provider',
  47. 'user' => $GLOBALS['user'],
  48. 'password' => $GLOBALS['password'],
  49. 'timeLimit' => '10',
  50. 'action' => 'PreOrderSearch',
  51. 'container' => array(
  52. array(
  53. 'provider' => $GLOBALS['eurotradeUrl'],
  54. 'login' => $GLOBALS['eurotradeLogin'],
  55. 'password' => $GLOBALS['eurotradePassword'],
  56. 'code' => '1069',
  57. 'producer' => 'A.B.S.',
  58. 'itemHash' => 'e0c99bf30838b1a742c62aaafdf60446'
  59. )
  60. )
  61. );
  62.  
  63. print_r(getResponse($preOrderSearch));
  64. die;
  65.  
  66. function findCheapestByPrice($big) {
  67. $lowest = array();
  68. foreach($big as $id => $array) {
  69. $low = false;
  70. $prev = false;
  71. foreach($array as $k => $a) {
  72. if(!$low) {
  73. $low = $k;
  74. $prev = $a['price'];
  75. } else {
  76. if($a['price'] < $prev) {
  77. $prev = $a['price'];
  78. $low = $k;
  79. }
  80. }
  81. }
  82. $lowest[$id] = array( $low => $array[$low]);
  83. }
  84. return key(array_column($lowest, 'price'));
  85. }
  86.  
  87. function parseResponseByProducer($responce, $producer) {
  88. return array_filter($responce, function ($var) use ($producer) {
  89. return ($var['producer'] == $producer);
  90. });
  91. }
  92.  
  93. function getResponse($request) {
  94. try {
  95. $post = json_encode($request);
  96. $ch = curl_init($GLOBALS['url']);
  97. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  98. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  99. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  100. $data = curl_exec($ch);
  101. curl_close($ch);
  102. $responce = json_decode($data,true);
  103. return $responce;
  104. } catch (Exception $e) {
  105. return $e->getMessage();
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement