我正在尝试使用php为Paytm付款网关生成校验和。
<?php
// following files need to be included
require_once("./lib/config_paytm.php");
require_once("./lib/encdec_paytm.php");
if (strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0) {
throw new Exception('Request method must be POST');
}
$content = trim(file_get_contents("php://input"));
$decodeData = json_decode($content, true);
// var_dump($decodeData); // this return null
if (!empty($decodeData)) {
$paramList = array();
$paramList["MID"] = $decodeData["MID"]; //Provided by Paytm
$paramList["ORDER_ID"] = $decodeData["ORDER_ID"]; //unique OrderId for every request
$paramList["CUST_ID"] = $decodeData["CUST_ID"]; // unique customer identifier
$paramList["INDUSTRY_TYPE_ID"] = $decodeData["INDUSTRY_TYPE_ID"]; //Provided by Paytm
$paramList["CHANNEL_ID"] = $decodeData["CHANNEL_ID"]; //Provided by Paytm
$paramList["TXN_AMOUNT"] = $decodeData["TXN_AMOUNT"]; // transaction amount
$paramList["WEBSITE"] = $decodeData["WEBSITE"]; //Provided by Paytm
$paramList["CALLBACK_URL"] = $decodeData["CALLBACK_URL"]; //Provided by Paytm
// $paramList["EMAIL"] = $decodeData["MID"]; // customer email id
$paramList["MOBILE_NO"] = $decodeData["MOBILE_NO"]; // customer 10 digit mobile no.
$checkSum = getChecksumFromArray($paramList, PAYTM_MERCHANT_KEY);
if (!empty($checkSum)) {
echo json_encode(array("CHECKSUMHASH" => $checkSum));
} else {
echo json_encode(array("ORDER_ID" => $decodeData["ORDER_ID"]));
}
} else {
echo "Something went wrong";
}
if (!is_array($decodeData)) {
throw new Exception(('Recieved content containes invalid JSON'));
}
结果json_decode
返回NULL
。即$decodeData
是NULL
。
$content
会返回正确的详细信息。
要指出的一件事是
$content
包含PAYTM_MERCHANT_KEY
具有特殊字符,例如@和%。那是原因json_decode
无法解码数据?
我的代码有问题吗?