From 4713b2019cae287cb94ac78b2b9cf22f7965cdc3 Mon Sep 17 00:00:00 2001 From: hupeng Date: Thu, 30 Jul 2020 15:20:27 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=91=E5=AE=9A=E6=89=8B=E6=9C=BA=E5=8F=B7?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=8C=E5=9C=B0=E5=9D=80=E6=96=B0=E5=A2=9E?= =?UTF-8?q?JsonIgnoreProperties=E6=B3=A8=E8=A7=A3=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E9=82=A3=E8=BE=B9=E5=AD=97=E6=AE=B5=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=AF=BC=E8=87=B4=E6=98=A0=E5=B0=84=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rest/controller/WxMaUserController.java | 38 ++++++++----------- .../modules/user/param/AddressParam.java | 2 + 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/yshop-app/src/main/java/co/yixiang/modules/wechat/rest/controller/WxMaUserController.java b/yshop-app/src/main/java/co/yixiang/modules/wechat/rest/controller/WxMaUserController.java index 46dcd216..37b98d5c 100644 --- a/yshop-app/src/main/java/co/yixiang/modules/wechat/rest/controller/WxMaUserController.java +++ b/yshop-app/src/main/java/co/yixiang/modules/wechat/rest/controller/WxMaUserController.java @@ -14,7 +14,9 @@ import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; import cn.hutool.core.util.StrUtil; import co.yixiang.api.ApiResult; +import co.yixiang.api.YshopException; import co.yixiang.common.bean.LocalUser; +import co.yixiang.common.interceptor.AuthCheck; import co.yixiang.exception.BadRequestException; import co.yixiang.exception.ErrorRequestException; import co.yixiang.modules.user.domain.YxUser; @@ -53,52 +55,46 @@ public class WxMaUserController { private final RedisUtils redisUtils; - + @AuthCheck @PostMapping("/binding") @ApiOperation(value = "公众号绑定手机号", notes = "公众号绑定手机号") public ApiResult verify(@Validated @RequestBody BindPhoneParam param) { - Object codeObj = redisUtils.get("code_" + param.getPhone()); if(codeObj == null){ return ApiResult.fail("请先获取验证码"); } String code = codeObj.toString(); - if (!StrUtil.equals(code, param.getCaptcha())) { return ApiResult.fail("验证码错误"); } YxUser user = LocalUser.getUser(); - YxUserQueryVo userQueryVo = userService.getYxUserById(user.getUid()); - if(StrUtil.isNotBlank(userQueryVo.getPhone())){ + if(StrUtil.isNotBlank(user.getPhone())){ return ApiResult.fail("您的账号已经绑定过手机号码"); } - YxUser yxUser = new YxUser(); - yxUser.setPhone(param.getPhone()); - yxUser.setUid(user.getUid()); - userService.updateById(yxUser); + user.setPhone(param.getPhone()); + userService.updateById(user); return ApiResult.ok("绑定成功"); } - + @AuthCheck @PostMapping("/wxapp/binding") @ApiOperation(value = "小程序绑定手机号", notes = "小程序绑定手机号") public ApiResult> phone(@Validated @RequestBody WxPhoneParam param) { YxUser user = LocalUser.getUser(); - YxUserQueryVo userQueryVo = userService.getYxUserById(user.getUid()); - if(StrUtil.isNotBlank(userQueryVo.getPhone())){ - throw new BadRequestException("您的账号已经绑定过手机号码"); + if(StrUtil.isNotBlank(user.getPhone())){ + throw new YshopException("您的账号已经绑定过手机号码"); } //读取redis配置 - String appId = RedisUtil.get(ShopKeyUtils.getWxAppAppId()); - String secret = RedisUtil.get(ShopKeyUtils.getWxAppSecret()); + String appId = redisUtils.getY(ShopKeyUtils.getWxAppAppId()); + String secret = redisUtils.getY(ShopKeyUtils.getWxAppSecret()); if (StrUtil.isBlank(appId) || StrUtil.isBlank(secret)) { - throw new ErrorRequestException("请先配置小程序"); + throw new YshopException("请先配置小程序"); } WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl(); wxMaConfig.setAppid(appId); @@ -114,13 +110,11 @@ public class WxMaUserController { .getPhoneNoInfo(session.getSessionKey(), param.getEncryptedData(), param.getIv()); phone = phoneNoInfo.getPhoneNumber(); - YxUser yxUser = new YxUser(); - yxUser.setPhone(phone); - yxUser.setUid(user.getUid()); - userService.updateById(yxUser); + user.setPhone(phone); + userService.updateById(user); } catch (WxErrorException e) { - throw new BadRequestException(e.getMessage()); - //e.printStackTrace(); + e.printStackTrace(); + throw new YshopException("绑定失败"); } Map map = new LinkedHashMap<>(); map.put("phone",phone); diff --git a/yshop-mall/src/main/java/co/yixiang/modules/user/param/AddressParam.java b/yshop-mall/src/main/java/co/yixiang/modules/user/param/AddressParam.java index 3015969e..8bda51ee 100644 --- a/yshop-mall/src/main/java/co/yixiang/modules/user/param/AddressParam.java +++ b/yshop-mall/src/main/java/co/yixiang/modules/user/param/AddressParam.java @@ -1,5 +1,6 @@ package co.yixiang.modules.user.param; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.Data; import javax.validation.constraints.NotBlank; @@ -11,6 +12,7 @@ import java.io.Serializable; * @Date 2019/10/28 **/ @Data +@JsonIgnoreProperties(ignoreUnknown = true) public class AddressParam implements Serializable { private String id; @NotBlank