我回应了这一点并在 ajax 中获取。
$result= $this->mpesa->STKPushQuery($checkoutRequestID, 174379, "bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919");
json 得到的结果是:
{"requestId":"","errorCode":"400.002.02","errorMessage":"Bad Request - Invalid CheckoutRequestID"}
现在,在我的 php 代码中,我需要获取 errorCode 的键,有时它是 successCode,所以当我尝试这样做时:
if ($result->errorCode=="400.002.02"){
$Data = '{"status":"Submit payment before Checking for it"}';
echo $Data;
没关系,因为 errorCode 是在 Json 中找到的。当出现成功消息时,即:
if ($result->successCode=="0"){
$Data = '{"status":"Payment Successful"}';
echo $Data;
}
我在第一个语句中遇到错误。因为在 Json 中找不到 errorCode 所以我实际需要的是获取 json 的密钥(这将是 errorCode 或 successCode),即
$mystatusCode== Get the either the errorCode or SuccessCode (key in Json array[1])
if ($results->mystatusCode=="400.002.02"){
$Data = '{"status":"Submit payment before Checking for it"}';
echo $Data;
}else if ($results->mystatusCode=="0"){
$Data = '{"status":"Payment has been processed successfully"}';
echo $Data;
}
慕沐林林