php - 哪个是使用 PHP (8) 检查用户在 Ussd 程序中选择的选项的更好方法
问题描述
我正在使用非洲跟踪测试环境在 PHP(版本 8)中构建一个简单的基于 USSD 的支付网关
我不知道哪个是检查当前用户选择或与之交互的级别或选项的更好方法
我目前的代码..
public function handleSession(Request $request)
{
$text=$request->input('text');
// We split the response(text) to an array
// It helps us to check which option the current user selects
$level = explode("*", $text);
// Initially, the response is an empty string
if ( $text == "" ) {
// We send our ussd menu
$response = $this->welcomeInterface();
}
// If user selects the first option from the menu (first level menu)
if(isset($level[0]) && $level[0] == 1 && !isset($level[1]))
{
$response = $this->buyerOptionsInterface();
}
// If user select the second option from the menu
if(isset($level[0]) && $level[0] == 2 && !isset($level[1]))
{
$response = $this->sellerOptionsInterface();
}
// If user select the third option from the menu (last option)
if(isset($level[0]) && $level[0] == 3 && !isset($level[1]))
{
$response= $this->termsAndConditionsInterface();
}
// If user selects the first option from our first level menu, and first option of second level menu
if(isset($level[0]) && $level[0] == 1 && isset($level[1]) && $level[1] == 1 && !isset($level[2])) {
$response = $this->insertSellerPhoneNumber();
}
// If user select the first option of first level menu,and first option of second level menu and first option of third level menu
if(isset($level[0]) && $level[0] == 1 && isset($level[1]) && $level[1] == 1 && isset($level[2]) && $level[2] == 1 && !isset($level[3])) {
$response = $this->insertPrice();
}
header('Content-type: text/plain');
echo $response;
}
代码有效,但是当用户被说到第五层时,它们变得更难阅读
哪个是重构上述代码的更好方法,框架是 Laravel (Version 8)
解决方案
推荐阅读
- python - 运行python脚本时,找不到模块错误
- python - Tesseract - 根本无法识别希腊字母
- r - 使用 map() 创建绘图列表
- powerbi - 将共享文件夹连接到 power bi
- python - 如何将卡住的功能包装在计时器块中?
- authentication - 将凭据传入和传出 Dialogflow 的最佳方式是什么
- python - 如何同时绘制带有样式编码和颜色编码的 swarmplot/stripplot
- javascript - 使用没有 style-src 'unsafe-inline' 的 ACE Web-Editor
- angular - 重定向后未显示角度材料表数据
- assembly - 由有符号单字节元素组成的正元素之和