When building and operating modern websites, especially when your platform involves high-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 it can be viewed, ensuring that your paid content is properly protected.

Explicitly document the payment attributes: Obtain document details

Before determining whether the user has paid, we first need to know whether the target document itself has been set as paid content. The document details interface of Anqi CMS/api/archive/detailThis can help us obtain detailed information about the document, including the price information.

You can send a GET request to{域名地址}/api/archive/detailwith 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, in 'fen'.

  • Ifpricehas a value of0,then it indicates that the document is free content, which any user can view directly without the need for payment verification.
  • Ifpriceis greater than0If this is the case, it means 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

When the document is confirmed as paid content, the next step is to verify whether the current user has completed the payment for the document. Anqin 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 in 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 containsdatathe field istrueIt indicates that the currently logged-in user has paid for this document and is allowed to view the full content of the document.
  • Ifdatathe field isfalseIf this is the case, it means the current user has not made a payment. At this point, you can show the user the purchase options and guide them through the payment process.

It is worth noting that calling this interface requires the user to be logged in. If the user attempts to access paid content without logging in or if their session credentials have expired, the API may return1001(Not logged in) or1002(Unauthorized) and other error codes, you need to guide the user to perform login operations according to these error codes.

Used together to implement content permission management

Combine the above two APIs, and you can build a complete and flexible access control logic for paid content:

  1. When a user tries to access a document, the first call is made:/api/archive/detailRetrieve the detailed information of the document.
  2. Check the returned data forpriceFields:
    • Ifpriceresponse for0and directly display the document content.
    • Ifpricegreater0means the document is a paid content and payment verification is required.
  3. Next, call/api/archive/order/checkAnd pass the documentid.
  4. Based on/api/archive/order/checkreturneddataFields:
    • Ifdataresponse fortrueIndicates that the user has paid, and the document content is displayed.
    • Ifdataresponse forfalseIndicates that the user has not paid, and the user is shown a purchase prompt or a preview of the document content.
    • If the API returns an unlogged/unauthorized error, guide the user to log in.

Through this process, you can precisely provide a customized content access experience for your website visitors, which can protect your intellectual property rights, enhance users' willingness to pay, and maximize the value of content.

Common Questions (FAQ)

Q1:If the document details interface returns thepricefield is 0, do I need toarchiveOrderCheckcall the interface?A1:No need. IfpriceThe field is 0, which means that the document itself is free, and any user can view it without paying.Directly proceed without any additional payment status verification, which also helps optimize your system performance.

Q2:Call/api/archive/order/checkWhat is the result if the user is not logged in or unauthorized during the interface?A2: In this case, the API usually returns an error code (for examplecode: 1001indicating not logged in,code: 1002Represents unauthorized), not a boolean valuetrueorfalse。You should catch these errors and guide the user to perform login operations according to the situation, or prompt them that they need to log in to purchase and view paid content.

Q3:In addition to payment, does AnQiCMS support other types of document access restrictions, such as membership levels or password protection?A3: Yes, AnQiCMS not only supports price-based access, but also provides other access control methods. There may be some 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 combine these fields and interface with the payment status to build a more complex document access permission system.