payment-sandbox
v1.0.8
Published
支付回调沙箱:解密加密参数,构造回调报文,发送到 JSON / Redis / Pulsar
Maintainers
Readme
payment-sandbox
支付回调沙箱工具。从加密的交易参数中还原订单信息,构造标准支付回调报文,JSON 输出、发送到 Redis 或 Pulsar,用于本地调试支付回调处理逻辑。
安装
npm install -g payment-sandbox快速开始
第一步:配置
# 配置解密密钥(md5Key)
payment-sandbox config key
# 配置默认接收方式(json / redis / pulsar)
payment-sandbox config mode
# 配置 Pulsar Tenant(默认 PC)
payment-sandbox config tenant
# 配置 Redis 连接
payment-sandbox config redis
# 配置 Pulsar 连接
payment-sandbox config pulsar
# 查看当前配置
payment-sandbox config配置保存在 ~/.payment-sandbox/config.json,一次配置,到处复用。所有配置项敲回车表示不修改当前值。
第二步:发送回调
payment-sandbox send交互流程:
- 粘贴加密交易参数(自动解密并预览 module / category / innerOrderNo)
- 选择回调结果(successful / failed / pending)
- 选择 isKeytop(Y / N,默认 Y)
- 选择 paymentMethod(或 random 随机)
- 选择 paymentType(或 random 随机)
- 选择 bankType(或 random 随机)
工具会按照全局配置的接收方式发送回调,并输出提取信息和发送结果。
非交互式发送(exec)
适合 AI 生成测试用例或脚本调用,所有参数通过命令行传入,--key 和 --receiver 仅对本次有效,不写入全局配置:
payment-sandbox exec --param <加密参数> \
[--key <md5Key>] [--receiver json|redis|pulsar] \
[--result successful|failed|pending] \
[--isKeytop Y|N] \
[--paymentMethod <方式>] [--paymentType <类型>] [--bankType <银行>]示例:
# 使用已配置的 key 和接收方式
payment-sandbox exec --param 43cc8a3b...
# 临时指定 key 和接收方式
payment-sandbox exec --param 43cc8a3b... --key 251fd1ef... --receiver pulsar
# 指定支付结果和方式
payment-sandbox exec --param 43cc8a3b... --result successful --paymentMethod 001 --isKeytop Y
# 输出 JSON,适合脚本消费
payment-sandbox exec --param 43cc8a3b... --receiver json命令一览
| 命令 | 说明 |
|---|---|
| payment-sandbox | 查看当前配置 |
| payment-sandbox config | 查看当前配置 |
| payment-sandbox config key | 配置 md5Key |
| payment-sandbox config mode | 配置默认接收方式 |
| payment-sandbox config tenant | 配置 Pulsar Tenant(默认 PC) |
| payment-sandbox config redis | 配置 Redis 连接 |
| payment-sandbox config pulsar | 配置 Pulsar 连接 |
| payment-sandbox send | 交互式发送支付回调 |
| payment-sandbox exec --param <密文> | 非交互式发送,配置仅当次有效 |
项目级 Profile
如果不同项目使用不同的加密规则或 topic 模板,可以在项目目录放置 payment-sandbox.json(或 profiles/project-profile.json),工具会自动加载并与默认配置合并。
参考模板:profiles/project-profile.example.json
注意:
payment-sandbox.json通常包含项目密钥,不要提交到代码仓库。
接收方式
| 方式 | 说明 |
|---|---|
| json | 将回调报文输出到终端,不发送任何网络请求,适合快速验证 |
| redis | 通过 PUBLISH / LPUSH / RPUSH 发送到指定 topic |
| pulsar | 通过 pulsar-client 发布到指定 topic |
本地接收测试
如果需要本地 HTTP 端点接收回调:
node $(npm root -g)/payment-sandbox/scripts/mock-receiver.js --port 8080 --path /callback无头模式
也可以直接传入 JSON 文件执行,适合脚本调用:
node $(npm root -g)/payment-sandbox/scripts/run-sandbox.js --input input.jsoninput.json 格式参考:examples/manual-input.json
License
ISC
