Ver código fonte

数据汇聚

孙永军 2 anos atrás
pai
commit
84c0849749

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

@@ -94,10 +94,10 @@ public class OauthRestController {
         return new RedirectDto("wait 还得找厂家对");
     }
 
-    @RequestMapping("weibo/callback")
+   /* @RequestMapping("weibo/callback")
     public void weiboCallback(WeiboCallbackDto dto, HttpServletRequest request) {
         logger.info("key", "oauth/weibo/callback", "data", JSON.toJSONString(dto));
-    }
+    }*/
 
     @RequestMapping("bilibili/code")
     @LoginRequired

+ 0 - 7
src/main/java/com/sxtvs/open/api/odata/dao/YoumeiAccountMapper.java

@@ -1,7 +0,0 @@
-package com.sxtvs.open.api.odata.dao;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.sxtvs.open.api.odata.entity.YoumeiAccount;
-
-public interface YoumeiAccountMapper extends BaseMapper<YoumeiAccount> {
-}

+ 0 - 28
src/main/java/com/sxtvs/open/api/odata/entity/YoumeiAccount.java

@@ -1,28 +0,0 @@
-package com.sxtvs.open.api.odata.entity;
-
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-import java.util.Date;
-
-@Data
-@Builder
-@NoArgsConstructor
-@AllArgsConstructor
-public class YoumeiAccount {
-
-    @TableId(type = IdType.INPUT)
-    private String openId;
-    private String accessToken;
-    private String refreshToken;
-    private Date atExpireTime;
-    private Date rtExpireTime;
-    private String nickName;
-    private Date createTime;
-    private Date updateTime;
-    private String secret;
-}

+ 0 - 70
src/main/java/com/sxtvs/open/api/odata/service/YoumeiTokenService.java

@@ -1,70 +0,0 @@
-package com.sxtvs.open.api.odata.service;
-
-import cn.hutool.core.date.DateField;
-import cn.hutool.core.date.DateTime;
-import cn.hutool.http.HttpUtil;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.sxtvs.open.api.odata.dao.YoumeiAccountMapper;
-import com.sxtvs.open.api.odata.entity.YoumeiAccount;
-import lombok.SneakyThrows;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.Date;
-import java.util.HashMap;
-
-@Service
-public class YoumeiTokenService extends ServiceImpl<YoumeiAccountMapper, YoumeiAccount> {
-
-    @Autowired
-    private ObjectMapper objectMapper;
-
-    @SneakyThrows
-    public void refreshToken() {
-        Date expireTime = new DateTime()
-                .offset(DateField.HOUR, 2)
-                .toJdkDate();
-
-        //检测快过期的at
-        for (YoumeiAccount youmeiAccount : this.lambdaQuery()
-                .le(YoumeiAccount::getAtExpireTime, expireTime)
-                .list()) {
-
-            HashMap<String, Object> params = new HashMap<>();
-            params.put("appId", youmeiAccount.getOpenId());
-            params.put("responseType", "code");
-            params.put("state", "");
-            String body = HttpUtil.post("https://api-open.51wyq.cn/dataapp/api/oauth2/authorize", params);
-            String authorizeCode = objectMapper.readTree(body).get("authorizeCode").get("authorizeCode").asText();
-
-            params.clear();
-            params.put("appId", youmeiAccount.getOpenId());
-            params.put("grantType", "authorization_code");
-            params.put("appSecret", youmeiAccount.getSecret());
-            params.put("authorizeCode", authorizeCode);
-
-            body = HttpUtil.post("https://api-open.51wyq.cn/dataapp/api/oauth2/token", params);
-            JsonNode jsonNode = objectMapper.readTree(body).get("accessToken");
-
-            String accessToken = jsonNode.get("accessToken").asText();
-            long expireIn = jsonNode.get("expireIn").asLong();
-
-            youmeiAccount.setAccessToken(accessToken);
-            youmeiAccount.setAtExpireTime(new Date(expireIn));
-            youmeiAccount.setUpdateTime(new Date());
-
-            this.updateById(youmeiAccount);
-        }
-    }
-
-    public static void main(String[] args) {
-        for (int i = 0; i < 30; i++) {
-            System.out.println(new DateTime()
-                    .offset(DateField.HOUR, i * 2)
-                    .toJdkDate());
-        }
-    }
-
-}

+ 9 - 0
src/main/java/com/sxtvs/open/api/youmei/entity/YoumeiAccount.java

@@ -6,6 +6,7 @@ import lombok.Getter;
 import lombok.Setter;
 
 import java.io.Serializable;
+import java.util.Date;
 
 /**
  * <p>
@@ -26,4 +27,12 @@ public class YoumeiAccount implements Serializable {
 
     private String accessToken;
 
+    private String refreshToken;
+    private Date atExpireTime;
+    private Date rtExpireTime;
+    private String nickName;
+    private Date createTime;
+    private Date updateTime;
+    private String secret;
+
 }

+ 0 - 64
src/main/java/com/sxtvs/open/core/http/APIResponseAdvice.java

@@ -1,64 +0,0 @@
-package com.sxtvs.open.core.http;
-
-import com.sxtvs.open.core.advice.APIResponse;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.http.HttpStatus;
-import org.springframework.validation.BindingResult;
-import org.springframework.validation.FieldError;
-import org.springframework.validation.ObjectError;
-import org.springframework.web.bind.MethodArgumentNotValidException;
-import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.bind.annotation.ResponseStatus;
-import org.springframework.web.bind.annotation.RestControllerAdvice;
-
-import java.util.List;
-
-@RestControllerAdvice
-@Slf4j
-public class APIResponseAdvice  {
-
-    @ExceptionHandler(MethodArgumentNotValidException.class)
-    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
-    public APIResponse validError(MethodArgumentNotValidException ex) {
-        log.error("校验未通过", ex);
-        BindingResult result = ex.getBindingResult();
-        StringBuilder builder = new StringBuilder();
-        if (result.hasErrors()) {
-
-            List<ObjectError> errors = result.getAllErrors();
-
-            errors.forEach(p -> {
-
-                FieldError fieldError = (FieldError) p;
-                builder.append(fieldError.getDefaultMessage()).append(";");
-                log.error("Data check failure : object{" + fieldError.getObjectName() + "},field{" + fieldError.getField() +
-                        "},errorMessage{" + fieldError.getDefaultMessage() + "}");
-
-            });
-
-        }
-
-        APIResponse apiResponse = new APIResponse();
-        apiResponse.setCode(-1);
-
-        apiResponse.setMessage(builder.toString());
-        return apiResponse;
-    }
-
-    /**
-     * 拦截未知的运行时异常
-     *
-     * @author fengshuonan
-     * @date 2020/12/16 15:12
-     */
-    @ExceptionHandler(Throwable.class)
-    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
-    public APIResponse serverError(Throwable ex) {
-        log.error("服务器运行异常", ex);
-        APIResponse apiResponse = new APIResponse();
-        apiResponse.setCode(-1);
-        apiResponse.setMessage(ex.getMessage());
-        return apiResponse;
-    }
-
-}