接口统一的调用异常

报错返回参数:msgCode

名称 描述介绍
服务器开小差了 MTOP 接口的兜底报错
HSF执行错误 HSF 接口没有发布到对应环境
请求API不存在 调用的 mtop 接口不存在
请求参数不正确 参数填写不正确,请查看文档对照参数
(包括,参数类型不正确 和 参数未填写)
除前三个报错信息,剩下的报错,都透传至服务端接口

如何判断当前页面的环境

  1. if (AI.urlParam().type === 'debug' || AI.urlParam().type === 'localDebug') {
  2. // 预发环境
  3. } else {
  4. // 线上环境
  5. }

查询食谱推荐列表接口

mtop.alibaba.aicloud.recipe.getRecomandRecipePage

参数

名称 参数类型 是否必须 描述
devId string 是 设备 devId
productKey string 是 设备 productKey
params object 是 主要参数
params.openAccountId string 是 用户账号的 accountId
pageInfo object 否 页码参数
pageInfo.pageNum number 否 当前页码
pageInfo.pageSize number 否 当前页面展示数量

示例

  1. // 调用示例
  2. AI.aiRequestMtopProxy({
  3. api: 'mtop.alibaba.aicloud.recipe.getRecomandRecipePage',
  4. data: {
  5. devId: 'a80171320100009715c507da78000000', // 获取url上的 AI.devId
  6. productKey: '306', // 获取url上的 AI.productKey
  7. params: JSON.stringify({
  8. openAccountId: "0yl8oK0WFDBwEheQxSMD4g==",
  9. enviroment: 1
  10. }),
  11. pageInfo: JSON.stringify({
  12. pageNum: 1,
  13. pageSize: 10
  14. })
  15. }
  16. }).then((res) => {
  17. console.log('返回信息', res);
  18. }).catch((res) => {
  19. console.log('失败返回', res);
  20. });
  21. // 返回数据
  22. {
  23. "api": "mtop.alibaba.aicloud.recipe.getRecomandRecipePage",
  24. "data": {
  25. "success": "true",
  26. "model": {
  27. "success": true,
  28. "retValue": {
  29. "pageNum": 1, // 第N页
  30. "pageSize": 10, // 一页条数
  31. "total": 5, // 总条数
  32. "list": [
  33. {
  34. "contentRecipeId": 1137111, // 内容食谱id
  35. "recipeName": "开灯1111", // 食谱名
  36. "collectNum": 0, // 食谱收藏数
  37. "recipeType": 0, // 食谱类型 0视频菜谱 1图文菜谱
  38. "description": "xxxdescription111", // 食谱描述
  39. "functionType": 2, // 功能类型,1 非智能食谱 2智能食谱
  40. "recipeTime": 0, // 食谱制作时间(秒)
  41. // 食谱图片地址
  42. "imageUrl": {
  43. "img": "www.xxximg111.com", // 默认图片
  44. "large": "www.xxxlarge111.com", // 大图
  45. "medium": "www.xxxmedium111.com", // 中图
  46. "small": "www.xxxsmall111.com" // 小图
  47. }
  48. }
  49. ]
  50. },
  51. "extentions": null
  52. },
  53. "statusCode": "200"
  54. }
  55. }

查询菜谱收藏列表接口

mtop.alibaba.aicloud.recipe.getFavoriteRecipeItem

参数

名称 参数类型 是否必须 描述
pageNum number 否 当前页码
pageSize number 否 当前页面展示数量

示例

  1. // 调用示例
  2. AI.aiRequestMtopProxy({
  3. api: 'mtop.alibaba.aicloud.recipe.getFavoriteRecipeItem',
  4. data: {
  5. pageNum: 1,
  6. pageSize: 10
  7. }
  8. }).then((res) => {
  9. console.log('返回信息', res);
  10. }).catch((res) => {
  11. console.log('失败返回', res);
  12. });
  13. // 返回数据
  14. {
  15. "api": "mtop.alibaba.aicloud.recipe.getFavoriteRecipeItem",
  16. "v": "1.0",
  17. "ret": [
  18. "SUCCESS::调用成功"
  19. ],
  20. "data": {
  21. "success": "true",
  22. "msgCode": "null",
  23. "msgInfo": "SUCCESS",
  24. "model": {
  25. "totalCnt": 2,
  26. "totalPage": 0,
  27. "pageNum": 1,
  28. "pageSize": 10,
  29. "statusCode": 200,
  30. "message": null,
  31. "exception": null,
  32. "result": [
  33. {
  34. "sourceName": null, //源名称
  35. "recipeType": 1, //食谱类型 0 语音食谱 1 图文食谱
  36. "tips": "", //小贴士
  37. "cookTime": null, //制作时长单位秒
  38. "difficulty": null, //难度
  39. "cookStepNum": 1, //总部数
  40. "audioUrl": "这个李子酸看着都会流口水!", //音频地址 图文食谱为描述
  41. "viewCount": 17000,
  42. "favorCount": 515,
  43. "innerfavorCount":0,//内容中心收藏数
  44. "functionType": 2, // 功能类型,1 非智能食谱 2智能食谱
  45. "tmjlFavorCount": 173, // 天猫精灵收藏数
  46. "intellectRecipe": 1, // 食谱类型(1 普通食谱 2 智能食谱)
  47. "commentCount": 0,
  48. "score": null,
  49. "videoPlayCount": null,
  50. "cookedCount": 13,
  51. "dishesCount": 13,
  52. "rawPageUrl": "https://www.xiachufang.com/recipe/100236532/", //三方连接地址
  53. "tipsAudioUrl": null,
  54. "id": 780363, //食谱id
  55. "rawId": "100236532", //三方id
  56. "source": "xiachufang", //三方源
  57. "sourceId": null,
  58. "title": "开胃李子酸", //食谱名称
  59. "category": "audio",
  60. "type": "program",
  61. "hotScore": null,
  62. "commCateId": 80027001, //内容分类 80027001 固定 值
  63. "tppExtendInfo": null,
  64. "x1Pv30d": 0,
  65. "x1PvTotal": 0,
  66. "isCharge": false, //是否收费
  67. "isAudition": false, //是否试看
  68. "resourceId": null,
  69. "description": "这个李子酸看着都会流口水!", //描述
  70. "offline": false, //是否上线
  71. "rankLevel": null,
  72. "videoUrl": null,
  73. "ingredients": [ //食材
  74. {
  75. "name": "紫苏叶(超市有卖)", //名称
  76. "weight": "1把" // 用量
  77. }
  78. ],
  79. "publishTime": "2014-05-18T14:10:30.000Z", //发布时间
  80. "tags": [ //标签
  81. {
  82. "commonCateId": null,
  83. "id": 94045, //标签id
  84. "title": null,
  85. "alias": null,
  86. "description": null,
  87. "isOnline": null,
  88. "type": "program",
  89. "tagGroup": null
  90. }
  91. ],
  92. "authors": [ //作者
  93. {
  94. "source": null,
  95. "id": 726699,
  96. "title": null, //作者名称
  97. "alias": null,
  98. "description": null,
  99. "isOnline": null,
  100. "type": "program",
  101. "gender": null,
  102. "authorTypes": [ //作者类型
  103. {
  104. "name": "DEFAULT"
  105. }
  106. ],
  107. "cover": null
  108. }
  109. ],
  110. "itemType": null,
  111. "valid": null,
  112. "cover": { //封面
  113. "img": "https://aicontent.alibabausercontent.com/image-pre/732/732/6cde2c525b3d6a503fbabb5efdb97697.jpg!medium",
  114. "large": "https://aicontent.alibabausercontent.com/image-pre/732/732/6cde2c525b3d6a503fbabb5efdb97697.jpg!large",
  115. "mediam": null,
  116. "medium": "https://aicontent.alibabausercontent.com/image-pre/732/732/6cde2c525b3d6a503fbabb5efdb97697.jpg!medium",
  117. "small": "https://aicontent.alibabausercontent.com/image-pre/732/732/6cde2c525b3d6a503fbabb5efdb97697.jpg!small"
  118. },
  119. "alias": [
  120. ],
  121. "releaseTime": null
  122. }
  123. ],
  124. "extentions": null,
  125. "detail": null
  126. },
  127. "statusCode": "200"
  128. }
  129. }

查询是否收藏了该菜谱

mtop.alibaba.aicloud.recipe.searchDetail

参数

名称 参数类型 是否必须 描述
params object 是 参数对象
params.id string 是 食谱 id

示例

  1. // 调用示例
  2. AI.aiRequestMtopProxy({
  3. api: 'mtop.alibaba.aicloud.recipe.searchDetail',
  4. data: {
  5. params: JSON.stringify({id: 780368})
  6. }
  7. }).then((res) => {
  8. console.log('返回信息', res);
  9. }).catch((res) => {
  10. console.log('失败返回', res);
  11. });
  12. // 返回数据
  13. {
  14. "api": "mtop.alibaba.aicloud.recipe.searchDetail",
  15. "v": "1.0",
  16. "ret": [
  17. "SUCCESS::调用成功"
  18. ],
  19. "data": {
  20. "success": "true",
  21. "msgCode": "success",
  22. "msgInfo": "SUCCESS",
  23. "model": {
  24. "code": 200,
  25. "message": "success",
  26. "result": {
  27. hasFavorite: true // 是否收藏标志
  28. },
  29. "extendInfo": null
  30. },
  31. "statusCode": "200"
  32. }
  33. }


收藏or取消收藏操作

mtop.alibaba.aicloud.recipe.favoriteRecipeItem

参数

名称 参数类型 是否必须 描述
contentRecipeIds array 是 菜谱id
isFavorite boolean 是 是否收藏, true 收藏, false 取消收藏

示例

  1. // 调用示例
  2. AI.aiRequestMtopProxy({
  3. api: 'mtop.alibaba.aicloud.recipe.favoriteRecipeItem',
  4. data: {
  5. contentRecipeIds: JSON.stringify([780368, 780363]),
  6. isFavorite: true
  7. }
  8. }).then((res) => {
  9. console.log('返回信息', res);
  10. }).catch((res) => {
  11. console.log('失败返回', res);
  12. });
  13. // 返回数据
  14. {
  15. "api": "mtop.alibaba.aicloud.recipe.favoriteRecipeItem",
  16. "v": "1.0",
  17. "ret": [
  18. "SUCCESS::调用成功"
  19. ],
  20. "data": {
  21. "success": "true",//操作成功标志
  22. "msgCode": "null",//操作结果码
  23. "msgInfo": "SUCCESS",//操作结果信息
  24. "model": {
  25. "statusCode": 200,
  26. "message": null,
  27. "exception": null,//异常信息
  28. "result": {
  29. "successIds": [//收藏成功id
  30. 780363,
  31. 780368
  32. ],
  33. "failIds": [//收藏失败id
  34. ]
  35. },
  36. "extentions": null,
  37. "detail": null
  38. },
  39. "statusCode": "200"
  40. }
  41. }

查询食谱关联产品及设备信息接口

mtop.alibaba.aicloud.recipe.getRecipeProductDetailList

参数

名称 参数类型 是否必须 描述
devId string 是 设备 devId
productKey string 是 设备 productKey
params object 是 主要参数
params.openAccountId string 是 用户账号的 accountId
params.contentRecipeId string 是 云食谱Id

示例

  1. // 调用示例
  2. AI.aiRequestMtopProxy({
  3. api: 'mtop.alibaba.aicloud.recipe.getRecipeProductDetailList',
  4. data: {
  5. devId: AI.devId, // 获取url上的 devId
  6. productKey: AI.productKey, // 获取url上的 productKey
  7. params: JSON.stringify({
  8. openAccountId: "0yl8oK0WFDBwEheQxSMD4g==",
  9. contentRecipeId: "779736",
  10. enviroment: 1 // 环境,1测试,2线上
  11. })
  12. }
  13. }).then((res) => {
  14. console.log('返回信息', res);
  15. }).catch((res) => {
  16. console.log('失败返回', res);
  17. });
  18. // 返回数据
  19. {
  20. "api": "mtop.alibaba.aicloud.recipe.getRecipeProductDetailList",
  21. "data": {
  22. "success": "true",
  23. "model": {
  24. "retCode": 200,
  25. "success": true,
  26. "retValue": [
  27. {
  28. "contentRecipeId": 779736, // 内容食谱id
  29. "productKey": "306", // 产品key
  30. "productName": "智能LED灯泡", // 产品名
  31. // 产品icon图
  32. "productIcon": "https://img.alicdn.com/tfs/TB1yQ7cNgHqK1RjSZJnXXbNLpXa-160-160.png",
  33. "businessRecipeId": 7, // 行业食谱id
  34. "controlApiName": "alibaba.ailabs.iot.saas.devicecontrol", // 控制接口名
  35. "deviceStatusApiName": "alibaba.ailabs.iot.saas.deviceStatus", // 设备状态接口名
  36. "openAccountId": "xxxxx", // openaccountId
  37. // 设备列表
  38. "deviceList": [
  39. {
  40. "deviceId": "a80171320100009715c507da78000000" // 设备 Id
  41. }
  42. ]
  43. }
  44. ],
  45. "extentions": null
  46. },
  47. "statusCode": "200"
  48. }
  49. }

行业设备控制接口

mtop.alibaba.aicloud.recipe.businessDeviceControl

参数

名称 参数类型 是否必须 描述
devId string 是 设备 devId (h5 sdk 自动填写)
productKey string 是 设备 productKey (h5 sdk 自动填写)
params object 是 主要参数
params.openAccountId string 是 用户账号的 accountId
params.controlApiName string 是 控制接口名
params.releaseStatus number 是 1 预发 2线上
params.domain number 是 1 食谱
params.payload object 是 领域参数

示例
command 指令支持:启动指令 deviceStart,关闭指令 deviceStop,暂停指令 deviceSuspend

  1. // 调用示例
  2. AI.aiRequestMtopProxy({
  3. api: 'mtop.alibaba.aicloud.recipe.businessDeviceControl',
  4. data: {
  5. devId: AI.devId,
  6. productKey: AI.productKey,
  7. params: JSON.stringify({
  8. openAccountId: "0yl8oK0WFDBwEheQxSMD4g==",
  9. controlApiName: "alibaba.ailabs.iot.saas.devicecontrol",
  10. releaseStatus: 2,
  11. releaseVersion: null,
  12. domain: 1,
  13. payload: JSON.stringify({"businessRecipeId": 100,"command":"deviceStart"})
  14. })
  15. }
  16. }).then((res) => {
  17. console.log('返回信息', res);
  18. }).catch((res) => {
  19. console.log('失败返回', res);
  20. });
  21. // 返回数据
  22. {
  23. "api": "mtop.alibaba.aicloud.recipe.businessDeviceControl",
  24. "data": {
  25. "success": "true",
  26. "model": {
  27. "retCode": 200,
  28. "success": true,
  29. "retValue": true, // 是否成功 true 成功 false 失败
  30. "extentions": null
  31. },
  32. "statusCode": "200"
  33. }
  34. }

错误码:

retCode message
302002 productKey=13414的产品功能定义不支持属性:workSwitch
300003 该账号下没有天猫精灵可以推送指令
302007 设备处于离线状态
302030 音箱不在线,无法推送指令
120010 其他食谱正在制作中
120017 您食谱操作太快了

查询设备食谱制作状态

mtop.alibaba.aicloud.recipe.getDeviceCurrentStatus

参数

名称 参数类型 是否必须 描述
devId string 是 设备 devId (h5 sdk 自动填写)
productKey string 是 设备 productKey (h5 sdk 自动填写)
params object 是 主要参数
params.openAccountId string 是 用户账号的 accountId
params.deviceStatusApiName string 否 设备状态接口名
params.releaseStatus number 是 1 预发 2线上
params.domain number 是 1 食谱
params.payload object 是 领域参数

示例

  1. // 调用示例
  2. AI.aiRequestMtopProxy({
  3. api: 'mtop.alibaba.aicloud.recipe.getDeviceCurrentStatus',
  4. data: {
  5. devId: AI.devId,
  6. productKey: AI.productKey,
  7. params: JSON.stringify({
  8. openAccountId: "0yl8oK0WFDBwEheQxSMD4g==",
  9. deviceStatusApiName: "alibaba.ailabs.iot.saas.deviceStatus",
  10. releaseStatus: 2,
  11. releaseVersion: null,
  12. domain: 1,
  13. payload: JSON.stringify({"businessRecipeId": 2})
  14. })
  15. }
  16. }).then((res) => {
  17. console.log('返回信息', res);
  18. }).catch((res) => {
  19. console.log('失败返回', res);
  20. });
  21. // 返回数据
  22. {
  23. "api": "mtop.alibaba.aicloud.recipe.getDeviceCurrentStatus",
  24. "data": {
  25. "success": "true",
  26. "model": {
  27. "retCode": 200, // 这里返回的是字符串对像,需要先 JSON.parse 一下
  28. "retValue": {
  29. "contentRecipeId": 1137111, // 内容食谱id
  30. "currentContentRecipeStepId": 9420204, // 当前食谱步骤id
  31. "deviceId": "a80171320100009715c507da78000000", // 设备id
  32. "runStatus": 1, // 运行状态,0 停止 1 运行 2 暂停 3 食谱完成 4 中断暂停
  33. "totalTimeleft": 180, // 剩余时间总时间,单位秒
  34. "productName": "智能LED灯泡", // 产品名称
  35. "productKey": "306", // 产品key
  36. "controlApiName": "alibaba.ailabs.iot.saas.devicecontrol", // 控制接口名
  37. "deviceStatusApiName": "alibaba.ailabs.iot.saas.deviceStatus", // 设备状态接口名
  38. "businessRecipeId": 100, // 行业食谱id
  39. "totalTime": 180 // 总时间,单位秒
  40. "deviceStatus": {"name":"start/开始","value":1} // 设备状态
  41. "interruptErrorInfo": {"code": 302007,"message":"设备处于离线状态"} // 中断错误码
  42. },
  43. "extentions": null
  44. },
  45. "statusCode": "200"
  46. }
  47. }

获取云食谱详情接口

