CN110336856B - Interface calling method and device, electronic equipment and storage medium - Google Patents

Interface calling method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN110336856B
CN110336856B CN201910386979.3A CN201910386979A CN110336856B CN 110336856 B CN110336856 B CN 110336856B CN 201910386979 A CN201910386979 A CN 201910386979A CN 110336856 B CN110336856 B CN 110336856B
Authority
CN
China
Prior art keywords
interface
request
called
processing result
preset time
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910386979.3A
Other languages
Chinese (zh)
Other versions
CN110336856A (en
Inventor
朱章
卢一飞
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chengdu Zhongshen Growth Technology Co ltd
Original Assignee
Chengdu Zhongshen Growth Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Chengdu Zhongshen Growth Technology Co ltd filed Critical Chengdu Zhongshen Growth Technology Co ltd
Priority to CN201910386979.3A priority Critical patent/CN110336856B/en
Publication of CN110336856A publication Critical patent/CN110336856A/en
Application granted granted Critical
Publication of CN110336856B publication Critical patent/CN110336856B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/133Protocols for remote procedure calls [RPC]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/34Network arrangements or protocols for supporting network services or applications involving the movement of software or configuration parameters 
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]

Abstract

The application provides an interface calling method, an interface calling device, an electronic device and a storage medium, wherein the interface calling method comprises the following steps: controlling a task execution thread to send an asynchronous interface calling request to interface equipment to be called, wherein the calling request comprises: the method comprises the steps that data to be processed, an interface ID to be called and a request ID are obtained, so that the interface equipment obtains a processing result based on the data to be processed and the interface ID to be called; and releasing the occupation of the request on the thread within a first preset time length from the sending of the request, and controlling the thread to send a next asynchronous interface calling request to the interface equipment, wherein the first preset time length is less than a second preset time length, and the second preset time length is the time length from the sending of the request to the receiving of a state code corresponding to the request ID returned by the interface equipment, so that the thread is not required to be released after the state code returned by the interface equipment to be called is obtained, the waiting time of the thread is shortened, and the calling request processing efficiency is improved.

Description

