浏览代码

一体化登录接口

hym 4 年之前
父节点
当前提交
0894d58a06
共有 15 个文件被更改,包括 582 次插入3 次删除
  1. 8 1
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/WebSecurityConfig.java
  2. 58 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/platform/PlatformAuthenticationProvider.java
  3. 58 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/platform/PlatformAuthenticationToken.java
  4. 55 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/platform/PlatformCheckUserFilter.java
  5. 9 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/platform/PlatformException.java
  6. 94 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/platform/PlatformLoginAuthenticationFilter.java
  7. 214 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/platform/PlatformLoginUserDetailService.java
  8. 49 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/platform/PlatformSecurityConfig.java
  9. 9 0
      smart-city-platform/src/main/java/com/bz/smart_city/controller/UserController.java
  10. 3 0
      smart-city-platform/src/main/java/com/bz/smart_city/dao/UserMapper.java
  11. 2 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/UserService.java
  12. 8 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/UserServiceImpl.java
  13. 4 1
      smart-city-platform/src/main/resources/application-dev.properties
  14. 4 1
      smart-city-platform/src/main/resources/application-sit.properties
  15. 7 0
      smart-city-platform/src/main/resources/mapper/UserMapper.xml

+ 8 - 1
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/WebSecurityConfig.java

@@ -7,6 +7,7 @@ import com.bz.smart_city.commom.security.assistant.openid.OpenidSecurityConfig;
 import com.bz.smart_city.commom.security.integration.IntegrationSecurityConfig;
 import com.bz.smart_city.commom.security.mobile.MobileLoginUserDetailService;
 import com.bz.smart_city.commom.security.mobile.MobileSecurityConfig;
+import com.bz.smart_city.commom.security.platform.PlatformSecurityConfig;
 import com.bz.smart_city.commom.security.smsCode.SmsCodeCheckUserFilter;
 import com.bz.smart_city.commom.security.smsCode.SmsCodeSecurityConfig;
 import com.bz.smart_city.commom.security.validate.ValidateCodeCheckFilter;
@@ -80,6 +81,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
     private IntegrationSecurityConfig integrationSecurityConfig;
     @Autowired
     private AppSecurityConfig appSecurityConfig;
+    @Autowired
+    private PlatformSecurityConfig platformSecurityConfig;
 
     @Bean
     public PasswordEncoder passwordEncoder() {
@@ -112,6 +115,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .antMatchers("/platform/**")
                 .antMatchers("/device/valve/update").antMatchers("/message/generatedMessage")
                 .antMatchers("/integration/user/save","/integration/user/del")
+                .antMatchers("/user/bindUniqId")
                 .antMatchers("/rabbit/**").antMatchers("/meter/updateUserCode","/meter/getMeterReadList");
 
     }
@@ -154,7 +158,10 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .and()
                 .apply(integrationSecurityConfig)
                 .and()
-                .apply(appSecurityConfig);
+                .apply(appSecurityConfig)
+                .and().
+                apply(platformSecurityConfig)
+        ;
 
     }
 

+ 58 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/platform/PlatformAuthenticationProvider.java

@@ -0,0 +1,58 @@
+package com.bz.smart_city.commom.security.platform;
+
+import com.bz.smart_city.commom.security.mobile.MobileLoginAuthenticationToken;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.security.authentication.AuthenticationProvider;
+import org.springframework.security.authentication.InternalAuthenticationServiceException;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.util.Assert;
+
+@Slf4j
+public class PlatformAuthenticationProvider implements AuthenticationProvider {
+
+    private UserDetailsService userDetailsService;
+
+    private PasswordEncoder passwordEncoder;
+
+    @Override
+    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
+        PlatformAuthenticationToken authenticationToken = (PlatformAuthenticationToken) authentication;
+        UserDetails userDetails = userDetailsService.loadUserByUsername((String) authenticationToken.getPrincipal());
+        if (userDetails == null) {
+            throw new InternalAuthenticationServiceException("无法获取用户信息");
+        }
+        String presentedPassword = authenticationToken.getCredentials().toString();
+
+        PlatformAuthenticationToken platformAuthenticationToken = new PlatformAuthenticationToken(userDetails,authenticationToken.getCredentials(),userDetails.getAuthorities());
+
+        platformAuthenticationToken.setDetails(authenticationToken.getDetails());
+
+        return platformAuthenticationToken;
+    }
+
+    @Override
+    public boolean supports(Class<?> authentication) {
+        return PlatformAuthenticationToken.class.isAssignableFrom(authentication);
+    }
+
+    public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
+        Assert.notNull(passwordEncoder, "passwordEncoder cannot be null");
+        this.passwordEncoder = passwordEncoder;
+    }
+
+    protected PasswordEncoder getPasswordEncoder() {
+        return passwordEncoder;
+    }
+
+    public UserDetailsService getUserDetailsService() {
+        return userDetailsService;
+    }
+
+    public void setUserDetailsService(UserDetailsService userDetailsService) {
+        this.userDetailsService = userDetailsService;
+    }
+}