mtop.alibaba.aicloud.recipe.listDataRecipeV2

参数

名称 参数类型 是否必须 描述
contentRecipeIds array 是 食谱Id
needStep boolean 是 是否需要获取步骤

示例

  1. // 调用示例
  2. AI.aiRequestMtopProxy({
  3. api: 'mtop.alibaba.aicloud.recipe.listDataRecipeV2',
  4. data: {
  5. contentRecipeIds: JSON.stringify([779712]),
  6. needStep: true,
  7. params: JSON.stringify({
  8. isProductData: 2 // 2 是线上环境 非2 是预发环境 (默认非2)
  9. })
  10. }
  11. }).then((res) => {
  12. console.log('返回信息', res);
  13. }).catch((res) => {
  14. console.log('失败返回', res);
  15. });
  16. // 返回数据
  17. {
  18. "api": "mtop.alibaba.aicloud.recipe.listDataRecipeV2",
  19. "data": {
  20. "success": "true"
  21. "model": {
  22. "totalSize": 1, // 总数
  23. "currentPageNum": 0, // 当前页
  24. "pageSize": 0, // 每页数量
  25. "success": true,
  26. "data": [
  27. {
  28. "batchId": null, // 批次号
  29. "id": 779712, // 菜谱的id
  30. "name": "奶黄水晶饼", // 菜谱名称
  31. "type": 1, // 菜谱类型 0 视频 1 图文
  32. "tips": null, // 小贴士
  33. //菜谱描述
  34. "description": "朋友送了这套小巧玲珑的模具给我正好做可以做水蒸饼,而且花纹也很清晰。",
  35. "source": "xiachufang", // 菜谱来源
  36. "rawId": "100591900", // 外部系统菜谱id
  37. "cookTime": 0, // 菜谱制作时长 单位秒
  38. "difficulty": null, // 菜谱制作难度
  39. "firstCommonCateId": 80027, // 菜谱类型 固定值
  40. "secCommonCateId": 80027001, // 菜谱类型 固定值
  41. "cookStepNum": 9, // 菜谱总步数
  42. "audioUrl": "朋友送了这套小巧玲珑的模具给我正好做可以做水蒸饼,而且花纹也很清晰。",// audio 链接
  43. "audit": 1, // 审核状态 0 未审核 1 审核中 2 审核通过 3 审核不通过
  44. "rawPageUrl": "https://www.xiachufang.com/recipe/100591900/",//三方地址链接
  45. "functionType": 2, // 功能类型,1 非智能食谱 2智能食谱
  46. "steps": [
  47. {
  48. "id": 6455563, // 菜谱步骤内部id
  49. "recipeId": 779712, // 菜谱id
  50. "batchId": null, // 批次号
  51. "name": "1", // 菜谱名称
  52. "source": "xiachufang", // 菜谱来源
  53. "rawId": "1", // 三方菜谱步骤id
  54. "description": "将所有粉类过筛与糖粉混合", // 菜谱步骤描述
  55. "orderIndex": 1, // 菜谱步骤顺序
  56. "audioUrl": "将所有粉类过筛与糖粉混合", // 菜谱音频地址 没有音频方文字
  57. "extendInfo": "{\"data_version\":\"2\"}",
  58. "tips": null, // 步骤小贴士
  59. "recipeRawId": "100591900", // 菜谱三方id
  60. "tipsAudioUrl": null,
  61. "operation": null,
  62. "coverUrl": { // 菜谱封面
  63. "img": "https://aicontent.alibabausercontent.com/image-pre/732/732/c625fa544601221f106b905aa69e88e9.webp!medium", // 默认封面
  64. "large": "https://aicontent.alibabausercontent.com/image-pre/732/732/c625fa544601221f106b905aa69e88e9.webp!large", // 大图
  65. "mediam": null,
  66. "medium": "https://aicontent.alibabausercontent.com/image-pre/732/732/c625fa544601221f106b905aa69e88e9.webp!medium",// 中图
  67. "small": "https://aicontent.alibabausercontent.com/image-pre/732/732/c625fa544601221f106b905aa69e88e9.webp!small"// 小图
  68. },
  69. "videoUrl": { // 菜谱步骤视频
  70. "cover" : { // 封面
  71. "img" : "https://aicontent.alibabausercontent.com/image/732/c4c75437005237ab974a7083bed6e348.webp!medium",
  72. "large" : "",
  73. "mediam" : "",
  74. "medium" : "",
  75. "small" : ""
  76. },
  77. "defaultUrl" : "", // 默认连接
  78. "height" : 0,
  79. "high" : "",
  80. "standard" : "",
  81. "ultra" : "",
  82. "width" : 0
  83. }
  84. }
  85. ],
  86. "alias": [
  87. ],
  88. "coverUrl": { // 封面
  89. "img": "https://aicontent.alibabausercontent.com/image-pre/732/732/669a23deebc1f97d34b33f711ef1ec46.jpg!medium",// 默认图片
  90. "large": "https://aicontent.alibabausercontent.com/image-pre/732/732/669a23deebc1f97d34b33f711ef1ec46.jpg!large",// 大图
  91. "mediam": null,
  92. "medium": "https://aicontent.alibabausercontent.com/image-pre/732/732/669a23deebc1f97d34b33f711ef1ec46.jpg!medium",// 中图
  93. "small": "https://aicontent.alibabausercontent.com/image-pre/732/732/669a23deebc1f97d34b33f711ef1ec46.jpg!small"// 小图
  94. },
  95. "videoUrl": null,
  96. "authorIds": [
  97. {
  98. "source": null,
  99. "id": 726115, // 作者id
  100. "title": "b文惠", // 作者名称
  101. "alias": null,
  102. "description": null,
  103. "isOnline": null,
  104. "type": "program",
  105. "gender": null,
  106. "authorTypes": [
  107. {
  108. "name": "DEFAULT"
  109. }
  110. ],
  111. "cover": null
  112. }
  113. ],
  114. "tagIds": [
  115. {
  116. "commonCateId": null,
  117. "id": 358242, // 标签id
  118. "title": "饼", // 标签名称
  119. "alias": null,
  120. "description": null,
  121. "isOnline": null,
  122. "type": "program",
  123. "tagGroup": {
  124. "id": 8, // 标签组id
  125. "groupName": "测试1", // 标签组名称
  126. "desc": null
  127. }
  128. }
  129. ],
  130. "ingredient": [ // 食材
  131. {
  132. "name": "糯米粉", // 名称
  133. "weight": "40克" // 用量
  134. },
  135. {
  136. "name": "热开水",
  137. "weight": "146克"
  138. },
  139. {
  140. "name": "生粉",
  141. "weight": "20克"
  142. },
  143. {
  144. "name": "植物油",
  145. "weight": "2汤匙"
  146. },
  147. {
  148. "name": "澄粉",
  149. "weight": "150克"
  150. },
  151. {
  152. "name": "糖粉",
  153. "weight": "20克"
  154. }
  155. ],
  156. "online": {
  157. "name": "ONLINE"
  158. },
  159. "copyright": {
  160. "name": "YES"
  161. },
  162. "publishTime": "2015-11-12T23:54:11.000Z"
  163. }
  164. ]
  165. },
  166. "statusCode": "200"
  167. }
  168. }

