{"components":{"schemas":{"Error":{"properties":{"code":{"example":4001,"type":"integer"},"msg":{"example":"\u7f3a\u5c11\u7b7e\u540d\u53c2\u6570","type":"string"}},"type":"object"},"QuestionInput":{"properties":{"logic_rules":{"description":"\u903b\u8f91\u8df3\u8f6c\u89c4\u5219","items":{"type":"object"},"type":"array"},"options":{"description":"\u9009\u9879\u5217\u8868\uff08choice/dropdown/sort \u7c7b\u578b\uff09","items":{"properties":{"label":{"type":"string"}},"type":"object"},"type":"array"},"required":{"description":"\u662f\u5426\u5fc5\u7b54","type":"boolean"},"settings":{"description":"\u9898\u76ee\u6269\u5c55\u8bbe\u7f6e","type":"object"},"title":{"description":"\u9898\u76ee\u6807\u9898","type":"string"},"type":{"description":"\u9898\u76ee\u7c7b\u578b","enum":["single_choice","multi_choice","fill","fill_multi","dropdown","matrix_single","matrix_multi","nps","likert5","likert7","sort","rating_star","rating_number","file_upload","cascader","date","time","location","divider","section"],"type":"string"},"ukey":{"description":"\u9898\u76ee\u552f\u4e00\u6807\u8bc6\uff08\u53ef\u9009\uff0c\u81ea\u52a8\u751f\u6210\uff09","type":"string"}},"required":["type","title"],"type":"object"},"ResponseDetail":{"properties":{"answers":{"items":{"properties":{"answer":{"type":"string"},"file_ids":{"items":{"type":"integer"},"type":"array"},"question_id":{"type":"integer"},"question_title":{"type":"string"}},"type":"object"},"type":"array"},"duration_seconds":{"type":"integer"},"id":{"type":"integer"},"ip_address":{"type":"string"},"submitted_at":{"type":"string"},"survey_id":{"type":"integer"},"user_id":{"type":"integer"}},"type":"object"},"ResponseInput":{"properties":{"answers":{"description":"\u7b54\u6848\u5217\u8868","items":{"properties":{"file_ids":{"description":"\u6587\u4ef6 ID \u5217\u8868\uff08file_upload \u9898\u578b\uff09","items":{"type":"integer"},"type":"array"},"question_ukey":{"description":"\u9898\u76ee ukey","type":"string"},"value":{"description":"\u7b54\u6848\u503c\uff08\u5b57\u7b26\u4e32/\u6570\u7ec4/\u5bf9\u8c61\uff0c\u53d6\u51b3\u4e8e\u9898\u578b\uff09"}},"required":["question_ukey"],"type":"object"},"type":"array"},"duration_seconds":{"description":"\u586b\u5199\u7528\u65f6\uff08\u79d2\uff09","type":"integer"},"survey_id":{"description":"\u76ee\u6807\u95ee\u5377 ID","type":"integer"}},"required":["survey_id","answers"],"type":"object"},"Success":{"properties":{"code":{"example":0,"type":"integer"},"data":{"type":"object"},"msg":{"example":"\u64cd\u4f5c\u6210\u529f","type":"string"}},"type":"object"},"Survey":{"properties":{"created_at":{"format":"date-time","type":"string"},"description":{"type":"string"},"id":{"description":"\u95ee\u5377 ID","type":"integer"},"status":{"enum":["draft","published","paused","closed"],"type":"string"},"title":{"description":"\u95ee\u5377\u6807\u9898","type":"string"}},"type":"object"},"SurveyInput":{"properties":{"description":{"description":"\u95ee\u5377\u63cf\u8ff0","type":"string"},"questions":{"description":"\u9898\u76ee\u5217\u8868","items":{"$ref":"#/components/schemas/QuestionInput"},"type":"array"},"settings":{"description":"\u95ee\u5377\u8bbe\u7f6e","properties":{"finish_message":{"description":"\u63d0\u4ea4\u6210\u529f\u540e\u63d0\u793a\u8bed","type":"string"},"permission":{"description":"\u586b\u5199\u6743\u9650","enum":["public","login","login_identify"],"type":"string"}},"type":"object"},"title":{"description":"\u95ee\u5377\u6807\u9898","example":"\u7528\u6237\u6ee1\u610f\u5ea6\u8c03\u7814","type":"string"}},"required":["title"],"type":"object"}},"securitySchemes":{"appAuth":{"description":"\u5e94\u7528\u5bc6\u94a5\uff0c\u914d\u5408 X-Timestamp / X-Nonce / X-Sign \u4f7f\u7528 HMAC-SHA256 \u7b7e\u540d","in":"header","name":"X-App-Key","type":"apiKey"}}},"info":{"description":"## \u63a5\u5165\u65b9\u5f0f\n\n\u6240\u6709\u5f00\u653e\u63a5\u53e3\u9700\u901a\u8fc7 **HMAC-SHA256 \u7b7e\u540d\u8ba4\u8bc1**\uff0c\u8bf7\u6c42\u5934\u643a\u5e26\u4ee5\u4e0b\u5b57\u6bb5\uff1a\n\n| \u8bf7\u6c42\u5934 | \u8bf4\u660e |\n|---|---|\n| `X-App-Key` | \u5e94\u7528\u5bc6\u94a5\uff08\u7533\u8bf7\u540e\u83b7\u5f97\uff09 |\n| `X-Timestamp` | Unix \u65f6\u95f4\u6233\uff08\u79d2\uff09\uff0c\u4e0e\u670d\u52a1\u5668\u5dee \u22645 \u5206\u949f |\n| `X-Nonce` | \u968f\u673a\u5b57\u7b26\u4e32\uff08\u6bcf\u6b21\u8bf7\u6c42\u4e0d\u540c\uff0c\u9632\u91cd\u653e\uff09 |\n| `X-Sign` | \u7b7e\u540d\u503c\uff08\u89c1\u4e0b\u65b9\u7b97\u6cd5\uff09 |\n\n### \u7b7e\u540d\u7b97\u6cd5\n\n```\nmessage = HTTP\u65b9\u6cd5 + \"\\n\" + \u8bf7\u6c42\u8def\u5f84 + \"\\n\" + \u65f6\u95f4\u6233 + \"\\n\" + Nonce + \"\\n\" + \u8bf7\u6c42\u4f53\nsign = HMAC-SHA256(AppSecret, message)\n```\n\n### \u9519\u8bef\u7801\n\n| \u9519\u8bef\u7801 | \u8bf4\u660e |\n|---|---|\n| 4001 | \u7f3a\u5c11\u7b7e\u540d\u53c2\u6570\u6216\u5e94\u7528\u672a\u901a\u8fc7\u5ba1\u6838 |\n| 4002 | \u65f6\u95f4\u6233\u8fc7\u671f\u6216\u683c\u5f0f\u9519\u8bef |\n| 4003 | \u91cd\u590d\u8bf7\u6c42\uff08Nonce \u5df2\u4f7f\u7528\uff09 |\n| 4004 | \u7b7e\u540d\u6821\u9a8c\u5931\u8d25 |\n| 4290 | QPS \u8d85\u9650 |\n| 4291 | \u65e5\u8c03\u7528\u91cf\u8d85\u9650 |\n","title":"\u667a\u91c7\u95ee\u5377 \u00b7 \u5f00\u653e\u5e73\u53f0 API","version":"1.0.0"},"openapi":"3.0.0","paths":{"/files/upload":{"post":{"description":"\u4e0a\u4f20\u6587\u4ef6\u5e76\u8fd4\u56de\u6587\u4ef6 ID\u3002\u652f\u6301\u4e24\u79cd\u65b9\u5f0f\uff1a\n1. `multipart/form-data`\uff08\u6807\u51c6\u6587\u4ef6\u4e0a\u4f20\uff09\n2. JSON Body\uff08`data` \u5b57\u6bb5\u4f20 Base64 \u7f16\u7801\uff0c`file_name` \u6307\u5b9a\u6587\u4ef6\u540d\uff09\n\n\u8fd4\u56de\u7684 `file_id` \u53ef\u7528\u4e8e\u7b54\u5377 `file_upload` \u9898\u578b\u3002","requestBody":{"content":{"application/json":{"schema":{"properties":{"data":{"description":"Base64 \u7f16\u7801\u7684\u6587\u4ef6\u5185\u5bb9","type":"string"},"file_name":{"description":"\u6587\u4ef6\u540d","type":"string"},"mime_type":{"description":"MIME \u7c7b\u578b","type":"string"}},"type":"object"}},"multipart/form-data":{"schema":{"properties":{"file":{"description":"\u6587\u4ef6","format":"binary","type":"string"}},"type":"object"}}}},"responses":{"200":{"content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/Success"},{"properties":{"data":{"properties":{"file_id":{"description":"\u6587\u4ef6 ID","type":"integer"},"file_name":{"description":"\u6587\u4ef6\u540d","type":"string"},"url":{"description":"\u6587\u4ef6\u8bbf\u95ee URL","type":"string"}},"type":"object"}}}]}}},"description":"\u4e0a\u4f20\u6210\u529f"}},"security":[{"appAuth":[]}],"summary":"\u4e0a\u4f20\u6587\u4ef6"}},"/responses":{"post":{"description":"\u901a\u8fc7 API \u63d0\u4ea4\u7b54\u5377\u6570\u636e\u3002\u652f\u6301\u6240\u6709\u9898\u578b\uff0c\u6587\u4ef6\u4e0a\u4f20\u9898\u53ef\u4f20\u5165 `file_ids`\uff08\u5148\u901a\u8fc7 `/files/upload` \u4e0a\u4f20\u83b7\u5f97 ID\uff09\u3002\u652f\u6301 Base64 \u7f16\u7801\u6587\u4ef6\u3002","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ResponseInput"}}},"required":true},"responses":{"200":{"content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/Success"},{"properties":{"data":{"properties":{"response_id":{"description":"\u7b54\u5377 ID","type":"integer"}},"type":"object"}}}]}}},"description":"\u63d0\u4ea4\u6210\u529f"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}},"description":"\u53c2\u6570\u9519\u8bef\u6216\u95ee\u5377\u672a\u53d1\u5e03"}},"security":[{"appAuth":[]}],"summary":"\u63d0\u4ea4\u7b54\u5377"}},"/responses/export":{"get":{"description":"\u6309\u95ee\u5377 ID \u6279\u91cf\u5bfc\u51fa\u6240\u6709\u7b54\u5377\u4e3a CSV \u6587\u4ef6\u3002","parameters":[{"description":"\u95ee\u5377 ID","in":"query","name":"survey_id","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"content":{"text/csv":{}},"description":"CSV \u6587\u4ef6\u6d41"}},"security":[{"appAuth":[]}],"summary":"\u5bfc\u51fa\u7b54\u5377\uff08CSV\uff09"}},"/responses/{id}":{"get":{"description":"\u6839\u636e\u7b54\u5377 ID \u67e5\u8be2\u5b8c\u6574\u7b54\u6848\u5185\u5bb9\u3002","parameters":[{"description":"\u7b54\u5377 ID","in":"path","name":"id","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/Success"},{"properties":{"data":{"$ref":"#/components/schemas/ResponseDetail"}}}]}}},"description":"\u6210\u529f"}},"security":[{"appAuth":[]}],"summary":"\u67e5\u8be2\u7b54\u5377\u8be6\u60c5"}},"/surveys":{"get":{"description":"\u5206\u9875\u67e5\u8be2\u5f53\u524d\u7528\u6237\u62e5\u6709\u7684\u95ee\u5377\u5217\u8868\u3002","parameters":[{"description":"\u9875\u7801","in":"query","name":"page","schema":{"default":1,"type":"integer"}},{"description":"\u6bcf\u9875\u6570\u91cf","in":"query","name":"per_page","schema":{"default":20,"maximum":100,"type":"integer"}}],"responses":{"200":{"content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/Success"},{"properties":{"data":{"properties":{"items":{"items":{"$ref":"#/components/schemas/Survey"},"type":"array"},"page":{"type":"integer"},"pages":{"type":"integer"},"total":{"type":"integer"}},"type":"object"}}}]}}},"description":"\u6210\u529f"}},"security":[{"appAuth":[]}],"summary":"\u67e5\u8be2\u95ee\u5377\u5217\u8868"},"post":{"description":"\u521b\u5efa\u65b0\u95ee\u5377\uff0c\u53ef\u540c\u65f6\u4f20\u5165\u9898\u76ee\u5217\u8868\u3002","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SurveyInput"}}},"required":true},"responses":{"200":{"content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/Success"},{"properties":{"data":{"$ref":"#/components/schemas/Survey"}}}]}}},"description":"\u521b\u5efa\u6210\u529f"}},"security":[{"appAuth":[]}],"summary":"\u521b\u5efa\u95ee\u5377"}},"/surveys/{id}":{"delete":{"description":"\u5220\u9664\u95ee\u5377\u53ca\u5176\u6240\u6709\u9898\u76ee\u548c\u7b54\u5377\u6570\u636e\u3002","parameters":[{"description":"\u95ee\u5377 ID","in":"path","name":"id","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"\u5220\u9664\u6210\u529f"},"403":{"description":"\u65e0\u6743\u64cd\u4f5c"}},"security":[{"appAuth":[]}],"summary":"\u5220\u9664\u95ee\u5377"},"put":{"description":"\u66f4\u65b0\u95ee\u5377\u6807\u9898\u3001\u63cf\u8ff0\u6216\u8bbe\u7f6e\u3002","parameters":[{"description":"\u95ee\u5377 ID","in":"path","name":"id","required":true,"schema":{"type":"integer"}}],"requestBody":{"content":{"application/json":{"schema":{"properties":{"description":{"type":"string"},"settings":{"type":"object"},"title":{"type":"string"}},"type":"object"}}}},"responses":{"200":{"description":"\u66f4\u65b0\u6210\u529f"},"403":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}},"description":"\u65e0\u6743\u64cd\u4f5c"}},"security":[{"appAuth":[]}],"summary":"\u66f4\u65b0\u95ee\u5377"}},"/surveys/{id}/publish":{"post":{"description":"\u5c06\u95ee\u5377\u72b6\u6001\u6539\u4e3a published\uff0c\u5f00\u59cb\u6536\u96c6\u7b54\u5377\u3002","parameters":[{"description":"\u95ee\u5377 ID","in":"path","name":"id","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"\u53d1\u5e03\u6210\u529f"},"403":{"description":"\u65e0\u6743\u64cd\u4f5c"}},"security":[{"appAuth":[]}],"summary":"\u53d1\u5e03\u95ee\u5377"}},"/webhooks":{"post":{"description":"\u4e3a\u95ee\u5377\u914d\u7f6e Webhook\uff0c\u652f\u6301\u4e24\u79cd\u6a21\u5f0f\uff1a\n- **push**\uff1a\u5e73\u53f0\u5728\u4e8b\u4ef6\u89e6\u53d1\u65f6\u5411\u56de\u8c03\u5730\u5740\u63a8\u9001\u6570\u636e\n- **inbound**\uff1a\u5e73\u53f0\u751f\u6210\u4e13\u5c5e\u63a5\u6536\u94fe\u63a5\uff0c\u7b2c\u4e09\u65b9 POST \u6570\u636e\u5230\u6b64\u94fe\u63a5\u5373\u81ea\u52a8\u5165\u5e93","requestBody":{"content":{"application/json":{"schema":{"properties":{"events":{"description":"\u89e6\u53d1\u4e8b\u4ef6","items":{"type":"string"},"type":"array"},"survey_id":{"description":"\u76ee\u6807\u95ee\u5377 ID","type":"integer"},"url":{"description":"\u56de\u8c03\u5730\u5740\uff08push \u6a21\u5f0f\u5fc5\u586b\uff09","type":"string"}},"required":["survey_id"],"type":"object"}}}},"responses":{"200":{"description":"\u914d\u7f6e\u6210\u529f"}},"security":[{"appAuth":[]}],"summary":"\u914d\u7f6e Webhook \u56de\u8c03"}},"/webhooks/{id}/logs":{"get":{"description":"\u67e5\u770b\u6307\u5b9a Webhook \u7684\u63a8\u9001/\u63a5\u6536\u8bb0\u5f55\u3002","parameters":[{"description":"Webhook ID","in":"path","name":"id","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"\u65e5\u5fd7\u5217\u8868"}},"security":[{"appAuth":[]}],"summary":"\u67e5\u770b Webhook \u63a8\u9001\u65e5\u5fd7"}}},"security":[{"appAuth":[]}],"servers":[{"description":"\u5f53\u524d\u670d\u52a1\u5668","url":""}],"tags":[{"description":"\u95ee\u5377 CRUD \u4e0e\u53d1\u5e03","name":"\u95ee\u5377\u7ba1\u7406"},{"description":"\u7b54\u5377\u63d0\u4ea4\u4e0e\u67e5\u8be2","name":"\u7b54\u5377\u7ba1\u7406"},{"description":"\u6587\u4ef6\u4e0a\u4f20\u4e0e\u7ba1\u7406","name":"\u6587\u4ef6\u4e0a\u4f20"},{"description":"Webhook \u56de\u8c03\u914d\u7f6e\u4e0e\u65e5\u5fd7","name":"Webhook"}],"x-sign-examples":{"javascript":"const crypto = require(\"crypto\");\n\nconst app_key = \"YOUR_KEY\";\nconst app_secret = \"YOUR_SECRET\";\nconst ts = String(Math.floor(Date.now() / 1000));\nconst nonce = crypto.randomBytes(8).toString(\"hex\");\n\n// \u793a\u4f8b\uff1a\u63d0\u4ea4\u7b54\u5377\nconst body = JSON.stringify({\n    survey_id: 1,\n    answers: [\n        { question_ukey: \"abc123\", value: \"\u6ee1\u610f\" },\n        { question_ukey: \"def456\", value: [\"\u9009\u9879A\", \"\u9009\u9879B\"] },\n    ]\n});\nconst message = [\"POST\", \"/api/v1/responses\", ts, nonce, body].join(\"\\n\");\nconst sign = crypto.createHmac(\"sha256\", app_secret).update(message).digest(\"hex\");\n\nfetch(\"http://localhost:5025/api/v1/responses\", {\n    method: \"POST\",\n    body: body,\n    headers: {\n        \"Content-Type\": \"application/json\",\n        \"X-App-Key\": app_key,\n        \"X-Timestamp\": ts,\n        \"X-Nonce\": nonce,\n        \"X-Sign\": sign,\n    },\n}).then(r => r.json()).then(console.log);","python":"import hashlib, hmac, time, secrets, requests\n\napp_key = \"YOUR_KEY\"\napp_secret = \"YOUR_SECRET\"\nts = str(int(time.time()))\nnonce = secrets.token_hex(8)\n\n# \u793a\u4f8b\uff1a\u521b\u5efa\u95ee\u5377\nbody = '{\"title\": \"\u7528\u6237\u6ee1\u610f\u5ea6\u8c03\u7814\", \"questions\": [{\"type\": \"single_choice\", \"title\": \"\u60a8\u5bf9\u4ea7\u54c1\u7684\u6ee1\u610f\u5ea6\uff1f\", \"options\": [{\"label\": \"\u975e\u5e38\u6ee1\u610f\"}, {\"label\": \"\u6ee1\u610f\"}, {\"label\": \"\u4e00\u822c\"}, {\"label\": \"\u4e0d\u6ee1\u610f\"}]}]}'\nmessage = \"\\n\".join([\"POST\", \"/api/v1/surveys\", ts, nonce, body])\nsign = hmac.new(app_secret.encode(), message.encode(), hashlib.sha256).hexdigest()\n\nresp = requests.post(\n    \"http://localhost:5025/api/v1/surveys\",\n    data=body,\n    headers={\n        \"Content-Type\": \"application/json\",\n        \"X-App-Key\": app_key,\n        \"X-Timestamp\": ts,\n        \"X-Nonce\": nonce,\n        \"X-Sign\": sign,\n    }\n)\nprint(resp.json())"}}