+ 58 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/platform/PlatformAuthenticationToken.java

@@ -0,0 +1,58 @@
+package com.bz.smart_city.commom.security.platform;
+
+import org.springframework.security.authentication.AbstractAuthenticationToken;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.SpringSecurityCoreVersion;
+
+import java.util.Collection;
+
+public class PlatformAuthenticationToken  extends AbstractAuthenticationToken {
+    private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
+
+    /**
+     * 手机号
+     */
+    private final Object principal;
+    private Object credentials;
+
+
+    public PlatformAuthenticationToken(String mobile, Object credentials) {
+        super(null);
+        this.principal = mobile;
+        this.credentials = credentials;
+        setAuthenticated(false);
+    }
+
+    public PlatformAuthenticationToken(Object principal,Object credentials, Collection<? extends GrantedAuthority> authorities) {
+        super(authorities);
+        this.principal = principal;
+        this.credentials = credentials;
+        super.setAuthenticated(true);
+    }
+
+    @Override
+    public Object getCredentials() {
+        return this.credentials;
+    }
+
+    @Override
+    public Object getPrincipal() {
+        return this.principal;
+    }
+    /**
+     * @param isAuthenticated
+     * @throws IllegalArgumentException
+     */
+    @Override
+    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
+        if (isAuthenticated) {
+            throw new IllegalArgumentException("Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
+        }
+        super.setAuthenticated(false);
+    }
+
+    @Override
+    public void eraseCredentials() {
+        super.eraseCredentials();
+    }
+}

+ 55 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/platform/PlatformCheckUserFilter.java

@@ -0,0 +1,55 @@
+package com.bz.smart_city.commom.security.platform;
+
+import com.bz.smart_city.commom.security.smsCode.SmsCodeException;
+import com.bz.smart_city.commom.util.ByteArrayUtils;
+import com.bz.smart_city.commom.util.RedisUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.security.web.authentication.AuthenticationFailureHandler;
+import org.springframework.stereotype.Component;
+import org.springframework.web.context.request.ServletWebRequest;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+
+/**
+ * 验证码验证
+ */
+@Component
+public class PlatformCheckUserFilter extends OncePerRequestFilter {
+
+    @Autowired
+    @Qualifier("userAuthenticationFailureHandler")
+    private AuthenticationFailureHandler userAuthenticationFailureHandler;
+    @Value("${server.servlet.context-path}")
+    private String contextPath;
+    @Autowired
+    RedisUtil redisUtil;
+    @Value("${spring.profiles.active}")
+    private String active;
+
+    @Override
+    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
+        if (StringUtils.equals(contextPath+"/user/platformLogin888", request.getRequestURI()) && StringUtils.equalsIgnoreCase(request.getMethod(), "post")) {
+            try {
+                validate(new ServletWebRequest(request));
+            } catch (SmsCodeException e) {
+                userAuthenticationFailureHandler.onAuthenticationFailure(request, response, e);
+                return;
+            }
+        }
+        filterChain.doFilter(request, response);
+    }
+
+    private void validate(ServletWebRequest servletWebRequest) {
+
+        String mobile = servletWebRequest.getParameter("code");
+    }
+}

+ 9 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/platform/PlatformException.java

@@ -0,0 +1,9 @@
+package com.bz.smart_city.commom.security.platform;
+
+import org.springframework.security.core.AuthenticationException;
+
+public class PlatformException extends AuthenticationException {
+    public PlatformException(String msg) {
+        super(msg);
+    }
+}

+ 94 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/platform/PlatformLoginAuthenticationFilter.java

@@ -0,0 +1,94 @@
+package com.bz.smart_city.commom.security.platform;
+
+import com.bz.smart_city.commom.security.mobile.MobileLoginAuthenticationToken;
+import org.springframework.security.authentication.AuthenticationServiceException;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
+import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
+import org.springframework.util.Assert;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class PlatformLoginAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
+    // ~ Static fields/initializers
+    // =====================================================================================
+
+    public static final String SPRING_SECURITY_FORM_MOBILE_KEY = "code";
+    public static final String SPRING_SECURITY_FORM_PASSWORD_KEY = "password";
+
+    private String mobileParameter = SPRING_SECURITY_FORM_MOBILE_KEY;
+    private String passwordParameter = SPRING_SECURITY_FORM_PASSWORD_KEY;
+    private boolean postOnly = true;
+
+    // ~ Constructors
+    // ===================================================================================================
+
+    public PlatformLoginAuthenticationFilter() {
+        super(new AntPathRequestMatcher("/user/platformLogin", "POST"));
+    }
+
+    // ~ Methods
+    // ========================================================================================================
+
+    @Override
+    public Authentication attemptAuthentication(HttpServletRequest request,
+                                                HttpServletResponse response) throws AuthenticationException {
+        if (postOnly && !request.getMethod().equals("POST")) {
+            throw new AuthenticationServiceException(
+                    "Authentication method not supported: " + request.getMethod());
+        }
+
+        String mobile = obtainMobile(request);
+
+
+
+        mobile = mobile.trim();
+
+        PlatformAuthenticationToken authRequest = new PlatformAuthenticationToken(mobile, "");
+
+        // Allow subclasses to set the "details" property
+        setDetails(request, authRequest);
+
+        return this.getAuthenticationManager().authenticate(authRequest);
+    }
+
+    private String obtainMobile(HttpServletRequest request) {
+        return request.getParameter(mobileParameter);
+    }
+
+
+    protected String obtainPassword(HttpServletRequest request) {
+        return request.getParameter(passwordParameter);
+    }
+
+
+    protected void setDetails(HttpServletRequest request, PlatformAuthenticationToken authRequest) {
+        authRequest.setDetails(authenticationDetailsSource.buildDetails(request));
+    }
+
+
+    public void setMobileParameter(String mobileParameter) {
+        Assert.hasText(mobileParameter, "Username parameter must not be empty or null");
+        this.mobileParameter = mobileParameter;
+    }
+
+
+    public void setPasswordParameter(String passwordParameter) {
+        Assert.hasText(passwordParameter, "Password parameter must not be empty or null");
+        this.passwordParameter = passwordParameter;
+    }
+
+    public void setPostOnly(boolean postOnly) {
+        this.postOnly = postOnly;
+    }
+
+    public final String getmobileParameter() {
+        return mobileParameter;
+    }
+
+    public final String getPasswordParameter() {
+        return passwordParameter;
+    }
+}

+ 214 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/platform/PlatformLoginUserDetailService.java

