GetMachineQrCodeAdapt.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2017-2020 吴学文 and java110 team.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.java110.job.adapt.hcIot;
  17. import com.alibaba.fastjson.JSONObject;
  18. import com.java110.core.client.RestTemplate;
  19. import com.java110.core.factory.GenerateCodeFactory;
  20. import com.java110.job.adapt.DatabusAdaptImpl;
  21. import com.java110.vo.ResultVo;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.http.HttpEntity;
  24. import org.springframework.http.HttpMethod;
  25. import org.springframework.http.HttpStatus;
  26. import org.springframework.http.ResponseEntity;
  27. import org.springframework.stereotype.Component;
  28. import org.springframework.util.MultiValueMap;
  29. /**
  30. * 开门适配器
  31. * 接口协议地址: https://gitee.com/java110/MicroCommunityThings/blob/master/back/docs/api.md
  32. *
  33. * @desc add by 吴学文 15:29
  34. */
  35. @Component(value = "getMachineQrCodeAdapt")
  36. public class GetMachineQrCodeAdapt extends DatabusAdaptImpl {
  37. @Autowired
  38. RestTemplate outRestTemplate;
  39. @Override
  40. public ResultVo getQRcode(JSONObject paramIn) {
  41. JSONObject postParameters = new JSONObject();
  42. postParameters.put("taskId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_machineTranslateId));
  43. postParameters.put("machineCode", paramIn.getString("machineCode"));
  44. postParameters.put("userId", paramIn.getString("userId"));
  45. HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity(postParameters.toJSONString(), getHeaders(outRestTemplate));
  46. ResponseEntity<String> responseEntity = outRestTemplate.exchange(IotConstant.getUrl(IotConstant.GET_QRCODE), HttpMethod.POST, httpEntity, String.class);
  47. if (responseEntity.getStatusCode() != HttpStatus.OK) {
  48. return new ResultVo(ResultVo.CODE_ERROR, responseEntity.getBody());
  49. }
  50. JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
  51. return new ResultVo(paramOut.getInteger("code"), paramOut.getString("msg"), paramOut.getString("data"));
  52. }
  53. }