Paytm支付网关交易API不起作用



>我需要帮助来实现paytm支付网关。 我正在Android应用程序中实现网关,并且已正确编码,并且没有错误,沙盒键工作正常,我也收到了响应,但随后Paytm向我发送了一个名为"检查状态API.php的文件,并对我说了这句话 我引用了我的电子邮件

对于交易状态 API,请使用 MID 和 订单 ID 并在以下链接中传递 https://pguat.paytm.com/oltp/HANDLER_INTERNAL/getTxnStatus?JsonData={"MID":"MID","ORDERID":"ORDERID","CHECKSUMHASH":"CHECKSUMHASH"}

请在该传递后对 CHECKSUMHASH 进行 URL 编码 校验和哈希值到状态 API。

我有一个附件这个文件

检查状态 API.php

public function PaytmTransactionStatus($order_id){
header("Pragma: no-cache");
header("Cache-Control: no-cache");
header("Expires: 0");
require_once("lib/config_paytm.php"); 
require_once("lib/encdec_paytm.php");
$checkSum = "";    
$data = array(
"MID"=>"DIY12386817555501617",// please use your own MID.
"ORDER_ID"=>$order_id,
);
$key = 'bKMfNxPPf_QdZppa';
$checkSum =getChecksumFromArray($data, $key);// Please use your own merchant key value.

$request=array("MID"=>'**************',
"ORDERID"=>$order_id,"CHECKSUMHASH"=>$checkSum);
$JsonData =json_encode($request);
$postData = 'JsonData='.urlencode($JsonData);
$url = "https://pguat.paytm.com/oltp/HANDLER_INTERNAL/getTxnStatus";
$HEADER[] = "Content-Type: application/json";
$HEADER[] = "Accept: application/json";
$args['HEADER'] = $HEADER;  
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);   
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $args['HEADER']);
$server_output = curl_exec($ch);
return json_decode($server_output,true);

我用我的修改了 MID 和商家密钥并将其上传到服务器,但 API 不起作用,它返回我在浏览器中编写的整个代码,但它应该返回 json。

暂存和生产 URL 的 URL 存在问题。


$url = 'https://securegw-stage.paytm.in/merchant-status/getTxnStatus';

实时
$url = 'https://securegw.paytm.in/merchant-status/getTxnStatus';

使用以下代码检查状态:

<?php
header("Pragma: no-cache");
header("Cache-Control: no-cache");
header("Expires: 0");
// following files need to be included
$raw_data = json_decode(file_get_contents('php://input'), true);
function pkcs5_unpad_e($text) {
$pad = ord($text{strlen($text) - 1});
if ($pad > strlen($text))
return false;
return substr($text, 0, -1 * $pad);
}
function pkcs5_pad_e($text, $blocksize) {
$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);
}
function encrypt_e($input, $ky) {
$key = $ky;
$size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, 'cbc');
$input = pkcs5_pad_e($input, $size);
$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', 'cbc', '');
$iv = "@@@@&&&&####$$$$";
mcrypt_generic_init($td, $key, $iv);
$data = mcrypt_generic($td, $input);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$data = base64_encode($data);
return $data;
}
function getChecksumFromArray($arrayList, $key, $sort=1) {
if ($sort != 0) {
ksort($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 getArray2Str($arrayList) {
$paramStr = "";
$flag = 1;
foreach ($arrayList as $key => $value) {
if ($flag) {
$paramStr .= checkString_e($value);
$flag = 0;
} else {
$paramStr .= "|" . checkString_e($value);
}
}
return $paramStr;
}
//Gaurav check
function generateSalt_e($length) {
$random = "";
srand((double) microtime() * 1000000);
$data = "AbcDE123IJKLMN67QRSTUVWXYZ";
$data .= "aBCdefghijklmn123opq45rs67tuv89wxyz";
$data .= "0FGH45OP89";
for ($i = 0; $i < $length; $i++) {
$random .= substr($data, (rand() % (strlen($data))), 1);
}
return $random;
}
function checkString_e($value) {
$myvalue = ltrim($value);
$myvalue = rtrim($myvalue);
if ($myvalue == 'null')
$myvalue = '';
return $myvalue;
}

//test code
$checkSum = "";
$paramList = array();
$paramList["MID"] = 'your_MID';
$paramList["ORDERID"] = $raw_data["order_id"];
//Here checksum string will return by getChecksumFromArray() function.
$checkSum = getChecksumFromArray($paramList,"your_key");
$check=urlencode($checkSum);  
$paramList["CHECKSUMHASH"]=$check;
$data_string = json_encode($paramList); 
$ch = curl_init();                    // initiate curl
$url = "https://secure.paytm.in/oltp/HANDLER_INTERNAL/getTxnStatus?JsonData=".$data_string; // where you want to post data
$headers = array('Content-Type:application/json');
$ch = curl_init();  // initiate curl
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);  // tell curl you want to post something
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string); // define what you want to post
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return the output in string format
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);     
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);    
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec ($ch); // execute
$info = curl_getinfo($ch);
//print_r($info)."<br />";
echo ($output);
?>

经过一些研究工作,我终于写了一些工作正常的东西

<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
$order_id = $_POST['order_id'];

header("Pragma: no-cache");
header("Cache-Control: no-cache");
header("Expires: 0");
require_once("./lib/config_paytm.php");
require_once("./lib/encdec_paytm.php");
$checkSum = "";   
$paramList = array();
$paramList["MID"] = 'YOUR MID'; //Provided by Paytm
$paramList["ORDER_ID"] = $order_id; //unique OrderId for every request
$checkSum = getChecksumFromArray($paramList,"YOUR KEY");
$paramList["CHECKSUMHASH"] = urlencode($checkSum);
$data_string = 'JsonData='.json_encode($paramList);

$ch = curl_init();                    // initiate curl
$url = "https://pguat.paytm.com/oltp/HANDLER_INTERNAL/getTxnStatus"; // 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);  
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string); 
post
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); /
format
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec ($ch); // execute
$info = curl_getinfo($ch);
echo $output;
return json_decode($output, true);
}
?>

更改暂存网址

$url = "https://securegw-tage.paytm.in/order/status";

生产

$url = "https://securegw.paytm.in/order/status";

最新更新