Created
January 9, 2020 08:41
-
-
Save gjp0609/bb9a8fffe24deb1d5f4cd0aca98b6dfe to your computer and use it in GitHub Desktop.
微信域名授权跳转
解决微信授权域名限制
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val authUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECTURI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect" | |
private val appId = "xxxxxxx" | |
private val redirectUrl = "http://www.xxx.com/xxx/redirectBack" | |
@GetMapping("/getCode") | |
fun redirect(url: String, scope: String, response: HttpServletResponse) { | |
println(url) | |
val encodeUrl = encode(url, StandardCharsets.UTF_8) | |
val redirectUrl: String = authUrl | |
.replace("APPID", appId) | |
.replace("REDIRECTURI", encode("$redirectUrl?url=$encodeUrl", StandardCharsets.UTF_8)) | |
.replace("SCOPE", scope) | |
response.sendRedirect(redirectUrl) | |
} | |
@GetMapping("/redirectBack") | |
fun redirectBack(url: String, response: HttpServletResponse, code: String) { | |
val redirectUrl = url + (if (url.contains("?")) "&" else "?") + "code=$code" | |
response.sendRedirect(redirectUrl) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment