Commit 9c1727e7c3a17b75460fabff96b767dd99285749

Authored by weiliwhereareyou@163.com
1 parent 68171716

登录接口开发

mobsite-getway-domain/src/main/java/com/diligrp/mobsite/getway/domain/common/RedisKey.java
@@ -22,7 +22,11 @@ public final class RedisKey { @@ -22,7 +22,11 @@ public final class RedisKey {
22 public static final String USER_DEVICEID = ZDAPP_GETWAY+":USER:DEVICEID"; 22 public static final String USER_DEVICEID = ZDAPP_GETWAY+":USER:DEVICEID";
23 public static final String USER_REGISTERNO = ZDAPP_GETWAY+":USER:REGISTERNO"; 23 public static final String USER_REGISTERNO = ZDAPP_GETWAY+":USER:REGISTERNO";
24 24
25 - public static final String USER_SHOPID = ZDAPP_GETWAY+":USER:SHOPID"; 25 + public static final String USER_SELLER_SHOPID = ZDAPP_GETWAY+":SELLER:SHOPID";
  26 +
  27 + public static final String USER_BUYER_CURRENTSHOPID = ZDAPP_GETWAY+":BUYER:SHOPID";
  28 +
  29 + public static final String USER_BUYER_SHOPUSERID = ZDAPP_GETWAY+":BUYER:SHOPUSERID";
26 30
27 //门卫登录信息 31 //门卫登录信息
28 public static final String GUARD_LOGININFO = ZDAPP_GETWAY+":GUARD:LOGININFO"; 32 public static final String GUARD_LOGININFO = ZDAPP_GETWAY+":GUARD:LOGININFO";
mobsite-getway-domain/src/main/java/com/diligrp/mobsite/getway/domain/protocol/login/LoginResp.java
@@ -29,7 +29,7 @@ public class LoginResp extends BaseResp { @@ -29,7 +29,7 @@ public class LoginResp extends BaseResp {
29 * 账户ID 29 * 账户ID
30 */ 30 */
31 @ApiModelProperty(value = "用户id") 31 @ApiModelProperty(value = "用户id")
32 - private Long accountId; 32 + private Long buyerId;
33 /** 33 /**
34 * 账户名 34 * 账户名
35 */ 35 */
@@ -49,25 +49,36 @@ public class LoginResp extends BaseResp { @@ -49,25 +49,36 @@ public class LoginResp extends BaseResp {
49 private String headImg; 49 private String headImg;
50 50
51 51
52 -  
53 - /**  
54 - * get value of LoginResp.accountId  
55 - * @return the accountId  
56 - * @createTime Aug 13, 2014 9:58:39 AM  
57 - * @author weili  
58 - */  
59 - public Long getAccountId() {  
60 - return accountId; 52 + @ApiModelProperty(value = "当前绑定的店铺id")
  53 + private Long currentShopId;
  54 +
  55 + @ApiModelProperty(value = "店铺购买者ID")
  56 + private Long shopBuyerId;
  57 +
  58 +
  59 + public Long getBuyerId() {
  60 + return buyerId;
61 } 61 }
62 62
63 - /**  
64 - * set value of LoginResp.accountId  
65 - * @param accountId the accountId to set  
66 - * @createTime Aug 13, 2014 9:58:39 AM  
67 - * @author weili  
68 - */  
69 - public void setAccountId(Long accountId) {  
70 - this.accountId = accountId; 63 + public void setBuyerId(Long buyerId) {
  64 + this.buyerId = buyerId;
  65 + }
  66 +
  67 +
  68 + public Long getCurrentShopId() {
  69 + return currentShopId;
  70 + }
  71 +
  72 + public void setCurrentShopId(Long currentShopId) {
  73 + this.currentShopId = currentShopId;
  74 + }
  75 +
  76 + public Long getShopBuyerId() {
  77 + return shopBuyerId;
  78 + }
  79 +
  80 + public void setShopBuyerId(Long shopBuyerId) {
  81 + this.shopBuyerId = shopBuyerId;
71 } 82 }
72 83
73 /** 84 /**
mobsite-getway-rpc/src/main/java/com/diligrp/mobsite/getway/rpc/impl/PassportRPCImpl.java
@@ -103,17 +103,17 @@ public class PassportRPCImpl extends BaseServiceImpl implements PassportRPC { @@ -103,17 +103,17 @@ public class PassportRPCImpl extends BaseServiceImpl implements PassportRPC {
103 resp.setMsg(msg); 103 resp.setMsg(msg);
104 104
105 //缓存userId 105 //缓存userId
106 - String cookieRedisKey = redisUtil.makeKey(RedisKey.USER_LOGININFO, Constant.USER_ROLE_SELLER+String.valueOf(resp.getSellerId())); 106 + String cookieRedisKey = redisUtil.makeKey(RedisKey.USER_LOGININFO, Constant.USER_ROLE_SIGN_SELLER+String.valueOf(resp.getSellerId()));
107 redisUtil.setStringByExpire(cookieRedisKey, String.valueOf(resp.getSellerId()), loginExpireTime); 107 redisUtil.setStringByExpire(cookieRedisKey, String.valueOf(resp.getSellerId()), loginExpireTime);
108 108
109 //缓存shopId 109 //缓存shopId
110 - String shopIdKey = redisUtil.makeKey(RedisKey.USER_SHOPID, Constant.USER_ROLE_SELLER+String.valueOf(resp.getSellerId()));  
111 - redisUtil.setStringByExpire(shopIdKey, String.valueOf(resp.getShopId()), loginExpireTime); 110 + //String shopIdKey = redisUtil.makeKey(RedisKey.USER_SELLER_SHOPID, Constant.USER_ROLE_SIGN_SELLER+String.valueOf(resp.getSellerId()));
  111 + //redisUtil.setStringByExpire(shopIdKey, String.valueOf(resp.getShopId()), loginExpireTime);
112 112
113 113
114 //缓存设备id,userId作为key 114 //缓存设备id,userId作为key
115 if (!Validator.isNull(req.getDeviceId())) { 115 if (!Validator.isNull(req.getDeviceId())) {
116 - String onlyOneLoginRedisKey = redisUtil.makeKey(RedisKey.USER_DEVICEID, Constant.USER_ROLE_SELLER+String.valueOf(resp.getSellerId())); 116 + String onlyOneLoginRedisKey = redisUtil.makeKey(RedisKey.USER_DEVICEID, Constant.USER_ROLE_SIGN_SELLER+String.valueOf(resp.getSellerId()));
117 redisUtil.setStringByExpire(onlyOneLoginRedisKey, req.getDeviceId(), loginExpireTime); 117 redisUtil.setStringByExpire(onlyOneLoginRedisKey, req.getDeviceId(), loginExpireTime);
118 } 118 }
119 return resp; 119 return resp;
@@ -202,7 +202,74 @@ public class PassportRPCImpl extends BaseServiceImpl implements PassportRPC { @@ -202,7 +202,74 @@ public class PassportRPCImpl extends BaseServiceImpl implements PassportRPC {
202 @Override 202 @Override
203 public LoginResp buyerLogin(LoginReq req) { 203 public LoginResp buyerLogin(LoginReq req) {
204 204
205 - return null; 205 + Map<String,String> params = new HashMap<String, String>();
  206 + params.put("userName", req.getAccountName());
  207 + params.put("password", req.getPassword());
  208 + params.put("src", "zadeapp");
  209 + BaseOutput<String> output = null;
  210 + try {
  211 + output = super.httpPost("/api/login/login.html", params, null,passportSign);
  212 + } catch (Exception e) {
  213 + log.error("调用passport用户验证接口失败",e);
  214 + throw new ServiceException();
  215 + }
  216 +
  217 + JSONObject jsonBody = JSONObject.parseObject(output.getData());
  218 + int code = 0;
  219 + try {
  220 + code = jsonBody.getIntValue("code");
  221 + } catch (Exception e) {
  222 + log.error("passport返回数据:msg={}",jsonBody);
  223 + throw new ServiceException(ResultCode.BUSINESS_FAILED,"登录失败请重新登录");
  224 + }
  225 +
  226 + String msg = jsonBody.getString("msg");
  227 +
  228 + if (code == PASSPORT_LOGIN_CODE_LOCKED || code == PASSPORT_LOGIN_CODE_ACCOUNT_NOT_EXIST
  229 + || code == PASSPORT_LOGIN_CODE_PASSWORD_WRONG) {
  230 + throw new ServiceException(code,msg);
  231 + }else if (code != ResultCode.SUCCESS) {
  232 + throw new ServiceException(ResultCode.BUSINESS_FAILED,msg);
  233 + }
  234 +
  235 + //resp.setToken(jsonBody.getString("token"));
  236 + JSONObject jsonUser = jsonBody.getJSONObject("accountInfo");
  237 + LoginResp resp = new LoginResp();
  238 + resp.setBuyerId(jsonUser.getLong("accountId"));
  239 + resp.setHeadImg(jsonUser.getString("img"));
  240 + resp.setMobile("13985454555");
  241 + resp.setAccountName("");
  242 + resp.setCurrentShopId(123L);
  243 + resp.setShopBuyerId(122L);
  244 + resp.setCode(code);
  245 + resp.setMsg(msg);
  246 +
  247 + //缓存userId
  248 + String cookieRedisKey = redisUtil.makeKey(RedisKey.USER_LOGININFO, Constant.USER_ROLE_SIGN_BUYER+String.valueOf(resp.getBuyerId()));
  249 + redisUtil.setStringByExpire(cookieRedisKey, String.valueOf(resp.getBuyerId()), loginExpireTime);
  250 +
  251 + //缓存设备id,userId作为key
  252 + if (!Validator.isNull(req.getDeviceId())) {
  253 + String onlyOneLoginRedisKey = redisUtil.makeKey(RedisKey.USER_DEVICEID, Constant.USER_ROLE_SIGN_BUYER+String.valueOf(resp.getBuyerId()));
  254 + redisUtil.setStringByExpire(onlyOneLoginRedisKey, req.getDeviceId(), loginExpireTime);
  255 + }
  256 +
  257 + //缓存currentShopId
  258 + //if (!Validator.isNull(resp.getCurrentShopId())){
  259 + // String currentShopIdKey = redisUtil.makeKey(RedisKey.USER_BUYER_CURRENTSHOPID, Constant.USER_ROLE_SIGN_BUYER+String.valueOf(resp.getBuyerId()));
  260 + // redisUtil.setStringByExpire(currentShopIdKey, String.valueOf(resp.getCurrentShopId()), loginExpireTime);
  261 + //}
  262 +
  263 +
  264 + //缓存shopBuyerId
  265 + //if (!Validator.isNull(resp.getShopBuyerId())){
  266 + // String shopUserIdKey = redisUtil.makeKey(RedisKey.USER_BUYER_SHOPUSERID, Constant.USER_ROLE_SIGN_BUYER+String.valueOf(resp.getBuyerId()));
  267 + // redisUtil.setStringByExpire(shopUserIdKey, String.valueOf(resp.getShopBuyerId()), loginExpireTime);
  268 + //}
  269 +
  270 +
  271 +
  272 + return resp;
206 } 273 }
207 274
208 } 275 }
mobsite-getway-service/src/main/java/com/diligrp/mobsite/getway/service/buyer/user/impl/UserServiceImpl.java
@@ -74,7 +74,7 @@ public class UserServiceImpl implements UserService { @@ -74,7 +74,7 @@ public class UserServiceImpl implements UserService {
74 if (!Validator.isEmpty(req.getRegisterNo())) { 74 if (!Validator.isEmpty(req.getRegisterNo())) {
75 // 缓存 75 // 缓存
76 String redisKey = redisUtil.makeKey(RedisKey.USER_REGISTERNO,Constant.USER_ROLE_SIGN_BUYER+ 76 String redisKey = redisUtil.makeKey(RedisKey.USER_REGISTERNO,Constant.USER_ROLE_SIGN_BUYER+
77 - String.valueOf(resp.getAccountId())); 77 + String.valueOf(resp.getBuyerId()));
78 78
79 GetRegisterNoResp mappers = redisUtil.getObject(redisKey, 79 GetRegisterNoResp mappers = redisUtil.getObject(redisKey,
80 GetRegisterNoResp.class); 80 GetRegisterNoResp.class);
@@ -82,7 +82,7 @@ public class UserServiceImpl implements UserService { @@ -82,7 +82,7 @@ public class UserServiceImpl implements UserService {
82 RegisterNoMapper mapper = new RegisterNoMapper(); 82 RegisterNoMapper mapper = new RegisterNoMapper();
83 mapper.setRegisterNo(req.getRegisterNo()); 83 mapper.setRegisterNo(req.getRegisterNo());
84 mapper.setSysFlag(RegisterNoMapper.SYS_FLAG_JPUSH); 84 mapper.setSysFlag(RegisterNoMapper.SYS_FLAG_JPUSH);
85 - mapper.setUserid(resp.getAccountId()); 85 + mapper.setUserid(resp.getBuyerId());
86 mapper.setUserType(Constant.USER_ROLE_BUYER); 86 mapper.setUserType(Constant.USER_ROLE_BUYER);
87 mapper.setDeviceType(req.getDeviceType()); 87 mapper.setDeviceType(req.getDeviceType());
88 try { 88 try {
mobsite-getway-web/src/main/java/com/diligrp/mobsite/getway/web/filter/LoginTimeoutInterceptor.java
@@ -49,9 +49,9 @@ public class LoginTimeoutInterceptor extends HandlerInterceptorAdapter { @@ -49,9 +49,9 @@ public class LoginTimeoutInterceptor extends HandlerInterceptorAdapter {
49 } 49 }
50 50
51 //检测token信息 51 //检测token信息
52 - //if (!checkTokenInfo(body,request)) {  
53 - // return false;  
54 - //} 52 + if (!checkTokenInfo(body,request)) {
  53 + return false;
  54 + }
55 55
56 return super.preHandle(request, response, handler); 56 return super.preHandle(request, response, handler);
57 } 57 }