xiongzhu 5 years ago
parent
commit
7bd73d10c3

+ 23 - 0
src/main/java/com/izouma/awesomeAdmin/pojo/InboundMessage.java

@@ -0,0 +1,23 @@
+package com.izouma.awesomeAdmin.pojo;
+
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlCData;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import lombok.Data;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import java.util.List;
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@Data
+public class InboundMessage {
+    @JacksonXmlElementWrapper(useWrapping = false)
+    private List<String> destinationAddress;
+
+    private String senderAddress;
+
+    @JacksonXmlCData
+    private String bodyText;
+
+    private String contributionID;
+}

+ 1 - 9
src/main/java/com/izouma/awesomeAdmin/pojo/InboundMessageNotification.java

@@ -13,13 +13,5 @@ import java.util.List;
 @XmlAccessorType(XmlAccessType.FIELD)
 @Data
 public class InboundMessageNotification {
-    @JacksonXmlElementWrapper(useWrapping = false)
-    private List<String> destinationAddress;
-
-    private String senderAddress;
-
-    @JacksonXmlCData
-    private String bodyText;
-
-    private String contributionID;
+    private InboundMessage inboundMessage;
 }

+ 8 - 3
src/main/java/com/izouma/awesomeAdmin/web/CallbackController.java

@@ -3,7 +3,9 @@ package com.izouma.awesomeAdmin.web;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.dataformat.xml.XmlMapper;
+import com.izouma.awesomeAdmin.pojo.InboundMessage;
 import com.izouma.awesomeAdmin.pojo.InboundMessageNotification;
 import com.izouma.awesomeAdmin.utils.CspUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -33,17 +35,19 @@ public class CallbackController {
         log.info("InboundMessageNotification for {}: \n{}", chatbotURI, httpEntity.getBody());
 
         XmlMapper xmlMapper = new XmlMapper();
+        xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
         try {
-            InboundMessageNotification inboundMessage = xmlMapper
+            InboundMessageNotification inboundMessageNotification = xmlMapper
                     .readValue(httpEntity.getBody(), InboundMessageNotification.class);
+            InboundMessage inboundMessage = inboundMessageNotification.getInboundMessage();
             if (StringUtils.isNotEmpty(inboundMessage.getBodyText())) {
                 String body = new String(Base64.getDecoder()
                         .decode(inboundMessage.getBodyText()), StandardCharsets.UTF_8);
                 log.info("bodyText: \n{}", body);
                 JSONObject jsonObject = JSON.parseObject(body);
-                String replyText = jsonObject.getJSONObject("jsonObject").getJSONObject("reply")
+                String replyText = jsonObject.getJSONObject("response").getJSONObject("reply")
                         .getJSONObject("postback").getString("data");
-                if ("联系我们".equals(replyText)) {
+                if ("联系方式".equals(replyText)) {
                     Pattern pattern = Pattern.compile("sip:(?<phone>.+)@.+");
                     Matcher matcher = pattern.matcher(inboundMessage.getSenderAddress());
                     if (matcher.matches()) {
@@ -58,6 +62,7 @@ public class CallbackController {
             }
         } catch (Exception e) {
             e.printStackTrace();
+            log.error("InboundMessageNotification error", e);
         }
     }