多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
### 3.2.6 挑战单词 #### (1)功能说明 激情澎湃的猜单词游戏。游戏有四关,难度递增。每一关有10道题。游戏中,机器人给出一个单词,并让用户选择相应的单词类型。用户答对一道题,就能获得1分,并进入下一题;用户答错,则没有加分,而机器人会告诉用户答案,并进入下一题。在每一关中,用户答对6道题(即获得6分),才能有资格进入下一关。在最后一关中,答对8道以下的用户能获得“单词小将”的称号;答对8或9道题的用户能获得“单词达人”的称号;全答对的用户能获得“单词王”的称号。 #### (2) 接口说明 **请求方法** * POST **请求地址** * [http://api.ruyi.ai/v1/message](http://api.ruyi.ai/v1/message) **请求参数说明** | 参数名 | 参数类型 | 是否必须 | 参数说明 | | :--- | :--- | :---: | :--- | | q | String | 是 | 自然语言表达,例如“挑战单词" | | app\_key | String | 是 | 应用开发者秘钥,注册开发者后台账号,建立虚拟助理后获得 | | user\_id | String | 是 | 用户唯一标识,便于支持个性化语义解析。建议开发者使用 UUID 字符,且不同用户必须用不同的 user\_id,防止意图串。 | #### (3) 返回说明 **返回参数说明** | 名称 | 类型 | 说明 | | :--- | :--- | :--- | | code | Integer | 返回代码 | | msg | String | 返回代码描述 | | parameters | JSON Object | 解析到的实体以及服务说明 | | action | String | 服务的接口名称 | | name | String | 匹配的意图名称 | | result | JSON Object | 接口返回内容 | | outputs | Array | 服务输出结果,微信端使用 type 类型为 wechat 开头的内容;硬件端收到所有内容,依据需求解析使用 | **返回代码说明** | 返回代码 | 错误类型 | 说明 | | :--- | :--- | :--- | | 0/200 | 成功 | 请求成功 | | 400 | 无效请求 | 某些必需参数缺失或参数值错误,详见msg字段 | | 401 | 未授权 | 授权失败,app\_key缺失或错误 | | 403 | 请求被禁止 | 有效请求,但服务拒绝响应,请联系contact@ruyi.ai | | 408 | 请求超时 | 请求响应超时,一般响应时间设置为2000ms以内 | | 429 | 短时间内大量访问 | 短时间内请求数过多 | | 500 | 内部错误 | 服务处理异常 | | 503 | 服务不可用 | 服务异常或正在维护 | #### (4)请求示例 **请求范例** *挑战单词 开始游戏 渗透 沉默 退出* **请求示例** (挑战单词) * http://api.ruyi.ai/ruyi-api/v1/message?app_key=APP_KEY&user_id=user0&q=挑战单词 ```json { "code": 0, "msg": "ok", "result": { "_text": "挑战单词", "msg_id": "03a6e843-d08a-4e94-98f0-cc3aacd08dbd", "intents": [ { "parameters": { "service": "challengeVocab" }, "name": "挑战单词", "result": { "text": "游戏有四关,难度递增。我给你一个单词,你来猜这个单词的类型。准备好了对我说“开始游戏”", "type": "dialog" }, "outputs": [ { "type": "wechat.text", "property": { "text": "游戏有四关,难度递增。我给你一个单词,你来猜这个单词的类型。准备好了对我说“开始游戏”" } }, { "type": "dialog", "property": { "text": "游戏有四关,难度递增。我给你一个单词,你来猜这个单词的类型。准备好了对我说“开始游戏”", "emotion": "like" } } ], "score": "1.0", "scoreColor": "c4", "is_match": 1, "skill_id": "aa9a75f6-442d-4b18-a166-e6dd3fd8bd52", "id": "33812004-880d-4efc-a0e5-ba4d57c71f93", "action": "dialog" } ], "meta_process_milliseconds": 110 } } ``` **请求示例** (开始游戏) * http://api.ruyi.ai/ruyi-api/v1/message?app_key=APP_KEY&user_id=user0&q=开始游戏 ```json { "code": 0, "msg": "ok", "result": { "_text": "开始游戏", "msg_id": "4f583750-610e-4fa5-862c-ffece97da251", "intents": [ { "parameters": { "service": "challengeVocab" }, "action": "开始游戏", "name": "开始游戏", "result": { "code": 200, "response": { "code": 0, "msg": "成功", "result": { "level": "1", "question": "fulsomeness", "answer": "谄媚", "explanation": "n.虚情,谄媚", "options": [ "吹毛求疵", "谄媚" ], "is_right": "yes", "total_score": "0", "level_score": "0", "q_no": "1" } }, "text": "第1关:请直接说出这个单词的类型。单词【fulsomeness】的分类是【吹毛求疵】还是【谄媚】", "type": "dialog" }, "outputs": [ { "type": "wechat.text", "property": { "text": "第1关:请直接说出这个单词的类型。单词【fulsomeness】的分类是【吹毛求疵】还是【谄媚】" } }, { "type": "dialog", "property": { "text": "第1关:请直接说出这个单词的类型。单词【fulsomeness】的分类是【吹毛求疵】还是【谄媚】", "emotion": "despite" } } ], "score": "1.0", "scoreColor": "c4", "is_match": 1, "skill_id": "aa9a75f6-442d-4b18-a166-e6dd3fd8bd52", "id": "2bb16ddc-ad95-43cb-8a3d-20d84a9d3b25" } ], "meta_process_milliseconds": 88 } } ``` **请求示例** (选择题目) * http://api.ruyi.ai/ruyi-api/v1/message?app_key=APP_KEY&user_id=user0&q=谄媚 ```json 格式化JSON: { "code": 0, "msg": "ok", "result": { "_text": "谄媚", "msg_id": "ebaffaa1-4469-4bd7-8082-7b63b161c090", "intents": [ { "parameters": { "text": "谄媚", "service": "challengeVocab" }, "action": "玩游戏", "name": "玩游戏", "result": { "code": 200, "response": { "code": 0, "msg": "成功", "result": { "level": "1", "last_answer": "谄媚", "question": "frippery", "answer": "俗丽廉价", "explanation": "n.低俗,俗艳", "options": [ "外表外皮", "俗丽廉价" ], "is_right": "yes", "total_score": "1", "level_score": "1", "q_no": "2" } }, "text": "你答对了,第1关,第2题:frippery是【外表外皮】或者【俗丽廉价】", "type": "dialog" }, "outputs": [ { "type": "wechat.text", "property": { "text": "你答对了,第1关,第2题:frippery是【外表外皮】或者【俗丽廉价】" } }, { "type": "dialog", "property": { "text": "你答对了,第1关,第2题:frippery是【外表外皮】或者【俗丽廉价】", "emotion": "calm" } } ], "score": "1.0", "scoreColor": "c4", "is_match": 1, "skill_id": "aa9a75f6-442d-4b18-a166-e6dd3fd8bd52", "id": "b13de92c-a700-4831-8f43-9ff9ce2c072c" } ], "meta_process_milliseconds": 120 } } ``` **请求示例** (退出) * http://api.ruyi.ai/ruyi-api/v1/message?app_key=APP_KEY&user_id=user0&q=退出 ```json { "code": 0, "msg": "ok", "result": { "_text": "退出", "msg_id": "e2243368-2c8c-4754-b788-325e42dea520", "intents": [ { "parameters": { "service": "challengeVocab" }, "action": "退出游戏", "name": "退出游戏", "result": { "code": 200, "response": { "code": 0, "msg": "成功", "result": { "level": "1", "total_score": "1", "level_score": "1", "q_no": "2" } }, "text": "谢谢你参与挑战单词。你在第1关挑战了2个单词,本关得分1分,总分1分,加油哦!", "type": "dialog" }, "outputs": [ { "type": "wechat.text", "property": { "text": "谢谢你参与挑战单词。你在第1关挑战了2个单词,本关得分1分,总分1分,加油哦!" } }, { "type": "dialog", "property": { "text": "谢谢你参与挑战单词。你在第1关挑战了2个单词,本关得分1分,总分1分,加油哦!", "emotion": "happy" } } ], "score": "1.0", "scoreColor": "c4", "is_match": 1, "skill_id": "aa9a75f6-442d-4b18-a166-e6dd3fd8bd52", "id": "fb868cd6-0ae8-4d47-8840-b26e4fdf9638" } ], "meta_process_milliseconds": 127 } } ``` **详细参数说明** | 名称 | 类型 | 说明 | | :--- | :--- | :--- | | text | String | 输入文本 | | question | String | 问题 | | answer | String | 答案 | | explanation | String | 单词解释 | | total_score | String | 用户得的总分 | | level_score | String | 用户在当前关数所得的分 | | option | String | 选项 | | level| String | 关数 | | lastAnswer| String | 上一个问题的答案 | | service | String | 服务名称 | **指令清单** | 指令名称 | 范例 | | :--- | :--- | | 唤醒| 挑战单词| | 开始游戏| 开始| | 猜类型| 魔法| | 继续(有资格闯入下一关时,才能被触发)| 继续| | 退出| 退出|