孙永军 2 anni fa
parent
commit
1bf9f7065a

+ 4 - 2
src/main/java/com/sxtvs/open/api/odata/controller/OauthController.java

@@ -1,7 +1,9 @@
 package com.sxtvs.open.api.odata.controller;
 
 import cn.hutool.core.util.StrUtil;
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.sxtvs.open.api.odata.service.*;
+import com.sxtvs.open.api.odata.service.impl.WbYmAccountServiceImpl;
 import com.sxtvs.open.core.sls.AliyunLogger;
 import jakarta.servlet.http.HttpServletRequest;
 import org.apache.commons.io.IOUtils;
@@ -62,10 +64,10 @@ public class OauthController {
     }
 
     @Autowired
-    private WeiboAccountService weiboAccountService;
+    private WbYmAccountServiceImpl weiboAccountService;
 
     @RequestMapping("weibo/callback")
-    public String weiboCallback(String code, String state) {
+    public String weiboCallback(String code, String state) throws JsonProcessingException {
         logger.info("key", "oauth/weibo/callback", "code", code);
         // todo 用户数据入库
         weiboAccountService.upsert(code);

+ 1 - 1
src/main/java/com/sxtvs/open/api/odata/controller/OauthRestController.java

@@ -91,7 +91,7 @@ public class OauthRestController {
     public RedirectDto weiboQrCode() {
         var weiboUrl = oauthService.getWeiboUrl();
         logger.info("key", "weiboQrCode", "url", weiboUrl);
-        return new RedirectDto("wait 还得找厂家对");
+        return new RedirectDto(weiboUrl);
     }
 
 //    @RequestMapping("weibo/callback")

+ 18 - 0
src/main/java/com/sxtvs/open/api/odata/controller/WbYmAccountController.java

@@ -0,0 +1,18 @@
+package com.sxtvs.open.api.odata.controller;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author syj
+ * @since 2023-03-16
+ */
+@RestController
+@RequestMapping("/odata/wbYmAccount")
+public class WbYmAccountController {
+
+}

+ 57 - 0
src/main/java/com/sxtvs/open/api/odata/dto/weibo/YMWeiboAccount.java

@@ -0,0 +1,57 @@
+package com.sxtvs.open.api.odata.dto.weibo;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+@NoArgsConstructor
+@Data
+public class YMWeiboAccount {
+
+    @JsonProperty("msg")
+    private String msg;
+    @JsonProperty("umeiTransactionId")
+    private String umeiTransactionId;
+    @JsonProperty("code")
+    private Integer code;
+    @JsonProperty("data")
+    private List<DataDTO> data;
+    @JsonProperty("transactionId")
+    private String transactionId;
+
+    @NoArgsConstructor
+    @Data
+    public static class DataDTO {
+        @JsonProperty("group_uid")
+        private Long groupUid;
+        @JsonProperty("network_group_id")
+        private Long networkGroupId;
+        @JsonProperty("user")
+        private UserDTO user;
+
+        @NoArgsConstructor
+        @Data
+        public static class UserDTO {
+            @JsonProperty("friends_count")
+            private Integer friendsCount;
+            @JsonProperty("rz_name")
+            private String rzName;
+            @JsonProperty("statuses_count")
+            private Integer statusesCount;
+            @JsonProperty("followers_count")
+            private Integer followersCount;
+            @JsonProperty("name")
+            private String name;
+            @JsonProperty("description")
+            private String description;
+            @JsonProperty("profile_image_url")
+            private String profileImageUrl;
+            @JsonProperty("location")
+            private String location;
+            @JsonProperty("id")
+            private String id;
+        }
+    }
+}

+ 35 - 0
src/main/java/com/sxtvs/open/api/odata/entity/WbYmAccount.java

@@ -0,0 +1,35 @@
+package com.sxtvs.open.api.odata.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import java.time.LocalDateTime;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author syj
+ * @since 2023-03-16
+ */
+@Getter
+@Setter
+@TableName("wb_ym_account")
+public class WbYmAccount implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private Long groupUid;
+
+    private Long networkGroupId;
+
+    private String nickName;
+
+    private LocalDateTime createTime;
+
+    private LocalDateTime updateTime;
+
+    private Integer groupType;
+}

+ 16 - 0
src/main/java/com/sxtvs/open/api/odata/mapper/WbYmAccountMapper.java

@@ -0,0 +1,16 @@
+package com.sxtvs.open.api.odata.mapper;
+
+import com.sxtvs.open.api.odata.entity.WbYmAccount;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author syj
+ * @since 2023-03-16
+ */
+public interface WbYmAccountMapper extends BaseMapper<WbYmAccount> {
+
+}

+ 16 - 0
src/main/java/com/sxtvs/open/api/odata/service/IWbYmAccountService.java

@@ -0,0 +1,16 @@
+package com.sxtvs.open.api.odata.service;
+
+import com.sxtvs.open.api.odata.entity.WbYmAccount;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author syj
+ * @since 2023-03-16
+ */
+public interface IWbYmAccountService extends IService<WbYmAccount> {
+
+}

+ 4 - 1
src/main/java/com/sxtvs/open/api/odata/service/OauthService.java

@@ -1,5 +1,6 @@
 package com.sxtvs.open.api.odata.service;
 
+import cn.hutool.core.util.IdUtil;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.sxtvs.open.api.odata.dto.wx.WxApiCreatePreAuthCodeRequest;
 import com.sxtvs.open.api.odata.dto.wx.WxApiCreatePreAuthCodeResponse;
@@ -29,7 +30,9 @@ public class OauthService {
     @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)
+        var state = IdUtil.nanoId();
+        var body = Request.get("https://api-open.51wyq.cn/dataapp/api/umei/fw/open/network_group/get_auth_url?accessToken=" + accessToken +
+                "&state="+state+"&redirect_uri=https://open.sxtvs.net/oauth/weibo/callback")
                 .execute()
                 .returnContent()
                 .asString(StandardCharsets.UTF_8);

+ 5 - 0
src/main/java/com/sxtvs/open/api/odata/service/WeiboAccountService.java

@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.http.HttpUtil;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.sxtvs.open.api.odata.dao.WeiboAccountMapper;
 import com.sxtvs.open.api.odata.dto.weibo.WeiboAccessTokenResponse;
@@ -11,6 +12,8 @@ import com.sxtvs.open.api.odata.dto.weibo.WeiboCreateTask;
 import com.sxtvs.open.api.odata.dto.weibo.show.UserShowResponse;
 import com.sxtvs.open.api.odata.entity.WeiboAccount;
 import com.sxtvs.open.api.odata.entity.WeiboTask;
+import com.sxtvs.open.api.odata.dto.weibo.YMWeiboAccount;
+import com.sxtvs.open.api.youmei.service.YoumeiAccountServiceImpl;
 import com.sxtvs.open.core.conf.Constant;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
@@ -34,6 +37,8 @@ public class WeiboAccountService extends ServiceImpl<WeiboAccountMapper, WeiboAc
     @Autowired
     private QrcodeLogServiceImpl qrcodeLogService;
 
+
+
     @SneakyThrows
     public void upsert(String code) {
         Map<String, Object> map = new HashMap<>();

+ 49 - 0
src/main/java/com/sxtvs/open/api/odata/service/impl/WbYmAccountServiceImpl.java

@@ -0,0 +1,49 @@
+package com.sxtvs.open.api.odata.service.impl;
+
+import cn.hutool.http.HttpUtil;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.sxtvs.open.api.odata.dto.weibo.YMWeiboAccount;
+import com.sxtvs.open.api.odata.entity.WbYmAccount;
+import com.sxtvs.open.api.odata.mapper.WbYmAccountMapper;
+import com.sxtvs.open.api.odata.service.IWbYmAccountService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.sxtvs.open.api.youmei.service.YoumeiAccountServiceImpl;
+import jakarta.annotation.Resource;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+import java.util.Map;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author syj
+ * @since 2023-03-16
+ */
+@Service
+public class WbYmAccountServiceImpl extends ServiceImpl<WbYmAccountMapper, WbYmAccount> implements IWbYmAccountService {
+    @Resource
+    private YoumeiAccountServiceImpl youmeiAccountService;
+
+    @Resource
+    private ObjectMapper objectMapper;
+
+    public void upsert(String networkGroupId) throws JsonProcessingException {
+        String accessToken = youmeiAccountService.getSxgdAccount().getAccessToken();
+        String body = HttpUtil.createPost("https://api-open.51wyq.cn/dataapp/api/umei/fw/open/network_group/get_weibo_user_info")
+                .form(Map.of("accessToken", accessToken, "network_group_ids", new String[]{networkGroupId}))
+                .execute().body();
+        YMWeiboAccount o = objectMapper.readValue(body, YMWeiboAccount.class);
+
+        WbYmAccount wbYmAccount = new WbYmAccount();
+        wbYmAccount.setGroupUid(o.getData().get(0).getGroupUid());
+        wbYmAccount.setNetworkGroupId(o.getData().get(0).getNetworkGroupId());
+        wbYmAccount.setNickName(o.getData().get(0).getUser().getName());
+        wbYmAccount.setGroupType(1);
+        wbYmAccount.setUpdateTime(LocalDateTime.now());
+        saveOrUpdate(wbYmAccount);
+    }
+}