Commit 0747b6a3 authored by muhong's avatar muhong

新增修改 小程序登录和收藏册接口

parent cad17097
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<result column="user_id" jdbcType="BIGINT" property="userId" /> <result column="user_id" jdbcType="BIGINT" property="userId" />
<result column="title" jdbcType="VARCHAR" property="title" /> <result column="title" jdbcType="VARCHAR" property="title" />
<result column="description" jdbcType="VARCHAR" property="description" /> <result column="description" jdbcType="VARCHAR" property="description" />
<result column="sort" jdbcType="INTEGER" property="sort" />
<result column="add_time" jdbcType="TIMESTAMP" property="addTime" /> <result column="add_time" jdbcType="TIMESTAMP" property="addTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="deleted" jdbcType="BIT" property="deleted" /> <result column="deleted" jdbcType="BIT" property="deleted" />
...@@ -72,7 +73,7 @@ ...@@ -72,7 +73,7 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, user_id, title, description, add_time, update_time, deleted id, user_id, title, description, sort, add_time, update_time, deleted
</sql> </sql>
<sql id="Blob_Column_List"> <sql id="Blob_Column_List">
images images
...@@ -127,7 +128,7 @@ ...@@ -127,7 +128,7 @@
</foreach> </foreach>
</when> </when>
<otherwise> <otherwise>
id, user_id, title, description, add_time, update_time, deleted, images id, user_id, title, description, sort, add_time, update_time, deleted, images
</otherwise> </otherwise>
</choose> </choose>
from favorites from favorites
...@@ -182,7 +183,7 @@ ...@@ -182,7 +183,7 @@
</foreach> </foreach>
</when> </when>
<otherwise> <otherwise>
id, user_id, title, description, add_time, update_time, deleted, images id, user_id, title, description, sort, add_time, update_time, deleted, images
</otherwise> </otherwise>
</choose> </choose>
from favorites from favorites
...@@ -203,11 +204,11 @@ ...@@ -203,11 +204,11 @@
SELECT LAST_INSERT_ID() SELECT LAST_INSERT_ID()
</selectKey> </selectKey>
insert into favorites (user_id, title, description, insert into favorites (user_id, title, description,
add_time, update_time, deleted, sort, add_time, update_time,
images) deleted, images)
values (#{userId,jdbcType=BIGINT}, #{title,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, values (#{userId,jdbcType=BIGINT}, #{title,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
#{addTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT}, #{sort,jdbcType=INTEGER}, #{addTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
#{images,jdbcType=LONGVARCHAR}) #{deleted,jdbcType=BIT}, #{images,jdbcType=LONGVARCHAR})
</insert> </insert>
<insert id="insertSelective" parameterType="com.wwdz.ch.db.domain.Favorites"> <insert id="insertSelective" parameterType="com.wwdz.ch.db.domain.Favorites">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long"> <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
...@@ -224,6 +225,9 @@ ...@@ -224,6 +225,9 @@
<if test="description != null"> <if test="description != null">
description, description,
</if> </if>
<if test="sort != null">
sort,
</if>
<if test="addTime != null"> <if test="addTime != null">
add_time, add_time,
</if> </if>
...@@ -247,6 +251,9 @@ ...@@ -247,6 +251,9 @@
<if test="description != null"> <if test="description != null">
#{description,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
</if> </if>
<if test="sort != null">
#{sort,jdbcType=INTEGER},
</if>
<if test="addTime != null"> <if test="addTime != null">
#{addTime,jdbcType=TIMESTAMP}, #{addTime,jdbcType=TIMESTAMP},
</if> </if>
...@@ -282,6 +289,9 @@ ...@@ -282,6 +289,9 @@
<if test="record.description != null"> <if test="record.description != null">
description = #{record.description,jdbcType=VARCHAR}, description = #{record.description,jdbcType=VARCHAR},
</if> </if>
<if test="record.sort != null">
sort = #{record.sort,jdbcType=INTEGER},
</if>
<if test="record.addTime != null"> <if test="record.addTime != null">
add_time = #{record.addTime,jdbcType=TIMESTAMP}, add_time = #{record.addTime,jdbcType=TIMESTAMP},
</if> </if>
...@@ -305,6 +315,7 @@ ...@@ -305,6 +315,7 @@
user_id = #{record.userId,jdbcType=BIGINT}, user_id = #{record.userId,jdbcType=BIGINT},
title = #{record.title,jdbcType=VARCHAR}, title = #{record.title,jdbcType=VARCHAR},
description = #{record.description,jdbcType=VARCHAR}, description = #{record.description,jdbcType=VARCHAR},
sort = #{record.sort,jdbcType=INTEGER},
add_time = #{record.addTime,jdbcType=TIMESTAMP}, add_time = #{record.addTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,jdbcType=TIMESTAMP}, update_time = #{record.updateTime,jdbcType=TIMESTAMP},
deleted = #{record.deleted,jdbcType=BIT}, deleted = #{record.deleted,jdbcType=BIT},
...@@ -319,6 +330,7 @@ ...@@ -319,6 +330,7 @@
user_id = #{record.userId,jdbcType=BIGINT}, user_id = #{record.userId,jdbcType=BIGINT},
title = #{record.title,jdbcType=VARCHAR}, title = #{record.title,jdbcType=VARCHAR},
description = #{record.description,jdbcType=VARCHAR}, description = #{record.description,jdbcType=VARCHAR},
sort = #{record.sort,jdbcType=INTEGER},
add_time = #{record.addTime,jdbcType=TIMESTAMP}, add_time = #{record.addTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,jdbcType=TIMESTAMP}, update_time = #{record.updateTime,jdbcType=TIMESTAMP},
deleted = #{record.deleted,jdbcType=BIT} deleted = #{record.deleted,jdbcType=BIT}
...@@ -338,6 +350,9 @@ ...@@ -338,6 +350,9 @@
<if test="description != null"> <if test="description != null">
description = #{description,jdbcType=VARCHAR}, description = #{description,jdbcType=VARCHAR},
</if> </if>
<if test="sort != null">
sort = #{sort,jdbcType=INTEGER},
</if>
<if test="addTime != null"> <if test="addTime != null">
add_time = #{addTime,jdbcType=TIMESTAMP}, add_time = #{addTime,jdbcType=TIMESTAMP},
</if> </if>
...@@ -358,6 +373,7 @@ ...@@ -358,6 +373,7 @@
set user_id = #{userId,jdbcType=BIGINT}, set user_id = #{userId,jdbcType=BIGINT},
title = #{title,jdbcType=VARCHAR}, title = #{title,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR}, description = #{description,jdbcType=VARCHAR},
sort = #{sort,jdbcType=INTEGER},
add_time = #{addTime,jdbcType=TIMESTAMP}, add_time = #{addTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
deleted = #{deleted,jdbcType=BIT}, deleted = #{deleted,jdbcType=BIT},
...@@ -369,6 +385,7 @@ ...@@ -369,6 +385,7 @@
set user_id = #{userId,jdbcType=BIGINT}, set user_id = #{userId,jdbcType=BIGINT},
title = #{title,jdbcType=VARCHAR}, title = #{title,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR}, description = #{description,jdbcType=VARCHAR},
sort = #{sort,jdbcType=INTEGER},
add_time = #{addTime,jdbcType=TIMESTAMP}, add_time = #{addTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
deleted = #{deleted,jdbcType=BIT} deleted = #{deleted,jdbcType=BIT}
...@@ -427,7 +444,7 @@ ...@@ -427,7 +444,7 @@
</foreach> </foreach>
</when> </when>
<otherwise> <otherwise>
id, user_id, title, description, add_time, update_time, deleted, images id, user_id, title, description, sort, add_time, update_time, deleted, images
</otherwise> </otherwise>
</choose> </choose>
from favorites from favorites
......
package com.wwdz.ch.wx.entity.request; package com.wwdz.ch.wx.entity.request;
import com.github.pagehelper.Page;
import com.xxdxxs.entity.Entity; import com.xxdxxs.entity.Entity;
import com.xxdxxs.support.Delete;
import com.xxdxxs.support.Insert;
import com.xxdxxs.support.Select;
import com.xxdxxs.support.Update;
import lombok.Data; import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
@Data @Data
public class FavoritesRequestDto implements Entity { public class FavoritesRequestDto implements Entity {
// 收藏册id // 收藏册id
@NotNull(groups = {Update.class, Select.class}, message = "id不能为空")
private Long id; private Long id;
// 收藏册标题 // 收藏册标题
@NotBlank(groups = {Insert.class, Update.class}, message = "标题不能为空")
@Length(groups = {Insert.class, Update.class}, max = 20, message = "标题字数不能超过20个字符")
private String title; private String title;
// 收藏册描述 // 收藏册描述
@Length(groups = {Insert.class, Update.class}, max = 200, message = "描述字数不能超过200个字符")
private String description; private String description;
// 收藏册图片,用;分隔 // 收藏册图片,用;分隔
private String images; private String images;
// 用户id // 用户id
@NotNull(groups = {Insert.class, Update.class, Page.class, Delete.class}, message = "用户id不能为空")
private Long userId; private Long userId;
// 当前页 // 当前页
@NotNull(groups = Page.class, message = "当前页不能为空")
private Integer page; private Integer page;
// 页面大小 // 页面大小
@NotNull(groups = Page.class, message = "页面大小不能为空")
private Integer size; private Integer size;
// 收藏册id列表 // 收藏册id列表
......
...@@ -18,4 +18,6 @@ public class UserRequestDto implements Entity { ...@@ -18,4 +18,6 @@ public class UserRequestDto implements Entity {
private String profile; private String profile;
private String background; private String background;
private String smsType; private String smsType;
private String encryptedData;
private String iv;
} }
...@@ -2,7 +2,9 @@ package com.wwdz.ch.wx.impl; ...@@ -2,7 +2,9 @@ package com.wwdz.ch.wx.impl;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.wwdz.ch.core.captcha.CaptchaCodeManager;
import com.wwdz.ch.core.notify.NotifyService; import com.wwdz.ch.core.notify.NotifyService;
import com.wwdz.ch.core.notify.NotifyType; import com.wwdz.ch.core.notify.NotifyType;
import com.wwdz.ch.core.notify.SmsResult; import com.wwdz.ch.core.notify.SmsResult;
...@@ -15,10 +17,8 @@ import com.wwdz.ch.db.domain.User; ...@@ -15,10 +17,8 @@ import com.wwdz.ch.db.domain.User;
import com.wwdz.ch.wx.constant.CacheCodeEnum; import com.wwdz.ch.wx.constant.CacheCodeEnum;
import com.wwdz.ch.wx.dao.UserInfo; import com.wwdz.ch.wx.dao.UserInfo;
import com.wwdz.ch.wx.dao.UserToken; import com.wwdz.ch.wx.dao.UserToken;
import com.wwdz.ch.wx.dao.WxLoginInfo;
import com.wwdz.ch.wx.entity.request.FavoritesRequestDto; import com.wwdz.ch.wx.entity.request.FavoritesRequestDto;
import com.wwdz.ch.wx.entity.request.UserRequestDto; import com.wwdz.ch.wx.entity.request.UserRequestDto;
import com.wwdz.ch.core.captcha.CaptchaCodeManager;
import com.wwdz.ch.wx.service.FavoritesService; import com.wwdz.ch.wx.service.FavoritesService;
import com.wwdz.ch.wx.service.UserService; import com.wwdz.ch.wx.service.UserService;
import com.wwdz.ch.wx.service.UserTokenManager; import com.wwdz.ch.wx.service.UserTokenManager;
...@@ -59,15 +59,10 @@ public class UserServiceImpl implements UserService { ...@@ -59,15 +59,10 @@ public class UserServiceImpl implements UserService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public Result loginByWx(WxLoginInfo wxLoginInfo, HttpServletRequest request) { public Result loginByWx(UserRequestDto dto, HttpServletRequest request) {
try { try {
String code = wxLoginInfo.getCode(); String code = dto.getCode();
UserInfo userInfo = wxLoginInfo.getUserInfo(); // 获取微信用户的sessionKey和openId
if (StringUtils.isBlank(code) || Objects.isNull(userInfo)) {
return Result.failed(401, "参数不对");
}
Long shareUserId = wxLoginInfo.getShareUserId();
String sessionKey = null; String sessionKey = null;
String openId = null; String openId = null;
try { try {
...@@ -78,31 +73,42 @@ public class UserServiceImpl implements UserService { ...@@ -78,31 +73,42 @@ public class UserServiceImpl implements UserService {
logger.error("微信登录,调用官方接口失败:{}", code, e); logger.error("微信登录,调用官方接口失败:{}", code, e);
return Result.failed("微信登录失败,获取openid失败"); return Result.failed("微信登录失败,获取openid失败");
} }
if (sessionKey == null || openId == null) { if (sessionKey == null || openId == null) {
logger.error("微信登录,调用官方接口失败:{}", code); logger.error("微信登录,调用官方接口失败:{}", code);
return Result.failed("微信登录失败,获取openid失败"); return Result.failed("微信登录失败,获取openid失败");
} }
// 获取用户微信绑定的手机号
String mobile = "";
if (StringUtils.isNotBlank(dto.getEncryptedData()) && StringUtils.isNotBlank(dto.getIv())) {
try {
WxMaPhoneNumberInfo wxMaPhoneNumberInfo = wxMaService.getUserService().getPhoneNoInfo(sessionKey, dto.getEncryptedData(), dto.getIv());
mobile = wxMaPhoneNumberInfo.getPhoneNumber();
} catch (Exception e) {
logger.error("微信登录,调用官方获取手机号接口失败:{}", code, e);
}
}
User user = userDao.queryByOid(openId); User user = userDao.queryByOid(openId);
if (user == null) { if (user == null) {
user = new User(); user = new User();
user.setUsername(openId); user.setUsername(openId);
user.setPassword(openId); user.setPassword(openId);
user.setWeixinOpenid(openId); user.setWeixinOpenid(openId);
user.setAvatar(userInfo.getAvatarUrl()); user.setAvatar(dto.getAvatarUrl());
user.setNickname("微信用户" + StringUtil.generateRandomString(10)); user.setNickname("微信用户" + StringUtil.generateRandomString(10));
user.setGender((byte) 0); user.setGender((byte) 0);
user.setUserLevel((byte) 0); user.setUserLevel((byte) 0);
user.setStatus((byte) 0); user.setStatus((byte) 0);
user.setLastLoginTime(new Date()); user.setLastLoginTime(new Date());
user.setLastLoginIp(IpUtil.client(request)); user.setLastLoginIp(IpUtil.client(request));
user.setShareUserId(shareUserId); user.setShareUserId(dto.getShareUserId());
user.setMobile(mobile);
userDao.insert(user); userDao.insert(user);
FavoritesRequestDto dto = new FavoritesRequestDto(); FavoritesRequestDto favoritesRequestDto = new FavoritesRequestDto();
dto.setUserId(user.getId()); favoritesRequestDto.setUserId(user.getId());
favoritesService.addDefault(dto); favoritesService.addDefault(favoritesRequestDto);
} else { } else {
user.setLastLoginTime(new Date()); user.setLastLoginTime(new Date());
user.setLastLoginIp(IpUtil.client(request)); user.setLastLoginIp(IpUtil.client(request));
...@@ -121,6 +127,7 @@ public class UserServiceImpl implements UserService { ...@@ -121,6 +127,7 @@ public class UserServiceImpl implements UserService {
} }
userToken.setSessionKey(sessionKey); userToken.setSessionKey(sessionKey);
UserInfo userInfo = new UserInfo();
Map<Object, Object> result = new HashMap<Object, Object>(); Map<Object, Object> result = new HashMap<Object, Object>();
result.put("token", userToken.getToken()); result.put("token", userToken.getToken());
result.put("tokenExpire", userToken.getExpireTime().toString()); result.put("tokenExpire", userToken.getExpireTime().toString());
......
package com.wwdz.ch.wx.service; package com.wwdz.ch.wx.service;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.wx.dao.WxLoginInfo;
import com.wwdz.ch.wx.entity.request.UserRequestDto; import com.wwdz.ch.wx.entity.request.UserRequestDto;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
public interface UserService { public interface UserService {
Result loginByWx(WxLoginInfo wxLoginInfo, HttpServletRequest request); Result loginByWx(UserRequestDto dto, HttpServletRequest request);
Result regCaptcha(UserRequestDto dto); Result regCaptcha(UserRequestDto dto);
......
...@@ -2,15 +2,14 @@ package com.wwdz.ch.wx.web; ...@@ -2,15 +2,14 @@ package com.wwdz.ch.wx.web;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.wx.entity.request.ItemRequestDto;
import com.wwdz.ch.wx.entity.request.FavoritesRequestDto; import com.wwdz.ch.wx.entity.request.FavoritesRequestDto;
import com.wwdz.ch.wx.entity.request.ItemRequestDto;
import com.wwdz.ch.wx.service.FavoritesService; import com.wwdz.ch.wx.service.FavoritesService;
import com.xxdxxs.support.Delete; import com.xxdxxs.support.Delete;
import com.xxdxxs.support.Insert;
import com.xxdxxs.support.Select; import com.xxdxxs.support.Select;
import com.xxdxxs.support.Update;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -38,13 +37,40 @@ public class WxFavoritesController { ...@@ -38,13 +37,40 @@ public class WxFavoritesController {
@ApiOperation(value = "新增") @ApiOperation(value = "新增")
@PostMapping("/add") @PostMapping("/add")
public Result add(@RequestBody @Validated(Insert.class)FavoritesRequestDto dto) { public Result add(@RequestBody FavoritesRequestDto dto) {
if (Objects.isNull(dto.getUserId())) {
return Result.failed("用户id不能为空");
}
if (StringUtils.isBlank(dto.getTitle())) {
return Result.failed("标题不能为空");
}
if (dto.getTitle().length() > 20) {
return Result.failed("标题的字数不能大于20字");
}
if (StringUtils.isNotBlank(dto.getDescription()) && dto.getDescription().length() > 200) {
return Result.failed("描述的字数不能大于200字");
}
return favoritesService.add(dto); return favoritesService.add(dto);
} }
@ApiOperation(value = "修改") @ApiOperation(value = "修改")
@PostMapping("/update") @PostMapping("/update")
public Result update(@RequestBody @Validated(Update.class)FavoritesRequestDto dto) { public Result update(@RequestBody FavoritesRequestDto dto) {
if (Objects.isNull(dto.getId())) {
return Result.failed("id不能为空");
}
if (Objects.isNull(dto.getUserId())) {
return Result.failed("用户id不能为空");
}
if (StringUtils.isBlank(dto.getTitle())) {
return Result.failed("标题不能为空");
}
if (dto.getTitle().length() > 20) {
return Result.failed("标题的字数不能大于20字");
}
if (StringUtils.isNotBlank(dto.getDescription()) && dto.getDescription().length() > 200) {
return Result.failed("描述的字数不能大于200字");
}
return favoritesService.update(dto); return favoritesService.update(dto);
} }
......
...@@ -8,7 +8,6 @@ import com.wwdz.ch.db.domain.UserAccountObsolete; ...@@ -8,7 +8,6 @@ import com.wwdz.ch.db.domain.UserAccountObsolete;
import com.wwdz.ch.db.service.DtsAccountService; import com.wwdz.ch.db.service.DtsAccountService;
import com.wwdz.ch.wx.annotation.LoginUser; import com.wwdz.ch.wx.annotation.LoginUser;
import com.wwdz.ch.wx.constant.CacheCodeEnum; import com.wwdz.ch.wx.constant.CacheCodeEnum;
import com.wwdz.ch.wx.dao.WxLoginInfo;
import com.wwdz.ch.wx.entity.request.UserRequestDto; import com.wwdz.ch.wx.entity.request.UserRequestDto;
import com.wwdz.ch.wx.service.UserService; import com.wwdz.ch.wx.service.UserService;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -91,9 +90,9 @@ public class WxUserController { ...@@ -91,9 +90,9 @@ public class WxUserController {
@ApiOperation(value = "微信登录") @ApiOperation(value = "微信登录")
@PostMapping("/loginByWx") @PostMapping("/loginByWx")
public Result loginByWx(@RequestBody WxLoginInfo wxLoginInfo, HttpServletRequest request) { public Result loginByWx(@RequestBody UserRequestDto dto, HttpServletRequest request) {
logger.info("【请求开始】微信登录,请求参数,wxLoginInfo:{}", JSONObject.toJSONString(wxLoginInfo)); logger.info("【请求开始】微信登录,请求参数,wxLoginInfo:{}", JSONObject.toJSONString(dto));
return userService.loginByWx(wxLoginInfo, request); return userService.loginByWx(dto, request);
} }
@ApiOperation(value = "登录手机验证码") @ApiOperation(value = "登录手机验证码")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment