Complete Python suite to talk to the encrypted AcBuy API (acbuy.com). It includes a library and a CLI (acbuy), handles transport encryption, captcha, token cache, product URL parsing, and exposes dozens of endpoints ready for terminal usage or automation.
The project mirrors the real web UI flow: it downloads the AES key from the site JS bundle, encrypts/decrypts bodies, RSA-encrypts the password, and keeps headers consistent (Lang, Accept-Language, Currency, Device). Everything is encapsulated so you only pass credentials and JSON.
Main blocks:
- Login with captcha (OCR or manual) and configurable retries (
ACBUY_MAX_LOGIN_ATTEMPTS) - Local token cache validated via JWT
exp - Payload encryption/decryption (AES-ECB + PKCS7) and RSA password encryption on login
- Product URL parser (1688/Taobao/Goofish) to extract IDs/SKU and build calls from links
- CLI with dozens of commands, JSON support via
--params(GET) and--payload(POST/PUT/DELETE)
python3 -m venv .venv
source .venv/bin/activate
pip install -e .
export ACBUY_EMAIL="you@example.com"
export ACBUY_PASSWORD="your_password"
acbuy login
acbuy user-infoOptional:
acbuy login --manual
acbuy clear-cache- Quick start
- Overview
- Project structure and code docs
- Encryption and decryption (detailed)
- Installation
- Configuration
- How it works
- Authentication and cache
- CLI
- Product URLs (--url)
- Endpoints with required parameters
- Practical examples (with args)
- Examples by command (detailed)
- Command groups
- Library usage (Python)
- Troubleshooting
- Tests
- Support scripts
This project is designed to:
- Encapsulate all encryption required by the API
- Perform login with captcha (OCR or manual)
- Reuse token via local cache
- Expose a clear CLI with grouped commands
- Allow parameters via JSON (
--params/--payload) - Extract data from URLs (1688 / Taobao / Goofish)
Each file has function/argument documentation in docs/CODE_REFERENCE.md. Summary of core modules:
Main files in src/acbuy:
-
client.pyAcBuyClient: main API entry point.- Composes service mixins and exposes all
get_*,post_*,put_*anddelete_*methods. - Centralizes encryption/decryption and auth headers via a shared base.
-
services/- Smaller mixins split by feature (e.g.,
user_profile,user_cart,payment_wallet,order_list,product_catalog,resource_task,logistics_catalog,marketing_report,storage_package). - Each mixin groups closely related endpoints to keep classes focused.
- Smaller mixins split by feature (e.g.,
-
crypto.pyfetch_aes_key: downloads the main JS bundle and extracts the AES key.AESCipher: AES encrypt/decrypt with PKCS7.rsa_encrypt: RSA-encrypts the password.
-
http.pybuild_session: creates arequests.Sessionwith retries and default headers.
-
config.pySettings: configuration values from environment variables.- Current defaults:
pt,pt-PT,BRL.
-
cache.pyload_token,save_token,clear_cache.- Validates expiration via JWT.
-
captcha.py- Saves captcha to cache.
OcrCaptchaSolver: OCR using OpenCV + Tesseract.
-
cli.py- Main CLI (
acbuy). - Maps commands -> client methods.
- Supports
--params,--payload,--url.
- Main CLI (
-
url_parser.py- URL parser for 1688/Taobao/Goofish.
- Extracts
itemId,goodsId,source,sku,skuId.
See the technical article in docs/CRYPTOGRAPHY.md (AES key bootstrap, AES-ECB+PKCS7, RSA on login, wire format, and Python examples).
Quick snippet to decrypt any encrypted body from Burp/DevTools:
from acbuy.client import AcBuyClient
from acbuy.config import Settings
client = AcBuyClient(Settings.from_env()) # fetches AES key from the site
print(client.aes.decrypt("yp3ye9cuklb/W94I...")) # Base64 ciphertext from the bodyRequirements:
- Python 3.9+
- (Optional) OCR via Tesseract installed on your system. Without it, use
acbuy login --manual.- macOS (Homebrew):
brew install tesseract - Debian/Ubuntu:
sudo apt-get install tesseract-ocr
- macOS (Homebrew):
python3 -m venv .venv
source .venv/bin/activate
pip install -e .export ACBUY_EMAIL="you@example.com"
export ACBUY_PASSWORD="your_password"| Variable | Default | Notes |
|---|---|---|
ACBUY_BASE_URL |
https://www.acbuy.com |
Site/API base |
ACBUY_LANG |
pt |
Lang header |
ACBUY_ACCEPT_LANGUAGE |
pt-PT |
Accept-Language header |
ACBUY_CURRENCY |
BRL |
Currency header |
ACBUY_DEVICE |
pc |
Device header |
ACBUY_TIMEOUT |
15 |
Timeout (seconds) |
ACBUY_MAX_LOGIN_ATTEMPTS |
10 |
Max attempts for login/captcha |
ACBUY_TOKEN_MARGIN |
60 |
JWT exp margin (seconds) |
ACBUY_CACHE_DIR |
~/.cache/acbuy |
Cache folder (token + captcha) |
ACBUY_REGISTER_COUNTRY_CODE |
BR |
Country code for registration |
ACBUY_REGISTER_COUNTRY |
巴西 |
Country name for registration |
ACBUY_REGISTER_LANGUAGE |
pt |
Language sent on registration |
ACBUY_INVITE_CODE |
AC244922609 |
Optional invite code |
ACBUY_INVITE_SOURCE |
TB |
Invite source (TB, etc.) |
ACBUY_PROMOTER_CODE |
`` | Optional promoter code |
The options below override the corresponding environment variables:
--email,--password--base-url--timeout--max-attempts--cache-dir
For registration (acbuy register), if you do not pass explicit flags, the CLI uses defaults from ACBUY_REGISTER_COUNTRY_CODE, ACBUY_REGISTER_COUNTRY, ACBUY_REGISTER_LANGUAGE, ACBUY_INVITE_CODE, ACBUY_INVITE_SOURCE, and ACBUY_PROMOTER_CODE.
- The client builds a
requests.Sessionwith automatic retries. - Default headers are pinned (Accept, Content-Type, Lang, Currency, Device, X-Encrypted).
- A random User-Agent is chosen per session.
- The AES key is extracted from the site JS bundle.
- The client fetches
https://www.acbuy.com/, finds the main JS, and captures the embedded AES key. - This key encrypts request bodies and decrypts responses.
- Payloads are AES-ECB encrypted with PKCS7 padding.
- The password is RSA-encrypted with the public key from the API.
- Responses are decrypted automatically.
- Technical details in
docs/CRYPTOGRAPHY.md.
- Captcha is fetched via endpoint, decrypted, and saved to
ACBUY_CACHE_DIR/captcha.png. - OCR attempts to solve (OpenCV + pytesseract).
- If OCR fails, manual mode asks for captcha on the terminal.
- In manual mode, wrong captcha is retried up to
ACBUY_MAX_LOGIN_ATTEMPTS.
- Token is saved to
ACBUY_CACHE_DIR/auth_cache.json(default:~/.cache/acbuy/auth_cache.json). - Cache is validated via JWT
expand a safety margin (ACBUY_TOKEN_MARGIN). - With a valid token, no new login is required.
acbuy loginperforms login, prints the token, and saves it in cache.acbuy login --manualforces manual captcha (with retries up toACBUY_MAX_LOGIN_ATTEMPTS).acbuy captchadownloads a captcha and saves it toACBUY_CACHE_DIR/captcha.png(useful for inspection).
- Token is stored at
ACBUY_CACHE_DIR/auth_cache.json(default:~/.cache/acbuy/auth_cache.json). acbuy clear-cacheremoves only the token (does not deletecaptcha.png).- To force a fresh login even with a valid token:
acbuy login --no-cache. - Use
clear-cachewhen you want to switch accounts or ensure a brand-new token.
If you run a command without being authenticated, the CLI exits and asks you to run acbuy login.
acbuy <command> [--params '{...}'] [--payload '{...}'] [--url "..."]--params: JSON object for query string (GET only)--payload: JSON object for body (POST/PUT/DELETE)--url: product URL to extract fields (only for some commands)--manual: force manual captcha (loginandregister)--no-cache: do not use cached token (non-login commands will exit asking foracbuy login)--base-url,--timeout,--max-attempts,--cache-dir,--verbose
- If
--urland--params/--payloadare used together, JSON overrides values extracted from the URL.
- Use single quotes in the shell to avoid JSON being interpreted.
- Avoid ending JSON with
.or;(if it happens, the CLI tries to strip it automatically).
acbuy issue-detail-list --params '{"pageNum":1,"pageSize":10,"status":0}'
acbuy user-tags-put --payload '{"id":8753,"name":"VIP","bgColor":"#FF8F1F","comment":"Tag edited"}'acbuy registerfollows the same captcha flow as login (OCR by default;--manualto type). If the API returns a token, it is saved automatically.- Default registration values (country, invite code, language) come from
ACBUY_REGISTER_*,ACBUY_INVITE_*,ACBUY_PROMOTER_CODE. - Activation (if the platform requires a code): use
register-activewith--payload.
Examples:
acbuy register --manual --country-code BR --register-country "巴西" --invite-code AC244922609
acbuy register-active --payload '{"code":"1234","userId":"405414802","account":"email@example.com"}'The parser understands 1688, Taobao and Goofish URLs. It attempts to extract:
itemIdgoodsIdsource(TB or AL)skuskuId
Mapping:
- 1688:
/offer/<id>.html->itemId=<id>,source=AL,goodsId=AL<id> - Taobao:
?id=<id>->itemId=<id>,source=TB,goodsId=TB<id> - Goofish: only
itemId(does not producegoodsId)
Commands that support --url:
product-item-detailproduct-item-photosproduct-item-matchproduct-measureitem-logistics-dataproduct-post-feecollect-is-collectbrowsing-history-add
Limitation:
- Goofish URLs are supported only by
product-item-match.
Examples:
acbuy product-item-detail --url "https://item.taobao.com/item.htm?id=xxxxxxxxxxxx"
acbuy product-item-photos --url "https://detail.1688.com/offer/xxxxxxxxxxxx.html"
acbuy product-item-match --url "https://www.goofish.com/item?id=xxxxxxxxxxxx"Some endpoints fail without correct parameters. The CLI validates this and reports missing keys (e.g., Missing required --params: ...).
acbuy payment-channel-list --params '{"country":"CN","orderNo":"ZE02353003730"}'
acbuy payment-fee --params '{"channelId":100,"orderNo":"ZE02353003730","currency":"USD"}'User / profile:
acbuy user-info
acbuy login-history
acbuy address-list
acbuy user-tags
acbuy user-tags-post --payload '{"name":"VIP","bgColor":"#07B9B9","comment":"Notes"}'
acbuy user-tags-put --payload '{"id":8749,"name":"VIP","bgColor":"#FF8F1F","comment":"Tag edited"}'
acbuy user-tags-delete --tag-id 8749Notes:
- For
user-tags-postanduser-tags-put,userIdis auto-filled viauser-infoif missing in the payload. - If
user-tags-postreturns "duplicate information", useuser-tags-putto edit oruser-tags-deleteto remove.
Registration:
acbuy register --manual --country-code BR --register-country "巴西" --register-email new@example.com --register-password "password123" --no-apply-token
acbuy register-active --payload '{"code":"1234","userId":"405414802","account":"email@example.com"}'Cart:
acbuy cart-list
acbuy cart-add --payload '{"itemId":"625214050696","quantity":1}'
acbuy cart-edit --payload '{"cartId":"123","quantity":2}' # quantity maps to goodsNum automatically
acbuy cart-selected-remove --payload '{"cartIds":["123","456"]}'Note: the cart API requires multiple fields (storeId, goodsAttr, prices). The examples above only work if the payload includes the fields that the web UI sends; use a Burp export as reference or build the payload from product data (sku, store, price) to avoid 500s.
Orders:
acbuy user-order-list --payload '{"page":1,"pageSize":20}'
acbuy item-status-count --payload '{}'
acbuy order-count --payload '{}'
acbuy item-logistics-data --url "https://item.taobao.com/item.htm?id=625214050696"Payments:
acbuy wallet-balance
acbuy payment-channel-list --params '{"country":"CN","orderNo":"ZE02353003730"}'
acbuy payment-fee --params '{"channelId":100,"orderNo":"ZE02353003730","currency":"USD"}'Products:
acbuy product-item-detail --url "https://item.taobao.com/item.htm?id=625214050696"
acbuy product-item-photos --url "https://detail.1688.com/offer/570423754750.html"
acbuy product-measure --params '{"spuIds":"TB625214050696"}'
acbuy product-post-fee --payload '{"goodsId":"TB625214050696"}'Resources:
acbuy activity-detail --params '{"id":3211908173210603,"lang":"pt"}'
acbuy issue-detail-list --params '{"pageNum":1,"pageSize":10,"status":0}'Captcha:
acbuy login --manual
acbuy captchaNote: the payloads below are basic examples. Some endpoints require additional fields depending on account type, order, or context.
acbuy register --manual
acbuy login
acbuy login --manual
acbuy captcha
acbuy register-active --payload '{"code":"1234","userId":"405414802","account":"email@example.com"}'In manual mode, if the captcha is incorrect, the CLI retries up to ACBUY_MAX_LOGIN_ATTEMPTS (for login and register).
acbuy registeraccepts--register-email/--register-password(to avoid reusing the login env vars) and--no-apply-tokento prevent overwriting the current token.
acbuy clear-cacheacbuy user-info
acbuy login-history
acbuy address-list
acbuy member-config-list
acbuy user-tags
acbuy user-tags-post --payload '{"name":"VIP","bgColor":"#07B9B9","comment":"Notes"}'
acbuy user-tags-put --payload '{"id":8749,"name":"VIP","bgColor":"#FF8F1F","comment":"Tag edited"}'
acbuy user-tags-delete --tag-id 8749
acbuy bill-address-detail
acbuy bill-address-post --payload '{"name":"John","country":"BR","city":"Lisbon","address":"Street X, 123"}'
acbuy browsing-history-list --params '{"pageNum":1,"pageSize":10}'
acbuy browsing-history-add --url "https://item.taobao.com/item.htm?id=625214050696"
acbuy address-add --payload '{"firstName":"John","country":"BR","countryCode":"BR","city":"Sao Paulo"}'
acbuy address-edit --payload '{"id":237770,"firstName":"John","countryCode":"BR"}'
acbuy address-remove --payload '{"id":237770}'
acbuy user-info-edit --payload '{"userId":244922609,"userName":"AC244922609"}'Note: in user-tags-post and user-tags-put, userId is auto-filled via user-info if missing in the payload. To update a tag, the payload must include id. If user-tags-post returns "duplicate information", change name or use user-tags-put/user-tags-delete.
acbuy cart-list
acbuy cart-nums
acbuy cart-add --payload '{"itemId":"625214050696","quantity":1}'
acbuy cart-edit --payload '{"cartId":"123","quantity":2}'
acbuy cart-buy --payload '{"cartIds":["123","456"]}'
acbuy cart-selected-remove --payload '{"cartIds":["123","456"]}'acbuy user-order-list --payload '{"page":1,"pageSize":20}'
acbuy item-status-count --payload '{}'
acbuy order-count --payload '{}'
acbuy order-pending-list --payload '{"page":1,"pageSize":20}'
acbuy order-item-steps --payload '{"orderNo":"ZE02353003730"}'
acbuy order-delete --payload '{"orderNo":"ZE02353003730"}'
acbuy order-advance-payment --payload '{"orderNo":"ZE02353003730"}'
acbuy order-wait-pay-cancel --payload '{"orderNo":"ZE02353003730"}'
acbuy item-logistics-data --url "https://item.taobao.com/item.htm?id=625214050696"acbuy wallet-balance
acbuy wallet-check-pwd
acbuy payment-channel-list --params '{"country":"CN","orderNo":"ZE02353003730"}'
acbuy payment-fee --params '{"channelId":100,"orderNo":"ZE02353003730","currency":"USD"}'
acbuy payment-order --payload '{"orderNo":"ZE02353003730","channelId":100}'
acbuy exchange-rate --params '{"currency":"USD"}'
acbuy exchange-rate-actual --params '{"currency":"USD"}'
acbuy balance-detail-list --params '{"pageNum":1,"pageSize":10}'
acbuy business-type-list
acbuy discount-list --payload '{"pageNum":1,"pageSize":10}'
acbuy recharge-create --payload '{"currency":"BRL","amount":"100.00","originalAmount":100}'acbuy country-alphabet
acbuy express-list --params '{"status":1}'
acbuy logistics-mail-limit
acbuy logistics-linecount --payload '{"countryCode":"CN","weight":1.2}'
acbuy logistics-notice-query --payload '{"orderNo":"ZE02353003730"}'acbuy marketing-bills --params '{"pageNum":1,"pageSize":10}'
acbuy marketing-invite-records --params '{"pageNum":1,"pageSize":10}'
acbuy marketing-level-conf
acbuy marketing-promoter-info
acbuy marketing-settle-packages --params '{"pageNum":1,"pageSize":10}'
acbuy marketing-withdrawals --params '{"pageNum":1,"pageSize":10}'
acbuy marketing-withdraw-bankacbuy task-count
acbuy user-task-list --params '{"pageNum":1,"pageSize":10}'
acbuy issue-detail-list --params '{"pageNum":1,"pageSize":10,"status":0}'
acbuy issue-detail-exchange-coupon --payload '{"issueId":"123"}'
acbuy resource-code-list --params '{"hotStatus":1,"pageSize":1000}'
acbuy msg-notice-list
acbuy activity-list --params '{"lang":"en"}'
acbuy activity-detail --params '{"id":3211908173210603,"lang":"en"}'
acbuy advert-page --params '{"position":"top","page":"index"}'
acbuy doc-category --doc-id 111
acbuy doc-category-tree --params '{"lang":"en","status":1}'
acbuy country-state-list --payload '{"countryCode":"CN"}'acbuy increment-list
acbuy package-list --params '{"pageNum":1,"pageSize":10}'
acbuy preview-item-list --params '{"pageNum":1,"pageSize":10}'
acbuy pack-rewards-user-list --payload '{"pageNum":1,"pageSize":10}'acbuy category-recommend
acbuy product-item-detail --url "https://item.taobao.com/item.htm?id=625214050696"
acbuy product-item-photos --url "https://detail.1688.com/offer/570423754750.html"
acbuy product-item-match --url "https://www.goofish.com/item?id=995060882159"
acbuy product-measure --params '{"spuIds":"TB625214050696"}'
acbuy product-post-fee --payload '{"goodsId":"TB625214050696"}'acbuy letter-list --params '{"pageNum":1,"pageSize":10}'
acbuy letter-counts
acbuy letter-batch-read --letter-id 678071941673434 --payload '{}'acbuy collect-list --params '{"pageNum":1,"pageSize":10}'
acbuy store-collect-list --params '{"pageNum":1,"pageSize":10}'
acbuy collect-is-collect --payload '{"goodsId":"TB625214050696"}'register,register-active,login,captcha,clear-cache
user-info,login-history,address-list,member-config-list,user-tags,user-tags-post,user-tags-put,user-tags-delete,bill-address-detail,bill-address-post,address-add,address-edit,address-remove,user-info-edit,browsing-history-list,browsing-history-add
cart-list,cart-nums,cart-add,cart-edit,cart-buy,cart-selected-remove
user-order-list,item-status-count,order-count,order-pending-list,order-item-steps,order-delete,order-advance-payment,order-wait-pay-cancel,item-logistics-data
wallet-balance,wallet-check-pwd,payment-channel-list,payment-fee,payment-order,recharge-create,exchange-rate,exchange-rate-actual,balance-detail-list,business-type-list,discount-list
country-alphabet,express-list,logistics-mail-limit,logistics-linecount,logistics-notice-query
marketing-bills,marketing-invite-records,marketing-level-conf,marketing-promoter-info,marketing-settle-packages,marketing-withdrawals,marketing-withdraw-bank
task-count,user-task-list,issue-detail-list,issue-detail-exchange-coupon,resource-code-list,msg-notice-list,activity-list,activity-detail,advert-page,doc-category,doc-category-tree,country-state-list
increment-list,package-list,preview-item-list,pack-rewards-user-list
category-recommend,product-item-detail,product-item-photos,product-item-match,product-measure,product-post-fee
letter-list,letter-counts,letter-batch-read
collect-list,store-collect-list,collect-is-collect
acbuy --helpSimple example:
from acbuy.client import AcBuyClient
from acbuy.config import Settings
settings = Settings.from_env()
client = AcBuyClient(settings=settings)
# Manual login if needed
client.login(settings.email, settings.password, use_ocr=False)
info = client.get_user_info()
print(info)- "Not authenticated": run
acbuy loginfirst. - OCR failed: use
acbuy login --manual. - "Invalid JSON for --params/--payload": check shell quoting and remove trailing punctuation (e.g.,
.). - 500 without message: usually missing required
--params. - "Add failed, duplicate information": duplicate tag name; use
user-tags-putto edit oruser-tags-deleteto remove. - Order endpoints (advance/delete/wait-pay-cancel) depend on order state; if
orderNois not in the expected stage, the API returns 500. - Tesseract not found: install it or use manual mode.
source .venv/bin/activate
pip install -e .[dev]
python -m pytestscripts/check_endpoints.py: validates client endpoints. UseACBUY_EMAILandACBUY_PASSWORDand, optionally, samples (ACBUY_SAMPLE_GOODS_ID,ACBUY_SAMPLE_ITEM_ID,ACBUY_SAMPLE_ORDER_NO,ACBUY_SAMPLE_CHANNEL_ID,ACBUY_SAMPLE_LETTER_ID,ACBUY_SAMPLE_CART_ID). Options:--include-writesto include endpoints that mutate state (cart, orders, tags, payments).--fail-on-skipto fail if any endpoint is skipped due to missing samples.
- Extra env vars for full payloads:
ACBUY_RICH_GOODS_ID,ACBUY_RICH_ITEM_ID,ACBUY_RICH_SOURCE,ACBUY_RICH_SKU_ID(defaults use the 1688 item from the export). By default, cart add/edit/remove flows are disabled; enable withACBUY_ENABLE_CART_OPS=1if you want to exercise these endpoints against a real cart. scripts/burp_diff.py: compares a Burp XML export (like the provided model) with paths implemented insrc/acbuy(client +services/), listing missing and extra endpoints.scripts/parse_burp_xml.py: reads a Burp XML export, identifies method/path, extracts payload, and tries to decrypt request/response (encryptedfield) using the AES key loaded from the site. Options:--base-urlto override base URL (default: ACBUY_BASE_URL or https://www.acbuy.com)--limit Nto show only the first N items--no-decryptto skip decryption
Recommendation: use Burp exports with Base64 (export-base64-encode.xml) as the default, because they preserve the encrypted body exactly as it reaches the client and speed up analysis/decryption.