提问人:Shadrack Kipkorir 提问时间:11/6/2021 最后编辑:Stephen OstermillerShadrack Kipkorir 更新时间:2/25/2023 访问量:606
回调 URL 未接收 JSON 数据
Callback URL not receiving JSON data
问:
我有一个 PHP 页面,该页面接收 JSON 响应,位于 I have successfully posted responses using Postman when I post to either or
h 但当我发布到https://example.ac.ke/op/api/mypesa/index.php
https://example.com/op/api/mypesa/
ttps://example.com/op/api/mypesa/index.php
https://example.com/op/api/mypesa
我尝试在 htaccess 中重定向和添加尾随 / 徒劳无功。
我需要成为我的回调 URL。当我发布时,调用了接收页面,但似乎数据没有被重定向。https://example.com/op/api/mypesa
需要帮助重定向页面和帖子数据由于我成功重定向了页面但没有重定向数据
我的 .htaccess 包含以下内容
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L,QSA]
</IfModule>
使用邮递员发帖
从页面接收 JSON 数据的数据库表
使用邮递员向页面发布
我的索引文件的内容位于 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);
?>
答:
0赞
Joe Mwangi
2/25/2023
#1
确保您的回调 url 使用 https 从 safaricom API 获取响应。可以使用 ngrok!以在 Internet 上传输您的应用程序。
如果您已经这样做了并且您使用的是 ubuntu,您可以禁用 ufw 防火墙并重新启动计算机。sudo ufw disable
评论
/
/
/
/