|
@@ -12,6 +12,9 @@ import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.snowflake.Sequence;
|
|
import com.cyksj.common.snowflake.Sequence;
|
|
|
import com.cyksj.common.util.*;
|
|
import com.cyksj.common.util.*;
|
|
|
import com.cyksj.config.WeChatConfig;
|
|
import com.cyksj.config.WeChatConfig;
|
|
|
|
|
+import com.cyksj.config.wxlogin.BaseWxOpenPlatConfig;
|
|
|
|
|
+import com.cyksj.config.wxlogin.WxOpenPlatEnum;
|
|
|
|
|
+import com.cyksj.config.wxlogin.WxOpenPlatFactory;
|
|
|
import com.cyksj.config.wxlogin.WxOpenPlatYHLXLoginConfig;
|
|
import com.cyksj.config.wxlogin.WxOpenPlatYHLXLoginConfig;
|
|
|
import com.cyksj.dto.Result;
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
import com.cyksj.enums.GatewayResponse;
|
|
@@ -117,9 +120,11 @@ public class AuthorizationController {
|
|
|
*/
|
|
*/
|
|
|
@GetMapping(value = "/weChat/baseRedirect")
|
|
@GetMapping(value = "/weChat/baseRedirect")
|
|
|
public void redirect(String code, String state, HttpServletResponse response) throws Exception {
|
|
public void redirect(String code, String state, HttpServletResponse response) throws Exception {
|
|
|
|
|
+ String json = Codec.DoBase64.custom().setData(state).decodeAsText();
|
|
|
|
|
+ AuthRedirect re = Jsons.parseObject(json, AuthRedirect.class);
|
|
|
AuthToken token = weChatService.getAuthToken(code, weChatConfig.getAppid());
|
|
AuthToken token = weChatService.getAuthToken(code, weChatConfig.getAppid());
|
|
|
|
|
|
|
|
- baseRedirect(token, state, User.RegisterEnv.wx, response);
|
|
|
|
|
|
|
+ baseRedirect(token, re, User.RegisterEnv.wx, response);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -214,19 +219,62 @@ public class AuthorizationController {
|
|
|
.setCk(callback)
|
|
.setCk(callback)
|
|
|
.setCt(callbackType);
|
|
.setCt(callbackType);
|
|
|
String state = Codec.DoBase64.custom().setData(Jsons.toJson(redirect)).encodeAsText();
|
|
String state = Codec.DoBase64.custom().setData(Jsons.toJson(redirect)).encodeAsText();
|
|
|
- String wxAuthUrl = authorizationService.createWxAuthLoginUrl(state, wxOpenPlatYHLXLoginConfig.getRedirectUri());
|
|
|
|
|
|
|
+ String wxAuthUrl = authorizationService.createWxAuthLoginUrl(state, wxOpenPlatYHLXLoginConfig.getAppId(), wxOpenPlatYHLXLoginConfig.getRedirectUri());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(wxAuthUrl);
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(wxAuthUrl);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 微信网页统一授权登录
|
|
|
|
|
+ */
|
|
|
|
|
+ @GetMapping("/wx/unified/login")
|
|
|
|
|
+ public Result<String> wxUnifiedLogin(Long sharedId, Integer dsType, Long popularizeId, String dsCode, String type, String callbackType, String callback, String wt, String customId) throws Exception {
|
|
|
|
|
+ if (StrUtil.isEmpty(wt)) {
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
|
|
+ }
|
|
|
|
|
+ WxOpenPlatEnum wxOpenPlatEnum = WxOpenPlatEnum.valueOf(wt);
|
|
|
|
|
+ if (wxOpenPlatEnum == null) {
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
|
|
+ }
|
|
|
|
|
+ BaseWxOpenPlatConfig wxApp = WxOpenPlatFactory.getWeChatConfigStrategy(wxOpenPlatEnum.getAppId());
|
|
|
|
|
+
|
|
|
|
|
+ Long mappingId = SEQUENCE.nextId();
|
|
|
|
|
+ String loginUrl = wxApp.getLoginUrl();
|
|
|
|
|
+ redisService.set(mappingId.toString(), loginUrl, 60 * 60 * 24L);
|
|
|
|
|
+ if (StrUtil.isNotBlank(dsCode)) {
|
|
|
|
|
+ dsCode = dsCode.trim();
|
|
|
|
|
+ }
|
|
|
|
|
+ AuthRedirect redirect = new AuthRedirect().setMappingId(mappingId).setSharedId(sharedId).setDsType(dsType).setPid(popularizeId).setDsCode(dsCode)
|
|
|
|
|
+ .setCk(callback)
|
|
|
|
|
+ .setCd(customId)
|
|
|
|
|
+ .setCt(callbackType);
|
|
|
|
|
+ String state = Codec.DoBase64.custom().setData(Jsons.toJson(redirect)).encodeAsText();
|
|
|
|
|
+ String wxAuthUrl = authorizationService.createWxAuthLoginUrl(state, wxApp.getAppId(), wxApp.getRedirectUri());
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(wxAuthUrl);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 网页微信授权后统一跳转
|
|
|
|
|
+ */
|
|
|
|
|
+ @GetMapping("/wx/unified/baseRedirect")
|
|
|
|
|
+ public void wxUnifiedRedirect(String code, String state, HttpServletResponse response) throws Exception {
|
|
|
|
|
+ // 转跳参数
|
|
|
|
|
+ String json = Codec.DoBase64.custom().setData(state).decodeAsText();
|
|
|
|
|
+ AuthRedirect re = Jsons.parseObject(json, AuthRedirect.class);
|
|
|
|
|
+ AuthToken token = weChatService.getAuthToken(code, re.getAp());
|
|
|
|
|
+ //重定向
|
|
|
|
|
+ baseRedirect(token, re, User.RegisterEnv.pc, response);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 网页微信授权后跳转
|
|
* 网页微信授权后跳转
|
|
|
*/
|
|
*/
|
|
|
@GetMapping("/wx/authLogin/baseRedirect")
|
|
@GetMapping("/wx/authLogin/baseRedirect")
|
|
|
public void wxAuthLoginRedirect(String code, String state, HttpServletResponse response) throws Exception {
|
|
public void wxAuthLoginRedirect(String code, String state, HttpServletResponse response) throws Exception {
|
|
|
-
|
|
|
|
|
|
|
+ String json = Codec.DoBase64.custom().setData(state).decodeAsText();
|
|
|
|
|
+ AuthRedirect re = Jsons.parseObject(json, AuthRedirect.class);
|
|
|
AuthToken token = weChatService.getAuthToken(code, wxOpenPlatYHLXLoginConfig.getAppId());
|
|
AuthToken token = weChatService.getAuthToken(code, wxOpenPlatYHLXLoginConfig.getAppId());
|
|
|
//重定向
|
|
//重定向
|
|
|
- baseRedirect(token, state, User.RegisterEnv.pc, response);
|
|
|
|
|
|
|
+ baseRedirect(token, re, User.RegisterEnv.pc, response);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -397,15 +445,12 @@ public class AuthorizationController {
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(loginPhoneRep);
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(loginPhoneRep);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void baseRedirect(AuthToken token, String state, User.RegisterEnv registerEnv, HttpServletResponse response) throws Exception {
|
|
|
|
|
|
|
+ public void baseRedirect(AuthToken token, AuthRedirect re, User.RegisterEnv registerEnv, HttpServletResponse response) throws Exception {
|
|
|
// 根据openid 与 access_token 获取用户信息
|
|
// 根据openid 与 access_token 获取用户信息
|
|
|
GzhOAuth2UserInfo userinfo = weChatService.getUserInfo(token.getAccessToken(), token.getOpenid());
|
|
GzhOAuth2UserInfo userinfo = weChatService.getUserInfo(token.getAccessToken(), token.getOpenid());
|
|
|
|
|
|
|
|
- // 转跳参数
|
|
|
|
|
- String json = Codec.DoBase64.custom().setData(state).decodeAsText();
|
|
|
|
|
- AuthRedirect re = Jsons.parseObject(json, AuthRedirect.class);
|
|
|
|
|
//保存用户信息
|
|
//保存用户信息
|
|
|
- User user = userService.saveAuth(userinfo, re.getSharedId(), re.getDsType(), re.getPid(), registerEnv, re.getDsCode(), re.getCk(), re.getCt());
|
|
|
|
|
|
|
+ User user = userService.saveAuth(userinfo, re.getSharedId(), re.getDsType(), re.getPid(), registerEnv, re.getDsCode(), re.getCk(), re.getCt(), re.getCd());
|
|
|
if (user == null) {
|
|
if (user == null) {
|
|
|
throw BusinessRuntimeException.getInstance("系统错误,请重新授权");
|
|
throw BusinessRuntimeException.getInstance("系统错误,请重新授权");
|
|
|
}
|
|
}
|