Commit d0551ecea6a2b1fb36d74b1a145f951d64585502
1 parent
eff94aa9
Exists in
master
涂鸦学习红外接口对接完成
Showing
4 changed files
with
197 additions
and
0 deletions
Show diff stats
springboot/src/main/java/com/sincre/springboot/ApiModel/Codes.java
0 → 100644
| ... | ... | @@ -0,0 +1,39 @@ |
| 1 | +package com.sincre.springboot.ApiModel; | |
| 2 | + | |
| 3 | +import io.swagger.annotations.ApiModel; | |
| 4 | +import io.swagger.annotations.ApiModelProperty; | |
| 5 | + | |
| 6 | +@ApiModel | |
| 7 | +public class Codes { | |
| 8 | + @ApiModelProperty(name = "name",value = "学习到的红外名称") | |
| 9 | + private String name; | |
| 10 | + | |
| 11 | + public String getName() { | |
| 12 | + return name; | |
| 13 | + } | |
| 14 | + | |
| 15 | + public void setName(String name) { | |
| 16 | + this.name = name; | |
| 17 | + } | |
| 18 | + | |
| 19 | + public String getKey_name() { | |
| 20 | + return key_name; | |
| 21 | + } | |
| 22 | + | |
| 23 | + public void setKey_name(String key_name) { | |
| 24 | + this.key_name = key_name; | |
| 25 | + } | |
| 26 | + | |
| 27 | + public String getCode() { | |
| 28 | + return code; | |
| 29 | + } | |
| 30 | + | |
| 31 | + public void setCode(String code) { | |
| 32 | + this.code = code; | |
| 33 | + } | |
| 34 | + @ApiModelProperty(name = "key_name",value = "学习到的红外码按键名称") | |
| 35 | + private String key_name; | |
| 36 | + @ApiModelProperty(name = "code",value = "学习到的红外码") | |
| 37 | + private String code; | |
| 38 | + | |
| 39 | +} | ... | ... |
springboot/src/main/java/com/sincre/springboot/ApiModel/HWCode.java
0 → 100644
springboot/src/main/java/com/sincre/springboot/ApiModel/TuYaInfrared.java
| ... | ... | @@ -110,4 +110,16 @@ public class TuYaInfrared { |
| 110 | 110 | */ |
| 111 | 111 | @ApiModelProperty(name = "remote_name",value = "遥控名称") |
| 112 | 112 | private String remote_name; |
| 113 | + | |
| 114 | + public Codes getCodes() { | |
| 115 | + return codes; | |
| 116 | + } | |
| 117 | + | |
| 118 | + public void setCodes(Codes codes) { | |
| 119 | + this.codes = codes; | |
| 120 | + } | |
| 121 | + | |
| 122 | + @ApiModelProperty(name = "codes",value = "保存的红外信息") | |
| 123 | + private Codes codes; | |
| 124 | + | |
| 113 | 125 | } | ... | ... |
springboot/src/main/java/com/sincre/springboot/controller/TuYaYunController.java
| ... | ... | @@ -17,6 +17,7 @@ import org.apache.commons.lang3.StringUtils; |
| 17 | 17 | import org.springframework.web.bind.annotation.*; |
| 18 | 18 | import springfox.documentation.spring.web.json.Json; |
| 19 | 19 | |
| 20 | +import javax.annotation.security.PermitAll; | |
| 20 | 21 | import java.util.HashMap; |
| 21 | 22 | import java.util.Map; |
| 22 | 23 | |
| ... | ... | @@ -486,6 +487,137 @@ public class TuYaYunController { |
| 486 | 487 | } |
| 487 | 488 | |
| 488 | 489 | |
| 490 | + @ApiOperation("遥控器进入学习状态") | |
| 491 | + @ApiImplicitParams({ | |
| 492 | + @ApiImplicitParam(name="infrared_id",value = "设备ID",required = true,paramType = "path"), | |
| 493 | + @ApiImplicitParam(name="state",value = "学习模式,true是学习模式,false非学习模式",required = true) | |
| 494 | + }) | |
| 495 | + @GetMapping("{infrared_id}/getRemoteEnterStudy") | |
| 496 | + public ServerResponse getRemoteEnterStudy(@PathVariable String infrared_id,@RequestParam String state){ | |
| 497 | + | |
| 498 | + String apiUrl = String.format("/v1.0/infrareds/%s/learning-state?state=%s",infrared_id,state); | |
| 499 | + Map<String,String> map = headContent(); | |
| 500 | + String result = ApiHelper.doPut(TuYaCloudService.TuYaOpenUrl + apiUrl,map,""); | |
| 501 | + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class); | |
| 502 | + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult); | |
| 503 | + } | |
| 504 | + | |
| 505 | + @ApiOperation("查询到的红外码") | |
| 506 | + @ApiImplicitParams({ | |
| 507 | + @ApiImplicitParam(name="infrared_id",value = "设备ID",required = true,paramType = "path"), | |
| 508 | + @ApiImplicitParam(name="learning_time",value = "进入学习模式的时间",required = true) | |
| 509 | + }) | |
| 510 | + @GetMapping("{infrared_id}/getHWCode") | |
| 511 | + public ServerResponse getHWCode(@PathVariable String infrared_id,@RequestParam String learning_time){ | |
| 512 | + | |
| 513 | + String apiUrl = String.format("/v1.0/infrareds/%s/learning-codes?learning_time=%s",infrared_id,learning_time); | |
| 514 | + Map<String,String> map = headContent(); | |
| 515 | + String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,map); | |
| 516 | + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class); | |
| 517 | + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult); | |
| 518 | + } | |
| 519 | + | |
| 520 | + @ApiOperation("获取学习到的红外码(根据遥控器设备)") | |
| 521 | + @ApiImplicitParams({ | |
| 522 | + @ApiImplicitParam(name="infrared_id",value = "设备ID",required = true,paramType = "path"), | |
| 523 | + @ApiImplicitParam(name="remote_id",value = "遥控器ID",required = true,paramType = "path") | |
| 524 | + }) | |
| 525 | + @GetMapping("{infrared_id}/getHWCode/{remote_id}") | |
| 526 | + public ServerResponse getHWCodeByRemoteId(@PathVariable String infrared_id,@PathVariable String remote_id){ | |
| 527 | + | |
| 528 | + String apiUrl = String.format("/v1.0/infrareds/%s/remotes/%s/learning-codes",infrared_id,remote_id); | |
| 529 | + Map<String,String> map = headContent(); | |
| 530 | + String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,map); | |
| 531 | + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class); | |
| 532 | + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult); | |
| 533 | + } | |
| 534 | + | |
| 535 | + @ApiOperation("退出学习模式") | |
| 536 | + @ApiImplicitParams({ | |
| 537 | + @ApiImplicitParam(name="infrared_id",value = "设备ID",required = true,paramType = "path") | |
| 538 | + }) | |
| 539 | + @GetMapping("{infrared_id}/hwQuitSyudy") | |
| 540 | + public ServerResponse hwQuitSyudy(@PathVariable String infrared_id){ | |
| 541 | + | |
| 542 | + String apiUrl = String.format("/v1.0/infrareds/%s/learning-quit",infrared_id); | |
| 543 | + Map<String,String> map = headContent(); | |
| 544 | + String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,map); | |
| 545 | + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class); | |
| 546 | + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult); | |
| 547 | + } | |
| 548 | + | |
| 549 | + @ApiOperation("删除学习到的红外码") | |
| 550 | + @ApiImplicitParams({ | |
| 551 | + @ApiImplicitParam(name="infrared_id",value = "设备ID",required = true,paramType = "path"), | |
| 552 | + @ApiImplicitParam(name="learn_id",value = "学习到的红外ID",required = true,paramType = "path") | |
| 553 | + }) | |
| 554 | + @DeleteMapping("{infrared_id}/deteleLearnCode/{learn_id}") | |
| 555 | + public ServerResponse deteleLearnCode(@PathVariable String infrared_id,@PathVariable String learn_id){ | |
| 556 | + | |
| 557 | + String apiUrl = String.format("/v1.0/infrareds/%s/learning-codes/%s",infrared_id,learn_id); | |
| 558 | + Map<String,String> map = headContent(); | |
| 559 | + String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,map); | |
| 560 | + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class); | |
| 561 | + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult); | |
| 562 | + } | |
| 563 | + | |
| 564 | + @ApiOperation("保存学习到红外码") | |
| 565 | + @ApiImplicitParams({ | |
| 566 | + @ApiImplicitParam(name="infrared_id",value = "设备ID",required = true,paramType = "path") | |
| 567 | + }) | |
| 568 | + @PostMapping("{infrared_id}/saveLearnCode") | |
| 569 | + public ServerResponse saveLearnCode(@PathVariable String infrared_id,@RequestBody TuYaInfrared tuYaInfrared){ | |
| 570 | + | |
| 571 | + if(tuYaInfrared==null){ | |
| 572 | + return ServerResponse.createByErrorCodeMessage(400,"参数错误"); | |
| 573 | + } | |
| 574 | + | |
| 575 | + String apiUrl = String.format("/v1.0/infrareds/%s/learning-codes",infrared_id); | |
| 576 | + Map<String,String> map = headContent(); | |
| 577 | + String json = JSON.toJSONString(tuYaInfrared); | |
| 578 | + String result = ApiHelper.doPost(TuYaCloudService.TuYaOpenUrl + apiUrl,map,json); | |
| 579 | + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class); | |
| 580 | + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult); | |
| 581 | + } | |
| 582 | + | |
| 583 | + @ApiOperation("更新学习到红外码") | |
| 584 | + @ApiImplicitParams({ | |
| 585 | + @ApiImplicitParam(name="infrared_id",value = "设备ID",required = true,paramType = "path"), | |
| 586 | + @ApiImplicitParam(name="remote_index",value = "遥控器索引",required = true,paramType = "path") | |
| 587 | + }) | |
| 588 | + @PutMapping("{infrared_id}/editLearnCode/{remote_index}") | |
| 589 | + public ServerResponse saveLearnCode(@PathVariable String infrared_id,@PathVariable String remote_index,@RequestBody TuYaInfrared tuYaInfrared){ | |
| 590 | + | |
| 591 | + if(tuYaInfrared==null){ | |
| 592 | + return ServerResponse.createByErrorCodeMessage(400,"参数错误"); | |
| 593 | + } | |
| 594 | + | |
| 595 | + String apiUrl = String.format("/v1.0/infrareds/%s/learning-remotes/%s",infrared_id); | |
| 596 | + Map<String,String> map = headContent(); | |
| 597 | + String json = JSON.toJSONString(tuYaInfrared); | |
| 598 | + String result = ApiHelper.doPut(TuYaCloudService.TuYaOpenUrl + apiUrl,map,json); | |
| 599 | + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class); | |
| 600 | + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult); | |
| 601 | + } | |
| 602 | + @ApiOperation("下发到红外到的红外码") | |
| 603 | + @ApiImplicitParams({ | |
| 604 | + @ApiImplicitParam(name="infrared_id",value = "设备ID",required = true,paramType = "path"), | |
| 605 | + @ApiImplicitParam(name="remote_id",value = "遥控器设备ID(没有填TUYA)",required = true,paramType = "path"), | |
| 606 | + @ApiImplicitParam(name="code",value = "学习到的红外码",required = true) | |
| 607 | + }) | |
| 608 | + @GetMapping("{infrared_id}/getRemoteEnterStudy/{remote_id}") | |
| 609 | + public ServerResponse getRemoteEnterStudy(@PathVariable String infrared_id,@PathVariable String remote_id,@RequestParam String code){ | |
| 610 | + | |
| 611 | + String apiUrl = String.format("/v1.0/infrareds/%s/remote/%s/learning-codes",infrared_id,remote_id); | |
| 612 | + Map<String,String> map = headContent(); | |
| 613 | + HWCode hwCode = new HWCode(); | |
| 614 | + hwCode.setCode(code); | |
| 615 | + String jsonResult = JSON.toJSONString(hwCode); | |
| 616 | + String result = ApiHelper.doPost(TuYaCloudService.TuYaOpenUrl + apiUrl,map,jsonResult); | |
| 617 | + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class); | |
| 618 | + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult); | |
| 619 | + } | |
| 620 | + | |
| 489 | 621 | /** |
| 490 | 622 | * 请求头的参数 |
| 491 | 623 | * @return | ... | ... |