openydt-shared
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseopenydt CLI 共享基座
openydt CLI Shared Base
本技能是艾科智泊停车开放平台 CLI()的共享基础规则。所有 openydt 域技能(park / parking / trade / coupon / ticket / device / blacklist / visitor / data 等)在执行具体任务前,都应先 Read 本文件,以统一处理配置、签名、状态码、限速与安全。
openydtopenydtThis skill is the shared basic rule for the Aike Smart Parking Open Platform CLI (). All openydt domain skills (park / parking / trade / coupon / ticket / device / blacklist / visitor / data, etc.) should read this document first before executing specific tasks to unify configuration, signature, status code, rate limiting and security handling.
openydtopenydt配置 profile 与凭据
Configure Profiles and Credentials
凭据按「授权商 profile」管理,每个 profile 含 key/secret/env/sign。配置文件位于 (尊重 ),权限 0600。
~/.config/openydt-cli/config.jsonXDG_CONFIG_HOMEbash
undefinedCredentials are managed by "authorizer profiles", each profile contains key/secret/env/sign. The configuration file is located at (respects ), with permission 0600.
~/.config/openydt-cli/config.jsonXDG_CONFIG_HOMEbash
undefined新增或更新一个授权商 profile(首次使用从这里开始)
Add or update an authorizer profile (start here for first-time use)
openydt config set --profile demo --key test --secret 123456 --env test --sign v2
openydt config set --profile demo --key test --secret 123456 --env test --sign v2
列出所有 profile(secret 已脱敏),带 * 的是当前 profile
List all profiles (secret is desensitized), the one with * is the current profile
openydt config list
openydt config list
切换当前 profile
Switch current profile
openydt config use demo
openydt config use demo
打印配置文件路径
Print configuration file path
openydt config path
- `config set` 的 `--profile / --key / --secret` 必填;`--env` 默认 `test`,`--sign` 默认 `v2`。
- 第一次 `config set` 时,若尚无当前 profile,会自动把它设为当前 profile。openydt config path
- `--profile / --key / --secret` are required for `config set`; `--env` defaults to `test`, `--sign` defaults to `v2`.
- When running `config set` for the first time, if there is no current profile, it will automatically set the new profile as the current one.环境变量覆盖(适合 CI)
Environment Variable Override (Suitable for CI)
下列环境变量优先级高于 profile 中的值,可在不写配置文件的情况下临时覆盖:
| 变量 | 含义 |
|---|---|
| 选择 profile 名 |
| 覆盖 key |
| 覆盖 secret |
| 覆盖环境 test|dev|prod |
| 覆盖签名版本 v2|v3 |
优先级(从低到高):内置默认 < profile < 环境变量 < 命令行显式 flag。空值会被忽略。只要设置了 +,即使没有同名 profile 也能直接调用。
OPENYDT_KEYOPENYDT_SECRETThe following environment variables have higher priority than values in profiles, allowing temporary override without modifying the configuration file:
| Variable | Description |
|---|---|
| Select profile name |
| Override key |
| Override secret |
| Override environment test|dev|prod |
| Override signature version v2|v3 |
Priority (from lowest to highest): Built-in default < profile < environment variable < explicit command-line flag. Empty values are ignored. As long as + are set, you can directly call the interface even if there is no profile with the same name.
OPENYDT_KEYOPENYDT_SECRET全局 flag
Global Flags
所有命令通用:
| Flag | 说明 |
|---|---|
| 指定授权商 profile(默认当前 profile) |
| 指定环境(默认 test) |
| 输出格式(默认 json) |
| 签名版本(默认按 profile,否则 v2) |
| 确认执行写操作 |
| 只打印将发送的签名请求,不实际发送 |
| 输出调试信息到 stderr |
各环境 base URL:
- test →
https://openapi-test.yidianting.com.cn - dev →
https://openapi-dev.yidianting.xin - prod →
https://open.yidianting.xin
Common to all commands:
| Flag | Description |
|---|---|
| Specify authorizer profile (defaults to current profile) |
| Specify environment (defaults to test) |
| Output format (defaults to json) |
| Signature version (defaults to profile setting, otherwise v2) |
| Confirm write operation execution |
| Only print the signed request to be sent, do not actually send it |
| Output debug information to stderr |
Base URLs for each environment:
- test →
https://openapi-test.yidianting.com.cn - dev →
https://openapi-dev.yidianting.xin - prod →
https://open.yidianting.xin
认证验证
Authentication Verification
配置好后,先做一次冒烟验证(内部调用 确认凭据/签名链路可用):
getAuthParkCodesbash
openydt auth test成功输出 并列出授权车场;失败会打印 status/message/resultCode 并以对应退出码返回。
✓ 认证通过 (status=1)After configuration, perform a smoke test (internally calls to confirm the credential/signature link is available):
getAuthParkCodesbash
openydt auth testSuccess outputs and lists authorized parking lots; failure prints status/message/resultCode and returns with the corresponding exit code.
✓ Authentication passed (status=1)签名
Signature
请求路径形如 ,并带 头。时间戳 为本地时间 ,有效期 10 分钟。
POST {base}/openydt/api/v3/{cmd}?sign={sign}Authorization: base64(key:ts)tsyyyyMMddHHmmss| 版本 | 算法 | 说明 |
|---|---|---|
| v2(默认) | | 不含 body;测试环境默认可用 |
| v3 | | 含 compact 后的 body |
重要:实测测试 key 仅接受 v2;用 v3 调用测试 key 会返回「签名错误」(status=4),除非平台对该 key 专门开通了 v3。默认保持 v2 即可,仅在平台明确为该 key 开通 v3 后再用 。
--sign v3签名用的 body 与实际发送的 body 必须字节一致:CLI 会先做一次 JSON compact 再同时用于签名与发送(字符串内部空格如 会保留)。
"2019-04-16 00:11:25"Request path is in the form , with the header. Timestamp is local time , valid for 10 minutes.
POST {base}/openydt/api/v3/{cmd}?sign={sign}Authorization: base64(key:ts)tsyyyyMMddHHmmss| Version | Algorithm | Description |
|---|---|---|
| v2(default) | | Does not include body; available by default in test environment |
| v3 | | Includes compacted body |
Important: Test keys only accept v2 in practice; using v3 to call test keys will return "signature error" (status=4) unless the platform has specifically enabled v3 for that key. Keep v2 by default, only use after the platform explicitly enables v3 for the key.
--sign v3The body used for signature must be byte-consistent with the actual sent body: the CLI will first compact the JSON and use it for both signature and sending (internal spaces in strings like are retained).
"2019-04-16 00:11:25"三层命令模型
Three-tier Command Model
调用任意接口有三条路径,按优先级选择:
- 域一等命令(首选):,参数已结构化为 flag,最易用。例如
openydt <域> <命令>、openydt park get-auth-park-codes。当前内置域:openydt parking <子命令>。blacklist coupon data device park parking redlist ticket trade visitor - 通用兜底:,对任意业务编码 cmd 自动签名并 POST,覆盖任何可调用接口。
openydt api <cmd> --body '{...}'bashopenydt api getParkFee --body '{"carCode":"粤EJW962"}' openydt api getAuthParkCodes echo '{"parkCode":"PTD2YBBZ"}' | openydt api getParkOnSiteCar --body-file -与--body互斥;--body-file从 stdin 读取。--body-file - - schema 探索(若有):用于发现接口与字段,再回到 ① 或 ②。
There are three paths to call any interface, selected by priority:
- Domain First-class Command(Preferred): , parameters are structured as flags, most user-friendly. For example
openydt <domain> <command>,openydt park get-auth-park-codes. Currently built-in domains:openydt parking <subcommand>.blacklist coupon data device park parking redlist ticket trade visitor - General Fallback: , automatically signs and POSTs for any business code cmd, covering any callable interface.
openydt api <cmd> --body '{...}'bashopenydt api getParkFee --body '{"carCode":"粤EJW962"}' openydt api getAuthParkCodes echo '{"parkCode":"PTD2YBBZ"}' | openydt api getParkOnSiteCar --body-file -and--bodyare mutually exclusive;--body-filereads from stdin.--body-file - - Schema Exploration(if available): Used to discover interfaces and fields, then return to ① or ②.
响应包络与状态码
Response Envelope and Status Codes
平台统一包络:。
{"data":..., "message":"...", "resultCode":N, "status":N}status| status | 含义 |
|---|---|
| 1 | 业务成功 |
| 2 | 业务失败(看 resultCode) |
| 3 | 系统异常 |
| 4 | 签名错误 |
| 5 | key 错误 |
| 6 | 未授权 |
| 7 | 请求参数不完整 |
当 时看 (常见业务码,源自 ):
status == 2resultCodeinternal/client/codes.go| resultCode | 含义 |
|---|---|
| 901 | 系统发生异常 |
| 902 | 远程服务器未响应 |
| 903 | 运营商不存在 |
| 904 | 停车场不存在 |
| 905 | 未找到在场车辆 |
| 906 | 账单不存在 |
| 907 | 账单已同步 |
| 908 | 其它错误 |
| 909 | 请求参数错误 |
| 910 | 找不到授权商下面的停车场 |
| 911 | 无权限操作该停车场 |
| 912 | 查费已超时,请重新查费 |
| 1801 | 找不到指定车辆 |
The platform uses a unified envelope: .
{"data":..., "message":"...", "resultCode":N, "status":N}Meaning of :
status| status | Meaning |
|---|---|
| 1 | Business success |
| 2 | Business failure (check resultCode) |
| 3 | System exception |
| 4 | Signature error |
| 5 | Key error |
| 6 | Unauthorized |
| 7 | Incomplete request parameters |
When , check (common business codes, from ):
status == 2resultCodeinternal/client/codes.go| resultCode | Meaning |
|---|---|
| 901 | System exception occurred |
| 902 | Remote server did not respond |
| 903 | Operator does not exist |
| 904 | Parking lot does not exist |
| 905 | No on-site vehicle found |
| 906 | Bill does not exist |
| 907 | Bill has been synchronized |
| 908 | Other errors |
| 909 | Request parameter error |
| 910 | No parking lot found under the authorizer |
| 911 | No permission to operate this parking lot |
| 912 | Fee inquiry timed out, please retry |
| 1801 | Specified vehicle not found |
进程退出码
Process Exit Codes
| 退出码 | 含义 |
|---|---|
| 0 | 成功(status=1) |
| 1 | 业务失败(status=2 或其它非成功) |
| 2 | 参数错误(用法错误) |
| 4 | 鉴权失败(status=4 签名 / 5 key / 6 未授权) |
| 5 | 网络/传输失败 |
| Exit Code | Meaning |
|---|---|
| 0 | Success(status=1) |
| 1 | Business failure(status=2 or other non-success status) |
| 2 | Parameter error(usage error) |
| 4 | Authentication failure(status=4 signature /5 key /6 unauthorized) |
| 5 | Network/transmission failure |
限速与重试
Rate Limiting and Retry
- 授权车场数 < 60 的授权商:限速 300 次/分。批量调用时自行节流,避免触发 429。
- 客户端已内置重试 + 指数退避(约 400ms 起,带抖动,默认最多重试 3 次)。
- 遇网关偶发 404、连接重置、429/502/503/504 会自动重试;非包络的 HTML 错误页不重试。
- 是业务态,需按提示重新查费,不是网络重试范畴。
查费超时(resultCode 912)
- Authorizers with fewer than 60 authorized parking lots: rate limit 300 times/minute. Throttle batch calls to avoid triggering 429.
- The client has built-in retry + exponential backoff(starts at about 400ms, with jitter, maximum 3 retries by default).
- Automatically retries on occasional gateway 404, connection reset, 429/502/503/504; does not retry non-envelope HTML error pages.
- "Fee inquiry timed out(resultCode 912)" is a business state, need to retry as prompted, not within network retry scope.
安全规则
Security Rules
- 写操作必须 :缴费、开闸、发券、开通月票、加/移黑名单等任何会改变平台状态的操作,必须显式带
--yes才会执行,避免误操作。--yes - 先 预览:危险或不确定的请求先用
--dry-run查看将发送的签名请求(URL/sign/ts/body),确认无误后再去掉。--dry-run - 不要明文输出密钥:不要把 key/secret 打印到终端或日志;已对 secret 脱敏。
config list - 默认在 环境验证;切到
test前务必与用户确认。prod
- Write operations require : Any operation that changes the platform state, such as payment, gate opening, coupon issuance, monthly pass activation, adding/removing from blacklist, etc., must explicitly include
--yesto execute, avoiding misoperations.--yes - Preview with first: Use
--dry-runfor dangerous or uncertain requests to view the signed request to be sent(URL/sign/ts/body), then remove it after confirmation.--dry-run - Do not output keys in plain text: Do not print key/secret to the terminal or logs; has desensitized the secret.
config list - Verify in environment by default; be sure to confirm with users before switching to
test.prod
测试车场(仅测试环境)
Test Parking Lots (Test Environment Only)
| parkCode | 用途 |
|---|---|
| 可查费,配套测试车牌 |
| 有存量数据,适合查记录 / 查在场车辆 |
示例:
bash
openydt api getParkFee --body '{"parkCode":"1ZS7H5PQH9","carCode":"粤EJW962"}'
openydt api getParkOnSiteCar --body '{"parkCode":"PTD2YBBZ"}'| parkCode | Purpose |
|---|---|
| Fee inquiry available, matching test license plate |
| Has historical data, suitable for querying records / on-site vehicles |
Examples:
bash
openydt api getParkFee --body '{"parkCode":"1ZS7H5PQH9","carCode":"粤EJW962"}'
openydt api getParkOnSiteCar --body '{"parkCode":"PTD2YBBZ"}'