Interface calling method and device, electronic equipment and storage medium
Technical Field
The present application relates to the field of data processing, and in particular, to an interface calling method, an interface calling apparatus, an electronic device, and a storage medium.
Background
With the development of internet technology, platforms with leading technical status in respective fields gradually open their functional interfaces, which are provided for broad developers to call, and the developers can use more advanced and comprehensive functions while not needing to perform lengthy and repetitive development or related development and technical learning, thereby bringing more perfect products.
However, in the existing asynchronous interface calling technology, after a server sends an asynchronous interface calling request to a third-party server by a control thread, the thread must be released after a status code returned by the third-party server is received, and the thread can process the next asynchronous interface calling request.
Content of application
In view of this, an object of the embodiments of the present application is to provide an interface calling method, an interface calling apparatus, an electronic device, and a storage medium, so as to improve the processing efficiency of an interface calling request, shorten the waiting time of a user, and improve the user experience.
In a first aspect, an embodiment of the present application provides an interface calling method, where the method includes: controlling a task execution thread to send an asynchronous interface calling request to interface equipment to be called, wherein the calling request comprises: the method comprises the steps that data to be processed, an interface ID to be called and a request ID are obtained, so that the interface equipment obtains a processing result based on the data to be processed and the interface ID to be called; and releasing the occupation of the request on the thread within a first preset time length after the request is sent, and controlling the thread to send a next asynchronous interface calling request to the interface equipment, wherein the first preset time length is less than a second preset time length, and the second preset time length is the time length from the sending of the request to the receiving of a state code corresponding to the request ID returned by the interface equipment.
In the implementation process, for each asynchronous interface calling request, within a first preset time length from the sending of the request to the interface device to be called, the occupation of the request on the thread is released, and the thread is controlled to send a next asynchronous interface calling request to the interface device, wherein the first preset time length is less than a second preset time length, the second preset time length is the time length from the sending of the request to the receiving of the status code corresponding to the request ID returned by the interface device, and the thread is not required to be released after the status code returned by the interface device to be called is obtained, so that the waiting time of the thread is shortened, the processing efficiency of the interface calling request is improved, the waiting time of a user is shortened, and the user experience is improved.
Based on the first aspect, in one possible design, after the task execution thread sends the asynchronous interface call request to the interface device to be called, the method further includes: determining whether a processing result corresponding to the request ID returned by the interface equipment is received within a third preset time length from the sending of the request, wherein the third preset time length is longer than the second preset time length; and when determining that the processing result corresponding to the request ID returned by the interface equipment is not received, retransmitting the request to the interface equipment.
In the implementation process, whether a processing result returned by the interface device is received or not is determined within a third preset time length from the sending of the request, wherein the third preset time length is longer than the second preset time length, and the request is retransmitted to the interface device when the processing result returned by the interface device is determined not to be received.
Based on the first aspect, in a possible design, after determining whether a processing result corresponding to the request ID returned by the interface device is received, the method further includes: determining that a processing result corresponding to the request ID returned by the interface equipment is received; correspondingly storing the processing result, the interface ID to be called and the data to be processed; and when the interface ID to be called and the data to be processed are obtained again, obtaining a processing result corresponding to the interface ID to be called and the data to be processed from a pre-stored corresponding relation among the processing result, the interface ID to be called and the data to be processed.
In the implementation process, the processing result, the interface ID to be called and the data to be processed are correspondingly stored, when the same interface ID to be called and the same data to be processed are obtained again, the interface ID to be called and the data to be processed are not required to be sent to the interface device to be called, and the processing result corresponding to the interface ID to be called and the data to be processed is directly obtained from the corresponding relation among the pre-stored processing result, the interface ID to be called and the data to be processed, so that the processing efficiency of an interface calling request is improved, the waiting time of a user is shortened, and the user experience is improved.
Based on the first aspect, in one possible design, before the controlling task execution thread sends the asynchronous interface call request to the interface device to be called, the method further includes: receiving an interface calling requirement sent by a user terminal, wherein the interface calling requirement comprises: the interface ID to be called and the data to be processed; caching the interface calling requirement to a cache queue; controlling the thread to read the interface calling requirement from the cache queue; and controlling the thread to generate the calling request based on the interface ID to be called in the interface calling requirement, the data to be processed in the interface calling requirement and the pre-allocated request ID corresponding to the interface calling requirement.
In the implementation process, the calling requirement is cached to the cache correspondingly, when the calling requirement can be processed, the interface calling requirement is read from the cache queue, and the calling requirement is processed, so that the reading and processing of the requirement are adapted to the actual processing capacity.
Based on the first aspect, in a possible design, the interface call requirement further includes: after the account of the user terminal controls the thread to read the interface call requirement from the cache queue, the method further includes: and controlling the thread to extract the account number of the user terminal in the interface calling requirement, and determining that the account number of the user terminal is a legal account number.
In the implementation process, whether the account number of the user terminal is a legal account number is determined, when the account number of the user terminal is the legal account number, the interface calling requirement is processed, otherwise, the interface calling requirement is not processed, the calling request cannot be sent to the interface equipment to be called, and then, the calling of the interface equipment to be called by an illegal user is prevented.
Based on the first aspect, in a possible design, determining that the account of the user terminal is a valid account includes: and determining the account of the user terminal as a legal account based on the corresponding relation between the pre-stored account and the interface ID.
In the implementation process, for each interface, when the interface only allows part of users to call, whether the account of the user terminal is a legal account is determined based on the corresponding relationship between the pre-stored account and the interface ID, when the account of the user terminal and the interface ID to be called are completely matched with the pre-stored account and the interface ID, the account of the user terminal is determined to be a legal account, otherwise, the account of the user terminal is determined to be an illegal account, and then the interface is prevented from being called by the illegal user.
In a possible design based on the first aspect, the method further includes: and after receiving a processing result corresponding to the request ID returned by the interface equipment, sending the processing result to the user terminal corresponding to the request ID.
In the implementation process, based on the request ID, the processing result corresponding to the request ID can be accurately sent to the user terminal corresponding to the request ID.
In a second aspect, an embodiment of the present application provides an interface invoking device, where the interface invoking device includes: a sending unit, configured to control a task execution thread to send an asynchronous interface call request to an interface device to be called, where the call request includes: the method comprises the steps that data to be processed, an interface ID to be called and a request ID are obtained, so that the interface equipment obtains a processing result based on the data to be processed and the interface ID to be called; the release unit is used for releasing the occupation of the thread by the request within a first preset time length from the sending of the request and controlling the thread to send a next asynchronous interface calling request to the interface equipment; the first preset time length is less than a second preset time length, and the second preset time length is the time length from the time when the request is sent to the time when a status code corresponding to the request ID returned by the interface equipment is received.
Based on the second aspect, in one possible design, the apparatus further includes: the device further comprises: the judging unit is used for determining whether a processing result which is returned by the interface equipment and corresponds to the request ID is received or not within a third preset time length from the sending of the request; the third preset time length is longer than the second preset time length; and the first execution unit is used for retransmitting the request to the interface equipment when determining that the processing result corresponding to the request ID returned by the interface equipment is not received.
Based on the second aspect, in one possible design, the apparatus further includes: a determining unit, configured to determine that a processing result corresponding to the request ID returned by the interface device is received; the storage unit is used for correspondingly storing the processing result, the interface ID to be called and the data to be processed; and the obtaining unit is used for obtaining a processing result corresponding to the interface ID to be called and the data to be processed from a pre-stored corresponding relation among the processing result, the interface ID to be called and the data to be processed when the interface ID to be called and the data to be processed are obtained again.
Based on the second aspect, in one possible design, the apparatus further includes: the device comprises a receiving unit and a processing unit, wherein the receiving unit is used for receiving an interface calling requirement sent by a user terminal, and the interface calling requirement comprises: the interface ID to be called and the data to be processed; the cache unit is used for caching the interface calling requirement to a cache queue; the reading unit is used for controlling the thread to read the interface calling requirement from the cache queue; and the processing unit is used for controlling the interface ID to be called in the interface calling requirement of the thread, the data to be processed in the interface calling requirement and a pre-allocated request ID corresponding to the interface calling requirement to generate the calling request.
Based on the second aspect, in a possible design, the interface call requirement further includes: the account of the user terminal, the apparatus further comprising: and the account determining unit is used for controlling the thread to extract the account of the user terminal in the interface calling requirement and determining the account of the user terminal as a legal account.
Based on the second aspect, in a possible design, the account determination unit is further configured to determine, based on a correspondence between a pre-stored account and an interface ID, that the account of the user terminal is a valid account.
Based on the second aspect, in one possible design, the apparatus further includes: and the result sending unit is used for sending the processing result to the user terminal corresponding to the request ID after receiving the processing result corresponding to the request ID returned by the interface equipment.
In a third aspect, an embodiment of the present application provides an electronic device, including a processor and a memory connected to the processor, where a computer program is stored in the memory, and when the computer program is executed by the processor, the electronic device is caused to perform the method of the first aspect.
In a fourth aspect, an embodiment of the present application provides a storage medium, in which a computer program is stored, and when the computer program runs on a computer, the computer is caused to execute the method of the first aspect.
Additional features and advantages of the present application will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by the practice of the embodiments of the present application. The objectives and other advantages of the application may be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the embodiments are briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained according to the drawings without inventive efforts;
fig. 1 is a schematic structural diagram of an interface call system according to an embodiment of the present application;
fig. 2 is a schematic flowchart of a seed interface calling method according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of an interface invoking device according to an embodiment of the present disclosure;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
The technical solution in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures. Meanwhile, in the description of the present application, the terms "first", "second", and the like are used only for distinguishing the description, and are not to be construed as indicating or implying relative importance.
Examples
Referring to fig. 1, fig. 1 is a schematic structural diagram of an interface invoking system provided in an embodiment of the present application, and as shown in fig. 1, the system includes a user terminal, a server, and an interface device, where the interface device is a device capable of providing a plurality of function interface invoking services for the user terminal, where the number of the user terminal is at least one, the number of the server is at least one, and the number of the interface device is at least one, and in this embodiment, for convenience of description, it is assumed that the number of the user terminals is multiple (such as a user terminal 11, a user terminal 12, a user terminal 13, and the like), the number of the server is 1, the number of the interface device is 1, in other embodiments, the number of the servers may be 2, 5, and the number of the interface devices may be 2, 3, 5, and the like, the above number is not limiting.
Based on the interface calling system, referring to fig. 2, the interface calling method applied to the interface calling system may include:
s100: the method comprises the following steps that a server controls a task execution thread to send an asynchronous interface calling request to interface equipment to be called, wherein the calling request comprises: the data processing method comprises the steps of data to be processed, an interface ID to be called and a request ID.
S110: and the interface equipment returns a status code to the server based on the calling request.
S120: and the interface equipment returns a processing result to the server based on the data to be processed and the interface to be called.
S200: the server releases the occupation of the request on the thread within a first preset time length after the request is sent, and controls the thread to send a next asynchronous interface calling request to the interface equipment; the first preset time length is less than a second preset time length, and the second preset time length is the time length from the time when the request is sent to the time when a status code corresponding to the request ID returned by the interface equipment is received.
S300: after receiving the processing result corresponding to the request ID returned by the interface device, the server sends the processing result to the user terminal 11 corresponding to the request ID.
The execution sequence of S120 and S200 is not limited.
The flow of the method of the present application is described in detail below.
S100: the method comprises the following steps that a server controls a task execution thread to send an asynchronous interface calling request to interface equipment to be called, wherein the calling request comprises: the interface device comprises data to be processed, an interface ID to be called and a request ID, so that the interface device can obtain a processing result based on the data to be processed and the interface ID to be called.
In the method, a server controls an available and idle task execution thread to send a connection establishment request to an interface device to be called based on a Transmission Control Protocol/Internet Protocol (TCP/IP) under the condition that an asynchronous interface call request to be processed exists and an available and idle task execution thread exists, and after the connection establishment is successful, the server controls the thread to send the asynchronous interface call request to be processed to the interface device to be called, wherein the call request comprises: the interface device comprises data to be processed, an interface ID to be called and a request ID, so that the interface device calls a corresponding interface function based on the interface ID to be called to process the data to be processed, and a processing result is obtained. In this embodiment, the server adopts a multi-threaded service mode, the number of the task execution threads is multiple, the number of the task execution threads is positively correlated with the processing capacity of the server, and in order to better distinguish each call request, the server allocates a request ID to each call request, and the request IDs of the call requests are different, so that the interface device can correctly correlate the processing result with the request ID, and then when the server successfully receives the processing result corresponding to the request ID returned by the interface device, the server can correctly correlate the call request corresponding to the request ID with the processing result.
As an implementation manner, the invocation request further includes: the account ID is used for enabling the interface device to be called to determine whether the account ID is legal or not based on the account ID stored in advance, and in the case that the account ID is illegal, the interface device to be called returns prompt information used for representing call failure to the server, where the prompt information may be represented by 00 or 11, and the form of the prompt information is not limited.
S200: the server releases the occupation of the request on the thread within a first preset time length after the request is sent, and controls the thread to send a next asynchronous interface calling request to the interface equipment; the first preset time length is less than a second preset time length, and the second preset time length is the time length from the time when the request is sent to the time when a status code corresponding to the request ID returned by the interface equipment is received.
The server releases the occupation of the request to the thread within a first preset time length from the time when the thread sends the request to the interface equipment to be called, controls the thread to process the next asynchronous interface calling request to be processed, wherein the first preset time length is less than a second preset time length, the second preset time length is the time length from the time when the request is sent to the time when a status code corresponding to the request ID returned by the interface equipment is received, the status code corresponds to the request ID one by one, the first preset time length can be 2 seconds, 3 seconds, 5 seconds, 7 seconds and the like, the second preset time length can be 2 seconds, 3 seconds and the like, the time length of the second preset time length, the first preset time length and the processing capacity of the interface equipment are related, the faster the processing capacity of the interface equipment is, the shorter the second preset time length and the first preset time length are, in this embodiment, the second preset time is 2 seconds, and the first preset time is 3 seconds.
For example, when the first preset duration is 3 seconds, the a1 thread starts sending the a request to the interface device to be called at 8 o 'clock 10 min 20 s at 3/5/2019, releases the occupation of the a request on the a1 thread at 8 o' clock 10 min 23 s at 3/5/2019, and controls the a1 thread to send the next asynchronous interface call request to be processed to the interface device to be called.
In the implementation process, for each asynchronous interface call request, the server releases the occupation of the request on the thread within a first preset time period from the time when the request is sent to the interface device to be called, controls the thread to send a next asynchronous interface call request to the interface device, and does not need to release the thread after a status code returned by the interface device to be called is obtained, where the status code may be a character used for representing success or failure of the request, and only on the premise that the request is successful, the interface device returns a processing result to the server, for example, when the status code is 0, the request is failed, and when the status code is 1, the request is successful, the waiting time of the thread is shortened, the processing efficiency of the interface call request is improved, the waiting time of a user is shortened, and the user experience is improved.
As an embodiment, after S200, the method further includes:
a1: the server determines whether a processing result corresponding to the request ID returned by the interface equipment is received within a third preset time length from the sending of the request; and the third preset time length is greater than the second preset time length.
The third preset time is longer than the second preset time, and when the second preset time is 2 seconds, the third preset time can be 4 seconds, 6 seconds, 8 seconds and the like, and the third preset time is related to the processing capacity of the interface device, and the faster the processing capacity of the interface device is, the shorter the third preset time is.
As an implementation manner, within a third preset time period from the time when the thread sends the request to the interface device to be called, the server searches whether a processing result corresponding to the request ID exists from a first corresponding relationship between a pre-stored request ID and a processing result based on the request ID. The implementation of the embodiment is based on the premise that after the server obtains the processing result and the request ID returned by the interface device to be called, the server stores the processing result and the request ID in a one-to-one correspondence manner.
As another embodiment, in a second preset time period after the server control thread sends the request to the interface device to be called, the server determines, based on the request ID, whether the request ID exists in the request IDs stored in advance and used for representing the obtained processing result. The implementation of this embodiment is based on the premise that, after the server obtains the processing result and the request ID returned by the interface device to be called, the server stores the request ID in a file or a table used for representing the obtained processing result, and the storage location is not limited.
A2: and the server resends the request to the interface equipment when determining that the processing result corresponding to the request ID returned by the interface equipment is not received.
As an implementation manner, when the first corresponding relationship is stored in the server and the server does not find the processing result corresponding to the request ID in the first corresponding relationship, the request is obtained from the corresponding relationship between the request ID and the asynchronous interface call request stored in advance, and the thread is controlled to resend the request to the interface device to be called.
For example, when the second preset duration is 4 seconds, the a1 thread starts to send an a request to the interface device to be called at 8 o 'clock 10 min 20 seconds at 3/5/8 o' clock in 2019, where the request ID of the a request is 112, whether a processing result corresponding to the request ID exists is searched for in a first corresponding relationship between the pre-stored request ID and the processing result at 8 o 'clock 10 min 24 seconds at 3/5/8 o' clock in 2019, and when the processing result corresponding to the request ID does not exist in the first corresponding relationship, the a request is obtained from the corresponding relationship between the pre-stored request ID and the asynchronous interface call request, and an available and idle thread is controlled to resend the a request to the interface device to be called.
As another embodiment, when a request ID for representing an acquired processing result is stored in the server, and the server determines that the request ID does not exist in the request ID for representing the acquired processing result, the server acquires the request from the corresponding relationship between the request ID stored in advance and the asynchronous interface call request, and controls the thread to resend the request to the interface device to be called.
In the implementation process, the server determines whether a processing result and a request ID returned by the interface device are received within a third preset time period from the sending of the request, wherein the third preset time period is longer than the second preset time period, and retransmits the request to the interface device when it is determined that the processing result returned by the interface device is not received.
In another embodiment, when determining that the processing result corresponding to the request ID returned by the interface device is received, the server deletes the pre-stored correspondence between the request ID and the request to reduce the storage pressure of the server.
As an embodiment, after a1, the method further comprises:
the server searches a processing result corresponding to the request ID returned by the interface device from the pre-stored corresponding relationship between the processing result and the request ID, and then establishes a corresponding relationship between the processing result, the interface ID to be called, and the data to be processed.
When the server acquires the same interface ID to be called and the same data to be processed again, the server does not need to send the interface ID to be called and the data to be processed to interface equipment to be called, and acquires the processing result corresponding to the interface ID to be called and the data to be processed directly from the corresponding relation among the pre-stored processing result, the interface ID to be called and the data to be processed, so that the processing efficiency of an interface calling request is improved, the waiting time of a user is shortened, and the user experience is improved.
As an embodiment, before S100, the method further includes: b1, B2, B3 and B4.
Prior to B1, the method further comprises: the user terminal 11 sends the interface call request to the server.
B1: the method comprises the following steps that a server receives an interface calling requirement sent by a user terminal, wherein the interface calling requirement comprises the following steps: the interface ID to be called and the data to be processed.
The method comprises the following steps that a server receives an interface calling requirement sent by a user terminal, wherein the interface calling requirement comprises the following steps: the interface ID to be called and the data to be processed.
In this embodiment, the interface call requirement further includes an IP address of the user terminal.
As an implementation manner, after receiving an Internet Protocol (IP) address of a user terminal sent by the user terminal, a server receives an interface calling requirement sent by the user terminal, wherein the interface calling request does not include the IP address of the user terminal, and the server adds the IP address of the user terminal to data in the interface calling requirement to update the data in the interface calling requirement.
B2: and the server caches the interface calling requirement to a cache queue.
And when the cache queue can also cache data, the server caches the interface calling requirement to the cache queue.
When the buffer queue cannot buffer the storage space of the data at present, reestablishing a new waiting buffer queue of the uncached data, buffering the request to the waiting buffer queue, and when the available storage space exists in the buffer queue, buffering the data in the waiting buffer queue to the buffer queue according to a first-in first-out principle.
B3: and the server controls the thread to read the interface calling requirement from the cache queue.
When available and idle threads exist and the to-be-processed interface calling requirement exists in the cache queue, the server controls the available and idle threads to read the to-be-processed interface calling requirement from the cache queue according to a first-in first-out principle.
B4: and the server controls the thread to generate the calling request based on the interface ID to be called in the interface calling requirement, the data to be processed in the interface calling requirement and the pre-allocated request ID corresponding to the interface calling requirement.
The server controls the thread to extract an interface ID to be called in the interface calling requirement and data to be processed in the interface calling requirement, after the interface ID to be called and the data to be processed are obtained, the server controls the thread to perform data integration based on the interface ID to be called, the data to be processed and a pre-allocated request ID corresponding to the calling request to generate the calling request, wherein each calling request corresponds to a unique request ID, one request ID corresponds to only one calling request, and the calling request comprises: the data processing method comprises the steps of data to be processed, an interface ID to be called and a request ID.
In another embodiment, the server controls the thread to generate the call request based on the interface call requirement and a request ID corresponding to the interface call requirement and allocated in advance.
In the implementation process, the server caches the call requirement to the cache queue, and when the call requirement can be processed, the server controls the thread to read the interface call requirement from the cache queue and process the call requirement, so that the reading and processing of the requirement are adapted to the actual processing capacity.
As an embodiment, before S100, the method further includes:
and when the interface calling requirement to be processed is determined to exist, the server control thread processes the interface calling requirement to generate the calling request.
As an embodiment, the interface call requirement further includes: the account number of the user terminal, after B3, the method further comprising:
and the server controls the thread to extract the account number of the user terminal in the interface calling requirement, and determines that the account number of the user terminal is a legal account number.
As an implementation manner, the server controls the thread to analyze the interface calling requirement, obtains a user terminal account corresponding to the interface calling requirement, and searches whether the user terminal account exists in pre-stored user accounts.
As another embodiment, the server controls the thread to analyze the interface calling requirement, obtains a user terminal account corresponding to the interface calling requirement, determines whether the account and the interface ID to be called of the user terminal are matched with the pre-stored account and the interface ID based on the corresponding relationship between the pre-stored account and the interface ID, and determines whether the user terminal is a legal account according to the matching result.
For example, when the account number of the user terminal is ABC, the interface ID to be called is a1, and the correspondence between the pre-stored account number and the interface ID includes: the interface ID is a1 and corresponds to the account ABD; the interface ID is b1 and corresponds to the account ABC; the interface ID is a2 and the account ACD corresponds to each other, so that the user terminal account is ABC, and the matching of the interface ID to be called, a1, the pre-stored account and the interface ID fails.
When the account of the user terminal is ABC and the ID of the interface to be called is b1, matching the account of the user terminal with the ID of the interface to be called b1 with the pre-stored account and interface ID is successful.
As another embodiment, when the server is capable of performing data transmission with at least two interface devices to be called, and when the interface IDs of different interface devices to be called are the same, the calling requirement further includes: the ID of the interface device to be called.
The server controls the thread to analyze the interface calling requirement, obtains a user terminal account corresponding to the interface calling requirement and an ID of the interface equipment to be called, determines whether the account, the interface ID to be called and the ID of the interface equipment to be called of the user terminal are matched with the account, the ID of the interface equipment and the interface ID which are stored in advance or not based on the corresponding relation between the account, the ID of the interface equipment to be called and the interface ID, and determines whether the user terminal is a legal account or not according to a matching result.
As an implementation manner, when the account of the user terminal is a valid account, the server controls the thread to analyze the interface call requirement, obtain an interface ID to be called and data to be processed, and process the interface ID to be called, the data to be processed, and a request ID to obtain the call request, where each call request corresponds to a unique request ID, and one request ID corresponds to only one call request, where the call request includes: the data processing method comprises the steps of data to be processed, an interface ID to be called and a request ID.
As another implementation manner, when the account of the user terminal is an illegal account, the server sends a prompt message of account error to the user terminal.
As an embodiment, the method further comprises: after receiving the processing result corresponding to the request ID and the request ID returned by the interface device, acquiring the IP address of the user terminal corresponding to the request ID from the pre-stored corresponding relation between the request ID and the IP address of the user terminal based on the request ID, and then sending the processing result to the user terminal corresponding to the request ID based on the IP address of the user terminal.
In the implementation process, based on the request ID, the server can accurately send the processing result corresponding to the request ID to the user terminal corresponding to the request ID.
Referring to fig. 3, fig. 3 is a block diagram of an interface invoking device 400 according to an embodiment of the present application, and the block diagram shown in fig. 3 will be described below, where the interface invoking device includes:
a sending unit 410, configured to control a task execution thread to send an asynchronous interface call request to an interface device to be called, where the call request includes: the method comprises the steps that data to be processed, an interface ID to be called and a request ID are obtained, so that the interface equipment obtains a processing result based on the data to be processed and the interface ID to be called; a releasing unit 420, configured to release, within a first preset duration from sending the request, occupation of the thread by the request, and control the thread to send a next asynchronous interface call request to the interface device; the first preset time length is less than a second preset time length, and the second preset time length is the time length from the time when the request is sent to the time when a status code corresponding to the request ID returned by the interface equipment is received.
As an embodiment, the apparatus further comprises: the device further comprises: the judging unit is used for determining whether a processing result which is returned by the interface equipment and corresponds to the request ID is received or not within a third preset time length from the sending of the request; the third preset time length is longer than the second preset time length; and the first execution unit is used for retransmitting the request to the interface equipment when determining that the processing result corresponding to the request ID returned by the interface equipment is not received.
As an embodiment, the apparatus further comprises: a determining unit, configured to determine that a processing result corresponding to the request ID returned by the interface device is received; the storage unit is used for correspondingly storing the processing result, the interface ID to be called and the data to be processed; and the obtaining unit is used for obtaining a processing result corresponding to the interface ID to be called and the data to be processed from a pre-stored corresponding relation among the processing result, the interface ID to be called and the data to be processed when the interface ID to be called and the data to be processed are obtained again.
As an embodiment, the apparatus further comprises: the device comprises a receiving unit and a processing unit, wherein the receiving unit is used for receiving an interface calling requirement sent by a user terminal, and the interface calling requirement comprises: the interface ID to be called and the data to be processed; the cache unit is used for caching the interface calling requirement to a cache queue; the reading unit is used for controlling the thread to read the interface calling requirement from the cache queue; and the processing unit is used for controlling the thread to generate the calling request based on the interface ID to be called in the interface calling requirement, the data to be processed in the interface calling requirement and the pre-allocated request ID corresponding to the interface calling requirement.
As an embodiment, the interface call requirement further includes: the account of the user terminal, the apparatus further comprising: and the account determining unit is used for controlling the thread to extract the account of the user terminal in the interface calling requirement and determining the account of the user terminal as a legal account.
As an implementation manner, the account determining unit is further configured to determine, based on a correspondence between a pre-stored account and an interface ID, that the account of the user terminal is a valid account.
As an embodiment, the apparatus further comprises: and the result sending unit is used for sending the processing result to the user terminal corresponding to the request ID after receiving the processing result corresponding to the request ID returned by the interface equipment.
For the process of implementing each function by each functional unit in this embodiment, please refer to the content described in the embodiment shown in fig. 1 and fig. 2, which is not described herein again.
As shown in fig. 4, an embodiment of the present application provides an electronic device 100, where the electronic device 100 may be the server, and the electronic device 100 may include: memory 102, process 101, communication interface 103, and a communication bus for enabling the connection communications of these components.
The Memory 102 is used to store various data such as an asynchronous interface call request, a processing result returned by an interface device to be called, and a computer program instruction corresponding to the interface call method and apparatus provided in the embodiment of the present application, where the Memory 102 may be, but is not limited to, a Random Access Memory (RAM), a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Read-Only Memory (EPROM), an electrically Erasable Read-Only Memory (EEPROM), and the like.
The processor 101 is configured to, when reading and running a computer program instruction stored in the memory, execute the steps of the interface call method provided in the embodiment of the present application to control a task execution thread to send an asynchronous interface call request to an interface device to be called, release occupation of the thread by the request within a first preset time period after the request is sent, and control the thread to send a next asynchronous interface call request to the interface device, where the processor 102 is further configured to store a processing result returned by the interface device in the memory 102.
The processor 101 may be an integrated circuit chip having signal processing capability. The Processor 101 may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; but may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components. The various methods, steps, and logic blocks disclosed in the embodiments of the present application may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The communication interface 103 may use any transceiver or the like for communicating with other devices or communication networks, such as ethernet, Radio Access Network (RAN), Wireless Local Area Network (WLAN), etc.
In addition, an embodiment of the present application further provides a storage medium, in which a computer program is stored, and when the computer program runs on a computer, the computer is caused to execute the interface calling method provided in any embodiment of the present application.
To sum up, the interface calling method, the interface calling device, the electronic device and the storage medium provided by the embodiments of the present application, the method includes: controlling a task execution thread to send an asynchronous interface calling request to interface equipment to be called, wherein the calling request comprises: the method comprises the steps that data to be processed, an interface ID to be called and a request ID are obtained, so that the interface equipment obtains a processing result based on the data to be processed and the interface ID to be called; and releasing the occupation of the request on the thread within a first preset time length from the sending of the request, and controlling the thread to send a next asynchronous interface calling request to the interface equipment, wherein the first preset time length is less than a second preset time length, and the second preset time length is the time length from the sending of the request to the receiving of a state code corresponding to the request ID returned by the interface equipment, so that the thread is not required to be released after a state code corresponding to the request ID returned by the interface equipment to be called is obtained, the waiting time of the thread is shortened, the processing efficiency of the interface calling request is improved, the waiting time of a user is shortened, and the user experience is improved.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. The apparatus embodiments described above are merely illustrative, and for example, the flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based devices that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, functional modules in the embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.

