Browse Source

微信登录

master
nili 5 months ago
parent
commit
ec50eadcf6
  1. 3
      game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixUserMapper.java
  2. 3
      game-service/src/main/java/awesome/group/game/service/bo/citrus/LoginReq.java
  3. 38
      game-service/src/main/java/awesome/group/game/service/citrus/UserService.java
  4. 8
      game-web/src/main/java/awesome/group/game/web/rest/citrus/OpenController.java

3
game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixUserMapper.java

@ -13,6 +13,9 @@ public interface MatrixUserMapper extends BaseMapper<MatrixUser> {
@Select("select * from matrix_user where app_id = #{appId} and mobile = #{mobile}") @Select("select * from matrix_user where app_id = #{appId} and mobile = #{mobile}")
MatrixUser selectByAppIdAndMobile(int appId, String mobile); MatrixUser selectByAppIdAndMobile(int appId, String mobile);
@Select("select * from matrix_user where app_id = #{appId} and open_id = #{openId}")
MatrixUser selectByAppIdAndOpenId(int appId, String openId);
@Update("update matrix_user set money = money + #{cent} where id = #{userId}") @Update("update matrix_user set money = money + #{cent} where id = #{userId}")
int incMoney(int userId, int cent); int incMoney(int userId, int cent);

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

@ -8,4 +8,7 @@ public class LoginReq {
public String token;//友盟token public String token;//友盟token
public String inviteCode; public String inviteCode;
public String accessToken;//微信的
public String openId;//微信的
} }

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

@ -11,10 +11,7 @@ import awesome.group.game.dao.mapper.MatrixUserMapper;
import awesome.group.game.service.SmsService; import awesome.group.game.service.SmsService;
import awesome.group.game.service.UMengService; import awesome.group.game.service.UMengService;
import awesome.group.game.service.bo.MatrixAdvRecordSimple; import awesome.group.game.service.bo.MatrixAdvRecordSimple;
import awesome.group.game.service.bo.citrus.CashRecord; import awesome.group.game.service.bo.citrus.*;
import awesome.group.game.service.bo.citrus.LoginReq;
import awesome.group.game.service.bo.citrus.TeamBo;
import awesome.group.game.service.bo.citrus.UserBo;
import awesome.group.game.service.bo.matrix.AppNormalConfig; import awesome.group.game.service.bo.matrix.AppNormalConfig;
import awesome.group.game.service.bo.matrix.UmengConfigBo; import awesome.group.game.service.bo.matrix.UmengConfigBo;
import awesome.group.game.service.common.exception.PaganiException; import awesome.group.game.service.common.exception.PaganiException;
@ -62,6 +59,9 @@ public class UserService {
@Autowired @Autowired
private MatrixAdvRecordMapper advRecordMapper; private MatrixAdvRecordMapper advRecordMapper;
@Autowired
private WeiXinService weiXinService;
public static final int STATUS_WAITING = 0;//等审核 public static final int STATUS_WAITING = 0;//等审核
public static final int STATUS_AUDIT_PASS = 1;//已审核通过 public static final int STATUS_AUDIT_PASS = 1;//已审核通过
@ -130,6 +130,36 @@ public class UserService {
return user; return user;
} }
public MatrixUser loginByWechat(String appCode, String accessToken, String openId, String inviteCode) {
Assert.isTrue(StringUtils.hasText(appCode), "非法请求");
Assert.isTrue(StringUtils.hasText(accessToken), "非法请求");
Assert.isTrue(StringUtils.hasText(openId), "非法请求");
MatrixApp app = appMapper.queryByCode(appCode);
Assert.isTrue(app != null, "非法请求");
WxUserInfo info = weiXinService.getWxUserInfo(accessToken, openId);
MatrixUser user = userMapper.selectByAppIdAndOpenId(app.getId(), info.openid);
if (user != null && user.getStatus() == Constants.USER_BANNED) {
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "账号异常,无法登录");
}
MatrixUser upUser = null;
if (StringUtils.hasText(inviteCode)) {
upUser = userMapper.selectByInviteCode(inviteCode);
}
if (user == null) {
user = new MatrixUser();
user.setAppId(app.getId());
user.setWxOpenId(info.openid);
user.setNickname(info.nickname);
user.setAvatar(info.headimgurl);
user.setUpUid(upUser == null ? null : upUser.getId());
user.setInviteCode(RandomStringUtils.randomAlphabetic(12));
userMapper.insert(user);
} else {
userMapper.updateWx(info.openid, info.nickname, info.headimgurl, user.getId());
}
return user;
}
public UserBo getUser(Integer uid) { public UserBo getUser(Integer uid) {
MatrixUser u = userMapper.selectById(uid); MatrixUser u = userMapper.selectById(uid);
MatrixApp app = new MatrixApp(); MatrixApp app = new MatrixApp();

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

@ -85,6 +85,14 @@ public class OpenController {
return new R<>(R.CODE_SUCCESS, "ok", token); return new R<>(R.CODE_SUCCESS, "ok", token);
} }
@PostMapping("/loginByWechat")
@RestApi
public R<String> loginByWechat(@RequestBody LoginReq req) {
MatrixUser u = userService.loginByWechat(req.appCode, req.accessToken, req.openId, req.inviteCode);
String token = JwtUtils.generatorToken(u.getId() + "", 15 * 86400);
return new R<>(R.CODE_SUCCESS, "ok", token);
}
@GetMapping("/open/getAppDetail") @GetMapping("/open/getAppDetail")
@RestApi @RestApi

Loading…
Cancel
Save