yshop1.9.5,H5新增手机号绑定,账户信息管理等功能修复其他bug,明细请登陆演示后台查看
This commit is contained in:
@ -410,6 +410,7 @@ public class AuthController {
|
|||||||
public ApiResult<String> verify(@Validated @RequestBody VerityParam param) {
|
public ApiResult<String> verify(@Validated @RequestBody VerityParam param) {
|
||||||
Boolean isTest = true;
|
Boolean isTest = true;
|
||||||
YxUser yxUser = userService.findByName(param.getPhone());
|
YxUser yxUser = userService.findByName(param.getPhone());
|
||||||
|
if(param.getType() == null) param.setType("bind");
|
||||||
if (param.getType().equals("register") && ObjectUtil.isNotNull(yxUser)) {
|
if (param.getType().equals("register") && ObjectUtil.isNotNull(yxUser)) {
|
||||||
return ApiResult.fail("手机号已注册");
|
return ApiResult.fail("手机号已注册");
|
||||||
}
|
}
|
||||||
@ -452,10 +453,12 @@ public class AuthController {
|
|||||||
@PostMapping("/register")
|
@PostMapping("/register")
|
||||||
@ApiOperation(value = "H5注册新用户", notes = "H5注册新用户")
|
@ApiOperation(value = "H5注册新用户", notes = "H5注册新用户")
|
||||||
public ApiResult<String> register(@Validated @RequestBody RegParam param) {
|
public ApiResult<String> register(@Validated @RequestBody RegParam param) {
|
||||||
String code = redisUtils.get("code_" + param.getAccount()).toString();
|
|
||||||
if (StrUtil.isEmpty(code)) {
|
Object codeObj = redisUtils.get("code_" + param.getAccount());
|
||||||
|
if(codeObj == null){
|
||||||
return ApiResult.fail("请先获取验证码");
|
return ApiResult.fail("请先获取验证码");
|
||||||
}
|
}
|
||||||
|
String code = codeObj.toString();
|
||||||
|
|
||||||
if (!StrUtil.equals(code, param.getCaptcha())) {
|
if (!StrUtil.equals(code, param.getCaptcha())) {
|
||||||
return ApiResult.fail("验证码错误");
|
return ApiResult.fail("验证码错误");
|
||||||
|
@ -7,7 +7,7 @@ import javax.validation.constraints.NotBlank;
|
|||||||
/**
|
/**
|
||||||
* @ClassName LoginParam
|
* @ClassName LoginParam
|
||||||
* @Author hupeng <610796224@qq.com>
|
* @Author hupeng <610796224@qq.com>
|
||||||
* @Date 2020/02/15
|
* @Date 2020/01/15
|
||||||
**/
|
**/
|
||||||
@Data
|
@Data
|
||||||
public class LoginParam {
|
public class LoginParam {
|
||||||
|
@ -14,6 +14,5 @@ public class VerityParam {
|
|||||||
@NotBlank(message = "手机号必填")
|
@NotBlank(message = "手机号必填")
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
private String type;
|
private String type;
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,12 @@ import co.yixiang.common.web.controller.BaseController;
|
|||||||
import co.yixiang.modules.order.service.YxStoreOrderService;
|
import co.yixiang.modules.order.service.YxStoreOrderService;
|
||||||
import co.yixiang.modules.shop.service.YxStoreProductRelationService;
|
import co.yixiang.modules.shop.service.YxStoreProductRelationService;
|
||||||
import co.yixiang.modules.shop.service.YxSystemGroupDataService;
|
import co.yixiang.modules.shop.service.YxSystemGroupDataService;
|
||||||
|
import co.yixiang.modules.user.entity.YxUser;
|
||||||
import co.yixiang.modules.user.service.YxSystemUserLevelService;
|
import co.yixiang.modules.user.service.YxSystemUserLevelService;
|
||||||
import co.yixiang.modules.user.service.YxUserBillService;
|
import co.yixiang.modules.user.service.YxUserBillService;
|
||||||
import co.yixiang.modules.user.service.YxUserService;
|
import co.yixiang.modules.user.service.YxUserService;
|
||||||
import co.yixiang.modules.user.service.YxUserSignService;
|
import co.yixiang.modules.user.service.YxUserSignService;
|
||||||
|
import co.yixiang.modules.user.web.param.UserEditParam;
|
||||||
import co.yixiang.modules.user.web.vo.YxSystemUserLevelQueryVo;
|
import co.yixiang.modules.user.web.vo.YxSystemUserLevelQueryVo;
|
||||||
import co.yixiang.modules.user.web.vo.YxUserQueryVo;
|
import co.yixiang.modules.user.web.vo.YxUserQueryVo;
|
||||||
import co.yixiang.utils.SecurityUtils;
|
import co.yixiang.utils.SecurityUtils;
|
||||||
@ -21,6 +23,7 @@ import io.swagger.annotations.ApiOperation;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@ -219,6 +222,22 @@ public class UserController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/user/edit")
|
||||||
|
@ApiOperation(value = "用户修改信息",notes = "用修改信息")
|
||||||
|
public ApiResult<Object> edit(@Validated @RequestBody UserEditParam param){
|
||||||
|
int uid = SecurityUtils.getUserId().intValue();
|
||||||
|
|
||||||
|
YxUser yxUser = new YxUser();
|
||||||
|
yxUser.setAvatar(param.getAvatar());
|
||||||
|
yxUser.setNickname(param.getNickname());
|
||||||
|
yxUser.setUid(uid);
|
||||||
|
|
||||||
|
yxUserService.updateById(yxUser);
|
||||||
|
|
||||||
|
return ApiResult.ok("修改成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package co.yixiang.modules.user.web.param;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName UserEditParam
|
||||||
|
* @Author hupeng <610796224@qq.com>
|
||||||
|
* @Date 2020/02/07
|
||||||
|
**/
|
||||||
|
@Data
|
||||||
|
public class UserEditParam implements Serializable {
|
||||||
|
@NotBlank(message = "请上传头像")
|
||||||
|
private String avatar;
|
||||||
|
@NotBlank(message = "请填写昵称")
|
||||||
|
private String nickname;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,47 +1,129 @@
|
|||||||
package co.yixiang.modules.wechat.web.controller;
|
package co.yixiang.modules.wechat.web.controller;
|
||||||
|
|
||||||
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.WxMaPhoneNumberInfo;
|
||||||
|
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import co.yixiang.annotation.AnonymousAccess;
|
||||||
|
import co.yixiang.common.api.ApiResult;
|
||||||
|
import co.yixiang.exception.ErrorRequestException;
|
||||||
|
import co.yixiang.modules.notify.NotifyType;
|
||||||
|
import co.yixiang.modules.notify.SmsResult;
|
||||||
|
import co.yixiang.modules.security.rest.param.VerityParam;
|
||||||
|
import co.yixiang.modules.user.entity.YxUser;
|
||||||
import co.yixiang.modules.user.service.YxUserService;
|
import co.yixiang.modules.user.service.YxUserService;
|
||||||
import co.yixiang.modules.user.service.YxWechatUserService;
|
import co.yixiang.modules.user.service.YxWechatUserService;
|
||||||
|
import co.yixiang.modules.user.web.vo.YxUserQueryVo;
|
||||||
|
import co.yixiang.modules.wechat.web.param.BindPhoneParam;
|
||||||
|
import co.yixiang.modules.wechat.web.param.WxPhoneParam;
|
||||||
|
import co.yixiang.mp.utils.JsonUtils;
|
||||||
|
import co.yixiang.utils.RedisUtil;
|
||||||
|
import co.yixiang.utils.RedisUtils;
|
||||||
|
import co.yixiang.utils.SecurityUtils;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.aliyuncs.CommonResponse;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信小程序用户接口
|
* @author hupeng
|
||||||
*
|
* @date 2020/02/07
|
||||||
* @author xuwenbo
|
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||||
@Api(value = "微信小程序", tags = "微信小程序", description = "微信小程序")
|
@Api(value = "微信其他", tags = "微信其他", description = "微信其他")
|
||||||
public class WxMaUserController {
|
public class WxMaUserController {
|
||||||
|
|
||||||
private final WxMaService wxMaService;
|
private final WxMaService wxMaService;
|
||||||
private final YxWechatUserService wechatUserService;
|
private final YxWechatUserService wechatUserService;
|
||||||
private final YxUserService userService;
|
private final YxUserService userService;
|
||||||
|
private final RedisUtils redisUtils;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// /**
|
@PostMapping("/binding")
|
||||||
// * <pre>
|
@ApiOperation(value = "公众号绑定手机号", notes = "公众号绑定手机号")
|
||||||
// * 获取用户绑定手机号信息
|
public ApiResult<String> verify(@Validated @RequestBody BindPhoneParam param) {
|
||||||
// * </pre>
|
|
||||||
// */
|
Object codeObj = redisUtils.get("code_" + param.getPhone());
|
||||||
// @GetMapping("/phone")
|
if(codeObj == null){
|
||||||
// public String phone(String sessionKey, String signature,
|
return ApiResult.fail("请先获取验证码");
|
||||||
// String rawData, String encryptedData, String iv) {
|
}
|
||||||
//
|
String code = codeObj.toString();
|
||||||
// // 用户信息校验
|
|
||||||
// if (!wxMaService.getUserService().checkUserInfo(sessionKey, rawData, signature)) {
|
|
||||||
// return "user check failed";
|
if (!StrUtil.equals(code, param.getCaptcha())) {
|
||||||
// }
|
return ApiResult.fail("验证码错误");
|
||||||
//
|
}
|
||||||
// // 解密
|
|
||||||
// WxMaPhoneNumberInfo phoneNoInfo = wxMaService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);
|
int uid = SecurityUtils.getUserId().intValue();
|
||||||
//
|
YxUserQueryVo userQueryVo = userService.getYxUserById(uid);
|
||||||
// return JsonUtils.toJson(phoneNoInfo);
|
if(StrUtil.isNotBlank(userQueryVo.getPhone())){
|
||||||
// }
|
return ApiResult.fail("您的账号已经绑定过手机号码");
|
||||||
|
}
|
||||||
|
|
||||||
|
YxUser yxUser = new YxUser();
|
||||||
|
yxUser.setPhone(param.getPhone());
|
||||||
|
yxUser.setUid(uid);
|
||||||
|
userService.updateById(yxUser);
|
||||||
|
|
||||||
|
return ApiResult.ok("绑定成功");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/wxapp/binding")
|
||||||
|
@ApiOperation(value = "小程序绑定手机号", notes = "小程序绑定手机号")
|
||||||
|
public ApiResult<String> phone(@Validated @RequestBody WxPhoneParam param) {
|
||||||
|
|
||||||
|
int uid = SecurityUtils.getUserId().intValue();
|
||||||
|
YxUserQueryVo userQueryVo = userService.getYxUserById(uid);
|
||||||
|
if(StrUtil.isNotBlank(userQueryVo.getPhone())){
|
||||||
|
return ApiResult.fail("您的账号已经绑定过手机号码");
|
||||||
|
}
|
||||||
|
|
||||||
|
//读取redis配置
|
||||||
|
String appId = RedisUtil.get("wxapp_appId");
|
||||||
|
String secret = RedisUtil.get("wxapp_secret");
|
||||||
|
if (StrUtil.isBlank(appId) || StrUtil.isBlank(secret)) {
|
||||||
|
throw new ErrorRequestException("请先配置小程序");
|
||||||
|
}
|
||||||
|
WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
|
||||||
|
wxMaConfig.setAppid(appId);
|
||||||
|
wxMaConfig.setSecret(secret);
|
||||||
|
wxMaService.setWxMaConfig(wxMaConfig);
|
||||||
|
try {
|
||||||
|
WxMaJscode2SessionResult session = wxMaService.getUserService()
|
||||||
|
.getSessionInfo(param.getCode());
|
||||||
|
|
||||||
|
// 解密
|
||||||
|
WxMaPhoneNumberInfo phoneNoInfo = wxMaService.getUserService()
|
||||||
|
.getPhoneNoInfo(session.getSessionKey(), param.getEncryptedData(), param.getIv());
|
||||||
|
|
||||||
|
YxUser yxUser = new YxUser();
|
||||||
|
yxUser.setPhone(phoneNoInfo.getPhoneNumber());
|
||||||
|
yxUser.setUid(uid);
|
||||||
|
userService.updateById(yxUser);
|
||||||
|
} catch (WxErrorException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return ApiResult.ok("绑定成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package co.yixiang.modules.wechat.web.param;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName BindPhoneParam
|
||||||
|
* @Author hupeng <610796224@qq.com>
|
||||||
|
* @Date 2020/2/7
|
||||||
|
**/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class BindPhoneParam {
|
||||||
|
@NotBlank(message = "验证码必填")
|
||||||
|
private String captcha;
|
||||||
|
|
||||||
|
@NotBlank(message = "手机号必填")
|
||||||
|
private String phone;
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package co.yixiang.modules.wechat.web.param;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName WxPhoneParam
|
||||||
|
* @Author hupeng <610796224@qq.com>
|
||||||
|
* @Date 2020/02/07
|
||||||
|
**/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class WxPhoneParam {
|
||||||
|
@NotBlank(message = "code参数缺失")
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private String encryptedData;
|
||||||
|
|
||||||
|
private String iv;
|
||||||
|
}
|
Reference in New Issue
Block a user