hurugang 5 лет назад
Родитель
Сommit
917e5ac276

+ 6 - 0
pom.xml

@@ -118,6 +118,12 @@
             <groupId>wsdl4j</groupId>
             <artifactId>wsdl4j</artifactId>
         </dependency>
+        <!-- 引入org.json所需依赖 -->
+        <dependency>
+            <groupId>org.json</groupId>
+            <artifactId>json</artifactId>
+            <version>20160810</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 2 - 4
src/main/java/cn/hnthyy/thmz/ThmzApplication.java

@@ -1,11 +1,9 @@
 package cn.hnthyy.thmz;
 
-import cn.hnthyy.thmz.webservice.service.impl.WebServiceTestImpl;
+import cn.hnthyy.thmz.webservice.service.impl.CriticalWebServiceImpl;
 import lombok.extern.slf4j.Slf4j;
-import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.boot.builder.SpringApplicationBuilder;
 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
 
@@ -20,7 +18,7 @@ public class ThmzApplication extends SpringBootServletInitializer {
         SpringApplication.run(ThmzApplication.class, args);
         String address = "http://127.0.0.1:7611/hubo/WebService";
         //发布WebService,WebServiceImpl类是WebServie接口的具体实现类
-        Endpoint.publish(address, new WebServiceTestImpl());
+        Endpoint.publish(address, new CriticalWebServiceImpl());
         System.out.println("使用WebServicePublishListener发布webservice成功!");
     }
 

+ 20 - 0
src/main/java/cn/hnthyy/thmz/webservice/service/CriticalWebService.java

@@ -0,0 +1,20 @@
+package cn.hnthyy.thmz.webservice.service;
+
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+//使用@WebService注解标注WebServiceI接口
+
+/**
+ * 危急值信息接收服务
+ */
+@WebService
+public interface CriticalWebService {
+    /**
+     * 接收危急值
+     * @param accessToken
+     * @param msg 消息体
+     * @return
+     */
+    @WebMethod
+    String criticalAccept(String accessToken ,String msg);
+}

+ 0 - 13
src/main/java/cn/hnthyy/thmz/webservice/service/IWebServiceTest.java

@@ -1,13 +0,0 @@
-package cn.hnthyy.thmz.webservice.service;
-
-import javax.jws.WebMethod;
-import javax.jws.WebService;
-//使用@WebService注解标注WebServiceI接口
-@WebService
-public interface IWebServiceTest {
-    @WebMethod
-    String sayHello(String name);
-     
-    @WebMethod
-    String save(String name,String pwd);
-}

+ 45 - 0
src/main/java/cn/hnthyy/thmz/webservice/service/impl/CriticalWebServiceImpl.java

@@ -0,0 +1,45 @@
+package cn.hnthyy.thmz.webservice.service.impl;
+
+
+import cn.hnthyy.thmz.webservice.service.CriticalWebService;
+import com.fasterxml.jackson.databind.JsonNode;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.json.JSONObject;
+
+import javax.jws.WebService;
+import java.util.HashMap;
+import java.util.Map;
+
+@Slf4j
+@WebService
+public class CriticalWebServiceImpl implements CriticalWebService {
+    private String token ="oI9#ur02cbBHdop87e6Y728Ax30IIlgd";
+    @Override
+    public String criticalAccept(String accessToken, String msg) {
+        Map<String,String> resultMap=new HashMap<>();
+        if(StringUtils.isBlank(accessToken)){
+            resultMap.put("Code","false");
+            resultMap.put("Message","token不能为空");
+            log.error("token不能为空");
+            JSONObject jsonObj=new JSONObject(resultMap);
+            return jsonObj.toString();
+        }
+        if(StringUtils.isBlank(msg)){
+            resultMap.put("Code","false");
+            resultMap.put("Message","msg为空");
+            log.error("msg为空");
+            JSONObject jsonObj=new JSONObject(resultMap);
+            return jsonObj.toString();
+        }
+        if(!token.equals(accessToken)){
+            resultMap.put("Code","false");
+            resultMap.put("Message","token校验失败");
+            log.error("token校验失败");
+            JSONObject jsonObj=new JSONObject(resultMap);
+            return jsonObj.toString();
+        }
+        JSONObject myJsonObject = new JSONObject(msg);
+        return null;
+    }
+}

+ 0 - 23
src/main/java/cn/hnthyy/thmz/webservice/service/impl/WebServiceTestImpl.java

@@ -1,23 +0,0 @@
-package cn.hnthyy.thmz.webservice.service.impl;
-
-import cn.hnthyy.thmz.webservice.service.IWebServiceTest;
-
-import javax.jws.WebService;
-
-@WebService
-public class WebServiceTestImpl implements IWebServiceTest {
- 
-    @Override
-    public String sayHello(String name) {
-        // TODO Auto-generated method stub
-        System.out.println("WebService sayHello "+name);
-        return "sayHello "+name;
-    }
- 
-    @Override
-    public String save(String name, String pwd) {
-        // TODO Auto-generated method stub
-        System.out.println("WebService save "+name+", "+pwd);
-        return "save Success";
-    }
-}

+ 17 - 0
src/test/java/cn/hnthyy/thmz/HotelTimeTest.java

@@ -1,6 +1,10 @@
 package cn.hnthyy.thmz;
 
 import org.apache.commons.lang3.StringUtils;
+import org.json.JSONObject;
+
+import java.util.HashMap;
+import java.util.Map;
 
 public class HotelTimeTest {
     private int IsAfternoon(int currentTime) {
@@ -25,5 +29,18 @@ public class HotelTimeTest {
             System.out.println(i);
         }
 
+
+
+
+        Map<String,String> map=new HashMap<>();
+        //Map 对象存入 用户名,密码,电话号码
+        map.put("username", "liyang");
+        map.put("pwd", "111111");
+        map.put("telephone", "152232323");
+
+        //Map 转成  JSONObject 字符串
+        JSONObject jsonObj=new JSONObject(map);
+        System.out.println(jsonObj.toString());
+
     }
 }