zyx 2 anni fa
parent
commit
7c4da69388
35 ha cambiato i file con 816 aggiunte e 18 eliminazioni
  1. 1 0
      build.gradle
  2. 49 14
      src/main/java/com/sxtvs/open/api/odata/controller/OauthController.java
  3. 29 0
      src/main/java/com/sxtvs/open/api/odata/controller/OauthRestController.java
  4. 17 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/WxApiAuthorizerTokenRequest.java
  5. 17 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/WxApiAuthorizerTokenResponse.java
  6. 15 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/WxApiComponentTokenRequest.java
  7. 15 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/WxApiComponentTokenResponse.java
  8. 13 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/WxApiCreatePreAuthCodeRequest.java
  9. 15 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/WxApiCreatePreAuthCodeResponse.java
  10. 14 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/WxApiGetAuthorizerInfoRequest.java
  11. 14 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/WxCommonResponse.java
  12. 45 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/apiquery/AuthorizationInfo.java
  13. 29 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/apiquery/ConfirmInfo.java
  14. 22 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/apiquery/FuncInfoItem.java
  15. 15 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/apiquery/FuncscopeCategory.java
  16. 15 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/apiquery/WxApiQueryAuthRequest.java
  17. 18 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/apiquery/WxApiQueryAuthResponse.java
  18. 24 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/authorization/AuthorizationInfo.java
  19. 25 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/authorization/AuthorizationInfoResponse.java
  20. 71 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/authorization/AuthorizerInfo.java
  21. 43 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/authorization/BusinessInfo.java
  22. 15 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/authorization/FuncInfoItem.java
  23. 15 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/authorization/FuncscopeCategory.java
  24. 15 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/authorization/ServiceTypeInfo.java
  25. 15 0
      src/main/java/com/sxtvs/open/api/odata/dto/wx/authorization/VerifyTypeInfo.java
  26. 22 0
      src/main/java/com/sxtvs/open/api/odata/service/OauthService.java
  27. 68 0
      src/main/java/com/sxtvs/open/api/odata/wxutil/PKCS7Encoder.java
  28. 46 0
      src/main/java/com/sxtvs/open/api/odata/wxutil/WxCrypt.java
  29. 35 0
      src/main/java/com/sxtvs/open/api/odata/wxutil/WxXmlUtil.java
  30. 14 2
      src/main/java/com/sxtvs/open/core/auth/LoginInterceptor.java
  31. 1 0
      src/main/java/com/sxtvs/open/core/conf/Constant.java
  32. 26 0
      src/main/java/com/sxtvs/open/core/conf/OauthConfig.java
  33. 11 0
      src/main/java/com/sxtvs/open/core/sls/AliyunLogger.java
  34. 11 2
      src/main/resources/application.yml
  35. 16 0
      src/main/resources/templates/weixin-code.html

+ 1 - 0
build.gradle

