|
|
@@ -19,16 +19,14 @@ import com.ytpm.app.param.AppConfigUpdateParam;
|
|
|
import com.ytpm.app.param.DyzAdRecordParam;
|
|
|
import com.ytpm.app.param.IosLoginParam;
|
|
|
import com.ytpm.app.param.WxLoginParam;
|
|
|
-import com.ytpm.app.view.IosPowerResView;
|
|
|
-import com.ytpm.app.view.IosUserInfo;
|
|
|
-import com.ytpm.app.view.WxDefaultConfig;
|
|
|
-import com.ytpm.app.view.WxLoginResult;
|
|
|
-import com.ytpm.app.view.WxUserInfo;
|
|
|
+import com.ytpm.app.view.*;
|
|
|
import com.ytpm.feign.RiskFeign;
|
|
|
import com.ytpm.general.RepMessage;
|
|
|
import com.ytpm.general.Result;
|
|
|
import com.ytpm.general.StatusCode;
|
|
|
+import com.ytpm.handle.CustomerException;
|
|
|
import com.ytpm.lemonios.dao.AdRecordMapper;
|
|
|
+import com.ytpm.lemonios.dao.AppDefaultConfigMapper;
|
|
|
import com.ytpm.lemonios.dao.AppUserMapper;
|
|
|
import com.ytpm.lemonios.dao.DitchMapper;
|
|
|
import com.ytpm.lemonios.redis.RedisService;
|
|
|
@@ -41,12 +39,7 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
@@ -67,6 +60,8 @@ import java.util.stream.Collectors;
|
|
|
@RequestMapping("/wx")
|
|
|
public class WxController {
|
|
|
|
|
|
+ @Resource
|
|
|
+ private AppDefaultConfigMapper appDefaultConfigMapper;
|
|
|
@Resource
|
|
|
private AppUserMapper appUserMapper;
|
|
|
@Resource
|
|
|
@@ -100,7 +95,7 @@ public class WxController {
|
|
|
@Transactional
|
|
|
public Result<YtDyzUser> wxLogin(@RequestBody WxLoginParam param, HttpServletRequest request) {
|
|
|
//根据应用获取配置调用微信接口登录
|
|
|
- WxDefaultConfig defaultConfig = appUserMapper.getDefaultConfig(param.getAppType());
|
|
|
+ WxDefaultConfig defaultConfig = appDefaultConfigMapper.getByAppType(param.getAppType());
|
|
|
if (Objects.isNull(defaultConfig)) {
|
|
|
return new Result<>(StatusCode.ACCESS_ERR, "微信登录失败,未找到相应配置!");
|
|
|
}
|
|
|
@@ -198,7 +193,7 @@ public class WxController {
|
|
|
if (result.getCode() != 200) {
|
|
|
String errorMessage = result.getMessage();
|
|
|
if (user.getLoginType() == LoginType.VISITOR && RepMessage.RISK_VISITOR_LOWER_VALUE.equals(errorMessage)) {
|
|
|
- WxDefaultConfig defaultConfig = appUserMapper.getLastDefaultConfig();
|
|
|
+ WxDefaultConfig defaultConfig = appDefaultConfigMapper.getLast();
|
|
|
return Result.resultErr(StrUtil.emptyToDefault(defaultConfig.getLowValueTip(), errorMessage));
|
|
|
}
|
|
|
return Result.resultErr(errorMessage);
|
|
|
@@ -243,33 +238,64 @@ public class WxController {
|
|
|
@PostMapping("/iosLogin")
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Result<YtDyzUser> iosLogin(@RequestBody IosLoginParam param, HttpServletRequest request) {
|
|
|
- //根据应用ID获取配置调用接口登录
|
|
|
- WxDefaultConfig defaultConfig = appUserMapper.getDefaultConfigByDitchId(param.getDitchId());
|
|
|
- // 当默认配置不存在时,尝试通过渠道信息获取备用配置
|
|
|
- if (Objects.isNull(defaultConfig)) {
|
|
|
- // 1. 检查渠道是否存在(提前拦截无效情况)
|
|
|
- YtDitch ditch = ditchMapper.selectById(param.getDitchId());
|
|
|
- if (ditch != null) {
|
|
|
- // 2. 通过渠道的appId获取备用配置
|
|
|
- defaultConfig = appUserMapper.getByAppId(ditch.getAppId());
|
|
|
+ try {
|
|
|
+ // 1.根据应用ID获取配置调用接口登录,当默认配置不存在时,尝试通过渠道的appId获取备用配置
|
|
|
+ WxDefaultConfig defaultConfig = appDefaultConfigMapper.getByDitchId(param.getDitchId());
|
|
|
+ if (defaultConfig == null) {
|
|
|
+ // 检查渠道是否存在(提前拦截无效情况)
|
|
|
+ YtDitch ditch = ditchMapper.selectById(param.getDitchId());
|
|
|
+ defaultConfig = ditch == null ? null : appDefaultConfigMapper.getByAppId(ditch.getAppId());
|
|
|
}
|
|
|
- }
|
|
|
- if (Objects.isNull(defaultConfig)) {
|
|
|
- return new Result<>(StatusCode.ACCESS_ERR, "登录失败,未找到相应配置!");
|
|
|
- }
|
|
|
- // 幂等请求校验
|
|
|
- if (StrUtil.isNotEmpty(param.getRequestId())) {
|
|
|
- String redisKey = StrUtil.format("visitor:requestId:{}:{}", param.getDitchId(), param.getIosId());
|
|
|
- if (!redisService.hasKey(redisKey)) {
|
|
|
- return new Result<>(StatusCode.ACCESS_ERR, "登录失败,重复请求!");
|
|
|
+ if (Objects.isNull(defaultConfig)) {
|
|
|
+ throw new CustomerException("登录失败,未找到相应配置!");
|
|
|
+ }
|
|
|
+ // (可选)幂等请求校验
|
|
|
+ if (StrUtil.isNotEmpty(param.getRequestId())) {
|
|
|
+ String redisKey = StrUtil.format("visitor:requestId:{}:{}", param.getDitchId(), param.getIosId());
|
|
|
+ if (!redisService.hasKey(redisKey)) {
|
|
|
+ throw new CustomerException("登录失败,重复请求!");
|
|
|
+ }
|
|
|
+ String cacheKey = redisService.getStr(redisKey);
|
|
|
+ if (!StrUtil.equals(cacheKey, param.getRequestId())) {
|
|
|
+ throw new CustomerException("登录失败,重复请求!");
|
|
|
+ }
|
|
|
+ redisService.del(redisKey);
|
|
|
}
|
|
|
- String cacheKey = redisService.getStr(redisKey);
|
|
|
- if (!StrUtil.equals(cacheKey, param.getRequestId())) {
|
|
|
- return new Result<>(StatusCode.ACCESS_ERR, "登录失败,重复请求!");
|
|
|
+ // 2.处理phoneJson, loginIp, nickName等
|
|
|
+ param.setLoginIp(getClientIp(request));
|
|
|
+ handlePhoneJson(param);
|
|
|
+ IosUserInfo userInfo = setIosUserInfo(param);
|
|
|
+ // 是否进行风控校验
|
|
|
+ boolean enableRiskCheck = defaultConfig.getEnableLoginRiskCheck() != null && defaultConfig.getEnableLoginRiskCheck() == 1;
|
|
|
+ // 3.根据入参获取或注册用户
|
|
|
+ YtDyzUser dyzUser = appUserService.crudForNewTransIos(param, userInfo, LoginType.IOS);
|
|
|
+ // 4.处理登陆前广告记录数据 如果传入游客广告记录,执行游客登陆校验
|
|
|
+ handlePreAdList(dyzUser, param, defaultConfig, enableRiskCheck);
|
|
|
+ // 5.状态更新 游客登陆前风控 -> 正常
|
|
|
+ YtDyzUser newUser = new YtDyzUser();
|
|
|
+ newUser.setUserId(dyzUser.getUserId());
|
|
|
+ dyzUser.setUserStatus(UserStatusEnum.NORMAL.getCode());
|
|
|
+ newUser.setUserStatus(UserStatusEnum.NORMAL.getCode());
|
|
|
+ appUserMapper.updateUser(newUser);
|
|
|
+ // 6.进行默认登陆风控校验
|
|
|
+ if (enableRiskCheck) {
|
|
|
+ dyzUser.setPhoneJson(param.getPhoneJson());
|
|
|
+ loginRiskCheck(dyzUser, defaultConfig);
|
|
|
+ }
|
|
|
+ // 7.更新登录时间
|
|
|
+ if (dyzUser.getLastLoginTime() != null && dyzUser.getRegistryTime() != null) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ dyzUser.setLastLoginTimeStr(sdf.format(dyzUser.getLastLoginTime()));
|
|
|
+ dyzUser.setRegistryTimeStr(sdf.format(dyzUser.getRegistryTime()));
|
|
|
}
|
|
|
- redisService.del(redisKey);
|
|
|
+ //调用风控服务校验默认风控配置
|
|
|
+ return Result.resultOk(RepMessage.LOGIN_SUCCESS, dyzUser);
|
|
|
+ } catch (CustomerException e) {
|
|
|
+ return new Result<>(StatusCode.ACCESS_ERR, e.getMessage());
|
|
|
}
|
|
|
- // phoneJson 处理
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handlePhoneJson(IosLoginParam param) {
|
|
|
if (StrUtil.isNotEmpty(param.getPhoneJson())) {
|
|
|
JSONObject jsonObject = JSONObject.parseObject(param.getPhoneJson());
|
|
|
List<String> appList = null;
|
|
|
@@ -285,32 +311,35 @@ public class WxController {
|
|
|
param.setPhoneJson(JSONObject.toJSONString(jsonObject));
|
|
|
}
|
|
|
}
|
|
|
- IosUserInfo userInfo = setIosUserInfo(param);
|
|
|
- param.setLoginIp(getClientIp(request));
|
|
|
- // 获取或注册用户
|
|
|
- YtDyzUser dyzUser = appUserService.crudForNewTransIos(param, userInfo, LoginType.IOS);
|
|
|
- // 如果传入游客广告记录,执行游客登陆校验
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 登陆前广告数据处理
|
|
|
+ */
|
|
|
+ private void handlePreAdList(YtDyzUser dyzUser, IosLoginParam param, WxDefaultConfig defaultConfig,
|
|
|
+ boolean enableRiskCheck) {
|
|
|
if (CollUtil.isNotEmpty(param.getPreAdList())) {
|
|
|
dyzUser.setLoginType(LoginType.VISITOR);
|
|
|
List<YtDyzAdRecord> preAdRecordList = saveVisitorAdRecord(dyzUser, param);
|
|
|
dyzUser.setPreAdRecordList(preAdRecordList);
|
|
|
- Result<?> result = riskFeign.checkLoginRisk(dyzUser);
|
|
|
- if (result.getCode() != 200) {
|
|
|
- String errorMessage = result.getMessage();
|
|
|
- if (RepMessage.RISK_VISITOR_LOWER_VALUE.equals(errorMessage)) {
|
|
|
- errorMessage = StrUtil.emptyToDefault(defaultConfig.getLowValueTip(), errorMessage);
|
|
|
+ if (enableRiskCheck) {
|
|
|
+ Result<?> result = riskFeign.checkLoginRisk(dyzUser);
|
|
|
+ if (result.getCode() != 200) {
|
|
|
+ String errorMessage = result.getMessage();
|
|
|
+ if (RepMessage.RISK_VISITOR_LOWER_VALUE.equals(errorMessage)) {
|
|
|
+ errorMessage = StrUtil.emptyToDefault(defaultConfig.getLowValueTip(), errorMessage);
|
|
|
+ }
|
|
|
+ throw new CustomerException(errorMessage);
|
|
|
}
|
|
|
- return new Result<>(StatusCode.ACCESS_ERR, errorMessage);
|
|
|
}
|
|
|
}
|
|
|
- // 状态更新 游客登陆前风控 -> 正常
|
|
|
- YtDyzUser newUser = new YtDyzUser();
|
|
|
- newUser.setUserId(dyzUser.getUserId());
|
|
|
- dyzUser.setUserStatus(UserStatusEnum.NORMAL.getCode());
|
|
|
- newUser.setUserStatus(UserStatusEnum.NORMAL.getCode());
|
|
|
- appUserMapper.updateUser(newUser);
|
|
|
- //调用风控服务校验默认风控配置
|
|
|
- dyzUser.setPhoneJson(param.getPhoneJson());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 登陆风控校验
|
|
|
+ */
|
|
|
+ private void loginRiskCheck(YtDyzUser dyzUser, WxDefaultConfig defaultConfig) throws CustomerException {
|
|
|
dyzUser.setLoginType(LoginType.IOS);
|
|
|
dyzUser.setRiskCode("313");
|
|
|
Result<?> result = riskFeign.checkRisk(dyzUser);
|
|
|
@@ -325,17 +354,13 @@ public class WxController {
|
|
|
String[] split = ipLimitTips.split(",");
|
|
|
errorMessage = split[RandomUtil.randomInt(split.length)];
|
|
|
}
|
|
|
- return new Result<>(StatusCode.ACCESS_ERR, errorMessage);
|
|
|
+ throw new CustomerException(errorMessage);
|
|
|
}
|
|
|
- if (dyzUser.getLastLoginTime() != null && dyzUser.getRegistryTime() != null) {
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- dyzUser.setLastLoginTimeStr(sdf.format(dyzUser.getLastLoginTime()));
|
|
|
- dyzUser.setRegistryTimeStr(sdf.format(dyzUser.getRegistryTime()));
|
|
|
- }
|
|
|
- //调用风控服务校验默认风控配置
|
|
|
- return Result.resultOk(RepMessage.LOGIN_SUCCESS, dyzUser);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存登陆前游客广告
|
|
|
+ */
|
|
|
private List<YtDyzAdRecord> saveVisitorAdRecord(YtDyzUser ytDyzUser, IosLoginParam visitorLoginParam) {
|
|
|
List<DyzAdRecordParam> preAdList = visitorLoginParam.getPreAdList();
|
|
|
// 保存登陆前传递的广告记录
|
|
|
@@ -360,16 +385,17 @@ public class WxController {
|
|
|
log.info(StrUtil.format("[visitor adRecords]userId:{} recordCount:{} revenue:{}",
|
|
|
ytDyzUser.getUserId(), adRecordIds.size(), totalRevenue.toPlainString()));
|
|
|
}
|
|
|
- return CollUtil.isEmpty(adRecordIds) ? new ArrayList<>()
|
|
|
- : recordMapper.selectRecordByIds(AdRecordEnum.LOGIN_BEFORE.getCode(), adRecordIds);
|
|
|
+ return CollUtil.isEmpty(adRecordIds) ?
|
|
|
+ new ArrayList<>() : recordMapper.selectRecordByIds(AdRecordEnum.LOGIN_BEFORE.getCode(), adRecordIds);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@ApiEncrypt(response = true)
|
|
|
@PostMapping("/getByDitchId")
|
|
|
@ApiOperation("获取默认配置")
|
|
|
@Transactional
|
|
|
public Result<WxDefaultConfig> getByDitchId(@RequestBody IosLoginParam param) {
|
|
|
- WxDefaultConfig defaultConfig = appUserMapper.getDefaultConfigByDitchId(param.getDitchId());
|
|
|
+ WxDefaultConfig defaultConfig = appDefaultConfigMapper.getByDitchId(param.getDitchId());
|
|
|
return Result.resultOk(RepMessage.QUERY_SUCCESS, defaultConfig);
|
|
|
}
|
|
|
|
|
|
@@ -395,7 +421,7 @@ public class WxController {
|
|
|
@ApiOperation("获取微信默认配置项")
|
|
|
@GetMapping("/defaultConfig")
|
|
|
public Result<WxDefaultConfig> getWxDefaultConfig(int appType) {
|
|
|
- WxDefaultConfig config = appUserMapper.getDefaultConfig(appType);
|
|
|
+ WxDefaultConfig config = appDefaultConfigMapper.getByAppType(appType);
|
|
|
if (Objects.isNull(config)) {
|
|
|
return Result.resultErr("应用类型有误!");
|
|
|
}
|
|
|
@@ -425,7 +451,7 @@ public class WxController {
|
|
|
@ApiOperation("保存应用默认配置")
|
|
|
@PostMapping("/saveAppConfig")
|
|
|
public Result<String> saveAppConfig(@RequestBody YtAppDefaultConfig defaultConfig) {
|
|
|
- appUserMapper.saveAppConfig(defaultConfig);
|
|
|
+ appDefaultConfigMapper.saveAppConfig(defaultConfig);
|
|
|
return Result.resultOk(RepMessage.SAVE_SUCCESS);
|
|
|
}
|
|
|
|
|
|
@@ -433,7 +459,7 @@ public class WxController {
|
|
|
@ApiOperation("修改应用默认配置")
|
|
|
@PostMapping("/updateAppConfig")
|
|
|
public Result<String> updateAppConfig(@RequestBody YtAppDefaultConfig defaultConfig) {
|
|
|
- appUserMapper.updateAppConfig(defaultConfig);
|
|
|
+ appDefaultConfigMapper.updateAppConfig(defaultConfig);
|
|
|
return Result.resultOk(RepMessage.SAVE_SUCCESS);
|
|
|
}
|
|
|
|
|
|
@@ -443,7 +469,7 @@ public class WxController {
|
|
|
public void updateAppsConfig(@RequestBody AppConfigUpdateParam param) {
|
|
|
if (CollUtil.isNotEmpty(param.getApps()) && param.getDefaultConfig() != null) {
|
|
|
String appIds = String.join(",", param.getApps());
|
|
|
- List<WxDefaultConfig> configs = appUserMapper.getConfigByIds(appIds);
|
|
|
+ List<WxDefaultConfig> configs = appDefaultConfigMapper.getByAppIds(appIds);
|
|
|
YtAppDefaultConfig updateInfo = param.getDefaultConfig();
|
|
|
for (WxDefaultConfig config : configs) {
|
|
|
YtAppDefaultConfig appConfig = new YtAppDefaultConfig();
|
|
|
@@ -466,7 +492,7 @@ public class WxController {
|
|
|
if (StrUtil.isNotEmpty(updateInfo.getTakuInterstitialPid())) {
|
|
|
appConfig.setTakuInterstitialPid(updateInfo.getTakuInterstitialPid());
|
|
|
}
|
|
|
- appUserMapper.updateAppConfig(appConfig);
|
|
|
+ appDefaultConfigMapper.updateAppConfig(appConfig);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -476,7 +502,7 @@ public class WxController {
|
|
|
@GetMapping("/getConfigs")
|
|
|
public List<WxDefaultConfig> getConfigs(@RequestParam(name = "appIds") String appIds) {
|
|
|
List<WxDefaultConfig> configs = new ArrayList<>();
|
|
|
- List<WxDefaultConfig> dyzConfigs = appUserMapper.getConfigByIds(appIds);
|
|
|
+ List<WxDefaultConfig> dyzConfigs = appDefaultConfigMapper.getByAppIds(appIds);
|
|
|
if (CollUtil.isNotEmpty(dyzConfigs)) {
|
|
|
configs.addAll(dyzConfigs);
|
|
|
}
|
|
|
@@ -487,9 +513,9 @@ public class WxController {
|
|
|
@ApiOperation("删除默认配置")
|
|
|
@GetMapping("/delDefaultConfig")
|
|
|
public void delDefaultConfig(@RequestParam(name = "appId") String appId) {
|
|
|
- List<WxDefaultConfig> dyzConfig = appUserMapper.getConfigByIds(appId);
|
|
|
+ List<WxDefaultConfig> dyzConfig = appDefaultConfigMapper.getByAppIds(appId);
|
|
|
if (CollUtil.isNotEmpty(dyzConfig)) {
|
|
|
- appUserMapper.delByAppId(appId);
|
|
|
+ appDefaultConfigMapper.delByAppId(appId);
|
|
|
// 同步删除渠道记录
|
|
|
ditchMapper.deleteByAppId(appId);
|
|
|
}
|