@@ -0,0 +1,214 @@
+package com.bz.smart_city.commom.security.platform;
+
+import com.alibaba.fastjson.JSONObject;
+import com.bz.smart_city.commom.security.validate.ValidateCodeException;
+import com.bz.smart_city.commom.util.ByteArrayUtils;
+import com.bz.smart_city.commom.util.RedisUtil;
+import com.bz.smart_city.dao.*;
+import com.bz.smart_city.dto.LoginUser;
+import com.bz.smart_city.dto.SiteUserDto;
+import com.bz.smart_city.entity.*;
+import com.bz.smart_city.service.PermissionService;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.security.authentication.DisabledException;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+@Component
+public class PlatformLoginUserDetailService implements UserDetailsService {
+    @Resource
+    private UserMapper userMapper;
+    @Resource
+    private PermissionService permissionService;
+    @Resource
+    private SiteUserMapper siteUserMapper;
+    @Resource
+    private SiteMapper siteMapper;
+    @Resource
+    private ProgramMapper programMapper;
+    @Resource
+    private ProgramItemMapper programItemMapper;
+    @Resource
+    private CustomerMapper customerMapper;
+    @Autowired
+    private RedisUtil redisUtil;
+
+    @Value("${platform_appid}")
+    private String appId;
+
+    @Value("${platform_appSecret}")
+    private String appSecret;
+    @Value("${platform_url}")
+     private String url;
+
+    private String sendApiReQuest(String path ,  Map<String, Object> map){
+
+        RestTemplate restTemplate=new RestTemplate();
+        ResponseEntity<String> res = restTemplate.getForEntity(path,String.class,map);
+        String body = res.getBody();
+        JSONObject info = JSONObject.parseObject(body);
+        String result=null;
+        if(info.getInteger("status")==0){
+            result=info.getString("data");
+        }
+        return result;
+    }
+    @Override
+    public UserDetails loadUserByUsername(String code) throws UsernameNotFoundException {
+        JSONObject jsonObject=new JSONObject();
+        jsonObject.put("appId",appId);
+        jsonObject.put("appSecret",appSecret);
+        jsonObject.put("code",code);
+        String uniqId = sendApiReQuest(url, jsonObject);
+
+        User user =userMapper.findUserByUniqId(uniqId);
+
+        if (user == null) {
+            String key= UUID.randomUUID().toString();
+            if(uniqId!=null)
+            redisUtil.set(key,uniqId);
+            redisUtil.setExpire(key,1800);
+            throw new PlatformException(key);
+        }
+
+        //判断是否禁用
+        if (user.getStatus() == 2) {
+            throw new DisabledException("账号已被禁用");
+        }
+        LoginUser loginUser = new LoginUser();
+        BeanUtils.copyProperties(user, loginUser);
+
+        Map<Integer, List<Permission>> permissionMap = new HashMap<>();
+        Map<Integer, List<ProgramItem>> datePermissionMap = new HashMap<>();
+        if (user.getIsSuperAdmin() == 1) {
+            //超级管理员的权限
+            List<Permission> permissions = permissionService.getPermissionBySuperAdmin();
+            permissionMap.put(0, permissions);
+            loginUser.setCurrentSiteId(0);
+            loginUser.setType(1);
+        } else  {
+            //站点管理员(多站点)
+            Integer siteId = null;
+            List<Site> siteList = siteUserMapper.getSiteByUserId(user.getId());
+            List<SiteUserDto> siteV2List = siteUserMapper.getSiteByUserIdV2(user.getId());
+            if (siteList == null || siteList.size() == 0) {
+                throw new ValidateCodeException("该用户未关联站点");
+            }
+
+            siteV2List.forEach(site -> {
+                if(site.getUserType() == 2){
+                    List<Permission> permissions = permissionService.getPermissionBySiteAdminV2(site.getId(),site.getType());;
+                    permissionMap.put(site.getId(), permissions);
+                }else {
+                    permissionMap.put(site.getId(), permissionService.getPermissionByUserId(user.getId(), site.getId()));
+                }
+
+
+                List<ProgramItem> programItemList = programItemMapper.getBySiteIdAndUserId(site.getId(), user.getId());
+                if (programItemList != null && programItemList.size() > 0) {
+                    datePermissionMap.put(site.getId(), programItemList);
+                }
+            });
+            permissionMap.put(0, newArrayList());
+
+
+            String key = "useSelectSiteId:" + user.getId();
+            byte[] useSelectSiteIdByte = redisUtil.get(key.getBytes());
+            if (useSelectSiteIdByte != null) {
+                Integer useSelectSiteId = (Integer) ByteArrayUtils.bytesToObject(useSelectSiteIdByte).get();
+                if (!checkSite(siteList, useSelectSiteId)) {
+                    siteId = siteList.size()>0?siteList.get(0).getId():0;
+                    //保存redis
+                    redisUtil.setExpire(key.getBytes(), ByteArrayUtils.objectToBytes(siteId).get());
+                }else {
+                    siteId = useSelectSiteId;
+                }
+            }else {
+                siteId = siteList.size()>0?siteList.get(0).getId():0;
+                //保存redis
+                redisUtil.setExpire(key.getBytes(), ByteArrayUtils.objectToBytes(siteId).get());
+            }
+
+
+            SiteUser siteUser = siteUserMapper.findBySiteIdAndUserId(siteId,user.getId());
+
+            loginUser.setType(siteUser.getType());
+            loginUser.setOrgId(siteUser.getOrganId());
+            loginUser.setSiteId(siteId);
+            loginUser.setCurrentSiteId(siteId);
+            loginUser.setSiteList(siteList);
+            loginUser.setIsSiteAdmin(siteUser.getIsAdmin());//站点管理员
+            loginUser.setSiteType(checkSiteType(siteList,siteId));
+
+            Site site = siteMapper.findById(siteId);
+            loginUser.setCustomerId(site.getCustomerId());
+            loginUser.setCustomerName(site.getCustomerName());
+            loginUser.setOrgId(siteUser.getOrganId());
+
+            //查询数据权限
+
+        }
+
+        /*else {
+            //查询平台用户的站点
+            Site site = siteUserMapper.findSiteByUserId(user.getId());
+            if (site != null) {
+                List<Site> siteList = newArrayList();
+                siteList.add(site);
+                loginUser.setSiteId(site.getId());
+                loginUser.setCurrentSiteId(site.getId());
+                loginUser.setSiteList(siteList);
+
+                //查询功能权限
+                permissionMap.put(site.getId(), permissionService.getPermissionByUserId(user.getId(), null));
+                //查询数据权限
+                datePermissionMap.put(site.getId(), programItemMapper.getBySiteIdAndUserId(site.getId(), user.getId()));
+            }
+        }*/
+
+
+        /*Customer customer = null;
+        if(loginUser.getOrgId()!=null) {
+            customer = customerMapper.findByOrgId(loginUser.getOrgId());
+            //loginUser.setOrgId(user.getOrganId());
+        }
+        if(customer!=null)
+          loginUser.setCustomerId(customer.getId());*/
+        loginUser.setPermissionMap(permissionMap);
+        loginUser.setDataPermissionMap(datePermissionMap);
+        return loginUser;
+    }
+
+    //判断siteList中是否包含siteId
+    private boolean checkSite(List<Site> siteList, Integer siteId) {
+        return siteList.parallelStream().anyMatch(site -> site.getId().equals(siteId));
+    }
+
+    private Integer checkSiteType(List<Site> siteList, Integer siteId) {
+        Integer siteType = null;
+        for (Site site : siteList) {
+            if(site.getId().equals(siteId)){
+                siteType =  site.getType();
+                break;
+            }
+        }
+        return siteType;
+    }
+}

+ 49 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/platform/PlatformSecurityConfig.java

@@ -0,0 +1,49 @@
+package com.bz.smart_city.commom.security.platform;
+
+import com.bz.smart_city.commom.security.mobile.MobileLoginUserDetailService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.annotation.Bean;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.security.web.DefaultSecurityFilterChain;
+import org.springframework.security.web.authentication.AuthenticationFailureHandler;
+import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
+import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
+import org.springframework.stereotype.Component;
+
+@Component
+public class PlatformSecurityConfig extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
+    @Autowired
+    @Qualifier("userAuthenticationSuccessHandler")
+    private AuthenticationSuccessHandler authenticationSuccessHandler;
+    @Autowired
+    @Qualifier("userAuthenticationFailureHandler")
+    private AuthenticationFailureHandler authenticationFailureHandler;
+    @Autowired
+    private PlatformLoginUserDetailService userDetailsService;
+    @Autowired
+    private PlatformCheckUserFilter smsCodeCheckUserFilter;
+    @Bean
+    public PasswordEncoder passwordEncoder() {
+        return new BCryptPasswordEncoder();
+    }
+
+
+
+    @Override
+    public void configure(HttpSecurity http) throws Exception {
+        PlatformLoginAuthenticationFilter platformLoginAuthenticationFilter = new PlatformLoginAuthenticationFilter();
+        platformLoginAuthenticationFilter.setAuthenticationManager(http.getSharedObject(AuthenticationManager.class));
+        platformLoginAuthenticationFilter.setAuthenticationSuccessHandler(authenticationSuccessHandler);
+        platformLoginAuthenticationFilter.setAuthenticationFailureHandler(authenticationFailureHandler);
+
+        PlatformAuthenticationProvider platformAuthenticationProvider = new PlatformAuthenticationProvider();
+        platformAuthenticationProvider.setUserDetailsService(userDetailsService);
+        http.authenticationProvider(platformAuthenticationProvider)
+                .addFilterAfter(platformLoginAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
+    }
+}

+ 9 - 0
smart-city-platform/src/main/java/com/bz/smart_city/controller/UserController.java

@@ -275,4 +275,13 @@ public class UserController {
         userService.bindOpenId(openId);
         return new AjaxMessage(ResultStatus.OK);
     }
+    @PostMapping("bindUniqId")
+    @ApiOperation(value = "绑定一体化id")
+    public AjaxMessage bindUniqId(
+            @ApiParam(value = "phone", required = true) @RequestParam(required = true) String phone,
+            @ApiParam(value = "platformKey", required = true) @RequestParam(required = true) String platformKey
+    ) {
+        userService.bindUniqId(phone,platformKey);
+        return new AjaxMessage(ResultStatus.OK);
+    }
 }

