|
@@ -22,19 +22,20 @@ 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;
|
|
|
import com.cyksj.mapper.PhoneCodeMapper;
|
|
import com.cyksj.mapper.PhoneCodeMapper;
|
|
|
|
|
+import com.cyksj.mapper.manage.cps.UserDistributePopularizeMapper;
|
|
|
import com.cyksj.model.dto.AuthRedirect;
|
|
import com.cyksj.model.dto.AuthRedirect;
|
|
|
import com.cyksj.model.dto.AuthToken;
|
|
import com.cyksj.model.dto.AuthToken;
|
|
|
import com.cyksj.model.dto.GzhOAuth2UserInfo;
|
|
import com.cyksj.model.dto.GzhOAuth2UserInfo;
|
|
|
import com.cyksj.model.dto.JsSdkTicket;
|
|
import com.cyksj.model.dto.JsSdkTicket;
|
|
|
import com.cyksj.model.entity.PhoneCode;
|
|
import com.cyksj.model.entity.PhoneCode;
|
|
|
import com.cyksj.model.entity.User;
|
|
import com.cyksj.model.entity.User;
|
|
|
-import com.cyksj.model.request.LoginPhoneReq;
|
|
|
|
|
|
|
+import com.cyksj.model.entity.UserDistributePopularize;
|
|
|
|
|
+import com.cyksj.model.request.LoginReq;
|
|
|
import com.cyksj.model.response.LoginPhoneRep;
|
|
import com.cyksj.model.response.LoginPhoneRep;
|
|
|
import com.cyksj.model.response.WxGzhQrCodeTicketRep;
|
|
import com.cyksj.model.response.WxGzhQrCodeTicketRep;
|
|
|
import com.cyksj.redis.RedisService;
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.authorization.AuthorizationService;
|
|
import com.cyksj.service.authorization.AuthorizationService;
|
|
|
import com.cyksj.service.distribute.DistributeService;
|
|
import com.cyksj.service.distribute.DistributeService;
|
|
|
-import com.cyksj.service.distribute.equipment.EquipmentDistributeService;
|
|
|
|
|
import com.cyksj.service.mail.MailService;
|
|
import com.cyksj.service.mail.MailService;
|
|
|
import com.cyksj.service.template.TemplateCommonService;
|
|
import com.cyksj.service.template.TemplateCommonService;
|
|
|
import com.cyksj.service.user.UserService;
|
|
import com.cyksj.service.user.UserService;
|
|
@@ -89,10 +90,10 @@ public class AuthorizationController {
|
|
|
|
|
|
|
|
private final DistributeService distributeService;
|
|
private final DistributeService distributeService;
|
|
|
|
|
|
|
|
- private final EquipmentDistributeService equipDistributeService;
|
|
|
|
|
|
|
+ private final UserDistributePopularizeMapper distributePopularizeMapper;
|
|
|
|
|
|
|
|
@GetMapping(value = "/weChat")
|
|
@GetMapping(value = "/weChat")
|
|
|
- public void base(String url, Long sharedId, Integer dsType, Long popularizeId, String authType, HttpServletResponse response) throws Exception {
|
|
|
|
|
|
|
+ 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);
|
|
|
|
|
|
|
@@ -102,7 +103,10 @@ public class AuthorizationController {
|
|
|
|
|
|
|
|
Long mappingId = SEQUENCE.nextId();
|
|
Long mappingId = SEQUENCE.nextId();
|
|
|
redisService.set(mappingId.toString(),url,60*60*24L);
|
|
redisService.set(mappingId.toString(),url,60*60*24L);
|
|
|
- AuthRedirect redirect = new AuthRedirect().setMappingId(mappingId).setSharedId(sharedId).setDsType(dsType).setPid(popularizeId);
|
|
|
|
|
|
|
+ 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();
|
|
String state = Codec.DoBase64.custom().setData(Jsons.toJson(redirect)).encodeAsText();
|
|
|
|
|
|
|
|
response.sendRedirect(authorizationService.createUrl(state,authType));
|
|
response.sendRedirect(authorizationService.createUrl(state,authType));
|
|
@@ -199,14 +203,17 @@ public class AuthorizationController {
|
|
|
* 网页微信授权登录
|
|
* 网页微信授权登录
|
|
|
*/
|
|
*/
|
|
|
@GetMapping("/wx/authLogin")
|
|
@GetMapping("/wx/authLogin")
|
|
|
- public Result<String> wxAuthorize(Long sharedId, Integer dsType, Long popularizeId) throws Exception {
|
|
|
|
|
|
|
+ public Result<String> wxAuthorize(Long sharedId, Integer dsType, Long popularizeId, String dsCode) throws Exception {
|
|
|
String wxAuthUrl = redisService.getStr(RedisService.key.WX_LOGIN_AUTH_URI.getNameFormat(wxOpenPlatYHLXLoginConfig.getAppId()));
|
|
String wxAuthUrl = redisService.getStr(RedisService.key.WX_LOGIN_AUTH_URI.getNameFormat(wxOpenPlatYHLXLoginConfig.getAppId()));
|
|
|
Long mappingId = SEQUENCE.nextId();
|
|
Long mappingId = SEQUENCE.nextId();
|
|
|
redisService.set(mappingId.toString(), wxOpenPlatYHLXLoginConfig.getLoginUrl(), 60 * 60 * 24L);
|
|
redisService.set(mappingId.toString(), wxOpenPlatYHLXLoginConfig.getLoginUrl(), 60 * 60 * 24L);
|
|
|
- AuthRedirect redirect = new AuthRedirect().setMappingId(mappingId).setSharedId(sharedId).setDsType(dsType).setPid(popularizeId);
|
|
|
|
|
|
|
+ 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();
|
|
String state = Codec.DoBase64.custom().setData(Jsons.toJson(redirect)).encodeAsText();
|
|
|
if (StrUtil.isEmpty(wxAuthUrl)) {
|
|
if (StrUtil.isEmpty(wxAuthUrl)) {
|
|
|
- wxAuthUrl = authorizationService.createWxAuthLoginUrl(state);
|
|
|
|
|
|
|
+ wxAuthUrl = authorizationService.createWxAuthLoginUrl(state, false);
|
|
|
}
|
|
}
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(wxAuthUrl);
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(wxAuthUrl);
|
|
|
}
|
|
}
|
|
@@ -226,9 +233,9 @@ public class AuthorizationController {
|
|
|
* 网页扫描微信公众号二维码 临时凭证ticket 关注后登录
|
|
* 网页扫描微信公众号二维码 临时凭证ticket 关注后登录
|
|
|
*/
|
|
*/
|
|
|
@GetMapping("/wx/gzh/login/qrCode")
|
|
@GetMapping("/wx/gzh/login/qrCode")
|
|
|
- public Result<WxGzhQrCodeTicketRep> getWxGzhQrCode(Long sharedId, Integer dsType, Long popularizeId) throws Exception {
|
|
|
|
|
|
|
+ public Result<WxGzhQrCodeTicketRep> getWxGzhQrCode(Long sharedId, Integer dsType, Long popularizeId, String dsCode) throws Exception {
|
|
|
//获取gzh带参数的二维码
|
|
//获取gzh带参数的二维码
|
|
|
- WxGzhQrCodeTicketRep result = weChatService.getWxGzhQrCode(sharedId, dsType, popularizeId, null);
|
|
|
|
|
|
|
+ WxGzhQrCodeTicketRep result = weChatService.getWxGzhQrCode(sharedId, dsType, popularizeId, null, dsCode);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(result);
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -237,7 +244,7 @@ public class AuthorizationController {
|
|
|
*/
|
|
*/
|
|
|
@GetMapping("/wx/gzh/qrCode")
|
|
@GetMapping("/wx/gzh/qrCode")
|
|
|
public Result<WxGzhQrCodeTicketRep> getWxGzhBindQrcode(String loginPhone) throws Exception {
|
|
public Result<WxGzhQrCodeTicketRep> getWxGzhBindQrcode(String loginPhone) throws Exception {
|
|
|
- WxGzhQrCodeTicketRep result = weChatService.getWxGzhQrCode(null, null, null, loginPhone);
|
|
|
|
|
|
|
+ WxGzhQrCodeTicketRep result = weChatService.getWxGzhQrCode(null, null, null, loginPhone, null);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(result);
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -343,14 +350,14 @@ public class AuthorizationController {
|
|
|
*/
|
|
*/
|
|
|
@PostMapping("/login/phone")
|
|
@PostMapping("/login/phone")
|
|
|
@NoSubmit
|
|
@NoSubmit
|
|
|
- public Result<LoginPhoneRep> loginByPhone(@RequestBody LoginPhoneReq loginPhoneReq) throws Exception {
|
|
|
|
|
|
|
+ public Result<LoginPhoneRep> loginByPhone(@RequestBody LoginReq LoginReq) throws Exception {
|
|
|
LambdaQueryWrapper<User> wrapper = Wrappers.lambdaQuery(User.class).last("limit 1");
|
|
LambdaQueryWrapper<User> wrapper = Wrappers.lambdaQuery(User.class).last("limit 1");
|
|
|
- if (loginPhoneReq.getType() == 1) {
|
|
|
|
|
- if (StrUtil.hasEmpty(loginPhoneReq.getPhone(), loginPhoneReq.getCode())) {
|
|
|
|
|
|
|
+ if (LoginReq.getType() == 1) {
|
|
|
|
|
+ if (StrUtil.hasEmpty(LoginReq.getPhone(), LoginReq.getCode())) {
|
|
|
throw BusinessRuntimeException.getInstance("请输入对应信息");
|
|
throw BusinessRuntimeException.getInstance("请输入对应信息");
|
|
|
}
|
|
}
|
|
|
DateTime now = DateTime.now();
|
|
DateTime now = DateTime.now();
|
|
|
- PhoneCode phoneCode = phoneCodeMapper.selectOne(Wrappers.lambdaQuery(PhoneCode.class).eq(PhoneCode::getPhone, loginPhoneReq.getPhone()).last("limit 1"));
|
|
|
|
|
|
|
+ PhoneCode phoneCode = phoneCodeMapper.selectOne(Wrappers.lambdaQuery(PhoneCode.class).eq(PhoneCode::getPhone, LoginReq.getPhone()).last("limit 1"));
|
|
|
if (phoneCode == null || StrUtil.isEmpty(phoneCode.getCode())) {
|
|
if (phoneCode == null || StrUtil.isEmpty(phoneCode.getCode())) {
|
|
|
throw BusinessRuntimeException.getInstance("请重新获取手机验证码");
|
|
throw BusinessRuntimeException.getInstance("请重新获取手机验证码");
|
|
|
}
|
|
}
|
|
@@ -360,50 +367,63 @@ public class AuthorizationController {
|
|
|
if (now.isAfter(afterFiveMinutes)) {
|
|
if (now.isAfter(afterFiveMinutes)) {
|
|
|
throw BusinessRuntimeException.getInstance("手机验证码已失效,请重新获取");
|
|
throw BusinessRuntimeException.getInstance("手机验证码已失效,请重新获取");
|
|
|
}
|
|
}
|
|
|
- if (!StrUtil.equals(loginPhoneReq.getCode(), phoneCode.getCode())) {
|
|
|
|
|
|
|
+ if (!StrUtil.equals(LoginReq.getCode(), phoneCode.getCode())) {
|
|
|
throw BusinessRuntimeException.getInstance("手机验证码错误,请重新输入");
|
|
throw BusinessRuntimeException.getInstance("手机验证码错误,请重新输入");
|
|
|
}
|
|
}
|
|
|
- wrapper.eq(User::getLoginPhone, loginPhoneReq.getPhone());
|
|
|
|
|
- }else if (loginPhoneReq.getType() == 2){
|
|
|
|
|
- if (StrUtil.isEmpty(loginPhoneReq.getEmail())) {
|
|
|
|
|
|
|
+ wrapper.eq(User::getLoginPhone, LoginReq.getPhone());
|
|
|
|
|
+ }else if (LoginReq.getType() == 2){
|
|
|
|
|
+ if (StrUtil.isEmpty(LoginReq.getEmail())) {
|
|
|
throw BusinessRuntimeException.getInstance("邮箱不能为空");
|
|
throw BusinessRuntimeException.getInstance("邮箱不能为空");
|
|
|
}
|
|
}
|
|
|
- String code = redisService.getStr(RedisService.key.EMAIL_CODE_KEY.getNameFormat(loginPhoneReq.getEmail()));
|
|
|
|
|
|
|
+ String code = redisService.getStr(RedisService.key.EMAIL_CODE_KEY.getNameFormat(LoginReq.getEmail()));
|
|
|
if (StrUtil.isEmpty(code)) {
|
|
if (StrUtil.isEmpty(code)) {
|
|
|
throw BusinessRuntimeException.getInstance("邮箱验证码已失效,请重新获取");
|
|
throw BusinessRuntimeException.getInstance("邮箱验证码已失效,请重新获取");
|
|
|
}
|
|
}
|
|
|
- if (!StrUtil.equals(loginPhoneReq.getCode(), code)) {
|
|
|
|
|
|
|
+ if (!StrUtil.equals(LoginReq.getCode(), code)) {
|
|
|
throw BusinessRuntimeException.getInstance("邮箱验证码错误,请重新输入");
|
|
throw BusinessRuntimeException.getInstance("邮箱验证码错误,请重新输入");
|
|
|
}
|
|
}
|
|
|
- wrapper.eq(User::getEmail, loginPhoneReq.getEmail());
|
|
|
|
|
- redisService.del(RedisService.key.EMAIL_CODE_KEY.getNameFormat(loginPhoneReq.getEmail()));
|
|
|
|
|
|
|
+ wrapper.eq(User::getEmail, LoginReq.getEmail());
|
|
|
|
|
+ redisService.del(RedisService.key.EMAIL_CODE_KEY.getNameFormat(LoginReq.getEmail()));
|
|
|
}else {
|
|
}else {
|
|
|
throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重新操作");
|
|
throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重新操作");
|
|
|
}
|
|
}
|
|
|
//保存用户信息
|
|
//保存用户信息
|
|
|
User user = userService.getOne(wrapper);
|
|
User user = userService.getOne(wrapper);
|
|
|
- Long sharedId = loginPhoneReq.getSharedId();
|
|
|
|
|
|
|
+ String dsCode = LoginReq.getDsCode();
|
|
|
|
|
+ Long sharedId = LoginReq.getSharedId();
|
|
|
|
|
+ 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();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
if (user == null) {
|
|
if (user == null) {
|
|
|
user = new User();
|
|
user = new User();
|
|
|
- if (loginPhoneReq.getPopularizeId() != null) {
|
|
|
|
|
- user.setPopularizeId(loginPhoneReq.getPopularizeId());
|
|
|
|
|
|
|
+ if (LoginReq.getPopularizeId() != null) {
|
|
|
|
|
+ user.setPopularizeId(LoginReq.getPopularizeId());
|
|
|
}
|
|
}
|
|
|
- if (loginPhoneReq.getType() == 1) {
|
|
|
|
|
- user.setLoginPhone(loginPhoneReq.getPhone());
|
|
|
|
|
- } else if (loginPhoneReq.getType() == 2) {
|
|
|
|
|
- user.setEmail(loginPhoneReq.getEmail());
|
|
|
|
|
|
|
+ if (LoginReq.getType() == 1) {
|
|
|
|
|
+ user.setLoginPhone(LoginReq.getPhone());
|
|
|
|
|
+ } else if (LoginReq.getType() == 2) {
|
|
|
|
|
+ user.setEmail(LoginReq.getEmail());
|
|
|
}
|
|
}
|
|
|
String name = Constant.DEFAULT_NAME;
|
|
String name = Constant.DEFAULT_NAME;
|
|
|
- if (loginPhoneReq.getType() == 2) {
|
|
|
|
|
|
|
+ if (LoginReq.getType() == 2) {
|
|
|
name += "@";
|
|
name += "@";
|
|
|
}
|
|
}
|
|
|
- user.setNickname(String.format("%s%s", name, Codec.DoDigest.custom().setAlgorithm(Codec.DoDigest.Algorithm.MD5).setStringData(String.format("%s%s", user.getId(), loginPhoneReq.getType() == 1 ? user.getLoginPhone() : user.getEmail())).toHexString().substring(0, 6)));
|
|
|
|
|
|
|
+ user.setNickname(String.format("%s%s", name, Codec.DoDigest.custom().setAlgorithm(Codec.DoDigest.Algorithm.MD5).setStringData(String.format("%s%s", user.getId(), LoginReq.getType() == 1 ? user.getLoginPhone() : user.getEmail())).toHexString().substring(0, 6)));
|
|
|
//默认头像
|
|
//默认头像
|
|
|
user.setHeadimgurl(Constant.DEFAULT_HEAD_IMG);
|
|
user.setHeadimgurl(Constant.DEFAULT_HEAD_IMG);
|
|
|
userService.save(user);
|
|
userService.save(user);
|
|
|
//新用户分销
|
|
//新用户分销
|
|
|
if (sharedId != null) {
|
|
if (sharedId != null) {
|
|
|
- distributeService.saveDistributionInvitation(sharedId, user.getId());
|
|
|
|
|
|
|
+ distributeService.saveDistributionInvitation(sharedId, user.getId(), dsPopularizeId);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
//写回登陆信息
|
|
//写回登陆信息
|
|
@@ -420,7 +440,7 @@ public class AuthorizationController {
|
|
|
String json = Codec.DoBase64.custom().setData(state).decodeAsText();
|
|
String json = Codec.DoBase64.custom().setData(state).decodeAsText();
|
|
|
AuthRedirect re = Jsons.parseObject(json, AuthRedirect.class);
|
|
AuthRedirect re = Jsons.parseObject(json, AuthRedirect.class);
|
|
|
//保存用户信息
|
|
//保存用户信息
|
|
|
- User user = userService.saveAuth(userinfo, re.getSharedId(), re.getDsType(), re.getPid());
|
|
|
|
|
|
|
+ User user = userService.saveAuth(userinfo, re.getSharedId(), re.getDsType(), re.getPid(), re.getDsCode());
|
|
|
if (user == null) {
|
|
if (user == null) {
|
|
|
throw BusinessRuntimeException.getInstance("系统错误,请重新授权");
|
|
throw BusinessRuntimeException.getInstance("系统错误,请重新授权");
|
|
|
}
|
|
}
|