|
|
@@ -96,39 +96,41 @@ public class AuthorizationController {
|
|
|
@GetMapping(value = "/weChat")
|
|
|
public void base(String url, String dsCode, Long sharedId, Integer dsType, Long popularizeId, String authType, HttpServletResponse response) throws Exception {
|
|
|
|
|
|
- log.info("微信授权转跳. url: {},authType:{}",url,authType);
|
|
|
+ log.info("微信授权转跳. url: {},authType:{}", url, authType);
|
|
|
|
|
|
// 无论是否为老用户 均转跳到授权页面
|
|
|
// 若授权过 则无需再次授权 直接回调 /user/wechat/redirect
|
|
|
// 新用户同意授权后 也会回调 /user/wechat/redirect
|
|
|
|
|
|
Long mappingId = SEQUENCE.nextId();
|
|
|
- redisService.set(mappingId.toString(),url,60*60*24L);
|
|
|
+ redisService.set(mappingId.toString(), url, 60 * 60 * 24L);
|
|
|
if (StrUtil.isNotBlank(dsCode)) {
|
|
|
dsCode = dsCode.trim();
|
|
|
}
|
|
|
AuthRedirect redirect = new AuthRedirect().setMappingId(mappingId).setSharedId(sharedId).setDsType(dsType).setPid(popularizeId).setDsCode(dsCode);
|
|
|
String state = Codec.DoBase64.custom().setData(Jsons.toJson(redirect)).encodeAsText();
|
|
|
|
|
|
- response.sendRedirect(authorizationService.createUrl(state,authType));
|
|
|
+ response.sendRedirect(authorizationService.createUrl(state, authType));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 全量授权
|
|
|
+ *
|
|
|
* @author chan
|
|
|
* @date 2021-10-11 上午11:57
|
|
|
*/
|
|
|
@GetMapping(value = "/weChat/baseRedirect")
|
|
|
public void redirect(String code, String state, HttpServletResponse response) throws Exception {
|
|
|
- AuthToken token = weChatService.getAuthToken(code,weChatConfig.getAppid());
|
|
|
+ AuthToken token = weChatService.getAuthToken(code, weChatConfig.getAppid());
|
|
|
|
|
|
baseRedirect(token, state, User.RegisterEnv.wx, response);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 静默授权
|
|
|
+ *
|
|
|
* @author chan
|
|
|
* @date 2021-10-11 上午11:58
|
|
|
*/
|
|
|
@@ -140,18 +142,18 @@ public class AuthorizationController {
|
|
|
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());
|
|
|
|
|
|
// 查询用户期望转跳的url
|
|
|
String url = redisService.getStr(re.getMappingId().toString());
|
|
|
String data = Codec.DoBase64.custom().setData(token.getOpenid()).encodeAsText();
|
|
|
|
|
|
- Cookie cookie = new Cookie("openKey",data);
|
|
|
+ Cookie cookie = new Cookie("openKey", data);
|
|
|
cookie.setMaxAge(31536000);
|
|
|
cookie.setPath("/");
|
|
|
response.addCookie(cookie);
|
|
|
|
|
|
- log.info("微信授权转跳. url: {}",url);
|
|
|
+ log.info("微信授权转跳. url: {}", url);
|
|
|
response.sendRedirect(url);
|
|
|
|
|
|
}
|
|
|
@@ -160,11 +162,11 @@ public class AuthorizationController {
|
|
|
* 微信js-sdk 权限验证
|
|
|
*/
|
|
|
@RequestMapping(value = "/jsTicket", method = RequestMethod.GET)
|
|
|
- public Result<JsSdkTicket> ticket(String appId, String url) throws Exception{
|
|
|
+ public Result<JsSdkTicket> ticket(String appId, String url) throws Exception {
|
|
|
if (StringUtils.isBlank(url)) {
|
|
|
throw BusinessRuntimeException.getInstance("请输入授权网址.");
|
|
|
}
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(authorizationService.getJsTicket(Optional.ofNullable(appId).orElse(weChatConfig.getAppid()),url));
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(authorizationService.getJsTicket(Optional.ofNullable(appId).orElse(weChatConfig.getAppid()), url));
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -204,10 +206,14 @@ public class AuthorizationController {
|
|
|
* 网页微信授权登录
|
|
|
*/
|
|
|
@GetMapping("/wx/authLogin")
|
|
|
- public Result<String> wxAuthorize(Long sharedId, Integer dsType, Long popularizeId, String dsCode) throws Exception {
|
|
|
+ public Result<String> wxAuthorize(Long sharedId, Integer dsType, Long popularizeId, String dsCode, String type) throws Exception {
|
|
|
String wxAuthUrl = redisService.getStr(RedisService.key.WX_LOGIN_AUTH_URI.getNameFormat(wxOpenPlatYHLXLoginConfig.getAppId()));
|
|
|
Long mappingId = SEQUENCE.nextId();
|
|
|
- redisService.set(mappingId.toString(), wxOpenPlatYHLXLoginConfig.getLoginUrl(), 60 * 60 * 24L);
|
|
|
+ String loginUrl = wxOpenPlatYHLXLoginConfig.getLoginUrl();
|
|
|
+ if (StrUtil.isNotBlank(type)) {
|
|
|
+ loginUrl = String.format("https://nf.video/%s/web", type);
|
|
|
+ }
|
|
|
+ redisService.set(mappingId.toString(), loginUrl, 60 * 60 * 24L);
|
|
|
if (StrUtil.isNotBlank(dsCode)) {
|
|
|
dsCode = dsCode.trim();
|
|
|
}
|
|
|
@@ -269,10 +275,12 @@ public class AuthorizationController {
|
|
|
}
|
|
|
StpUserUtil.login(userId);
|
|
|
String token = StpUserUtil.getTokenValue();
|
|
|
-
|
|
|
+ if (StrUtil.isEmpty(user.getShowId())) {
|
|
|
+ user.setShowId(userService.getUserShowId(userId));
|
|
|
+ }
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.putOpt("saToken", token);
|
|
|
- jsonObject.putOpt("uid", userId);
|
|
|
+ jsonObject.putOpt("showId", user.getShowId());
|
|
|
jsonObject.putOpt("nickname", user.getNickname());
|
|
|
jsonObject.putOpt("img", user.getHeadimgurl());
|
|
|
|
|
|
@@ -326,7 +334,7 @@ public class AuthorizationController {
|
|
|
} else phoneCodeMapper.updateById(phoneCode);
|
|
|
if (!isFree) {
|
|
|
SmsUtil.sendTencent(phone, code);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
// 发送短信
|
|
|
SmsUtil.sendLuoKey2Msg(phone, String.format("尊敬的用户,您的验证码为%s,此验证码仅用于银河录像。【银河录像局】", code));
|
|
|
}
|
|
|
@@ -383,7 +391,7 @@ public class AuthorizationController {
|
|
|
throw BusinessRuntimeException.getInstance("手机验证码错误,请重新输入");
|
|
|
}
|
|
|
wrapper.eq(User::getLoginPhone, loginReq.getPhone());
|
|
|
- }else if (loginReq.getType() == 2){
|
|
|
+ } else if (loginReq.getType() == 2) {
|
|
|
if (StrUtil.isEmpty(loginReq.getEmail())) {
|
|
|
throw BusinessRuntimeException.getInstance("邮箱不能为空");
|
|
|
}
|
|
|
@@ -396,7 +404,7 @@ public class AuthorizationController {
|
|
|
}
|
|
|
wrapper.eq(User::getEmail, loginReq.getEmail());
|
|
|
redisService.del(RedisService.key.EMAIL_CODE_KEY.getNameFormat(loginReq.getEmail()));
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重新操作");
|
|
|
}
|
|
|
//保存用户信息
|
|
|
@@ -406,13 +414,19 @@ public class AuthorizationController {
|
|
|
Long dsPopularizeId = null;
|
|
|
if (StrUtil.isNotBlank(dsCode)) {
|
|
|
dsCode = dsCode.trim();
|
|
|
- UserDistributePopularize distributePopularize = distributePopularizeMapper.selectOne(Wrappers.lambdaQuery(UserDistributePopularize.class)
|
|
|
- .eq(UserDistributePopularize::getCode, dsCode)
|
|
|
- .select(UserDistributePopularize::getUserId, UserDistributePopularize::getId).last("limit 1"));
|
|
|
- if (distributePopularize != null) {
|
|
|
- log.info("渠道sharedId:{}设置固定推广链接PC用户分销", distributePopularize.getUserId());
|
|
|
- sharedId = distributePopularize.getUserId();
|
|
|
- dsPopularizeId = distributePopularize.getId();
|
|
|
+ User sharedUser = userService.getOne(Wrappers.lambdaQuery(User.class)
|
|
|
+ .eq(User::getShowId, dsCode).last("limit 1"));
|
|
|
+ if (sharedUser != null) {
|
|
|
+ sharedId = sharedUser.getId();
|
|
|
+ } else {
|
|
|
+ UserDistributePopularize distributePopularize = distributePopularizeMapper.selectOne(Wrappers.lambdaQuery(UserDistributePopularize.class)
|
|
|
+ .eq(UserDistributePopularize::getCode, dsCode)
|
|
|
+ .select(UserDistributePopularize::getUserId, UserDistributePopularize::getId).last("limit 1"));
|
|
|
+ if (distributePopularize != null) {
|
|
|
+ log.info("渠道sharedId:{}设置固定推广链接PC用户分销", distributePopularize.getUserId());
|
|
|
+ sharedId = distributePopularize.getUserId();
|
|
|
+ dsPopularizeId = distributePopularize.getId();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if (user == null) {
|
|
|
@@ -442,7 +456,10 @@ public class AuthorizationController {
|
|
|
}
|
|
|
//写回登陆信息
|
|
|
StpUserUtil.login(user.getId());
|
|
|
- LoginPhoneRep loginPhoneRep = new LoginPhoneRep(StpUserUtil.getTokenValue(), user.getId(), user.getNickname(), user.getHeadimgurl());
|
|
|
+ if (StrUtil.isEmpty(user.getShowId())) {
|
|
|
+ user.setShowId(userService.getUserShowId(user.getId()));
|
|
|
+ }
|
|
|
+ LoginPhoneRep loginPhoneRep = new LoginPhoneRep(StpUserUtil.getTokenValue(), user.getShowId(), user.getNickname(), user.getHeadimgurl());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(loginPhoneRep);
|
|
|
}
|
|
|
|
|
|
@@ -468,7 +485,10 @@ public class AuthorizationController {
|
|
|
cookie.setPath("/");
|
|
|
response.addCookie(cookie);
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.putOpt("uid", user.getId());
|
|
|
+ if (StrUtil.isEmpty(user.getShowId())) {
|
|
|
+ user.setShowId(userService.getUserShowId(user.getId()));
|
|
|
+ }
|
|
|
+ jsonObject.putOpt("showId", user.getShowId());
|
|
|
jsonObject.putOpt("nickName", user.getNickname());
|
|
|
|
|
|
Cookie userInfo = new Cookie("info", Base64.encode(jsonObject.toString()));
|