Claims (8)

1. An interface calling method, comprising:
controlling a task execution thread to send an asynchronous interface calling request to interface equipment to be called, wherein the calling request comprises: the method comprises the steps that data to be processed, an interface ID to be called and a request ID are obtained, so that the interface equipment obtains a processing result based on the data to be processed and the interface ID to be called;
releasing the occupation of the request on the thread within a first preset time length from the sending of the request, and controlling the thread to send a next asynchronous interface calling request to the interface equipment; the first preset time length is less than a second preset time length, and the second preset time length is the time length from the time when the request is sent to the time when a status code corresponding to the request ID returned by the interface equipment is received;
after the task execution thread is controlled to send an asynchronous interface calling request to the interface device to be called, the method further comprises the following steps: determining whether a processing result corresponding to the request ID returned by the interface equipment is received within a third preset time length from the sending of the request, wherein the third preset time length is longer than the second preset time length; when determining that the processing result corresponding to the request ID returned by the interface equipment is not received, retransmitting the request to the interface equipment;
after determining whether a processing result corresponding to the request ID returned by the interface device is received, the method further includes: determining that a processing result corresponding to the request ID returned by the interface equipment is received; correspondingly storing the processing result, the interface ID to be called and the data to be processed; and when the interface ID to be called and the data to be processed are obtained again, obtaining a processing result corresponding to the interface ID to be called and the data to be processed from a pre-stored corresponding relation among the processing result, the interface ID to be called and the data to be processed.
2. The method of claim 1, wherein before controlling the task execution thread to send the asynchronous interface call request to the interface device to be called, the method further comprises:
receiving an interface calling requirement sent by a user terminal, wherein the interface calling requirement comprises: the interface ID to be called and the data to be processed;
caching the interface calling requirement to a cache queue;
controlling the thread to read the interface calling requirement from the cache queue;
and controlling the thread to generate the calling request based on the interface ID to be called in the interface calling requirement, the data to be processed in the interface calling requirement and the pre-allocated request ID corresponding to the interface calling requirement.
3. The method of claim 2, wherein the interface call requirement further comprises: after the account of the user terminal controls the thread to read the interface call requirement from the cache queue, the method further includes:
and controlling the thread to extract the account number of the user terminal in the interface calling requirement, and determining the account number of the user terminal as a legal account number.
4. The method of claim 3, wherein determining that the account of the user terminal is a valid account comprises:
and determining the account of the user terminal as a legal account based on the corresponding relation between the pre-stored account and the interface ID.
5. The method of claim 2, further comprising:
and after receiving a processing result corresponding to the request ID returned by the interface equipment, sending the processing result to the user terminal corresponding to the request ID.
6. An interface invocation apparatus, characterized in that said apparatus comprises:
a sending unit, configured to control a task execution thread to send an asynchronous interface call request to an interface device to be called, where the call request includes: the method comprises the steps that data to be processed, an interface ID to be called and a request ID are obtained, so that the interface equipment obtains a processing result based on the data to be processed and the interface ID to be called;
the release unit is used for releasing the occupation of the thread by the request within a first preset time length from the sending of the request and controlling the thread to send a next asynchronous interface calling request to the interface equipment; the first preset time length is less than a second preset time length, and the second preset time length is the time length from the time when the request is sent to the time when a status code returned by the interface equipment based on the request is received;
the release unit is further configured to determine whether a processing result corresponding to the request ID returned by the interface device is received within a third preset time period from the sending of the request, where the third preset time period is longer than the second preset time period; when determining that the processing result corresponding to the request ID returned by the interface equipment is not received, retransmitting the request to the interface equipment; determining that a processing result corresponding to the request ID returned by the interface equipment is received; correspondingly storing the processing result, the interface ID to be called and the data to be processed; and when the interface ID to be called and the data to be processed are obtained again, obtaining a processing result corresponding to the interface ID to be called and the data to be processed from a pre-stored corresponding relation among the processing result, the interface ID to be called and the data to be processed.
7. An electronic device comprising a memory and a processor, the memory having stored therein computer program instructions, wherein the computer program instructions, when read and executed by the processor, perform the steps of the method according to any one of claims 1-5.
8. A storage medium having stored thereon computer program instructions which, when read and executed by a computer, perform the steps of the method according to any one of claims 1-5.
CN201910386979.3A 2019-05-10 2019-05-10 Interface calling method and device, electronic equipment and storage medium Active CN110336856B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910386979.3A CN110336856B (en) 2019-05-10 2019-05-10 Interface calling method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910386979.3A CN110336856B (en) 2019-05-10 2019-05-10 Interface calling method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN110336856A CN110336856A (en) 2019-10-15
CN110336856B true CN110336856B (en) 2021-11-26

