Browse Source

Merge remote-tracking branch 'origin/package' into package

lth 1 year ago
parent
commit
43316c6a5c
17 changed files with 268 additions and 25 deletions
  1. 2 1
      game-data/game-data-serve/src/main/java/com/zanxiang/game/data/serve/pojo/dto/PromotionDayDTO.java
  2. 2 1
      game-data/game-data-serve/src/main/java/com/zanxiang/game/data/serve/pojo/dto/TencentPromotionDayDTO.java
  3. 5 4
      game-data/game-data-serve/src/main/java/com/zanxiang/game/data/serve/service/impl/PromotionDayServiceImpl.java
  4. 6 1
      game-module/game-module-base/src/main/java/com/zanxiang/game/module/base/pojo/enums/ShellControlEnum.java
  5. 1 1
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/ManageApplication.java
  6. 7 0
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/params/GameAuthUpdateParam.java
  7. 1 0
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/GameAuthServiceImpl.java
  8. 5 0
      game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/GameAppletShell.java
  9. 1 1
      game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/SDKApplication.java
  10. 5 2
      game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/controller/LoginController.java
  11. 134 0
      game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/pojo/result/IpCheckResult.java
  12. 4 1
      game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IGameAppletShellService.java
  13. 4 1
      game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IRegisterLoginService.java
  14. 9 0
      game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IUserCardService.java
  15. 47 5
      game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/GameAppletShellServiceImpl.java
  16. 4 3
      game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/LoginServiceImpl.java
  17. 31 4
      game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/UserCardServiceImpl.java

+ 2 - 1
game-data/game-data-serve/src/main/java/com/zanxiang/game/data/serve/pojo/dto/PromotionDayDTO.java

@@ -8,6 +8,7 @@ import lombok.Data;
 import lombok.NoArgsConstructor;
 
 import java.time.LocalDate;
+import java.util.List;
 
 /**
  * @author tianhua
@@ -96,7 +97,7 @@ public class PromotionDayDTO extends BasePage {
      * 渠道ID
      */
     @ApiModelProperty(value = "渠道ID")
-    private Long[] agentId;
+    private List<Long> agentId;
 
     /**
      * cp名称

+ 2 - 1
game-data/game-data-serve/src/main/java/com/zanxiang/game/data/serve/pojo/dto/TencentPromotionDayDTO.java

@@ -8,6 +8,7 @@ import lombok.Data;
 import lombok.NoArgsConstructor;
 
 import java.time.LocalDate;
+import java.util.List;
 
 /**
  * @author tianhua
@@ -96,7 +97,7 @@ public class TencentPromotionDayDTO extends BasePage {
      * 渠道ID
      */
     @ApiModelProperty(value = "渠道ID")
-    private Long[] agentId;
+    private List<Long> agentId;
 
     /**
      * cp名称

+ 5 - 4
game-data/game-data-serve/src/main/java/com/zanxiang/game/data/serve/service/impl/PromotionDayServiceImpl.java

@@ -12,6 +12,7 @@ import com.zanxiang.game.data.serve.pojo.vo.*;
 import com.zanxiang.game.data.serve.service.IAdsPromotionDayService;
 import com.zanxiang.game.data.serve.utils.Page;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.nutz.dao.Cnd;
@@ -787,8 +788,8 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
         if (userIds != null) {
             cri.where().andInList("pitcher_id", userIds);
         }
-        if (ArrayUtils.isNotEmpty(dto.getAgentId())) {
-            cri.where().andInList("agent_id", Arrays.asList(dto.getAgentId()));
+        if (CollectionUtils.isNotEmpty(dto.getAgentId())) {
+            cri.where().andInList("agent_id", dto.getAgentId());
         }
         if (StringUtils.isNotBlank(dto.getCpName())) {
             cri.where().andEquals("cp_name", dto.getCpName());
@@ -860,8 +861,8 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
         if (userIds != null) {
             cri.where().andInList("pitcher_id", userIds);
         }
-        if (ArrayUtils.isNotEmpty(dto.getAgentId())) {
-            cri.where().andInList("agent_id", Arrays.asList(dto.getAgentId()));
+        if (CollectionUtils.isNotEmpty(dto.getAgentId())) {
+            cri.where().andInList("agent_id", dto.getAgentId());
         }
         if (StringUtils.isNotBlank(dto.getCpName())) {
             cri.where().andEquals("cp_name", dto.getCpName());

+ 6 - 1
game-module/game-module-base/src/main/java/com/zanxiang/game/module/base/pojo/enums/ShellControlEnum.java

@@ -30,7 +30,12 @@ public enum ShellControlEnum {
     /**
      * 角色等级控制开启
      */
-    SHELL_CONTROL_LOW_LEVEL_OPEN(3, "角色等级控制开启");
+    SHELL_CONTROL_LOW_LEVEL_OPEN(3, "角色等级控制开启"),
+
+    /**
+     * 省份屏蔽
+     */
+    SHELL_CONTROL_PROV_OPEN(4, "省份屏蔽");
 
     /**
      * 壳包控制类型

+ 1 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/ManageApplication.java

@@ -21,7 +21,7 @@ public class ManageApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(ManageApplication.class, args);
-        System.out.println("赞象Manage服务启动成功 <游戏授权模块修改> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 <游戏授权模块修改1> ( ´・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 7 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/params/GameAuthUpdateParam.java

@@ -33,4 +33,11 @@ public class GameAuthUpdateParam {
     @NotNull(message = "用户id不可为空")
     @ApiModelProperty(notes = "用户id")
     private Long userId;
+
+    /**
+     * 是否包含自然量
+     */
+    @NotNull(message = "用户id不可为空")
+    @ApiModelProperty(notes = "是否包含自然量")
+    private Boolean defaultAgent;
 }

+ 1 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/GameAuthServiceImpl.java

@@ -118,6 +118,7 @@ public class GameAuthServiceImpl extends ServiceImpl<GameAuthMapper, GameAuth> i
         //修改
         return super.update(new LambdaUpdateWrapper<GameAuth>()
                 .set(GameAuth::getGameId, param.getGameId())
+                .set(GameAuth::getDefaultAgent, param.getDefaultAgent())
                 .set(GameAuth::getUpdateBy, SecurityUtil.getUserId())
                 .set(GameAuth::getUpdateTime, LocalDateTime.now())
                 .eq(GameAuth::getId, param.getId()));

+ 5 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/GameAppletShell.java

@@ -99,4 +99,9 @@ public class GameAppletShell implements Serializable {
      */
     private String testVersion;
 
+    /**
+     * 省份屏蔽
+     */
+    private String provShield;
+
 }

+ 1 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/SDKApplication.java

@@ -23,7 +23,7 @@ public class SDKApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(SDKApplication.class, args);
-        System.out.println("赞象SDK服务启动成功 <壳包控制兼容多版本测试> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象SDK服务启动成功 <壳包屏蔽省份22> ( ´・・)ノ(._.`) \n" +
                 " ___________ _   __\n" +
                 "/  ___|  _  \\ | / /\n" +
                 "\\ `--.| | | | |/ / \n" +

+ 5 - 2
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/controller/LoginController.java

@@ -18,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
+
 /**
  * @author : lingfeng
  * @time : 2022-06-21
@@ -37,8 +39,9 @@ public class LoginController {
     @ApiOperation(value = "微信小游戏code授权登录")
     @PostMapping("/wx/code")
     @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = UserLoginVO.class)})
-    public ResultVO<UserLoginVO> loginWxCode(@Validated @RequestBody LoginVxCodeParam param, UserData userData) {
-        return registerLoginService.loginWxCode(param, userData);
+    public ResultVO<UserLoginVO> loginWxCode(@Validated @RequestBody LoginVxCodeParam param, UserData userData,
+                                             HttpServletRequest request) {
+        return registerLoginService.loginWxCode(param, userData, request);
     }
 
     @UnSignCheck

+ 134 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/pojo/result/IpCheckResult.java

@@ -0,0 +1,134 @@
+package com.zanxiang.game.module.sdk.pojo.result;
+
+import lombok.Data;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-10-13
+ * @description : ip检测
+ */
+@Data
+public class IpCheckResult {
+
+    /**
+     * 消息
+     */
+    private String msg;
+
+    /**
+     * 是否成功
+     */
+    private boolean success;
+
+    /**
+     * 错误码
+     */
+    private Integer code;
+
+    /**
+     * 数据
+     */
+    private DataBean data;
+
+    @Data
+    public static class DataBean {
+
+        /**
+         * 订单号
+         */
+        private String orderNo;
+
+        /**
+         * 结果
+         */
+        private IpCheckResult.ResultBean result;
+    }
+
+    @Data
+    public static class ResultBean {
+
+        /**
+         * 大洲
+         */
+        private String continent;
+
+        /**
+         * 所属机构
+         */
+        private String owner;
+
+        /**
+         * 国家
+         */
+        private String country;
+
+        /**
+         * 经度
+         */
+        private String lng;
+
+        /**
+         * 行政编码
+         */
+        private String adcode;
+
+        /**
+         * 城市
+         */
+        private String city;
+
+        /**
+         * 时区
+         */
+        private String timezone;
+
+        /**
+         * 运营商
+         */
+        private String isp;
+
+        /**
+         * 精度
+         */
+        private String accuracy;
+
+        /**
+         * 采集方式
+         */
+        private String source;
+
+        /**
+         * 自治域编码
+         */
+        private String asnumber;
+
+        /**
+         * 国家编码
+         */
+        private String areacode;
+
+        /**
+         * 邮编
+         */
+        private String zipcode;
+
+        /**
+         * 定位半径
+         */
+        private String radius;
+
+        /**
+         * 省份
+         */
+        private String prov;
+
+        /**
+         * 纬度
+         */
+        private String lat;
+    }
+
+    public Boolean isFail() {
+        return this.code != 200;
+    }
+}

+ 4 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IGameAppletShellService.java

@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.zanxiang.game.module.mybatis.entity.GameAppletShell;
 import com.zanxiang.game.module.mybatis.entity.User;
 
+import javax.servlet.http.HttpServletRequest;
+
 /**
  * @author : lingfeng
  * @time : 2023-07-06
@@ -25,7 +27,8 @@ public interface IGameAppletShellService extends IService<GameAppletShell> {
      *
      * @param user     用户
      * @param register 注册
+     * @param request  网络请求
      * @return {@link Integer}
      */
-    Integer getUserShellSwitch(User user, boolean register);
+    Integer getUserShellSwitch(User user, boolean register, HttpServletRequest request);
 }

+ 4 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IRegisterLoginService.java

@@ -8,6 +8,8 @@ import com.zanxiang.game.module.sdk.pojo.param.UserData;
 import com.zanxiang.game.module.sdk.pojo.vo.UserLoginVO;
 import com.zanxiang.module.util.pojo.ResultVO;
 
+import javax.servlet.http.HttpServletRequest;
+
 /**
  * @author : lingfeng
  * @time : 2022-06-22
@@ -20,9 +22,10 @@ public interface IRegisterLoginService {
      *
      * @param param    : 授权参数
      * @param userData : 用户信息
+     * @param request  : 网络请求
      * @return {@link ResultVO}<{@link UserLoginVO}>
      */
-    ResultVO<UserLoginVO> loginWxCode(LoginVxCodeParam param, UserData userData);
+    ResultVO<UserLoginVO> loginWxCode(LoginVxCodeParam param, UserData userData, HttpServletRequest request);
 
     /**
      * 登录密码

+ 9 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IUserCardService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.zanxiang.game.module.mybatis.entity.UserCard;
 import com.zanxiang.game.module.sdk.pojo.param.UserCardUpdateParam;
 import com.zanxiang.game.module.sdk.pojo.param.UserData;
+import com.zanxiang.game.module.sdk.pojo.result.IpCheckResult;
 import com.zanxiang.module.util.pojo.ResultVO;
 
 /**
@@ -21,4 +22,12 @@ public interface IUserCardService extends IService<UserCard> {
      * @return {@link ResultVO}<{@link Boolean}>
      */
     ResultVO<Boolean> userAuthentication(UserCardUpdateParam param, UserData userData);
+
+    /**
+     * ip监测
+     *
+     * @param ip : 网络地址
+     * @return {@link IpCheckResult}
+     */
+    IpCheckResult userIpCheck(String ip);
 }

+ 47 - 5
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/GameAppletShellServiceImpl.java

@@ -10,16 +10,20 @@ import com.zanxiang.game.module.mybatis.entity.GameUserRole;
 import com.zanxiang.game.module.mybatis.entity.User;
 import com.zanxiang.game.module.mybatis.mapper.GameAppletShellMapper;
 import com.zanxiang.game.module.sdk.enums.ShellSwitchEnum;
+import com.zanxiang.game.module.sdk.pojo.result.IpCheckResult;
 import com.zanxiang.game.module.sdk.service.IGameAppletShellService;
 import com.zanxiang.game.module.sdk.service.IGameExtService;
 import com.zanxiang.game.module.sdk.service.IGameUserRoleService;
+import com.zanxiang.game.module.sdk.service.IUserCardService;
 import com.zanxiang.module.util.JsonUtil;
 import com.zanxiang.module.util.exception.BaseException;
+import com.zanxiang.module.web.util.IpUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.logging.log4j.util.Strings;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.servlet.http.HttpServletRequest;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Objects;
@@ -39,6 +43,9 @@ public class GameAppletShellServiceImpl extends ServiceImpl<GameAppletShellMappe
     @Autowired
     private IGameUserRoleService gameUserRoleService;
 
+    @Autowired
+    private IUserCardService userCardService;
+
     @Override
     public Integer getShellSwitch(String appId, String version) {
         log.error("壳包接口收到请求, appId : {}, version : {}", appId, version);
@@ -82,7 +89,7 @@ public class GameAppletShellServiceImpl extends ServiceImpl<GameAppletShellMappe
     }
 
     @Override
-    public Integer getUserShellSwitch(User user, boolean register) {
+    public Integer getUserShellSwitch(User user, boolean register, HttpServletRequest request) {
         GameAppletShell gameAppletShell = super.getOne(new LambdaQueryWrapper<GameAppletShell>()
                 .eq(GameAppletShell::getGameId, user.getGameId()));
         //未设置, 统一返回关闭
@@ -103,12 +110,14 @@ public class GameAppletShellServiceImpl extends ServiceImpl<GameAppletShellMappe
         if (Objects.equals(proControlType, ShellControlEnum.SHELL_CONTROL_NEW_USER_OPEN.getShellControl())) {
             return register ? ShellSwitchEnum.SHELL_SWITCH_OPEN.getShellSwitch() : ShellSwitchEnum.SHELL_SWITCH_CLOSE.getShellSwitch();
         }
+
+        //查询用户角色列表
+        List<GameUserRole> gameUserRoleList = gameUserRoleService.list(new LambdaQueryWrapper<GameUserRole>()
+                .eq(GameUserRole::getUserId, user.getId())
+                .eq(GameUserRole::getGameId, user.getGameId()));
+
         //等级控制开启
         if (Objects.equals(proControlType, ShellControlEnum.SHELL_CONTROL_LOW_LEVEL_OPEN.getShellControl())) {
-            //查询用户角色等级
-            List<GameUserRole> gameUserRoleList = gameUserRoleService.list(new LambdaQueryWrapper<GameUserRole>()
-                    .eq(GameUserRole::getUserId, user.getId())
-                    .eq(GameUserRole::getGameId, user.getGameId()));
             //不存在角色的新用户, 开启
             if (CollectionUtils.isEmpty(gameUserRoleList)) {
                 return ShellSwitchEnum.SHELL_SWITCH_OPEN.getShellSwitch();
@@ -121,6 +130,39 @@ public class GameAppletShellServiceImpl extends ServiceImpl<GameAppletShellMappe
             }
             return ShellSwitchEnum.SHELL_SWITCH_CLOSE.getShellSwitch();
         }
+
+        //省份屏蔽
+        if (Objects.equals(proControlType, ShellControlEnum.SHELL_CONTROL_PROV_OPEN.getShellControl())) {
+            if (Strings.isBlank(gameAppletShell.getProvShield())) {
+                return ShellSwitchEnum.SHELL_SWITCH_CLOSE.getShellSwitch();
+            }
+            String prov = null;
+            try {
+                IpCheckResult result = userCardService.userIpCheck(IpUtil.getRealIp(request));
+                prov = result.getData().getResult().getProv();
+            } catch (Exception ignored) {
+            }
+            //未查询到归属地, 或者不包含屏蔽省份, 关闭壳包
+            if (prov == null || !prov.contains(gameAppletShell.getProvShield())) {
+                return ShellSwitchEnum.SHELL_SWITCH_CLOSE.getShellSwitch();
+            }
+            //未设置更多的等级限制, 直接进壳
+            if (gameAppletShell.getProControlLevel() == null) {
+                return ShellSwitchEnum.SHELL_SWITCH_OPEN.getShellSwitch();
+            }
+            //不存在角色的新用户, 开启
+            if (CollectionUtils.isEmpty(gameUserRoleList)) {
+                return ShellSwitchEnum.SHELL_SWITCH_OPEN.getShellSwitch();
+            }
+            //获取用户等级最高的角色
+            GameUserRole gameUserRole = gameUserRoleList.stream().max(Comparator.comparing(GameUserRole::getRoleLevel)).orElse(null);
+            //角色不存在, 或者等级小于等于控制等级
+            if (gameUserRole == null || gameUserRole.getRoleLevel() <= gameAppletShell.getProControlLevel()) {
+                return ShellSwitchEnum.SHELL_SWITCH_OPEN.getShellSwitch();
+            }
+            return ShellSwitchEnum.SHELL_SWITCH_CLOSE.getShellSwitch();
+        }
+
         log.error("壳包控制配置不存在, 默认进壳包, userId : {}, gameAppletShell : {}", user.getId(), JsonUtil.toString(gameAppletShell));
         return ShellSwitchEnum.SHELL_SWITCH_OPEN.getShellSwitch();
     }

+ 4 - 3
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/LoginServiceImpl.java

@@ -31,6 +31,7 @@ import reactor.util.function.Tuple2;
 import reactor.util.function.Tuple3;
 import reactor.util.function.Tuples;
 
+import javax.servlet.http.HttpServletRequest;
 import java.time.LocalDateTime;
 import java.util.Map;
 import java.util.Objects;
@@ -104,7 +105,7 @@ public class LoginServiceImpl implements IRegisterLoginService {
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public ResultVO<UserLoginVO> loginWxCode(LoginVxCodeParam param, UserData userData) {
+    public ResultVO<UserLoginVO> loginWxCode(LoginVxCodeParam param, UserData userData, HttpServletRequest request) {
         //验证登录ip是否封禁
         if (ipBanService.checkIpBan(userData)) {
             return ResultVO.fail(HttpStatusEnum.IP_HALT.getMsg());
@@ -134,7 +135,7 @@ public class LoginServiceImpl implements IRegisterLoginService {
             agentService.userAgentUpdate(user, userData.getChannel());
             //返回登录信息
             UserLoginVO userLoginVO = this.createUserLoginVO(user, userData);
-            userLoginVO.setAppletShellSwitch(gameAppletShellService.getUserShellSwitch(user, Boolean.FALSE));
+            userLoginVO.setAppletShellSwitch(gameAppletShellService.getUserShellSwitch(user, Boolean.FALSE, request));
             log.error("返回用户登录信息, userLoginVO : {}", JsonUtil.toString(userLoginVO));
             return ResultVO.ok(userLoginVO);
         }
@@ -142,7 +143,7 @@ public class LoginServiceImpl implements IRegisterLoginService {
         user = userCreateSave(userData, openId, null, null, openId, sessionKey);
         //返回登录信息
         UserLoginVO userLoginVO = this.createUserLoginVO(user, userData);
-        userLoginVO.setAppletShellSwitch(gameAppletShellService.getUserShellSwitch(user, Boolean.TRUE));
+        userLoginVO.setAppletShellSwitch(gameAppletShellService.getUserShellSwitch(user, Boolean.TRUE, request));
         log.error("返回用户登录信息, userLoginVO : {}", JsonUtil.toString(userLoginVO));
         return ResultVO.ok(userLoginVO);
     }

+ 31 - 4
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/UserCardServiceImpl.java

@@ -11,6 +11,7 @@ import com.zanxiang.game.module.sdk.constant.RegexConstant;
 import com.zanxiang.game.module.sdk.pojo.param.UserCardUpdateParam;
 import com.zanxiang.game.module.sdk.pojo.param.UserData;
 import com.zanxiang.game.module.sdk.pojo.result.CardCheckResult;
+import com.zanxiang.game.module.sdk.pojo.result.IpCheckResult;
 import com.zanxiang.game.module.sdk.service.IUserCardService;
 import com.zanxiang.game.module.sdk.service.IUserService;
 import com.zanxiang.module.util.JsonUtil;
@@ -20,15 +21,13 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.logging.log4j.util.Strings;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.ResponseEntity;
+import org.springframework.http.*;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
 import org.springframework.web.client.RestTemplate;
+import org.springframework.web.util.UriComponentsBuilder;
 import reactor.util.function.Tuple2;
 import reactor.util.function.Tuples;
 
@@ -227,4 +226,32 @@ public class UserCardServiceImpl extends ServiceImpl<UserCardMapper, UserCard> i
         log.error("实名认证结果, result : {}", JsonUtil.toString(result));
         return Tuples.of(result.past(), result.getAddress());
     }
+
+    @Override
+    public IpCheckResult userIpCheck(String ip) {
+        String url = "https://ipcity.market.alicloudapi.com/ip/city/query";
+        String appCode = "f395b1587fc04a49a975f908660fb1e9";
+        //构造请求参数
+        UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(url).queryParam("ip", ip);
+        //请求头
+        HttpHeaders headers = new HttpHeaders();
+        headers.set("Authorization", "APPCODE " + appCode);
+        RequestEntity<Object> requestEntity = new RequestEntity<>(headers, HttpMethod.GET, uriBuilder.build().toUri());
+        //请求
+        IpCheckResult result;
+        try {
+            ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
+            String body = responseEntity.getBody();
+            result = JsonUtil.toObj(body, IpCheckResult.class);
+        } catch (Exception e) {
+            log.error("请求阿里ip检测接口异常, ip : {}, e : {}", ip, e.getMessage());
+            throw new BaseException("请求阿里ip监测接口异常");
+        }
+        if (result == null || result.isFail()) {
+            log.error("请求阿里ip检测接口返回值为空, ip : {}, result : {}", ip, JsonUtil.toString(result));
+            throw new BaseException("请求阿里ip检测接口返回值为空");
+        }
+        log.error("ip检测结果, result : {}", JsonUtil.toString(result));
+        return result;
+    }
 }