zyx 2 年之前
父节点
当前提交
dd773ec724

+ 12 - 8
src/main/java/com/sxtvs/open/api/odata/controller/OauthController.java

@@ -1,6 +1,8 @@
 package com.sxtvs.open.api.odata.controller;
 
 import cn.hutool.core.util.IdUtil;
+import com.sxtvs.open.api.odata.service.OauthService;
+import com.sxtvs.open.api.youmei.service.YoumeiAccountServiceImpl;
 import com.sxtvs.open.core.sls.AliyunLogger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
@@ -13,6 +15,10 @@ public class OauthController {
     public static String kuaishouClientKey = "ks657244072487589897";
     public static String kuaishouClientSecret = "d-LL1KyA6QSDzJG3AtzKZQ";
 
+
+    @Autowired
+    private OauthService oauthService;
+
     @Autowired
     private AliyunLogger logger;
 
@@ -64,14 +70,12 @@ public class OauthController {
         return "redirect:https://www.baidu.com";
     }
 
-//    @RequestMapping("weibo/code")
-//    public String weiboQrCode() {
-//        logger.info("key", "toutiaoQrCode");
-//        return "redirect:https://open.snssdk.com/oauth/authorize/?" +
-//                "client_key=awfrca76s1petwh0&response_type=code&" +
-//                "scope=toutiao.video.data,user_info&" +
-//                "redirect_uri=http%3A%2F%2Fimport.smcic.net%2Ftoutiao%2Fcallback-open";
-//    }
+    @RequestMapping("weibo/code")
+    public String weiboQrCode() {
+        var weiboUrl = oauthService.getWeiboUrl();
+        logger.info("key", "weiboQrCode","url",weiboUrl);
+        return weiboUrl;
+    }
 
     @RequestMapping("weibo/callback")
     public String weiboCallback(String code) {

+ 30 - 0
src/main/java/com/sxtvs/open/api/odata/service/OauthService.java

@@ -0,0 +1,30 @@
+package com.sxtvs.open.api.odata.service;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.sxtvs.open.api.youmei.service.YoumeiAccountServiceImpl;
+import lombok.SneakyThrows;
+import org.apache.hc.client5.http.fluent.Request;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.nio.charset.StandardCharsets;
+
+@Service
+public class OauthService {
+    @Autowired
+    private YoumeiAccountServiceImpl youmeiAccountService;
+
+    @Autowired
+    private ObjectMapper objectMapper;
+
+    @SneakyThrows
+    public String getWeiboUrl() {
+        var accessToken = youmeiAccountService.getSxgdAccount().getAccessToken();
+        var body = Request.get("https://api-open.51wyq.cn/dataapp/api/umei/fw/open/network_group/get_auth_url?accessToken=" + accessToken)
+                .execute()
+                .returnContent()
+                .asString(StandardCharsets.UTF_8);
+        String url = objectMapper.readTree(body).get("data").get("auth_url").asText();
+        return "redirect:" + url;
+    }
+}

+ 4 - 0
src/main/java/com/sxtvs/open/api/youmei/service/YoumeiAccountServiceImpl.java

@@ -31,6 +31,10 @@ public class YoumeiAccountServiceImpl extends ServiceImpl<YoumeiAccountMapper, Y
     @Autowired
     private AliyunLogger logger;
 
+    public YoumeiAccount getSxgdAccount() {
+        return getById("sxgd");
+    }
+
 
     private final HashMap<Integer, String> belongMap = new HashMap<>() {{
         put(9, "错别字、词");