|
|
@@ -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}")
|