@@ -47,6 +47,7 @@ dependencies {
     implementation 'com.aliyun.openservices:aliyun-log-producer:0.3.11'
     implementation 'org.springframework.boot:spring-boot-starter-data-redis'
     implementation 'org.springframework.boot:spring-boot-starter-web'
+
     compileOnly 'org.projectlombok:lombok'
     annotationProcessor 'org.projectlombok:lombok'
     testImplementation 'org.springframework.boot:spring-boot-starter-test'

+ 49 - 14
src/main/java/com/sxtvs/open/api/odata/controller/OauthController.java

@@ -1,20 +1,22 @@
 package com.sxtvs.open.api.odata.controller;
 
 import cn.hutool.core.util.IdUtil;
+import com.sxtvs.open.api.odata.dto.wx.WxApiCreatePreAuthCodeResponse;
 import com.sxtvs.open.api.odata.service.OauthService;
-import com.sxtvs.open.api.youmei.service.YoumeiAccountServiceImpl;
+import com.sxtvs.open.core.conf.OauthConfig;
 import com.sxtvs.open.core.sls.AliyunLogger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.servlet.ModelAndView;
+
+import java.util.Map;
 
 @Controller
 @RequestMapping("oauth")
 public class OauthController {
 
-    public static String kuaishouClientKey = "ks657244072487589897";
-    public static String kuaishouClientSecret = "d-LL1KyA6QSDzJG3AtzKZQ";
-
 
     @Autowired
     private OauthService oauthService;
@@ -25,7 +27,7 @@ public class OauthController {
     @RequestMapping("douyin/code")
     public String douyinQrCode() {
         var state = IdUtil.nanoId();
-        logger.info("key", "douyinQrCode","state",state);
+        logger.info("key", "oauth/douyin/code", "state", state);
         return "redirect:https://open.douyin.com/platform/oauth/connect/?" +
                 "client_key=awfrca76s1petwh0&response_type=code&" +
                 "scope=video.data%2Cfans.list%2Cdata.external.item%2Cdata.external.user%2Cfans.data%2Cvideo.list%2Crenew_refresh_token%2Cuser_info&" +
@@ -34,30 +36,30 @@ public class OauthController {
 
     @RequestMapping("douyin/callback")
     public String douyinCallback(String code, String state) {
-        logger.info("key", "douyinCallback", "code", code, "state", state);
+        logger.info("key", "oauth/douyin/callback", "code", code, "state", state);
         return "redirect:https://www.baidu.com";
     }
 
     @RequestMapping("kuaishou/code")
     public String kuaishouQrCode() {
         var state = IdUtil.nanoId();
-        logger.info("key", "kuaishouQrCode","state",state);
+        logger.info("key", "oauth/douyin/code", "state", state);
         return "redirect:https://open.kuaishou.com/oauth2/connect?" +
-                "app_id=" + kuaishouClientKey + "&response_type=code&" +
+                "app_id=" + OauthConfig.kuaishouClientKey + "&response_type=code&" +
                 "scope=user_info%2Cuser_video_info&" +
                 "redirect_uri=https%3A%2F%2Fimport.smcic.net%2Fkuaishou%2Fcallback-open&state=" + state;
     }
 
     @RequestMapping("kuaishou/callback")
     public String kuaishouCallback(String code, String state) {
-        logger.info("key", "kuaishouCallback", "code", code,"state",state);
+        logger.info("key", "oauth/kuaishou/callback", "code", code, "state", state);
         return "redirect:https://www.baidu.com";
     }
 
     @RequestMapping("toutiao/code")
     public String toutiaoQrCode() {
         var state = IdUtil.nanoId();
-        logger.info("key", "toutiaoQrCode","state",state);
+        logger.info("key", "oauth/toutiao/code", "state", state);
         return "redirect:https://open.snssdk.com/oauth/authorize/?" +
                 "client_key=awfrca76s1petwh0&response_type=code&" +
                 "scope=toutiao.video.data,user_info&" +
@@ -66,20 +68,53 @@ public class OauthController {
 
     @RequestMapping("toutiao/callback")
     public String toutiaoCallback(String code, String state) {
-        logger.info("key", "toutiaoCallback", "code", code,"state",state);
+        logger.info("key", "oauth/toutiao/callback", "code", code, "state", state);
         return "redirect:https://www.baidu.com";
     }
 
     @RequestMapping("weibo/code")
     public String weiboQrCode() {
+        logger.info("key", "oauth/weibo/code");
         var weiboUrl = oauthService.getWeiboUrl();
-        logger.info("key", "weiboQrCode","url",weiboUrl);
+        logger.info("key", "weiboQrCode", "url", weiboUrl);
         return weiboUrl;
     }
 
     @RequestMapping("weibo/callback")
-    public String weiboCallback(String code) {
-        logger.info("key", "weiboCallback", "code", code);
+    public String weiboCallback(String code, String state) {
+        logger.info("key", "oauth/weibo/callback", "code", code);
+        return "redirect:https://www.baidu.com";
+    }
+
+    @RequestMapping("bilibili/code")
+    public String bilibiliQrCode() {
+        var state = IdUtil.nanoId();
+        logger.info("key", "oauth/bilibili/code", "state", state);
+        return "redirect:https://passport.bilibili.com/register/pc_oauth2.html#/?client_id=e79e6fdef9d446d7" +
+                "&return_url=https%3A%2F%2Fimport.smcic.net%2Fbilibili%2Fcallback-open&response_type=code&state=" + state;
+    }
+
+    @RequestMapping("bilibili/callback")
+    public String bilibiliCallback(String code, String state) {
+        logger.info("key", "oauth/bilibili/callback", "code", code, "state", state);
+        return "redirect:https://www.baidu.com";
+    }
+
+    @RequestMapping("weixin/code")
+    public ModelAndView weixinQrCode() {
+        logger.info("key", "oauth/weixin/code");
+        WxApiCreatePreAuthCodeResponse preAuthCodeResponse = oauthService.createPreAuthCodeResponse();
+        ModelAndView view = new ModelAndView();
+        view.setViewName("weixin-code");
+        view.addObject("pre_auth_code", preAuthCodeResponse.getPreAuthCode());
+        return view;
+    }
+
+    @RequestMapping("weixin/wx7040933fd0e4b0e8/callback")
+    public String callback(
+            @RequestParam("auth_code") String authCode,
+            @RequestParam("expires_in") Integer expiresIn) {
+        logger.info("key", "oauth/wx7040933fd0e4b0e8/code", "data", Map.of("authCode", authCode, "expiresIn", expiresIn));
         return "redirect:https://www.baidu.com";
     }
 }

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

@@ -0,0 +1,29 @@
+package com.sxtvs.open.api.odata.controller;
+
+import com.sxtvs.open.api.odata.wxutil.WxCrypt;
+import com.sxtvs.open.api.odata.wxutil.WxXmlUtil;
+import com.sxtvs.open.core.sls.AliyunLogger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController("oauth")
+public class OauthRestController {
+
+    @Autowired
+    private AliyunLogger logger;
+
+    @Autowired
+    private StringRedisTemplate redisTemplate;
+
+    @RequestMapping("weixin/auth")
+    public String auth(@RequestBody String body) {
+        logger.info("body", body, "key", "oauth/weixin/auth");
+        String xml = WxCrypt.decrypt(WxXmlUtil.getEncrypt(body));
+        String componentVerifyTicket = WxXmlUtil.getComponentVerifyTicket(xml);
+        redisTemplate.opsForValue().set("WX_TICKET", componentVerifyTicket);
+        return "success";
+    }
+}

+ 17 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/WxApiAuthorizerTokenRequest.java

@@ -0,0 +1,17 @@
+package com.sxtvs.open.api.odata.dto.wx;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+
+@Data
+public class WxApiAuthorizerTokenRequest {
+    @JsonProperty("component_access_token")
+    private String componentAccessToken;
+    @JsonProperty("component_appid")
+    private String componentAppid;
+    @JsonProperty("authorizer_appid")
+    private String authorizerAppid;
+    @JsonProperty("authorizer_refresh_token")
+    private String authorizerRefreshToken;
+}

+ 17 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/WxApiAuthorizerTokenResponse.java

@@ -0,0 +1,17 @@
+package com.sxtvs.open.api.odata.dto.wx;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class WxApiAuthorizerTokenResponse extends WxCommonResponse {
+    @JsonProperty("authorizer_access_token")
+    private String authorizerAccessToken;
+    @JsonProperty("expires_in")
+    private Integer expiresIn;
+    @JsonProperty("authorizer_refresh_token")
+    private String authorizerRefreshToken;
+}

+ 15 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/WxApiComponentTokenRequest.java

@@ -0,0 +1,15 @@
+package com.sxtvs.open.api.odata.dto.wx;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+
+@Data
+public class WxApiComponentTokenRequest  {
+    @JsonProperty("component_appid")
+    private String componentAppid;
+    @JsonProperty("component_appsecret")
+    private String componentAppsecret;
+    @JsonProperty("component_verify_ticket")
+    private String componentVerifyTicket;
+}

+ 15 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/WxApiComponentTokenResponse.java

@@ -0,0 +1,15 @@
+package com.sxtvs.open.api.odata.dto.wx;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class WxApiComponentTokenResponse extends WxCommonResponse{
+    @JsonProperty("component_access_token")
+    private String componentAccessToken;
+    @JsonProperty("expires_in")
+    private Integer expiresIn;
+}

+ 13 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/WxApiCreatePreAuthCodeRequest.java

@@ -0,0 +1,13 @@
+package com.sxtvs.open.api.odata.dto.wx;
+
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+@Data
+public class WxApiCreatePreAuthCodeRequest {
+    @JsonProperty("component_access_token")
+    private String componentAccessToken;
+    @JsonProperty("component_appid")
+    private String componentAppid;
+}

+ 15 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/WxApiCreatePreAuthCodeResponse.java

@@ -0,0 +1,15 @@
+package com.sxtvs.open.api.odata.dto.wx;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class WxApiCreatePreAuthCodeResponse extends WxCommonResponse {
+    @JsonProperty("pre_auth_code")
+    private String preAuthCode;
+    @JsonProperty("expires_in")
+    private Integer expiresIn;
+}

+ 14 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/WxApiGetAuthorizerInfoRequest.java

@@ -0,0 +1,14 @@
+package com.sxtvs.open.api.odata.dto.wx;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+@Data
+public class WxApiGetAuthorizerInfoRequest {
+    @JsonProperty("component_access_token")
+    private String componentAccessToken;
+    @JsonProperty("component_appid")
+    private String componentAppid;
+    @JsonProperty("authorizer_appid")
+    private String authorizerAppid;
+}

+ 14 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/WxCommonResponse.java

@@ -0,0 +1,14 @@
+package com.sxtvs.open.api.odata.dto.wx;
+
+import lombok.Data;
+
+@Data
+public class WxCommonResponse {
+    private int errcode;
+    private String errmsg;
+
+    public boolean hasError() {
+        return errcode != 0;
+    }
+
+}

+ 45 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/apiquery/AuthorizationInfo.java

@@ -0,0 +1,45 @@
+package com.sxtvs.open.api.odata.dto.wx.apiquery;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class AuthorizationInfo{
+
+	@JsonProperty("authorizer_appid")
+	private String authorizerAppid;
+
+	@JsonProperty("authorizer_access_token")
+	private String authorizerAccessToken;
+
+	@JsonProperty("authorizer_refresh_token")
+	private String authorizerRefreshToken;
+
+	@JsonProperty("expires_in")
+	private int expiresIn;
+
+	@JsonProperty("func_info")
+	private List<FuncInfoItem> funcInfo;
+
+	public String getAuthorizerAppid(){
+		return authorizerAppid;
+	}
+
+	public String getAuthorizerAccessToken(){
+		return authorizerAccessToken;
+	}
+
+	public String getAuthorizerRefreshToken(){
+		return authorizerRefreshToken;
+	}
+
+	public int getExpiresIn(){
+		return expiresIn;
+	}
+
+	public List<FuncInfoItem> getFuncInfo(){
+		return funcInfo;
+	}
+}

+ 29 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/apiquery/ConfirmInfo.java

@@ -0,0 +1,29 @@
+package com.sxtvs.open.api.odata.dto.wx.apiquery;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+@Data
+public class ConfirmInfo{
+
+	@JsonProperty("need_confirm")
+	private int needConfirm;
+
+	@JsonProperty("can_confirm")
+	private int canConfirm;
+
+	@JsonProperty("already_confirm")
+	private int alreadyConfirm;
+
+	public int getNeedConfirm(){
+		return needConfirm;
+	}
+
+	public int getCanConfirm(){
+		return canConfirm;
+	}
+
+	public int getAlreadyConfirm(){
+		return alreadyConfirm;
+	}
+}

+ 22 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/apiquery/FuncInfoItem.java

@@ -0,0 +1,22 @@
+package com.sxtvs.open.api.odata.dto.wx.apiquery;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+@Data
+public class FuncInfoItem{
+
+	@JsonProperty("funcscope_category")
+	private FuncscopeCategory funcscopeCategory;
+
+	@JsonProperty("confirm_info")
+	private ConfirmInfo confirmInfo;
+
+	public FuncscopeCategory getFuncscopeCategory(){
+		return funcscopeCategory;
+	}
+
+	public ConfirmInfo getConfirmInfo(){
+		return confirmInfo;
+	}
+}

+ 15 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/apiquery/FuncscopeCategory.java

@@ -0,0 +1,15 @@
+package com.sxtvs.open.api.odata.dto.wx.apiquery;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+@Data
+public class FuncscopeCategory{
+
+	@JsonProperty("id")
+	private int id;
+
+	public int getId(){
+		return id;
+	}
+}

+ 15 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/apiquery/WxApiQueryAuthRequest.java

@@ -0,0 +1,15 @@
+package com.sxtvs.open.api.odata.dto.wx.apiquery;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+
+@Data
+public class WxApiQueryAuthRequest {
+    @JsonProperty("component_access_token")
+    private String componentAccessToken;
+    @JsonProperty("component_appid")
+    private String componentAppid;
+    @JsonProperty("authorization_code")
+    private String authorizationCode;
+}

+ 18 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/apiquery/WxApiQueryAuthResponse.java

@@ -0,0 +1,18 @@
+package com.sxtvs.open.api.odata.dto.wx.apiquery;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.sxtvs.open.api.odata.dto.wx.WxCommonResponse;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class WxApiQueryAuthResponse extends WxCommonResponse {
+
+	@JsonProperty("authorization_info")
+	private AuthorizationInfo authorizationInfo;
+
+	public AuthorizationInfo getAuthorizationInfo(){
+		return authorizationInfo;
+	}
+}

+ 24 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/authorization/AuthorizationInfo.java

@@ -0,0 +1,24 @@
+package com.sxtvs.open.api.odata.dto.wx.authorization;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class AuthorizationInfo{
+
+	@JsonProperty("authorizer_appid")
+	private String authorizerAppid;
+
+	@JsonProperty("func_info")
+	private List<FuncInfoItem> funcInfo;
+
+	public String getAuthorizerAppid(){
+		return authorizerAppid;
+	}
+
+	public List<FuncInfoItem> getFuncInfo(){
+		return funcInfo;
+	}
+}

+ 25 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/authorization/AuthorizationInfoResponse.java

@@ -0,0 +1,25 @@
+package com.sxtvs.open.api.odata.dto.wx.authorization;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.sxtvs.open.api.odata.dto.wx.WxCommonResponse;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class AuthorizationInfoResponse extends WxCommonResponse {
+
+	@JsonProperty("authorizer_info")
+	private AuthorizerInfo authorizerInfo;
+
+	@JsonProperty("authorization_info")
+	private AuthorizationInfo authorizationInfo;
+
+	public AuthorizerInfo getAuthorizerInfo(){
+		return authorizerInfo;
+	}
+
+	public AuthorizationInfo getAuthorizationInfo(){
+		return authorizationInfo;
+	}
+}

+ 71 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/authorization/AuthorizerInfo.java

@@ -0,0 +1,71 @@
+package com.sxtvs.open.api.odata.dto.wx.authorization;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+@Data
+public class AuthorizerInfo{
+
+	@JsonProperty("qrcode_url")
+	private String qrcodeUrl;
+
+	@JsonProperty("business_info")
+	private BusinessInfo businessInfo;
+
+	@JsonProperty("user_name")
+	private String userName;
+
+	@JsonProperty("nick_name")
+	private String nickName;
+
+	@JsonProperty("head_img")
+	private String headImg;
+
+	@JsonProperty("principal_name")
+	private String principalName;
+
+	@JsonProperty("alias")
+	private String alias;
+
+	@JsonProperty("verify_type_info")
+	private VerifyTypeInfo verifyTypeInfo;
+
+	@JsonProperty("service_type_info")
+	private ServiceTypeInfo serviceTypeInfo;
+
+	public String getQrcodeUrl(){
+		return qrcodeUrl;
+	}
+
+	public BusinessInfo getBusinessInfo(){
+		return businessInfo;
+	}
+
+	public String getUserName(){
+		return userName;
+	}
+
+	public String getNickName(){
+		return nickName;
+	}
+
+	public String getHeadImg(){
+		return headImg;
+	}
+
+	public String getPrincipalName(){
+		return principalName;
+	}
+
+	public String getAlias(){
+		return alias;
+	}
+
+	public VerifyTypeInfo getVerifyTypeInfo(){
+		return verifyTypeInfo;
+	}
+
+	public ServiceTypeInfo getServiceTypeInfo(){
+		return serviceTypeInfo;
+	}
+}

+ 43 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/authorization/BusinessInfo.java

@@ -0,0 +1,43 @@
+package com.sxtvs.open.api.odata.dto.wx.authorization;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+@Data
+public class BusinessInfo{
+
+	@JsonProperty("open_pay")
+	private int openPay;
+
+	@JsonProperty("open_card")
+	private int openCard;
+
+	@JsonProperty("open_store")
+	private int openStore;
+
+	@JsonProperty("open_scan")
+	private int openScan;
+
+	@JsonProperty("open_shake")
+	private int openShake;
+
+	public int getOpenPay(){
+		return openPay;
+	}
+
+	public int getOpenCard(){
+		return openCard;
+	}
+
+	public int getOpenStore(){
+		return openStore;
+	}
+
+	public int getOpenScan(){
+		return openScan;
+	}
+
+	public int getOpenShake(){
+		return openShake;
+	}
+}

+ 15 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/authorization/FuncInfoItem.java

@@ -0,0 +1,15 @@
+package com.sxtvs.open.api.odata.dto.wx.authorization;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+@Data
+public class FuncInfoItem{
+
+	@JsonProperty("funcscope_category")
+	private FuncscopeCategory funcscopeCategory;
+
+	public FuncscopeCategory getFuncscopeCategory(){
+		return funcscopeCategory;
+	}
+}

+ 15 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/authorization/FuncscopeCategory.java

@@ -0,0 +1,15 @@
+package com.sxtvs.open.api.odata.dto.wx.authorization;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+@Data
+public class FuncscopeCategory{
+
+	@JsonProperty("id")
+	private int id;
+
+	public int getId(){
+		return id;
+	}
+}

+ 15 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/authorization/ServiceTypeInfo.java

@@ -0,0 +1,15 @@
+package com.sxtvs.open.api.odata.dto.wx.authorization;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+@Data
+public class ServiceTypeInfo{
+
+	@JsonProperty("id")
+	private int id;
+
+	public int getId(){
+		return id;
+	}
+}

+ 15 - 0
src/main/java/com/sxtvs/open/api/odata/dto/wx/authorization/VerifyTypeInfo.java

@@ -0,0 +1,15 @@
+package com.sxtvs.open.api.odata.dto.wx.authorization;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+@Data
+public class VerifyTypeInfo{
+
+	@JsonProperty("id")
+	private int id;
+
+	public int getId(){
+		return id;
+	}
+}

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

@@ -1,10 +1,14 @@
 package com.sxtvs.open.api.odata.service;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.sxtvs.open.api.odata.dto.wx.WxApiCreatePreAuthCodeRequest;
+import com.sxtvs.open.api.odata.dto.wx.WxApiCreatePreAuthCodeResponse;
 import com.sxtvs.open.api.youmei.service.YoumeiAccountServiceImpl;
+import com.sxtvs.open.core.conf.OauthConfig;
 import lombok.SneakyThrows;
 import org.apache.hc.client5.http.fluent.Request;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Service;
 
 import java.nio.charset.StandardCharsets;
@@ -17,6 +21,9 @@ public class OauthService {
     @Autowired
     private ObjectMapper objectMapper;
 
+    @Autowired
+    private StringRedisTemplate redisTemplate;
+
     @SneakyThrows
     public String getWeiboUrl() {
         var accessToken = youmeiAccountService.getSxgdAccount().getAccessToken();
@@ -27,4 +34,19 @@ public class OauthService {
         String url = objectMapper.readTree(body).get("data").get("auth_url").asText();
         return "redirect:" + url;
     }
+
+    @SneakyThrows
+    public WxApiCreatePreAuthCodeResponse createPreAuthCodeResponse() {
+        var ticket = redisTemplate.opsForValue().get("WX_TICKET");
+        WxApiCreatePreAuthCodeRequest authCodeRequest = new WxApiCreatePreAuthCodeRequest();
+        authCodeRequest.setComponentAppid(OauthConfig.wxClientKey);
+        authCodeRequest.setComponentAccessToken(ticket);
+        var body = Request.post("https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?" +
+                        "component_access_token=" + ticket)
+                .execute()
+                .returnContent()
+                .asString(StandardCharsets.UTF_8);
+
+        return objectMapper.readValue(body, WxApiCreatePreAuthCodeResponse.class);
+    }
 }

+ 68 - 0
src/main/java/com/sxtvs/open/api/odata/wxutil/PKCS7Encoder.java

@@ -0,0 +1,68 @@
+/**
+ * 对公众平台发送给公众账号的消息加解密示例代码.
+ *
+ * @copyright Copyright (c) 1998-2014 Tencent Inc.
+ */
+
+// ------------------------------------------------------------------------
+
+package com.sxtvs.open.api.odata.wxutil;
+
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+
+/**
+ * 提供基于PKCS7算法的加解密接口.
+ */
+class PKCS7Encoder {
+	static Charset CHARSET = StandardCharsets.UTF_8;
+	static int BLOCK_SIZE = 32;
+
+	/**
+	 * 获得对明文进行补位填充的字节.
+	 *
+	 * @param count 需要进行填充补位操作的明文字节个数
+	 * @return 补齐用的字节数组
+	 */
+	static byte[] encode(int count) {
+		// 计算需要填充的位数
+		int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE);
+		if (amountToPad == 0) {
+			amountToPad = BLOCK_SIZE;
+		}
+		// 获得补位所用的字符
+		char padChr = chr(amountToPad);
+		StringBuilder tmp = new StringBuilder();
+		for (int index = 0; index < amountToPad; index++) {
+			tmp.append(padChr);
+		}
+		return tmp.toString().getBytes(CHARSET);
+	}
+
+	/**
+	 * 删除解密后明文的补位字符
+	 *
+	 * @param decrypted 解密后的明文
+	 * @return 删除补位字符后的明文
+	 */
+	static byte[] decode(byte[] decrypted) {
+		int pad = (int) decrypted[decrypted.length - 1];
+		if (pad < 1 || pad > 32) {
+			pad = 0;
+		}
+		return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad);
+	}
+
+	/**
+	 * 将数字转化成ASCII码对应的字符,用于对明文进行补码
+	 *
+	 * @param a 需要转化的数字
+	 * @return 转化得到的字符
+	 */
+	static char chr(int a) {
+		byte target = (byte) (a & 0xFF);
+		return (char) target;
+	}
+
+}

+ 46 - 0
src/main/java/com/sxtvs/open/api/odata/wxutil/WxCrypt.java

@@ -0,0 +1,46 @@
+package com.sxtvs.open.api.odata.wxutil;
+
+import cn.hutool.crypto.Mode;
+import cn.hutool.crypto.Padding;
+import cn.hutool.crypto.symmetric.AES;
+import org.apache.commons.codec.binary.Base64;
+
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+
+public class WxCrypt {
+
+    static Charset CHARSET = StandardCharsets.UTF_8;
+
+    private static final byte[] aesKey = Base64.decodeBase64("smcicsdifajfksafjas1279sdmfa923121v9113ekas=".getBytes());
+
+    private static final AES aes = new AES(Mode.CBC, Padding.NoPadding, aesKey, Arrays.copyOfRange(aesKey, 0, 16));
+
+    public static String encrypt(){
+        return "";
+    }
+
+    public static String decrypt(String text){
+        byte[] encrypted = Base64.decodeBase64(text);
+        byte[] original = aes.decrypt(encrypted);
+        // 去除补位字符
+        byte[] bytes = PKCS7Encoder.decode(original);
+        // 分离16位随机字符串,网络字节序和AppId
+        byte[] networkOrder = Arrays.copyOfRange(bytes, 16, 20);
+        int xmlLength = recoverNetworkBytesOrder(networkOrder);
+
+        String xmlContent = new String(Arrays.copyOfRange(bytes, 20, 20 + xmlLength), CHARSET);
+        return xmlContent;
+    }
+
+    private static int recoverNetworkBytesOrder(byte[] orderBytes) {
+        int sourceNumber = 0;
+        for (int i = 0; i < 4; i++) {
+            sourceNumber <<= 8;
+            sourceNumber |= orderBytes[i] & 0xff;
+        }
+        return sourceNumber;
+    }
+
+}

+ 35 - 0
src/main/java/com/sxtvs/open/api/odata/wxutil/WxXmlUtil.java

@@ -0,0 +1,35 @@
+package com.sxtvs.open.api.odata.wxutil;
+
+import lombok.SneakyThrows;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import java.io.StringReader;
+
+public class WxXmlUtil {
+    @SneakyThrows
+    public static String getComponentVerifyTicket(String xml){
+        Document document = getDocument(xml);
+        return document.getElementsByTagName("ComponentVerifyTicket").item(0).getTextContent();
+    }
+
+    @SneakyThrows
+    public static String getEncrypt(String xml){
+        Document document = getDocument(xml);
+        return document.getElementsByTagName("Encrypt").item(0).getTextContent();
+    }
+
+    private static Document getDocument(String xml) throws ParserConfigurationException, SAXException, IOException {
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        DocumentBuilder db = dbf.newDocumentBuilder();
+        StringReader sr = new StringReader(xml);
+        InputSource is = new InputSource(sr);
+        return db.parse(is);
+    }
+
+}

+ 14 - 2
src/main/java/com/sxtvs/open/core/auth/LoginInterceptor.java

@@ -3,12 +3,15 @@ package com.sxtvs.open.core.auth;
 
 import com.sxtvs.open.core.advice.BizException;
 import com.sxtvs.open.core.conf.Constant;
+import jakarta.servlet.http.Cookie;
 import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpServletResponse;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.web.method.HandlerMethod;
 import org.springframework.web.servlet.AsyncHandlerInterceptor;
 
 import java.lang.reflect.Method;
+import java.util.Arrays;
 
 public class LoginInterceptor implements AsyncHandlerInterceptor {
     @Override
@@ -24,8 +27,17 @@ public class LoginInterceptor implements AsyncHandlerInterceptor {
             return true;
         }
 
-        // 这写你拦截需要干的事儿,比如取缓存,SESSION,权限判断等
-        String token = request.getHeader(Constant.TOKEN_HEADER_NAME);
+        // 优先取header
+        var token = request.getHeader(Constant.TOKEN_HEADER_NAME);
+
+        // 接下来取cookie
+        if (StringUtils.isBlank(token)) {
+            token = Arrays.stream(request.getCookies())
+                    .filter(x -> x.getName().equals(Constant.TOKEN_COOKIE_NAME))
+                    .map(Cookie::getValue)
+                    .findFirst()
+                    .orElse("");
+        }
 
         if (!AESUtil.isOk(token)) {
             throw new BizException("没有登录");

+ 1 - 0
src/main/java/com/sxtvs/open/core/conf/Constant.java

@@ -18,5 +18,6 @@ public class Constant {
     public static final long SUB_TIME = 1600000000;
 
     public static final String TOKEN_HEADER_NAME = "Authorization";
+    public static final String TOKEN_COOKIE_NAME = "sxtvs-token";
 
 }

+ 26 - 0
src/main/java/com/sxtvs/open/core/conf/OauthConfig.java

@@ -0,0 +1,26 @@
+package com.sxtvs.open.core.conf;
+
+public class OauthConfig {
+    public static String douyinClientKey = "awfrca76s1petwh0";
+    public static String douyinClientSecret = "4c0bcabf25e937679cdb85cd9cc9a64b";
+
+    public static String kuaishouClientKey = "ks657244072487589897";
+    public static String kuaishouClientSecret = "d-LL1KyA6QSDzJG3AtzKZQ";
+
+    public static String weiboKey = "2787601065";
+    public static String weiboSecret = "3b3dfcd73027ccd29fc7b73fb2242dc2";
+
+    public static String wxClientKey = "wxdca527f24b99b4c0";
+    public static String wxClientSecret = "5bd99087f5eba81711d1f68d77cd4f79";
+
+
+    public static String weixinZhiHuiRongMeiAppId = "wx5e1699e1707030ac";
+    public static String weixinZhiHuiRongMeiSecret = "65c4f421f2bba4cd5d7f1219123e0fd9";
+
+    public static String bilibiliClientId = "e79e6fdef9d446d7";
+    public static String bilibiliSecret = "70d40a332aa54132a72239efba022450";
+
+    public static String weixinWishAppId = "wx8560c9c2e174f07f";
+    public static String weixinWishSecret = "38cb0abbb0fddf94485ee6b13fc31f2d";
+
+}

+ 11 - 0
src/main/java/com/sxtvs/open/core/sls/AliyunLogger.java

@@ -6,14 +6,18 @@ import com.aliyun.openservices.aliyun.log.producer.ProducerConfig;
 import com.aliyun.openservices.aliyun.log.producer.ProjectConfig;
 import com.aliyun.openservices.aliyun.log.producer.errors.ProducerException;
 import com.aliyun.openservices.log.common.LogItem;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.sxtvs.open.core.auth.HttpContextUtil;
 import jakarta.annotation.PostConstruct;
+import lombok.SneakyThrows;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.web.context.request.RequestAttributes;
 import org.springframework.web.context.request.RequestContextHolder;
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.util.Map;
 import java.util.Optional;
 
 @Component
@@ -24,6 +28,9 @@ public class AliyunLogger {
 
     private final String app = "open";
 
+    @Autowired
+    private ObjectMapper objectMapper;
+
     @PostConstruct
     public void init() {
 
@@ -91,6 +98,7 @@ public class AliyunLogger {
         return item;
     }
 
+    @SneakyThrows
     private String format(Object obj) {
         if (obj == null) {
             return "";
@@ -100,6 +108,9 @@ public class AliyunLogger {
             err.printStackTrace(new PrintWriter(sw, true));
             return sw.getBuffer().toString();
         }
+        if (obj instanceof Map<?, ?> map) {
+            return objectMapper.writeValueAsString(map);
+        }
         return obj.toString();
     }
 

+ 11 - 2
src/main/resources/application.yml

@@ -1,5 +1,3 @@
-
-
 mybatis-plus:
   mapper-locations: classpath*:com/sxtvs/**/*.xml
   configuration:
@@ -41,5 +39,16 @@ spring:
           url: jdbc:mysql://rm-2vc3039h858t9ab7sfo.mysql.cn-chengdu.rds.aliyuncs.com:3306/collect?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&nullCatalogMeansCurrent=true
           username: cxzx
           password: sxtvs53$68HD
+  data:
+    redis:
+      host: r-2vch6mmrbgv8vjc44epd.redis.cn-chengdu.rds.aliyuncs.com
+      port: 6379
+      password: vkckussJJCBX&^55sd
+  thymeleaf:
+    cache: false
+  jackson:
+    time-zone: GMT+8
+    date-format: "yyyy-MM-dd HH:mm:ss"
+
 server:
   port: 80

+ 16 - 0
src/main/resources/templates/weixin-code.html

@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+<script th:inline="javascript">
+    /*<![CDATA[*/
+    var pre_auth_code = /*[[${pre_auth_code}]]*/ '';
+    window.location = 'https://mp.weixin.qq.com/cgi-bin/componentloginpage?' +
+        'component_appid=wx7040933fd0e4b0e8&pre_auth_code=' + pre_auth_code + '&redirect_uri=http%3A%2F%2Fopen.sxtvs.net%2Foauth%2Fweixin%2Fwx7040933fd0e4b0e8%2Fcallback&auth_type=1'
+    /*]]>*/
+</script>
+</body>
+</html>