|
|
@@ -1,5 +1,6 @@
|
|
|
package com.cyksj.service.authorization.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.cyksj.common.util.Codec;
|
|
|
import com.cyksj.config.WeChatConfig;
|
|
|
import com.cyksj.config.wxlogin.WxOpenPlatYHLXLoginConfig;
|
|
|
@@ -11,6 +12,8 @@ import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.net.MalformedURLException;
|
|
|
+import java.net.URL;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
@@ -33,11 +36,11 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public String createUrl(String state, String authType) {
|
|
|
- return weChatService.createUrl(state,weChatConfig.getDomain() + WeChatAuthRedirectUrl.get(authType).getUrl()
|
|
|
- ,weChatConfig.getAppid(),WeChatAuthRedirectUrl.get(authType).getScope());
|
|
|
+ public String createUrl(String url, String state, String authType) throws MalformedURLException {
|
|
|
+ String domain = gerUrlDomain(url);
|
|
|
+ return weChatService.createUrl(state, (domain != null ? domain : weChatConfig.getDomain()) + WeChatAuthRedirectUrl.get(authType).getUrl()
|
|
|
+ , weChatConfig.getAppid(), WeChatAuthRedirectUrl.get(authType).getScope());
|
|
|
}
|
|
|
-
|
|
|
@Override
|
|
|
public JsSdkTicket getJsTicket(String appId, String url) throws Exception {
|
|
|
|
|
|
@@ -66,4 +69,19 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
|
|
return weChatService.createWxAuthLoginUrl(state, appId, URLEncoder.encode(redirectUrl, StandardCharsets.UTF_8));
|
|
|
}
|
|
|
|
|
|
+ public static String gerUrlDomain(String url) {
|
|
|
+ try {
|
|
|
+ if (StrUtil.isNotBlank(url) && !url.contains("nf.video")) {
|
|
|
+ if (!url.contains("http")) {
|
|
|
+ url = "https://" + url;
|
|
|
+ }
|
|
|
+ URL questUrl = new URL(url);
|
|
|
+ String domain = questUrl.getAuthority();
|
|
|
+ return "https://" + domain + "/";
|
|
|
+ }
|
|
|
+ } catch (MalformedURLException e) {
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
}
|