Browse Source

登录绑定上级

master
nili 7 months ago
parent
commit
d6d27106cc
  1. 1
      game-service/src/main/java/awesome/group/game/service/bo/citrus/LoginReq.java
  2. 7
      game-service/src/main/java/awesome/group/game/service/citrus/UserService.java
  3. 2
      game-web/src/main/java/awesome/group/game/web/filter/CitrusLoginFilter.java
  4. 2
      game-web/src/main/java/awesome/group/game/web/rest/citrus/OpenController.java

1
game-service/src/main/java/awesome/group/game/service/bo/citrus/LoginReq.java

@ -6,5 +6,6 @@ public class LoginReq {
public String appCode; public String appCode;
public String code;//验证码 public String code;//验证码
public String token;//友盟token public String token;//友盟token
public String inviteCode;
} }

7
game-service/src/main/java/awesome/group/game/service/citrus/UserService.java

@ -92,7 +92,7 @@ public class UserService {
return user; return user;
} }
public MatrixUser loginByToken(String appCode, String token) { public MatrixUser loginByToken(String appCode, String token, String inviteCode) {
Assert.isTrue(StringUtils.hasText(appCode), "非法请求"); Assert.isTrue(StringUtils.hasText(appCode), "非法请求");
Assert.isTrue(StringUtils.hasText(token), "非法请求"); Assert.isTrue(StringUtils.hasText(token), "非法请求");
MatrixApp app = appMapper.queryByCode(appCode); MatrixApp app = appMapper.queryByCode(appCode);
@ -101,10 +101,15 @@ public class UserService {
UmengConfigBo configBo = gson.fromJson(app.getUmeng(), UmengConfigBo.class); UmengConfigBo configBo = gson.fromJson(app.getUmeng(), UmengConfigBo.class);
String mobile = uMengService.getMobile(token, configBo); String mobile = uMengService.getMobile(token, configBo);
MatrixUser user = userMapper.selectByAppIdAndMobile(app.getId(), mobile); MatrixUser user = userMapper.selectByAppIdAndMobile(app.getId(), mobile);
MatrixUser upUser = null;
if (StringUtils.hasText(inviteCode)) {
upUser = userMapper.selectByInviteCode(inviteCode);
}
if (user == null) { if (user == null) {
user = new MatrixUser(); user = new MatrixUser();
user.setAppId(app.getId()); user.setAppId(app.getId());
user.setMobile(mobile); user.setMobile(mobile);
user.setUpUid(upUser == null ? null : upUser.getId());
user.setInviteCode(RandomStringUtils.randomAlphabetic(12)); user.setInviteCode(RandomStringUtils.randomAlphabetic(12));
userMapper.insert(user); userMapper.insert(user);
} }

2
game-web/src/main/java/awesome/group/game/web/filter/CitrusLoginFilter.java

@ -68,7 +68,7 @@ public class CitrusLoginFilter implements Filter {
} }
private void authFail(ServletResponse response) throws IOException { private void authFail(ServletResponse response) throws IOException {
R<String> res = new R<>(-88888, "not login ", null); R<String> res = new R<>(-88888, "", null);
Gson gson = new Gson(); Gson gson = new Gson();
response.setContentType("application/json;charset=UTF-8"); response.setContentType("application/json;charset=UTF-8");
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");

2
game-web/src/main/java/awesome/group/game/web/rest/citrus/OpenController.java

@ -70,7 +70,7 @@ public class OpenController {
@PostMapping("/loginByToken") @PostMapping("/loginByToken")
@RestApi @RestApi
public R<String> loginByToken(@RequestBody LoginReq req) { public R<String> loginByToken(@RequestBody LoginReq req) {
MatrixUser u = userService.loginByToken(req.appCode, req.token); MatrixUser u = userService.loginByToken(req.appCode, req.token, req.inviteCode);
String token = JwtUtils.generatorToken(u.getId() + "", 15 * 86400); String token = JwtUtils.generatorToken(u.getId() + "", 15 * 86400);
return new R<>(R.CODE_SUCCESS, "ok", token); return new R<>(R.CODE_SUCCESS, "ok", token);
} }

Loading…
Cancel
Save