Bill generation method and device, electronic device, and program product

CN122820288APending Publication Date: 2026-09-25TRAVELSKY TECHNOLOGY LIMITED
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611046436.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-14
Publication Date
2026-09-25

AI Technical Summary

Technical Problem

[0004]本发明实施例提供了一种账单生成方法及其装置、电子设备、程序产品,以至少解决相关技术中无法实时计算接口调用费用,导致生成账单的时效性较差的技术问题

Benefits of technology

[0023]在本发明中,接收当前接口调用请求,并确定当前接口调用请求携带的调用信息指示的目标业务服务器;通过目标业务服务器对当前接口调用请求进行处理,生成多个接口调用日志,并将每个接口调用日志写入数据中心服务器的预设目录;获取预设目录中的每个接口调用日志,并写入目标目录,对目标目录下的接口调用日志进行处理,得到结构化数据,将所有结构化数据发送至缓存数据库集群;通过缓存数据库集群处理结构化数据,得到每日累计费用数据;基于每日累计费用数据,生成目标账单,解决了相关技术中无法实时计算接口调用费用,导致生成账单的时效性较差的技术问题。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122820288A_ABST
    Figure CN122820288A_ABST
Patent Text Reader

Abstract

The application discloses a bill generation method and device, electronic equipment and program product, and relates to the technical field of data processing, wherein the bill generation method comprises the following steps: receiving a current interface calling request, and determining a target business server indicated by calling information carried by the current interface calling request; processing the current interface calling request through the target business server, and writing each interface calling log generated into a preset directory of the target business server; acquiring each interface calling log through a data center server, writing into a target directory, processing the interface calling log under the target directory, obtaining structured data, and sending all the structured data to a cache database cluster; processing the structured data through the cache database cluster, obtaining daily cumulative cost data, and generating a target bill. The application solves the technical problem that the interface calling cost cannot be calculated in real time in the related art, and the timeliness of generating a bill is poor.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing technology, and more specifically, to a bill generation method and apparatus, electronic device, and program product. Background Technology

[0002] Application programming interfaces (APIs) serve as the carriers of service delivery and data exchange. Billing based on API call volume is a common charging method, where users pay according to the actual number of API calls. Currently, most billing schemes employ an offline batch processing model: large amounts of API call logs generated daily are initially stored in files or message queues, then aggregated and statistically analyzed by offline jobs the following morning. Bills are calculated based on tiered pricing, and finally, a bill is generated and pushed to the user. This T+1 model has significant drawbacks: users cannot monitor their spending in real time, and operators cannot promptly suspend service when a user's balance is insufficient, leading to the risk of bad debts.

[0003] There is currently no effective solution to the above problems. Summary of the Invention

[0004] This invention provides a bill generation method, apparatus, electronic device, and program product to at least solve the technical problem in related technologies where the inability to calculate interface call fees in real time leads to poor timeliness in bill generation.

[0005] According to one aspect of the embodiments of this application, a bill generation method is provided, applied to a bill generation system. The bill generation system includes at least: multiple business servers, a data center server, and a cache database cluster. The bill generation method includes: receiving a current interface call request and determining the target business server indicated by the call information carried in the current interface call request; processing the current interface call request through the target business server to generate multiple interface call logs and writing each interface call log to a preset directory on the data center server; obtaining each interface call log in the preset directory and writing it to a target directory; processing the interface call logs in the target directory to obtain structured data; sending all structured data to the cache database cluster; processing the structured data through the cache database cluster to obtain daily cumulative cost data; and generating a target bill based on the daily cumulative cost data.

[0006] Furthermore, before processing structured data through the cache database cluster to obtain daily cumulative cost data, the process includes: configuring multiple versions of tiered billing rules for each business server interface, configuring the effective time of each version of the tiered billing rules, and storing multiple versions of the tiered billing rules in the cache database cluster.

[0007] Furthermore, the cache database cluster stores preset scripts. The steps of processing structured data through the cache database cluster to obtain daily cumulative cost data include: calculating the current number of interface calls to the target business server based on the structured data; executing the billing operation for the current interface call using the preset script based on the current number of interface calls to obtain the current interface call cost; and summing up the current interface call costs obtained from all billing operations each day to obtain the daily cumulative cost data.

[0008] Furthermore, the steps for obtaining the current interface call fee by performing the billing operation of the current interface call using a preset script based on the current number of interface calls include: obtaining the call timestamp of the current interface call; matching from multiple versions of tiered billing rules based on the call timestamp and the rule effective time corresponding to each version of the tiered billing rule to obtain the target tiered billing rule; and calculating the current interface call fee based on the target tiered billing rule and the current number of interface calls.

[0009] Further, the steps for calculating the current interface call cost based on the target tiered billing rules and the current number of interface calls include: obtaining the cumulative number of interface calls made by the user account to the target business server, wherein the cumulative number of interface calls is obtained by summing multiple historical structured data, and the historical structured data is obtained by processing historical interface call logs obtained from historical calls to the target business server; calculating the sum of the cumulative number of interface calls and the current number of interface calls to obtain the target cumulative number of calls; comparing the cumulative number of interface calls with multiple billing tiers in the target tiered billing rules to obtain the billing tier to which the cumulative number of interface calls belongs; comparing the target cumulative number of calls with multiple billing tiers in the target tiered billing rules to obtain the billing tier to which the target cumulative number of calls belongs; if the billing tier to which the cumulative number of interface calls belongs is different from the billing tier to which the target cumulative number of calls belongs, calculating the current interface call cost based on the first billing price in the billing tier to which the cumulative number of interface calls belongs and the second billing price in the billing tier to which the target cumulative number of calls belongs.

[0010] Furthermore, after calculating the current API call cost, the process includes: adjusting the user account based on the current API call cost; or, adjusting the user account based on the daily cumulative cost data.

[0011] Furthermore, the steps of obtaining each interface call log in the preset directory and writing it to the target directory, and processing the interface call logs in the target directory to obtain structured data include: using a buffer reader to read each interface call log in the target directory; determining multiple target fields and constructing regular expressions based on the target fields and the corresponding parsing rules; and using regular expressions to extract fields from each interface call log to obtain structured data.

[0012] Furthermore, the step of sending all structured data to the cache database cluster includes: calculating the number of interface call logs in the target directory; and sending all structured data to the cache database cluster if the number equals a preset threshold.

[0013] According to another aspect of the embodiments of this application, a bill generation apparatus is also provided, applied to a bill generation system. The bill generation system includes at least: multiple business servers, a data center server, and a cache database cluster. The bill generation apparatus includes: a first determining unit, configured to receive a current interface call request and determine the target business server indicated by the call information carried in the current interface call request; a first generating unit, configured to process the current interface call request through the target business server, generate multiple interface call logs, and write each interface call log to a preset directory of the data center server; a first processing unit, configured to obtain each interface call log in the preset directory, write it to the target directory, process the interface call logs in the target directory to obtain structured data, and send all structured data to the cache database cluster; a second processing unit, configured to process the structured data through the cache database cluster to obtain daily cumulative cost data; and a second generating unit, configured to generate a target bill based on the daily cumulative cost data.

[0014] Furthermore, the billing generation device includes: a first configuration module, used to configure multiple versions of tiered billing rules for each business server interface and configure the effective time of each version of the tiered billing rules before processing structured data through the cache database cluster to obtain daily cumulative cost data; and a first storage module, used to store the multiple versions of the tiered billing rules to the cache database cluster.

[0015] Furthermore, the cache database cluster stores preset scripts, and the second processing unit includes: a first calculation module, used to calculate the current number of interface calls of the target business server based on structured data; a first execution module, used to execute the billing operation of the current interface call according to the current number of interface calls using the preset script to obtain the current interface call cost; and a second calculation module, used to accumulate the current interface call costs obtained from all billing operations each day to obtain the daily cumulative cost data.

[0016] Furthermore, the first execution module includes: a first acquisition submodule, used to acquire the call timestamp of the current interface call; a first matching submodule, used to match from multiple versions of tiered billing rules based on the call timestamp and the rule effective time corresponding to each version of the tiered billing rule to obtain the target tiered billing rule; and a first calculation submodule, used to calculate the current interface call cost based on the target tiered billing rule and the current number of interface calls.

[0017] Further, the first calculation submodule includes: a first acquisition subunit, used to acquire the cumulative number of times the user account calls the target business server's interface, wherein the cumulative number of interface calls is obtained by accumulating multiple historical structured data, and the historical structured data is obtained by processing historical interface call logs obtained from historical calls to the target business server; a first calculation subunit, used to calculate the sum of the cumulative number of interface calls and the current number of interface calls to obtain the target cumulative number of calls; a first comparison subunit, used to compare the cumulative number of interface calls with multiple billing tiers in the target tiered billing rules to obtain the billing tier to which the cumulative number of interface calls belongs; a second comparison subunit, used to compare the target cumulative number of calls with multiple billing tiers in the target tiered billing rules to obtain the billing tier to which the target cumulative number of calls belongs; and a second calculation subunit, used to calculate the current interface call fee based on the first billing price in the billing tier to which the cumulative number of interface calls belongs and the second billing price in the billing tier to which the target cumulative number of calls belongs, when the billing tier to which the cumulative number of interface calls belongs is different from the billing tier to which the target cumulative number of calls belongs.

[0018] Furthermore, the bill generation device also includes: a first adjustment module, used to adjust the user account based on the current interface call cost after calculating the current interface call cost; and a second adjustment module, used to adjust the user account based on the daily cumulative cost data.

[0019] Furthermore, the first processing unit includes: a first reading module, used to read each interface call log in the target directory using a buffered reader; a first construction module, used to determine multiple target fields and construct regular expressions based on the target fields and the parsing rules corresponding to the target fields; and a first extraction module, used to extract fields from each interface call log using regular expressions to obtain structured data.

[0020] Furthermore, the first processing unit also includes: a third calculation module for calculating the number of interface call logs in the target directory; and a first sending module for sending all structured data to the cache database cluster when the number equals a preset threshold.

[0021] According to another aspect of the embodiments of this application, a computer program product is also provided, including a non-volatile computer-readable storage medium storing a computer program, which, when executed by a processor, implements any of the above-described bill generation methods.

[0022] According to another aspect of the embodiments of this application, an electronic device is also provided, including one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement any of the above-described bill generation methods.

[0023] In this invention, a current interface call request is received, and the target business server indicated by the call information carried in the current interface call request is determined. The current interface call request is processed by the target business server to generate multiple interface call logs, and each interface call log is written to a preset directory of a data center server. Each interface call log in the preset directory is obtained and written to the target directory. The interface call logs in the target directory are processed to obtain structured data, and all structured data is sent to a cache database cluster. The structured data is processed by the cache database cluster to obtain daily cumulative cost data. Based on the daily cumulative cost data, a target bill is generated, which solves the technical problem in related technologies that the interface call cost cannot be calculated in real time, resulting in poor timeliness of bill generation.

[0024] In this invention, a current interface call request is received, and the target business server indicated by the call information carried in the current interface call request is determined. The current interface call request is processed by the target business server to generate multiple interface call logs. Each interface call log is written to a preset directory of the data center server. Each interface call log in the preset directory is retrieved and written to the target directory. Unstructured log data is processed into structured data using parsing rules such as regular expressions. Then, a batch sending mechanism is triggered based on a preset threshold to send the structured data in batches to the cache database cluster. This achieves efficient data writing and high-speed aggregation calculation within the cluster. Subsequently, bills are generated based on the daily fee data accumulated in real time in the Redis cache (Remote Dictionary Server, i.e., the cache database cluster). This achieves real-time processing of the entire chain from traffic collection to bill output, reducing the latency of bill generation and improving processing performance in high-concurrency scenarios. Attached Figure Description

[0025] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this invention, illustrate exemplary embodiments of the invention and are used to explain the invention, but do not constitute an undue limitation of the invention. In the drawings:

[0026] Figure 1 A hardware structure block diagram of a computer terminal (or mobile device) for implementing a bill generation method is shown;

[0027] Figure 2 This is a flowchart of the bill generation method according to Embodiment 1 of this application;

[0028] Figure 3 This is a flowchart of a real-time billing and billing method based on Redis high-concurrency interface calls according to an embodiment of this application;

[0029] Figure 4 This is a structural diagram of a real-time billing and invoicing system based on Redis high-concurrency interface calls according to an embodiment of this application;

[0030] Figure 5 This is a schematic diagram of a bill generation device according to an embodiment of this application;

[0031] Figure 6 This is a structural block diagram of an electronic device according to an embodiment of this application. Detailed Implementation

[0032] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0033] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0034] It should be noted that all relevant information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, and displayed data) collected and involved in this invention are information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, storage, use, processing, transmission, provision, disclosure, and application of this data comply with the relevant laws, regulations, and standards of the relevant regions, do not violate public order and good morals, and provide corresponding operation entry points for users to choose to authorize or refuse. For example, this system has an interface with relevant users or organizations. Before obtaining relevant information, a request to obtain the information needs to be sent to the aforementioned user or organization through the interface. After receiving consent from the aforementioned user or organization, the relevant information is obtained. If the user chooses to refuse, the process enters the expert decision-making process.

[0035] Because the billing generation system involves fund processing, it has high requirements for data accuracy, atomicity, and auditability. Call volume statistics must not be lost or duplicated, fee calculations must be precise, and balance deductions must be executed atomically with call volume accumulation. Furthermore, all operations should be traceable and reconcilable. While the distributed cache Redis offers high performance, it does not natively support complex transactions and rollbacks, posing a risk of data loss if used directly for billing. In this invention, by simultaneously uploading the file and hash digest file to the data center server, the server can recalculate the file's hash digest and compare it with the uploaded hash digest file, thus ensuring data consistency. Simultaneously, a preset script is stored in the Redis cache to execute billing operations. Billing, deductions, and balance updates can be completed in real time after each interface call, generating bills in real time.

[0036] The present invention will now be described in detail with reference to various embodiments.

[0037] Example 1

[0038] According to an embodiment of this application, an embodiment of a bill generation method is also provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0039] The method embodiment provided in Embodiment 1 of this application can be executed on a mobile terminal, computer terminal, or similar computing device. Figure 1 A hardware block diagram of a computer terminal (or mobile device) for implementing a bill generation method is shown. Figure 1 As shown, computer terminal 10 (or mobile device) may include one or more ( Figure 1The processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.), a memory 104 for storing data, and a transmission device 106 for communication functions may also be included. In addition, it may include: a display, a keyboard, a cursor control device, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of a BUS bus), a network interface, a power supply, and / or a camera, wherein the network interface can be connected to wired and / or wireless networks. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, computer terminal 10 may also include... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.

[0040] It should be noted that the aforementioned one or more processors 102 and / or other data processing circuits are generally referred to herein as "data processing circuits". These data processing circuits may be embodied, in whole or in part, in software, hardware, firmware, or any other combination thereof. Furthermore, the data processing circuits may be a single, independent processing module, or may be integrated, in whole or in part, into any other element within the computer terminal 10 (or mobile device). As involved in the embodiments of this application, the data processing circuits serve as a processor control mechanism (e.g., selection of a variable resistor termination path connected to an interface).

[0041] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the bill generation method in this embodiment. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, thereby realizing the aforementioned bill generation method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the computer terminal 10 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0042] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of the computer terminal 10. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module, used for wireless communication with the Internet.

[0043] The display may be, for example, a touchscreen liquid crystal display (LCD) that allows the user to interact with the user interface of the computer terminal 10 (or mobile device).

[0044] Under the aforementioned operating environment, this application provides the following: Figure 2 The bill generation method shown. Figure 2 This is a flowchart of the bill generation method according to Embodiment 1 of this application, as follows: Figure 2 As shown, the method includes the following steps:

[0045] Step S201: Receive the current interface call request and determine the target business server indicated by the call information carried in the current interface call request.

[0046] In this embodiment of the invention, the bill generation system includes at least: multiple business servers, a data center server, and a cache database cluster. The current interface call request is an API (Application Programming Interface) request initiated by a user through a client account to a business server, such as an order query or payment transfer. The call information is metadata or routing information carried in the request, used to identify which server should handle the request; it typically includes a server identifier, interface domain name, or a load-balanced routing label. The target business server is the specific physical server or virtual machine node that actually receives and executes the request.

[0047] Optionally, the billing system also includes an API gateway layer. Account information checks can be performed at the API gateway layer. Before processing the current API call request through the target business server, user account information is read using Redis (i.e., a cache database cluster) for subsequent processing. For example, if the balance is insufficient, a 402 status code is immediately returned without consuming business resources; if the balance is greater than the maximum single charge or the first tier price configured in the tiered billing rules (e.g., 0.01), the request is allowed. The maximum single charge of the API can be obtained from the local Caffeine cache (a local caching library). If the requested data does not exist in the local cache, the configured first tier price is queried.

[0048] User account information (such as balance) is not cached at the gateway layer. It is read directly from the Redis master node each time. When the balance is insufficient, a low balance event is asynchronously sent to the message queue to notify the user to recharge.

[0049] Step S202: The target business server processes the current interface call request, generates multiple interface call logs, and writes each interface call log to a preset directory on the data center server.

[0050] In this embodiment of the invention, the target business server processes the current interface call request and generates multiple interface call logs. These logs are text records of detailed information about each interface call, including key fields such as timestamp, user ID, interface name, execution time, status code, and traffic volume. Instead of directly writing the logs to Redis, the target business server first writes the API call logs to a local file. This local file acts as a buffer, decoupling business processing from data collection asynchronously. Even if Redis is temporarily unavailable, the data will not be lost and will be retransmitted after recovery.

[0051] Optionally, the daemon process of the target business server can also monitor a local file (such as / var / log / api / access.log) and perform a rollover every 5 minutes or when the file size reaches a preset threshold (such as 100MB). This involves copying the current log file (i.e., access.log) to a log file with a timestamp and server identifier (such as engineApi.log.{yyyyMMddHHmm}.{serverId}), and clearing the original access.log file. Logs can then be written to this file to generate multiple API call logs.

[0052] When copying log files, a corresponding MD5 (Message-Digest Algorithm 5) checksum file can be generated simultaneously. The MD5 value of the file is stored, and both the log file and the MD5 file are uploaded to a pre-defined directory on the data center server (e.g., / sftp_incoming / {serverId} / ) via SFTP (Secure File Transfer Protocol). Using SFTP to transfer log files supports resuming interrupted downloads, and the MD5 checksum ensures file integrity.

[0053] Step S203: Obtain each interface call log in the preset directory and write it to the target directory. Process the interface call logs in the target directory to obtain structured data, and send all the structured data to the cache database cluster.

[0054] In this embodiment of the invention, the log file name may include a server identifier and a timestamp. The data center server can record processed file names and automatically ignore them during repeated transmissions, achieving idempotency at the transport layer. The data center server scans files in a preset directory every 10 seconds. Upon discovering a new file, it calculates its MD5 hash and compares it with the MD5 hash of the transmitted file. If they match, the file is moved to / processing / (i.e., the target directory); otherwise, a retransmission is requested.

[0055] Before the data center server sends structured data to the cache database cluster, it can retrieve the call logs for each interface in the target directory, apply pre-compiled regular expressions to extract key fields (i.e., obtain structured data such as userId, apiId, successFlag, etc.), and discard failed call records. By filtering out invalid data, the storage pressure on Redis and subsequent billing load are reduced.

[0056] Step S204: Process structured data through a cache database cluster to obtain daily cumulative cost data.

[0057] In this embodiment of the invention, the cache database cluster stores preset scripts. Redis executes Lua scripts in a single thread, encapsulating calculation rules such as billing, deduction, and accumulation within the preset scripts. During script execution, no other commands are inserted, ensuring atomicity and isolation, and avoiding concurrency contention. The number of calls to the structured data calculation interface is used to calculate the call cost based on the preset scripts, thus obtaining the daily cumulative cost data.

[0058] Step S205: Generate the target bill based on the daily cumulative expense data.

[0059] In this embodiment of the invention, when the system reaches its billing cycle (e.g., daily at midnight or a specific time), the cache database cluster can be traversed using the Jedis SCAN command, using the pattern daily_cost: The `{yesterday}` function matches all user expense records from the previous day. During the iteration, it retrieves the userId and the corresponding expense value. It then uses a HashMap data structure for aggregation calculation, using the userId as the key and the cumulative expense amount as the value. It sums up multiple expenses under the same userId to obtain the daily cumulative expense data for each user within the specified date. For each bill record to be generated, the Snowflake algorithm can be used to generate a globally unique `bill_id` (i.e., the identifier of each bill).

[0060] In summary, by receiving API call requests and identifying the target business server, the server generates API call logs and writes them to a preset directory. The data center server then retrieves the logs from the preset directory, processes them into structured data, and sends them to a cache database cluster. The cache database cluster processes the structured data to obtain daily cumulative cost data. Finally, the target bill is generated based on the daily cumulative cost data. This achieves real-time aggregation calculation and automated output of standardized bills in high-concurrency scenarios, thereby solving the technical problem in related technologies where API call costs cannot be calculated in real time, resulting in poor timeliness of bill generation.

[0061] In order to accurately match the tiered billing rules, it is necessary to first configure the rule effective time for each version of the tiered billing rules. In the bill generation method provided in Embodiment 1 of this application, multiple versions of tiered billing rules are configured for each business server interface, and the rule effective time is configured for each version of the tiered billing rules; the multiple versions of tiered billing rules are stored in the cache database cluster.

[0062] In this embodiment of the invention, multiple versions of tiered configurations can be stored for each API (i.e., the interface of the business server), and the effective time of the tiered billing rules can be configured for each version. Thus, the billing Lua script (i.e., the preset script) can find the version number in effect at that time based on the call date. The tiered billing rules can be: a unit price of 0.01 yuan for the first 10,000 calls, 0.008 yuan for calls from the 10,000th to the 50,000th, and 0.005 yuan for calls exceeding 50,000; no further restrictions are imposed.

[0063] When calculating costs, the system needs to query the currently valid billing rules in real time. Storing the rules in a memory-level Redis cluster can reduce the rule reading latency to the millisecond level, avoiding querying the slow relational database for each calculation, thereby improving the overall computing performance.

[0064] The cache database cluster stores preset scripts. In order to accurately obtain the daily cumulative cost data, in the bill generation method provided in Embodiment 1 of this application, the current interface call count of the target business server is calculated based on structured data; according to the current interface call count, the billing operation of the current interface call is executed using the preset script to obtain the current interface call cost; the current interface call cost obtained from all billing operations each day is accumulated to obtain the daily cumulative cost data.

[0065] In this embodiment of the invention, the cache database cluster stores a preset script. This script encapsulates specific business logic (such as counting call counts and executing billing logic), which can be executed atomically on the server side, reducing the number of network interactions between the client and the server. When the data center server sends cleaned structured data to the cache database cluster, the preset script is triggered to execute. The script first extracts the interface identifier and user identifier from the structured data and increments a counter to calculate in real time the current call count of the target business server's interface (e.g., 100 requests per second). While calculating the call count, the preset script reads the corresponding tiered billing rules, calculates the corresponding cost based on the current interface call count, obtains the current interface call cost, and accumulates the current interface call costs obtained from all daily billing operations to obtain the daily cumulative cost data.

[0066] In order to accurately calculate the current interface call cost, the bill generation method provided in Embodiment 1 of this application obtains the call timestamp of the current interface call; based on the call timestamp and the effective time of the rule corresponding to each version of the tiered billing rule, it matches from multiple versions of the tiered billing rule to obtain the target tiered billing rule; and based on the target tiered billing rule and the current number of interface calls, it calculates the current interface call cost.

[0067] In this embodiment of the invention, to accurately implement differentiated billing under different periods and strategies, the system uses a time-dimensional rule matching mechanism to ensure the accuracy and flexibility of the billing logic. The timestamp of the current interface call can be obtained from the log file name. Based on the call timestamp and the effective time of the rule corresponding to each version of the tiered billing rule, matching is performed from multiple versions of the tiered billing rule (i.e., matching the call timestamp with the effective time) to obtain the target tiered billing rule. Based on the billing range, unit price logic, and the number of current interface calls in the target tiered billing rule, the cost of the current interface call is calculated.

[0068] To improve the accuracy of calculating the current interface call cost, the billing generation method provided in Embodiment 1 of this application obtains the cumulative number of interface calls made by the user account to the target business server. The cumulative number of interface calls is obtained by summing multiple historical structured data sets, which are obtained by processing historical interface call logs obtained from historical calls to the target business server. The cumulative number of interface calls is then calculated by adding the cumulative number of calls to the current number of calls to obtain the target cumulative number of calls. The cumulative number of calls is then compared with multiple billing tiers in the target tiered billing rules to obtain the billing tier to which the cumulative number of calls belongs. The target cumulative number of calls is then compared with multiple billing tiers in the target tiered billing rules to obtain the billing tier to which the target cumulative number of calls belongs. If the billing tier to which the cumulative number of calls belongs is different from the billing tier to which the target cumulative number of calls belongs, the current interface call cost is calculated based on the first billing price in the billing tier to which the cumulative number of calls belongs and the second billing price in the billing tier to which the target cumulative number of calls belongs.

[0069] In this embodiment of the invention, the cumulative number of times a user account calls the target business server's interface is obtained. The cumulative number of times the interface is called is calculated by summing multiple historical structured data. The cumulative number of times the interface is called is the total number of times the user account calls the target business server's interface before the current call. The historical structured data is also obtained by processing the historical interface call logs obtained from the historical calls to the target business server.

[0070] By calculating the sum of the cumulative number of API calls and the current number of API calls, the current cumulative number of calls (i.e., the target cumulative number of calls) can be obtained. The cumulative number of API calls is compared with multiple billing tiers in the target tiered billing rules to obtain the billing tier to which the cumulative number of API calls belongs. The target cumulative number of calls is also compared with multiple billing tiers in the target tiered billing rules to obtain the billing tier to which the target cumulative number of calls belongs. If the billing tier to which the cumulative number of API calls belongs is different from the billing tier to which the target cumulative number of calls belongs, the current API call cost is calculated based on the first billing price in the billing tier to which the cumulative number of API calls belongs and the second billing price in the billing tier to which the target cumulative number of calls belongs.

[0071] For example, if the target tiered billing rules are: Tier A: 0-1000 times, 0.01 yuan / time; Tier B: 1001-10000 times, 0.008 yuan / time; Tier C: 10001 times and above, 0.005 yuan / time; the cumulative number of API calls is 9800, falling into Tier B (1001-10000 times); and the target cumulative number of calls is 10100, falling into Tier C (10001 times and above). Then, 10000-9800=200 times will be calculated at the Tier B price (first billing price 0.008 yuan), and 10100-10000=100 times will be calculated at the Tier C price (second billing price 0.005 yuan). Current API call cost = (200...) 0.08)+(100 0.05) = 21 yuan.

[0072] Optionally, the script does not perform rounding, retains the original double-precision floating-point value, and postpones rounding to the billing generation stage to avoid amplifying accumulated errors. By comparing billing tiers and calculating differentiated unit prices in segments, high-precision tiered billing is achieved. Combined with time-triggered rule matching, the system can flexibly respond to differentiated tiered strategies for different periods and different users, enhancing the business's adaptability to complex billing needs.

[0073] In order to accurately adjust user accounts, the bill generation method provided in Embodiment 1 of this application adjusts user accounts based on the current interface call cost; or, adjusts user accounts based on daily cumulative cost data.

[0074] In this embodiment of the invention, after the cost calculation is completed, the calculation result needs to be converted into actual accounting changes. The system can adjust the account in two dimensions, corresponding to real-time settlement scenarios and periodic settlement scenarios respectively. In the real-time settlement scenario, the user account is adjusted based on the current interface call cost. In the periodic settlement scenario, the user account is adjusted based on the daily cumulative cost data. The user account can also be adjusted based on the monthly cumulative cost data. The adjustment period can be set according to actual needs.

[0075] To accurately obtain structured data, the bill generation method provided in Embodiment 1 of this application uses a buffer reader to read each interface call log in the target directory; determines multiple target fields, and constructs regular expressions based on the target fields and the corresponding parsing rules; and uses regular expressions to extract fields from each interface call log to obtain structured data.

[0076] In this embodiment of the invention, the target field may include: userId, apiId, successFlag. Based on the target field and the parsing rules corresponding to the target field, a regular expression is constructed, such as \\[userId\\]:([^\\[]+). \\[apiId\\]:([^\\[]+). \\[successFlag\\]:([^\\[]+) The data center server can use BufferedReader (i.e., buffered reader) to read the files under / processing / (i.e., API call logs) line by line, apply regular expressions to each file to extract fields, and obtain the data corresponding to userId, apiId, and successFlag (i.e., structured data).

[0077] To improve throughput, in the bill generation method provided in Embodiment 1 of this application, the number of interface call logs in the target directory is calculated; if the number is equal to a preset threshold, all structured data is sent to the cache database cluster.

[0078] In this embodiment of the invention, the number of interface call logs in the target directory can be calculated. If the number is equal to a preset threshold (e.g., 1000), or if all the logs in the directory have been read, the logs can be sent to the cache database cluster in one go via Redis Pipeline (i.e., pipeline technology). By merging N network round trips into one network round trip, network latency accumulation can be reduced and throughput can be improved.

[0079] Figure 3 This is a flowchart illustrating a real-time billing and billing method based on high-concurrency Redis interface calls according to an embodiment of this application, such as... Figure 3 As shown, the system obtains the cumulative call count (i.e., the sum of the cumulative number of API calls and the current number of API calls), and determines whether it crosses the tier boundary. If it crosses the tier boundary, it calculates the cross-tier segment fee (i.e., the current API call fee is calculated based on the first billing price in the billing tier to which the cumulative number of API calls belongs and the second billing price in the billing tier to which the target cumulative number of calls belongs). If it does not cross the tier boundary, it directly calculates the current tier fee. At the same time, it also needs to determine whether the user's account balance is sufficient. If the balance is sufficient, it deducts the fee, records the transaction, and returns the result. If the balance is insufficient, it returns the result of insufficient balance.

[0080] Figure 4 This is a structural diagram of a real-time billing and billing system based on Redis high-concurrency interface calls, according to an embodiment of this application. Figure 4As shown, the system includes: a data acquisition module, a Redis cluster, a balance check and call blocking module, a billing engine (Lua script), and a bill generation module. The data acquisition module collects API call logs from the business server in real time, performs preliminary filtering and formatting, and efficiently transmits them to the Redis cluster via SFTP+Pipeline. The Redis cluster, as the core storage and computing component of the system, stores all the status data required for real-time billing (call counters, user balances, tier configurations, accumulated fees, etc.) and has built-in Lua scripts to execute atomic billing logic. The balance check and call blocking module is deployed at the API gateway layer. It queries the user's balance in real time before the API request reaches the business logic; if the balance is insufficient, the call is directly rejected to prevent arrears. The billing engine (Lua script), encapsulated in Redis, is responsible for the entire process of atomic billing, deduction, and accumulation for a single API call, supporting cross-tier segmented billing. The bill generation module can periodically (daily / monthly) read accumulated fee data from Redis, generate structured bills, and persist them to a relational database.

[0081] The billing generation method provided in this application can obtain the maximum cost per API call and tiered configuration through a two-level caching strategy that combines local Caffeine caching with remote Redis queries, significantly reducing database query pressure. Then, based on the dynamic comparison of cumulative call counts and tiered billing rules, segmented billing logic is implemented, and account adjustments can be made based on single call costs or daily cumulative costs. At the same time, key fields can be quickly extracted from massive unstructured logs and transformed into structured data through regular expression parsing rules. By setting a preset threshold trigger mechanism and using RedisPipeline technology, data is batch packaged and sent to the cache database cluster, merging multiple network requests into a single send, reducing network round-trip latency, achieving dynamic matching of read and write rates, ensuring data consistency and system stability under high concurrency, and improving the real-time performance of billing generation.

[0082] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.

[0083] Example 2

[0084] This application also provides a bill generation apparatus. It should be noted that the bill generation apparatus of this application can be used to execute the bill generation method provided in this application. The bill generation apparatus provided in this application is described below.

[0085] According to an embodiment of this application, an apparatus for implementing the above-described bill generation method is also provided. Figure 5 This is a schematic diagram of a bill generation device according to an embodiment of this application, such as... Figure 5 As shown, the bill generation device may include: a first determining unit 50, a first generating unit 51, a first processing unit 52, a second processing unit 53, and a second generating unit 54.

[0086] The first determining unit 50 is used to receive the current interface call request and determine the target business server indicated by the call information carried in the current interface call request.

[0087] The first generation unit 51 is used to process the current interface call request through the target business server, generate multiple interface call logs, and write each interface call log to a preset directory of the data center server.

[0088] The first processing unit 52 is used to obtain each interface call log in the preset directory and write it to the target directory, process the interface call logs in the target directory to obtain structured data, and send all the structured data to the cache database cluster.

[0089] The second processing unit 53 is used to process structured data through a cache database cluster to obtain daily cumulative cost data;

[0090] The second generation unit 54 is used to generate a target bill based on daily cumulative cost data.

[0091] The bill generation device provided in this application embodiment can receive a current interface call request through a first determining unit 50 and determine the target business server indicated by the call information carried in the current interface call request. It can process the current interface call request through the target business server through a first generating unit 51, generate multiple interface call logs, and write each interface call log to a preset directory of a data center server. It can obtain each interface call log in the preset directory through a first processing unit 52 and write it to the target directory. It can process the interface call logs in the target directory to obtain structured data and send all structured data to a cache database cluster. It can process the structured data through the cache database cluster through a second processing unit 53 to obtain daily cumulative cost data. It can generate a target bill based on the daily cumulative cost data through a second generating unit 54.

[0092] Optionally, the bill generation device includes: a first configuration module, configured to configure multiple versions of tiered billing rules for each business server interface and configure the effective time of each version of the tiered billing rules before processing structured data through the cache database cluster to obtain daily cumulative cost data; and a first storage module, configured to store the multiple versions of the tiered billing rules to the cache database cluster.

[0093] Optionally, the cache database cluster stores a preset script, and the second processing unit 53 includes: a first calculation module, used to calculate the current number of interface calls of the target business server based on structured data; a first execution module, used to execute the billing operation of the current interface call according to the current number of interface calls using the preset script to obtain the current interface call cost; and a second calculation module, used to accumulate the current interface call costs obtained from all billing operations each day to obtain the daily cumulative cost data.

[0094] Optionally, the first execution module includes: a first acquisition submodule, used to acquire the call timestamp of the current interface call; a first matching submodule, used to match from multiple versions of tiered billing rules based on the call timestamp and the rule effective time corresponding to each version of the tiered billing rule to obtain the target tiered billing rule; and a first calculation submodule, used to calculate the current interface call cost based on the target tiered billing rule and the current number of interface calls.

[0095] Optionally, the first calculation submodule includes: a first acquisition subunit, used to acquire the cumulative number of times the user account calls the target business server's interface, wherein the cumulative number of interface calls is obtained by summing multiple historical structured data, and the historical structured data is obtained by processing historical interface call logs obtained from historical calls to the target business server; a first calculation subunit, used to calculate the sum of the cumulative number of interface calls and the current number of interface calls to obtain the target cumulative number of calls; a first comparison subunit, used to compare the cumulative number of interface calls with multiple billing tiers in the target tiered billing rules to obtain the billing tier to which the cumulative number of interface calls belongs; a second comparison subunit, used to compare the target cumulative number of calls with multiple billing tiers in the target tiered billing rules to obtain the billing tier to which the target cumulative number of calls belongs; and a second calculation subunit, used to calculate the current interface call fee based on the first billing price in the billing tier to which the cumulative number of interface calls belongs and the second billing price in the billing tier to which the target cumulative number of calls belongs, when the billing tier to which the cumulative number of interface calls belongs is different from the billing tier to which the target cumulative number of calls belongs.

[0096] Optionally, the bill generation device further includes: a first adjustment module, used to adjust the user account based on the current interface call cost after calculating the current interface call cost; and a second adjustment module, used to adjust the user account based on daily cumulative cost data.

[0097] Optionally, the first processing unit 52 includes: a first reading module, used to read each interface call log in the target directory using a buffer reader; a first construction module, used to determine multiple target fields and construct regular expressions based on the target fields and the parsing rules corresponding to the target fields; and a first extraction module, used to extract fields from each interface call log using regular expressions to obtain structured data.

[0098] Optionally, the first processing unit 52 further includes: a third calculation module for calculating the number of interface call logs in the target directory; and a first sending module for sending all structured data to the cache database cluster when the number equals a preset threshold.

[0099] The aforementioned bill generation device may further include a processor and a memory. The first determining unit 50, the first generating unit 51, the first processing unit 52, the second processing unit 53, the second generating unit 54, etc., are all stored in the memory as program units, and the processor executes the aforementioned program units stored in the memory to realize the corresponding functions.

[0100] The processor mentioned above contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and by adjusting kernel parameters, a target bill can be generated based on daily accumulated expense data.

[0101] The aforementioned memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0102] It should be noted that the first determining unit 50, the first generating unit 51, the first processing unit 52, the second processing unit 53, and the second generating unit 54 mentioned above correspond to steps S201 to S205 in Embodiment 1. The instances and application scenarios implemented by the above units and the corresponding steps are the same, but are not limited to the content disclosed in Embodiment 1. It should be noted that the above units can be hardware or software components stored in memory (e.g., memory 104) and processed by one or more processors (e.g., processors 102a, 102b, ..., 102n). The above units can also be part of a device and run in the computer terminal 10 provided in Embodiment 1.

[0103] Example 3

[0104] Embodiments of this application may provide a computer terminal, which may be any computer terminal device in a group of computer terminals. Optionally, in this embodiment, the aforementioned computer terminal may also be replaced with a mobile terminal or an electronic device, etc.

[0105] Optionally, in this embodiment, the computer terminal may be located in at least one of a plurality of network devices in a computer network.

[0106] In this embodiment, the computer terminal described above can execute the program code for the following steps in the bill generation method: receiving the current interface call request and determining the target business server indicated by the call information carried in the current interface call request; processing the current interface call request through the target business server to generate multiple interface call logs and writing each interface call log to a preset directory of the data center server; obtaining each interface call log in the preset directory and writing it to the target directory, processing the interface call logs in the target directory to obtain structured data, and sending all structured data to the cache database cluster; processing the structured data through the cache database cluster to obtain daily cumulative cost data; and generating the target bill based on the daily cumulative cost data.

[0107] Optionally, the aforementioned computer terminal may execute the program code for the following steps in the bill generation method: configuring multiple versions of tiered billing rules for each business server interface, and configuring the effective time of each version of the tiered billing rules; storing the multiple versions of the tiered billing rules in a cache database cluster.

[0108] Optionally, the aforementioned computer terminal may execute program code for the following steps in the bill generation method: calculating the current number of interface calls to the target business server based on structured data; performing billing operations for the current interface calls using a preset script based on the current number of interface calls to obtain the current interface call cost; and summing up the current interface call costs obtained from all billing operations each day to obtain the daily cumulative cost data.

[0109] Optionally, the aforementioned computer terminal may execute the program code for the following steps in the bill generation method: obtaining the call timestamp of the current interface call; matching from multiple versions of tiered billing rules based on the call timestamp and the rule effective time corresponding to each version of the tiered billing rule to obtain the target tiered billing rule; and calculating the current interface call fee based on the target tiered billing rule and the current number of interface calls.

[0110] Optionally, the aforementioned computer terminal can execute the program code for the following steps in the bill generation method: obtaining the cumulative number of times the user account calls the target business server's interface, wherein the cumulative number of interface calls is obtained by summing multiple historical structured data, and the historical structured data is obtained by processing historical interface call logs obtained from historical calls to the target business server; calculating the sum of the cumulative number of interface calls and the current number of interface calls to obtain the target cumulative number of calls; comparing the cumulative number of interface calls with multiple billing tiers in the target tiered billing rules to obtain the billing tier to which the cumulative number of interface calls belongs; comparing the target cumulative number of calls with multiple billing tiers in the target tiered billing rules to obtain the billing tier to which the target cumulative number of calls belongs; if the billing tier to which the cumulative number of interface calls belongs is different from the billing tier to which the target cumulative number of calls belongs, calculating the current interface call fee based on the first billing price in the billing tier to which the cumulative number of interface calls belongs and the second billing price in the billing tier to which the target cumulative number of calls belongs.

[0111] Optionally, the aforementioned computer terminal may execute program code for the following steps in the bill generation method: adjusting the user account based on the current interface call cost; or, adjusting the user account based on daily cumulative cost data.

[0112] Optionally, the aforementioned computer terminal may execute the program code for the following steps in the bill generation method: using a buffer reader to read each interface call log in the target directory; determining multiple target fields and constructing regular expressions based on the target fields and the corresponding parsing rules; and using regular expressions to extract fields from each interface call log to obtain structured data.

[0113] Optionally, the aforementioned computer terminal may execute program code for the following steps in the bill generation method: calculating the number of interface call logs in the target directory; and if the number equals a preset threshold, sending all structured data to the cache database cluster.

[0114] Optionally, Figure 6 This is a structural block diagram of an electronic device according to an embodiment of this application. Figure 6 As shown, the electronic device may include: one or more ( Figure 6 (Only one is shown) Processor 602, memory 604, memory controller, and peripheral interface, wherein the peripheral interface is connected to the radio frequency module, audio module and display.

[0115] The memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the bill generation method and apparatus in this application embodiment. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, thereby implementing the aforementioned bill generation method. The memory may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to the terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0116] The processor can invoke the information and application program stored in the memory through the transmission device to execute the steps described above in the bill generation method.

[0117] The embodiments of this application provide a bill generation scheme. By constructing a distributed high-concurrency processing architecture based on a Redis cluster and adopting cross-boundary segmented pricing and configuration version management, it can meet complex pricing and auditing requirements. By using Lua scripts to bundle billing, deduction, and accumulation, it reduces concurrent accounting errors. Users can view consumption details in real time, thereby solving the technical problem in related technologies that cannot calculate interface call fees in real time, resulting in poor timeliness of bill generation.

[0118] Those skilled in the art will understand that Figure 6 The structure shown is for illustrative purposes only. Electronic devices can also be terminal devices such as smartphones, tablets, PDAs, and mobile internet devices (MIDs). Figure 6 This does not limit the structure of the aforementioned electronic device. For example, electronic devices may also include components that are more... Figure 6 The more or fewer components shown (such as network interfaces, display devices, etc.), or having the same Figure 6 The different configurations shown.

[0119] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing the hardware related to the terminal device. The program can be stored in a computer-readable storage medium, which may include: flash drive, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0120] Example 4

[0121] Embodiments of this application also provide a storage medium. Optionally, in this embodiment, the storage medium can be used to store the program code executed by the bill generation method provided in Embodiment 1.

[0122] Optionally, in this embodiment, the storage medium may be located in any computer terminal in a group of computer terminals in a computer network, or in any mobile terminal in a group of mobile terminals.

[0123] This application also provides a computer program product that, when executed on a data processing device, is adapted to perform the steps of a bill generation method.

[0124] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0125] In the above embodiments of this application, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0126] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.

