绑定手机号修复,地址新增JsonIgnoreProperties注解防止微信那边字段新增导致映射的问题
This commit is contained in:
@ -14,7 +14,9 @@ import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
|||||||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import co.yixiang.api.ApiResult;
|
import co.yixiang.api.ApiResult;
|
||||||
|
import co.yixiang.api.YshopException;
|
||||||
import co.yixiang.common.bean.LocalUser;
|
import co.yixiang.common.bean.LocalUser;
|
||||||
|
import co.yixiang.common.interceptor.AuthCheck;
|
||||||
import co.yixiang.exception.BadRequestException;
|
import co.yixiang.exception.BadRequestException;
|
||||||
import co.yixiang.exception.ErrorRequestException;
|
import co.yixiang.exception.ErrorRequestException;
|
||||||
import co.yixiang.modules.user.domain.YxUser;
|
import co.yixiang.modules.user.domain.YxUser;
|
||||||
@ -53,52 +55,46 @@ public class WxMaUserController {
|
|||||||
private final RedisUtils redisUtils;
|
private final RedisUtils redisUtils;
|
||||||
|
|
||||||
|
|
||||||
|
@AuthCheck
|
||||||
@PostMapping("/binding")
|
@PostMapping("/binding")
|
||||||
@ApiOperation(value = "公众号绑定手机号", notes = "公众号绑定手机号")
|
@ApiOperation(value = "公众号绑定手机号", notes = "公众号绑定手机号")
|
||||||
public ApiResult<String> verify(@Validated @RequestBody BindPhoneParam param) {
|
public ApiResult<String> verify(@Validated @RequestBody BindPhoneParam param) {
|
||||||
|
|
||||||
Object codeObj = redisUtils.get("code_" + param.getPhone());
|
Object codeObj = redisUtils.get("code_" + param.getPhone());
|
||||||
if(codeObj == null){
|
if(codeObj == null){
|
||||||
return ApiResult.fail("请先获取验证码");
|
return ApiResult.fail("请先获取验证码");
|
||||||
}
|
}
|
||||||
String code = codeObj.toString();
|
String code = codeObj.toString();
|
||||||
|
|
||||||
|
|
||||||
if (!StrUtil.equals(code, param.getCaptcha())) {
|
if (!StrUtil.equals(code, param.getCaptcha())) {
|
||||||
return ApiResult.fail("验证码错误");
|
return ApiResult.fail("验证码错误");
|
||||||
}
|
}
|
||||||
YxUser user = LocalUser.getUser();
|
YxUser user = LocalUser.getUser();
|
||||||
YxUserQueryVo userQueryVo = userService.getYxUserById(user.getUid());
|
if(StrUtil.isNotBlank(user.getPhone())){
|
||||||
if(StrUtil.isNotBlank(userQueryVo.getPhone())){
|
|
||||||
return ApiResult.fail("您的账号已经绑定过手机号码");
|
return ApiResult.fail("您的账号已经绑定过手机号码");
|
||||||
}
|
}
|
||||||
|
|
||||||
YxUser yxUser = new YxUser();
|
user.setPhone(param.getPhone());
|
||||||
yxUser.setPhone(param.getPhone());
|
userService.updateById(user);
|
||||||
yxUser.setUid(user.getUid());
|
|
||||||
userService.updateById(yxUser);
|
|
||||||
|
|
||||||
return ApiResult.ok("绑定成功");
|
return ApiResult.ok("绑定成功");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@AuthCheck
|
||||||
@PostMapping("/wxapp/binding")
|
@PostMapping("/wxapp/binding")
|
||||||
@ApiOperation(value = "小程序绑定手机号", notes = "小程序绑定手机号")
|
@ApiOperation(value = "小程序绑定手机号", notes = "小程序绑定手机号")
|
||||||
public ApiResult<Map<String,Object>> phone(@Validated @RequestBody WxPhoneParam param) {
|
public ApiResult<Map<String,Object>> phone(@Validated @RequestBody WxPhoneParam param) {
|
||||||
YxUser user = LocalUser.getUser();
|
YxUser user = LocalUser.getUser();
|
||||||
YxUserQueryVo userQueryVo = userService.getYxUserById(user.getUid());
|
if(StrUtil.isNotBlank(user.getPhone())){
|
||||||
if(StrUtil.isNotBlank(userQueryVo.getPhone())){
|
throw new YshopException("您的账号已经绑定过手机号码");
|
||||||
throw new BadRequestException("您的账号已经绑定过手机号码");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//读取redis配置
|
//读取redis配置
|
||||||
String appId = RedisUtil.get(ShopKeyUtils.getWxAppAppId());
|
String appId = redisUtils.getY(ShopKeyUtils.getWxAppAppId());
|
||||||
String secret = RedisUtil.get(ShopKeyUtils.getWxAppSecret());
|
String secret = redisUtils.getY(ShopKeyUtils.getWxAppSecret());
|
||||||
if (StrUtil.isBlank(appId) || StrUtil.isBlank(secret)) {
|
if (StrUtil.isBlank(appId) || StrUtil.isBlank(secret)) {
|
||||||
throw new ErrorRequestException("请先配置小程序");
|
throw new YshopException("请先配置小程序");
|
||||||
}
|
}
|
||||||
WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
|
WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
|
||||||
wxMaConfig.setAppid(appId);
|
wxMaConfig.setAppid(appId);
|
||||||
@ -114,13 +110,11 @@ public class WxMaUserController {
|
|||||||
.getPhoneNoInfo(session.getSessionKey(), param.getEncryptedData(), param.getIv());
|
.getPhoneNoInfo(session.getSessionKey(), param.getEncryptedData(), param.getIv());
|
||||||
|
|
||||||
phone = phoneNoInfo.getPhoneNumber();
|
phone = phoneNoInfo.getPhoneNumber();
|
||||||
YxUser yxUser = new YxUser();
|
user.setPhone(phone);
|
||||||
yxUser.setPhone(phone);
|
userService.updateById(user);
|
||||||
yxUser.setUid(user.getUid());
|
|
||||||
userService.updateById(yxUser);
|
|
||||||
} catch (WxErrorException e) {
|
} catch (WxErrorException e) {
|
||||||
throw new BadRequestException(e.getMessage());
|
e.printStackTrace();
|
||||||
//e.printStackTrace();
|
throw new YshopException("绑定失败");
|
||||||
}
|
}
|
||||||
Map<String,Object> map = new LinkedHashMap<>();
|
Map<String,Object> map = new LinkedHashMap<>();
|
||||||
map.put("phone",phone);
|
map.put("phone",phone);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package co.yixiang.modules.user.param;
|
package co.yixiang.modules.user.param;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
@ -11,6 +12,7 @@ import java.io.Serializable;
|
|||||||
* @Date 2019/10/28
|
* @Date 2019/10/28
|
||||||
**/
|
**/
|
||||||
@Data
|
@Data
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class AddressParam implements Serializable {
|
public class AddressParam implements Serializable {
|
||||||
private String id;
|
private String id;
|
||||||
@NotBlank
|
@NotBlank
|
||||||
|
Reference in New Issue
Block a user