azandazama / menuplus
MenuPlus: 一个简化创建 USSD 应用程序过程的 PHP 库
v1.0
2020-05-21 20:37 UTC
This package is auto-updated.
Last update: 2024-09-19 15:34:42 UTC
README
USSD 是一种惊人的技术,对于那些想要创建能够触及大量人群的应用程序的人来说。USSD 是一种古老的技术,但即使在今天,它仍然有其存在的价值。这个 PHP 库通过 AAT Mobile USSD API 简化了创建此类应用的过程。
了解更多关于 MenuPlus 的信息
要求
为了使用 MenuPlus,您需要在与 AAT Mobile 建立 USSD 帐户后,然后可以要求这个库并开始编码 👨🏽💻
安装
MenuPlus 通过 Composer 安装。
composer require azandazama/menuplus
当然,您也可以手动编辑您的 composer.json 文件
{ "require": { "azandazama/menuplus": "^1.0" } }
USSD 菜单
MenuPlus 提供不同类型的 USSD 菜单,用于不同的目的。以下将展示代码和截图。
标准菜单
这个菜单提供所有功能,提供了无限选项和选项 URL。 截图
$ussd->title = 'Welcome to the Example Ussd Platform!'; $ussd->options = ['Option 1', 'Option 2', 'Option 3']; $ussd->option_url = ['index.php?page=1', 'index.php?page=2', 'index.php?page=3']; echo $ussd->addMenu($url);
选项有 URL($ussd->option_url
),您可以认为选项($ussd->options
)是链接,菜单是页面。选项和选项 URL 是平行数组,每个选项对应每个选项 URL。
文本菜单
这个菜单没有选项,因此标题被视为选项。 截图
$ussd->title = 'Please provide first and last name'; $ussd->option_url = 'index.php?file=4'; echo $ussd->addMenu($url);
分页菜单
这个菜单提供所有功能,并允许您使用分页对菜单进行排序
$ussd->title = 'Select an option'; $ussd->options = ['Option 1', 'Option 2', 'Option 3', 'Option 4', 'Option 5', 'Option 6', 'Option 7']; // Menu options can all share the same url $ussd->option_url = 'index.php?page=5'; // [3] is the amount of options that will be shown in this menu return $ussd->paginateMenu($url, 3);
入门
以下是一个 MenuPlus 库的基本使用示例。
<?php require_once './vendor/autoload.php'; $ussd = new \MenuPlus\Ussd; // ensure your url ends with a backslash $url = 'https://:7000/'; function initMenu($ussd, $url) { switch(@$_GET['page']) { case '': // This is the first menu the application will serve $ussd->title = 'Welcome to the Example Ussd Platform!'; $ussd->options = ['Questionnaire', 'Register', 'Shows available', 'Exit']; $ussd->option_url = ['index.php?page=1', 'index.php?page=2', 'index.php?page=3', 'index.php?page=4', 'index.php?page=exit']; return $ussd->addMenu($url); break; case 1: $ussd->title = 'What year was Nelson Mandela born'; $ussd->options = ['1900', '1918', 'Back']; $ussd->option_url = ['index.php?page=answer&ans=wrong', 'index.php?page=answer&ans=correct', 'index.php']; return $ussd->addMenu($url); break; case 2: // FreeText Menu's have no options just one title and url $ussd->title = 'Please provide first and last name'; $ussd->option_url = 'index.php?file=names'; return $ussd->addMenu($url); break; case 3: $ussd->title = 'Select your favourite TV show'; $ussd->options = ['The Simpsons', 'Star Wars', 'Peanuts', 'South Park', 'Courage the Cowardly Dog', 'Avatar: The Last Airbender', 'Dexters Laboratory', 'Futurama', 'The Jetsons', 'Phineas and Ferb', 'Kim Possible', 'Samurai Jack', 'Dora the Explorer']; // Menu options can all share the same url $ussd->option_url = 'index.php?page=shows'; // [5] is the amount of options that will be shown per menu return $ussd->paginateMenu($url, 5); break; case 'exit': $ussd->title = "Thank you!\nUssd Platform"; return $ussd->addMenu($url); break; } } echo initMenu($ussd, $url);
作者
- Azanda Zama 邮箱: judah.zama@gmail.com IG: @azanda.zama Twitter: @wlrdofazanda Linkedin: Azanda Zama