Acg-Faka API Bridge
About 1827 words
ACG-Faka and xstock communicate over the store-sharing protocol: ACG-Faka acts as the downstream and sends POST requests to the xstock adapter component, with all protocol paths shaped as {store-url}/shared/{controller}/{method}.
- Adapter component:
xstock.distshopadapter.acg_faka - Protocol version: ACG-Faka V3.1.2 refactored version
- Service URL:
http://<xstock-host>:11021/dist/acg/{shop-id} - Online debugging:
http://<xstock-host>:11021/swagger/index.html
Authentication and signature
All requests are application/x-www-form-urlencoded and carry these common fields:
| Field | Description |
|---|---|
app_id | Merchant ID |
app_key | Merchant key |
sign | Signature, lowercase MD5 hex |
Signature algorithm:
1. Take all non-empty fields except sign, sorted by field name in ASCII ascending order
2. Join them with http_build_query, then apply urldecode once
3. Append "&key=" + app_key
4. MD5 the whole string and convert it to lowercaseArray fields are expanded as key[0], key[1] before they take part in sorting.
All responses share this shape:
{ "code": 200, "msg": "success", "data": {} }code=200 means success; anything else is a business error, and msg gives a human-readable reason.
Endpoint overview
| Method | Path | Purpose | xstock command |
|---|---|---|---|
| POST | /shared/authentication/connect | Connectivity test | ping |
| POST | /shared/commodity/items | Product list (category tree) | get_goods |
| POST | /shared/commodity/item | Product details | get_goods |
| POST | /shared/commodity/inventory | Stock and cost price | get_avail |
| POST | /shared/commodity/inventoryState | Pre-order stock check | get_avail |
| POST | /shared/commodity/stock | Real-time stock | get_avail |
| POST | /shared/commodity/valuation | Real-time quote | get_quote |
| POST | /shared/commodity/trade | Place order (currently disabled) | post_order |
| POST | /shared/commodity/query/{tradeNo} | Query by upstream order number | get_orders |
| POST | /shared/commodity/queryByRequest | Query by request number | get_orders |
| POST | /shared/commodity/draftCard | Pre-select card keys (not supported) | — |
| GET | /xstock/calltest (reverse direction) | Connectivity self-check: confirm the extension file is active | — |
| POST | /xstock/callback (reverse direction) | Delivery callback: xstock pushes the delivered content | Delivery callback |
The "On this page" list on the right jumps to each endpoint.
POST Connectivity test
Endpoint: /shared/authentication/connect
No business parameters; only the common fields. Returns:
{ "code": 200, "msg": "success", "data": { "shopName": "xstock", "balance": "501.00" } }The ACG-Faka admin panel calls this when you save a "Store Sharing" entry; on failure the list shows a failed connection status.
POST Product list
Endpoint: /shared/commodity/items
No business parameters. data is an array of categories, and each category's children holds its products:
[
{
"id": 1,
"name": "数字账号",
"children": [
{
"id": "9a1b2c3d4e5f60718293a4b5c6d7e8f9",
"name": "示例数字账号(月付)",
"price": "10.00",
"factory_price": "9.50",
"stock": 18,
"delivery_way": 0
}
]
}
]The product id is xstock's guid and is used as the code parameter in later calls.
POST Product details
Endpoint: /shared/commodity/item
| Parameter | Required | Description |
|---|---|---|
code | Yes | Product GUID |
sharedCode | Compatible | Legacy protocol field, same value as code |
Returns a single product object whose fields match those in the list, plus specs (race) and configuration.
POST Stock and cost price
Endpoint: /shared/commodity/inventory
| Parameter | Required | Description |
|---|---|---|
sharedCode | Yes | Product GUID |
race | No | Spec identifier; omit for the default spec |
Returns the stock and cost price of the product (or spec), which ACG-Faka uses to compute cost and sellability.
POST Pre-order stock check
Endpoint: /shared/commodity/inventoryState
| Parameter | Required | Description |
|---|---|---|
shared_code | Yes | Product GUID |
race | No | Spec |
num | Yes | Quantity to buy |
When the quantity is insufficient it returns a non-200 business error, which ACG-Faka surfaces as "insufficient stock".
POST Real-time stock
Endpoint: /shared/commodity/stock
| Parameter | Required | Description |
|---|---|---|
code | Yes | Product GUID |
race | No | Spec |
Returns the currently sellable quantity without prices, which suits frequent stock refreshes.
POST Real-time quote
Endpoint: /shared/commodity/valuation
| Parameter | Required | Description |
|---|---|---|
code | Yes | Product GUID |
race | No | Spec |
num | Yes | Quantity to buy |
Returns the unit price and subtotal calculated with your tier discount; it does not hold stock.
POST Place order
Endpoint: /shared/commodity/trade
| Parameter | Required | Description |
|---|---|---|
code | Yes | Product GUID |
race | No | Spec |
num | Yes | Quantity |
tradeNo | Yes | Downstream order number, the idempotency key |
request | No | Additional order fields (for manually delivered products) |
Currently disabled
The adapter component ships with trade_enabled=false, so calls return the readable message "ordering is not yet open upstream, please try again later". Once ordering is enabled, the response structure matches the order query.
POST Query by upstream order number
Endpoint: /shared/commodity/query/{tradeNo}
The path parameter tradeNo is the upstream order number. The current adapter component always returns "order not found" — the platform's trading command is not in place yet.
POST Query by request number
Endpoint: /shared/commodity/queryByRequest
| Parameter | Required | Description |
|---|---|---|
requestNo | Yes | Downstream request number |
It always returns found=false while the order is unfilled; once filled it returns the order status and deliverables.
POST Pre-select card keys
Endpoint: /shared/commodity/draftCard
The xstock platform has no concept of pre-selecting card keys, so it always returns an empty list. ACG-Faka then falls back to allocating them at order time.
POST Delivery callback
Endpoint: POST /xstock/callback (opposite direction: xstock pushes to ACG-Faka)
ACG-Faka has no upstream callback protocol, so order delivery could only be pulled by the downstream. This endpoint is a receiver added on the ACG-Faka side: after procurement or delivery completes, xstock pushes the delivered content to ACG-Faka, which writes it into the order and marks the order as shipped.
- Controller file:
app/Controller/Xstock.php(single-file extension, no core code changes) - Route mapping:
/xstock/callback→App\Controller\Xstock::callback() - Full URL:
http://<faka-host>/xstock/callback - Media type:
application/json(shop_idmay also be passed as a query parameter)
Request body
{
"shop_id": "S-ACG",
"trade_no": "202611301234567890",
"secret": "账号:demo_user_01\n密码:demo_pass_01",
"delivery_status": 1,
"ts": 1796000000,
"sign": "6f1c2a..."
}| Field | Required | Description |
|---|---|---|
shop_id | Yes | xstock store identifier; equal to the last path segment of that store's URL in ACG-Faka's Store Sharing, e.g. S-ACG |
trade_no | Yes | ACG-Faka order number; if not found, matching falls back to the downstream request number request_no |
secret | Yes | Delivered content as plain text (card keys, account credentials or download information) |
delivery_status | Yes | Fixed 1, meaning shipped |
ts | Yes | Unix timestamp in seconds; must match the signature |
sign | Yes | HMAC-SHA256 signature, lowercase hex |
The signing key comes from the shared store
No key is stored in the file. The server finds the matching "Store Sharing" record by shop_id (comparing the last path segment of the store URL) and verifies the signature with that record's app_key (merchant key):
string_to_sign = ts + "\n" + trade_no + "\n" + secret
sign = HMAC_SHA256(string_to_sign, that shared store's app_key) // lowercase hexExample:
xstock callback URL template: http://host:11021/dist/acg/S-ACG
ACG-Faka shared store domain: http://host.docker.internal:11021/dist/acg/S-ACG
last segment: S-ACG ← this is the shop_idIf several shared records share the same last path segment, the request counts as ambiguous and the endpoint returns 404, so the wrong key is never used. A timestamp skew greater than 300 seconds is rejected.
Response
On success:
{ "code": 200, "msg": "ok" }On failure it returns 4xx with a reason:
| code | Scenario |
|---|---|
400 | Incomplete parameters, or a malformed shop_id |
401 | Timestamp outside the window, or signature mismatch |
403 | Source IP not in the allowlist, or the order's product does not belong to this shared store |
404 | No matching shared store (including ambiguous URLs), or the order does not exist |
405 | A method other than POST |
409 | The order is unpaid and cannot be delivered |
500 | Writing the order failed |
Server-side processing flow
- Accepts POST only;
- Validates the source IP (
ALLOWED_IPS, unrestricted by default); - Reads
shop_id(the query parameter takes precedence) and the remaining fields, and checks that they are complete; - Validates the
shop_idcharacter set (SHOP_ID_PATTERN, 1–64 alphanumeric characters plus._-); - Finds the shared store by
shop_idand uses that record'sapp_keyas the verification key; - Validates the timestamp window and the HMAC signature;
- Looks up the order by
trade_no, falling back torequest_no; - Only allows delivery of orders with
status=1(paid); - Verifies that the order's product belongs to this shared store, preventing cross-store writes;
- Idempotency: if the delivered content is identical and the order is already shipped, returns 200 directly;
- Writes
secretanddelivery_status=1, and clearsshared_error; - Triggers ACG-Faka's built-in shipping email according to
SEND_EMAIL(a failure does not affect the delivery result).
ACG-Faka-side configuration
XstockCallbackConfig at the top of the file:
| Constant | Description |
|---|---|
ALLOWED_IPS | Source IP allowlist; an empty array means no restriction; the self-check endpoint is exempt |
SIGN_TOLERANCE | Allowed timestamp skew, 300 seconds by default |
SEND_EMAIL | Whether to trigger the shipping email after a successful delivery |
SHOP_ID_PATTERN | Allowed shop_id character set; defaults to alphanumeric plus ._-, 1–64 characters |
No separate callback key needs to be configured: the key comes from the Store Sharing record's app_key, so stores do not affect each other.
Deployment
Mount a single file; no changes to ACG-Faka core code:
services:
faka:
volumes:
- ./ext/acg_callback.3.8.6.php:/var/www/html/app/Controller/Xstock.php:roInside the container the file must be named Xstock.php (the class name must match the file name for autoloading); the host file name may carry a version number. After changing it, run docker compose up -d.
GET Connectivity self-check
Endpoint: GET /xstock/calltest
Used on the xstock side when testing a store connection, to confirm that the extension file is mounted and active. It responds in plain text, requires no signature and performs no business operations.
xstock-callback-ok;version=3.8.6;time=2026-11-30T22:10:00+08:00;shared_count=1| Fragment | Description |
|---|---|
xstock-callback-ok | Fixed marker; its presence means the file is active |
version | Extension version |
time | Current server time (RFC 3339) |
shared_count | Number of configured shared stores; -1 when the query fails |
This endpoint is exempt from ALLOWED_IPS, so you can verify it directly with a browser or curl during deployment:
curl http://<faka-host>/xstock/calltestMapping to xstock commands
| Shared endpoint | xstock command | Description |
|---|---|---|
authentication/connect | ping | Connectivity and balance |
commodity/items, item | get_goods | Products and SKUs |
commodity/inventory, stock, inventoryState | get_avail | Sellable quantity |
commodity/valuation | get_quote | Unit price quote |
commodity/trade | post_order | Place order (disabled) |
commodity/query, queryByRequest | get_orders | Order query |
/xstock/calltest (reverse direction) | Connectivity self-check | Confirm the extension is active |
/xstock/callback (reverse direction) | Delivery callback | Push the delivered content once delivery completes |
For admin panel steps see ACG-Faka backend setup.