From ce64e667815b39efdc2f8bd52be0d43d49db8d84 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期日, 17 七月 2022 00:06:29 +0800
Subject: [PATCH] 优化小区位置

---
 service-api/src/main/java/com/java110/api/smo/login/impl/OwnerAppLoginSMOImpl.java |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/service-api/src/main/java/com/java110/api/smo/login/impl/OwnerAppLoginSMOImpl.java b/service-api/src/main/java/com/java110/api/smo/login/impl/OwnerAppLoginSMOImpl.java
index 95c9afc..76ca094 100644
--- a/service-api/src/main/java/com/java110/api/smo/login/impl/OwnerAppLoginSMOImpl.java
+++ b/service-api/src/main/java/com/java110/api/smo/login/impl/OwnerAppLoginSMOImpl.java
@@ -9,6 +9,7 @@
 import com.java110.core.context.PageData;
 import com.java110.core.factory.AuthenticationFactory;
 import com.java110.core.factory.WechatFactory;
+import com.java110.core.log.LoggerFactory;
 import com.java110.dto.owner.OwnerAppUserDto;
 import com.java110.dto.ownerCarOpenUser.OwnerCarOpenUserDto;
 import com.java110.dto.smallWeChat.SmallWeChatDto;
@@ -26,7 +27,6 @@
 import com.java110.utils.util.StringUtil;
 import com.java110.vo.ResultVo;
 import org.slf4j.Logger;
-import com.java110.core.log.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.HttpStatus;
@@ -54,6 +54,7 @@
     private final static int expireTime = 7200;
 
     private final static int LOGIN_PAGE = 1;
+    private final static int COMMON_PAGE = 2;
 
     @Autowired
     private RestTemplate restTemplate;
@@ -214,13 +215,12 @@
         logger.debug("璋冪敤寰俊鎹㈠幓openId " + paramOut);
         if (paramOut.getStatusCode() != HttpStatus.OK) {
             return ResultVo.redirectPage(errorUrl);
-
         }
-
         JSONObject paramObj = JSONObject.parseObject(paramOut.getBody());
 
         //鑾峰彇 openId
         String openId = paramObj.getString("openid");
+
         String userinfo_url = WechatConstant.APP_GET_USER_INFO_URL
                 .replace("ACCESS_TOKEN", paramObj.getString("access_token"))
                 .replace("OPENID", openId);
@@ -235,6 +235,11 @@
         //澶勭悊鏄电О鏈夌壒娈婄鍙峰鑷� 鍏ュ簱澶辫触闂
         userinfo_paramObj.put("nickname", Base64Convert.byteToBase64(userinfo_paramObj.getString("nickname").getBytes()));
 
+        //鍏紬鍙锋湭缁戝畾 寮�鏀惧钩鍙�
+        if (StringUtil.isEmpty(userinfo_paramObj.getString("unionid"))) {
+            userinfo_paramObj.put("unionid", "-1");
+        }
+
         int loginFlag = paramIn.getInteger("loginFlag");
 
         //璇存槑鏄櫥褰曢〉闈紝涓嬪彂code 灏卞彲浠ワ紝涓嶉渶瑕佷笅鍙慿ey 涔嬬被
@@ -244,12 +249,26 @@
             CommonCache.setValue(code, openId, expireTime);
             CommonCache.setValue(code + "-nickname", userinfo_paramObj.getString("nickname"), expireTime);
             CommonCache.setValue(code + "-headimgurl", userinfo_paramObj.getString("headimgurl"), expireTime);
+            CommonCache.setValue(code + "-unionid", userinfo_paramObj.getString("unionid"), expireTime);
             if (errorUrl.indexOf("?") > 0) {
                 errorUrl += ("&code=" + code);
             } else {
                 errorUrl += ("?code=" + code);
             }
+            logger.debug("鐧诲綍璺宠浆url:{}", errorUrl);
+
             return ResultVo.redirectPage(errorUrl);
+        }
+
+        if (loginFlag == COMMON_PAGE) {
+            //灏唎penId鏀惧埌redis 缂撳瓨锛岀粰鍓嶆涓嬪彂涓存椂绁ㄦ嵁
+            if (errorUrl.indexOf("?") > 0) {
+                redirectUrl += ("&openId=" + openId);
+            } else {
+                redirectUrl += ("?openId=" + openId);
+            }
+            logger.debug("璺宠浆url:{}", redirectUrl);
+            return ResultVo.redirectPage(redirectUrl);
         }
 
         //鍒ゆ柇褰撳墠openId 鏄惁缁戝畾浜嗕笟涓�
@@ -266,6 +285,7 @@
             CommonCache.setValue(code, openId, expireTime);
             CommonCache.setValue(code + "-nickname", userinfo_paramObj.getString("nickname"), expireTime);
             CommonCache.setValue(code + "-headimgurl", userinfo_paramObj.getString("headimgurl"), expireTime);
+            CommonCache.setValue(code + "-unionid", userinfo_paramObj.getString("unionid"), expireTime);
             if (errorUrl.indexOf("?") > 0) {
                 errorUrl += ("&code=" + code);
             } else {
@@ -295,6 +315,8 @@
             CommonCache.setValue(code, openId, expireTime);
             CommonCache.setValue(code + "-nickname", userinfo_paramObj.getString("nickname"), expireTime);
             CommonCache.setValue(code + "-headimgurl", userinfo_paramObj.getString("headimgurl"), expireTime);
+            CommonCache.setValue(code + "-unionid", userinfo_paramObj.getString("unionid"), expireTime);
+
             if (errorUrl.indexOf("?") > 0) {
                 errorUrl += ("&code=" + code);
             } else {
@@ -523,6 +545,7 @@
         String openId = CommonCache.getValue(code);
         String nickname = CommonCache.getValue(code + "-nickname");
         String headimgurl = CommonCache.getValue(code + "-headimgurl");
+        String unionid = CommonCache.getValue(code + "-unionid");
 
         if (StringUtil.isEmpty(openId)) {
             responseEntity = new ResponseEntity<>("椤甸潰澶辨晥锛岃鍒锋柊鍚庨噸璇�", HttpStatus.UNAUTHORIZED);
@@ -539,6 +562,7 @@
         JSONObject userOwnerInfo = new JSONObject();
         OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
         ownerAppUserDto.setOpenId(openId);
+        ownerAppUserDto.setUnionId(unionid);
         // ownerAppUserDto.setNickName(StringUtil.encodeEmoji(nickname));
         ownerAppUserDto.setNickName(nickname);
         ownerAppUserDto.setHeadImgUrl(headimgurl);

--
Gitblit v1.8.0