我回應(yīng)了這一點(diǎn)并在 ajax 中獲取。$result= $this->mpesa->STKPushQuery($checkoutRequestID, 174379, "bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919");json 得到的結(jié)果是:{"requestId":"","errorCode":"400.002.02","errorMessage":"Bad Request - Invalid CheckoutRequestID"}現(xiàn)在,在我的 php 代碼中,我需要獲取 errorCode 的鍵,有時(shí)它是 successCode,所以當(dāng)我嘗試這樣做時(shí):if ($result->errorCode=="400.002.02"){ $Data = '{"status":"Submit payment before Checking for it"}'; echo $Data;沒關(guān)系,因?yàn)?errorCode 是在 Json 中找到的。當(dāng)出現(xiàn)成功消息時(shí),即:if ($result->successCode=="0"){ $Data = '{"status":"Payment Successful"}'; echo $Data;}我在第一個(gè)語句中遇到錯(cuò)誤。因?yàn)樵?Json 中找不到 errorCode 所以我實(shí)際需要的是獲取 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;}
1 回答

慕沐林林
TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊
使用isset將實(shí)現(xiàn)您的目標(biāo):
$mystatusCode = ( isset($result->errorCode) ? $result->errorCode :
( isset($result->successCode) ? $result->successCode :
NULL
)
);
或者您可以直接在 if 語句中使用它,而不需要?jiǎng)?chuàng)建新的單個(gè)變量:
if (isset($result->errorCode) && $result->errorCode == "400.002.02") {
...
}
elseif (isset($result->successCode) && $result->successCode == "0") {
...
}
- 1 回答
- 0 關(guān)注
- 142 瀏覽
添加回答
舉報(bào)
0/150
提交
取消