parent
0cbf984e9b
commit
1cf9ad598a
@ -0,0 +1,87 @@ |
||||
package com.cweb.controller; |
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService; |
||||
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.cweb.config.SessionKeyCache; |
||||
import com.cweb.config.WxMaConfiguration; |
||||
import com.hai.common.exception.ErrorCode; |
||||
import com.hai.common.exception.ErrorHelp; |
||||
import com.hai.common.exception.SysCode; |
||||
import com.hai.common.security.SessionObject; |
||||
import com.hai.common.security.UserCenter; |
||||
import com.hai.common.security.VerifyCode; |
||||
import com.hai.common.security.VerifyCodeStorage; |
||||
import com.hai.common.utils.ResponseMsgUtil; |
||||
import com.hai.entity.HighUser; |
||||
import com.hai.model.HighUserModel; |
||||
import com.hai.model.ResponseData; |
||||
import com.hai.service.HighUserService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.Date; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/user") |
||||
@Api(value = "用户共用接口") |
||||
public class HighUserCommonController { |
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(WechatController.class); |
||||
|
||||
@Resource |
||||
private HighUserService highUserService; |
||||
|
||||
@Resource |
||||
private UserCenter userCenter; |
||||
|
||||
@RequestMapping(value = "/login", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "登录接口【用户不存在会自动注册】") |
||||
public ResponseData login(@RequestParam(value = "phone", required = true) String phone, |
||||
@RequestParam(value = "code", required = true) String code, |
||||
HttpServletRequest request, HttpServletResponse response) { |
||||
try { |
||||
VerifyCode verifyCode = VerifyCodeStorage.getDate(phone); |
||||
if(verifyCode == null) { |
||||
log.error("HighUserController --> bindUserPhone() error!", "验证码错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "验证码错误"); |
||||
} |
||||
if(!verifyCode.getObject().equals(code)) { |
||||
log.error("HighUserController --> bindUserPhone() error!", "验证码错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "验证码错误"); |
||||
} |
||||
|
||||
HighUser user = highUserService.findByPhone(phone); |
||||
if(user == null) { |
||||
user = new HighUser(); |
||||
user.setName("用户" + System.currentTimeMillis()); |
||||
user.setPhone(phone); |
||||
user.setGold(0); |
||||
user.setRegTime(new Date()); |
||||
user.setStatus(1); |
||||
highUserService.insertUser(user); |
||||
} |
||||
// 定义个人所有数据
|
||||
HighUserModel highUserModel = new HighUserModel(); |
||||
user.setPassword(null); |
||||
highUserModel.setHighUser(user); |
||||
SessionObject so = new SessionObject(user.getOpenId(), 1 , highUserModel); |
||||
userCenter.save(request, response, so); |
||||
return ResponseMsgUtil.success(so); |
||||
} catch (Exception e) { |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue