Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.00 KB | None | 0 0
  1. <?php
  2.  
  3. function curl_post($url, array $post = NULL, array $options = array())
  4. {
  5.     $username = 'admin';
  6.     $password = 'admin';
  7.  
  8.  
  9.     $defaults = array(
  10.         CURLOPT_POST => 1,
  11.         CURLOPT_HEADER => 0,
  12.         CURLOPT_URL => $url,
  13.         CURLOPT_FRESH_CONNECT => 1,
  14.         CURLOPT_RETURNTRANSFER => 1,
  15.         CURLOPT_BINARYTRANSFER => 1,
  16.         CURLOPT_FORBID_REUSE => 1,
  17.         CURLOPT_TIMEOUT => 4,
  18.         CURLOPT_USERPWD => $username . ":" . $password,
  19.         CURLOPT_POSTFIELDS => http_build_query($post)
  20.     );
  21.  
  22.     $ch = curl_init();
  23.     curl_setopt_array($ch, ($options + $defaults));
  24.     if( ! $result = curl_exec($ch))
  25.     {
  26.         trigger_error(curl_error($ch));
  27.     }
  28.  
  29.     curl_close($ch);
  30.     return $result;
  31. }
  32.  
  33. function prepareProducts() {
  34.     $product01 = array(
  35.         'supplier_id' => '12345',
  36.         'name' => 'Rumpel',
  37.         'supplier' => 'lcwaikiki',
  38.         'description_short' => 'Rumpel description+',
  39.         'description' => 'Rumpel very long description',
  40.         'category_id' => 299,
  41.         'category_name' => 'Jabberwocky',
  42.         'supplier_url' => 'http =>//microsoft.com',
  43.         'color' => 'red',
  44.         'price' => 1500,
  45.         'image' => 'http =>//vignette3.wikia.nocookie.net/muppet/images/5/58/Rumpelco.jpg/revision/latest?cb=20090522111255',
  46.         'images' => array(
  47.             'http =>//cdn1.stuttgarter-zeitung.de/media.media.151be88a-f2be-47c5-9e61-b5abb1e4ba89.normalized.jpeg',
  48.             'http =>//vignette1.wikia.nocookie.net/muppet/images/9/9f/1_Sesamstrasse_Schaf_2002.jpg/revision/latest?cb=20090522112938'
  49.         ),
  50.         'variants' => array(
  51.             array(
  52.                 'sku' => 'rum01',
  53.                 'name' => 'Rumpel01',
  54.                 'price' => 1500,
  55.                 'amount' => 7
  56.             ),
  57.             array(
  58.                 'sku' => 'rum02',
  59.                 'name' => 'Rumpel02',
  60.                 'price' => 1600,
  61.                 'amount' => 6
  62.             ),
  63.             array(
  64.                 'sku' => 'rum03',
  65.                 'name' => 'Rumpel03',
  66.                 'price' => 1300,
  67.                 'amount' => 8
  68.             ),
  69.             array(
  70.                 'sku' => 'rum04',
  71.                 'name' => 'Rumpel04',
  72.                 'price' => 1900,
  73.                 'amount' => 14
  74.             ),
  75.         )
  76.     );
  77.  
  78.     $product02 = array(
  79.         'supplier_id' => '12346',
  80.         'name' => 'Stumpel',
  81.         'supplier' => 'lcwaikiki',
  82.         'description_short' => 'Stumpel description',
  83.         'description' => 'Stumpel very long description',
  84.         'category_id' => 302,
  85.         'category_name' => 'Jabberwocky',
  86.         'supplier_url' => 'http =>//microsoft.com',
  87.         'color' => 'blue',
  88.         'price' => 2500,
  89.         'image' => 'http =>//vignette3.wikia.nocookie.net/muppet/images/5/58/Rumpelco.jpg/revision/latest?cb=20090522111255',
  90.         'images' => array(
  91.             'http =>//cdn1.stuttgarter-zeitung.de/media.media.151be88a-f2be-47c5-9e61-b5abb1e4ba89.normalized.jpeg',
  92.             'http =>//vignette1.wikia.nocookie.net/muppet/images/9/9f/1_Sesamstrasse_Schaf_2002.jpg/revision/latest?cb=20090522112938'
  93.         ),
  94.         'variants' => array(
  95.             array(
  96.                 'sku' => 'stum01',
  97.                 'name' => 'Stumpel01',
  98.                 'price' => 34500,
  99.                 'amount' => 6
  100.             ),
  101.             array(
  102.                 'sku' => 'stum02',
  103.                 'name' => 'Stumpel02',
  104.                 'price' => 1600,
  105.                 'amount' => 12
  106.             ),
  107.             array(
  108.                 'sku' => 'stum03',
  109.                 'name' => 'Stumpel03',
  110.                 'price' => 1200,
  111.                 'amount' => 4
  112.             ),
  113.         )
  114.     );
  115.  
  116.     $data = [$product01, $product02];
  117.     return $data;
  118. }
  119.  
  120.  
  121. function setProduct()
  122. {
  123.     $url = "http://grooger.tm/api/setProduct/";
  124.  
  125.     $data = prepareProducts();
  126.  
  127.     $post = ['data' => json_encode($data)];
  128.  
  129.     echo curl_post($url, $post);
  130. }
  131.  
  132.  
  133. setProduct();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement