When building and operating modern websites, especially when your platform involves quality content or exclusive resources, how to effectively manage content access permissions is a core issue.AnQiCMS (AnQiCMS) provides a powerful and flexible API interface, allowing you to precisely control the viewing conditions of documents, including determining whether a specific document requires payment and whether the user has completed the payment.
We will discuss how to use the API provided by AnQiCMS to check if a specific document has been paid for before viewing, to ensure that your paid content is properly protected.
Define the paid attributes of the document: Get document details
Before determining whether the user has paid, we first need to know whether the target document itself is set as paid content. Anqi CMS document detail interface/api/archive/detailIt can help us obtain detailed information about the document, including the price information of the document.
You can send a GET request to{域名地址}/api/archive/detailand include the document'sid(Or)filename) as a parameter to get the document details. For example,GET {域名地址}/api/archive/detail?id=123.
In the returned data, you will find a field namedprice. The value of this field represents the price of the document, unit is 'points'.
- If
priceThe value is0This indicates that the document is free content, which can be viewed directly by any user without payment verification. - If
priceis greater than0This indicates that this is a paid document. At this point, we need to further determine whether the current user has paid for this document.
By this step, we can effectively avoid unnecessary payment status checks for free documents, optimize system resources and response time.
Check if the user has paid: Verify order interface
Once the document is confirmed as paid content, the next step is to verify whether the current user has completed the payment for the document. AnQi CMS provides a dedicated interface for this: /api/archive/order/check.
You also need to send a GET request to{域名地址}/api/archive/order/checkand pass the document you want to checkidFor example,GET {域名地址}/api/archive/order/check?id=123.
The response of this interface is very direct:
- If the returned data contains
dataField istrueThis indicates that the currently logged-in user has paid for this document and is allowed to view the full content of the document. - If
dataField isfalseThis means that the current user has not paid. At this point, you can show the user the purchase options and guide them through the payment process.
It is worth noting that this interface requires the user to be logged in. If the user attempts to access paid content without being logged in or if their session token has expired, the API may return1001(Not logged in) or1002etc. error codes, you need to guide the user to log in according to these error codes.
Combined use to implement content permission management
Combine the above two APIs, and you can build a complete and flexible paid content access control logic:
- When the user tries to access a document, the first call is made to
/api/archive/detailGet the detailed information of the document. - Check the returned data for
priceField:- If
priceWith0, directly display the document content. - If
pricegreater than0, then the document is paid content and payment verification is required.
- If
- Next, call
/api/archive/order/checkPass the document inid. - Based on
/api/archive/order/checkreturneddataField:- If
dataWithtrueMeans the user has paid, display the document content. - If
dataWithfalseMeans the user has not paid, show the user a purchase prompt or a preview of the content. - If the API returns an unlogged/unauthorized error, guide the user to log in.
- If
By this process, you can accurately provide your website visitors with a customized content access experience, which can protect your intellectual property rights, enhance users' willingness to pay, and maximize the value of content.
Frequently Asked Questions (FAQ)
Q1: If the document detail interface returns thepricefield is 0, do I need to call thearchiveOrderCheckinterface?A1: No need. IfpriceField 0 means that the document itself is free, and any user can view it without paying.Let it go, no need for additional payment status verification, which also helps optimize your system performance.
Q2: Call/api/archive/order/checkWhat result will be obtained when an interface, if the user is not logged in or not authorized?A2: In this case, the API will usually return an error code (such ascode: 1001indicating not logged in,code: 1002Indicates unauthorized, not a boolean valuetrueorfalseYou should catch these errors and guide users to log in according to the situation, or prompt them that they need to log in to purchase and view paid content.
Q3: In addition to paid pricing, does AnQiCMS support other types of document access restrictions, such as membership levels or password protection?A3: Yes, AnQiCMS not only supports paid pricing, but also provides other access control methods. There may be in the document details.read_levelField (corresponding to user group or member level), and existsarchivePasswordCheckThe interface is used to verify the document password. You can use these fields and interface to build a more complex document access permission system based on the payment status.