我正在尝试将Telenor EasyPay付款网关与我的在线商店集成,但是无论我怎么做,我都会在EasyPay服务器上收到“无效请求”错误。这是问题的快照。
这是我的暂存帐户的代码请求代码:
<form id="easypay" target="_blank" name="easypay" method="post" action="https://easypaystg.easypaisa.com.pk/easypay/Index.jsf">
<input type="hidden" name="storeId" value="my_store_id_here" />
<input type="hidden" name="amount" value="10" />
<input type="hidden" name="postBackURL" value="https://my-store.com/post-back.php" />
<input type="hidden" name="orderRefNum" value="5555"/>
<input type="hidden" name="expiryDate" value="20201115 05:10:00" />
<input type="hidden" name="autoRedirect" value="1" />
<input type="hidden" name="paymentMethod" value="MA_PAYMENT_METHOD" />
<input type="hidden" name="emailAddr" value="client_email@gmail.com" />
<input type="hidden" name="mobileNum" value="client_mob_num" />
<input type="hidden" name="merchantHashedReq" value="<?php echo $hashedRequest;?>" />
<input type = "submit" value="Pay With EasyPay">
</form>
我用于哈希请求参数的PHP中的另一段代码是:
function getHashedRequest($hKey, $orderId, $amt, $autoRed, $expiryDate, $storeId, $merchantConfirmPage,$paymentMode,$phone,$email) {
$hashRequest = '';
if(strlen($hKey) > 0 && (strlen($hKey) == 16 || strlen($hKey) == 24 || strlen($hKey) == 32 )) {
// Create Parameter map
//error_log('Order INFO: '. $orderId);
$paramMap = array();
$paramMap['amount'] = $amt ;
$paramMap['autoRedirect'] = $autoRed ;
$paramMap['expiryDate'] = $expiryDate;
$paramMap['mobileNum'] = $phone ;
$paramMap['emailAddr'] = $email ;
$paramMap['orderRefNum'] = $orderId;
$paramMap['paymentMethod'] = $paymentMode;
$paramMap['postBackURL'] = $merchantConfirmPage;
$paramMap['storeId'] = $storeId;
//Creating string to be encoded
$mapString = '';
foreach ($paramMap as $key => $val) {
$mapString .= $key.'='.$val.'&';
}
$mapString = substr($mapString , 0, -1);
// error_log('MAPString: '.$mapString);
// Encrypting mapString
function pkcs5_pad($text, $blocksize) {
$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);
}
$alg = 'MCRYPT_RIJNDAEL_128'; // AES
$mode = 'MCRYPT_MODE_ECB'; // ECB
//////////////////////////////////////////
//$key previously generated safely, ie: openssl_random_pseudo_bytes
$ivlen = openssl_cipher_iv_length($cipher="AES-128-CBC");
$iv = openssl_random_pseudo_bytes($ivlen);
$ciphertext_raw = openssl_encrypt($mapString, 'aes-256-ctr', $hKey, $options=OPENSSL_RAW_DATA, $iv);
$hmac = hash_hmac('sha256', $ciphertext_raw, $hKey, $as_binary=true);
$hashRequest = base64_encode( $iv.$hmac.$ciphertext_raw);
}
return $hashRequest;
}
我不知道我在做什么错。任何帮助,将不胜感激。谢谢