License manager API can check license key is valid or not.

Request

To request to server need specific parameters are a, b, api_Key, license_key, post_token and signature. The value of ’a ‘must be ‘license’ and ‘b’ equal ‘check’.

We send this parameter as "postData" array to server.

$apiKey = '338e7963ffd9137deb18dd002b7deff9';
$apiSecret = '3dabbf055f4fb283724b6664fcd34a8c';
$apiURL = 'http://test.joudisoft.com/license-manager/www/api/v1/system/';
$licenseKey = '74382066405804';

$postData = array(
'a' => 'license',
'b' => 'check',
'api_key' => apiKey,
'license_key' => licenseKey,
'post_token' => md5(rand(1,500).time()),
);

Then sort postData descending sort.

ksort($postData);

Then concatenate all postData element and put them in signature.

foreach($postData as $key => $val) {
if((!is_string($val) && !is_numeric($val))) continue;
$signature .= $val;
}

An MD5 hash apiSecre and signature, The two values are concatenated and then hashed using the MD5 algorithm, then put MD5 result in signature and add it to postData.

$postData['signature'] = md5($apiSecret.$signature);

A-"function_exists " Function send request to server and determine property of request using curl library .

function_exists('curl_init'){
$request = curl_init($apiURL);
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_POSTFIELDS, $postData);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($request, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($request, CURLOPT_TIMEOUT, 120);
$responseData = curl_exec($request);
$responseHttpCode = curl_getinfo($request, CURLINFO_HTTP_CODE);
curl_close($request);
}

1- if request hasn’t done successfully, mean response code not equal 200 this short message will appears to you.

if(!stristr($httpHeaders[0], '200'))
echo "API Request Failed, HTTP / Error: $httpHeaders[0]";

2- If responseData is empty or not string, this message will appears to you.

echo 'API Request Failed';

3-if responseData is empty or not array or msg key of responseData is empty or type key of responseData is empty, this message will appear.

if(empty($responseData) || !is_array($responseData) || empty($responseData['msg']) || empty($responseData['type']))
echo 'Invalid Response Data Syntax';
}

4-if value of type element in responseData isn’t equal success; the API response is type and msg value.

if($responseData['type'] !== 'success') {
echo ucfirst($responseData['type']) . ' : ' . $responseData['msg'];
}

5-New parameter "signature Plus" used to ensure that this responce from license server,if "signature Plus" is equal server "signaturePlus",the responce is as below.

$signaturePlus = md5($postData['signature'].$apiSecret);
if($responseData['signature_plus'] !== $signaturePlus) {
echo 'Response received, an invalid signature plus detected, message not coming from license Server';
exit();
}

6-if type of responseData is equal success .the output as show below.

if($responseData['type'] == 'success') {
echo "License check done, License key is valid";
echo "Response Data in JSON";
echo json_encode($responseData);
}

Output

	License check done, License key is valid

	Response Data in JSON
	{"msg":"License key is valid","type":"success","signature_plus":"988bf0f0670d7651066b16fe786d513f"}