Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //TODO: set your API key found in http://wyday.com/limelm/settings/
- $api_key = 'PASTE THE API KEY HERE';
- //TODO: set the version id to generate & find keys for
- // the version id is found in the url. For example http://wyday.com/limelm/version/100/
- // the version id is 100.
- $version_id = '100';
- date_default_timezone_set('America/Toronto');
- function urlEncodePostData($post_data)
- {
- $post_string = '';
- foreach ($post_data as $key => $value)
- {
- if (is_array($value))
- {
- foreach ($value as $sub_value)
- {
- $post_string .= $key.'[]='.urlencode($sub_value).'&';
- }
- }
- else
- $post_string .= $key.'='.urlencode($value).'&';
- }
- $post_string = rtrim($post_string, '& ');
- $request = curl_init('https://wyday.com/limelm/api/rest/');
- curl_setopt($request, CURLOPT_HEADER, 0);
- curl_setopt($request, CURLOPT_ENCODING, "");
- curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($request, CURLOPT_POSTFIELDS, $post_string);
- curl_setopt($request, CURLOPT_SSL_VERIFYPEER, TRUE);
- return $request;
- }
- function generateProductKey($post_data)
- {
- $request = urlEncodePostData($post_data);
- $jObj = json_decode(curl_exec($request));
- if ($jObj->stat == 'ok')
- {
- foreach ($jObj->pkeys->pkey as $pkey)
- {
- return $pkey->key;
- }
- }
- else
- {
- // Uncomment the next line to see the error LimeLM is giving you.
- echo $jObj->message;
- }
- return null;
- }
- try
- {
- $post_data = array
- (
- 'method' => 'limelm.pkey.generate',
- 'api_key' => $api_key,
- 'version_id' => $version_id,
- 'num_keys' => 1,
- 'num_acts' => $quantity,
- 'email' => $email,
- 'feature_name' => array('fastspring_subscription_id', 'subscription_expiry'),
- 'feature value' => array($reference, date('Y-m-d H:i:s', strtotime('+1 year'))),
- 'nojsoncallback' => 1,
- 'format' => 'json'
- );
- $product_key = generateProductKey($post_data);
- echo $product_key . "\r\n";
- }
- catch (Exception $e)
- {
- // Uncomment the next line to see the exception.
- //echo 'Failure: '.$e->getMessage();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment