Interaction method and device for virtual SIM card and server apduTechnical Field
The invention belongs to the technical field of communication, and relates to an interaction method and device for a virtual SIM card and a server apdu.
Background
Generally, interaction between a virtual SIM card and a back-end server APDU (Application Protocol Data Unit) is complicated, and sending a command to the virtual SIM card by the back-end server requires manual processing of the cause and effect relationship of multiple commands, for example, the back-end server needs to send two commands a and B to the virtual SIM card, but the command B needs to wait for the command a to return and then can be sent continuously, so that such a logical judgment needs to be written in a service code, which not only pollutes the service code, but also makes it difficult to add a command or modify the service code subsequently.
Disclosure of Invention
In view of this, the present invention provides an interaction method for a virtual SIM card and a server APDU, which handles the causal relationship of multiple commands, is isolated from a service code, and is convenient for maintenance.
In order to achieve the above object, in one aspect, the present invention provides the following technical solutions:
a method for interaction between a virtual SIM card and a server APDU comprises the following steps:
s1: sequentially inputting and storing commands to be sent in a configuration file, wherein each command comprises a command name, a command type, command content and a command execution type;
s2: inputting a command name which needs to be sent to the virtual SIM card on a background management page;
s3: reading the configuration file to a server memory, and analyzing the configuration file into a json tree;
s4: the server analyzes the relationship among the multiple commands in the json tree according to the command execution type in the configuration file, wherein the relationship comprises a sequence relationship and a causal relationship;
s5: if the commands needing to be sent are in a sequential relation, the server sends all the commands to the virtual SIM card together in sequence; and if the command is in a cause-and-effect relationship, the server dynamically generates a next command after receiving a corresponding return result of the virtual SIM card and continuously sends the next command to the virtual SIM card.
Further, one command in the configuration file can include a plurality of parallel instructions, and a sequence relationship or a causal relationship also exists among the instructions.
In another aspect of the present invention, a device for interaction between a virtual SIM card and a server APDU is provided, which includes a server, a management terminal and a virtual SIM card, where the server includes an APDU interaction engine and a communication module, and the APDU interaction engine includes a reading module, a json tree analysis module, a relationship analysis module, a sending module, a receiving module and a command generation module; the management terminal is used for adding or modifying commands in the configuration file, communicating with the server and inputting commands to be sent;
the server is connected with the management terminal and the virtual SIM card through the communication module, the reading module is used for reading the content of the configuration file, the json tree analyzing module is used for analyzing the configuration file into a json tree, the relation analyzing module is used for analyzing the relation of a plurality of commands in the configuration file, the relation comprises a sequence relation and a causal relation, the commands of the sequence relation are directly and simultaneously sent to the virtual SIM card through the sending module in sequence, the receiving module is used for receiving a return result after the virtual SIM card receives the commands, the command generating module is used for generating a next sent command according to the return result of the virtual SIM card, and the commands of the causal relation are dynamically generated by the command generating module after the receiving module receives the return result of the virtual SIM card and then are sent to the virtual SIM card through the sending module.
The system further comprises a database which stores command contents, the database is connected with the server, and the reading module reads the command contents in the database according to the configuration file.
The invention has the beneficial effects that: the invention solves the problem of hard coding, does not need to modify the service codes when the commands need to be added in the later stage of the project, directly configures the sequence and the causal relationship in the configuration file, reduces the pollution to the service codes and is more convenient for subsequent maintenance and modification.
Drawings
In order to make the object, technical scheme and beneficial effect of the invention more clear, the invention provides the following drawings for explanation:
FIG. 1 is a detailed flow chart of an embodiment of the present invention.
Detailed Description
Preferred embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
A method for interaction between a virtual SIM card and a server APDU comprises the following steps:
s1: sequentially inputting and storing commands to be sent in a configuration file, wherein each command comprises a command name, a command type, command content and a command execution type;
s2: inputting a command name which needs to be sent to the virtual SIM card on a background management page;
s3: reading the configuration file to a server memory, and analyzing the configuration file into a json tree;
s4: the server analyzes the relationship among the multiple commands in the json tree according to the command execution type in the configuration file, wherein the relationship comprises a sequence relationship and a causal relationship;
s5: if the commands needing to be sent are in a sequential relation, the server sends all the commands to the virtual SIM card together in sequence; and if the command is in a cause-and-effect relationship, the server dynamically generates a next command after receiving a corresponding return result of the virtual SIM card and continuously sends the next command to the virtual SIM card.
One command in the configuration file can comprise a plurality of parallel instructions, and sequence relations or causal relations also exist among the instructions.
The invention is illustrated by a specific embodiment.
The method comprises the following steps: entering commands in the configuration file:
the method comprises the steps that a cd-mf and a read-2fe2 are names of commands, type is command type, data is command content, is-dynamic is command execution type, and is-dynamic is false, wherein the command is not a dynamic command, does not need to wait for a virtual SIM card to return a result and is dynamically generated through an APDU interactive engine, and is directly sent to the virtual SIM card together with the previous command in sequence; the "is-dynamic" is "true" indicating that the command is a dynamic command, and the previous command needs to be sent first, and waits for the result returned by the virtual SIM card, and then the APDU interaction engine dynamically generates the command according to the result and sends the command to the virtual SIM card.
A device for interaction between a virtual SIM card and a server APDU comprises a server, a management terminal and the virtual SIM card, wherein the server comprises an APDU interaction engine and a communication module, and the APDU interaction engine comprises a reading module, a json tree analysis module, a relation analysis module, a sending module, a receiving module and a command generation module; the management terminal is used for adding or modifying commands in the configuration file, communicating with the server and inputting commands to be sent;
the server is connected with the management terminal and the virtual SIM card through the communication module, the reading module is used for reading the content of the configuration file, the json tree analyzing module is used for analyzing the configuration file into a json tree, the relation analyzing module is used for analyzing the relation of a plurality of commands in the configuration file, the relation comprises a sequence relation and a causal relation, the commands of the sequence relation are directly and simultaneously sent to the virtual SIM card through the sending module in sequence, the receiving module is used for receiving a return result after the virtual SIM card receives the commands, the command generating module is used for generating a next sent command according to the return result of the virtual SIM card, and the commands of the causal relation are dynamically generated by the command generating module after the receiving module receives the return result of the virtual SIM card and then are sent to the virtual SIM card through the sending module.
The system also comprises a database which stores command contents, the database is connected with the server, and the reading module also reads the command contents in the database according to the configuration file.
As shown in fig. 1, when an administrator issues cd-mf and read-2fe2 commands through a management terminal, a reading module sends a configuration file to a memory, a json tree analysis module analyzes the configuration file into a json tree, a relationship analysis module analyzes that a first instruction in a cd-mf command and a read-2fe2 command is an inactive command, namely, a command sent in sequence, a sending module sends the cd-mf command and the first instruction of read-2fe2 to a virtual SIM card in sequence, the sending module waits for a result returned by the virtual SIM card, a receiving module sends the result to a command generation module after receiving the returned result to generate a next complete command, and the command is sent to the virtual SIM card through the sending module.
When the command type is "open", which means that the command content of the command is only a part, the remaining part is stored in the database, and the reading module will also read the remaining part from the database for parsing and sending.
Finally, it is noted that the above-mentioned preferred embodiments illustrate rather than limit the invention, and that, although the invention has been described in detail with reference to the above-mentioned preferred embodiments, it will be understood by those skilled in the art that various changes in form and detail may be made therein without departing from the scope of the invention as defined by the appended claims.