dcs 2 months ago
parent
commit
dd91976379

+ 14 - 1
virgo.core/src/main/java/com/bosshand/virgo/core/service/MgrUserService.java

@@ -153,7 +153,20 @@ public class MgrUserService {
 		if (StringUtil.notBlank(str)) {
 			return JSONObject.parseObject(str).getJSONObject("data").getString("token");
 		}
-		return "商场服务异常!";
+		return "商城服务异常!";
+	}
+
+	/**
+	 * 获取商场后台token
+	 */
+	public String getShopMobileToken(String phone) {
+		String url = "https://www.workark.com/prod-api/mobile-api/loginOrReg?mobile="+phone+"&smsCode="+"";
+		JSONObject js = new JSONObject();
+		String str = WeChatUtil.httpPost(url, js, null);
+		if (StringUtil.notBlank(str)) {
+			return JSONObject.parseObject(str).getJSONObject("data").getString("token");
+		}
+		return "商城服务异常!";
 	}
 
 	public void delete(int userId) {

+ 26 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/shiro/VirgoAuthenticationFilter.java

@@ -62,6 +62,16 @@ public class VirgoAuthenticationFilter extends AuthenticatingFilter {
 		this.shopToken = null;
 	}
 
+	private String shopMobileToken = null;
+
+	private void initMobileShopToken(String shopMobileToken) {
+		this.shopMobileToken = shopMobileToken;
+	}
+
+	private void releaseShopMobileToken() {
+		this.shopMobileToken = null;
+	}
+
 	@Override
 	protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) throws Exception {
 		String phone = null;
@@ -100,6 +110,8 @@ public class VirgoAuthenticationFilter extends AuthenticatingFilter {
 				}
 				MgrUser user = mgrUserService.getByPhone(phone);
 				init(mgrUserService.wxLogin(wxCode));
+				// 登录商场移动端
+				initMobileShopToken(mgrUserService.getShopMobileToken(phone));
 				if (user != null) {
 					CodeCache.setKey(phone, CodeCache.DefaultPhoneCode);
 					return createToken(phone, CodeCache.DefaultPhoneCode, request, response);
@@ -120,12 +132,16 @@ public class VirgoAuthenticationFilter extends AuthenticatingFilter {
 				CodeCache.setKey(dto.getPhone(), CodeCache.DefaultPhoneCode);
 				// 登录商城后台
 				initShopToken(mgrUserService.getShopToken());
+				// 登录商场移动端
+				initMobileShopToken(mgrUserService.getShopMobileToken(dto.getPhone()));
 				return createToken(dto.getPhone(), CodeCache.DefaultPhoneCode, request, response);
 			}
 
 			// 密码登录
 			if(dto.getPassword() != null){
 				String password = SecurityUtils.MD5LoginSecu(dto.getPassword().getBytes());
+				// 登录商场移动端
+				initMobileShopToken(mgrUserService.getShopMobileToken(dto.getPhone()));
 				return createToken(dto.getPhone(), password, request, response);
 			}
 
@@ -151,6 +167,8 @@ public class VirgoAuthenticationFilter extends AuthenticatingFilter {
 			log.error("Can not create token", e);
 			throw new AuthException("Can not create token", Constant.RET_INVALID_PASSWORD, e);
 		}
+		// 登录商场移动端
+		initMobileShopToken(mgrUserService.getShopMobileToken(phone));
 		return createToken(phone, phoneCode, request, response);
 	}
 	
@@ -162,6 +180,10 @@ public class VirgoAuthenticationFilter extends AuthenticatingFilter {
 				JSONObject jsonObject = JSONObject.parseObject(wxJson);
 				release();
 				jsonObject.put("token", subject.getSession().getId().toString());
+				if (shopMobileToken != null) {
+					jsonObject.put("shopMobileToken", shopMobileToken);
+					releaseShopMobileToken();
+				}
 				response.getWriter().write(JSON.toJSONString(Response.ok(jsonObject)));
 			} else {
 				Map<String, String> map = new HashMap<String, String>();
@@ -170,6 +192,10 @@ public class VirgoAuthenticationFilter extends AuthenticatingFilter {
 					map.put("shopToken", shopToken);
 					releaseShopToken();
 				}
+				if (shopMobileToken != null) {
+					map.put("shopMobileToken", shopMobileToken);
+					releaseShopMobileToken();
+				}
 				response.getWriter().write(JSON.toJSONString(Response.ok(map)));
 			}
 		}