获取云食谱详情步骤列表接口

mtop.alibaba.aicloud.recipe.queryStepsByRecipeIdV2

参数

名称 参数类型 是否必须 描述
contentRecipeId array 是 食谱Id

示例

  1. // 调用示例
  2. AI.aiRequestMtopProxy({
  3. api: 'mtop.alibaba.aicloud.recipe.queryStepsByRecipeIdV2',
  4. data: {
  5. contentRecipeId: 779712,
  6. params: JSON.stringify({
  7. isProductData: 2 // 2 是线上环境 非2 是预发环境 (默认非2)
  8. })
  9. }
  10. }).then((res) => {
  11. console.log('返回信息', res);
  12. }).catch((res) => {
  13. console.log('失败返回', res);
  14. });
  15. // 返回数据
  16. {
  17. "api": "mtop.alibaba.aicloud.recipe.queryStepsByRecipeIdV2",
  18. "v": "1.0",
  19. "ret": [
  20. "SUCCESS::调用成功"
  21. ],
  22. "data": {
  23. "success": "true",
  24. "msgCode": "调用成功!",
  25. "msgInfo": "SUCCESS",
  26. "model": {
  27. "totalSize": 9,
  28. "currentPageNum": 0,
  29. "pageSize": 0,
  30. "message": "调用成功!",
  31. "retCode": 200,
  32. "success": true,
  33. "data": [
  34. {
  35. "id": 6455563, //菜谱步骤内部id
  36. "recipeId": 779712, //菜谱id
  37. "batchId": null, //批次号
  38. "name": "1", //菜谱名称
  39. "source": "xiachufang", //菜谱来源
  40. "rawId": "1", //三方菜谱步骤id
  41. "description": "将所有粉类过筛与糖粉混合", //菜谱步骤描述
  42. "orderIndex": 1, //菜谱步骤顺序
  43. "audioUrl": "将所有粉类过筛与糖粉混合", //菜谱音频地址 没有音频方文字
  44. "extendInfo": "{\"data_version\":\"2\"}",//扩展信息
  45. "tips": null, //步骤小贴士
  46. "recipeRawId": "100591900", //菜谱三方id
  47. "tipsAudioUrl": null,
  48. "operation": null,
  49. "coverUrl": { //菜谱封面
  50. "img": "https://aicontent.alibabausercontent.com/image-pre/732/732/c625fa544601221f106b905aa69e88e9.webp!medium", //默认封面
  51. "large": "https://aicontent.alibabausercontent.com/image-pre/732/732/c625fa544601221f106b905aa69e88e9.webp!large", //大图
  52. "mediam": null,
  53. "medium": "https://aicontent.alibabausercontent.com/image-pre/732/732/c625fa544601221f106b905aa69e88e9.webp!medium",//中图
  54. "small": "https://aicontent.alibabausercontent.com/image-pre/732/732/c625fa544601221f106b905aa69e88e9.webp!small"//小图
  55. },
  56. "videoUrl": {//菜谱步骤视频
  57. "cover" : {//封面
  58. "img" : "https://aicontent.alibabausercontent.com/image/732/c4c75437005237ab974a7083bed6e348.webp!medium",
  59. "large" : "",
  60. "mediam" : "",
  61. "medium" : "",
  62. "small" : ""
  63. },
  64. "defaultUrl" : "",//默认连接
  65. "height" : 0,
  66. "high" : "",
  67. "standard" : "",
  68. "ultra" : "",
  69. "width" : 0
  70. }
  71. }
  72. ]
  73. },
  74. "statusCode": "200"
  75. }
  76. }

