yumeng 4 rokov pred
rodič
commit
0fcd43dc4d

+ 12 - 0
pom.xml

@@ -44,6 +44,18 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.5.9</version>
+        </dependency>
+
+
         <!-- starter-test:junit + spring-test + mockito -->
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 0 - 29
src/main/java/cn/com/ctop/callback/conf/XxlMqConf.java

@@ -1,29 +0,0 @@
-package cn.com.ctop.callback.conf;
-
-import com.xxl.mq.client.factory.impl.XxlMqSpringClientFactory;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.stereotype.Component;
-
-@Component
-public class XxlMqConf {
-
-    // ---------------------- param ----------------------
-
-    @Value("${xxl.mq.admin.address}")
-    private String adminAddress;
-    @Value("${xxl.mq.accessToken}")
-    private String accessToken;
-
-
-    @Bean
-    public XxlMqSpringClientFactory getXxlMqConsumer(){
-
-        XxlMqSpringClientFactory xxlMqSpringClientFactory = new XxlMqSpringClientFactory();
-        xxlMqSpringClientFactory.setAdminAddress(adminAddress);
-        xxlMqSpringClientFactory.setAccessToken(accessToken);
-
-        return xxlMqSpringClientFactory;
-    }
-
-}

+ 34 - 10
src/main/java/cn/com/ctop/callback/controller/CallbackController.java

@@ -1,29 +1,53 @@
 package cn.com.ctop.callback.controller;
 
-import com.xxl.mq.client.message.XxlMqMessage;
-import com.xxl.mq.client.producer.XxlMqProducer;
+import cn.com.ctop.callback.util.HttpUtils;
+import com.alibaba.fastjson.JSONObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.HashMap;
+import java.util.Map;
+
 @Controller
 public class CallbackController {
     private Logger logger = LoggerFactory.getLogger(CallbackController.class);
+
     @ExceptionHandler({Exception.class})
     public String exception(Exception e) {
         e.printStackTrace();
         return e.getMessage();
     }
-    @RequestMapping("/callback")
+
+    @GetMapping("/kuaishouCallback")
     @ResponseBody
-    public String callback(){
-        String topic = "bytedance_auth";
-        String data = "时间戳:" + System.currentTimeMillis();
-        logger.info(data);
-        XxlMqProducer.produce(new XxlMqMessage(topic, data));
-        return "SUCCESS";
+    public String kuaishouCallback(HttpServletRequest request, HttpServletResponse response, @RequestParam("auth_code") String authCode, @RequestParam("state") String state) {
+        String result = null;
+        try {
+            JSONObject json = JSONObject.parseObject(state);
+            if (json == null) {
+                throw new Exception("回调信息为空");
+            }
+            Map<String, Object> map = new HashMap<>();
+            map.put("auth_code", authCode);
+            map.put("state", state);
+            String channelType = json.getString("channelType");
+            if (channelType.equals("jiaoyang")) {
+                result = HttpUtils.httpGet("http://192.168.1.8:8805/jeecg-boot/kuaishou", map, null);
+
+            } else {
+                result = HttpUtils.httpGet("http://129.28.197.250:8804/jeecg-boot/kuaishou", map, null);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            result = e.getMessage();
+        }
+        return result;
     }
 }

+ 71 - 0
src/main/java/cn/com/ctop/callback/util/HttpUtils.java

@@ -0,0 +1,71 @@
+package cn.com.ctop.callback.util;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+import java.net.URLEncoder;
+import java.util.Map;
+
+/**
+ * @author 宋英豪
+ */
+
+public class HttpUtils {
+    public static String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36";
+
+    public static String httpGet(String url, Map<String, Object> paramsMap, Map<String, String> headers) {
+        String result = null;
+        try {
+            // CloseableHttpClient httpClient = HttpClients.createDefault();
+            //创建参数列表
+            HttpClient httpclient = getHttpclient();
+            StringBuilder postBody = null;
+            if (paramsMap != null) {
+                postBody = new StringBuilder();
+                for (Map.Entry<String, Object> entry : paramsMap.entrySet()) {
+                    if (entry.getValue() == null) {
+                        continue;
+                    }
+                    postBody.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue().toString(),
+                            "utf-8")).append("&");
+                }
+                if (!paramsMap.isEmpty()) {
+                    postBody.deleteCharAt(postBody.length() - 1);
+                }
+            }
+            String urlStr;
+            if (postBody != null && postBody.length() > 0) {
+                urlStr = url + "?" + postBody;
+            } else {
+                urlStr = url;
+            }
+            HttpGet httpget = new HttpGet(urlStr);
+            httpget.setHeader("User-Agent", USER_AGENT);
+            if (headers != null) {
+                for (String key : headers.keySet()) {
+                    httpget.setHeader(key, headers.get(key));
+                }
+            }
+            HttpEntity respEntity;
+            HttpResponse response = httpclient.execute(httpget);
+            respEntity = response.getEntity();
+            result = EntityUtils.toString(respEntity);
+        } catch (Exception e) {
+
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+    public static HttpClient getHttpclient() {
+        RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout(180000).setConnectTimeout(30000)
+                .setConnectionRequestTimeout(30000).setStaleConnectionCheckEnabled(true).build();
+        return HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build();
+    }
+
+}