Family

ID=68139374

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910386979.3A Active CN110336856B (en) 2019-05-10 2019-05-10 Interface calling method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN110336856B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116828022B (en) * 2023-08-30 2023-11-24 北京白龙马云行科技有限公司 Method, device, equipment and medium for managing connection relation with server

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2007041390A2 (en) * 2005-09-29 2007-04-12 Honda Motor Co., Ltd. Extensible task engine framework for humanoid robots
CN1976349A (en) * 2001-10-05 2007-06-06 Bea系统公司 System and method for receiving and sending asynchronous message between java servlets and HTTP client computer
CN101621532A (en) * 2008-06-30 2010-01-06 中兴通讯股份有限公司 Method for realizing HTTP application by thread pool
CN103577469A (en) * 2012-08-03 2014-02-12 深圳市腾讯计算机系统有限公司 Database connection multiplexing method and device
CN105530220A (en) * 2014-09-29 2016-04-27 中科华核电技术研究院有限公司 OPC-based interface method for realizing system communication of two different types of protocols
CN106850740A (en) * 2016-12-19 2017-06-13 中国科学院信息工程研究所 A kind of throughput data method for stream processing high
CN107104999A (en) * 2016-02-23 2017-08-29 北京京东尚科信息技术有限公司 The treating method and apparatus of service interface call request
CN108234606A (en) * 2017-12-15 2018-06-29 浪潮软件股份有限公司 A kind of information management method and managing device
CN109040307A (en) * 2018-09-11 2018-12-18 中国银行股份有限公司 A kind of self-cleaning method and device of communication connection
CN109508256A (en) * 2018-08-27 2019-03-22 郑州云海信息技术有限公司 The metadata management method and device of a kind of meta data server during restarting

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10423446B2 (en) * 2016-11-28 2019-09-24 Arm Limited Data processing

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1976349A (en) * 2001-10-05 2007-06-06 Bea系统公司 System and method for receiving and sending asynchronous message between java servlets and HTTP client computer
WO2007041390A2 (en) * 2005-09-29 2007-04-12 Honda Motor Co., Ltd. Extensible task engine framework for humanoid robots
CN101621532A (en) * 2008-06-30 2010-01-06 中兴通讯股份有限公司 Method for realizing HTTP application by thread pool
CN103577469A (en) * 2012-08-03 2014-02-12 深圳市腾讯计算机系统有限公司 Database connection multiplexing method and device
CN105530220A (en) * 2014-09-29 2016-04-27 中科华核电技术研究院有限公司 OPC-based interface method for realizing system communication of two different types of protocols
CN107104999A (en) * 2016-02-23 2017-08-29 北京京东尚科信息技术有限公司 The treating method and apparatus of service interface call request
CN106850740A (en) * 2016-12-19 2017-06-13 中国科学院信息工程研究所 A kind of throughput data method for stream processing high
CN108234606A (en) * 2017-12-15 2018-06-29 浪潮软件股份有限公司 A kind of information management method and managing device
CN109508256A (en) * 2018-08-27 2019-03-22 郑州云海信息技术有限公司 The metadata management method and device of a kind of meta data server during restarting
CN109040307A (en) * 2018-09-11 2018-12-18 中国银行股份有限公司 A kind of self-cleaning method and device of communication connection

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
Web1Services异步调用模型的研究与实现;陈延彬;《中国优秀硕士学位论文全文数据库,信息科技辑》;20070430;全文 *
Web服务组合执行引擎中服务异步调用机制研究;李玲勇,高春鸣,文华南;《计算机应用研究》;20100227;文献第1-5页 *

