cakeImport文件在Cake Php 3.8中



我只是想在CakePhp中包含一个文件,但没有任何帮助。我已经将该文件放在供应商文件夹中。

这是该文件的路径:

vendor/paytm/PaytmChecksum.php

我试图在我的控制器中导入它,如下所示:

require_once(ROOT  . DS .  'vendor'  . DS .  'paytm'  . DS .  'PaytmChecksum.php');

但没用。所以,我尝试了另一种方法,在控制器顶部的两行下面加上

use CakeFilesystemFile;
use CakeFilesystemFolder;

然后在控制器操作中这样做:

$dir = new Folder(ROOT . DS . 'vendor' . DS . 'paytm' . DS . 'PaytmChecksum.php');

但什么都不起作用。我试图将文件夹放在当前目录中,然后尝试将文件包含在require_once中,但也没有起作用。

有人能帮我做同样的事吗?

我在paytm校验和中也遇到了一个问题。所以我在组件中创建了一个文件。......srcControllerComponentPaytmChecksumComponent.php

代码是.

<?php
namespace AppControllerComponent;
use CakeControllerComponent;
define('PAYTM_ENVIRONMENT', 'TEST'); // PROD
define('PAYTM_MERCHANT_KEY', '*********************'); //Change this constant's value with Merchant key received from Paytm.
define('PAYTM_MERCHANT_MID', '*************'); //Change this constant's value with MID (Merchant ID) received from Paytm.
define('PAYTM_MERCHANT_WEBSITE', 'WEBSTAGING'); //Change this constant's value with Website name received from Paytm.
define('PAYTM_REFUND_URL', '');
class PaytmChecksumComponent extends Component
{
public $PAYTM_STATUS_QUERY_NEW_URL = 'https://securegw-stage.paytm.in/merchant-status/getTxnStatus';
public $PAYTM_TXN_URL = 'https://securegw-stage.paytm.in/theia/processTransaction';
public function initialize(array $config): void
{
if (PAYTM_ENVIRONMENT == 'PROD') {
$this->PAYTM_STATUS_QUERY_NEW_URL = 'https://securegw.paytm.in/merchant-status/getTxnStatus';
$this->PAYTM_TXN_URL = 'https://securegw.paytm.in/theia/processTransaction';
}
define('PAYTM_STATUS_QUERY_URL', $this->PAYTM_STATUS_QUERY_NEW_URL);
define('PAYTM_STATUS_QUERY_NEW_URL', $this->PAYTM_STATUS_QUERY_NEW_URL);
define('PAYTM_TXN_URL', $this->PAYTM_TXN_URL);
}
function encrypt_e($input, $ky)
{
$key   = html_entity_decode($ky);
$iv = "@@@@&&&&####$$$$";
$data = openssl_encrypt($input, "AES-128-CBC", $key, 0, $iv);
return $data;
}
function decrypt_e($crypt, $ky)
{
$key   = html_entity_decode($ky);
$iv = "@@@@&&&&####$$$$";
$data = openssl_decrypt($crypt, "AES-128-CBC", $key, 0, $iv);
return $data;
}
function generateSalt_e($length)
{
$random = "";
srand((float) 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)
{
if ($value == 'null')
$value = '';
return $value;
}
function getChecksumFromArray($arrayList, $key, $sort = 1)
{
if ($sort != 0) {
ksort($arrayList);
}
$str = $this->getArray2Str($arrayList);
$salt = $this->generateSalt_e(4);
$finalString = $str . "|" . $salt;
$hash = hash("sha256", $finalString);
$hashString = $hash . $salt;
$checksum = $this->encrypt_e($hashString, $key);
return $checksum;
}
function getChecksumFromString($str, $key)
{
$salt = $this->generateSalt_e(4);
$finalString = $str . "|" . $salt;
$hash = hash("sha256", $finalString);
$hashString = $hash . $salt;
$checksum = $this->encrypt_e($hashString, $key);
return $checksum;
}
function verifychecksum_e($arrayList, $key, $checksumvalue)
{
$arrayList = $this->removeCheckSumParam($arrayList);
ksort($arrayList);
$str = $this->getArray2StrForVerify($arrayList);
$paytm_hash = $this->decrypt_e($checksumvalue, $key);
$salt = substr($paytm_hash, -4);
$finalString = $str . "|" . $salt;
$website_hash = hash("sha256", $finalString);
$website_hash .= $salt;
$validFlag = "FALSE";
if ($website_hash == $paytm_hash) {
$validFlag = "TRUE";
} else {
$validFlag = "FALSE";
}
return $validFlag;
}
function verifychecksum_eFromStr($str, $key, $checksumvalue)
{
$paytm_hash = $this->decrypt_e($checksumvalue, $key);
$salt = substr($paytm_hash, -4);
$finalString = $str . "|" . $salt;
$website_hash = hash("sha256", $finalString);
$website_hash .= $salt;
$validFlag = "FALSE";
if ($website_hash == $paytm_hash) {
$validFlag = "TRUE";
} else {
$validFlag = "FALSE";
}
return $validFlag;
}
function getArray2Str($arrayList)
{
$findme   = 'REFUND';
$findmepipe = '|';
$paramStr = "";
$flag = 1;
foreach ($arrayList as $key => $value) {
$pos = strpos($value, $findme);
$pospipe = strpos($value, $findmepipe);
if ($pos !== false || $pospipe !== false) {
continue;
}
if ($flag) {
$paramStr .= $this->checkString_e($value);
$flag = 0;
} else {
$paramStr .= "|" . $this->checkString_e($value);
}
}
return $paramStr;
}
function getArray2StrForVerify($arrayList)
{
$paramStr = "";
$flag = 1;
foreach ($arrayList as $key => $value) {
if ($flag) {
$paramStr .= $this->checkString_e($value);
$flag = 0;
} else {
$paramStr .= "|" . $this->checkString_e($value);
}
}
return $paramStr;
}
function redirect2PG($paramList, $key)
{
$hashString = $this->getchecksumFromArray($paramList, $key);
$checksum = $this->encrypt_e($hashString, $key);
}
function removeCheckSumParam($arrayList)
{
if (isset($arrayList["CHECKSUMHASH"])) {
unset($arrayList["CHECKSUMHASH"]);
}
return $arrayList;
}
function getTxnStatus($requestParamList)
{
return $this->callAPI(PAYTM_STATUS_QUERY_URL, $requestParamList);
}
function getTxnStatusNew($requestParamList)
{
return $this->callNewAPI(PAYTM_STATUS_QUERY_NEW_URL, $requestParamList);
}
function initiateTxnRefund($requestParamList)
{
$CHECKSUM = $this->getRefundChecksumFromArray($requestParamList, PAYTM_MERCHANT_KEY, 0);
$requestParamList["CHECKSUM"] = $CHECKSUM;
return $this->callAPI(PAYTM_REFUND_URL, $requestParamList);
}
function callAPI($apiURL, $requestParamList)
{
$jsonResponse = "";
$responseParamList = array();
$JsonData = json_encode($requestParamList);
$postData = 'JsonData=' . urlencode($JsonData);
$ch = curl_init($apiURL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($postData)
));
$jsonResponse = curl_exec($ch);
$responseParamList = json_decode($jsonResponse, true);
return $responseParamList;
}
function callNewAPI($apiURL, $requestParamList)
{
$jsonResponse = "";
$responseParamList = array();
$JsonData = json_encode($requestParamList);
$postData = 'JsonData=' . urlencode($JsonData);
$ch = curl_init($apiURL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($postData)
));
$jsonResponse = curl_exec($ch);
$responseParamList = json_decode($jsonResponse, true);
return $responseParamList;
}
function getRefundChecksumFromArray($arrayList, $key, $sort = 1)
{
if ($sort != 0) {
ksort($arrayList);
}
$str = $this->getRefundArray2Str($arrayList);
$salt = $this->generateSalt_e(4);
$finalString = $str . "|" . $salt;
$hash = hash("sha256", $finalString);
$hashString = $hash . $salt;
$checksum = $this->encrypt_e($hashString, $key);
return $checksum;
}
function getRefundArray2Str($arrayList)
{
$findmepipe = '|';
$paramStr = "";
$flag = 1;
foreach ($arrayList as $key => $value) {
$pospipe = strpos($value, $findmepipe);
if ($pospipe !== false) {
continue;
}
if ($flag) {
$paramStr .= $this->checkString_e($value);
$flag = 0;
} else {
$paramStr .= "|" . $this->checkString_e($value);
}
}
return $paramStr;
}
function callRefundAPI($refundApiURL, $requestParamList)
{
$jsonResponse = "";
$responseParamList = array();
$JsonData = json_encode($requestParamList);
$postData = 'JsonData=' . urlencode($JsonData);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $refundApiURL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$jsonResponse = curl_exec($ch);
$responseParamList = json_decode($jsonResponse, true);
return $responseParamList;
}
}

在控制器中加载组件

public function initialize(): void
{
parent::initialize();
//....................................
$this->loadComponent('PaytmChecksum');
//........................
}
// .............
function payment(){
//...$paytmParams = array(
"MID" => "*****",
"WEBSITE" => "DEFAULT",
"INDUSTRY_TYPE_ID" => "1",
"CHANNEL_ID" => "WEB",
"ORDER_ID" => "*************",
"CUST_ID" => "*****",
"MOBILE_NO" => "*****",
"EMAIL" => "*******",
"TXN_AMOUNT" => (float)100,
/* on completion of transaction, we will send you the response on this URL */
"CALLBACK_URL" => "https://******",
);
$checksum = $this->PaytmChecksum->getChecksumFromArray($paytmParams, "_@C%&uL"); 
pr($checksum);
}

最新更新