1、食谱TOP接口申请
1.1 定向申请地址
说明:目前只允许企业号进行申请;
http://my.open.taobao.com/common/applyIsv.htm?appTag=212&accessCode=E9780D2AC20DD170450FDBF555F67E3E
1.2 淘宝合作伙伴开发协议
1.3 填写开发者信息
1.4 创建食谱应用
1.5 申请TOP接口
2、SDK使用说明
2.1 选择需要的SDK版本进行构建
2.2 下载SDK并引入代码——JAVA演示
2.2.1 项目引入SDK包
(1)在项目resources目录下创建lib目录,将SDK包导入到该目录下
(2)pom中引入本地jar包
<dependency>
<groupId>ailib-iot</groupId>
<artifactId>sdk-java-auto</artifactId>
<version>1576072385423-20200612</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/taobao-sdk-java-auto_1576072385423-20200612.jar</systemPath>
</dependency>
2.3 食谱TOP接口调用——JAVA演示
2.3.1 插入或更新食谱测试
说明:返回结果是businessRecipeId 行业食谱id;
/**
* 插入或更新食谱测试
*/
public static void insertOrUpdateRecipeTest() throws ApiException {
DefaultTaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "30281416",
"4f9918cxxxxxxxxxxxxx6debcebaa");
AlibabaAilabsIotBusinessRecipeInsertorupdateRequest request = new AlibabaAilabsIotBusinessRecipeInsertorupdateRequest();
// 接口参数
BusinessRecipeOpenParam businessRecipeOpenParam = new BusinessRecipeOpenParam();
// 开放账号id
businessRecipeOpenParam.setOpenAccountId("a2uDllguxxxxxxM3wkl+w==");
// 食谱类型 0视频菜谱 1图文菜谱
businessRecipeOpenParam.setRecipeType(1L);
// 品类Id
businessRecipeOpenParam.setDevTypeId(11L);
// 食谱中文名称
businessRecipeOpenParam.setRecipeNameCn("蜜瓜奶昔");
// 食谱描述
businessRecipeOpenParam.setDescription("蜜瓜富含膳食纤维,酸奶富含益生菌,两者均有助于肠道健康。");
// 食谱图片
ImageUrlParam recipeImage = new ImageUrlParam();
recipeImage.setImg("http://www.xxx.com");
businessRecipeOpenParam.setRecipeImage(recipeImage);
// 食谱食材
List<RecipeIngredientParam> recipeIngredientList = new ArrayList<>();
RecipeIngredientParam recipeIngredientParam1 = new RecipeIngredientParam();
recipeIngredientParam1.setName("蜜瓜");
recipeIngredientParam1.setWeight("300g");
recipeIngredientList.add(recipeIngredientParam1);
RecipeIngredientParam recipeIngredientParam2 = new RecipeIngredientParam();
recipeIngredientParam2.setName("酸奶");
recipeIngredientParam2.setWeight("300g");
recipeIngredientList.add(recipeIngredientParam2);
businessRecipeOpenParam.setRecipeIngredientList(recipeIngredientList);
request.setParamBusinessRecipeOpenParam(businessRecipeOpenParam);
// 通用参数
request.setTimestamp(System.currentTimeMillis());
request.setTopApiVersion("2.0");
request.setTopContentType("application/json");
request.setTopHttpMethod("alibaba.ailabs.iot.business.recipe.insertorupdate");
request.setTopResponseType("application/json");
// 接口调用
AlibabaAilabsIotBusinessRecipeInsertorupdateResponse response = client.execute(request);
if (response.isSuccess()) {
System.out.println(response.getBody());
}
}
2.3.2 插入或更新食谱步骤测试
说明:返回的是businessRecipeStepId 行业食谱步骤id;
/**
* 插入或更新食谱步骤测试
*/
public static void insertOrUpdateRecipeStepTest() throws ApiException {
DefaultTaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "30281416",
"4f9918cxxxxxxxxxxxxx6debcebaa");
AlibabaAilabsIotBusinessRecipestepInsertorupdateRequest request = new AlibabaAilabsIotBusinessRecipestepInsertorupdateRequest();
// 接口参数
BusinessRecipeStepOpenParam businessRecipeStepOpenParam = new BusinessRecipeStepOpenParam();
// 开放账号Id
businessRecipeStepOpenParam.setOpenAccountId("a2uDllguxxxxxxM3wkl+w==");
// 行业食谱id
businessRecipeStepOpenParam.setBusinessRecipeId(6L);
// 指令标识:0不支持指令,1支持指令
businessRecipeStepOpenParam.setActionFlag(1L);
// 食谱步骤中文名
businessRecipeStepOpenParam.setRecipeStepNameCn("开始制作");
// 食谱步骤描述
businessRecipeStepOpenParam.setDescription("根据食谱称量口口蜜瓜块,然后放入研磨腔内,并加入3杯(300g)酸奶,选择“奶昔”功能键,点击“启动”即可");
// 食谱步骤顺序号
businessRecipeStepOpenParam.setSequence(1L);
// 食谱步骤图片
com.taobao.api.request.AlibabaAilabsIotBusinessRecipestepInsertorupdateRequest.ImageUrlParam imageUrl = new com.taobao.api.request.AlibabaAilabsIotBusinessRecipestepInsertorupdateRequest.ImageUrlParam();
imageUrl.setImg("http://www.xxx.com");
businessRecipeStepOpenParam.setImageUrl(imageUrl);
// 食谱步骤时间
businessRecipeStepOpenParam.setRecipeStepTime(180L);
businessRecipeStepOpenParam.setTips("请检查食材是否都放入研磨腔内");
// 步骤指令列表
List<BusinessRecipeStepActionOpenParam> recipeStepActionList = new ArrayList<>();
BusinessRecipeStepActionOpenParam businessRecipeStepActionOpenParam1 = new BusinessRecipeStepActionOpenParam();
// 指令名
businessRecipeStepActionOpenParam1.setActionName("runTime");
// 指令值
businessRecipeStepActionOpenParam1.setActionValue("180");
// 指令顺序号
businessRecipeStepActionOpenParam1.setSequence(1L);
recipeStepActionList.add(businessRecipeStepActionOpenParam1);
BusinessRecipeStepActionOpenParam businessRecipeStepActionOpenParam2 = new BusinessRecipeStepActionOpenParam();
// 指令名
businessRecipeStepActionOpenParam2.setActionName("recipeAction");
// 指令值
businessRecipeStepActionOpenParam2.setActionValue("2191000151000330031E50000530031E500005700000");
// 指令顺序号
businessRecipeStepActionOpenParam2.setSequence(2L);
recipeStepActionList.add(businessRecipeStepActionOpenParam2);
businessRecipeStepOpenParam.setRecipeStepActionList(recipeStepActionList);
request.setParamBusinessRecipeStepOpenParam(businessRecipeStepOpenParam);
// 通用参数
request.setTimestamp(System.currentTimeMillis());
request.setTopApiVersion("2.0");
request.setTopContentType("application/json");
request.setTopHttpMethod("alibaba.ailabs.iot.business.recipe.insertorupdate");
request.setTopResponseType("application/json");
// 接口调用
AlibabaAilabsIotBusinessRecipestepInsertorupdateResponse response = client.execute(request);
if (response.isSuccess()) {
System.out.println(response.getBody());
}
}
2.3.3 获取食谱分页数据
说明:返回结果是用户维度的食谱概要数据;
/**
* 获取食谱分页数据
*
* @throws ApiException
*/
public static void getRecipePageTest() throws ApiException {
DefaultTaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "30281416",
"4f9918cxxxxxxxxxxxxx6debcebaa");
AlibabaAilabsIotBusinessRecipeGetpageRequest request = new AlibabaAilabsIotBusinessRecipeGetpageRequest();
// 开放账号id
request.setOpenAccountId("a2uDllguxxxxxxM3wkl+w==");
// 分页页数
request.setPageNum(1L);
// 分页大小
request.setPageSize(10L);
// 通用参数
request.setTimestamp(System.currentTimeMillis());
request.setTopApiVersion("2.0");
request.setTopContentType("application/json");
request.setTopHttpMethod("alibaba.ailabs.iot.business.recipe.getdetail");
request.setTopResponseType("application/json");
// 接口调用
AlibabaAilabsIotBusinessRecipeGetpageResponse response = client.execute(request);
if (response.isSuccess()) {
System.out.println(response.getBody());
}
}
2.3.4 获取食谱详情数据
/**
* 获取食谱详情测试
*
* @throws ApiException
*/
public static void getRecipeDetailTest() throws ApiException {
DefaultTaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "30281416",
"4f9918cxxxxxxxxxxxxx6debcebaa");
AlibabaAilabsIotBusinessRecipeGetdetailRequest request = new AlibabaAilabsIotBusinessRecipeGetdetailRequest();
// 开放账号id
request.setOpenAccountId("a2uDllguxxxxxxM3wkl+w==");
// 食谱id
request.setBusinessRecipeId(1L);
// 通用参数
request.setTimestamp(System.currentTimeMillis());
request.setTopApiVersion("2.0");
request.setTopContentType("application/json");
request.setTopHttpMethod("alibaba.ailabs.iot.business.recipe.getdetail");
request.setTopResponseType("application/json");
// 接口调用
AlibabaAilabsIotBusinessRecipeGetdetailResponse response = client.execute(request);
if (response.isSuccess()) {
System.out.println(response.getBody());
}
}
3、补充文档
3.1 TOP接口操作文档
https://open.taobao.com/doc.htm?docId=101617&docType=1
3.2 OpenAccountId问题
请提供IOT开放平台账号邮箱给小二,由小二生成给到ISV;
3.3 厨电品类文档
https://www.aligenie.com/doc/357554/hiku59