|
|
@@ -221,12 +221,106 @@ public class AuthController {
|
|
|
String logincode = jsonObject.getStr("logincode");
|
|
|
String phonecode = jsonObject.getStr("phonecode");
|
|
|
|
|
|
+
|
|
|
+
|
|
|
AuthRequest authRequest = SocialUtils.getAuthRequest("wechat_mini_program", socialProperties);
|
|
|
AuthResponse<AuthUser> response = authRequest.login(AuthCallback.builder().code(logincode).build());
|
|
|
AuthUser authUserData = response.getData();
|
|
|
if (!response.ok()) {
|
|
|
return R.fail(response.getMsg());
|
|
|
}
|
|
|
+
|
|
|
+ wxMaService.switchover(socialProperties.getType().get("wechat_mini_program").getClientId());
|
|
|
+ WxMaPhoneNumberInfo phone = wxMaService.getUserService().getPhoneNumber(phonecode);
|
|
|
+ SysUserVo userVo = sysUserService.selectUserByUserName(phone.getPhoneNumber());
|
|
|
+ if(userVo==null){
|
|
|
+ //注册
|
|
|
+ RegisterBody user = new RegisterBody();
|
|
|
+ user.setUsername(phone.getPhoneNumber());
|
|
|
+ user.setPassword(UuidUtils.getUUID().substring(0,6));
|
|
|
+ user.setUserType("app_user");
|
|
|
+ user.setPhonenumber(phone.getPhoneNumber());
|
|
|
+ registerService.register(user);
|
|
|
+ userVo = sysUserService.selectUserByUserName(phone.getPhoneNumber());
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ SysUserBo bo = BeanUtil.toBean(userVo, SysUserBo.class);
|
|
|
+ if (bo.getRoleIds() == null) {
|
|
|
+ bo.setRoleIds(new Long[]{1763484977044361217L});
|
|
|
+ bo.setPassword(null);
|
|
|
+ bo.setUserType(null);
|
|
|
+ } else {
|
|
|
+ List<Long> a = Arrays.stream(bo.getRoleIds()).toList();
|
|
|
+ if(!a.contains(1763484977044361217L)){
|
|
|
+ a.add(1763484977044361217L);
|
|
|
+ }
|
|
|
+ bo.setPassword(null);
|
|
|
+ bo.setUserType(null);
|
|
|
+ bo.setRoleIds((Long[]) a.toArray());
|
|
|
+
|
|
|
+ }
|
|
|
+ DataPermissionHelper.ignore(() -> sysUserService.updateUser(bo));
|
|
|
+ }catch (Exception e){}
|
|
|
+
|
|
|
+ //绑定微信
|
|
|
+ SysSocialBo bo = BeanUtil.toBean(authUserData, SysSocialBo.class);
|
|
|
+ String authId = authUserData.getSource() + authUserData.getUuid();
|
|
|
+ BeanUtil.copyProperties(authUserData.getToken(), bo);
|
|
|
+ bo.setUserId(userVo.getUserId());
|
|
|
+ bo.setAuthId(authId);
|
|
|
+ bo.setOpenId(authUserData.getUuid());
|
|
|
+ bo.setUserName(authUserData.getUsername());
|
|
|
+ bo.setNickName(authUserData.getNickname());
|
|
|
+ // 查询是否已经绑定用户
|
|
|
+ List<SysSocialVo> list = sysSocialService.selectByAuthId(authId);
|
|
|
+ if (CollUtil.isEmpty(list)) {
|
|
|
+ // 没有绑定用户, 新增用户信息
|
|
|
+ sysSocialService.insertByBo(bo);
|
|
|
+ } else {
|
|
|
+ // 更新用户信息
|
|
|
+ bo.setId(list.get(0).getId());
|
|
|
+ sysSocialService.updateByBo(bo);
|
|
|
+ }
|
|
|
+
|
|
|
+ SysClient client = clientService.queryByClientId("e5cd7e4891bf95d1d19206ce24a7b32e");
|
|
|
+ LoginUser loginUser = loginService.buildLoginUser(userVo);
|
|
|
+ loginUser.setClientKey(client.getClientKey());
|
|
|
+ loginUser.setDeviceType(client.getDeviceType());
|
|
|
+ SaLoginModel model = new SaLoginModel();
|
|
|
+ model.setDevice(client.getDeviceType());
|
|
|
+ model.setTimeout(client.getTimeout());
|
|
|
+ model.setActiveTimeout(client.getActiveTimeout());
|
|
|
+ model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
|
|
|
+ // 生成token
|
|
|
+ LoginHelper.login(loginUser, model);
|
|
|
+
|
|
|
+ LoginVo loginVo = new LoginVo();
|
|
|
+ loginVo.setAccessToken(StpUtil.getTokenValue());
|
|
|
+ loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
|
|
+ loginVo.setClientId(client.getClientId());
|
|
|
+
|
|
|
+ return R.ok(loginVo);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping("/BC/loginByPhoneCodeAndLoginCode")
|
|
|
+ public R<LoginVo> BcregisterByPhonecode(@RequestBody String loginbody) throws WxErrorException {
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(loginbody);
|
|
|
+ String logincode = jsonObject.getStr("logincode");
|
|
|
+ String phonecode = jsonObject.getStr("phonecode");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ AuthRequest authRequest = SocialUtils.getAuthRequest("wechat_mini_program_1", socialProperties);
|
|
|
+ AuthResponse<AuthUser> response = authRequest.login(AuthCallback.builder().code(logincode).build());
|
|
|
+ AuthUser authUserData = response.getData();
|
|
|
+ if (!response.ok()) {
|
|
|
+ return R.fail(response.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+ wxMaService.switchover(socialProperties.getType().get("wechat_mini_program_1").getClientId());
|
|
|
WxMaPhoneNumberInfo phone = wxMaService.getUserService().getPhoneNumber(phonecode);
|
|
|
SysUserVo userVo = sysUserService.selectUserByUserName(phone.getPhoneNumber());
|
|
|
if(userVo==null){
|