Guest User

Untitled

a guest
Apr 12th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.07 KB | None | 0 0
  1. <?php
  2. //TODO: set your API key found in http://wyday.com/limelm/settings/
  3. $api_key = 'PASTE THE API KEY HERE';
  4.  
  5. //TODO: set the version id to generate & find keys for
  6. // the version id is found in the url. For example http://wyday.com/limelm/version/100/
  7. // the version id is 100.
  8. $version_id = '100';
  9.  
  10. date_default_timezone_set('America/Toronto');
  11.  
  12. function urlEncodePostData($post_data)
  13. {
  14.     $post_string = '';
  15.     foreach ($post_data as $key => $value)
  16.     {
  17.         if (is_array($value))
  18.         {
  19.             foreach ($value as $sub_value)
  20.             {
  21.                 $post_string .= $key.'[]='.urlencode($sub_value).'&';
  22.             }
  23.         }
  24.         else
  25.             $post_string .= $key.'='.urlencode($value).'&';
  26.     }
  27.     $post_string = rtrim($post_string, '& ');
  28.  
  29.     $request = curl_init('https://wyday.com/limelm/api/rest/');
  30.     curl_setopt($request, CURLOPT_HEADER, 0);
  31.     curl_setopt($request, CURLOPT_ENCODING, "");
  32.     curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
  33.     curl_setopt($request, CURLOPT_POSTFIELDS, $post_string);
  34.     curl_setopt($request, CURLOPT_SSL_VERIFYPEER, TRUE);
  35.     return $request;
  36. }
  37.  
  38. function generateProductKey($post_data)
  39. {
  40.     $request = urlEncodePostData($post_data);
  41.     $jObj = json_decode(curl_exec($request));
  42.  
  43.     if ($jObj->stat == 'ok')
  44.     {
  45.         foreach ($jObj->pkeys->pkey as $pkey)
  46.         {
  47.             return $pkey->key;
  48.         }
  49.     }
  50.     else
  51.     {
  52.         // Uncomment the next line to see the error LimeLM is giving you.
  53.         echo $jObj->message;
  54.     }
  55.     return null;
  56. }
  57.    
  58. try
  59. {
  60.     $post_data = array
  61.     (
  62.         'method' => 'limelm.pkey.generate',
  63.         'api_key' => $api_key,
  64.         'version_id' => $version_id,
  65.         'num_keys' => 1,
  66.         'num_acts' => $quantity,
  67.         'email' => $email,
  68.         'feature_name' => array('fastspring_subscription_id', 'subscription_expiry'),
  69.         'feature value' => array($reference, date('Y-m-d H:i:s', strtotime('+1 year'))),
  70.         'nojsoncallback' => 1,
  71.         'format' => 'json'
  72.     );
  73.     $product_key = generateProductKey($post_data);
  74.     echo $product_key . "\r\n";
  75. }
  76. catch (Exception $e)
  77. {
  78.     // Uncomment the next line to see the exception.
  79.     //echo 'Failure: '.$e->getMessage();
  80. }
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment