|
@@ -9,6 +9,7 @@ import com.zanxiang.game.module.base.rpc.IKfMsgRpc;
|
|
|
import com.zanxiang.game.module.mybatis.entity.Game;
|
|
import com.zanxiang.game.module.mybatis.entity.Game;
|
|
|
import com.zanxiang.game.module.mybatis.entity.GameApplet;
|
|
import com.zanxiang.game.module.mybatis.entity.GameApplet;
|
|
|
import com.zanxiang.game.module.mybatis.entity.GameExt;
|
|
import com.zanxiang.game.module.mybatis.entity.GameExt;
|
|
|
|
|
+import com.zanxiang.game.module.mybatis.entity.GameSupper;
|
|
|
import com.zanxiang.game.module.mybatis.mapper.GameAppletMapper;
|
|
import com.zanxiang.game.module.mybatis.mapper.GameAppletMapper;
|
|
|
import com.zanxiang.game.module.sdk.pojo.dto.AppletMsgDTO;
|
|
import com.zanxiang.game.module.sdk.pojo.dto.AppletMsgDTO;
|
|
|
import com.zanxiang.game.module.sdk.pojo.dto.GameAppletDTO;
|
|
import com.zanxiang.game.module.sdk.pojo.dto.GameAppletDTO;
|
|
@@ -17,6 +18,7 @@ import com.zanxiang.game.module.sdk.pojo.vo.GameInitVO;
|
|
|
import com.zanxiang.game.module.sdk.service.IGameAppletService;
|
|
import com.zanxiang.game.module.sdk.service.IGameAppletService;
|
|
|
import com.zanxiang.game.module.sdk.service.IGameExtService;
|
|
import com.zanxiang.game.module.sdk.service.IGameExtService;
|
|
|
import com.zanxiang.game.module.sdk.service.IGameService;
|
|
import com.zanxiang.game.module.sdk.service.IGameService;
|
|
|
|
|
+import com.zanxiang.game.module.sdk.service.IGameSupperService;
|
|
|
import com.zanxiang.game.module.sdk.service.api.WxApiService;
|
|
import com.zanxiang.game.module.sdk.service.api.WxApiService;
|
|
|
import com.zanxiang.game.module.sdk.service.pay.MiPayService;
|
|
import com.zanxiang.game.module.sdk.service.pay.MiPayService;
|
|
|
import com.zanxiang.game.module.sdk.util.SignUtil;
|
|
import com.zanxiang.game.module.sdk.util.SignUtil;
|
|
@@ -65,12 +67,26 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IGameAppletService gameAppletService;
|
|
private IGameAppletService gameAppletService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IGameSupperService gameSupperService;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
- public Map<String, String> getAppletToken(String gameAppId) {
|
|
|
|
|
- GameExt gameExt = gameExtService.getByGameAppId(gameAppId);
|
|
|
|
|
|
|
+ public Map<String, String> getAppletToken(String gameId, Long signTime, String sign) {
|
|
|
|
|
+ GameExt gameExt = gameExtService.getByGameAppId(gameId);
|
|
|
if (gameExt == null) {
|
|
if (gameExt == null) {
|
|
|
throw new BaseException("参数错误, 游戏配置信息不存在");
|
|
throw new BaseException("参数错误, 游戏配置信息不存在");
|
|
|
}
|
|
}
|
|
|
|
|
+ Game game = gameService.getById(gameExt.getGameId());
|
|
|
|
|
+ if (game == null) {
|
|
|
|
|
+ throw new BaseException("参数错误, 游戏信息不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ GameSupper gameSupper = gameSupperService.getById(game.getSuperGameId());
|
|
|
|
|
+ if (gameSupper == null) {
|
|
|
|
|
+ throw new BaseException("参数错误, 超父游戏信息不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ //签名验证
|
|
|
|
|
+ this.signCheck(gameSupper.getCpServerKey(), gameId, signTime, sign);
|
|
|
|
|
+ //获取小程序 accessToken
|
|
|
GameAppletDTO gameAppletDTO = gameAppletService.getByGameId(gameExt.getGameId());
|
|
GameAppletDTO gameAppletDTO = gameAppletService.getByGameId(gameExt.getGameId());
|
|
|
if (gameAppletDTO == null) {
|
|
if (gameAppletDTO == null) {
|
|
|
throw new BaseException("参数错误, 微信小游戏配置信息不存在");
|
|
throw new BaseException("参数错误, 微信小游戏配置信息不存在");
|
|
@@ -82,6 +98,20 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
|
|
|
return resultMap;
|
|
return resultMap;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void signCheck(String cpServerKey, String gameId, Long signTime, String sign) {
|
|
|
|
|
+ String signStr = "cpServerKey=" + cpServerKey + "gameId=" + gameId + "signTime=" + signTime;
|
|
|
|
|
+ String mySign;
|
|
|
|
|
+ try {
|
|
|
|
|
+ mySign = SignUtil.MD5(signStr);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Objects.equals(mySign.toUpperCase(), sign.toUpperCase())) {
|
|
|
|
|
+ log.error("加密验证失败, sign : {}, mySign : {}", sign, mySign);
|
|
|
|
|
+ throw new BaseException("加密标识错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public String appletMsgCheck(String appId, String signature, String timestamp, String nonce, String echoStr) throws Exception {
|
|
public String appletMsgCheck(String appId, String signature, String timestamp, String nonce, String echoStr) throws Exception {
|
|
|
log.error("appId : {}, signature : {}, timestamp : {}, nonce : {}, echoStr : {}", appId, signature, timestamp, nonce, echoStr);
|
|
log.error("appId : {}, signature : {}, timestamp : {}, nonce : {}, echoStr : {}", appId, signature, timestamp, nonce, echoStr);
|