Commit 58b82462 authored by Junling Bu's avatar Junling Bu
Browse files

chore: 简化#276的接口

parent d91818e8
......@@ -239,10 +239,12 @@ public class WxAuthController {
String password = JacksonUtil.parseString(body, "password");
String mobile = JacksonUtil.parseString(body, "mobile");
String code = JacksonUtil.parseString(body, "code");
// 如果是小程序注册,则必须非空
// 其他情况,可以为空
String wxCode = JacksonUtil.parseString(body, "wxCode");
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password) || StringUtils.isEmpty(mobile)
|| StringUtils.isEmpty(wxCode) || StringUtils.isEmpty(code)) {
|| StringUtils.isEmpty(code)) {
return ResponseUtil.badArgument();
}
......@@ -264,24 +266,28 @@ public class WxAuthController {
return ResponseUtil.fail(AUTH_CAPTCHA_UNMATCH, "验证码错误");
}
String openId = null;
try {
WxMaJscode2SessionResult result = this.wxService.getUserService().getSessionInfo(wxCode);
openId = result.getOpenid();
} catch (Exception e) {
e.printStackTrace();
return ResponseUtil.fail(AUTH_OPENID_UNACCESS, "openid 获取失败");
}
userList = userService.queryByOpenid(openId);
if (userList.size() > 1) {
return ResponseUtil.serious();
}
if (userList.size() == 1) {
LitemallUser checkUser = userList.get(0);
String checkUsername = checkUser.getUsername();
String checkPassword = checkUser.getPassword();
if (!checkUsername.equals(openId) || !checkPassword.equals(openId)) {
return ResponseUtil.fail(AUTH_OPENID_BINDED, "openid已绑定账号");
String openId = "";
// 非空,则是小程序注册
// 继续验证openid
if(!StringUtils.isEmpty(wxCode)) {
try {
WxMaJscode2SessionResult result = this.wxService.getUserService().getSessionInfo(wxCode);
openId = result.getOpenid();
} catch (Exception e) {
e.printStackTrace();
return ResponseUtil.fail(AUTH_OPENID_UNACCESS, "openid 获取失败");
}
userList = userService.queryByOpenid(openId);
if (userList.size() > 1) {
return ResponseUtil.serious();
}
if (userList.size() == 1) {
LitemallUser checkUser = userList.get(0);
String checkUsername = checkUser.getUsername();
String checkPassword = checkUser.getPassword();
if (!checkUsername.equals(openId) || !checkPassword.equals(openId)) {
return ResponseUtil.fail(AUTH_OPENID_BINDED, "openid已绑定账号");
}
}
}
......@@ -555,65 +561,4 @@ public class WxAuthController {
return ResponseUtil.ok(data);
}
@PostMapping("appregister")
public Object appRegister(@RequestBody String body, HttpServletRequest request) {
String username = JacksonUtil.parseString(body, "username");
String password = JacksonUtil.parseString(body, "password");
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
return ResponseUtil.badArgument();
}
List<LitemallUser> userList = userService.queryByUsername(username);
if (userList.size() > 0) {
return ResponseUtil.fail(AUTH_NAME_REGISTERED, "手机号已注册");
}
if (!RegexUtil.isMobileExact(username)) {
return ResponseUtil.fail(AUTH_INVALID_MOBILE, "手机号格式不正确");
}
String openId = username + "123456789";
userList = userService.queryByOpenid(openId);
if (userList.size() > 1) {
return ResponseUtil.serious();
}
if (userList.size() == 1) {
LitemallUser checkUser = userList.get(0);
String checkUsername = checkUser.getUsername();
String checkPassword = checkUser.getPassword();
if (!checkUsername.equals(openId) || !checkPassword.equals(openId)) {
return ResponseUtil.fail(AUTH_OPENID_BINDED, "openid已绑定账号");
}
}
LitemallUser user = null;
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
String encodedPassword = encoder.encode(password);
user = new LitemallUser();
user.setUsername(username);
user.setPassword(encodedPassword);
user.setMobile(username);
user.setWeixinOpenid(openId);
user.setAvatar("https://yanxuan.nosdn.127.net/80841d741d7fa3073e0ae27bf487339f.jpg?imageView&quality=90&thumbnail=64x64");
user.setNickname(username);
user.setGender((byte) 0);
user.setUserLevel((byte) 0);
user.setStatus((byte) 0);
user.setLastLoginTime(LocalDateTime.now());
user.setLastLoginIp(IpUtil.getIpAddr(request));
userService.add(user);
// 给新用户发送注册优惠券
couponAssignService.assignForRegister(user.getId());
// userInfo
UserInfo userInfo = new UserInfo();
userInfo.setNickName(username);
userInfo.setAvatarUrl(user.getAvatar());
// token
String token = UserTokenManager.generateToken(user.getId());
Map<Object, Object> result = new HashMap<Object, Object>();
result.put("token", token);
result.put("userInfo", userInfo);
return ResponseUtil.ok(result);
}
}
......@@ -66,30 +66,6 @@ public class WxCouponController {
return ResponseUtil.okList(couponList);
}
/**
* app个人优惠券列表
*
* @param userId
* @param page
* @param limit
* @param sort
* @param order
* @return
*/
@GetMapping("allcoupon")
public Object mylist(@LoginUser Integer userId,
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer limit,
@Sort @RequestParam(defaultValue = "add_time") String sort,
@Order @RequestParam(defaultValue = "desc") String order) {
if (userId == null) {
return ResponseUtil.unlogin();
}
List<LitemallCouponUser> couponUserList = couponUserService.queryList(userId, null, null, page, limit, sort, order);
List<CouponVo> couponVoList = change(couponUserList);
return ResponseUtil.okList(couponVoList, couponUserList);
}
/**
* 个人优惠券列表
*
......@@ -103,7 +79,7 @@ public class WxCouponController {
*/
@GetMapping("mylist")
public Object mylist(@LoginUser Integer userId,
@NotNull Short status,
Short status,
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer limit,
@Sort @RequestParam(defaultValue = "add_time") String sort,
......
Supports Markdown
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