diff --git a/tiesheng-ademo/src/main/java/com/tiesheng/demo/controller/TestController.java b/tiesheng-ademo/src/main/java/com/tiesheng/demo/controller/TestController.java index 85ed11d..e4bc2a7 100644 --- a/tiesheng-ademo/src/main/java/com/tiesheng/demo/controller/TestController.java +++ b/tiesheng-ademo/src/main/java/com/tiesheng/demo/controller/TestController.java @@ -1,14 +1,13 @@ package com.tiesheng.demo.controller; -import cn.hutool.log.LogFactory; import com.tiesheng.annotation.token.TokenIgnore; -import com.tiesheng.util.ip2region.DataBlock; -import com.tiesheng.util.ip2region.Ip2Region; +import com.tiesheng.util.config.GlobalConfig; import com.tiesheng.util.pojos.ApiResp; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.io.IOException; +import javax.servlet.http.HttpServletResponse; /** * @author hao @@ -17,6 +16,8 @@ import java.io.IOException; @RequestMapping("/test") public class TestController { + @Autowired + GlobalConfig globalConfig; @RequestMapping("/index") @TokenIgnore @@ -24,4 +25,10 @@ public class TestController { return ApiResp.respOK("hello world"); } + @RequestMapping("/redirect") + @TokenIgnore + public void redirect(HttpServletResponse response) { + globalConfig.redirect("mobile", "/test", response); + } + } diff --git a/tiesheng-ademo/src/main/resources/static/mobile/v1.0.0/index.html b/tiesheng-ademo/src/main/resources/static/mobile/v1.0.0/index.html new file mode 100644 index 0000000..451c6cf --- /dev/null +++ b/tiesheng-ademo/src/main/resources/static/mobile/v1.0.0/index.html @@ -0,0 +1,37 @@ + + + + + + + 钉钉授权 + + + + + + + diff --git a/tiesheng-ademo/src/main/resources/static/mobile/v1.0.1/index.html b/tiesheng-ademo/src/main/resources/static/mobile/v1.0.1/index.html new file mode 100644 index 0000000..451c6cf --- /dev/null +++ b/tiesheng-ademo/src/main/resources/static/mobile/v1.0.1/index.html @@ -0,0 +1,37 @@ + + + + + + + 钉钉授权 + + + + + + + diff --git a/tiesheng-util/src/main/java/com/tiesheng/util/config/GlobalConfig.java b/tiesheng-util/src/main/java/com/tiesheng/util/config/GlobalConfig.java index 85beed4..61a59e9 100644 --- a/tiesheng-util/src/main/java/com/tiesheng/util/config/GlobalConfig.java +++ b/tiesheng-util/src/main/java/com/tiesheng/util/config/GlobalConfig.java @@ -2,8 +2,15 @@ package com.tiesheng.util.config; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; +import cn.hutool.log.LogFactory; +import com.tiesheng.util.exception.ApiException; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; /** * @author hao @@ -45,6 +52,27 @@ public class GlobalConfig { return path; } + + /** + * 重定向 + * + * @param htmlDir 资源目录 + * @param route + */ + public void redirect(String htmlDir, String route, HttpServletResponse response) { + PathMatchingResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver(); + try { + Resource[] resources = patternResolver.getResources(String.format("classpath*:static/%s/*/index.html", htmlDir)); + if (resources.length == 0) { + throw new ApiException("无法重定向,请检查资源"); + } + String filename = resources[resources.length - 1].getFile().getPath(); + String path = buildPath(String.format("/%s%s#%s", htmlDir, StrUtil.subAfter(filename, htmlDir, true), route)); + response.sendRedirect(path); + } catch (IOException ignored) { + } + } + /////////////////////////////////////////////////////////////////////////// // setter\getter ///////////////////////////////////////////////////////////////////////////