Browse Source

加个接口

master
nili 1 year ago
parent
commit
cc497b9618
  1. 2
      game-dao/src/main/java/awesome/group/game/dao/mapper/WeGameUserMapper.java
  2. 6
      game-service/src/main/java/awesome/group/game/service/WxService.java
  3. 17
      game-service/src/main/java/awesome/group/game/service/bo/CurrentUser.java
  4. 13
      game-web/src/main/java/awesome/group/controller/LoginController.java

2
game-dao/src/main/java/awesome/group/game/dao/mapper/WeGameUserMapper.java

@ -19,6 +19,6 @@ public interface WeGameUserMapper extends BaseMapper<WeGameUser> {
@Update("update we_game_user set score = #{score} where id = #{id}")
int updateScore(@Param("score")Integer score, @Param("id")Integer id);
@Select("select * from we_game_user where app_id = #{appId} order by score desc limit #{size}")
@Select("select * from we_game_user where app_id = #{appId} and score > 0 order by score desc limit #{size}")
List<WeGameUser> queryTop(@Param("appId")String appId, @Param("size")Integer size);
}

6
game-service/src/main/java/awesome/group/game/service/WxService.java

@ -2,6 +2,7 @@ package awesome.group.game.service;
import awesome.group.game.dao.bean.GameApp;
import awesome.group.game.service.bo.CurrentUser;
import awesome.group.game.service.bo.RankList;
import awesome.group.game.service.bo.UserInfo;
import awesome.group.game.dao.bean.WeGameUser;
@ -33,6 +34,11 @@ public class WxService {
@Resource
private GameAppMapper gameAppMapper;
public CurrentUser currentUser(Integer userId) {
WeGameUser user = weGameUserMapper.selectById(userId);
return new CurrentUser(user);
}
public String login(String code, String appId) {
Code2SessionBo data = getSession(code, appId);
if (data == null || data.openid == null) {

17
game-service/src/main/java/awesome/group/game/service/bo/CurrentUser.java

@ -0,0 +1,17 @@
package awesome.group.game.service.bo;
import awesome.group.game.dao.bean.WeGameUser;
import lombok.Data;
import org.springframework.beans.BeanUtils;
@Data
public class CurrentUser extends UserInfo{
public String openId;
public CurrentUser() {
}
public CurrentUser(WeGameUser user) {
BeanUtils.copyProperties(user, this);
}
}

13
game-web/src/main/java/awesome/group/controller/LoginController.java

@ -2,15 +2,13 @@ package awesome.group.controller;
import awesome.group.RequestContext;
import awesome.group.aop.RestApi;
import awesome.group.game.service.bo.RankList;
import awesome.group.game.service.bo.UserInfo;
import awesome.group.game.service.WxService;
import awesome.group.game.service.bo.CurrentUser;
import awesome.group.game.service.bo.RankList;
import awesome.group.game.service.common.response.R;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/game/auth")
public class LoginController {
@ -18,6 +16,13 @@ public class LoginController {
@Resource
private WxService wxService;
@GetMapping
@RestApi
public R<CurrentUser> currentUser() {
Integer userId = RequestContext.getUid();
return new R<>(wxService.currentUser(userId));
}
/**
* 微信登陆
* 返回jwt token

Loading…
Cancel
Save