PayUMoney集成 - 如何计算哈希以与响应进行比较?

问题描述 投票:2回答:4

Hash请求生成Post

    $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);

但生成的HashHash服务器返回的PayU不匹配。可能是什么问题呢??任何帮助,将不胜感激。

php hash payment-gateway payumoney
4个回答
1
投票

看来你正试图重新实现PayU REST API。我在当前版本的REST API中找不到任何关于$hashSequence模式的引用。

你考虑过使用official SDK吗?


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 Kit,并将SALT键放在success.php页面中。

这是我最近的成功.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();
}
?>

0
投票

PayUMoney C#API中请求和响应中的哈希计算

hashSequence =

关键| txnid |量源|产品|姓|电子邮件| udf1 | udf2 | udf3 | udf4 | udf5 ||||||盐;

$ hash = hash(“sha512”,$ hashSequence);

Where salt is available on the PayUMoney dashboard.

注意:计算hashSequence时将使用空白udf字段,即使商家未在输入请求中传递任何udf字段。

对于响应散列,与支付请求散列相比,变量序列的顺序相反。此外,在salt和udf1之间添加了一个状态变量

Sequence

hashSequence = salt | status |||||| udf5 | udf4 | udf3 | udf2 | udf1 | email | firstname | productinfo | amount | txnid | key;

$ hash = hash(“sha512”,$ hashSequence);

Where salt is available on the PayUMoney dashboard.

以下是响应哈希计算的示例代码: -

                bool isCheckSum = false;
                var strhash = Request.Form["hash"];
                var strstatus = Request.Form["status"];
                var strfirstname = Request.Form["firstname"];
                var stramount = Request.Form["amount"];
                var strtxnid = Request.Form["txnid"];
                var strkey = Request.Form["key"];
                var strproductinfo = Request.Form["productinfo"];
                var stremail = Request.Form["email"];
                var stradditionalCharges = Request.Form["additionalCharges"];
                string strudf1 = Request.Form["udf1"];
                string strudf2 = Request.Form["udf2"];
                string strudf3 = Request.Form["udf3"];
                string strudf4 = Request.Form["udf4"];
                string strudf5 = Request.Form["udf5"];                   

                System.Security.Cryptography.SHA512Managed sha512 = new System.Security.Cryptography.SHA512Managed();
                byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(strSALT + "|" + strstatus + "||||||" + strudf5 + "|" + strudf4 + "|" + strudf3 + "|" + strudf2 + "|" + strudf1 + "|" + stremail + "|" + strfirstname + "|" + strproductinfo + "|" + stramount + "|" + strtxnid + "|" + strkey);
                byte[] hashBytes = sha512.ComputeHash(inputBytes);
                byte[] hashValue;
                string hex = "";
                hashValue = sha512.ComputeHash(inputBytes);
                foreach (byte x in hashValue)
                {
                    hex += String.Format("{0:x2}", x);
                }

                if(strhash == hex)
                {
                    isCheckSum = true;
                }
© www.soinside.com 2019 - 2024. All rights reserved.