0

我 有一个接收https://example.ac.ke/op/api/mypesa/index.php JSON 响应的https://example.com/op/api/mypesa/ PHP页面,位于ttps://example.com/op/api/mypesa/index.phphttps://example.com/op/api/mypesa

我尝试在 htaccess 中重定向和添加尾随 / 是徒劳的。我需要https://example.com/op/api/mypesa成为我的回调 URL。当我发布接收页面时被调用,但似乎数据没有被重定向。

需要帮助重定向页面和发布数据 因为我成功重定向页面但没有数据

我的 .htaccess 有以下内容

<IfModule mod_rewrite.c>

     RewriteEngine On
     RewriteCond %{REQUEST_FILENAME}  -f [OR]
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteRule ^(.*)$ index.php [L,QSA]

</IfModule>

使用邮递员发帖

使用邮递员发布到页面 https://example.com/op/api/mypesa//

从页面接收 json 数据的数据库表

从页面接收json数据的数据库表

使用邮递员发布到页面

  • 使用邮递员发布到页面 https://example.com/op/api/mypesa

我的索引文件的内容位于 mypesa 文件夹中

<?php
   require 'config.php';
    header("Content-Type: application/json");

    $response = '{
        "ResultCode": 0, 
        "ResultDesc": "Confirmation Received Successfully"
    }';

    $mpesaResponse = file_get_contents('php://input');

    $logFile = "M_PESAConfirmationResponse.txt";

    $jsonMpesaResponse = json_decode($mpesaResponse, true); 

    $transaction = array(
            ':TransactionType'      => $jsonMpesaResponse['TransactionType'],
            ':TransID'              => $jsonMpesaResponse['TransID'],
            ':TransTime'            => $jsonMpesaResponse['TransTime'],
            ':TransAmount'          => $jsonMpesaResponse['TransAmount'],
            ':BusinessShortCode'    => $jsonMpesaResponse['BusinessShortCode'],
            ':BillRefNumber'        => $jsonMpesaResponse['BillRefNumber'],
            ':InvoiceNumber'        => $jsonMpesaResponse['InvoiceNumber'],
            ':OrgAccountBalance'    => $jsonMpesaResponse['OrgAccountBalance'],
            ':ThirdPartyTransID'    => $jsonMpesaResponse['ThirdPartyTransID'],
            ':MSISDN'               => $jsonMpesaResponse['MSISDN'],
            ':FirstName'            => $jsonMpesaResponse['FirstName'],
            ':MiddleName'           => $jsonMpesaResponse['MiddleName'],
            ':LastName'             => $jsonMpesaResponse['LastName']
    );

  
    $log = fopen($logFile, "a");
    fwrite($log, $mpesaResponse);
    fclose($log);

    echo $response;

 
    insert_response($transaction);
?>
4

0 回答 0