|
@ -2,23 +2,26 @@ package awesome.group.game.service; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import awesome.group.game.dao.bean.GameApp; |
|
|
import awesome.group.game.dao.bean.GameApp; |
|
|
import awesome.group.game.service.bo.CurrentUser; |
|
|
import awesome.group.game.dao.bean.InviteRecord; |
|
|
import awesome.group.game.service.bo.RankList; |
|
|
import awesome.group.game.dao.mapper.InviteRecordMapper; |
|
|
import awesome.group.game.service.bo.UserInfo; |
|
|
import awesome.group.game.service.bo.*; |
|
|
import awesome.group.game.dao.bean.WeGameUser; |
|
|
import awesome.group.game.dao.bean.WeGameUser; |
|
|
import awesome.group.game.dao.bean.WxUserInfo; |
|
|
import awesome.group.game.service.bo.WxUserInfo; |
|
|
import awesome.group.game.dao.mapper.GameAppMapper; |
|
|
import awesome.group.game.dao.mapper.GameAppMapper; |
|
|
import awesome.group.game.dao.mapper.WeGameUserMapper; |
|
|
import awesome.group.game.dao.mapper.WeGameUserMapper; |
|
|
import awesome.group.game.service.bo.Code2SessionBo; |
|
|
|
|
|
import awesome.group.game.service.common.exception.PaganiException; |
|
|
import awesome.group.game.service.common.exception.PaganiException; |
|
|
import awesome.group.game.service.common.exception.PaganiExceptionCode; |
|
|
import awesome.group.game.service.common.exception.PaganiExceptionCode; |
|
|
import awesome.group.game.service.util.EncryptUtil; |
|
|
import awesome.group.game.service.util.EncryptUtil; |
|
|
import awesome.group.game.service.util.HttpUtils; |
|
|
import awesome.group.game.service.util.HttpUtils; |
|
|
import awesome.group.game.service.util.JwtUtils; |
|
|
import awesome.group.game.service.util.JwtUtils; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
import com.google.gson.Gson; |
|
|
import com.google.gson.Gson; |
|
|
import jakarta.annotation.Resource; |
|
|
import jakarta.annotation.Resource; |
|
|
|
|
|
import org.apache.commons.lang.RandomStringUtils; |
|
|
import org.springframework.beans.BeanUtils; |
|
|
import org.springframework.beans.BeanUtils; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.util.StringUtils; |
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
@ -34,12 +37,39 @@ public class WxService { |
|
|
@Resource |
|
|
@Resource |
|
|
private GameAppMapper gameAppMapper; |
|
|
private GameAppMapper gameAppMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
private InviteRecordMapper inviteRecordMapper; |
|
|
|
|
|
|
|
|
public CurrentUser currentUser(Integer userId) { |
|
|
public CurrentUser currentUser(Integer userId) { |
|
|
WeGameUser user = weGameUserMapper.selectById(userId); |
|
|
WeGameUser user = weGameUserMapper.selectById(userId); |
|
|
return new CurrentUser(user); |
|
|
return new CurrentUser(user); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public String login(String code, String appId) { |
|
|
public void setInviteCode() { |
|
|
|
|
|
List<WeGameUser> list = weGameUserMapper.selectList(Wrappers.emptyWrapper()); |
|
|
|
|
|
list.forEach(x -> { |
|
|
|
|
|
x.setInviteCode(RandomStringUtils.randomAlphanumeric(10)); |
|
|
|
|
|
weGameUserMapper.updateById(x); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
InviteRecord record = new InviteRecord(); |
|
|
|
|
|
record.setUserId(1000003); |
|
|
|
|
|
record.setInvitedUserId(1000001); |
|
|
|
|
|
inviteRecordMapper.insert(record); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public List<UserInfo> myInviteRecord(Integer userId) { |
|
|
|
|
|
List<Integer> list = inviteRecordMapper.query(userId); |
|
|
|
|
|
if (CollectionUtils.isEmpty(list)) { |
|
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
|
} |
|
|
|
|
|
LambdaQueryWrapper<WeGameUser> query = Wrappers.lambdaQuery(); |
|
|
|
|
|
query.in(WeGameUser::getId, list); |
|
|
|
|
|
List<WeGameUser> data = weGameUserMapper.selectList(query); |
|
|
|
|
|
return data.stream().map(UserInfo::new).toList(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public WeGameUser login(String code, String appId) { |
|
|
Code2SessionBo data = getSession(code, appId); |
|
|
Code2SessionBo data = getSession(code, appId); |
|
|
if (data == null || data.openid == null) { |
|
|
if (data == null || data.openid == null) { |
|
|
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "登陆失败,非法code"); |
|
|
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "登陆失败,非法code"); |
|
@ -51,13 +81,46 @@ public class WxService { |
|
|
u.setAppId(appId); |
|
|
u.setAppId(appId); |
|
|
u.setUnionId(data.unionid); |
|
|
u.setUnionId(data.unionid); |
|
|
u.setSessionKey(data.session_key); |
|
|
u.setSessionKey(data.session_key); |
|
|
|
|
|
u.setInviteCode(RandomStringUtils.randomAlphanumeric(10)); |
|
|
weGameUserMapper.insert(u); |
|
|
weGameUserMapper.insert(u); |
|
|
} else { |
|
|
} else { |
|
|
weGameUserMapper.updateSessionKey(data.session_key, u.getId()); |
|
|
weGameUserMapper.updateSessionKey(data.session_key, u.getId()); |
|
|
} |
|
|
} |
|
|
|
|
|
return u; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String loginV1(String code, String appId) { |
|
|
|
|
|
WeGameUser u = login(code, appId); |
|
|
return JwtUtils.generatorToken(u.getId() + "", 20 * 86400); |
|
|
return JwtUtils.generatorToken(u.getId() + "", 20 * 86400); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public LoginBo loginV2(String code, String appId, String inviteCode) { |
|
|
|
|
|
WeGameUser u = login(code, appId); |
|
|
|
|
|
LoginBo res = new LoginBo(); |
|
|
|
|
|
res.inviteCode = u.getInviteCode(); |
|
|
|
|
|
res.jwtToken = JwtUtils.generatorToken(u.getId() + "", 20 * 86400); |
|
|
|
|
|
if (!StringUtils.hasText(inviteCode)) { |
|
|
|
|
|
return res; |
|
|
|
|
|
} |
|
|
|
|
|
LambdaQueryWrapper<WeGameUser> query = Wrappers.lambdaQuery(); |
|
|
|
|
|
query.eq(WeGameUser::getInviteCode, inviteCode); |
|
|
|
|
|
WeGameUser user = weGameUserMapper.selectOne(query); |
|
|
|
|
|
if (user == null || user.getId().equals(u.getId())) { |
|
|
|
|
|
return res; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<InviteRecord> inviteQuery = Wrappers.lambdaQuery(); |
|
|
|
|
|
inviteQuery.eq(InviteRecord::getInvitedUserId, u.getId()); |
|
|
|
|
|
if (inviteRecordMapper.selectOne(inviteQuery) != null) { |
|
|
|
|
|
return res; |
|
|
|
|
|
} |
|
|
|
|
|
InviteRecord record = new InviteRecord(); |
|
|
|
|
|
record.userId = user.getId(); |
|
|
|
|
|
record.invitedUserId = u.getId(); |
|
|
|
|
|
inviteRecordMapper.insert(record); |
|
|
|
|
|
return res; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public void updateUserInfo(Integer userId, String rawData, String signature) { |
|
|
public void updateUserInfo(Integer userId, String rawData, String signature) { |
|
|
if (!verify(userId, rawData, signature)) { |
|
|
if (!verify(userId, rawData, signature)) { |
|
|
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "签名有误"); |
|
|
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "签名有误"); |
|
|