Also Published As

Publication number Publication date
CN110336856A (en) 2019-10-15

Similar Documents

Publication Publication Date Title
CN110413424B (en) Configurable third-party message callback method, device, server and storage medium
CN110851290A (en) Data synchronization method and device, electronic equipment and storage medium
CN112422497B (en) Message transmission method and device and computer equipment
CN112600928A (en) File transmission method and device, electronic equipment and medium
CN111752582A (en) Software updating method and device in local area network and electronic equipment
US7707291B2 (en) Handling incoming data
CN110336856B (en) Interface calling method and device, electronic equipment and storage medium
CN110581976B (en) Teleconferencing method, apparatus, computer system and readable storage medium
CN107645476B (en) Request processing method and device
US20160100015A1 (en) Systems and methods for resolving service initialization links in virtual desktop infrastructure environments
CN108429703B (en) DHCP client-side online method and device
CN112653736B (en) Parallel source returning method and device and electronic equipment
CN112822300B (en) RDMA (remote direct memory Access) -based data transmission method and device and electronic equipment
CN111338758A (en) Resource management method and device and electronic equipment
CN111274047A (en) Information processing method, terminal, system, computer device and storage medium
CN111556112A (en) Data transmission method and device, electronic equipment and storage medium
CN112822299B (en) RDMA (remote direct memory Access) -based data transmission method and device and electronic equipment
CN114301920A (en) System log forwarding method and device, computing device and storage medium
CN110865845B (en) Method for improving interface access efficiency and storage medium
CN113765819A (en) Resource access method, device, electronic equipment and storage medium
CN110557428A (en) script interpretation type service agent method and system based on Kubernetes
CN115242858B (en) Message processing method, device, electronic equipment and computer readable storage medium
CN114553806B (en) Optimization method, device and equipment for instant messaging and storage medium
CN112532699B (en) Data port updating method and device, electronic equipment and readable storage medium
CN101945163A (en) Method, mobile terminal and system for content treatment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant