|
@@ -3,7 +3,10 @@ package com.zanxiang.game.module.sdk.service.api;
|
|
|
import com.zanxiang.game.module.base.pojo.enums.PayApplicationTypeEnum;
|
|
|
import com.zanxiang.game.module.sdk.constant.RedisKeyConstant;
|
|
|
import com.zanxiang.game.module.sdk.enums.ExpireTimeEnum;
|
|
|
+import com.zanxiang.game.module.sdk.pojo.dto.GameAppletDTO;
|
|
|
+import com.zanxiang.game.module.sdk.service.IGameAppletService;
|
|
|
import com.zanxiang.game.module.sdk.util.RedisUtil;
|
|
|
+import com.zanxiang.game.module.sdk.util.SignUtil;
|
|
|
import com.zanxiang.module.util.JsonUtil;
|
|
|
import com.zanxiang.module.util.URIUtil;
|
|
|
import com.zanxiang.module.util.exception.BaseException;
|
|
@@ -33,6 +36,9 @@ public class WxApiService {
|
|
|
@Autowired
|
|
|
private RedisUtil<String> redisUtil;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IGameAppletService gameAppletService;
|
|
|
+
|
|
|
/**
|
|
|
* 根据应用类型获取openId
|
|
|
*
|
|
@@ -132,4 +138,37 @@ public class WxApiService {
|
|
|
redisUtil.setCache(key, resultMap.get("access_token"), ExpireTimeEnum.ONE_HOUR.getTime());
|
|
|
return resultMap.get("access_token");
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 返回是否过期
|
|
|
+ *
|
|
|
+ * @param gameId : 应用id
|
|
|
+ * @param openId : 用户openId
|
|
|
+ * @return {@link String}
|
|
|
+ */
|
|
|
+ public boolean checkSessionKey(Long gameId, String openId, String sessionKey) {
|
|
|
+ String signature;
|
|
|
+ String accessToken;
|
|
|
+ try {
|
|
|
+ signature = SignUtil.HMACSHA256("", sessionKey);
|
|
|
+ GameAppletDTO gameAppletDTO = gameAppletService.getByGameId(gameId);
|
|
|
+ accessToken = this.getAccessToken(gameAppletDTO.getAppId(), gameAppletDTO.getAppSecret());
|
|
|
+ } catch (Exception e) {
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+ Map<String, String> paramMap = new HashMap<>(4);
|
|
|
+ paramMap.put("access_token", accessToken);
|
|
|
+ paramMap.put("signature", signature);
|
|
|
+ paramMap.put("openid", openId);
|
|
|
+ paramMap.put("sig_method", "hmac_sha256");
|
|
|
+ // 发送请求
|
|
|
+ String url = URIUtil.fillUrlParams("https://api.weixin.qq.com/wxa/checksession", paramMap, Boolean.FALSE);
|
|
|
+ String sr = restTemplate.getForObject(url, String.class);
|
|
|
+ // 解析相应内容(转换成json对象)
|
|
|
+ Map<String, String> resultMap = JsonUtil.toMap(sr, Map.class, String.class);
|
|
|
+ if (resultMap == null || !Objects.equals("0", resultMap.get("errcode"))) {
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+ return Boolean.FALSE;
|
|
|
+ }
|
|
|
}
|