req.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from simple_http_server import request_map
  2. from simple_http_server import Request
  3. import json
  4. import logging
  5. from mqtthelper import my_helper
  6. # import paho.mqtt.client as mqtt
  7. @request_map("/aligenieservice", method=["GET", "POST", "PUT"])
  8. def handle(request=Request()):
  9. logger = logging.getLogger()
  10. data = json.loads(request.body)
  11. logger.info(data)
  12. intentName = data['intentName']
  13. slotEntry = data['slotEntities'][0]
  14. standardValue = slotEntry['standardValue']
  15. slotValue = slotEntry['slotValue']
  16. standardValue = standardValue.replace("空格"," ")
  17. slotValue = slotValue.replace("空格"," ")
  18. payloadContent = '{\"intentName\":\"'+intentName+"\",\"standardValue\":\""+standardValue+"\",\"slotValue\":\""+slotValue+"\"}"
  19. my_helper.send(content=payloadContent)
  20. # client = mqtt.Client()
  21. # client.connect("10.8.8.4",1883,60)
  22. # client.publish("pccontrol",payload=payloadContent)
  23. replyContent = "正在为你打开"+slotValue
  24. response = {
  25. "returnCode": "0",
  26. "returnErrorSolution": "",
  27. "returnMessage": "",
  28. "returnValue": {
  29. "reply": replyContent,
  30. "resultType": "RESULT",
  31. "executeCode": "SUCCESS",
  32. "msgInfo": ""
  33. }
  34. }
  35. return response