app 用户登录 用户注册
新增 登录过滤器 仅对app作用
This commit is contained in:
@@ -10,6 +10,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbMerchantAccountMapper;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbMerchantAccount;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbUserInfo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.AuthUserDto;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.OnlineUserDto;
|
||||
import com.chaozhanggui.system.cashierservice.service.LoginService;
|
||||
@@ -29,8 +30,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
@CrossOrigin(origins = "*")
|
||||
@RestController
|
||||
@@ -89,11 +89,6 @@ public class LoginContoller {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@RequestMapping("/wx/custom/login")
|
||||
public Result wxCustomLogin(HttpServletRequest request, @RequestBody Map<String, String> map
|
||||
// ,
|
||||
@@ -102,23 +97,23 @@ public class LoginContoller {
|
||||
) {
|
||||
|
||||
|
||||
if (ObjectUtil.isNull(map) || ObjectUtil.isEmpty(map)||!map.containsKey("code")||ObjectUtil.isEmpty(map.get("code"))) {
|
||||
if (ObjectUtil.isNull(map) || ObjectUtil.isEmpty(map) || !map.containsKey("code") || ObjectUtil.isEmpty(map.get("code"))) {
|
||||
Result.fail("code不能为空");
|
||||
}
|
||||
|
||||
String code=map.get("code").toString();
|
||||
String code = map.get("code").toString();
|
||||
|
||||
String qrCode=map.get("qrCode");
|
||||
String qrCode = map.get("qrCode");
|
||||
|
||||
String rawData=map.get("rawData");
|
||||
String rawData = map.get("rawData");
|
||||
|
||||
String signature=map.get("signature");
|
||||
String signature = map.get("signature");
|
||||
|
||||
String encryptedData=map.get("encryptedData");
|
||||
String encryptedData = map.get("encryptedData");
|
||||
|
||||
String ivStr=map.get("iv");
|
||||
String ivStr = map.get("iv");
|
||||
|
||||
String phone=map.get("phone");
|
||||
String phone = map.get("phone");
|
||||
|
||||
// 用户非敏感信息:rawData
|
||||
// 签名:signature
|
||||
@@ -136,11 +131,11 @@ public class LoginContoller {
|
||||
return Result.fail("签名校验失败");
|
||||
}
|
||||
|
||||
String nickName = rawDataJson.getString( "nickName");
|
||||
String avatarUrl = rawDataJson.getString( "avatarUrl");
|
||||
String nickName = rawDataJson.getString("nickName");
|
||||
String avatarUrl = rawDataJson.getString("avatarUrl");
|
||||
|
||||
try {
|
||||
return loginService.wxCustomLogin(openid, avatarUrl, nickName, phone,qrCode, IpUtil.getIpAddr(request));
|
||||
return loginService.wxCustomLogin(openid, avatarUrl, nickName, phone, qrCode, IpUtil.getIpAddr(request));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -151,16 +146,16 @@ public class LoginContoller {
|
||||
|
||||
|
||||
@RequestMapping("getPhoneNumber")
|
||||
public Result getPhoneNumber(@RequestBody Map<String,String> map){
|
||||
public Result getPhoneNumber(@RequestBody Map<String, String> map) {
|
||||
|
||||
if (ObjectUtil.isNull(map) || ObjectUtil.isEmpty(map)||!map.containsKey("code")||ObjectUtil.isEmpty(map.get("code"))) {
|
||||
if (ObjectUtil.isNull(map) || ObjectUtil.isEmpty(map) || !map.containsKey("code") || ObjectUtil.isEmpty(map.get("code"))) {
|
||||
Result.fail("code不能为空");
|
||||
}
|
||||
String code=map.get("code").toString();
|
||||
String code = map.get("code").toString();
|
||||
|
||||
String encryptedData=map.get("encryptedData");
|
||||
String encryptedData = map.get("encryptedData");
|
||||
|
||||
String ivStr=map.get("iv");
|
||||
String ivStr = map.get("iv");
|
||||
|
||||
|
||||
JSONObject SessionKeyOpenId = WechatUtil.getSessionKeyOrOpenId(code, customAppId, customSecrete);
|
||||
@@ -168,11 +163,11 @@ public class LoginContoller {
|
||||
String openid = SessionKeyOpenId.getString("openid");
|
||||
String sessionKey = SessionKeyOpenId.getString("session_key");
|
||||
|
||||
String data= WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr);
|
||||
if(ObjectUtil.isNotEmpty(data)&&JSONObject.parseObject(data).containsKey("phoneNumber")){
|
||||
String data = WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr);
|
||||
if (ObjectUtil.isNotEmpty(data) && JSONObject.parseObject(data).containsKey("phoneNumber")) {
|
||||
return Result.success(CodeEnum.SUCCESS, JSONObject.parseObject(data).get("phoneNumber"));
|
||||
}
|
||||
return Result.fail("获取手机号失败");
|
||||
return Result.fail("获取手机号失败");
|
||||
|
||||
}
|
||||
|
||||
@@ -196,34 +191,79 @@ public class LoginContoller {
|
||||
//生成token
|
||||
String token = StringUtil.genRandomNum(6) + StringUtil.getBillno() + StringUtil.genRandomNum(6);
|
||||
//存入redis
|
||||
OnlineUserDto jwtUserDto = onlineUserService.save(merchantAccount.getName(), merchantAccount.getAccount(), Integer.valueOf(merchantAccount.getShopId()), token,merchantAccount.getStatus());
|
||||
OnlineUserDto jwtUserDto = onlineUserService.save(merchantAccount.getName(), merchantAccount.getAccount(), Integer.valueOf(merchantAccount.getShopId()), token, merchantAccount.getStatus());
|
||||
|
||||
//组装登录数据
|
||||
Map<String, Object> authInfo = new HashMap<String, Object>(2) {{
|
||||
put("token", token);
|
||||
put("token", token);
|
||||
put("user", jwtUserDto);
|
||||
}};
|
||||
return Result.success(CodeEnum.ENCRYPT,authInfo);
|
||||
return Result.success(CodeEnum.ENCRYPT, authInfo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取会员码
|
||||
*
|
||||
* @param openId
|
||||
* @param token
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("createCardNo")
|
||||
public Result createCardNo(@RequestHeader("openId") String openId,@RequestHeader("token") String token,@RequestHeader("id") String id){
|
||||
return loginService.createCardNo(id,openId);
|
||||
public Result createCardNo(@RequestHeader("openId") String openId, @RequestHeader("token") String token, @RequestHeader("id") String id) {
|
||||
return loginService.createCardNo(id, openId);
|
||||
}
|
||||
|
||||
@GetMapping("/wx/userInfo")
|
||||
public Result userInfo(@RequestParam("userId") Integer userId,@RequestParam("shopId") String shopId ){
|
||||
return loginService.userInfo(userId,shopId);
|
||||
public Result userInfo(@RequestParam("userId") Integer userId, @RequestParam("shopId") String shopId) {
|
||||
return loginService.userInfo(userId, shopId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
*
|
||||
* @param phone 手机号
|
||||
* @param nickName 用户昵称
|
||||
* @param password 密码
|
||||
* @param code 验证码
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("register")
|
||||
public Result register(@RequestBody TbUserInfo userInfo) {
|
||||
boolean tf = loginService.validate(userInfo.getCode(), userInfo.getTelephone());
|
||||
if (tf) {
|
||||
return loginService.register(userInfo.getTelephone(), userInfo.getPassword(), userInfo.getNickName());
|
||||
} else {
|
||||
return Result.fail("验证码校验失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* App登录用户端的请求接口
|
||||
*
|
||||
* @param username 手机号
|
||||
* @param password 密码登录时使用
|
||||
* @param code 验证码登录时使用
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/app/login")
|
||||
public Result applogin(@RequestBody AuthUserDto authUserDto) {
|
||||
if (ObjectUtil.isNull(authUserDto.getCode())) {
|
||||
//验证密码
|
||||
String mdPasswordString = MD5Utils.MD5Encode(authUserDto.getPassword(), "utf-8");
|
||||
return loginService.appLogin(authUserDto.getUsername(), mdPasswordString);
|
||||
} else {
|
||||
boolean tf = loginService.validate(authUserDto.getCode(), authUserDto.getUsername());
|
||||
if (tf) {
|
||||
return loginService.appLogin(authUserDto.getUsername(), null);
|
||||
} else {
|
||||
return Result.fail("验证码输入有误");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@ import com.chaozhanggui.system.cashierservice.util.RedisUtils;
|
||||
import com.chaozhanggui.system.cashierservice.util.StringUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.ValidateCodeUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -40,7 +39,9 @@ public class PhoneValidateCodeController {
|
||||
*/
|
||||
@GetMapping
|
||||
public Result verifyPhoneIsExist(@RequestParam String phone) {
|
||||
|
||||
if (StringUtils.isBlank(phone)) {
|
||||
return Result.fail("手机号不可为空!");
|
||||
}
|
||||
String random = StringUtil.random(6);
|
||||
validateCodeUtil.requestValidateCodeAli(phone, random);
|
||||
//存入缓存
|
||||
|
||||
Reference in New Issue
Block a user