首页 文章

paytm支付网关交易api无法正常工作

提问于
浏览
-1

我需要帮助实现paytm支付网关 . 我在Android应用程序中实现网关,我已正确编码,我没有错误,沙箱键工作正常,我也得到了响应,但然后paytm发送给我一个文件命名'检查状态API.php'并说这对我来说我引用我的电子邮件

对于Transaction Status API,请使用MID和ORDER ID生成新的校验和,并将其传递到链接https://pguat.paytm.com/oltp/HANDLER_INTERNAL/getTxnStatus?JsonData={"MID":"MID","ORDERID “:”ORDERID“,”CHECKSUMHASH“:”CHECKSUMHASH“}在将校验和值传递给状态API之后,请对CHECKSUMHASH执行Url编码 .

我有一个附件这个文件

检查状态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 .

2 回答

  • 0

    使用此代码检查状态:

    <?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)."
    "; echo ($output); ?>
  • 0

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

    <?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);
    
         }
    
         ?>
    

相关问题