|
@@ -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;
|
|
|
}
|
|
|
}
|