| | |
| | | import com.mzl.flower.dto.request.CreateWechatUserDTO; |
| | | import com.mzl.flower.dto.request.UserLoginDTO; |
| | | import com.mzl.flower.dto.response.customer.CustomerDTO; |
| | | import com.mzl.flower.dto.response.wx.WxUserVO; |
| | | import com.mzl.flower.entity.system.User; |
| | | import com.mzl.flower.mapper.customer.CustomerMapper; |
| | | import com.mzl.flower.service.customer.CustomerService; |
| | | import com.mzl.flower.service.impl.WechatUserDetailsService; |
| | | import com.mzl.flower.service.login.LoginService; |
| | | import com.mzl.flower.service.system.UserService; |
| | | import com.mzl.flower.service.system.WeChatService; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.validation.constraints.NotBlank; |
| | | import java.util.Map; |
| | | |
| | | @Slf4j |
| | | @RestController |
| | |
| | | |
| | | public static final String SEPARATOR = ":"; |
| | | |
| | | |
| | | @PostMapping("/login/wechat") |
| | | @ApiOperation(value = "微信小程序登录", notes = "微信小程序登录") |
| | | public ResponseEntity<ReturnDataDTO<OAuth2AccessToken>> loginWeChat( |
| | |
| | | String openId = session.getOpenid(); |
| | | String sessionKey = session.getSessionKey(); |
| | | String unionId = session.getUnionid(); |
| | | // 判断当前用户账号是否存在 |
| | | dto.setOpenId(openId); |
| | | dto.setSessionKey(sessionKey); |
| | | dto.setUnionId(unionId); |
| | | dto.setUserType(Constants.USER_TYPE.customer.name()); |
| | | |
| | | User existUserByOpenId = userService.getExistUserByOpenId(openId, sessionKey, unionId, Constants.USER_TYPE.customer.name()); |
| | | if(ObjectUtils.isEmpty(existUserByOpenId)){ |
| | | userService.registWxUser(dto); |
| | | } |
| | | |
| | | User user = userService.findUserByOpenId(openId, sessionKey, unionId |
| | | , dto.getImgUrl(), dto.getNickname(),Constants.USER_TYPE.customer.name()); |
| | | String tokenCache = stringCacheClient.get(TOKEN_KEY + SEPARATOR + user.getId()); |
| | |
| | | } |
| | | } |
| | | |
| | | @PostMapping("/wx/getuserphonenumber") |
| | | @ApiOperation(value = "获取当前授权的手机号") |
| | | public ResponseEntity<ReturnDataDTO> getuserphonenumber(@RequestBody CreateWechatUserDTO dto) throws Exception{ |
| | | return returnData(R.SUCCESS.getCode(), weChatService.getuserphonenumber(dto)); |
| | | } |
| | | |
| | | @PostMapping("/wx/getExistUserByOpenId") |
| | | @ApiOperation(value = "查看当前微信号是否已经绑定了用户") |
| | | public ResponseEntity<ReturnDataDTO> getExistUserByOpenId(@RequestBody CreateWechatUserDTO dto) throws Exception{ |
| | | WxMaJscode2SessionResult session = weChatService.getWxMaSessionInfo(dto.getCode()); |
| | | String openId = session.getOpenid(); |
| | | String sessionKey = session.getSessionKey(); |
| | | String unionId = session.getUnionid(); |
| | | User user=userService.getExistUserByOpenId(openId, sessionKey, unionId,dto.getUserType()); |
| | | return returnData(R.SUCCESS.getCode(), new WxUserVO(openId,sessionKey,unionId,user)); |
| | | } |
| | | |
| | | @GetMapping("/wx/jscode2session") |
| | | @ApiOperation(value = "微信小程序授权") |
| | | public ResponseEntity<ReturnDataDTO> jscode2session(@NotBlank(message = "授权码不能为空") String jsCode,String userType) throws Exception{ |