@alipay/alipay-aipay 1.7.0 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/dist/commands/install-current.js +15 -7
- package/dist/commands/install.js +20 -16
- package/dist/commands/uninstall.js +8 -3
- package/dist/commands/update.js +34 -16
- package/dist/index.js +10 -4
- package/dist/utils/channels.js +67 -0
- package/dist/utils/config.js +15 -11
- package/dist/utils/file.js +23 -10
- package/dist/utils/npm.js +19 -33
- package/package.json +8 -3
- package/skill/SKILL.md +2 -0
- package/skill/references/normal/json/release-channel.json +1 -0
- package/skill/references/normal/scripts/self_update.mjs +62 -17
- package/skill/references/normal/self-update.md +3 -1
- package/skill-pre/SKILL.md +65 -0
- package/skill-pre/VERSION +1 -0
- package/skill-pre/references/integration/flow.md +602 -0
- package/skill-pre/references/integration/modules/alipay-sdk-reminder.md +281 -0
- package/skill-pre/references/integration/modules/checklist.md +154 -0
- package/skill-pre/references/integration/modules/code-examples/csharp/1-/351/200/232/347/224/250/346/216/245/345/217/243//345/274/202/346/255/245/351/200/232/347/237/245/345/244/204/347/220/206/344/273/243/347/240/201/347/244/272/344/276/213.md +199 -0
- package/skill-pre/references/integration/modules/code-examples/csharp/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/345/205/263/351/227/255/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +68 -0
- package/skill-pre/references/integration/modules/code-examples/csharp/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +83 -0
- package/skill-pre/references/integration/modules/code-examples/csharp/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +80 -0
- package/skill-pre/references/integration/modules/code-examples/csharp/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +73 -0
- package/skill-pre/references/integration/modules/code-examples/csharp/2-/347/275/221/347/253/231/346/224/257/344/273/230//347/273/237/344/270/200/346/224/266/345/215/225/344/270/213/345/215/225/345/271/266/346/224/257/344/273/230/351/241/265/351/235/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +62 -0
- package/skill-pre/references/integration/modules/code-examples/csharp/3-APP/346/224/257/344/273/230/APP/346/224/257/344/273/230/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +132 -0
- package/skill-pre/references/integration/modules/code-examples/csharp/4-/346/214/211/351/207/217/344/273/230/350/264/271/A2MPaymentDemo.md +640 -0
- package/skill-pre/references/integration/modules/code-examples/java/1-/351/200/232/347/224/250/346/216/245/345/217/243//345/274/202/346/255/245/351/200/232/347/237/245/345/244/204/347/220/206/344/273/243/347/240/201/347/244/272/344/276/213.md +184 -0
- package/skill-pre/references/integration/modules/code-examples/java/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/345/205/263/351/227/255/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +72 -0
- package/skill-pre/references/integration/modules/code-examples/java/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +96 -0
- package/skill-pre/references/integration/modules/code-examples/java/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +81 -0
- package/skill-pre/references/integration/modules/code-examples/java/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +77 -0
- package/skill-pre/references/integration/modules/code-examples/java/2-/347/275/221/347/253/231/346/224/257/344/273/230//347/273/237/344/270/200/346/224/266/345/215/225/344/270/213/345/215/225/345/271/266/346/224/257/344/273/230/351/241/265/351/235/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +69 -0
- package/skill-pre/references/integration/modules/code-examples/java/3-APP/346/224/257/344/273/230/APP/346/224/257/344/273/230/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +138 -0
- package/skill-pre/references/integration/modules/code-examples/java/4-/346/214/211/351/207/217/344/273/230/350/264/271/A2MPaymentDemoController.md +623 -0
- package/skill-pre/references/integration/modules/code-examples/nodejs/1-/351/200/232/347/224/250/346/216/245/345/217/243//345/274/202/346/255/245/351/200/232/347/237/245/345/244/204/347/220/206/344/273/243/347/240/201/347/244/272/344/276/213.md +135 -0
- package/skill-pre/references/integration/modules/code-examples/nodejs/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/345/205/263/351/227/255/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +51 -0
- package/skill-pre/references/integration/modules/code-examples/nodejs/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +63 -0
- package/skill-pre/references/integration/modules/code-examples/nodejs/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +59 -0
- package/skill-pre/references/integration/modules/code-examples/nodejs/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +54 -0
- package/skill-pre/references/integration/modules/code-examples/nodejs/2-/347/275/221/347/253/231/346/224/257/344/273/230//347/273/237/344/270/200/346/224/266/345/215/225/344/270/213/345/215/225/345/271/266/346/224/257/344/273/230/351/241/265/351/235/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +84 -0
- package/skill-pre/references/integration/modules/code-examples/nodejs/3-APP/346/224/257/344/273/230/APP/346/224/257/344/273/230/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +71 -0
- package/skill-pre/references/integration/modules/code-examples/nodejs/4-/346/214/211/351/207/217/344/273/230/350/264/271/A2MPaymentDemo.md +498 -0
- package/skill-pre/references/integration/modules/code-examples/php/1-/351/200/232/347/224/250/346/216/245/345/217/243//345/274/202/346/255/245/351/200/232/347/237/245/345/244/204/347/220/206/344/273/243/347/240/201/347/244/272/344/276/213.md +157 -0
- package/skill-pre/references/integration/modules/code-examples/php/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/345/205/263/351/227/255/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +59 -0
- package/skill-pre/references/integration/modules/code-examples/php/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +73 -0
- package/skill-pre/references/integration/modules/code-examples/php/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +69 -0
- package/skill-pre/references/integration/modules/code-examples/php/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +65 -0
- package/skill-pre/references/integration/modules/code-examples/php/2-/347/275/221/347/253/231/346/224/257/344/273/230//347/273/237/344/270/200/346/224/266/345/215/225/344/270/213/345/215/225/345/271/266/346/224/257/344/273/230/351/241/265/351/235/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +59 -0
- package/skill-pre/references/integration/modules/code-examples/php/3-APP/346/224/257/344/273/230/APP/346/224/257/344/273/230/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +110 -0
- package/skill-pre/references/integration/modules/code-examples/php/4-/346/214/211/351/207/217/344/273/230/350/264/271/A2MPaymentDemo.md +806 -0
- package/skill-pre/references/integration/modules/code-examples/python/1-/351/200/232/347/224/250/346/216/245/345/217/243//345/274/202/346/255/245/351/200/232/347/237/245/345/244/204/347/220/206/344/273/243/347/240/201/347/244/272/344/276/213.md +128 -0
- package/skill-pre/references/integration/modules/code-examples/python/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/345/205/263/351/227/255/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +57 -0
- package/skill-pre/references/integration/modules/code-examples/python/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +70 -0
- package/skill-pre/references/integration/modules/code-examples/python/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +65 -0
- package/skill-pre/references/integration/modules/code-examples/python/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +62 -0
- package/skill-pre/references/integration/modules/code-examples/python/2-/347/275/221/347/253/231/346/224/257/344/273/230//347/273/237/344/270/200/346/224/266/345/215/225/344/270/213/345/215/225/345/271/266/346/224/257/344/273/230/351/241/265/351/235/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +51 -0
- package/skill-pre/references/integration/modules/code-examples/python/3-APP/346/224/257/344/273/230/APP/346/224/257/344/273/230/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +47 -0
- package/skill-pre/references/integration/modules/code-examples/python/4-/346/214/211/351/207/217/344/273/230/350/264/271/A2MPaymentDemo.md +541 -0
- package/skill-pre/references/integration/modules/interface-contract/aipay-interface-contract.md +52 -0
- package/skill-pre/references/integration/modules/interface-contract/apppay-interface-contract.md +45 -0
- package/skill-pre/references/integration/modules/interface-contract/common-trade-contract.md +42 -0
- package/skill-pre/references/integration/modules/interface-contract/notify-url-contract.md +68 -0
- package/skill-pre/references/integration/modules/interface-contract/webpay-interface-contract.md +44 -0
- package/skill-pre/references/integration/modules/interface-guide.md +61 -0
- package/skill-pre/references/integration/modules/product-decision.md +73 -0
- package/skill-pre/references/integration/modules/sandbox/a2m-sandbox-test.md +235 -0
- package/skill-pre/references/integration/modules/sandbox/alipay-sandbox-tool.md +142 -0
- package/skill-pre/references/integration/modules/sandbox/sandbox-setup-guide.md +239 -0
- package/skill-pre/references/integration/modules/scripts/local_402_sandbox_pay.py +900 -0
- package/skill-pre/references/integration/modules/scripts/sandbox_config.sh +347 -0
- package/skill-pre/references/integration/modules/troubleshooting-flow.md +28 -0
- package/skill-pre/references/normal/alipay-cli-env.md +169 -0
- package/skill-pre/references/normal/conversation-telemetry.md +101 -0
- package/skill-pre/references/normal/full-process-routing.md +92 -0
- package/skill-pre/references/normal/integration-worker.md +90 -0
- package/skill-pre/references/normal/json/customer-messages.json +1 -0
- package/skill-pre/references/normal/json/managed-jq-assets.json +1 -0
- package/skill-pre/references/normal/json/policy-rules.json +1 -0
- package/skill-pre/references/normal/json/release-channel.json +1 -0
- package/skill-pre/references/normal/rejection-guide.md +41 -0
- package/skill-pre/references/normal/scripts/agent_platform.mjs +43 -0
- package/skill-pre/references/normal/scripts/alipay_cli_env.mjs +34 -0
- package/skill-pre/references/normal/scripts/alipay_cli_env.sh +55 -0
- package/skill-pre/references/normal/scripts/alipay_cli_refresh.mjs +129 -0
- package/skill-pre/references/normal/scripts/auth_runtime_runner.mjs +60 -0
- package/skill-pre/references/normal/scripts/checklist_sections.mjs +43 -0
- package/skill-pre/references/normal/scripts/common.sh +365 -0
- package/skill-pre/references/normal/scripts/conversation_telemetry.mjs +105 -0
- package/skill-pre/references/normal/scripts/detect_dev_tool.sh +79 -0
- package/skill-pre/references/normal/scripts/flow_loader.mjs +237 -0
- package/skill-pre/references/normal/scripts/integration_context_runner.mjs +151 -0
- package/skill-pre/references/normal/scripts/integration_message_runner.mjs +1456 -0
- package/skill-pre/references/normal/scripts/interaction_reply.mjs +140 -0
- package/skill-pre/references/normal/scripts/managed_jq.mjs +215 -0
- package/skill-pre/references/normal/scripts/onboarding_discovery_runner.mjs +387 -0
- package/skill-pre/references/normal/scripts/onboarding_message_runner.mjs +1425 -0
- package/skill-pre/references/normal/scripts/onboarding_recovery_runner.mjs +100 -0
- package/skill-pre/references/normal/scripts/open_official_url.sh +205 -0
- package/skill-pre/references/normal/scripts/platform_compat.mjs +42 -0
- package/skill-pre/references/normal/scripts/preview_runtime.mjs +151 -0
- package/skill-pre/references/normal/scripts/project_route_inspector.sh +132 -0
- package/skill-pre/references/normal/scripts/python_script_runner.mjs +58 -0
- package/skill-pre/references/normal/scripts/render_customer_message.mjs +1792 -0
- package/skill-pre/references/normal/scripts/runtime.mjs +271 -0
- package/skill-pre/references/normal/scripts/self_update.mjs +376 -0
- package/skill-pre/references/normal/scripts/telemetry.mjs +2102 -0
- package/skill-pre/references/normal/self-update.md +7 -0
- package/skill-pre/references/normal/telemetry.md +70 -0
- package/skill-pre/references/onboarding/assets/keygen.html +927 -0
- package/skill-pre/references/onboarding/flow.md +607 -0
- package/skill-pre/references/onboarding/modules/app-release.md +90 -0
- package/skill-pre/references/onboarding/modules/authorization.md +43 -0
- package/skill-pre/references/onboarding/modules/error-handling.md +62 -0
- package/skill-pre/references/onboarding/modules/product-sign.md +49 -0
- package/skill-pre/references/onboarding/modules/scripts/app.sh +1485 -0
- package/skill-pre/references/onboarding/modules/scripts/ar_sign_apply.sh +331 -0
- package/skill-pre/references/onboarding/modules/scripts/auth.sh +1040 -0
- package/skill-pre/references/onboarding/modules/scripts/download_key_tool.sh +4 -0
- package/skill-pre/references/onboarding/modules/scripts/error_handler.sh +841 -0
- package/skill-pre/references/onboarding/modules/scripts/mcc.sh +1085 -0
- package/skill-pre/references/onboarding/modules/scripts/network_retry.sh +135 -0
- package/skill-pre/references/onboarding/modules/scripts/query_sign_status.sh +105 -0
- package/skill-pre/references/onboarding/modules/scripts/service.sh +528 -0
- package/skill-pre/references/onboarding/modules/scripts/sign_status_parser.sh +58 -0
- package/skill-pre/references/onboarding/modules/scripts/upload_screenshots.sh +208 -0
- package/skill-pre/references/onboarding/modules/scripts/upload_special_license.sh +195 -0
- package/skill-pre/references/onboarding/modules/service-registration.md +40 -0
- package/skill-pre/references/runtime-entry.md +99 -0
- package/dist/commands/install-current.d.ts +0 -4
- package/dist/commands/install-current.d.ts.map +0 -1
- package/dist/commands/install-current.js.map +0 -1
- package/dist/commands/install.d.ts +0 -10
- package/dist/commands/install.d.ts.map +0 -1
- package/dist/commands/install.js.map +0 -1
- package/dist/commands/prepare-tools.d.ts +0 -5
- package/dist/commands/prepare-tools.d.ts.map +0 -1
- package/dist/commands/prepare-tools.js.map +0 -1
- package/dist/commands/uninstall.d.ts +0 -10
- package/dist/commands/uninstall.d.ts.map +0 -1
- package/dist/commands/uninstall.js.map +0 -1
- package/dist/commands/update.d.ts +0 -10
- package/dist/commands/update.d.ts.map +0 -1
- package/dist/commands/update.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types.d.ts +0 -42
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/alipay-cli.d.ts +0 -20
- package/dist/utils/alipay-cli.d.ts.map +0 -1
- package/dist/utils/alipay-cli.js.map +0 -1
- package/dist/utils/config.d.ts +0 -52
- package/dist/utils/config.d.ts.map +0 -1
- package/dist/utils/config.js.map +0 -1
- package/dist/utils/file.d.ts +0 -77
- package/dist/utils/file.d.ts.map +0 -1
- package/dist/utils/file.js.map +0 -1
- package/dist/utils/jq.d.ts +0 -17
- package/dist/utils/jq.d.ts.map +0 -1
- package/dist/utils/jq.js.map +0 -1
- package/dist/utils/npm.d.ts +0 -17
- package/dist/utils/npm.d.ts.map +0 -1
- package/dist/utils/npm.js.map +0 -1
- package/dist/utils/shell.d.ts +0 -24
- package/dist/utils/shell.d.ts.map +0 -1
- package/dist/utils/shell.js.map +0 -1
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#=============================================================================
|
|
3
|
+
# 脚本名称: service.sh
|
|
4
|
+
# 功能描述: 服务市场注册 - 查询已有服务 + 创建/修改服务
|
|
5
|
+
# 调用位置: list 用于 Step 3.1 前置资源查询;save/validate 用于 Step 5.2 服务市场注册
|
|
6
|
+
# 调用前置: 脚本通过 error_handler.sh 间接初始化 DEV_TOOL_NAME/PLATFORM_ID;必要时可用 DEV_TOOL_NAME 环境变量覆盖
|
|
7
|
+
# 用法:
|
|
8
|
+
# service list - 查询已有服务列表
|
|
9
|
+
# service save --name <n> --desc <d> --url <u> --pricing <p> --schema <json> [--service-id <id>]
|
|
10
|
+
# service validate --name <n> --desc <d> --url <u> --pricing <p> --schema <json>
|
|
11
|
+
# 返回值:
|
|
12
|
+
# list: stdout 成功时为空;stderr 输出带统一内部前缀的候选 JSON、SERVICE_CANDIDATE_ID 和 FLOW
|
|
13
|
+
# save: stderr 输出实际解析到的 SERVICE_ID(不接受 Agent 自填)
|
|
14
|
+
# validate: stderr 输出规范化结果(退出码 0=通过, 1=失败)
|
|
15
|
+
#=============================================================================
|
|
16
|
+
|
|
17
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
18
|
+
CANDIDATE_RUNNER="${SCRIPT_DIR}/../../../normal/scripts/onboarding_message_runner.mjs"
|
|
19
|
+
|
|
20
|
+
# 一次性 source error_handler(含 unwrap_mcp)
|
|
21
|
+
if [ -f "${SCRIPT_DIR}/error_handler.sh" ]; then
|
|
22
|
+
source "${SCRIPT_DIR}/error_handler.sh"
|
|
23
|
+
else
|
|
24
|
+
echo "❌ 缺少错误处理脚本: ${SCRIPT_DIR}/error_handler.sh"
|
|
25
|
+
exit 1
|
|
26
|
+
fi
|
|
27
|
+
source "${SCRIPT_DIR}/network_retry.sh"
|
|
28
|
+
|
|
29
|
+
require_command jq || exit 1
|
|
30
|
+
require_command alipay-cli || exit 1
|
|
31
|
+
require_command awk || exit 1
|
|
32
|
+
require_command node || exit 1
|
|
33
|
+
init_alipay_cli_product aipay || exit 1
|
|
34
|
+
|
|
35
|
+
SERVICE_LIST_PAGE_LIMIT=10
|
|
36
|
+
SERVICE_CREATE_LIMIT=10
|
|
37
|
+
|
|
38
|
+
normalize_service_pricing() {
|
|
39
|
+
local raw="$1"
|
|
40
|
+
local pricing_pattern='^ *([0-9]+([.][0-9]+)?) *(元(/次)?)? *$'
|
|
41
|
+
SERVICE_PRICING_NORMALIZED=""
|
|
42
|
+
case "$raw" in *$'\n'*|*$'\r'*|*$'\t'*) return 1 ;; esac
|
|
43
|
+
if [[ "$raw" =~ $pricing_pattern ]]; then
|
|
44
|
+
SERVICE_PRICING_NORMALIZED="${BASH_REMATCH[1]}"
|
|
45
|
+
return 0
|
|
46
|
+
fi
|
|
47
|
+
return 1
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
validate_service_fields() {
|
|
51
|
+
# 1. 服务名称:长度 1-50 字符
|
|
52
|
+
if [ -z "$SERVICE_NAME" ] || [ ${#SERVICE_NAME} -gt 50 ]; then
|
|
53
|
+
echo "❌ 服务名称长度需在 1-50 字符之间(当前长度: ${#SERVICE_NAME})"
|
|
54
|
+
exit 1
|
|
55
|
+
fi
|
|
56
|
+
|
|
57
|
+
# 2. 服务描述:长度 1-500 字符
|
|
58
|
+
if [ -z "$SERVICE_DESC" ] || [ ${#SERVICE_DESC} -gt 500 ]; then
|
|
59
|
+
echo "❌ 服务描述长度需在 1-500 字符之间(当前长度: ${#SERVICE_DESC})"
|
|
60
|
+
exit 1
|
|
61
|
+
fi
|
|
62
|
+
|
|
63
|
+
# 3. 服务地址:有效 URL
|
|
64
|
+
if [ -z "$RESOURCE_URL" ] || ! [[ "$RESOURCE_URL" =~ ^https?:// ]]; then
|
|
65
|
+
echo "❌ 请提供有效的 URL 地址(以 http:// 或 https:// 开头)"
|
|
66
|
+
exit 1
|
|
67
|
+
fi
|
|
68
|
+
|
|
69
|
+
# 4. 服务单价:提交值统一规范化为纯数字,模板负责追加“元/次”。
|
|
70
|
+
if [ -z "$PRICING" ] || ! normalize_service_pricing "$PRICING"; then
|
|
71
|
+
echo "❌ 服务单价格式不正确,请输入金额(如 0.03、0.03元或 0.03 元/次)"
|
|
72
|
+
exit 1
|
|
73
|
+
fi
|
|
74
|
+
PRICING="$SERVICE_PRICING_NORMALIZED"
|
|
75
|
+
PRICING_VALID=$(awk -v p="$PRICING" 'BEGIN { if (p + 0 >= 0.01) print "true"; else print "false" }')
|
|
76
|
+
if [ "$PRICING_VALID" = "false" ]; then
|
|
77
|
+
echo "❌ 服务单价最低为 0.01 元"
|
|
78
|
+
exit 1
|
|
79
|
+
fi
|
|
80
|
+
|
|
81
|
+
# 5. schemaUrl 在本流程中承载序列化后的 JSON 请求示例,不是 URL。
|
|
82
|
+
# CLI 接收原始 JSON;save 分支通过 jq --arg 将其安全写入字符串字段。
|
|
83
|
+
if [ -z "$SCHEMA_URL" ] || ! echo "$SCHEMA_URL" | jq . >/dev/null 2>&1; then
|
|
84
|
+
echo "❌ 请提供有效的 JSON 格式请求示例"
|
|
85
|
+
exit 1
|
|
86
|
+
fi
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
# ─── service list: 查询已有服务 ──────────────────────────────────────────────
|
|
90
|
+
fetch_service_page() {
|
|
91
|
+
local OFFSET="$1"
|
|
92
|
+
local LIMIT="$2"
|
|
93
|
+
local REQUEST_JSON RESULT BUSINESS BUSINESS_CODE BUSINESS_MESSAGE
|
|
94
|
+
|
|
95
|
+
REQUEST_JSON=$(jq -n \
|
|
96
|
+
--argjson limit "$LIMIT" \
|
|
97
|
+
--argjson offset "$OFFSET" \
|
|
98
|
+
'{request:{limit:$limit,offset:$offset}}')
|
|
99
|
+
|
|
100
|
+
require_alipay_cli_local_state_access_or_emit || return "$?"
|
|
101
|
+
export PLATFORM="${DEV_TOOL_NAME}" PLATFORM_ID="${PLATFORM_ID:-}"
|
|
102
|
+
run_network_retry RESULT read service_list_page -- alipay-cli mcp call a2a-pay-service.discoverBazaarServicesForMcp \
|
|
103
|
+
-d "$REQUEST_JSON" \
|
|
104
|
+
--json
|
|
105
|
+
RETRY_RC=$?
|
|
106
|
+
if [ "$RETRY_RC" -eq "${ALIPAY_CLI_LOCAL_STATE_PERMISSION_EXIT_CODE:-77}" ]; then
|
|
107
|
+
return "$RETRY_RC"
|
|
108
|
+
fi
|
|
109
|
+
if [ "$RETRY_RC" -ne 0 ]; then
|
|
110
|
+
echo "❌ 服务列表当前分页因网络或服务异常在自动重试两次后仍未恢复"
|
|
111
|
+
return 1
|
|
112
|
+
fi
|
|
113
|
+
|
|
114
|
+
if ! handle_error "$RESULT" "MCP_AUTHENTICATED_CALL"; then
|
|
115
|
+
return 1
|
|
116
|
+
fi
|
|
117
|
+
|
|
118
|
+
BUSINESS=$(unwrap_mcp "$RESULT")
|
|
119
|
+
|
|
120
|
+
BUSINESS_CODE=$(echo "$BUSINESS" | jq -r 'if has("code") then (.code | tostring) else "" end' 2>/dev/null)
|
|
121
|
+
if [ -n "$BUSINESS_CODE" ] && [ "$BUSINESS_CODE" != "10000" ]; then
|
|
122
|
+
BUSINESS_MESSAGE=$(echo "$BUSINESS" | jq -r '
|
|
123
|
+
.subMsg // .data.subMsg // .msg // .data.msg // "未知错误"
|
|
124
|
+
' 2>/dev/null)
|
|
125
|
+
BUSINESS_MESSAGE=$(sanitize_customer_error_text "$BUSINESS_MESSAGE")
|
|
126
|
+
echo "❌ 查询服务列表失败: ${BUSINESS_CODE} / ${BUSINESS_MESSAGE}"
|
|
127
|
+
return 1
|
|
128
|
+
fi
|
|
129
|
+
|
|
130
|
+
PAGE_FORMAT=$(echo "$BUSINESS" | jq -r '
|
|
131
|
+
if ((.code | tostring) == "10000") and
|
|
132
|
+
((.data | type) == "object") and
|
|
133
|
+
((.data.items | type) == "array") and
|
|
134
|
+
((.data.pagination | type) == "object") and
|
|
135
|
+
((.data.pagination.total | type) == "number") and
|
|
136
|
+
(.data.pagination.total >= 0) and
|
|
137
|
+
((.data.pagination.total | floor) == .data.pagination.total) and
|
|
138
|
+
((.data.pagination.offset | type) == "number") and
|
|
139
|
+
(.data.pagination.offset >= 0) and
|
|
140
|
+
((.data.pagination.offset | floor) == .data.pagination.offset) then
|
|
141
|
+
"current"
|
|
142
|
+
elif (.success == true) and
|
|
143
|
+
((.resultObj | type) == "object") and
|
|
144
|
+
((.resultObj.serviceList | type) == "array") then
|
|
145
|
+
"legacy"
|
|
146
|
+
else
|
|
147
|
+
"invalid"
|
|
148
|
+
end
|
|
149
|
+
' 2>/dev/null)
|
|
150
|
+
|
|
151
|
+
case "$PAGE_FORMAT" in
|
|
152
|
+
current)
|
|
153
|
+
PAGE_ITEMS=$(echo "$BUSINESS" | jq -c '.data.items')
|
|
154
|
+
PAGE_TOTAL=$(echo "$BUSINESS" | jq -r '.data.pagination.total')
|
|
155
|
+
PAGE_OFFSET=$(echo "$BUSINESS" | jq -r '.data.pagination.offset')
|
|
156
|
+
;;
|
|
157
|
+
legacy)
|
|
158
|
+
PAGE_ITEMS=$(echo "$BUSINESS" | jq -c '.resultObj.serviceList')
|
|
159
|
+
PAGE_TOTAL=$(echo "$PAGE_ITEMS" | jq 'length')
|
|
160
|
+
PAGE_OFFSET=0
|
|
161
|
+
;;
|
|
162
|
+
*)
|
|
163
|
+
echo "❌ 服务列表返回结构异常,无法解析 data.items 或兼容的 resultObj.serviceList"
|
|
164
|
+
return 1
|
|
165
|
+
;;
|
|
166
|
+
esac
|
|
167
|
+
|
|
168
|
+
if [ -z "$PAGE_ITEMS" ] || ! echo "$PAGE_ITEMS" | jq -e 'type == "array"' >/dev/null 2>&1; then
|
|
169
|
+
echo "❌ 服务列表返回结构异常,列表字段不是数组"
|
|
170
|
+
return 1
|
|
171
|
+
fi
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
fetch_service_list() {
|
|
175
|
+
local LIMIT="$SERVICE_LIST_PAGE_LIMIT"
|
|
176
|
+
local OFFSET=0
|
|
177
|
+
local EXPECTED_TOTAL=""
|
|
178
|
+
local PAGE_COUNT
|
|
179
|
+
|
|
180
|
+
SERVICE_LIST='[]'
|
|
181
|
+
|
|
182
|
+
while true; do
|
|
183
|
+
fetch_service_page "$OFFSET" "$LIMIT"
|
|
184
|
+
FETCH_RC=$?
|
|
185
|
+
if [ "$FETCH_RC" -ne 0 ]; then
|
|
186
|
+
return "$FETCH_RC"
|
|
187
|
+
fi
|
|
188
|
+
|
|
189
|
+
if [ "$PAGE_FORMAT" = "legacy" ]; then
|
|
190
|
+
SERVICE_LIST="$PAGE_ITEMS"
|
|
191
|
+
break
|
|
192
|
+
fi
|
|
193
|
+
|
|
194
|
+
if [ "$PAGE_OFFSET" -ne "$OFFSET" ]; then
|
|
195
|
+
echo "❌ 服务列表分页返回异常:期望 offset=${OFFSET},实际 offset=${PAGE_OFFSET}"
|
|
196
|
+
return 1
|
|
197
|
+
fi
|
|
198
|
+
|
|
199
|
+
if [ -z "$EXPECTED_TOTAL" ]; then
|
|
200
|
+
EXPECTED_TOTAL="$PAGE_TOTAL"
|
|
201
|
+
elif [ "$PAGE_TOTAL" -ne "$EXPECTED_TOTAL" ]; then
|
|
202
|
+
echo "❌ 服务列表分页返回异常:分页过程中 total 发生变化"
|
|
203
|
+
return 1
|
|
204
|
+
fi
|
|
205
|
+
|
|
206
|
+
SERVICE_LIST=$(jq -cn \
|
|
207
|
+
--argjson existing "$SERVICE_LIST" \
|
|
208
|
+
--argjson page "$PAGE_ITEMS" \
|
|
209
|
+
'$existing + $page')
|
|
210
|
+
SERVICE_COUNT=$(echo "$SERVICE_LIST" | jq 'length')
|
|
211
|
+
|
|
212
|
+
if [ "$SERVICE_COUNT" -gt "$EXPECTED_TOTAL" ]; then
|
|
213
|
+
echo "❌ 服务列表分页返回异常:已返回数量超过 total"
|
|
214
|
+
return 1
|
|
215
|
+
fi
|
|
216
|
+
if [ "$SERVICE_COUNT" -eq "$EXPECTED_TOTAL" ]; then
|
|
217
|
+
break
|
|
218
|
+
fi
|
|
219
|
+
|
|
220
|
+
PAGE_COUNT=$(echo "$PAGE_ITEMS" | jq 'length')
|
|
221
|
+
if [ "$PAGE_COUNT" -eq 0 ]; then
|
|
222
|
+
echo "❌ 服务列表分页返回异常:尚有未返回数据但当前页为空"
|
|
223
|
+
return 1
|
|
224
|
+
fi
|
|
225
|
+
OFFSET="$SERVICE_COUNT"
|
|
226
|
+
done
|
|
227
|
+
|
|
228
|
+
if ! echo "$SERVICE_LIST" | jq -e '
|
|
229
|
+
all(.[];
|
|
230
|
+
((.serviceId | type) == "string") and
|
|
231
|
+
(.serviceId | length > 0) and
|
|
232
|
+
((.serviceId | test("[\u0000-\u001f\u007f]") | not))
|
|
233
|
+
)
|
|
234
|
+
' >/dev/null 2>&1; then
|
|
235
|
+
echo "❌ 服务列表返回结构异常:候选 serviceId 缺失或包含控制字符"
|
|
236
|
+
return 1
|
|
237
|
+
fi
|
|
238
|
+
|
|
239
|
+
SERVICE_COUNT=$(echo "$SERVICE_LIST" | jq 'length')
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
service_list() {
|
|
243
|
+
fetch_service_list
|
|
244
|
+
FETCH_RC=$?
|
|
245
|
+
if [ "$FETCH_RC" -ne 0 ]; then
|
|
246
|
+
exit "$FETCH_RC"
|
|
247
|
+
fi
|
|
248
|
+
|
|
249
|
+
SERVICE_CANDIDATES=$(echo "$SERVICE_LIST" | jq -c '[.[] | {
|
|
250
|
+
serviceId: .serviceId,
|
|
251
|
+
serviceName: ((.serviceName // "未知") | tostring),
|
|
252
|
+
serviceDesc: ((.serviceDesc // "无描述") | tostring),
|
|
253
|
+
pricing: ((.metadata.pricing // .pricing // "未知") | tostring),
|
|
254
|
+
serviceStatus: ((.serviceStatus // .status // "未知") | tostring),
|
|
255
|
+
resourceUrl: ((.resourceUrl // "未知") | tostring)
|
|
256
|
+
}]')
|
|
257
|
+
if ! printf '%s' "$SERVICE_CANDIDATES" | node "$CANDIDATE_RUNNER" service-candidates >/dev/null 2>&1; then
|
|
258
|
+
echo "❌ 服务候选事实安全校验失败"
|
|
259
|
+
emit_control "FLOW:ERROR"
|
|
260
|
+
exit 1
|
|
261
|
+
fi
|
|
262
|
+
if ! emit_control_field "SERVICE_CANDIDATES_JSON" "$SERVICE_CANDIDATES"; then
|
|
263
|
+
echo "❌ 服务候选事实包含非法控制字符"
|
|
264
|
+
emit_control "FLOW:ERROR"
|
|
265
|
+
exit 1
|
|
266
|
+
fi
|
|
267
|
+
|
|
268
|
+
if [ "$SERVICE_COUNT" -eq 0 ] || [ "$SERVICE_LIST" = "[]" ] || [ -z "$SERVICE_LIST" ]; then
|
|
269
|
+
emit_control "FLOW:CREATE_NEW"
|
|
270
|
+
else
|
|
271
|
+
echo "$SERVICE_LIST" | jq -r '.[] | "SERVICE_CANDIDATE_ID=" + .serviceId' \
|
|
272
|
+
| while IFS= read -r marker; do emit_control "$marker"; done
|
|
273
|
+
emit_control "FLOW:SELECT"
|
|
274
|
+
fi
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
# ─── service save: 创建新服务 或 修改已有服务 ────────────────────────────────
|
|
278
|
+
service_save() {
|
|
279
|
+
SERVICE_ID=""
|
|
280
|
+
SERVICE_NAME=""
|
|
281
|
+
SERVICE_DESC=""
|
|
282
|
+
RESOURCE_URL=""
|
|
283
|
+
PRICING=""
|
|
284
|
+
SCHEMA_URL=""
|
|
285
|
+
|
|
286
|
+
while [[ $# -gt 0 ]]; do
|
|
287
|
+
case $1 in
|
|
288
|
+
--service-id)
|
|
289
|
+
[ $# -ge 2 ] || { echo "❌ 缺少参数值: $1"; exit 1; }
|
|
290
|
+
SERVICE_ID="$2"; shift 2 ;;
|
|
291
|
+
--name)
|
|
292
|
+
[ $# -ge 2 ] || { echo "❌ 缺少参数值: $1"; exit 1; }
|
|
293
|
+
SERVICE_NAME="$2"; shift 2 ;;
|
|
294
|
+
--desc)
|
|
295
|
+
[ $# -ge 2 ] || { echo "❌ 缺少参数值: $1"; exit 1; }
|
|
296
|
+
SERVICE_DESC="$2"; shift 2 ;;
|
|
297
|
+
--url)
|
|
298
|
+
[ $# -ge 2 ] || { echo "❌ 缺少参数值: $1"; exit 1; }
|
|
299
|
+
RESOURCE_URL="$2"; shift 2 ;;
|
|
300
|
+
--pricing)
|
|
301
|
+
[ $# -ge 2 ] || { echo "❌ 缺少参数值: $1"; exit 1; }
|
|
302
|
+
PRICING="$2"; shift 2 ;;
|
|
303
|
+
--schema)
|
|
304
|
+
[ $# -ge 2 ] || { echo "❌ 缺少参数值: $1"; exit 1; }
|
|
305
|
+
SCHEMA_URL="$2"; shift 2 ;;
|
|
306
|
+
*) echo "❌ 未知参数: $1"; exit 1 ;;
|
|
307
|
+
esac
|
|
308
|
+
done
|
|
309
|
+
|
|
310
|
+
if [ -z "$SERVICE_NAME" ] || [ -z "$SERVICE_DESC" ] || [ -z "$RESOURCE_URL" ] || [ -z "$PRICING" ] || [ -z "$SCHEMA_URL" ]; then
|
|
311
|
+
echo "❌ 缺少必填参数"
|
|
312
|
+
echo "用法(创建): bash service.sh save --name <name> --desc <desc> --url <url> --pricing <pricing> --schema <json>"
|
|
313
|
+
echo "用法(修改): bash service.sh save --service-id <id> --name <name> --desc <desc> --url <url> --pricing <pricing> --schema <json>"
|
|
314
|
+
exit 1
|
|
315
|
+
fi
|
|
316
|
+
if [ -n "$SERVICE_ID" ] && ! validate_control_value "$SERVICE_ID"; then
|
|
317
|
+
echo "❌ serviceId 包含非法控制字符"
|
|
318
|
+
exit 1
|
|
319
|
+
fi
|
|
320
|
+
validate_service_fields
|
|
321
|
+
|
|
322
|
+
if [ -z "$SERVICE_ID" ]; then
|
|
323
|
+
# 创建新服务(不传 serviceId)
|
|
324
|
+
fetch_service_list
|
|
325
|
+
FETCH_RC=$?
|
|
326
|
+
if [ "$FETCH_RC" -ne 0 ]; then
|
|
327
|
+
exit "$FETCH_RC"
|
|
328
|
+
fi
|
|
329
|
+
if [ "$SERVICE_COUNT" -ge "$SERVICE_CREATE_LIMIT" ]; then
|
|
330
|
+
echo "❌ 已达到服务数量上限(${SERVICE_CREATE_LIMIT}个),无法创建新服务"
|
|
331
|
+
echo "📋 您当前已有 $SERVICE_COUNT 个服务,请选择复用已有服务或修改已有服务"
|
|
332
|
+
emit_control "SERVICE_SAVE_RESULT=FAILED"
|
|
333
|
+
exit 1
|
|
334
|
+
fi
|
|
335
|
+
|
|
336
|
+
REQUEST_JSON=$(jq -n \
|
|
337
|
+
--arg serviceName "$SERVICE_NAME" \
|
|
338
|
+
--arg serviceDesc "$SERVICE_DESC" \
|
|
339
|
+
--arg resourceUrl "$RESOURCE_URL" \
|
|
340
|
+
--arg pricing "$PRICING" \
|
|
341
|
+
--arg schemaUrl "$SCHEMA_URL" \
|
|
342
|
+
'{request:{serviceName:$serviceName,serviceDesc:$serviceDesc,resourceUrl:$resourceUrl,pricing:$pricing,schemaUrl:$schemaUrl}}')
|
|
343
|
+
|
|
344
|
+
else
|
|
345
|
+
# 修改已有服务(必须传入 serviceId + 所有字段)
|
|
346
|
+
REQUEST_JSON=$(jq -n \
|
|
347
|
+
--arg serviceId "$SERVICE_ID" \
|
|
348
|
+
--arg serviceName "$SERVICE_NAME" \
|
|
349
|
+
--arg serviceDesc "$SERVICE_DESC" \
|
|
350
|
+
--arg resourceUrl "$RESOURCE_URL" \
|
|
351
|
+
--arg pricing "$PRICING" \
|
|
352
|
+
--arg schemaUrl "$SCHEMA_URL" \
|
|
353
|
+
'{request:{serviceId:$serviceId,serviceName:$serviceName,serviceDesc:$serviceDesc,resourceUrl:$resourceUrl,pricing:$pricing,schemaUrl:$schemaUrl}}')
|
|
354
|
+
|
|
355
|
+
fi
|
|
356
|
+
|
|
357
|
+
require_alipay_cli_local_state_access_or_emit || exit "$?"
|
|
358
|
+
export PLATFORM="${DEV_TOOL_NAME}" PLATFORM_ID="${PLATFORM_ID:-}"
|
|
359
|
+
run_network_retry RESULT write service_save -- alipay-cli mcp call a2a-pay-service.saveBazaarServiceForMcp \
|
|
360
|
+
-d "$REQUEST_JSON" \
|
|
361
|
+
--json
|
|
362
|
+
RETRY_RC=$?
|
|
363
|
+
if [ "$RETRY_RC" -eq 75 ]; then
|
|
364
|
+
if [ -z "$SERVICE_ID" ]; then
|
|
365
|
+
echo "❌ 服务创建响应不明;现有查询无法把同名候选唯一归属于本次创建,结果标记为 UNKNOWN,禁止自动重复创建"
|
|
366
|
+
emit_control "SERVICE_SAVE_RESULT=UNKNOWN"
|
|
367
|
+
exit 1
|
|
368
|
+
fi
|
|
369
|
+
if ALIPAY_AIPAY_SUPPRESS_LOCAL_FS_RETRY_MARKER=1 fetch_service_list; then
|
|
370
|
+
MATCH_COUNT=$(echo "$SERVICE_LIST" | jq --arg id "$SERVICE_ID" --arg name "$SERVICE_NAME" --arg desc "$SERVICE_DESC" --arg url "$RESOURCE_URL" --arg pricing "$PRICING" --arg schema "$SCHEMA_URL" '
|
|
371
|
+
[.[] | select(
|
|
372
|
+
.serviceId == $id and .serviceName == $name and .serviceDesc == $desc and
|
|
373
|
+
.resourceUrl == $url and
|
|
374
|
+
((.metadata.pricing // .pricing) | tostring) == $pricing and
|
|
375
|
+
(.metadata.schema_url // .schemaUrl) == $schema
|
|
376
|
+
)] | length
|
|
377
|
+
')
|
|
378
|
+
if [ "$MATCH_COUNT" -eq 1 ]; then
|
|
379
|
+
emit_control "✅ 服务修改已由列表查询核验成功"
|
|
380
|
+
emit_control "📋 服务ID: $SERVICE_ID"
|
|
381
|
+
emit_control "SERVICE_SAVE_RESULT=SUCCESS"
|
|
382
|
+
emit_control_field "SERVICE_ID" "$SERVICE_ID" || return 1
|
|
383
|
+
emit_stage_metric "onboarding.confirm_service"
|
|
384
|
+
return 0
|
|
385
|
+
fi
|
|
386
|
+
fi
|
|
387
|
+
echo "❌ 服务修改响应不明且现有列表无法排除传播延迟,结果标记为 UNKNOWN,禁止自动重复修改"
|
|
388
|
+
emit_control "SERVICE_SAVE_RESULT=UNKNOWN"
|
|
389
|
+
exit 1
|
|
390
|
+
elif [ "$RETRY_RC" -eq "${ALIPAY_CLI_LOCAL_STATE_PERMISSION_EXIT_CODE:-77}" ]; then
|
|
391
|
+
exit "$RETRY_RC"
|
|
392
|
+
elif [ "$RETRY_RC" -ne 0 ]; then
|
|
393
|
+
if [ -z "$SERVICE_ID" ]; then
|
|
394
|
+
echo "❌ 服务创建因明确未发送的网络异常在自动重试两次后仍未恢复"
|
|
395
|
+
else
|
|
396
|
+
echo "❌ 服务修改因明确未发送的网络异常在自动重试两次后仍未恢复"
|
|
397
|
+
fi
|
|
398
|
+
emit_control "SERVICE_SAVE_RESULT=FAILED"
|
|
399
|
+
exit 1
|
|
400
|
+
fi
|
|
401
|
+
|
|
402
|
+
# 错误检测
|
|
403
|
+
if ! handle_error "$RESULT" "MCP_AUTHENTICATED_CALL"; then
|
|
404
|
+
emit_control "SERVICE_SAVE_RESULT=FAILED"
|
|
405
|
+
exit 1
|
|
406
|
+
fi
|
|
407
|
+
|
|
408
|
+
# 解包 MCP 信封后按当前协议解析,并兼容旧 success/resultObj 协议。
|
|
409
|
+
BUSINESS=$(unwrap_mcp "$RESULT")
|
|
410
|
+
SAVE_FORMAT=$(echo "$BUSINESS" | jq -r '
|
|
411
|
+
if ((.code | tostring) == "10000") and
|
|
412
|
+
((.data | type) == "object") and
|
|
413
|
+
(.data.success == true) then
|
|
414
|
+
"current"
|
|
415
|
+
elif (.success == true) and
|
|
416
|
+
((.resultObj | type) == "object") then
|
|
417
|
+
"legacy"
|
|
418
|
+
else
|
|
419
|
+
"invalid"
|
|
420
|
+
end
|
|
421
|
+
' 2>/dev/null)
|
|
422
|
+
|
|
423
|
+
if [ "$SAVE_FORMAT" = "current" ] || [ "$SAVE_FORMAT" = "legacy" ]; then
|
|
424
|
+
OPERATION="创建"
|
|
425
|
+
if [ -n "$SERVICE_ID" ]; then
|
|
426
|
+
OPERATION="修改"
|
|
427
|
+
fi
|
|
428
|
+
|
|
429
|
+
if [ "$SAVE_FORMAT" = "current" ]; then
|
|
430
|
+
NEW_SERVICE_ID=$(echo "$BUSINESS" | jq -r --arg fallback "${SERVICE_ID}" '
|
|
431
|
+
(.data.serviceId | select(type == "string" and length > 0)) // $fallback
|
|
432
|
+
')
|
|
433
|
+
else
|
|
434
|
+
NEW_SERVICE_ID=$(echo "$BUSINESS" | jq -r --arg fallback "${SERVICE_ID}" '
|
|
435
|
+
(.resultObj.serviceId | select(type == "string" and length > 0)) // $fallback
|
|
436
|
+
')
|
|
437
|
+
fi
|
|
438
|
+
|
|
439
|
+
if ! validate_control_value "$NEW_SERVICE_ID"; then
|
|
440
|
+
echo "❌ 服务创建返回成功,但未解析到 serviceId,禁止继续后续流程"
|
|
441
|
+
emit_control "SERVICE_SAVE_RESULT=UNKNOWN"
|
|
442
|
+
exit 1
|
|
443
|
+
fi
|
|
444
|
+
emit_control "✅ 服务${OPERATION}成功"
|
|
445
|
+
emit_control "📋 服务ID: $NEW_SERVICE_ID"
|
|
446
|
+
emit_control "SERVICE_SAVE_RESULT=SUCCESS"
|
|
447
|
+
emit_control_field "SERVICE_ID" "$NEW_SERVICE_ID" || exit 1
|
|
448
|
+
emit_stage_metric "onboarding.confirm_service"
|
|
449
|
+
else
|
|
450
|
+
OPERATION="创建"
|
|
451
|
+
if [ -n "$SERVICE_ID" ]; then
|
|
452
|
+
OPERATION="修改"
|
|
453
|
+
fi
|
|
454
|
+
|
|
455
|
+
BUSINESS_CODE=$(echo "$BUSINESS" | jq -r 'if has("code") then (.code | tostring) else "" end' 2>/dev/null)
|
|
456
|
+
if [ -n "$BUSINESS_CODE" ] && [ "$BUSINESS_CODE" != "10000" ]; then
|
|
457
|
+
ERROR_MSG=$(echo "$BUSINESS" | jq -r '
|
|
458
|
+
.data.subMsg // .data.msg // .subMsg // .msg //
|
|
459
|
+
.error.message // .errorMessage // "未知错误"
|
|
460
|
+
' 2>/dev/null)
|
|
461
|
+
ERROR_MSG=$(sanitize_customer_error_text "$ERROR_MSG")
|
|
462
|
+
echo "❌ 服务${OPERATION}失败: ${BUSINESS_CODE} / ${ERROR_MSG}"
|
|
463
|
+
emit_control "SERVICE_SAVE_RESULT=FAILED"
|
|
464
|
+
else
|
|
465
|
+
echo "❌ 服务${OPERATION}返回结构异常,无法确认操作结果"
|
|
466
|
+
emit_control "SERVICE_SAVE_RESULT=UNKNOWN"
|
|
467
|
+
fi
|
|
468
|
+
exit 1
|
|
469
|
+
fi
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
# ─── service validate: 入参校验 ──────────────────────────────────────────────
|
|
473
|
+
service_validate() {
|
|
474
|
+
SERVICE_NAME=""
|
|
475
|
+
SERVICE_DESC=""
|
|
476
|
+
RESOURCE_URL=""
|
|
477
|
+
PRICING=""
|
|
478
|
+
SCHEMA_URL=""
|
|
479
|
+
|
|
480
|
+
while [[ $# -gt 0 ]]; do
|
|
481
|
+
case $1 in
|
|
482
|
+
--name)
|
|
483
|
+
[ $# -ge 2 ] || { echo "❌ 缺少参数值: $1"; exit 1; }
|
|
484
|
+
SERVICE_NAME="$2"; shift 2 ;;
|
|
485
|
+
--desc)
|
|
486
|
+
[ $# -ge 2 ] || { echo "❌ 缺少参数值: $1"; exit 1; }
|
|
487
|
+
SERVICE_DESC="$2"; shift 2 ;;
|
|
488
|
+
--url)
|
|
489
|
+
[ $# -ge 2 ] || { echo "❌ 缺少参数值: $1"; exit 1; }
|
|
490
|
+
RESOURCE_URL="$2"; shift 2 ;;
|
|
491
|
+
--pricing)
|
|
492
|
+
[ $# -ge 2 ] || { echo "❌ 缺少参数值: $1"; exit 1; }
|
|
493
|
+
PRICING="$2"; shift 2 ;;
|
|
494
|
+
--schema)
|
|
495
|
+
[ $# -ge 2 ] || { echo "❌ 缺少参数值: $1"; exit 1; }
|
|
496
|
+
SCHEMA_URL="$2"; shift 2 ;;
|
|
497
|
+
*) echo "❌ 未知参数: $1"; exit 1 ;;
|
|
498
|
+
esac
|
|
499
|
+
done
|
|
500
|
+
|
|
501
|
+
validate_service_fields
|
|
502
|
+
|
|
503
|
+
emit_control "✅ 服务信息校验通过"
|
|
504
|
+
emit_control_field "SERVICE_PRICING" "$PRICING" || exit 1
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
# ─── 入口分发 ────────────────────────────────────────────────────────────────
|
|
508
|
+
case "${1:-}" in
|
|
509
|
+
list)
|
|
510
|
+
service_list
|
|
511
|
+
;;
|
|
512
|
+
save)
|
|
513
|
+
shift
|
|
514
|
+
service_save "$@"
|
|
515
|
+
;;
|
|
516
|
+
validate)
|
|
517
|
+
shift
|
|
518
|
+
service_validate "$@"
|
|
519
|
+
;;
|
|
520
|
+
*)
|
|
521
|
+
echo "用法: bash service.sh <list|save|validate> [参数...]"
|
|
522
|
+
echo ""
|
|
523
|
+
echo " service list"
|
|
524
|
+
echo " service save --name <n> --desc <d> --url <u> --pricing <p> --schema <json> [--service-id <id>]"
|
|
525
|
+
echo " service validate --name <n> --desc <d> --url <u> --pricing <p> --schema <json>"
|
|
526
|
+
exit 1
|
|
527
|
+
;;
|
|
528
|
+
esac
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
emit_signed_flow() {
|
|
4
|
+
case "$1" in
|
|
5
|
+
"I1080300001000041203") echo "FLOW:PC_WEB_SIGNED" ;;
|
|
6
|
+
"I1080300001000041313") echo "FLOW:APP_SIGNED" ;;
|
|
7
|
+
"I1080300001000160457") echo "FLOW:AI_PAY_SIGNED" ;;
|
|
8
|
+
*) return 1 ;;
|
|
9
|
+
esac
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
emit_sign_status_from_business() {
|
|
13
|
+
local business="$1"
|
|
14
|
+
local sales_code="$2"
|
|
15
|
+
local ar_list ar_count has_effective has_submitted
|
|
16
|
+
|
|
17
|
+
case "$sales_code" in
|
|
18
|
+
"I1080300001000041203"|"I1080300001000041313"|"I1080300001000160457") ;;
|
|
19
|
+
*) return 1 ;;
|
|
20
|
+
esac
|
|
21
|
+
|
|
22
|
+
ar_list=$(printf '%s' "$business" | jq -c '
|
|
23
|
+
if (.resultObj | type) == "object" and (.resultObj.arInfoList | type) == "array" then
|
|
24
|
+
.resultObj.arInfoList
|
|
25
|
+
else
|
|
26
|
+
null
|
|
27
|
+
end
|
|
28
|
+
' 2>/dev/null) || return 1
|
|
29
|
+
[ -n "$ar_list" ] && printf '%s' "$ar_list" | jq -e 'type == "array"' >/dev/null 2>&1 || return 1
|
|
30
|
+
ar_count=$(printf '%s' "$ar_list" | jq 'length') || return 1
|
|
31
|
+
|
|
32
|
+
if [ "$ar_count" -eq 0 ]; then
|
|
33
|
+
echo "📋 签约状态: 未签约 (NOT_SIGNED);进入 Step 4 签约材料类别"
|
|
34
|
+
echo "SIGN_STATUS=NOT_SIGNED"
|
|
35
|
+
case "$sales_code" in
|
|
36
|
+
"I1080300001000041203") echo "FLOW:PC_WEB_NOT_SIGNED" ;;
|
|
37
|
+
"I1080300001000041313") echo "FLOW:APP_NOT_SIGNED" ;;
|
|
38
|
+
"I1080300001000160457") echo "FLOW:AI_PAY_NOT_SIGNED" ;;
|
|
39
|
+
esac
|
|
40
|
+
return 0
|
|
41
|
+
fi
|
|
42
|
+
|
|
43
|
+
has_effective=$(printf '%s' "$ar_list" | jq -r '[.[] | select(.arStatus == "02")] | length') || return 1
|
|
44
|
+
has_submitted=$(printf '%s' "$ar_list" | jq -r '[.[] | select(.arStatus == "01")] | length') || return 1
|
|
45
|
+
if [ "$has_effective" -gt 0 ]; then
|
|
46
|
+
echo "✅ 签约已生效;无需签约材料,继续 Step 4 资源决策"
|
|
47
|
+
echo "SIGN_STATUS=SIGNED_EFFECTIVE"
|
|
48
|
+
emit_signed_flow "$sales_code"
|
|
49
|
+
elif [ "$has_submitted" -gt 0 ]; then
|
|
50
|
+
echo "📋 已提交签约(待生效),无需重复提交签约,继续推进后续步骤"
|
|
51
|
+
echo "SIGN_STATUS=SIGN_SUBMITTED"
|
|
52
|
+
emit_signed_flow "$sales_code"
|
|
53
|
+
else
|
|
54
|
+
echo "📋 其他签约状态;保留已取得的只读结果并将签约分支标记为待核验"
|
|
55
|
+
echo "SIGN_STATUS=OTHER_STATUS"
|
|
56
|
+
echo "FLOW:OTHER_STATUS"
|
|
57
|
+
fi
|
|
58
|
+
}
|