Ver código fonte

优化本地代码

java110 5 anos atrás
pai
commit
634c7515c0

+ 5 - 0
java110-bean/src/main/java/com/java110/dto/user/UserAttrDto.java

@@ -5,6 +5,11 @@ import com.java110.dto.PageDto;
 import java.io.Serializable;
 
 public class UserAttrDto extends PageDto implements Serializable {
+
+    public static final String SPEC_KEY = "100202061602";//用户临时key
+
+    public static final String SPEC_OPEN_ID = "100201911001";//用户微信OPENID
+
     private String attrId;
     private String userId;
     private String specCd;

+ 20 - 0
java110-bean/src/main/java/com/java110/dto/user/UserDto.java

@@ -52,6 +52,10 @@ public class UserDto extends PageDto implements Serializable {
     private String openId;
     private String statusCd;
 
+    private String token;
+
+    private String key;//临时登录秘钥,每次登录后重置
+
 
     private String parentOrgName;
 
@@ -246,4 +250,20 @@ public class UserDto extends PageDto implements Serializable {
     public void setBelongCommunityId(String belongCommunityId) {
         this.belongCommunityId = belongCommunityId;
     }
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public String getToken() {
+        return token;
+    }
+
+    public void setToken(String token) {
+        this.token = token;
+    }
 }

+ 13 - 0
java110-bean/src/main/java/com/java110/vo/ResultVo.java

@@ -211,6 +211,19 @@ public class ResultVo implements Serializable {
         return responseEntity;
     }
 
+    /**
+     * 创建ResponseEntity对象
+     *
+     * @param code 状态嘛
+     * @param msg  返回信息
+     * @return
+     */
+    public static ResponseEntity<String> createResponseEntity(int code, String msg) {
+        ResultVo resultVo = new ResultVo(code, msg);
+        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
+        return responseEntity;
+    }
+
     /**
      * 创建ResponseEntity对象
      *

+ 10 - 0
java110-bean/src/main/java/com/java110/vo/api/user/ApiUserDataVo.java

@@ -22,6 +22,8 @@ public class ApiUserDataVo implements Serializable {
 
     private String openId;
 
+    private String key;
+
     private int age;
 
     private String sex;
@@ -123,4 +125,12 @@ public class ApiUserDataVo implements Serializable {
     public void setOpenId(String openId) {
         this.openId = openId;
     }
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
 }

+ 9 - 0
java110-db/src/main/resources/mapper/user/UserServiceDaoImplMapper.xml

@@ -540,6 +540,9 @@
         <if test="openId != null and openId !=''">
             ,u_user_attr ua
         </if>
+        <if test="key != null and key !=''">
+            ,u_user_attr ub
+        </if>
         where 1= 1
         <if test="openId != null and openId != ''">
             and u.user_id = ua.user_id
@@ -547,6 +550,12 @@
             and ua.value = #{openId}
             and ua.status_cd = '0'
         </if>
+        <if test="key != null and key != ''">
+            and u.user_id = ua.user_id
+            and ub.spec_cd = '100202061602'
+            and ub.value = #{key}
+            and ub.status_cd = '0'
+        </if>
         <if test="bId != null and bId !=''">
             and u.b_id = #{bId}
         </if>

+ 11 - 1
java110-utils/src/main/java/com/java110/utils/constant/ServiceCodeConstant.java

@@ -118,7 +118,12 @@ public class ServiceCodeConstant {
 
 
     /**
-     * 查询 组织管理
+     * 查询 用户私密信息
+     */
+    public static final String QUERY_USER_SECRET = "user.queryUserSecret";
+
+    /**
+     * 查询 用户
      */
     public static final String LIST_USERS = "user.listUsers";
 
@@ -249,6 +254,11 @@ public class ServiceCodeConstant {
      */
     public static final String SERVICE_CODE_USER_SERVICE_LOGIN = "user.service.login";
 
+    /**
+     * 用户登录服务处理
+     */
+    public static final String SERVICE_CODE_USER_LOGIN = "user.userLogin";
+
     /**
      * 用户退出登录服务处理
      */

+ 2 - 2
service-api/src/main/java/com/java110/api/listener/user/ListUsersListener.java

@@ -70,7 +70,8 @@ public class ListUsersListener extends AbstractServiceApiListener {
         List<ApiUserDataVo> users = null;
 
         if (count > 0) {
-            users = BeanConvertUtil.covertBeanList(userInnerServiceSMOImpl.getUsers(userDto), ApiUserDataVo.class);
+            List<UserDto> userDtos = userInnerServiceSMOImpl.getUsers(userDto);
+            users = BeanConvertUtil.covertBeanList(userDtos, ApiUserDataVo.class);
         } else {
             users = new ArrayList<>();
         }
@@ -84,6 +85,5 @@ public class ListUsersListener extends AbstractServiceApiListener {
         ResponseEntity<String> responseEntity = new ResponseEntity<String>(JSONObject.toJSONString(apiOrgVo), HttpStatus.OK);
 
         context.setResponseEntity(responseEntity);
-
     }
 }

+ 88 - 0
service-api/src/main/java/com/java110/api/listener/user/QueryUserSecretListener.java

@@ -0,0 +1,88 @@
+package com.java110.api.listener.user;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.api.listener.AbstractServiceApiListener;
+import com.java110.core.annotation.Java110Listener;
+import com.java110.core.context.DataFlowContext;
+import com.java110.core.event.service.api.ServiceDataFlowEvent;
+import com.java110.core.smo.user.IUserInnerServiceSMO;
+import com.java110.dto.user.UserAttrDto;
+import com.java110.dto.user.UserDto;
+import com.java110.utils.constant.ServiceCodeConstant;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
+import com.java110.vo.ResultVo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+
+import java.util.List;
+
+
+/**
+ * 这个类专门查询用户秘钥信息
+ */
+@Java110Listener("queryUserSecretListener")
+public class QueryUserSecretListener extends AbstractServiceApiListener {
+
+    @Autowired
+    private IUserInnerServiceSMO userInnerServiceSMOImpl;
+
+    @Override
+    public String getServiceCode() {
+        return ServiceCodeConstant.QUERY_USER_SECRET;
+    }
+
+    @Override
+    public HttpMethod getHttpMethod() {
+        return HttpMethod.GET;
+    }
+
+
+    public IUserInnerServiceSMO getUserInnerServiceSMOImpl() {
+        return userInnerServiceSMOImpl;
+    }
+
+    public void setUserInnerServiceSMOImpl(IUserInnerServiceSMO userInnerServiceSMOImpl) {
+        this.userInnerServiceSMOImpl = userInnerServiceSMOImpl;
+    }
+
+    @Override
+    protected void validate(ServiceDataFlowEvent event, JSONObject reqJson) {
+        //super.validatePageInfo(reqJson);
+        Assert.hasKeyAndValue(reqJson, "userId", "请求报文中未包含用户ID");
+    }
+
+    @Override
+    protected void doSoService(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson) {
+
+        ResponseEntity<String> responseEntity = null;
+        UserDto userDto = BeanConvertUtil.covertBean(reqJson, UserDto.class);
+
+        List<UserDto> userDtos = userInnerServiceSMOImpl.getUsers(userDto);
+
+        if (userDtos == null || userDtos.size() < 1) {
+            responseEntity = ResultVo.createResponseEntity(ResultVo.CODE_ERROR, "未找到用户信息");
+            context.setResponseEntity(responseEntity);
+            return;
+        }
+
+        userDto = userDtos.get(0);
+        List<UserAttrDto> userAttrDtos = userDto.getUserAttrs();
+        String key = "";
+        String openId = "";
+        for (UserAttrDto userAttrDto : userAttrDtos) {
+            if (UserAttrDto.SPEC_KEY.equals(userAttrDto.getSpecCd())) {
+                key = userAttrDto.getValue();
+            }
+
+            if (UserAttrDto.SPEC_OPEN_ID.equals(userAttrDto.getSpecCd())) {
+                openId = userAttrDto.getValue();
+            }
+        }
+        userDto.setKey(key);
+        userDto.setOpenId(openId);
+        responseEntity = ResultVo.createResponseEntity(ResultVo.CODE_OK, "成功", userDto);
+        context.setResponseEntity(responseEntity);
+    }
+}

+ 148 - 0
service-api/src/main/java/com/java110/api/listener/user/UserLoginListener.java

@@ -0,0 +1,148 @@
+package com.java110.api.listener.user;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.api.listener.AbstractServiceApiPlusListener;
+import com.java110.core.annotation.Java110Listener;
+import com.java110.core.context.DataFlowContext;
+import com.java110.core.event.service.api.ServiceDataFlowEvent;
+import com.java110.core.factory.AuthenticationFactory;
+import com.java110.core.smo.user.IUserInnerServiceSMO;
+import com.java110.dto.user.UserAttrDto;
+import com.java110.dto.user.UserDto;
+import com.java110.po.userAttr.UserAttrPo;
+import com.java110.utils.constant.BusinessTypeConstant;
+import com.java110.utils.constant.CommonConstant;
+import com.java110.utils.constant.ResponseConstant;
+import com.java110.utils.constant.ServiceCodeConstant;
+import com.java110.utils.exception.SMOException;
+import com.java110.utils.util.BeanConvertUtil;
+import com.java110.utils.util.ValidatorUtil;
+import com.java110.vo.ResultVo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * 用户注册 侦听
+ * Created by wuxw on 2018/5/18.
+ */
+@Java110Listener("userLoginListener")
+public class UserLoginListener extends AbstractServiceApiPlusListener {
+
+    private final static Logger logger = LoggerFactory.getLogger(UserLoginListener.class);
+
+
+    @Autowired
+    private IUserInnerServiceSMO userInnerServiceSMOImpl;
+
+
+    @Override
+    public String getServiceCode() {
+        return ServiceCodeConstant.SERVICE_CODE_USER_LOGIN;
+    }
+
+    @Override
+    public HttpMethod getHttpMethod() {
+        return HttpMethod.POST;
+    }
+
+
+    @Override
+    protected void validate(ServiceDataFlowEvent event, JSONObject reqJson) {
+
+    }
+
+    @Override
+    protected void doSoService(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson) {
+
+        //1.0 优先用 手机号登录
+        UserDto userDto = new UserDto();
+        String errorInfo = "";
+        if (reqJson.containsKey("userName")) {
+            if (!ValidatorUtil.isMobile(reqJson.getString("userName"))) {//用户临时秘钥登录
+                userDto.setTel(reqJson.getString("userName"));
+            } else {
+                userDto.setUserName(reqJson.getString("userName"));
+            }
+            userDto.setPassword(AuthenticationFactory.passwdMd5(reqJson.getString("passwd")));
+            errorInfo = "用户名或密码错误";
+        } else {
+            userDto.setKey(reqJson.getString("key"));
+            errorInfo = "临时票据错误";
+        }
+
+        List<UserDto> userDtos = userInnerServiceSMOImpl.getUsers(userDto);
+
+        if (userDtos == null || userDtos.size() < 1) {
+            throw new SMOException("登录失败," + errorInfo);
+        }
+
+        //表名登录成功
+        UserDto tmpUserDto = userDtos.get(0);
+
+        List<UserAttrDto> userAttrDtos = tmpUserDto.getUserAttrs();
+
+        UserAttrDto userAttrDto = getCurrentUserAttrDto(userAttrDtos, UserAttrDto.SPEC_KEY);
+        String newKey = UUID.randomUUID().toString();
+        if (userAttrDto != null) {
+            UserAttrPo userAttrPo = BeanConvertUtil.covertBean(userAttrDto, UserAttrPo.class);
+            userAttrPo.setValue(newKey);
+            super.update(context, userAttrPo, BusinessTypeConstant.BUSINESS_TYPE_UPDATE_USER_ATTR_INFO);
+        } else {
+            UserAttrPo userAttrPo = new UserAttrPo();
+            userAttrPo.setAttrId("-1");
+            userAttrPo.setUserId(tmpUserDto.getUserId());
+            userAttrPo.setSpecCd(UserAttrDto.SPEC_KEY);
+            userAttrPo.setValue(newKey);
+            super.insert(context, userAttrPo, BusinessTypeConstant.BUSINESS_TYPE_SAVE_USER_ATTR_INFO);
+        }
+
+
+        try {
+            Map userMap = new HashMap();
+            userMap.put(CommonConstant.LOGIN_USER_ID, tmpUserDto.getUserId());
+            userMap.put(CommonConstant.LOGIN_USER_NAME, tmpUserDto.getUserName());
+            String token = AuthenticationFactory.createAndSaveToken(userMap);
+            tmpUserDto.setPassword("");
+            tmpUserDto.setToken(token);
+            context.setResponseEntity(ResultVo.createResponseEntity(tmpUserDto));
+        } catch (Exception e) {
+            logger.error("登录异常:", e);
+            throw new SMOException(ResponseConstant.RESULT_CODE_INNER_ERROR, "系统内部错误,请联系管理员");
+        }
+    }
+
+    private UserAttrDto getCurrentUserAttrDto(List<UserAttrDto> userAttrDtos, String specCd) {
+        for (UserAttrDto userAttrDto : userAttrDtos) {
+            if (specCd.equals(userAttrDto.getSpecCd())) {
+                return userAttrDto;
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * 对请求报文处理
+     *
+     * @param paramIn
+     * @return
+     */
+    private JSONObject refreshParamIn(String paramIn) {
+        JSONObject paramObj = JSONObject.parseObject(paramIn);
+        paramObj.put("userId", "-1");
+        paramObj.put("levelCd", "0");
+
+        return paramObj;
+    }
+
+
+}

+ 0 - 94
service-api/src/main/java/com/java110/api/rest/GetPhotoByInst.java

@@ -1,94 +0,0 @@
-package com.java110.api.rest;
-
-import org.apache.commons.io.FileUtils;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.util.StringUtils;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.net.URL;
-
-/**
- * @ClassName GetPhotoByInst
- * @Description TODO
- * @Author wuxw
- * @Date 2019/8/28 22:49
- * @Version 1.0
- * add by wuxw 2019/8/28
- **/
-public class GetPhotoByInst {
-
-    final static String PHOTO_INFO_PATH= "photoInfo.txt";
-    final static String DEFAULTE_PHOTO_DIR= "./Api/photos/";
-
-    public static void main(String[] args) {
-        //读取文件
-        Reader reader = null;
-        String sb = "";
-        try {
-            InputStream inputStream = new ClassPathResource(PHOTO_INFO_PATH).getInputStream();
-            //InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(File.separator + filePath);
-            reader = new InputStreamReader(inputStream, "UTF-8");
-            int tempChar;
-            StringBuffer b = new StringBuffer();
-            while ((tempChar = reader.read()) != -1) {
-                b.append((char) tempChar);
-            }
-            sb = b.toString();
-
-            String[] strs = sb.split("\n");
-
-            for(String str : strs){
-                dealPhoto(str);
-            }
-        } catch (IOException e) {
-            e.printStackTrace();
-        } finally {
-            if (reader != null) {
-                try {
-                    reader.close();
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
-            }
-        }
-    }
-
-    private static void dealPhoto(String str) {
-
-        String[] tmpPhotoPaths = str.split("\\|");
-
-        String instId = tmpPhotoPaths[0];
-        String photoUrl = tmpPhotoPaths[1];
-
-        downloadFromUrl(photoUrl,DEFAULTE_PHOTO_DIR,"qhdx_"+instId+"_17.jpg");
-        //downloadFromUrl(photoUrl,DEFAULTE_PHOTO_DIR,instId+".jpg");
-    }
-
-
-    /**
-     * 文件下载的方法
-     * @param  url 地址
-     * @param  dir 目录
-     * @return String fileName
-     */
-    public static String downloadFromUrl(String url, String dir,String fileName) {
-
-        try {
-            URL httpurl = new URL(url);
-            //	fileName = getFileNameFromUrl(url);
-            //String[] us=url.split("/");
-            //fileName=us[us.length-1];
-            System.out.println("fileName:"+fileName);
-            File f = new File(dir + fileName);
-            FileUtils.copyURLToFile(httpurl, f);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return "Fault!";
-        }
-        return fileName;
-    }
-}

+ 2 - 0
service-front/src/main/java/com/java110/front/configuration/ServiceConfiguration.java

@@ -27,6 +27,7 @@ public class ServiceConfiguration {
         exclusions.append("/app/loginWx,");// 登录跳过
         exclusions.append("/app/loginProperty,");// 物业APP登录跳过
         exclusions.append("/app/loginOwner,");// 业主APP登录跳过
+        exclusions.append("/app/loginOwnerByKey,");// 根据key登录业主
         exclusions.append("/app/area.listAreas,");// 加载地区
         exclusions.append("/app/community.listCommunitys,");// 加载小区
         exclusions.append("/app/user.userSendSms,");// 发送短信验证码
@@ -37,6 +38,7 @@ public class ServiceConfiguration {
         exclusions.append("/app/wechat/gateway,");//微信公众号对接接口
         exclusions.append("/app/loginOwnerWechatAuth,");//微信公众号对接接口
         exclusions.append("/app/refreshToken");//微信公众号对接接口
+
         final FilterRegistrationBean registrationBean = new FilterRegistrationBean();
         registrationBean.setFilter(new JwtFilter());
         registrationBean.addUrlPatterns("/");

+ 27 - 0
service-front/src/main/java/com/java110/front/controller/LoginOwnerController.java

@@ -57,4 +57,31 @@ public class LoginOwnerController extends BaseController {
         return responseEntity;
     }
 
+
+    /**
+     * 微信登录接口
+     *
+     * @param postInfo
+     * @param request
+     */
+    @RequestMapping(path = "/loginOwnerByKey", method = RequestMethod.POST)
+    public ResponseEntity<String> loginOwnerByKey(@RequestBody String postInfo, HttpServletRequest request) {
+        /*IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);*/
+        String appId = request.getHeader("APP_ID");
+        if(StringUtil.isEmpty(appId)){
+            appId = request.getHeader("APP-ID");
+        }
+        IPageData pd = PageData.newInstance().builder("", "", "", postInfo,
+                "login", "", "", "", appId
+        );
+        ResponseEntity<String> responseEntity = ownerAppLoginSMOImpl.doLoginByKey(pd);
+        if (responseEntity.getStatusCode() != HttpStatus.OK) {
+            return responseEntity;
+        }
+        JSONObject outParam = JSONObject.parseObject(responseEntity.getBody());
+        pd.setToken(outParam.getString("token"));
+        request.setAttribute(CommonConstant.CONTEXT_PAGE_DATA, pd);
+        return responseEntity;
+    }
+
 }

+ 2 - 1
service-front/src/main/java/com/java110/front/controller/wechat/LoginOwnerWechatAuthController.java

@@ -55,9 +55,10 @@ public class LoginOwnerWechatAuthController extends BaseController {
      */
     @RequestMapping(path = "/refreshToken")
     public ResponseEntity<String> refreshToken(@RequestParam String redirectUrl,
+                               @RequestParam String errorUrl,
                                HttpServletRequest request,
                                HttpServletResponse response) {
-        return ownerAppLoginSMOImpl.refreshToken(null, redirectUrl, request, response);
+        return ownerAppLoginSMOImpl.refreshToken(null, redirectUrl,errorUrl, request, response);
 
     }
 

+ 11 - 1
service-front/src/main/java/com/java110/front/smo/ownerLogin/IOwnerAppLoginSMO.java

@@ -23,6 +23,15 @@ public interface IOwnerAppLoginSMO {
      */
     ResponseEntity<String> doLogin(IPageData pd) throws SMOException;
 
+    /**
+     * 根据key 登录
+     *
+     * @param pd 页面数据封装
+     * @return ResponseEntity 对象数据
+     * @throws SMOException 业务代码层
+     */
+    ResponseEntity<String> doLoginByKey(IPageData pd) throws SMOException;
+
     /**
      * 获取access_token
      *
@@ -40,5 +49,6 @@ public interface IOwnerAppLoginSMO {
      * @return
      * @throws SMOException
      */
-    ResponseEntity<String> refreshToken(IPageData pd, String redirectUrl, HttpServletRequest request, HttpServletResponse response) throws SMOException;
+    ResponseEntity<String> refreshToken(IPageData pd, String redirectUrl, String errorUrl,
+                                        HttpServletRequest request, HttpServletResponse response) throws SMOException;
 }

+ 68 - 9
service-front/src/main/java/com/java110/front/smo/ownerLogin/impl/OwnerAppLoginSMOImpl.java

@@ -7,6 +7,7 @@ import com.java110.core.context.IPageData;
 import com.java110.core.context.PageData;
 import com.java110.core.factory.AuthenticationFactory;
 import com.java110.dto.owner.OwnerAppUserDto;
+import com.java110.dto.user.UserDto;
 import com.java110.front.properties.WechatAuthProperties;
 import com.java110.front.smo.ownerLogin.IOwnerAppLoginSMO;
 import com.java110.utils.cache.CommonCache;
@@ -109,26 +110,74 @@ public class OwnerAppLoginSMOImpl extends AbstractFrontServiceSMO implements IOw
         }
     }
 
+    @Override
+    public ResponseEntity<String> doLoginByKey(IPageData pd) throws SMOException {
+        JSONObject paramIn = JSONObject.parseObject(pd.getReqData());
+        Assert.hasKeyAndValue(paramIn, "key", "请求报文中未包含临时秘钥");
+        logger.debug("doLogin入参:" + paramIn.toJSONString());
+        ResponseEntity<String> responseEntity;
+
+        JSONObject loginInfo = JSONObject.parseObject(pd.getReqData());
+
+        UserDto userDto = new UserDto();
+        userDto.setKey(paramIn.getString("key"));
+        userDto = super.postForApi(pd, userDto, ServiceCodeConstant.SERVICE_CODE_USER_LOGIN, UserDto.class);
+
+
+        //根据用户查询商户信息
+        String userId = userDto.getUserId();
+
+        pd = PageData.newInstance().builder(userId, "", "", pd.getReqData(),
+                "", "", "", "",
+                pd.getAppId());
+        OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
+        ownerAppUserDto.setUserId(userId);
+        List<OwnerAppUserDto> ownerAppUserDtos = super.getForApis(pd, ownerAppUserDto, ServiceCodeConstant.LIST_APPUSERBINDINGOWNERS, OwnerAppUserDto.class);
+
+
+        if (ownerAppUserDtos == null || ownerAppUserDtos.size() < 1) {
+            responseEntity = new ResponseEntity<>("用户未绑定业主", HttpStatus.BAD_REQUEST);
+            return responseEntity;
+        }
+
+        JSONObject appUser = JSONObject.parseObject(JSONObject.toJSONString(ownerAppUserDtos.get(0)));
+        appUser.put("userId", userId);
+        appUser.put("userName", paramIn.getString("username"));
+        JSONObject paramOut = new JSONObject();
+        paramOut.put("code", 0);
+        paramOut.put("msg", "成功");
+        paramOut.put("owner", appUser);
+        paramOut.put("token", userDto.getToken());
+        paramOut.put("key", userDto.getKey());
+        return new ResponseEntity<>(paramOut.toJSONString(), HttpStatus.OK);
+
+    }
+
     @Override
     public ResponseEntity<String> getPageAccessToken(IPageData pd) throws SMOException {
         JSONObject paramIn = JSONObject.parseObject(pd.getReqData());
         String authCode = paramIn.getString("code");
         String state = paramIn.getString("state");
-        String urlCode = CommonCache.getAndRemoveValue(paramIn.getString("urlCode"));
+        String paramStr = CommonCache.getAndRemoveValue(paramIn.getString("urlCode"));
 
-        if (StringUtil.isEmpty(urlCode)) {
-            return ResultVo.redirectPage("/#/pages/login/login");
+        if (StringUtil.isEmpty(paramStr)) {
+            return ResultVo.redirectPage("/");
         }
 
+        JSONObject param = JSONObject.parseObject(paramStr);
+        String redirectUrl = param.getString("redirectUrl");
+        String errorUrl = param.getString("errorUrl");
+
+
         String url = WechatConstant.APP_GET_ACCESS_TOKEN_URL.replace("APPID", wechatAuthProperties.getWechatAppId())
                 .replace("SECRET", wechatAuthProperties.getWechatAppSecret())
                 .replace("CODE", authCode);
 
         ResponseEntity<String> paramOut = outRestTemplate.getForEntity(url, String.class);
 
-        logger.debug("调用微信换去token ", paramOut);
+        logger.debug("调用微信换去openId ", paramOut);
         if (paramOut.getStatusCode() != HttpStatus.OK) {
-            return ResultVo.redirectPage("/#/pages/login/login");
+            return ResultVo.redirectPage(errorUrl);
 
         }
 
@@ -149,7 +198,7 @@ public class OwnerAppLoginSMOImpl extends AbstractFrontServiceSMO implements IOw
             //将openId放到redis 缓存,给前段下发临时票据
             String code = UUID.randomUUID().toString();
             CommonCache.setValue(code, openId, expireTime);
-            return ResultVo.redirectPage("/#/pages/login/login?code=" + code);
+            return ResultVo.redirectPage(errorUrl + "?code=" + code);
         }
 
         // String accessToken = paramObj.getString("access_token");//暂时不用
@@ -163,7 +212,12 @@ public class OwnerAppLoginSMOImpl extends AbstractFrontServiceSMO implements IOw
         } catch (Exception e) {
             logger.error("创建token失败");
         }
-        return ResultVo.redirectPage("/");
+        //查询用户key
+        UserDto userDto = new UserDto();
+        userDto.setUserId(ownerAppUserDtos.get(0).getUserId());
+        UserDto tmpUserDto = super.getForApi(pd, userDto, ServiceCodeConstant.QUERY_USER_SECRET, UserDto.class);
+        redirectUrl = redirectUrl + (redirectUrl.indexOf("?") > 0 ? "&key=" + tmpUserDto.getKey() : "?key=" + tmpUserDto.getKey());
+        return ResultVo.redirectPage(redirectUrl);
 
     }
 
@@ -178,10 +232,15 @@ public class OwnerAppLoginSMOImpl extends AbstractFrontServiceSMO implements IOw
      * @throws SMOException
      */
     @Override
-    public ResponseEntity<String> refreshToken(IPageData pd, String redirectUrl, HttpServletRequest request, HttpServletResponse response) throws SMOException {
+    public ResponseEntity<String> refreshToken(IPageData pd, String redirectUrl,
+                                               String errorUrl,
+                                               HttpServletRequest request, HttpServletResponse response) throws SMOException {
         //分配urlCode
         String urlCode = UUID.randomUUID().toString();
-        CommonCache.setValue(urlCode, redirectUrl, expireTime);
+        JSONObject param = new JSONObject();
+        param.put("redirectUrl", redirectUrl);
+        param.put("errorUrl", errorUrl);
+        CommonCache.setValue(urlCode, param.toJSONString(), expireTime);
 
         URL url = null;
         String openUrl = "";