2014-10-28 86 views
1

生成HashPost要求PayUMoney集成 - 如何计算哈希以便与响应进行比较?

$hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|" 
        ."udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10"; 
    $hashVarsSeq = explode('|', $hashSequence); 
    $hashString = ''; 
    foreach ($hashVarsSeq as $hashVar) { 
     $hashString .= isset($payObject['params'][$hashVar]) ? $payObject['params'][$hashVar] : ''; 
     $hashString .= '|'; 
    } 
    $hashString .= $salt; 
    //generate hash 
    $hash = strtolower(hash('sha512', $hashString)); 

得到成功响应产生Hash

$retHashSeq = $salt.'|'.$status.'||||||||'.$udf3.'|'.$udf2.'|'.$udf1.'|'.$email.'|||'.$amount.'|'.$txnid.'|'.$key; 
$hash = hash("sha512", $retHashSeq); 

但产生HashPayU服务器不与返回Hash比赛后。 可能是什么问题?任何帮助,将不胜感激。

+0

你是指PayU,但我不能找到它应该是什么什么。 – magnetik 2014-11-03 13:06:52

+0

这是PayUMoney。 – 2014-11-07 08:55:28

回答

1

看来你试图重新实现PayU REST API。 我无法在当前版本的REST API中找到对$hashSequence模式的任何引用。您是否考虑使用official SDK

+0

它对你有用吗?你有什么问题?你如何解决它? – 2016-07-20 19:13:50

0

此代码的Android hashcodegeneration在你的服务器端

<?php 

$key=$_POST["key"]; 

$salt="xxxxx"; #your payumoney salt 
$txnId=$_POST["txnid"]; 
$amount=$_POST["amount"]; 
$productName=$_POST["productInfo"]; 
$firstName=$_POST["firstName"]; 
$email=$_POST["email"]; 
$udf1=$_POST["udf1"]; 
$udf2=$_POST["udf2"]; 
$udf3=$_POST["udf3"]; 
$udf4=$_POST["udf4"]; 
$udf5=$_POST["udf5"]; 

$payhash_str = $key . '|' . checkNull($txnId) . '|' .checkNull($amount) . '|' .checkNull($productName) . '|' . checkNull($firstName) . '|' . checkNull($email) . '|' . checkNull($udf1) . '|' . checkNull($udf2) . '|' . checkNull($udf3) . '|' . checkNull($udf4) . '|' . checkNull($udf5) . '|' . $salt; 


function checkNull($value) { 
      if ($value == null) { 
        return ''; 
      } else { 
        return $value; 
      } 
     } 


$hash = strtolower(hash('sha512', $payhash_str)); 
$arr['result'] = $hash; 
$arr['status']=0; 
$arr['errorCode']=null; 
$arr['responseCode']=null; 
$arr['hashtest']=$payhash_str; 
$output=$arr; 


echo json_encode($output); 

?> 
0

我知道它晚来回答这个问题,但是这个答案可能有助于未来的搜索。只需从官方网站下载最新的PayUMoney套件,并将SALT密钥放入success.php页面。

这里是我的最新success.php

<?php 
include'config/db.php'; // Your database connection file if needed 
$status=$_POST["status"]; 
$firstname=$_POST["firstname"]; 
$amount=$_POST["amount"]; 
$txnid=$_POST["txnid"]; 
$posted_hash=$_POST["hash"]; 
$key=$_POST["key"]; 
$productinfo=$_POST["productinfo"]; 
$email=$_POST["email"]; 

$salt=""; // PLACE YOUR SALT KEY HERE 

// Salt should be same Post Request 
if(isset($_POST["additionalCharges"])){ 
    $additionalCharges=$_POST["additionalCharges"]; 
    $retHashSeq = $additionalCharges.'|'.$salt.'|'.$status.'|||||||||||'.$email.'|'.$firstname.'|'.$productinfo.'|'.$amount.'|'.$txnid.'|'.$key; 
}else{ 
    $retHashSeq = $salt.'|'.$status.'|||||||||||'.$email.'|'.$firstname.'|'.$productinfo.'|'.$amount.'|'.$txnid.'|'.$key; 
} 

$hash = strtolower(hash('sha512', $retHashSeq)); // NOTE: THIS PART IN YOUR KIT MAY HAVE AN ERROR. THERE YOU MIGHT GET $hash_string instead of $retHashSeq. JUST REPLACE $hash_string with $retHashSeq. 

if($hash != $posted_hash){ 
    // Transaction completed but is Invalid as Hash Values are not Matching. Notify Admin. 
    //header('Location: fail.php'); 
    //exit(); 
}else{ 
    // Transaction is Valid. Process orders here. 
    //header('Location: thanks.php'); 
    //exit(); 
} 
?> 
相关问题