xiongzhu 5 anos atrás
pai
commit
7dde034cfa

+ 17 - 82
src/main/java/com/izouma/awesomeAdmin/utils/CspUtil.java

@@ -17,11 +17,19 @@ import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
+import org.springframework.util.ResourceUtils;
 import org.springframework.web.client.RestTemplate;
 
 import javax.net.ssl.SSLContext;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
 import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.net.URLDecoder;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.security.cert.X509Certificate;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
@@ -30,6 +38,7 @@ import java.time.format.DateTimeFormatter;
 import java.util.Arrays;
 import java.util.Locale;
 import java.util.UUID;
+import java.util.stream.Collectors;
 
 public class CspUtil {
     private final static String username       = "njzm01";
@@ -38,9 +47,9 @@ public class CspUtil {
     private final static String serverRoot     = "https://api.5gcsp.mas.10086.cn/ocsp/developer";
     private final static String fileServerRoot = "https://api.5gcsp.mas.10086.cn/ocsp/fileservice";
 
-    private final static String CONTENT_TYPE_TEXT = "text/plain";
-    private final static String CONTENT_TYPE_FILE = "application/vnd.gsma.rcs-ft-http+xml";
-    private final static String CONTENT_TYPE_CARD = "application/vnd.gsma.botmessage.v1.0+json";
+    private final static String CONTENT_TYPE_TEXT  = "text/plain";
+    private final static String CONTENT_TYPE_FILE  = "application/vnd.gsma.rcs-ft-http+xml";
+    private final static String CONTENT_TYPE_CARD  = "application/vnd.gsma.botmessage.v1.0+json";
     private final static String CONTENT_TYPE_MULTI = "multipart/mixed; boundary=\"[next]\"";
 
     private static RestTemplate restTemplate;
@@ -195,85 +204,11 @@ public class CspUtil {
         OutboundMessageRequest request = new OutboundMessageRequest();
         request.setDestinationAddress(Arrays.asList(tel));
         request.setContentType(CONTENT_TYPE_MULTI);
-        String body = "--next\r\n" +
-                "Content-Type: application/vnd.gsma.botmessage.v1.0+json\r\n" +
-                "Content-Disposition: inline; filename=\"Message\"\r\n" +
-                "Content-Length: 902\r\n" +
-                "\r\n" +
-                "{\r\n" +
-                "    \"message\": {\r\n" +
-                "        \"generalPurposeCard\": {\r\n" +
-                "            \"layout\": {\r\n" +
-                "                \"cardOrientation\": \"VERTICAL\"\r\n" +
-                "            },\r\n" +
-                "            \"content\": {\r\n" +
-                "                \"media\": {\r\n" +
-                "                    \"mediaUrl\": \"https://cdn.server/path/media.mp4\",\r\n" +
-                "                    \"mediaContentType\": \"video/mp4\",\r\n" +
-                "                    \"mediaFileSize\": 2718288, \r\n" +
-                "                    \"thumbnailUrl\": \"https://cdn.server/path/media.png\",\r\n" +
-                "                    \"thumbnailContentType\": \"image/png\",\r\n" +
-                "                    \"thumbnailFileSize\": 3141,\r\n" +
-                "                    \"height\": \"MEDIUM_HEIGHT\"\r\n" +
-                "                },\r\n" +
-                "                \"title\": \"This is a single rich card.\",\r\n" +
-                "                \"description\": \"This is the description of the rich card. It's the first field that will be truncated if it exceeds the maximum width or height of a card.\"\r\n" +
-                "            }\r\n" +
-                "        }\r\n" +
-                "    }\r\n" +
-                "}\r\n" +
-                "--next\r\n" +
-                "Content-Type: application/vnd.gsma.botsuggestion.v1.0+json\r\n" +
-                "Content-Disposition: inline; filename=\"Chiplist.lst\"\r\n" +
-                "Content-Length: 550\r\n" +
-                "\r\n" +
-                "{\r\n" +
-                "    \"suggestions\": [\r\n" +
-                "        {\r\n" +
-                "            \"reply\": {\r\n" +
-                "                \"displayText\": \"Yes\",\r\n" +
-                "                \"postback\": {\r\n" +
-                "                    \"data\": \"set_by_chatbot_reply_yes\"\r\n" +
-                "                }\r\n" +
-                "            }\r\n" +
-                "        },\r\n" +
-                "        {\r\n" +
-                "            \"reply\": {\r\n" +
-                "                \"displayText\": \"No\",\r\n" +
-                "                \"postback\": {\r\n" +
-                "                    \"data\": \"set_by_chatbot_reply_no\"\r\n" +
-                "                }\r\n" +
-                "            }\r\n" +
-                "        },\r\n" +
-                "        {\r\n" +
-                "            \"action\": {\r\n" +
-                "                \"urlAction\": {\r\n" +
-                "                    \"openUrl\": {\r\n" +
-                "                        \"url\": \"https://www.google.com\"\r\n" +
-                "                    }\r\n" +
-                "                },\r\n" +
-                "                \"displayText\": \"Open website or deep link\",\r\n" +
-                "                \"postback\": {\r\n" +
-                "                    \"data\": \"set_by_chatbot_open_url\"\r\n" +
-                "                }\r\n" +
-                "            }\r\n" +
-                "        },\r\n" +
-                "        {\r\n" +
-                "            \"action\": {\r\n" +
-                "                \"dialerAction\": {\r\n" +
-                "                    \"dialPhoneNumber\": {\r\n" +
-                "                        \"phoneNumber\": \"+1650253000\"\r\n" +
-                "                    }\r\n" +
-                "                },\r\n" +
-                "                \"displayText\": \"Call a phone number\",\r\n" +
-                "                \"postback\": {\r\n" +
-                "                    \"data\": \"set_by_chatbot_open_dialer\"\r\n" +
-                "                }\r\n" +
-                "            }\r\n" +
-                "        }\r\n" +
-                "    ]\r\n" +
-                "}\r\n" +
-                "--next--\r\n";
+
+
+        String body = Files.lines(Paths.get(URLDecoder
+                .decode(CspUtil.class.getClassLoader().getResource("卡片悬浮.txt").getPath())))
+                .collect(Collectors.joining("\r\n"));
 
         System.out.println(body);
 

+ 12 - 5
src/main/java/com/izouma/awesomeAdmin/web/CallbackController.java

@@ -2,20 +2,27 @@ package com.izouma.awesomeAdmin.web;
 
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.HttpEntity;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 @RestController
+@RequestMapping("/msgCallback")
 @Slf4j
 public class CallbackController {
 
-    @RequestMapping("/msgCallback")
-    public void msgCallback(HttpEntity<String> httpEntity) {
-        log.info("msgCallback: \n{}", httpEntity.getBody());
+    @RequestMapping("/InboundMessageNotification/{chatbotURI}")
+    public void InboundMessageNotification(@PathVariable String chatbotURI, HttpEntity<String> httpEntity) {
+        log.info("InboundMessageNotification for {}: \n{}", chatbotURI, httpEntity.getBody());
     }
 
-    @RequestMapping("/auditCallback")
-    public void auditCallback(HttpEntity<String> httpEntity) {
+    @RequestMapping("/DeliveryInfoNotification/{chatbotURI}")
+    public void DeliveryInfoNotification(@PathVariable String chatbotURI, HttpEntity<String> httpEntity) {
+        log.info("DeliveryInfoNotification for {}: \n{}", chatbotURI, httpEntity.getBody());
+    }
+
+    @RequestMapping("/auditCallback/InboundMessageNotification/{chatbotURI}")
+    public void auditCallback(@PathVariable String chatbotURI, HttpEntity<String> httpEntity) {
         log.info("auditCallback: \n{}", httpEntity.getBody());
     }
 }

+ 79 - 0
src/main/resources/卡片悬浮.txt

@@ -0,0 +1,79 @@
+--next
+Content-Type: application/vnd.gsma.botmessage.v1.0+json
+Content-Disposition: inline; filename="Message"
+Content-Length: 902
+
+{
+    "message": {
+        "generalPurposeCard": {
+            "layout": {
+                "cardOrientation": "VERTICAL"
+            },
+            "content": {
+                "media": {
+                    "mediaUrl": "https://cdn.server/path/media.mp4",
+                    "mediaContentType": "video/mp4",
+                    "mediaFileSize": 2718288,
+                    "thumbnailUrl": "https://cdn.server/path/media.png",
+                    "thumbnailContentType": "image/png",
+                    "thumbnailFileSize": 3141,
+                    "height": "MEDIUM_HEIGHT"
+                },
+                "title": "This is a single rich card.",
+                "description": "This is the description of the rich card. It's the first field that will be truncated if it exceeds the maximum width or height of a card."
+            }
+        }
+    }
+}
+--next
+Content-Type: application/vnd.gsma.botsuggestion.v1.0+json
+Content-Disposition: inline; filename="Chiplist.lst"
+Content-Length: 550
+
+{
+    "suggestions": [
+        {
+            "reply": {
+                "displayText": "Yes",
+                "postback": {
+                    "data": "set_by_chatbot_reply_yes"
+                }
+            }
+        },
+        {
+            "reply": {
+                "displayText": "No",
+                "postback": {
+                    "data": "set_by_chatbot_reply_no"
+                }
+            }
+        },
+        {
+            "action": {
+                "urlAction": {
+                    "openUrl": {
+                        "url": "https://www.google.com"
+                    }
+                },
+                "displayText": "Open website or deep link",
+                "postback": {
+                    "data": "set_by_chatbot_open_url"
+                }
+            }
+        },
+        {
+            "action": {
+                "dialerAction": {
+                    "dialPhoneNumber": {
+                        "phoneNumber": "+1650253000"
+                    }
+                },
+                "displayText": "Call a phone number",
+                "postback": {
+                    "data": "set_by_chatbot_open_dialer"
+                }
+            }
+        }
+    ]
+}
+--next--