+ 3 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/UserMapper.java

@@ -73,5 +73,8 @@ public interface UserMapper {
 
     User findUserByName(@Param("name") String  name,@Param("sitId") BigInteger sitId);
 
+    User findUserByUniqId(String uniqId);
+
+    int bindUniqId(@Param("phone") String phone,@Param("uniqId")  String uniqId);
 }
 

+ 2 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/UserService.java

@@ -121,4 +121,6 @@ public interface UserService {
     void addIntegrationUser(String username, String mobilePhone);
 
     void delectIntegrationUser(String mobilePhone);
+
+    int bindUniqId(String phone, String platformKey);
 }

+ 8 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/UserServiceImpl.java

@@ -714,4 +714,12 @@ public class UserServiceImpl implements UserService {
             int result = userExtendInfoMapper.update(obj);
         }
     }
+
+    @Override
+    public int bindUniqId(String phone, String platformKey) {
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        String uniqId=redisUtil.get(platformKey);
+        return userMapper.bindUniqId(phone,uniqId);
+
+    }
 }

+ 4 - 1
smart-city-platform/src/main/resources/application-dev.properties

@@ -182,4 +182,7 @@ sync.customer.wuhan.id=136
 spring.data.mongodb.uri=mongodb://water:zcxk100@114.135.61.189:27071/meter-reading-database?authSource=meter-reading-database
 logging.level.org.springframework.data.mongodb.core=DEBUG
 account_userInfo_url=http://114.135.61.188:58084/api/pay/getAccountInfoByMetercode
-sync_customer_no_url=http://114.135.61.188:58084/api/customer/synCustomer
+sync_customer_no_url=http://114.135.61.188:58084/api/customer/synCustomer
+platform_appid=1001
+platform_appSecret=123456
+platform_url=http://114.135.61.187:38081/user-auth/user/getUniqId?appId={appId}&appSecret={appSecret}&code={code}

+ 4 - 1
smart-city-platform/src/main/resources/application-sit.properties

@@ -184,4 +184,7 @@ sync.customer.wuhan.id=136
 spring.data.mongodb.uri=mongodb://114.135.61.188:17017/meter-reading-database
 logging.level.org.springframework.data.mongodb.core=DEBUG
 account_userInfo_url=http://114.135.61.188:58084/api/pay/getAccountInfoByMetercode
-sync_customer_no_url=http://114.135.61.188:58084/api/customer/synCustomer
+sync_customer_no_url=http://114.135.61.188:58084/api/customer/synCustomer
+platform_appid=1001
+platform_appSecret=123456
+platform_url=http://114.135.61.187:38081/user-auth/user/getUniqId?appId={appId}&appSecret={appSecret}&code={code}

+ 7 - 0
smart-city-platform/src/main/resources/mapper/UserMapper.xml

@@ -355,6 +355,7 @@
                 <if test="user.updateDate != null"> update_date = #{user.updateDate,jdbcType=TIMESTAMP},</if>
                 <if test="user.updateBy != null"> update_by = #{user.updateBy,jdbcType=VARCHAR},</if>
                 <if test="user.openid != null"> openid = #{user.openid,jdbcType=VARCHAR}</if>
+                <if test="user.uniqid != null"> uniq_id = #{user.uniqid,jdbcType=VARCHAR}</if>
         </set>
 		WHERE id = #{user.id,jdbcType=INTEGER}
     </update>
@@ -491,6 +492,9 @@
             and user_id in <foreach collection="userIds" item="item" open="(" separator="," close=")">#{item}</foreach>
         </if>
     </update>
+    <update id="bindUniqId">
+        update sc_user set uniq_id=#{uniqId} where mobile_phone=#{phone} and status=1 and uniq_id is null
+    </update>
 
     <select id="findUserByMobilePhoneUnique" resultType="int">
         select count(1) from sc_user where status = 1 and mobile_phone = #{mobilePhone}
@@ -523,6 +527,9 @@
     inner join sc_user scuser on scsuser.user_id= scuser.id
     where scsuser.site_id=#{sitId} and scuser.name=#{name} limit 1
   </select>
+    <select id="findUserByUniqId" resultType="com.bz.smart_city.entity.User">
+        SELECT * FROM sc_user WHERE status != 0 and uniq_id = #{uniqId}
+    </select>
 
 
 </mapper>