Explorar el Código

新增文旅咨资讯类API接口

wangcong hace 3 años
padre
commit
1ed535bb21

+ 65 - 0
src/main/java/com/zhiqiyun/open/router/apis/WlApi.java

@@ -1,6 +1,7 @@
 package com.zhiqiyun.open.router.apis;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.dliyun.oap.framework.annotation.ServiceMethod;
 import com.dliyun.oap.framework.annotation.ServiceMethodBean;
@@ -184,4 +185,68 @@ public class WlApi {
             return OapResponse.fail(String.valueOf(resp.statusCode()), "HTTP ERROR - " + resp.statusCode());
         }
     }
+
+
+    private OapResponse getListOapResponse(String uri, Map<String, String> dataMap) throws Exception {
+        Connection.Response resp = Jsoup.connect(wlapiServerHost + uri).data(dataMap).method(Connection.Method.GET).ignoreContentType(true).ignoreHttpErrors(true).execute();
+        if (resp.statusCode() == 200) {
+            JSONObject jsonObject = JSON.parseObject(resp.body());
+            String code = jsonObject.getString("code");
+            String msg = jsonObject.getString("msg");
+            if (StringUtils.equals("0", code)) {
+                JSONArray data = jsonObject.getJSONArray("data");
+                return OapResponse.success().setBody(data);
+            } else {
+                return OapResponse.fail(code, msg);
+            }
+        } else {
+            return OapResponse.fail(String.valueOf(resp.statusCode()), "HTTP ERROR - " + resp.statusCode());
+        }
+    }
+
+    @ServiceMethod(method = "wlapi.content.detail", title = "文章详情")
+    public OapResponse contentDetail(@RequestBody ContentRequest request) throws Exception {
+        Map<String, String> dataMap = new HashMap<>();
+        dataMap.put("id", request.getId().toString());
+        return this.getOapResponse("/openApi/content/detail", dataMap);
+    }
+
+    @ServiceMethod(method = "wlapi.content.list.xczx", title = "文旅宣传,旅游资讯")
+    public OapResponse contentListWlxc(@RequestBody ContentRequest request) throws Exception {
+        Map<String, String> dataMap = new HashMap<>();
+        if(request.getType().equals(1)){//文旅宣传
+            dataMap.put("codes", "cultural_tourism_line,popular_attractions");
+        }else {//旅游资讯
+            dataMap.put("codes", "travel_news,industry_dynamics,notice_announcement");
+        }
+        dataMap.put("isRecommend", "1");
+        dataMap.put("page", request.getPage().toString());
+        dataMap.put("limit", request.getLimit().toString());
+        return this.getListOapResponse("/openApi/content/list", dataMap);
+    }
+
+    @ServiceMethod(method = "wlapi.content.page.xwzx", title = "文旅路线,热门景点,旅发要闻,行业动态,通知公告")
+    public OapResponse contentListLyzx(@RequestBody ContentRequest request) throws Exception {
+        Map<String, String> dataMap = new HashMap<>();
+        switch (request.getType()) {
+            case 4://热门景点
+                dataMap.put("code", "popular_attractions");
+                break;
+            case 5://旅发要闻
+                dataMap.put("code", "travel_news");
+                break;
+            case 6://行业动态
+                dataMap.put("code", "industry_dynamics");
+                break;
+            case 7://通知公告
+                dataMap.put("code", "notice_announcement");
+                break;
+            default://文旅路线
+                dataMap.put("code", "cultural_tourism_line");
+                break;
+        }
+        dataMap.put("page", request.getPage().toString());
+        dataMap.put("limit", request.getLimit().toString());
+        return this.getOapResponse("/openApi/content/page", dataMap);
+    }
 }

+ 27 - 0
src/main/java/com/zhiqiyun/open/router/request/wlapi/ContentRequest.java

@@ -0,0 +1,27 @@
+package com.zhiqiyun.open.router.request.wlapi;
+
+
+import com.dliyun.oap.framework.annotation.ServiceParamField;
+import com.dliyun.oap.framework.request.AbstractOapRequest;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 文章查询参数
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ContentRequest extends AbstractOapRequest {
+
+    @ServiceParamField(describe = "文章ID")
+    private Long id;
+
+    @ServiceParamField(describe = "分类 1 文旅宣传 2 旅游资讯 3 文旅路线 4 热门景点 5 旅发要闻 6 行业动态 7 通知公告")
+    private Integer type;
+
+    @ServiceParamField(describe = "页数")
+    private Integer page = 1;
+
+    @ServiceParamField(describe = "每页参数数量")
+    private Integer limit = 10;
+}

+ 11 - 1
src/test/java/com/zhiqiyun/TestSdk.java

@@ -12,7 +12,7 @@ import java.util.*;
 public class TestSdk {
     private DefaultClient getClient() {
         return new DefaultClient(
-                "https://dbadmin.zhlc.liucheng.gov.cn/router",
+                "http://127.0.0.1:9800/router",
                 "220228000020",
                 "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCSTihNSHP5mqzMxkqxeEv150GWUcfdNy9eoD9wWhWO5re59vi8ownmfpcKOSHhqM09W+/jwC5xbqhYJN2kbCMWTyBHJ1BaoldX736aOPCmo0octyiq2N3Xx5JFnBh5asXdEO12lrOXGNqcwwq6iDuw2Na3H4u7p3QEIz6LKLcGJQIDAQAB",
                 AlgorithmType.RSA
@@ -20,6 +20,16 @@ public class TestSdk {
     }
 
     @Test
+    public void wlapixc() throws ClientException {
+        Map<String, Object> dataMap = new HashMap<>();
+        dataMap.put("id", "1201818145291862423");
+        dataMap.put("limit", "1");
+        dataMap.put("type", "3");
+        Response<Map<String, Object>> response = this.getClient().execute("wlapi.content.detail","1.0.0", dataMap);
+        System.out.println(JSON.toJSONString(response));
+    }
+
+    @Test
     public void wlapiHotel() throws ClientException {
         Map<String, Object> dataMap = new HashMap<>();
         dataMap.put("page", "1");