[0127] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0128] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0129] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.

[0130] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.

Claims

1. A bill generation method, characterized in that, The billing system is applied to a billing generation system, which includes at least: multiple business servers, a data center server, and a cache database cluster. The billing generation method includes: Receive the current interface call request and determine the target business server indicated by the call information carried in the current interface call request; The target business server processes the current interface call request, generates multiple interface call logs, and writes each interface call log to a preset directory of the data center server. Obtain each of the interface call logs in the preset directory and write it to the target directory. Process the interface call logs in the target directory to obtain structured data, and send all the structured data to the cache database cluster. The structured data is processed by the cache database cluster to obtain daily cumulative cost data; Based on the daily cumulative cost data, a target bill is generated.

2. The bill generation method according to claim 1, characterized in that, Before processing the structured data through the cached database cluster to obtain the daily cumulative cost data, the process includes: Configure multiple versions of tiered billing rules for each interface of the business server, and configure the effective time of each version of the tiered billing rules; The multiple versions of the tiered billing rules are stored in the cache database cluster.

3. The bill generation method according to claim 1, characterized in that, The cache database cluster stores preset scripts. The steps for processing the structured data through the cache database cluster to obtain daily cumulative cost data include: Based on the structured data, calculate the current number of interface calls to the target business server; Based on the current number of interface calls, the billing operation for the current interface call is performed using the preset script to obtain the current interface call cost; The daily cumulative cost data is obtained by summing up the current interface call costs obtained from all the billing operations each day.

