130 lines
4.0 KiB
PHP
130 lines
4.0 KiB
PHP
<?php
|
|
|
|
function encrypt_e($input, $ky) {
|
|
$key = html_entity_decode($ky);
|
|
$iv = "@@@@&&&&####$$$$";
|
|
$data = openssl_encrypt($input, "AES-128-CBC", $key, 0, $iv);
|
|
return $data;
|
|
}
|
|
|
|
function decrypt_e($crypt, $ky) {
|
|
$key = html_entity_decode($ky);
|
|
$iv = "@@@@&&&&####$$$$";
|
|
$data = openssl_decrypt($crypt, "AES-128-CBC", $key, 0, $iv);
|
|
return $data;
|
|
}
|
|
|
|
function generateSalt_e($length) {
|
|
$random = "";
|
|
srand((int) ((double) microtime(true) * 1000000)); // Fix for deprecation
|
|
$data = "AbcDE123IJKLMN67ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
$data .= "aBCdefghijklmn123opq45rs67tuv89wxyz";
|
|
$data .= "0FGH45OP89";
|
|
|
|
for ($i = 0; $i < $length; $i++) {
|
|
$random .= substr($data, (rand() % strlen($data)), 1);
|
|
}
|
|
|
|
return $random;
|
|
}
|
|
|
|
function checkString_e($value) {
|
|
return ($value === 'null') ? '' : $value;
|
|
}
|
|
|
|
function getChecksumFromArray($arrayList, $key, $sort = 1) {
|
|
if ($sort != 0) {
|
|
ksort($arrayList);
|
|
}
|
|
// Convert all values to strings
|
|
$arrayList = array_map('strval', $arrayList);
|
|
$str = getArray2Str($arrayList);
|
|
$salt = generateSalt_e(4);
|
|
$finalString = $str . "|" . $salt;
|
|
$hash = hash("sha256", $finalString);
|
|
$hashString = $hash . $salt;
|
|
$checksum = encrypt_e($hashString, $key);
|
|
return $checksum;
|
|
}
|
|
|
|
function getChecksumFromString($str, $key) {
|
|
$salt = generateSalt_e(4);
|
|
$finalString = $str . "|" . $salt;
|
|
$hash = hash("sha256", $finalString);
|
|
$hashString = $hash . $salt;
|
|
$checksum = encrypt_e($hashString, $key);
|
|
return $checksum;
|
|
}
|
|
|
|
function verifychecksum_e($arrayList, $key, $checksumvalue) {
|
|
$arrayList = removeCheckSumParam($arrayList);
|
|
ksort($arrayList);
|
|
$str = getArray2StrForVerify($arrayList);
|
|
$paytm_hash = decrypt_e($checksumvalue, $key);
|
|
$salt = substr($paytm_hash, -4);
|
|
$finalString = $str . "|" . $salt;
|
|
$website_hash = hash("sha256", $finalString);
|
|
$website_hash .= $salt;
|
|
return ($website_hash === $paytm_hash) ? "TRUE" : "FALSE";
|
|
}
|
|
|
|
function getArray2Str($arrayList) {
|
|
$paramStr = "";
|
|
$flag = 1;
|
|
foreach ($arrayList as $key => $value) {
|
|
if (strpos($value, 'REFUND') !== false || strpos($value, '|') !== false) {
|
|
continue;
|
|
}
|
|
$paramStr .= ($flag) ? checkString_e($value) : "|" . checkString_e($value);
|
|
$flag = 0;
|
|
}
|
|
return $paramStr;
|
|
}
|
|
|
|
function getArray2StrForVerify($arrayList) {
|
|
$paramStr = "";
|
|
$flag = 1;
|
|
foreach ($arrayList as $key => $value) {
|
|
$paramStr .= ($flag) ? checkString_e($value) : "|" . checkString_e($value);
|
|
$flag = 0;
|
|
}
|
|
return $paramStr;
|
|
}
|
|
|
|
function removeCheckSumParam($arrayList) {
|
|
if (isset($arrayList["CHECKSUMHASH"])) {
|
|
unset($arrayList["CHECKSUMHASH"]);
|
|
}
|
|
return $arrayList;
|
|
}
|
|
|
|
function callAPI($apiURL, $requestParamList) {
|
|
$JsonData = json_encode($requestParamList);
|
|
$postData = 'JsonData=' . urlencode($JsonData);
|
|
$ch = curl_init($apiURL);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($postData)));
|
|
$jsonResponse = curl_exec($ch);
|
|
return json_decode($jsonResponse, true);
|
|
}
|
|
|
|
function callRefundAPI($refundApiURL, $requestParamList) {
|
|
$JsonData = json_encode($requestParamList);
|
|
$postData = 'JsonData=' . urlencode($JsonData);
|
|
$ch = curl_init($refundApiURL);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
|
curl_setopt($ch, CURLOPT_URL, $refundApiURL);
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
|
$jsonResponse = curl_exec($ch);
|
|
return json_decode($jsonResponse, true);
|
|
}
|
|
?>
|