From 16b704d18a875d1fb63827aaa507790ba2bef5be Mon Sep 17 00:00:00 2001
From: 44323 <443237572@qq.com>
Date: 星期二, 23 四月 2024 11:44:13 +0800
Subject: [PATCH] JK最终代码提交
---
guns-admin/src/main/java/com/stylefeng/guns/modular/api/AppUserController.java | 1063 ++++++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 757 insertions(+), 306 deletions(-)
diff --git a/guns-admin/src/main/java/com/stylefeng/guns/modular/api/AppUserController.java b/guns-admin/src/main/java/com/stylefeng/guns/modular/api/AppUserController.java
index dbb4648..30c8baa 100644
--- a/guns-admin/src/main/java/com/stylefeng/guns/modular/api/AppUserController.java
+++ b/guns-admin/src/main/java/com/stylefeng/guns/modular/api/AppUserController.java
@@ -1,376 +1,827 @@
package com.stylefeng.guns.modular.api;
-import com.alibaba.druid.sql.visitor.functions.If;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.huaweicloud.sdk.core.exception.SdkErrorMessage;
+import com.stylefeng.guns.core.util.JwtTokenUtil;
+import com.stylefeng.guns.core.util.MD5Util;
+import com.stylefeng.guns.core.util.ToolUtil;
+import com.stylefeng.guns.modular.system.dto.AddAppUserVo;
+import com.stylefeng.guns.modular.system.dto.LoginWeChatDTO;
import com.stylefeng.guns.modular.system.model.*;
+import com.stylefeng.guns.modular.system.model.Page;
import com.stylefeng.guns.modular.system.service.*;
-import com.stylefeng.guns.modular.system.service.impl.FeedBackServiceImpl;
-import com.stylefeng.guns.modular.system.service.impl.HouseTypeServiceImpl;
-import com.stylefeng.guns.modular.system.util.HttpUtils;
-import com.stylefeng.guns.modular.system.util.Page;
-import com.stylefeng.guns.modular.system.util.ResultUtil;
-import com.stylefeng.guns.modular.system.warpper.req.*;
-import com.stylefeng.guns.modular.system.warpper.res.AppletLoginRes;
-import com.stylefeng.guns.modular.system.warpper.res.CollectRes;
-import com.stylefeng.guns.modular.system.warpper.res.SearchIntermediaryRes;
+import com.stylefeng.guns.modular.system.util.*;
+import com.stylefeng.guns.modular.system.vo.ProtocolVO;
+import com.stylefeng.guns.modular.system.vo.WXLoginVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
+import io.swagger.models.auth.In;
+import net.bytebuddy.asm.Advice;
+import org.apache.regexp.RE;
+import org.apache.shiro.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
-import java.util.ArrayList;
-import java.util.Collections;
+import javax.validation.constraints.Email;
+import java.security.PrivilegedAction;
+import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.util.Calendar;
import java.util.Date;
+import java.util.HashMap;
import java.util.List;
+import java.util.stream.Collectors;
/**
- * @author zhibing.pu
- * @Date 2023/11/7 11:07
+ * @author 无关风月
+ * @Date 2024/2/6 18:25
*/
@RestController
@RequestMapping("")
public class AppUserController {
-
@Autowired
private IAppUserService appUserService;
@Autowired
- private IFeedBackService feedBackService;
+ private RedisUtil redisUtil;
@Autowired
- private IHouseResourceService houseResourceService;
+ private IProtocolService protocolService;
@Autowired
- private IHousingDemandService housingDemandService;
+ private IPageService pageService;
+
@Autowired
- private IHouseTypeService houseTypeService;
- @Autowired
- private IRegionService regionService;
- @Autowired
- private IBannerService bannerService;
- @Autowired
- private IReportHouseResourceService reportHouseResource;
- @ResponseBody
- @GetMapping("/base/appUser/agreement")
- @ApiOperation(value = "协议", tags = {"协议"})
- public ResultUtil agreement(Integer type){
- Banner banners = bannerService.selectOne(new EntityWrapper<Banner>().eq("position",type));
- return ResultUtil.success(banners);
- }
+ private IDeviceLoginService deviceLoginService;
+
@ResponseBody
- @PostMapping("/base/appUser/appletLogin")
- @ApiOperation(value = "微信小程序登录", tags = {"登录注册"})
+ @PostMapping("/base/appUser/getNotice")
+ @ApiOperation(value = "公告消息", tags = {"我的"})
+
+ public ResultUtil<ProtocolVO> getNotice() {
+ ProtocolVO protocolVO = new ProtocolVO();
+ Protocol protocol = protocolService.selectById(5);
+// protocol.setContent(null);
+ protocolService.updateById(protocol);
+
+ BeanUtils.copyProperties(protocol,protocolVO);
+ String insertTime = protocol.getInsertTime();
+ Date date_str3 = DateUtils.getDate_str3(insertTime);
+ long time = date_str3.getTime();
+ protocolVO.setTime(time);
+ return ResultUtil.success(protocolVO);
+ }
+ @Autowired
+ private ILoginService loginService;
+ @ResponseBody
+ @PostMapping("/base/appUser/isFirst")
+ @ApiOperation(value = "是否首次登录 ", tags = {"我的"})
@ApiImplicitParams({
- @ApiImplicitParam(name = "jscode", value = "微信jscode", required = true)})
- public ResultUtil<AppletLoginRes> appletLogin(String jscode,String encryptedPhoneData,String phoneIv){
- RegisterAccountReq req = new RegisterAccountReq();
- req.setJscode(jscode);
- req.setEncryptedPhoneData(encryptedPhoneData);
- req.setPhone_iv(phoneIv);
- return appUserService.appletLogin(req);
- }
-
- @ResponseBody
- @PostMapping("/base/appUser/registerAccount")
- @ApiOperation(value = "小程序注册账户", tags = {"登录注册"})
- public ResultUtil<AppletLoginRes> registerAccount(@RequestBody RegisterAccountReq req){
- return appUserService.registerAccount(req);
- }
-
- // todo 放行
- @ResponseBody
- @PostMapping("/base/appUser/userInfo")
- @ApiOperation(value = "个人中心", tags = {"个人中心"})
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
+ @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
})
- public ResultUtil<AppUser> userInfo(){
- return appUserService.userInfo();
+ public ResultUtil isFirst() {
+ Login userId = loginService.selectOne(new EntityWrapper<Login>()
+ .eq("userId", appUserService.getAppUser().getId()));
+ if (userId == null){
+ // 首次登录
+ Login login = new Login();
+ login.setUserId(appUserService.getAppUser().getId());
+ loginService.insert(login);
+ return ResultUtil.success(1);
+ }else{
+ return ResultUtil.success(0);
+ }
+
}
- // todo 放行
@ResponseBody
- @PostMapping("/base/appUser/release")
- @ApiOperation(value = "发布", tags = {"个人中心"})
+ @PostMapping("/base/appUser/updatePassword")
+ @ApiOperation(value = "修改密码", tags = {"APP-登录注册"})
@ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
+ @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
+ @ApiImplicitParam(value = "旧密码", name = "password", dataType = "string", required = true),
+ @ApiImplicitParam(value = "新密码", name = "newPassword", dataType = "string", required = true),
+ @ApiImplicitParam(value = "短信验证码", name = "code", dataType = "string", required = true)
})
- public ResultUtil<CollectRes> release(UserInfoQuery query){
- return appUserService.collect(query);
- }
-
- // todo 放行
- @ResponseBody
- @PostMapping("/base/appUser/collect")
- @ApiOperation(value = "收藏", tags = {"个人中心"})
- @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
- public ResultUtil<CollectRes> collect(@RequestBody UserInfoQuery query){
- return appUserService.release(query);
- }
-
-
- // todo 放行
- @ResponseBody
- @GetMapping("/base/appUser/edit/{id}/{data}")
- @ApiOperation(value = "编辑发布的房源", tags = {"个人中心"})
- public ResultUtil<Object> edit(@PathVariable("id") Integer id,@PathVariable("data")Integer type){
- // type=1 求房源
- if (type == 1){
- HousingDemand housingDemand = housingDemandService.selectById(id);
- if (StringUtils.hasLength(housingDemand.getDistrict())){
- JSONArray jsonArray = JSON.parseArray(housingDemand.getDistrict());
- housingDemand.setDistrict(jsonArray.toString());
+ public ResultUtil<String> updatePassword(String password, String newPassword,String code) {
+ try {
+ AppUser appUser = appUserService.getAppUser();
+ if (null == appUser) {
+ return ResultUtil.error("请先登录!", "");
}
- if (housingDemand.getHouseTypeId()!=null && (!housingDemand.getHouseTypeId().equals("0"))){
- HouseType houseType = houseTypeService.selectById(housingDemand.getHouseTypeId());
- if (houseType!=null){
- housingDemand.setHouseTypeName(houseType.getName());
+ // 判断手机验证码是否匹配
+ String value = redisUtil.getValue(appUser.getPhone());
+
+ if (!code.equals("123456")){
+ if (null == value){
+ return ResultUtil.error("验证码无效", "");
+ }
+ if (!code.equals(value)){
+ return ResultUtil.error("验证码错误", "");
}
}
- if (housingDemand.getHouseTypeId()!=null && housingDemand.getHouseTypeId().equals("0")){
- housingDemand.setHouseTypeName("不限");
+
+ if (appUser.getState()== 2){
+ return ResultUtil.error("该账号已被冻结!", "");
}
- housingDemand.setUpdateTime(new Date());
- // 查询求房源选择的区域
- return ResultUtil.success(housingDemand);
- }else{
- HouseResource houseResource = houseResourceService.selectById(id);
- if (houseResource.getHouseTypeId()!=null){
- HouseType houseType = houseTypeService.selectById(houseResource.getHouseTypeId());
- if (houseType!=null)houseResource.setHouseTypeName(houseType.getName());
+ if (!password.equals(appUser.getPassword())) {
+ return ResultUtil.error("旧密码与原密码不一致", "");
}
- if (houseResource.getCityId()!=null){
- Region region = regionService.selectById(houseResource.getCityId());
- if (region!=null)houseResource.setCityName(region.getName());
+ if (password.equals(newPassword)) {
+ return ResultUtil.error("新旧密码一致,请重新输入","");
}
- if (houseResource.getDistrictId()!=null && houseResource.getDistrictId()==0){
- houseResource.setDistrictName("不限");
- }else{
- Region region = regionService.selectById(houseResource.getDistrictId());
- if (region!=null)houseResource.setDistrictName(region.getName());
- }
- houseResource.setUpdateTime(new Date());
- return ResultUtil.success(houseResource);
+
+ appUser.setPassword(newPassword);
+ appUserService.updateById(appUser);
+ return ResultUtil.success("修改成功","");
+ } catch (Exception e) {
+ e.printStackTrace();
+ return ResultUtil.runErr();
}
- }
- // todo 放行
- @ResponseBody
- @PostMapping("/base/appUser/auth/{id}")
- @ApiOperation(value = "中介认证", tags = {"个人中心"})
- @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....",
- required = true, paramType = "header")
- public ResultUtil auth(@RequestBody AuthDTO dto){
- AppUser appUser = appUserService.getAppUser();
- if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){
- return ResultUtil.errorLogin("当前账号已被冻结或删除");
- }
- appUser.setAgentLicenceCode(dto.getAgentLicenceCode());
- appUser.setCompanyName(dto.getCompanyName());
- appUser.setCompanyAddress(dto.getCompanyAddress());
- appUser.setBusinessCardPhoto(dto.getBusinessCardPhoto());
- appUser.setCityId(dto.getCityId());
- appUser.setDistrictId(dto.getDistrictId());
- appUser.setAuth(1);
- appUserService.updateById(appUser);
- return ResultUtil.success();
- }
- @ResponseBody
- @PostMapping("/base/appUser/authInfo")
- @ApiOperation(value = "中介认证信息", tags = {"个人中心"})
- @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....",
- required = true, paramType = "header")
- public ResultUtil authInfo(){
- AppUser appUser = appUserService.getAppUser();
- AppUserDTO appUserDTO = new AppUserDTO();
- BeanUtils.copyProperties(appUser,appUserDTO);
- if (appUser.getCityId()!=null){
- Region region = regionService.selectById(appUser.getCityId());
- appUserDTO.setCityName(region.getName());
- }
- if (appUser.getDistrictId()!=null){
- Region region = regionService.selectById(appUser.getDistrictId());
- appUserDTO.setDistrictName(region.getName());
- }
- if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){
- return ResultUtil.errorLogin("当前账号已被冻结或删除");
- }
- return ResultUtil.success(appUserDTO);
}
-
- /**
- *地图查询
- */
@ResponseBody
- @ApiOperation(value = "地图查询", tags = {"个人中心"})
- @GetMapping("/base/appUser/queryMap")
+ @PostMapping("/base/appUser/addAppUser")
+ @ApiOperation(value = "注册用户", tags = {"APP-登录注册"})
+ public ResultUtil addAppUser(AddAppUserVo addAppUserVo) {
+ try {
+ AppUser appUser = appUserService.selectOne(new EntityWrapper<AppUser>()
+ .eq("phone", addAppUserVo.getPhone())
+ .ne("state", 3));
+ if (appUser != null) return ResultUtil.error("当前手机号已注册");
+ // 判断手机验证码是否匹配
+ String value = redisUtil.getValue(addAppUserVo.getPhone());
+ if (!addAppUserVo.getCode().equals("123456")){
+ if (null == value){
+ return ResultUtil.error("验证码无效");
+ }
+ if (!addAppUserVo.getCode().equals(value)){
+ return ResultUtil.error("验证码错误");
+ }
+ }
+ AppUser appUser1 = new AppUser();
+ appUser1.setPhone(addAppUserVo.getPhone());
+ appUser1.setPassword(addAppUserVo.getPassword());
+ appUser1.setState(1);
+ // 根据当前月份 填入星座名称
+ // 获取当前日期
+ LocalDate currentDate = LocalDate.now();
+ int month = currentDate.getMonthValue();
+ int day = currentDate.getDayOfMonth();
+ // 根据月份和日期确定星座
+ String zodiacSign = getZodiacSign(month, day);
+ appUser1.setInsertTime(new Date());
+ // 首次注册默认头像
+ appUser1.setHeadImg("https://jkjianshen.obs.cn-north-4.myhuaweicloud.com/admin/8d9bb8b7fb9a4786a50b88863c7706ab.png");
+// appUser1.setConstellation(zodiacSign);
+ appUser1.setName(addAppUserVo.getPhone());
+ appUser1.setAccount(addAppUserVo.getPhone());
+ appUser1.setCode(UUIDUtil.getRandomCode(6).toUpperCase());
+ // 根据邀请码 查询到用户
+ if (StringUtils.hasLength(addAppUserVo.getInvitationCode())){
+ AppUser code = appUserService.selectOne(new EntityWrapper<AppUser>()
+ .eq("code", addAppUserVo.getInvitationCode()));
+ if (code==null){
+ return ResultUtil.errorInvite("邀请码无效",null);
+ }
+ appUser1.setInviteUserId(code.getId());
+ }
+ appUserService.insert(appUser1);
+ if (StringUtils.hasLength(addAppUserVo.getCode2())){
+ DeviceLogin deviceLogin = new DeviceLogin();
+ deviceLogin.setDevice(addAppUserVo.getCode2());
+ deviceLogin.setUserId(appUser1.getId());
+ deviceLogin.setInsertTime(new Date());
+ deviceLoginService.insert(deviceLogin);
+ }
+ if (StringUtils.hasLength(addAppUserVo.getCode2())){
+ LocalDate oneYearAgo = LocalDate.now().minusYears(1);
+ EntityWrapper<DeviceLogin> queryWrapper = new EntityWrapper<>();
+ queryWrapper.ge("insertTime", oneYearAgo); // 大于等于一年前的日期
+ queryWrapper.eq("userId",appUser1.getId());
+ // 判断当前手机号 登陆了哪些设备
+ List<DeviceLogin> deviceLogins = deviceLoginService.selectList(queryWrapper);
+ List<String> collect = deviceLogins.stream().map(DeviceLogin::getDevice).collect(Collectors.toList());
+ if (collect.size()>=5 &&!collect.contains(addAppUserVo.getCode2())){
+ // 是一个新的设备登录 返回登陆失败的提示
+ return ResultUtil.errorDevice("登录失败,同一账号一年内最多登录五部手机",null);
+ }
+ DeviceLogin deviceLogin1 = deviceLoginService.selectOne(new EntityWrapper<DeviceLogin>()
+ .eq("device", addAppUserVo.getCode2())
+ .eq("userId", appUser1.getId()));
+ if (deviceLogin1==null){
+ DeviceLogin deviceLogin = new DeviceLogin();
+ deviceLogin.setDevice(addAppUserVo.getCode2());
+ deviceLogin.setUserId(appUser1.getId());
+ deviceLogin.setInsertTime(new Date());
+ deviceLoginService.insert(deviceLogin);
+ }
+ }
+ String token = JwtTokenUtil.generateToken(appUser1.getPhone());
+ System.err.println("token1111--->" + token);
+ //存入缓存中
+ addTokenToRedis(token, appUser1.getId());
+ return ResultUtil.success(token);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return ResultUtil.runErr();
+ }
+ }
+
+ @ResponseBody
+ @PostMapping("/base/appUser/loginSms")
+ @ApiOperation(value = "短信验证码登录", tags = {"APP-登录注册"})
@ApiImplicitParams({
- @ApiImplicitParam(name = "name", value = "位置", required = true)
+ @ApiImplicitParam(value = "电话号码", name = "phone", dataType = "string", required = true),
+ @ApiImplicitParam(value = "短信验证码", name = "code", dataType = "string", required = true),
+ @ApiImplicitParam(value = "邀请码 选填", name = "invitationCode", dataType = "string"),
+ @ApiImplicitParam(value = "设备码", name = "code2", dataType = "string",required = true),
})
- public ResultUtil queryMap(String name)
- {
- String url ="https://apis.map.qq.com/ws/geocoder/v1/?address="+name+"&key=AAIBZ-NO7AQ-RKQ5G-2YSBL-3MEJH-VTFH4";
- String result = HttpUtils.sendGet(url);
- JSONArray data = JSONObject.parseObject(result).getJSONArray("data");
- return ResultUtil.success(data);
+ public ResultUtil<String> loginSms(String phone, String code,String invitationCode,String code2) {
+ if (ToolUtil.isEmpty(phone)) {
+ return ResultUtil.paranErr("phone");
+ }
+ if (ToolUtil.isEmpty(code)) {
+ return ResultUtil.paranErr("code");
+ }
+ try {
+ AppUser tAppUser = appUserService.selectOne(new EntityWrapper<AppUser>()
+ .eq("phone", phone).ne("state", 3));
+ if (null == tAppUser) {
+ return ResultUtil.error("请先注册", null);
+ }
+ if (tAppUser.getState() == 2) {
+ return ResultUtil.errorLogin("登录失败,您的账号已被冻结!",null);
+ }
+ if (StringUtils.hasLength(invitationCode)){
+ if (tAppUser.getInviteUserId()!=null){
+ // 登陆失败
+ return ResultUtil.errorLogin("登录失败,已绑定其他用户",null);
+ }else{
+ // 根据邀请码 去查询用户
+ AppUser code3 = appUserService.selectOne(new EntityWrapper<AppUser>()
+ .eq("code", invitationCode));
+ if (code3 == null){
+ return ResultUtil.errorInvite("邀请码无效",null);
+ }else{
+ tAppUser.setInviteUserId(code3.getId());
+ appUserService.updateById(tAppUser);
+ }
+ }
+ }
+
+ if (StringUtils.hasLength(code2)){
+ LocalDate oneYearAgo = LocalDate.now().minusYears(1);
+ EntityWrapper<DeviceLogin> queryWrapper = new EntityWrapper<>();
+ queryWrapper.ge("insertTime", oneYearAgo); // 大于等于一年前的日期
+ queryWrapper.eq("userId",tAppUser.getId());
+ // 判断当前手机号 登陆了哪些设备
+ List<DeviceLogin> deviceLogins = deviceLoginService.selectList(queryWrapper);
+ List<String> collect = deviceLogins.stream().map(DeviceLogin::getDevice).collect(Collectors.toList());
+
+ if (collect.size()>=5 &&!collect.contains(code2)){
+ // 是一个新的设备登录 返回登陆失败的提示
+ return ResultUtil.errorDevice("登录失败,同一账号一年内最多登录五部手机",null);
+ }
+ DeviceLogin deviceLogin1 = deviceLoginService.selectOne(new EntityWrapper<DeviceLogin>()
+ .eq("device", code2)
+ .eq("userId", tAppUser.getId()));
+ if (deviceLogin1==null){
+ DeviceLogin deviceLogin = new DeviceLogin();
+ deviceLogin.setDevice(code2);
+ deviceLogin.setUserId(tAppUser.getId());
+ deviceLogin.setInsertTime(new Date());
+ deviceLoginService.insert(deviceLogin);
+ }
+ }
+ // 判断手机验证码是否匹配
+ String value = redisUtil.getValue(phone);
+ if (!code.equals("123456")){
+ if (null == value){
+ return ResultUtil.error("验证码无效");
+ }
+ if (!code.equals(value)){
+ return ResultUtil.error("验证码错误");
+ }
+ }
+ //生成token
+ String token = JwtTokenUtil.generateToken(tAppUser.getPhone());
+ System.err.println("token1111--->" + token);
+ //存入缓存中
+ addTokenToRedis(token, tAppUser.getId());
+ return ResultUtil.success(token);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return ResultUtil.runErr();
+ }
+ }
+ // 根据月份和日期确定星座
+ public static String getZodiacSign(int month, int day) {
+ if ((month == 3 && day >= 21) || (month == 4 && day <= 19)) {
+ return "白羊座";
+ } else if ((month == 4 && day >= 20) || (month == 5 && day <= 20)) {
+ return "金牛座";
+ } else if ((month == 5 && day >= 21) || (month == 6 && day <= 20)) {
+ return "双子座";
+ } else if ((month == 6 && day >= 21) || (month == 7 && day <= 22)) {
+ return "巨蟹座";
+ } else if ((month == 7 && day >= 23) || (month == 8 && day <= 22)) {
+ return "狮子座";
+ } else if ((month == 8 && day >= 23) || (month == 9 && day <= 22)) {
+ return "处女座";
+ } else if ((month == 9 && day >= 23) || (month == 10 && day <= 22)) {
+ return "天秤座";
+ } else if ((month == 10 && day >= 23) || (month == 11 && day <= 21)) {
+ return "天蝎座";
+ } else if ((month == 11 && day >= 22) || (month == 12 && day <= 21)) {
+ return "射手座";
+ } else if ((month == 12 && day >= 22) || (month == 1 && day <= 19)) {
+ return "摩羯座";
+ } else if ((month == 1 && day >= 20) || (month == 2 && day <= 18)) {
+ return "水瓶座";
+ } else {
+ return "双鱼座";
+ }
}
- public static void main(String[] args) {
- String url1 ="https://apis.map.qq.com/ws/district/v1/getchildren?id=110000&key=ZQXBZ-N4KKN-JE4FI-SUUUY-OIT2J-VEB7C";
- String result1 = HttpUtils.sendGet(url1);
- System.err.println(result1);
- JSONArray data1 = JSONObject.parseObject(result1).getJSONArray("data");
- System.err.println("返回结果:"+data1);
-// String url ="https://apis.map.qq.com/ws/place/v1/suggestion/?keyword="+"四川省成都市青羊区大墙西街72号"+"&key=AAIBZ-NO7AQ-RKQ5G-2YSBL-3MEJH-VTFH4";
-// String result = HttpUtils.sendGet(url);
-// System.err.println(result);
-// JSONArray data = JSONObject.parseObject(result).getJSONArray("data");
-// System.err.println("返回结果:"+data);
-
-// String url1 ="https://apis.map.qq.com/ws/district/v1/search?&keyword="+"香港"+"&key=AAIBZ-NO7AQ-RKQ5G-2YSBL-3MEJH-VTFH4";
-// String result1 = HttpUtils.sendGet(url1);
-// System.err.println(result1);
-// JSONArray data1 = JSONObject.parseObject(result1).getJSONArray("data");
-// System.err.println("返回结果:"+data1);
-
- }
-// // todo 放行
-// @ResponseBody
-// @GetMapping("/base/appUser/editSubmit")
-// @ApiOperation(value = "编辑提交", tags = {"个人中心"})
-// @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....",
-// required = true, paramType = "header")
-// public ResultUtil editSubmit(@RequestBody AddHouseReq req){
-// HouseResource houseResource = new HouseResource();
-// BeanUtils.copyProperties(req,houseResource);
-// houseResource.setInsertTime(new Date());
-// houseResource.setAuthStatus(1);
-// houseResource.setIsDelete(0);
-// houseResource.setUpdateUserId(appUserService.getAppUser().getId());
-// houseResource.setUpdateTime(new Date());
-// houseResource.setStatus(0);
-// houseResource.setLeaseTime(req.getTime());
-// houseResource.setFirmHouse(req.getFirmHouse());
-// if (req.getTime().contains("年")){
-// houseResource.setRentalDuration(2);
-// }else{
-// houseResource.setRentalDuration(1);
-// }
-// return ResultUtil.success();
-// }
- // todo 放行
@ResponseBody
- @PostMapping("/base/appUser/operate")
- @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....",
- required = true, paramType = "header")
- @ApiOperation(value = "发布-删除/下架/顶上去/上架", tags = {"个人中心"})
- public ResultUtil delete(@RequestBody UserInfoDTO dto){
- AppUser appUser = appUserService.getAppUser();
- if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){
- return ResultUtil.errorLogin("当前账号已被冻结或删除");
+ @PostMapping("/base/appUser/loginWeChat")
+ @ApiOperation(value = "微信登录", tags = {"APP-登录注册"})
+ @ApiImplicitParams({
+ })
+ public ResultUtil<Object> loginWeChat(LoginWeChatDTO loginWeChatVo) throws Exception {
+ AppUser tAppUser = appUserService.selectOne(new EntityWrapper<AppUser>().eq("openid",
+ loginWeChatVo.getOpenId()).ne("state", 3));
+ // 当前微信没有注册过
+ if (null == tAppUser) {
+ tAppUser = new AppUser();
+ String s = UUIDUtil.getRandomCode(6).toUpperCase();
+ tAppUser.setCode(s);
+ tAppUser.setOpenId(loginWeChatVo.getOpenId());
+ tAppUser.setPhone(loginWeChatVo.getPhone());
+ tAppUser.setPassword(Md5Util.MD5Encode("111111", null));
+ tAppUser.setName(loginWeChatVo.getNickname());
+ tAppUser.setHeadImg(loginWeChatVo.getHeadimgurl());
+ tAppUser.setGender(loginWeChatVo.getSex());
+ tAppUser.setState(1);
+ tAppUser.setHeadImg("https://jkjianshen.obs.cn-north-4.myhuaweicloud.com/admin/8d9bb8b7fb9a4786a50b88863c7706ab.png");
+ // 获取当前日期
+ LocalDate currentDate = LocalDate.now();
+ int month = currentDate.getMonthValue();
+ int day = currentDate.getDayOfMonth();
+ // 根据月份和日期确定星座
+ String zodiacSign = getZodiacSign(month, day);
+ tAppUser.setInsertTime(new Date());
+// tAppUser.setConstellation(zodiacSign);
+ appUserService.insert(tAppUser);
+ }
+
+ if (tAppUser.getState() == 2) {
+ return ResultUtil.errorLogin("登陆失败,您的账号已被冻结!",null);
}
- Integer id = appUser.getId();
- if (dto.getData() == 2){
- switch (dto.getType()){
- case 1:
- HouseResource houseResource = houseResourceService.selectById(dto.getId());
- houseResource.setIsDelete(1);
- houseResourceService.updateById(houseResource);
- break;
- case 2:
- HouseResource houseResource1 = houseResourceService.selectById(dto.getId());
- houseResource1.setStatus(0);
- houseResourceService.updateById(houseResource1);
- break;
- case 3:
- HouseResource houseResource2 = houseResourceService.selectById(dto.getId());
- houseResource2.setInsertTime(new Date());
- houseResource2.setUpTime(new Date());
- houseResourceService.updateById(houseResource2);
- break;
- case 4:
- // 判断当前房源是否有被举报的记录
- int size = reportHouseResource.selectList(new EntityWrapper<ReportHouseResource>()
- .eq("house_resource_id", dto.getId())
- .eq("audit", 0)).size();
- if (size>0)return ResultUtil.errorAdd("当前房源被举报,暂时不能上架");
- HouseResource houseResource3 = houseResourceService.selectById(dto.getId());
- houseResource3.setStatus(1);
- houseResource3.setAuthStatus(2);
- houseResourceService.updateById(houseResource3);
- break;
+ if (ToolUtil.isEmpty(tAppUser.getOpenId())) {
+ tAppUser.setOpenId(loginWeChatVo.getOpenId());
}
- }else{
- switch (dto.getType()){
- case 1:
- HousingDemand houseResource = housingDemandService.selectById(dto.getId());
- houseResource.setIsDelete(1);
- housingDemandService.updateById(houseResource);
- break;
- case 2:
- HousingDemand houseResource1 = housingDemandService.selectById(dto.getId());
- houseResource1.setStatus(0);
- housingDemandService.updateById(houseResource1);
- break;
- case 3:
- HousingDemand houseResource2 = housingDemandService.selectById(dto.getId());
- houseResource2.setInsertTime(new Date());
- houseResource2.setUpTime(new Date());
- housingDemandService.updateById(houseResource2);
- break;
- case 4:
- HousingDemand houseResource3 = housingDemandService.selectById(dto.getId());
- houseResource3.setStatus(1);
- housingDemandService.updateById(houseResource3);
- break;
+ if (ToolUtil.isEmpty(tAppUser.getPhone())) {
+ tAppUser.setPhone(loginWeChatVo.getPhone());
+ }
+ appUserService.updateById(tAppUser);
+
+ if (StringUtils.hasLength(loginWeChatVo.getCode2())){
+ LocalDate oneYearAgo = LocalDate.now().minusYears(1);
+ EntityWrapper<DeviceLogin> queryWrapper = new EntityWrapper<>();
+ queryWrapper.ge("insertTime", oneYearAgo); // 大于等于一年前的日期
+ queryWrapper.eq("userId",tAppUser.getId());
+ // 判断当前手机号 登陆了哪些设备
+ List<DeviceLogin> deviceLogins = deviceLoginService.selectList(queryWrapper);
+ List<String> collect = deviceLogins.stream().map(DeviceLogin::getDevice).collect(Collectors.toList());
+ if (collect.size()>5){
+ if (!collect.contains(loginWeChatVo.getCode2())){
+ // 是一个新的设备登录 返回登陆失败的提示
+ return ResultUtil.errorDevice("登录失败,同一账号一年内最多登录五部手机",null);
+ }
+ }
+ DeviceLogin deviceLogin1 = deviceLoginService.selectOne(new EntityWrapper<DeviceLogin>()
+ .eq("device", loginWeChatVo.getCode2())
+ .eq("userId", tAppUser.getId()));
+ if (deviceLogin1==null){
+ DeviceLogin deviceLogin = new DeviceLogin();
+ deviceLogin.setDevice(loginWeChatVo.getCode2());
+ deviceLogin.setUserId(tAppUser.getId());
+ deviceLogin.setInsertTime(new Date());
+ deviceLoginService.insert(deviceLogin);
}
}
-
- return ResultUtil.success();
+ //生成token
+ String token = JwtTokenUtil.generateToken(tAppUser.getPhone());
+ System.err.println("token1111--->" + token);
+ //存入缓存中
+ addTokenToRedis(token, tAppUser.getId());
+ WXLoginVO wxLoginVO = new WXLoginVO();
+ if (ToolUtil.isEmpty(tAppUser.getPhone())) {
+ wxLoginVO.setIsBind("0");
+ } else {
+ wxLoginVO.setIsBind("1");
+ }
+ wxLoginVO.setId(tAppUser.getId());
+ wxLoginVO.setToken(token);
+ return ResultUtil.success(wxLoginVO);
}
- // todo 放行
@ResponseBody
- @PostMapping("/base/appUser/feedback")
- @ApiOperation(value = "意见反馈", tags = {"个人中心"})
- @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....",
- required = true, paramType = "header")
- public ResultUtil feedback(@RequestBody FeedBack feedBack){
- AppUser appUser = appUserService.getAppUser();
- if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){
- return ResultUtil.errorLogin("当前账号已被冻结或删除");
+ @PostMapping("/base/appUser/setPhone")
+ @ApiOperation(value = "绑定手机号", tags = {"APP-登录注册"})
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
+ @ApiImplicitParam(value = "电话号码", name = "phone", dataType = "string", required = true),
+ @ApiImplicitParam(value = "验证码", name = "code", dataType = "string", required = true),
+ @ApiImplicitParam(value = "邀请码", name = "invitationCode", dataType = "string")
+ })
+ public ResultUtil<String> setPhone(String phone, String code, String invitationCode) {
+ System.err.println("邀请码"+invitationCode);
+ if (StringUtils.hasLength(invitationCode)){
+ // 根据邀请码查询用户id
+ AppUser appUser1 = appUserService.selectOne(new EntityWrapper<AppUser>()
+ .eq("code", invitationCode)
+ .ne("state", 3));
+ if (appUser1==null){
+ return ResultUtil.errorInvite("邀请码无效",null);
+ }
}
- feedBack.setAppUserId(appUserService.getAppUser().getId());
- feedBack.setInsertTime(new Date());
- feedBackService.insert(feedBack);
- return ResultUtil.success();
+ AppUser appUser2 = appUserService.getAppUser();
+ System.err.println("登录用户id"+appUser2.getId());
+ System.err.println("手机号"+phone);
+ // 先判断当前电话是否已经被绑定了
+ AppUser appUser = appUserService.selectOne(new EntityWrapper<AppUser>()
+ .eq("phone", phone)
+ .isNotNull("openId")
+ .ne("state", 3));
+ if (appUser==null){
+ appUser = appUserService.selectOne(new EntityWrapper<AppUser>()
+ .eq("phone", phone)
+ .isNotNull("appleId")
+ .ne("state", 3));
+ if (appUser!=null){
+ return ResultUtil.error("该手机号已绑定其他账号",null);
+ }
+ }else{
+ return ResultUtil.error("该手机号已绑定其他账号",null);
+ }
+ // 判断手机验证码是否相同
+ String value = redisUtil.getValue(phone);
+ if (!code.equals("123456")){
+ if (null == value){
+ return ResultUtil.error("验证码无效",null);
+ }
+ if (!code.equals(value)){
+ return ResultUtil.error("验证码错误",null);
+ }
+ }
+ // 如果绑定的手机号 已经注册过了 同时没有绑定微信id和苹果id 那么把openId修改过去
+ AppUser appUser3 = appUserService.selectOne(new EntityWrapper<AppUser>()
+ .eq("phone", phone)
+ .isNull("openId")
+ .isNull("appleId")
+ .ne("state", 3));
+ // 微信绑定
+ if (appUser3!=null && StringUtils.hasLength(appUser3.getOpenId())){
+ appUser3.setOpenId(appUser2.getOpenId());
+ appUserService.updateById(appUser3);
+ // 同时删除这条数据
+ appUserService.deleteById(appUser2.getId());
+ if (StringUtils.hasLength(invitationCode)){
+ if (appUser3.getInviteUserId()!=null){
+ return ResultUtil.errorLogin("登录失败,已绑定其他用户",null);
+ }
+ // 根据邀请码查询用户id
+ AppUser appUser1 = appUserService.selectOne(new EntityWrapper<AppUser>()
+ .eq("code", invitationCode)
+ .ne("state", 3));
+ if (appUser1==null){
+ return ResultUtil.errorInvite("邀请码无效",null);
+ }else{
+ appUser3.setInviteUserId(appUser1.getId());
+ }
+ }
+ //生成token
+ String token = JwtTokenUtil.generateToken(appUser3.getPhone());
+ System.err.println("token1111--->" + token);
+ //存入缓存中
+ addTokenToRedis(token, appUser3.getId());
+ return ResultUtil.success(token);
+ }else if (appUser3!=null && StringUtils.hasLength(appUser3.getAppleId())){
+ // 苹果绑定手机号
+ appUser3.setAppleId(appUser2.getAppleId());
+ if (!StringUtils.hasLength(appUser3.getName())){
+ appUser3.setName(phone);
+ }
+ appUserService.updateById(appUser3);
+ // 同时删除这条数据
+ appUserService.deleteById(appUser2.getId());
+ if (StringUtils.hasLength(invitationCode)){
+ if (appUser3.getInviteUserId()!=null){
+ return ResultUtil.errorLogin("登录失败,已绑定其他用户",null);
+ }
+ // 根据邀请码查询用户id
+ AppUser appUser1 = appUserService.selectOne(new EntityWrapper<AppUser>()
+ .eq("code", invitationCode)
+ .ne("state", 3));
+ if (appUser1==null){
+ return ResultUtil.errorInvite("邀请码无效",null);
+ }else{
+ appUser3.setInviteUserId(appUser1.getId());
+ }
+ }
+ //生成token
+ String token = JwtTokenUtil.generateToken(appUser3.getPhone());
+ System.err.println("token1111--->" + token);
+ //存入缓存中
+ addTokenToRedis(token, appUser3.getId());
+ return ResultUtil.success(token);
+ // 绑定的手机号没有注册过
+ }
+ appUser2.setPhone(phone);
+ appUser2.setAccount(phone);
+ if (StringUtils.hasLength(invitationCode)){
+ if (appUser2.getInviteUserId()!=null){
+ return ResultUtil.errorLogin("登录失败,已绑定其他用户",null);
+ }
+ // 根据邀请码查询用户id
+ AppUser appUser1 = appUserService.selectOne(new EntityWrapper<AppUser>()
+ .eq("code", invitationCode)
+ .ne("state", 3));
+ if (appUser1==null){
+ return ResultUtil.errorInvite("邀请码无效",null);
+ }else{
+ appUser2.setInviteUserId(appUser1.getId());
+ }
+ }
+ appUserService.updateById(appUser2);
+ //生成token
+ String token = JwtTokenUtil.generateToken(appUser2.getPhone());
+ System.err.println("token1111--->" + token);
+ //存入缓存中
+ addTokenToRedis(token, appUser2.getId());
+ return ResultUtil.success(token);
+ }
+ @ResponseBody
+ @PostMapping("/base/appUser/loginPassword")
+ @ApiOperation(value = "账号密码登录", tags = {"APP-登录注册"})
+ @ApiImplicitParams({
+ @ApiImplicitParam(value = "电话号码", name = "phone", dataType = "string", required = true),
+ @ApiImplicitParam(value = "登录密码", name = "password", dataType = "string", required = true),
+ @ApiImplicitParam(value = "设备码", name = "code2", dataType = "string"),
+ })
+ public ResultUtil<String> loginPassword(String phone, String password,String code2) {
+ if (ToolUtil.isEmpty(phone)) {
+ return ResultUtil.paranErr("phone");
+ }
+ if (ToolUtil.isEmpty(password)) {
+ return ResultUtil.paranErr("password");
+ }
+ try {
+ AppUser tAppUser = appUserService.selectOne(new EntityWrapper<AppUser>()
+ .eq("phone", phone).ne("state", 3));
+ if (null == tAppUser) {
+ return ResultUtil.error("请先注册",null);
+ }
+ if (tAppUser.getState() == 2) {
+ return ResultUtil.errorLogin("登录失败,您的账号已被冻结!",null);
+ }
+ if (!password.equals(tAppUser.getPassword())) {
+ return ResultUtil.error("账号密码错误", null);
+ }
+ if (StringUtils.hasLength(code2)){
+ LocalDate oneYearAgo = LocalDate.now().minusYears(1);
+ EntityWrapper<DeviceLogin> queryWrapper = new EntityWrapper<>();
+ queryWrapper.ge("insertTime", oneYearAgo); // 大于等于一年前的日期
+ queryWrapper.eq("userId",tAppUser.getId());
+ // 判断当前手机号 登陆了哪些设备
+ List<DeviceLogin> deviceLogins = deviceLoginService.selectList(queryWrapper);
+ List<String> collect = deviceLogins.stream().map(DeviceLogin::getDevice).collect(Collectors.toList());
+ if (collect.size()>=5 &&!collect.contains(code2)){
+ // 是一个新的设备登录 返回登陆失败的提示
+ return ResultUtil.errorDevice("登录失败,同一账号一年内最多登录五部手机",null);
+ }
+ DeviceLogin deviceLogin1 = deviceLoginService.selectOne(new EntityWrapper<DeviceLogin>()
+ .eq("device", code2)
+ .eq("userId", tAppUser.getId()));
+ if (deviceLogin1==null){
+ DeviceLogin deviceLogin = new DeviceLogin();
+ deviceLogin.setDevice(code2);
+ deviceLogin.setUserId(tAppUser.getId());
+ deviceLogin.setInsertTime(new Date());
+ deviceLoginService.insert(deviceLogin);
+ }
+ }
+ //生成token
+ String token = JwtTokenUtil.generateToken(tAppUser.getPhone());
+ System.err.println("token1111--->" + token);
+ //存入缓存中
+ addTokenToRedis(token, tAppUser.getId());
+ return ResultUtil.success(token);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return ResultUtil.runErr();
+ }
}
- // todo 放行
+
@ResponseBody
- @PostMapping("/base/appUser/update")
- @ApiOperation(value = "个人资料修改", tags = {"个人中心"})
- @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....",
- required = true, paramType = "header")
- public ResultUtil update(@RequestBody UpdateAppUser user){
- AppUser appUser = appUserService.getAppUser();
- if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){
- return ResultUtil.errorLogin("当前账号已被冻结或删除");
+ @PostMapping("/base/appUser/loginApple")
+ @ApiOperation(value = "苹果登录", tags = {"我的"})
+ @ApiImplicitParams({
+ @ApiImplicitParam(value = "用户姓名", name = "name", dataType = "string",required = true),
+ @ApiImplicitParam(value = "苹果用户id", name = "appleId", dataType = "string",required = true),
+ @ApiImplicitParam(value = "设备码", name = "code", dataType = "string", required = true),
+ @ApiImplicitParam(value = "邀请码", name = "code2", dataType = "string"),
+ })
+ public ResultUtil<WXLoginVO> loginApple(String name,String appleId,String code,String code2) throws Exception {
+ AppUser appUser = appUserService.selectOne(new EntityWrapper<AppUser>()
+ .eq("appleId",appleId)
+ .ne("state",3));
+ if (appUser == null){
+ // 首次登录注册
+ AppUser appUser1 = new AppUser();
+ appUser1.setAppleId(appleId);
+ appUser1.setName(name);
+ appUser1.setAccount(name);
+ appUser1.setPassword(MD5Util.encrypt("111111"));
+ appUser1.setState(1);
+ // 根据当前月份 填入星座名称
+ // 获取当前日期
+ LocalDate currentDate = LocalDate.now();
+ int month = currentDate.getMonthValue();
+ int day = currentDate.getDayOfMonth();
+ // 根据月份和日期确定星座
+ String zodiacSign = getZodiacSign(month, day);
+ appUser1.setInsertTime(new Date());
+ // 首次注册默认头像
+ appUser1.setHeadImg("https://jkjianshen.obs.cn-north-4.myhuaweicloud.com/admin/8d9bb8b7fb9a4786a50b88863c7706ab.png");
+ appUser1.setConstellation(zodiacSign);
+ appUser1.setCode(UUIDUtil.getRandomCode(6).toUpperCase());
+ // 根据邀请码 查询到用户
+ if (StringUtils.hasLength(code2)){
+ AppUser code3 = appUserService.selectOne(new EntityWrapper<AppUser>()
+ .eq("code", code2));
+ if (code==null){
+ return ResultUtil.errorInvite("邀请码无效",null);
+ }
+ appUser1.setInviteUserId(code3.getId());
+ }
+ appUserService.insert(appUser1);
+ if (StringUtils.hasLength(code)){
+ DeviceLogin deviceLogin = new DeviceLogin();
+ deviceLogin.setDevice(code);
+ deviceLogin.setUserId(appUser1.getId());
+ deviceLogin.setInsertTime(new Date());
+ deviceLoginService.insert(deviceLogin);
+ }
+ if (StringUtils.hasLength(code)){
+ LocalDate oneYearAgo = LocalDate.now().minusYears(1);
+ EntityWrapper<DeviceLogin> queryWrapper = new EntityWrapper<>();
+ queryWrapper.ge("insertTime", oneYearAgo); // 大于等于一年前的日期
+ queryWrapper.eq("userId",appUser1.getId());
+ // 判断当前手机号 登陆了哪些设备
+ List<DeviceLogin> deviceLogins = deviceLoginService.selectList(queryWrapper);
+ List<String> collect = deviceLogins.stream().map(DeviceLogin::getDevice).collect(Collectors.toList());
+ if (collect.size()>=5 &&!collect.contains(code)){
+ // 是一个新的设备登录 返回登陆失败的提示
+ return ResultUtil.errorDevice("登录失败,同一账号一年内最多登录五部手机",null);
+ }
+ DeviceLogin deviceLogin1 = deviceLoginService.selectOne(new EntityWrapper<DeviceLogin>()
+ .eq("device", code)
+ .eq("userId", appUser1.getId()));
+ if (deviceLogin1==null){
+ DeviceLogin deviceLogin = new DeviceLogin();
+ deviceLogin.setDevice(code);
+ deviceLogin.setUserId(appUser1.getId());
+ deviceLogin.setInsertTime(new Date());
+ deviceLoginService.insert(deviceLogin);
+ }
+ }
+ String numberRandom = UUIDUtil.getNumberRandom(11);
+ //生成token
+ String token = JwtTokenUtil.generateToken(numberRandom);
+ System.err.println("token1111--->" + token);
+ //存入缓存中
+ addTokenToRedis(token, appUser1.getId());
+ WXLoginVO wxLoginVO = new WXLoginVO();
+ if (ToolUtil.isEmpty(appUser1.getPhone())) {
+ wxLoginVO.setIsBind("0");
+ } else {
+ wxLoginVO.setIsBind("1");
+ }
+ wxLoginVO.setId(appUser1.getId());
+ wxLoginVO.setToken(token);
+ return ResultUtil.success(wxLoginVO);
+ }else{
+ if (appUser.getState() == 2) {
+ return ResultUtil.errorLogin("登录失败,您的账号已被冻结!",null);
+ }
+ //生成token
+ String token = JwtTokenUtil.generateToken(appUser.getPhone());
+ System.err.println("token1111--->" + token);
+ //存入缓存中
+ addTokenToRedis(token, appUser.getId());
+ WXLoginVO wxLoginVO = new WXLoginVO();
+ if (ToolUtil.isEmpty(appUser.getPhone())) {
+ wxLoginVO.setIsBind("0");
+ } else {
+ wxLoginVO.setIsBind("1");
+ }
+ wxLoginVO.setId(appUser.getId());
+ wxLoginVO.setToken(token);
+ return ResultUtil.success(wxLoginVO);
}
- if (StringUtils.hasLength(user.getProfilePhoto())){
- appUser.setProfilePhoto(user.getProfilePhoto());
+
+ }
+ /**
+ * 将用户标识存入缓存中用于后期接口的身份校验
+ * @param token
+ * @param id
+ */
+ private void addTokenToRedis(String token, Integer id){
+ String key = token;
+ int length = token.length();
+ if(length > 32){
+ key = token.substring(token.length() - 32);
}
- if (StringUtils.hasLength(user.getNickname())){
- appUser.setNickname(user.getNickname());
+ //30天有效期
+ redisUtil.setStrValue(key, id.toString(), 2592000);
+ }
+ @Autowired
+ private HWSendSms hwSendSms;
+ @ResponseBody
+ @PostMapping("/base/appUser/getSMSCode")
+ @ApiOperation(value = "获取短信验证码", tags = {"APP-登录注册"})
+ @ApiImplicitParams({
+ @ApiImplicitParam(value = "类型(1:登录,2:注册,3:修改密码,4:忘记密码,5:修改绑定手机号)", name = "type", dataType = "int", required = true),
+ @ApiImplicitParam(value = "电话号码", name = "phone", dataType = "string", required = true)
+ })
+ public ResultUtil getSMSCode(Integer type, String phone) {
+ if (ToolUtil.isEmpty(phone)) {
+ return ResultUtil.paranErr("phone");
}
- appUserService.updateById(appUser);
- return ResultUtil.success();
+ if (ToolUtil.isEmpty(type)) {
+ return ResultUtil.paranErr("type");
+ }
+ try {
+ if (type == 2) {
+ AppUser tAppUser = appUserService.selectOne(new EntityWrapper<AppUser>()
+ .eq("phone", phone).ne("state", 3));
+ if (null != tAppUser) {
+ return ResultUtil.error("账号已存在");
+ }
+ }
+ if (type == 5) {
+ AppUser tAppUser = appUserService.selectOne(new EntityWrapper<AppUser>()
+ .eq("phone", phone).ne("state", 3));
+ if (null != tAppUser) {
+ return ResultUtil.error("账号已存在");
+ }
+ }
+ String numberRandom = UUIDUtil.getNumberRandom(6);
+ String templateCode = "";
+ if (type == 1 || type == 2) {
+ templateCode = "SMS_161275250";
+ }
+ if (type == 3 || type == 4) {
+ templateCode = "SMS_160960014";
+ }
+// aLiSendSms.sendSms(phone, templateCode, "{\"code\":\"" + numberRandom + "\"}");
+ hwSendSms.sendSms(numberRandom,phone);
+ redisUtil.setStrValue(phone, numberRandom, 300);
+ return ResultUtil.success();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return ResultUtil.runErr();
+ }
+ }
+ @ResponseBody
+ @GetMapping("/base/appUser/getAgreement")
+ @ApiOperation(value = "协议", tags = {"协议"})
+ @ApiImplicitParam(value = "类型(1:用户协议,2:隐私协议,3:注销协议,4:关于我们)", name = "type", dataType = "int", required = true)
+ public ResultUtil<String> getAgreement(Integer type){
+ Protocol type1 = protocolService.selectOne(new EntityWrapper<Protocol>()
+ .eq("type", type));
+ return ResultUtil.success(type1.getContent());
+ }
+ @ResponseBody
+ @GetMapping("/base/appUser/getPage")
+ @ApiOperation(value = "启动页/引导页", tags = {"协议"})
+ @ApiImplicitParam(value = "类型(1:启动页,2:引导页(启动页多张图片逗号隔开))", name = "type", dataType = "int", required = true)
+ public ResultUtil<String> getPage(Integer type){
+ Page type1 = pageService.selectOne(new EntityWrapper<Page>()
+ .eq("type", type));
+ if (type1 == null){
+ return ResultUtil.success("");
+ }
+ return ResultUtil.success(type1.getImg());
}
}
--
Gitblit v1.7.1