长链接消息推送

  1. AI.deviceStatusChange({
  2. recipeCallback: resp => {
  3. console.error('长链接数据返回', resp)
  4. },
  5. errorCallback: (error) => { console.log('stateChange ERROR:', error) }
  6. });
  7. // 长链接数据返回
  8. {
  9. \"traceId\": \"1234567890abcdefghijkl0123456789\", // 追踪id
  10. \"timestamp\": 1547714598977, // 时间戳
  11. \"deviceId\": \"456A23FBEB27EDCF4B945094FD92AB0B\", // 设备Id
  12. \"domain\": 1, // 领域:1食谱
  13. \"payload\": { // 领域参数
  14. \"contentRecipeId\": 100, // 内容食谱id
  15. \"currentContentRecipeStepId\": 9000, // 当前内容食谱步骤id
  16. \"runStatus\": 2, // 运行状态,0 停止 1 运行 2 暂停 3 食谱完成 4 中断暂停
  17. \"timeLeftTotal\": 10, // 剩余时间总时间,单位秒
  18. \"totalTime\": 180, // 总时间,单位秒
  19. \"productName\": "破壁机", // 产品名称
  20. \"productKey\": \"6001\", // 产品key
  21. \"controlApiName\": \"alibaba.ailabs.iot.saas.devicecontrol\", // 控制接口名
  22. \"deviceStatusApiName\": \"alibaba.ailabs.iot.saas.deviceStatus\" // 设备状态接口名
  23. \"businessRecipeId\": 100, // 行业食谱id
  24. \"deviceStatus\": {\"name\":\"start/开始\",\"value\":1}, // 设备状态
  25. \"interruptErrorInfo\": {\"code\": 302007,\"message\":\"设备处于离线状态\"} // 中断错误码
  26. }
  27. }

如下图:云食谱相关长链接返回数据

  1. // 在store/modules/public.js 找到 deviceStatusChange 方法,加上 recipe 逻辑
  2. AI.deviceStatusChange({
  3. callback: resp => {
  4. console.log('长链接返回的设备状态:', Object.assign({}, resp.model));
  5. if (resp.recipe) {
  6. console.error('recipe', resp) // 云食谱返回数据
  7. // 注:当云食谱的长链接推送过来,返回的数据在 resp.recipe
  8. return
  9. }
  10. // 返回的设备状态,是在这个 resp.model 里面的,
  11. },
  12. errorCallback: (error) => { console.log('stateChange ERROR:', error) }
  13. });

image.png

获取蓝牙连接状态

  1. AI.getMeshConnestStatus() // 获取蓝牙连接状态 false 未连接 true 已连接

获取音箱列表信息

  1. // 获取列表信息 可根据返回的音箱列表中的 online 判断音箱是否在线
  2. AI.getListDeviceBaseInfoWithStatus().then((res) => {
  3. console.log('返回信息', res);
  4. }).catch((res) => {
  5. console.log('失败返回', res);
  6. });

