|
|
@ -4,16 +4,16 @@ import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.extra.servlet.ServletUtil; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.ccsens.signin.bean.dto.UserDto; |
|
|
|
import com.ccsens.signin.bean.po.SysUser; |
|
|
|
import com.ccsens.signin.bean.vo.UserVo; |
|
|
|
import com.ccsens.signin.exception.UserLoginException; |
|
|
|
import com.ccsens.signin.service.IUserService; |
|
|
|
import com.ccsens.util.CodeEnum; |
|
|
|
import com.ccsens.util.JsonResponse; |
|
|
|
import com.ccsens.util.JwtUtil; |
|
|
|
import com.ccsens.util.WebConstant; |
|
|
|
import com.ccsens.util.*; |
|
|
|
import com.ccsens.util.exception.BaseException; |
|
|
|
import com.ccsens.wechatutil.bean.po.WxPhoneDecryptInfo; |
|
|
|
import com.ccsens.wechatutil.wxmini.MiniEncryptionAndDecryptionUtil; |
|
|
|
import io.jsonwebtoken.Claims; |
|
|
|
import io.jsonwebtoken.ExpiredJwtException; |
|
|
|
import io.jsonwebtoken.SignatureException; |
|
|
@ -23,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.util.Map; |
|
|
@ -32,8 +33,10 @@ import java.util.Map; |
|
|
|
@RestController |
|
|
|
@RequestMapping("/users") |
|
|
|
public class UserController { |
|
|
|
@Autowired |
|
|
|
@Resource |
|
|
|
private IUserService userService; |
|
|
|
@Resource |
|
|
|
private RedisUtil redisUtil; |
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "/用户登录", notes = "") |
|
|
@ -224,20 +227,52 @@ public class UserController { |
|
|
|
public JsonResponse<UserVo.TokenBean> bindingPhoneNoCode(HttpServletRequest request, |
|
|
|
@ApiParam @RequestBody UserDto.WxBindingPhone2 wxPhone) throws Exception { |
|
|
|
Long currentUserId = Long.valueOf(((Claims) request.getAttribute(WebConstant.REQUEST_KEY_CLAIMS)).getSubject()); |
|
|
|
// 解密
|
|
|
|
Object sessionKey = redisUtil.get(StrUtil.format(WebConstant.Wx.SESSION_KEY, currentUserId, wxPhone.getMiniType())); |
|
|
|
if (ObjectUtil.isNull(sessionKey)) { |
|
|
|
return JsonResponse.newInstance().ok(CodeEnum.PARAM_ERROR); |
|
|
|
} |
|
|
|
String decryption = MiniEncryptionAndDecryptionUtil.decryption(wxPhone.getEncryptedData(), (String) sessionKey, wxPhone.getIv()); |
|
|
|
if (StrUtil.isEmpty(decryption)) { |
|
|
|
return JsonResponse.newInstance().ok(CodeEnum.DATA_DECRYPTION); |
|
|
|
} |
|
|
|
WxPhoneDecryptInfo wxPhoneDecryptInfo = JSONObject.parseObject(decryption, WxPhoneDecryptInfo.class); |
|
|
|
String phone = wxPhoneDecryptInfo.getPhoneNumber(); |
|
|
|
if (StrUtil.isEmpty(phone)) { |
|
|
|
return JsonResponse.newInstance().ok(CodeEnum.WBS_NOT_PHONE); |
|
|
|
} |
|
|
|
UserVo.UserSign userSignVo = null; |
|
|
|
try { |
|
|
|
|
|
|
|
userSignVo = userService.bindingPhoneNoCode(currentUserId,phone); |
|
|
|
|
|
|
|
|
|
|
|
UserVo.UserSign userSignVo = userService.bindingPhoneNoCode(currentUserId,wxPhone); |
|
|
|
|
|
|
|
UserVo.TokenBean tokenBean = null; |
|
|
|
if (ObjectUtil.isNotNull(userSignVo)) { |
|
|
|
if (ObjectUtil.isNull(userSignVo)) { |
|
|
|
return JsonResponse.newInstance().ok(); |
|
|
|
} |
|
|
|
WebConstant.CLIENT_TYPE clientType = WebConstant.CLIENT_TYPE.valueOf(1); |
|
|
|
WebConstant.IDENTIFY_TYPE identifyType = WebConstant.IDENTIFY_TYPE.valueOf(3); |
|
|
|
Map<String, Object> theMap = CollectionUtil.newHashMap(); |
|
|
|
theMap.put("authId", String.valueOf(userSignVo.getAuthId())); |
|
|
|
tokenBean = userService.getUserInfoAndToken(clientType,identifyType, userSignVo, theMap); |
|
|
|
UserVo.TokenBean tokenBean = userService.getUserInfoAndToken(clientType,identifyType, userSignVo, theMap); |
|
|
|
return JsonResponse.newInstance().ok(tokenBean); |
|
|
|
} catch (BaseException e) { |
|
|
|
if (e.getCode().intValue() == CodeEnum.MERGE_WX_PHONE.getCode().intValue()) { |
|
|
|
log.info("绑定手机号,需要合并:{},{}", phone, currentUserId); |
|
|
|
JsonResponse ok = JsonResponse.newInstance(); |
|
|
|
ok.setMsg(e.getMessage()); |
|
|
|
UserVo.TokenBean tokenBean = new UserVo.TokenBean(); |
|
|
|
tokenBean.setPhone(phone); |
|
|
|
ok.setData(tokenBean); |
|
|
|
return ok; |
|
|
|
} |
|
|
|
log.info("条件不符合要求,code:{}, message:{}", e.getCode(), e.getMessage()); |
|
|
|
return JsonResponse.newInstance().ok(); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("微信绑定手机号发生异常:", e); |
|
|
|
return JsonResponse.newInstance().ok(); |
|
|
|
} |
|
|
|
return JsonResponse.newInstance().ok(tokenBean); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|