Java USSD菜单树生成 - 如何 [英] Java USSD menu tree generation - how to
问题描述
我想使用Java生成一个基于树的菜单,该菜单将出现在USSD浏览器上。每个节点可能有子节点,以叶节点结尾。我还必须维护每个访问此菜单的用户的状态(比如他在菜单上的当前位置)以方便导航。
I want to generate a tree-based menu using Java that will appear on a USSD browser. Each node may have children, ending with leaf nodes. I will also have to maintain state regarding each user who accesses this menu (like his current position on the menu) to facilitate navigation.
关于如何实现树生成和状态管理?
Any ideas on how I may achieve the tree generation and state management?
推荐答案
我假设你从网关收到一条消息,例如:
(Session) #,UserInput)
你需要计算下一个要发送给用户的信息吗?
I assume that you get a message from the gateway such as: (Session#, UserInput) and you need to compute the next information to send to the user ?
我建议:
-
表CURRENTSTATE:
会话#
州
table CURRENTSTATE:
Session#
State
表状态:
状态
标题
table STATES:
State
Title
表格选择:
州
选择
名称
DoCode
NewState
table CHOICES:
State
Choice
Name
DoCode
NewState
然后当你收到消息(Session#,UserInput)时:
Then when you get the message (Session#, UserInput):
- 使用Session查询CURRENTSTATE #确定用户所处的状态。
- 使用State和Choice = UserInp查询CHOICES根据用户输入确定新状态(和DoCode)。
- 基于DoCode,您可以进行一些处理。
- 将CURRENTSTATE更新为反映新状态。
- 查询STATES获取标题(例如请选择一种颜色。
- 查询选择以获得新状态的可能选择(例如(1,蓝色),(2,红色)等。 )
- 构建消息(concat Title + choices)
- 向用户返回消息。
- query CURRENTSTATE using the Session# to determine what state the user is in.
- query CHOICES using the State and Choice=UserInput to determine the new state (and DoCode) based on user input.
- Based on DoCode, you can do some processing.
- update CURRENTSTATE to reflect the new state.
- query STATES to get the Title (e.g. "Please choose a color").
- query CHOICES to get the possible choices from the new state (e.g. (1, "Blue"), (2, "Red"), etc.)
- build the message (concat Title + choices)
- return message to user.
这是解决问题的合理方法吗?
Is that a reasonable way to solve the problem ?
这篇关于Java USSD菜单树生成 - 如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!