云食谱控制 mesh 设备

  1. // 注:controlInfo 是 调用了 "command":"deviceStart" 获取到的数据
  2. // mtop.alibaba.aicloud.recipe.businessDeviceControl
  3. // 调用示例
  4. AI.controlMeshDevice({
  5. compareParameters: controlInfo.sigmesh[0].compareParameters,
  6. action: controlInfo.sigmesh[0].action,
  7. uuid: controlInfo.sigmesh[0].uuid,
  8. device: controlInfo.sigmesh[0].device || {}
  9. }).then(resp => {
  10. AI.cabinet.GenieVue.$toast({ text: 'controlMeshDevice接口成功发送请求' })
  11. console.log('成功发送请求:' + JSON.stringify(result))
  12. }).catch(err => {
  13. AI.cabinet.GenieVue.$toast({ text: 'controlMeshDevice接口请求发送失败' })
  14. console.log('请求发送失败:' + JSON.stringify(err))
  15. })

实战示例

  1. // 启动云食谱
  2. startRecipe() {
  3. // 调用示例
  4. AI.aiRequestMtopProxy({
  5. api: 'mtop.alibaba.aicloud.recipe.businessDeviceControl',
  6. data: {
  7. devId: AI.devId,
  8. productKey: AI.productKey,
  9. params: JSON.stringify({
  10. openAccountId: "0yl8oK0WFDBwEheQxSMD4g==",
  11. controlApiName: "alibaba.ailabs.iot.saas.devicecontrol",
  12. releaseStatus: 1,
  13. releaseVersion: null,
  14. domain: 1,
  15. payload: JSON.stringify({"businessRecipeId": this.businessRecipeId || 567,"command":"deviceStart", "pushMethod": 1})
  16. })
  17. }
  18. }).then((res) => {
  19. console.log('返回信息', res);
  20. try {
  21. window.controlInfo = res.data.model.extentions.controlModel[0];
  22. AI.cabinet.GenieVue.$toast({ text: '启动云食谱成功' + res.data.msgInfo })
  23. } catch (error) {
  24. window.controlInfo = {}
  25. AI.cabinet.GenieVue.$toast({ text: '启动云食谱失败' + res.data.msgInfo })
  26. }
  27. }).catch((res) => {
  28. AI.cabinet.GenieVue.$toast({ text: '启动云食谱失败:' + res.data.msgInfo })
  29. console.log('失败返回', res);
  30. });
  31. },
  32. // 停止云食谱
  33. stopRecipe() {
  34. // 调用示例
  35. AI.aiRequestMtopProxy({
  36. api: 'mtop.alibaba.aicloud.recipe.businessDeviceControl',
  37. data: {
  38. devId: AI.devId,
  39. productKey: AI.productKey,
  40. params: JSON.stringify({
  41. openAccountId: "0yl8oK0WFDBwEheQxSMD4g==",
  42. controlApiName: "alibaba.ailabs.iot.saas.devicecontrol",
  43. releaseStatus: 1,
  44. releaseVersion: null,
  45. domain: 1,
  46. payload: JSON.stringify({"businessRecipeId": this.businessRecipeId || 567,"command":"deviceStop", "pushMethod": 1})
  47. })
  48. }
  49. }).then((res) => {
  50. AI.cabinet.GenieVue.$toast({ text: '停止云食谱成功' + res.data.msgInfo })
  51. console.log('返回信息', res);
  52. }).catch((res) => {
  53. AI.cabinet.GenieVue.$toast({ text: '停止云食谱失败' + res.data.msgInfo })
  54. console.log('失败返回', res);
  55. });
  56. },
  57. // 云食谱控制mesh设备
  58. controlMeshDevice() {
  59. console.log('window.controlInfo', window.controlInfo)
  60. if (!AI.cabinet.windvaneIsAvailable()) return console.log('请在天猫精灵app上调用controlMeshDevice方法')
  61. try {
  62. AI.controlMeshDevice({
  63. compareParameters: window.controlInfo.sigmesh[0].compareParameters,
  64. action: window.controlInfo.sigmesh[0].action,
  65. uuid: window.controlInfo.sigmesh[0].uuid,
  66. device: window.controlInfo.sigmesh[0].device || {}
  67. }).then(resp => {
  68. AI.cabinet.GenieVue.$toast({ text: 'controlMeshDevice接口成功发送请求' })
  69. console.log('成功发送请求:' + JSON.stringify(result))
  70. }).catch(err => {
  71. AI.cabinet.GenieVue.$toast({ text: 'controlMeshDevice接口请求发送失败' })
  72. console.log('请求发送失败:' + JSON.stringify(err))
  73. })
  74. } catch (error) {
  75. console.error('控制mesh设备了')
  76. }
  77. },