4. The bill generation method according to claim 3, characterized in that, The steps for obtaining the current interface call cost by performing a billing operation on the current interface call using the preset script based on the current number of interface calls include: Obtain the call timestamp of the current interface call; Based on the call timestamp and the effective time of the rule corresponding to each version of the tiered billing rule, the target tiered billing rule is obtained by matching from multiple versions of the tiered billing rule. The cost of the current interface call is calculated based on the target tiered billing rules and the current number of interface calls.

5. The bill generation method according to claim 4, characterized in that, The steps for calculating the current interface call cost based on the target tiered billing rules and the current number of interface calls include: The cumulative number of times a user account calls the target business server's interface is obtained, wherein the cumulative number of times the interface is called is calculated by summing multiple historical structured data, and the historical structured data is obtained by processing historical interface call logs obtained from historical calls to the target business server; Calculate the sum of the cumulative number of interface calls and the current number of interface calls to obtain the target cumulative number of calls; The cumulative number of API calls is compared with multiple billing tiers in the target tiered billing rules to obtain the billing tier to which the cumulative number of API calls belongs. The target cumulative number of calls is compared with multiple billing tiers in the target tiered billing rules to obtain the billing tier to which the target cumulative number of calls belongs; If the billing tier to which the cumulative number of interface calls belongs is different from the billing tier to which the target cumulative number of calls belongs, the current interface call cost is calculated based on the first billing price in the billing tier to which the cumulative number of interface calls belongs and the second billing price in the billing tier to which the target cumulative number of calls belongs.

6. The bill generation method according to claim 4, characterized in that, After calculating the cost of the current interface call, the following is included: Adjust the user account based on the current interface call cost; or, The user account is adjusted based on the daily cumulative cost data.

7. The bill generation method according to claim 1, characterized in that, The steps of obtaining each interface call log in the preset directory and writing it to the target directory, and processing the interface call logs in the target directory to obtain structured data, include: A buffered reader is used to read each of the interface call logs in the target directory; Identify multiple target fields, and construct regular expressions based on the target fields and the corresponding parsing rules; The regular expression is used to extract fields from each of the interface call logs to obtain the structured data.

8. The bill generation method according to claim 1, characterized in that, The steps of sending all the structured data to the cache database cluster include: Calculate the number of interface call logs in the target directory; If the number equals a preset threshold, all the structured data is sent to the cache database cluster.

9. A bill generation device, characterized in that, The billing system is applied to a billing generation system, which includes at least: multiple business servers, a data center server, and a cache database cluster. The billing generation device includes: The first determining unit is used to receive the current interface call request and determine the target business server indicated by the call information carried in the current interface call request. The first generation unit is used to process the current interface call request through the target business server, generate multiple interface call logs, and write each interface call log into a preset directory of the data center server; The first processing unit is used to obtain each of the interface call logs in the preset directory and write them to the target directory, process the interface call logs in the target directory to obtain structured data, and send all the structured data to the cache database cluster. The second processing unit is used to process the structured data through the cache database cluster to obtain daily cumulative cost data; The second generation unit is used to generate a target bill based on the daily cumulative cost data.

10. A computer program product, characterized in that, The method includes a non-volatile computer-readable storage medium storing a computer program that, when executed by a processor, implements the bill generation method according to any one of claims 1 to 8.

11. An electronic device, characterized in that, It includes one or more processors and a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the bill generation method according to any one of claims 1 to 8.