xiongzhu 5 năm trước cách đây
mục cha
commit
0628c201f7

+ 25 - 0
src/main/java/com/izouma/awesomeAdmin/pojo/InboundMessageNotification.java

@@ -0,0 +1,25 @@
+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 javax.xml.bind.annotation.XmlRootElement;
+import java.util.List;
+
+@XmlRootElement(name = "msg:inboundMessageNotification")
+@XmlAccessorType(XmlAccessType.FIELD)
+@Data
+public class InboundMessageNotification {
+    @JacksonXmlElementWrapper(useWrapping = false)
+    private List<String> destinationAddress;
+
+    private String senderAddress;
+
+    @JacksonXmlCData
+    private String bodyText;
+
+    private String contributionID;
+}

+ 45 - 0
src/main/java/com/izouma/awesomeAdmin/web/CallbackController.java

@@ -1,11 +1,28 @@
 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.dataformat.xml.XmlMapper;
+import com.izouma.awesomeAdmin.pojo.InboundMessageNotification;
+import com.izouma.awesomeAdmin.utils.CspUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.StringUtils;
 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;
 
+import java.io.File;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 @RestController
 @RequestMapping("/msgCallback")
 @Slf4j
@@ -14,6 +31,34 @@ public class CallbackController {
     @RequestMapping("/InboundMessageNotification/{chatbotURI}")
     public void InboundMessageNotification(@PathVariable String chatbotURI, HttpEntity<String> httpEntity) {
         log.info("InboundMessageNotification for {}: \n{}", chatbotURI, httpEntity.getBody());
+
+        XmlMapper xmlMapper = new XmlMapper();
+        try {
+            InboundMessageNotification inboundMessage = xmlMapper
+                    .readValue(httpEntity.getBody(), InboundMessageNotification.class);
+            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")
+                        .getJSONObject("postback").getString("data");
+                if ("联系方式".equals(replyText)) {
+                    Pattern pattern = Pattern.compile("sip:(?<phone>.+)@.+");
+                    Matcher matcher = pattern.matcher(inboundMessage.getSenderAddress());
+                    if (matcher.matches()) {
+                        String phone = matcher.group("phone");
+                        String url = CspUtil.serverRoot + "/messaging/group/plain/outbound/sip:" + CspUtil.chatBotId + "/requests";
+                        CspUtil.send(url, CspUtil.CONTENT_TYPE_CARD, FileUtils.readFileToString(new File(URLDecoder
+                                .decode(CspUtil.class.getClassLoader().getResource("联系方式.json")
+                                        .getPath(), "utf-8")), StandardCharsets.UTF_8)
+                                .replaceAll("\n", "\r\n"), "tel:" + phone);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 
     @RequestMapping("/DeliveryInfoNotification/{chatbotURI}")

+ 18 - 46
src/main/resources/1.xml

@@ -1,46 +1,18 @@
-<OutboundMessageRequest>
-    <destinationAddress>tel:+8618362933705</destinationAddress>
-    <contentType>application/vnd.gsma.botmessage.v1.0+json</contentType>
-    <bodyText><![CDATA[{
-  "message": {
-    "generalPurposeCardCarousel": {
-      "layout": {
-        "cardWidth": "MEDIUM_WIDTH"
-      },
-      "content": [
-        {
-          "media": {
-            "mediaUrl": "https://ticket-exchange.oss-cn-hangzhou.aliyuncs.com/image/2021-03-12-17-27-20KVwzhqcw.png",
-            "mediaContentType": "image/png",
-            "mediaFileSize": 20140,
-            "thumbnailUrl": "https://ticket-exchange.oss-cn-hangzhou.aliyuncs.com/image/2021-03-12-17-27-20KVwzhqcw.png",
-            "thumbnailContentType": "image/png",
-            "thumbnailFileSize": 20140,
-            "height": "SHORT_HEIGHT"
-          },
-          "title": "南京市发生3.0级地震",
-          "description": "请注意避险",
-          "suggestions": [
-            {
-              "action": {
-                "urlAction": {
-                  "openUrl": {
-                    "url": "http://5gcsp.izouma.com/alertPage?id=19",
-                    "fallbackUrl": "https://map.baidu.com/mobile/webapp/search/search/qt=inf&uid=2a7a25ec000f3a636c3e1bed/newmap=1&sharecallbackflag=poiDetailPage&vt=map&da_from=weixin&openna=1"
-                  }
-                },
-                "displayText": "立即查看",
-                "postback": {
-                  "data": "set_by_chatbot_open_url"
-                }
-              }
-            }
-          ]
-        }
-      ]
-    }
-  }
-}
-]]></bodyText>
-    <contributionID>5d4594be-4dae-4ec2-ab5c-3301f0888b67</contributionID>
-</OutboundMessageRequest>
+<msg:inboundMessageNotification xmlns:msg="urn:oma:xml:rest:netapi:messaging:1">
+    <inboundMessage>
+        <destinationAddress>sip:10650511101001400001@botplatform.rcs.chinamobile.com</destinationAddress>
+        <senderAddress>sip:+8618362933705@js.5GMC.ims.mnc000.mcc460.3gppnetwork.org</senderAddress>
+        <dateTime>2021-03-12T18:53:36.523+08:00</dateTime>
+        <messageId>1e91cd02-654f-1039-9774-f58991691825</messageId>
+        <contentType>application/vnd.gsma.botsuggestion.response.v1.0+json</contentType>
+        <contentEncoding>base64</contentEncoding>
+        <bodyText>
+            <![CDATA[eyJyZXNwb25zZSI6eyJyZXBseSI6eyJkaXNwbGF5VGV4dCI6IuiBlOezu+aIkeS7rCIsInBvc3RiYWNrIjp7ImRhdGEiOiLogZTns7vmlrnlvI8ifX19fQ==]]></bodyText>
+        <conversationID>a89f4161-72ac-4932-b713-acbd9668c626</conversationID>
+        <contributionID>1e9203fa-654f-1039-a423-3b9253a52412</contributionID>
+        <serviceCapability>
+            <capabilityId>ChatbotSA</capabilityId>
+            <version>+g.gsma.rcs.botversion=&quot;#=1,#=2&quot;</version>
+        </serviceCapability>
+    </inboundMessage>
+</msg:inboundMessageNotification>

+ 1 - 1
src/main/vue/src/views/AlertList.vue

@@ -29,7 +29,7 @@
             <el-table-column prop="level" label="震级"> </el-table-column>
             <el-table-column prop="feeling" label="震感"> </el-table-column>
             <el-table-column prop="arriveTime" label="时间"> </el-table-column>
-            <el-table-column label="操作" align="center" fixed="right" min-width="150">
+            <el-table-column label="操作" align="center" fixed="right" width="250">
                 <template slot-scope="{ row }">
                     <el-button @click="onSend(row)" size="mini">发送</el-button>
                     <el-button @click="editRow(row)" type="primary" size="mini" plain>编辑</el-button>

+ 1 - 1
src/main/vue/src/views/ArticleTemplateList.vue

@@ -26,7 +26,7 @@
             <el-table-column v-if="multipleMode" align="center" type="selection" width="50"> </el-table-column>
             <el-table-column prop="id" label="ID" width="100"> </el-table-column>
             <el-table-column prop="name" label="名称"> </el-table-column>
-            <el-table-column label="操作" align="center" fixed="right" min-width="150">
+            <el-table-column label="操作" align="center" fixed="right" width="250">
                 <template slot-scope="{ row }">
                     <el-button @click="onSend(row)" size="mini">发送</el-button>
                     <el-button @click="editRow(row)" type="primary" size="mini" plain>编辑</el-button>

+ 12 - 0
src/test/java/com/izouma/awesomeAdmin/CommonTest.java

@@ -31,6 +31,7 @@ import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.*;
 import java.util.List;
+import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import static java.nio.file.StandardOpenOption.CREATE;
@@ -179,4 +180,15 @@ public class CommonTest {
                 .addCall("电话", "15077886171", "333");
         System.out.println(jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(suggestions));
     }
+
+    @Test
+    public void testReg() {
+        String str = "sip:+8618362933705@js.5GMC.ims.mnc000.mcc460.3gppnetwork.org";
+        Pattern pattern = Pattern.compile("sip:(?<phone>.+)@.+");
+        Matcher matcher = pattern.matcher(str);
+        if (matcher.matches()) {
+            String phone = matcher.group("phone");
+            System.out.println(phone);
+        }
+    }
 }