Browse Source

移动端验证码 登录功能开发

user5 8 tháng trước cách đây
mục cha
commit
09c075680b
18 tập tin đã thay đổi với 2582 bổ sung5 xóa
  1. 5 0
      jeeplus-platform/jeeplus-admin/pom.xml
  2. 14 4
      jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/security/config/WebSecurityConfig.java
  3. 32 1
      jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/controller/LoginController.java
  4. 158 0
      jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/controller/UserController.java
  5. 7 0
      jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/mapper/UserMapper.java
  6. 37 0
      jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/mapper/xml/UserMapper.xml
  7. 6 0
      jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/model/LoginForm.java
  8. 12 0
      jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/service/UserService.java
  9. 1786 0
      jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/sms/CCPRestSDK.java
  10. 66 0
      jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/sms/CcopHttpClient.java
  11. 78 0
      jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/sms/DateUtil.java
  12. 62 0
      jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/sms/EncryptUtil.java
  13. 61 0
      jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/sms/LoggerUtil.java
  14. 45 0
      jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/sms/PropertiesUtil.java
  15. 196 0
      jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/sms/SMSUtils.java
  16. 9 0
      jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/utils/UserUtils.java
  17. 1 0
      jeeplus-platform/jeeplus-common/src/main/java/com/jeeplus/core/errors/ErrorConstants.java
  18. 7 0
      jeeplus-web/src/main/resources/application-development.yml

+ 5 - 0
jeeplus-platform/jeeplus-admin/pom.xml

@@ -35,6 +35,11 @@
             <artifactId>cas-client-core</artifactId>
             <version>3.5.1</version>
         </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <version>1.2.17</version>
+        </dependency>
     </dependencies>
 
 

+ 14 - 4
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/security/config/WebSecurityConfig.java

@@ -5,12 +5,12 @@ import com.jeeplus.security.exception.JwtAuthenticationEntryPoint;
 import com.jeeplus.security.jwt.JWTConfigurer;
 import com.jeeplus.security.jwt.TokenProvider;
 import com.jeeplus.security.service.CustomUserDetailsService;
+import com.jeeplus.security.util.DaoAuthenticationProvider;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.core.annotation.Order;
 import org.springframework.http.HttpMethod;
 import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
 import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
 import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -37,7 +37,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
      */
     @Override
     protected void configure(AuthenticationManagerBuilder auth) throws Exception {
-        DaoAuthenticationProvider provider = new DaoAuthenticationProvider ( );
+        DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
         // 设置不隐藏 未找到用户异常
         provider.setHideUserNotFoundExceptions ( true );
         // 用户认证service - 查询数据库的逻辑
@@ -69,14 +69,24 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                         "/weboffice/**",
                         "/ReportServer/**",
                         "/sys/login",
+                        "/sys/loginGetToken",
                         "/app/sys/login",
                         "/sys/sysConfig/getConfig",
                         "/getAppFlowChart",
                         "/sys/getCode",
-                        "/app/sys/getCode",
+                        "/sys/logout",
+                        "/test/savePwd",
+                        "/sys/getLoginCodeNumber",
+                        "/cwProjectReport/signatureCallBack/**",
                         "/app/file/download",
                         "/file/download",
-                        "/sys/casLogin" ).permitAll ( ) // 允许请求无需认证
+                        "/sys/casLogin",
+                        "/app/sys/getCode",
+                        "/sys/casLogin",
+                        "/app/luckyDraw/**",
+                        "/sys/user/saveNewPassword",
+                        "/app/sys/user/getLoginPhoneCode",
+                        "/app/sys/user/getPhoneCode").permitAll() // 允许请求无需认证
                 .antMatchers ( HttpMethod.OPTIONS, "/**" ).permitAll ( )
                 .anyRequest ( ).authenticated ( ) // 所有请求都需要验证
                 .and ( )

+ 32 - 1
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/controller/LoginController.java

@@ -24,6 +24,7 @@ import com.jeeplus.sys.utils.UserUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.jasig.cas.client.authentication.AttributePrincipal;
 import org.jasig.cas.client.validation.Assertion;
 import org.jasig.cas.client.validation.Cas20ServiceTicketValidator;
@@ -43,6 +44,7 @@ import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.util.Date;
+import java.util.List;
 import java.util.UUID;
 
 /**
@@ -78,9 +80,38 @@ public class LoginController {
         ResponseUtil responseUtil = new ResponseUtil ( );
         String username = loginForm.getUsername ( );
         String password = loginForm.getPassword ( );
-        String code = loginForm.getCode ( );
+        String loginPhoneCode = loginForm.getLoginPhoneCode ( );
+
+        // 判断当前页面输入的验证码是否与redis中存储的验证码匹配
+        String redisCode = (String) redisUtils.get(username + "loginPassword");
+        if(StringUtils.isBlank(password)){
+            if(StringUtils.isNotBlank(loginPhoneCode)){
+                if ( !loginPhoneCode.equals ( redisCode) ) {
+                    return ResponseEntity.badRequest ( ).body ( ErrorConstants.LOGIN_ERROR_ERROR_VALIDATE_CODE );
+                }
+            }else{
+                return ResponseEntity.badRequest ( ).body ( ErrorConstants.LOGIN_CODE );
+            }
+            password = "jsxgpassword";
+        }
+
+        /*String code = loginForm.getCode ( );
         if ( !code.equals ( RedisUtils.getInstance ( ).get ( CacheNames.SYS_CACHE_CODE, loginForm.getUuid ( ) ) ) ) {
             return ResponseEntity.badRequest ( ).body ( ErrorConstants.LOGIN_ERROR_ERROR_VALIDATE_CODE );
+        }*/
+
+        //根据登录名查询登录信息
+        List<UserDTO> loginUserList = userService.getUserIdByLoginOrMobile(username);
+        if(null != loginUserList){
+            if (loginUserList.size()>1){
+                throw new DisabledException ( "手机号重复,请联系管理员" );
+            }else{
+                if(loginUserList.size()==0){
+                    throw new DisabledException ( "未找到登陆人员信息" );
+                }else{
+                    username = loginUserList.get(0).getLoginName();
+                }
+            }
         }
         SecurityUtils.login ( username, password, authenticationManager ); //登录操作spring security
 

+ 158 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/controller/UserController.java

@@ -3,7 +3,9 @@
  */
 package com.jeeplus.sys.controller;
 
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -11,6 +13,7 @@ import com.google.common.collect.Lists;
 import com.google.gson.Gson;
 import com.jeeplus.aop.demo.annotation.DemoMode;
 import com.jeeplus.aop.logging.annotation.ApiLog;
+import com.jeeplus.common.redis.RedisUtils;
 import com.jeeplus.common.utils.ResponseUtil;
 import com.jeeplus.core.excel.ExcelOptions;
 import com.jeeplus.core.excel.annotation.ExportMode;
@@ -29,6 +32,7 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -38,6 +42,7 @@ import java.io.IOException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 /**
  * 用户Controller
@@ -54,6 +59,9 @@ public class UserController {
     @Autowired
     private UserService userService;
 
+    @Autowired
+    private RedisUtils redisUtils;
+
     /**
      * 根据id查询用户
      *
@@ -281,4 +289,154 @@ public class UserController {
         return ResponseEntity.ok ( res );
     }
 
+
+    /**
+     * 通过手机号获取验证码(忘记密码)
+     * @param mobile 手机号码
+     * @return
+     */
+    @ApiOperation(value = "通过手机号获取验证码(登陆)")
+    @GetMapping(value = "/getLoginPhoneCode")
+    public ResponseEntity<HashMap<String,Object>> getLoginPhoneCode(@RequestParam("mobile") String mobile) {
+        HashMap<String,Object> j = new HashMap<String,Object>();
+        //验证该手机号是否已经进行注册
+        User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getMobile, mobile));
+        if (ObjectUtil.isNotEmpty( user )) {
+            //生成四位随机验证码
+            String randomCode = String.valueOf((int) (Math.random() * 9000 + 1000));
+            System.out.println(randomCode);
+            redisUtils.setEx(mobile+ "loginPassword", randomCode, 300, TimeUnit.SECONDS);
+            HashMap<String,Object> result = null;
+            j.put("success",true);
+            j.put("message","短信发送成功!");
+            /*try{
+                //调用工具类返回结果
+                result = UserUtils.sendRandomCodes(mobile, randomCode);
+                String statusCode = (String) result.get("statusCode");
+                if (("000000").equals(statusCode)) {
+                    j.put("success",true);
+                    j.put("message","短信发送成功!");
+                    //存放验证码
+                    //以手机号+为key 五分钟为时效 将验证码进行短期存储
+                    redisUtils.setEx(mobile+ "loginPassword", randomCode, 300, TimeUnit.SECONDS);
+                }else if(statusCode.equals("160040")){
+                    j.put("success",false);
+                    j.put("message","手机号获取验证码次数已达每日上限!");
+                }else{
+                    j.put("success",false);
+                    j.put("message","短信发送失败,错误代码:101,请联系管理员!");
+                    j.put("ErrorXml",result);
+                }
+            }catch (Exception e){
+                e.printStackTrace();
+                j.put("success",false);
+                j.put("message","短信发送失败!");
+            }*/
+        } else {
+            j.put("success",false);
+            j.put("message","当前手机号未注册!请联系管理员");
+        }
+        return ResponseEntity.ok(j);
+    }
+
+
+    /**
+     * 通过手机号获取验证码(忘记密码)
+     * @param mobile 手机号码
+     * @return
+     */
+    @ApiOperation(value = "通过手机号获取验证码(忘记密码)")
+    @GetMapping(value = "/getPhoneCode")
+    public ResponseEntity<HashMap<String,Object>> getPhoneCode(@RequestParam("mobile") String mobile) {
+        HashMap<String,Object> j = new HashMap<String,Object>();
+        //验证该手机号是否已经进行注册
+        User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getMobile, mobile));
+        if (ObjectUtil.isNotEmpty( user )) {
+            //生成四位随机验证码
+            String randomCode = String.valueOf((int) (Math.random() * 9000 + 1000));
+
+            j.put("success",true);
+            j.put("message","短信发送成功!");
+            //存放验证码
+            //以手机号+为key 五分钟为时效 将验证码进行短期存储
+            redisUtils.setEx(mobile+ "resetPassword", randomCode, 300, TimeUnit.SECONDS);
+            HashMap<String,Object> result = null;
+            /*try{
+                //调用工具类返回结果
+                result = UserUtils.sendRandomCodes(mobile, randomCode);
+                String statusCode = (String) result.get("statusCode");
+                if (("000000").equals(statusCode)) {
+                    j.put("success",true);
+                    j.put("message","短信发送成功!");
+                    //存放验证码
+                    //以手机号+为key 五分钟为时效 将验证码进行短期存储
+                    redisUtils.setEx(mobile+ "resetPassword", randomCode, 300, TimeUnit.SECONDS);
+                }else if(statusCode.equals("160040")){
+                    j.put("success",false);
+                    j.put("message","手机号获取验证码次数已达每日上限!");
+                }else{
+                    j.put("success",false);
+                    j.put("message","短信发送失败,错误代码:101,请联系管理员!");
+                    j.put("ErrorXml",result);
+                }
+            }catch (Exception e){
+                e.printStackTrace();
+                j.put("success",false);
+                j.put("message","短信发送失败!");
+            }*/
+        } else {
+            j.put("success",false);
+            j.put("message","当前手机号未注册!请联系管理员");
+        }
+        return ResponseEntity.ok(j);
+    }
+
+
+
+    /**
+     * 修改密码
+     * @param mobile
+     * @param code
+     * @param newPassword
+     * @return
+     */
+    @GetMapping(value = "/saveNewPassword")
+    @ApiOperation(value = "保存新密码")
+    @Transactional(rollbackFor = Exception.class)
+    public ResponseEntity<HashMap<String,Object>> saveNewPassword(@RequestParam("mobile") String mobile,
+                                                                  @RequestParam("code") String code,
+                                                                  @RequestParam("newPassword") String newPassword) {
+        HashMap<String,Object> j = new HashMap<String,Object>();
+        // 判断当前页面输入的验证码是否与redis中存储的验证码匹配
+        String redisCode = (String) redisUtils.get(mobile + "resetPassword");
+        if (org.apache.commons.lang3.StringUtils.isNotBlank(redisCode)) {
+            if (redisCode.equals( code )) {
+                // 进行密码修改操作
+                User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getMobile, mobile));
+                if (ObjectUtil.isNotEmpty( user )) {
+                    if (org.apache.commons.lang3.StringUtils.isNotBlank( newPassword )) {
+                        user.setPassword(SecurityUtils.encryptPassword ( newPassword ));
+                        userService.updateById( user ); // 修改密码
+                        redisUtils.delete(mobile + "resetPassword"); // 删除redis中的key
+                        j.put("success",true);
+                        j.put("message","密码修改成功!");
+                    } else {
+                        j.put("success",false);
+                        j.put("message","请输入有效密码!");
+                    }
+                } else {
+                    j.put("success",false);
+                    j.put("message","当前手机号未注册!");
+                }
+            } else {
+                j.put("success",false);
+                j.put("message","验证码输入不正确!");
+            }
+        } else {
+            j.put("success",false);
+            j.put("message","当前手机验证码已失效,请重新发送验证码!");
+        }
+        return ResponseEntity.ok(j);
+    }
+
 }

+ 7 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/mapper/UserMapper.java

@@ -103,4 +103,11 @@ public interface UserMapper extends BaseMapper <User> {
      */
     void insertUserPost(@Param("userId") String userId, @Param("postId") String postId);
 
+    /**
+     * getUserIdByLoginOrMobile
+     * @param userName
+     * @return
+     */
+    List<UserDTO> getUserIdByLoginOrMobile(String userName);
+
 }

+ 37 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/mapper/xml/UserMapper.xml

@@ -66,6 +66,32 @@
     	o.parent_ids AS "officeDTO.parentIds"
     </sql>
 
+
+    <sql id="userOfficeColumns">
+    	a.id,
+    	a.login_name AS "loginName",
+		a.is_admin AS "isAdmin",
+    	a.password,
+    	a.no,
+		a.name,
+		a.email,
+		a.phone,
+		a.mobile,
+		a.login_ip AS "loginIp",
+		a.login_date AS "loginDate",
+		a.remarks,
+		a.login_flag,
+		a.photo,
+		a.qr_code,
+		a.sign,
+        a.create_by_id AS "createBy.id",
+        a.create_time,
+        a.update_by_id AS "updateBy.id",
+        a.update_time,
+    	o.id AS "parent.id",
+    	o.parent_ids AS "parentIds"
+    </sql>
+
     <sql id="userJoins">
         LEFT JOIN sys_office c ON c.id = a.company_id
 		LEFT JOIN sys_office o ON o.id = a.office_id
@@ -157,4 +183,15 @@
         INSERT INTO sys_user_post(user_id, post_id)
         VALUES (#{userId}, #{postId})
     </insert>
+
+    <select id="getUserIdByLoginOrMobile" resultType="com.jeeplus.sys.service.dto.UserDTO">
+        SELECT
+        <include refid="userOfficeColumns"/>
+        FROM sys_user a
+        <include refid="userJoins"/>
+        <where>
+            a.del_flag = 0
+            and (login_name = #{userName} or mobile = #{userName})
+        </where>
+    </select>
 </mapper>

+ 6 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/model/LoginForm.java

@@ -21,6 +21,12 @@ public class LoginForm {
     private String password;
 
     /**
+     * 登陆验证码
+     */
+    @ApiModelProperty("登陆验证码")
+    private String loginPhoneCode;
+
+    /**
      * 验证码
      */
     @ApiModelProperty("验证码")

+ 12 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/service/UserService.java

@@ -44,6 +44,9 @@ public class UserService extends ServiceImpl <UserMapper, User> {
     @Autowired
     private SysConfigService sysConfigService;
 
+    @Autowired
+    private UserMapper userMapper;
+
 
     /**
      * 获取用户
@@ -212,4 +215,13 @@ public class UserService extends ServiceImpl <UserMapper, User> {
         user.setLoginDate(new Date ());
         super.updateById (user);
     }
+
+    /**
+     * 根据登录名或手机号获取用户信息
+     * @param loginName
+     * @return
+     */
+    public List<UserDTO> getUserIdByLoginOrMobile(String loginName) {
+        return userMapper.getUserIdByLoginOrMobile (loginName);
+    }
 }

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1786 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/sms/CCPRestSDK.java


+ 66 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/sms/CcopHttpClient.java

@@ -0,0 +1,66 @@
+package com.jeeplus.sys.sms;
+
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.impl.client.DefaultHttpClient;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.security.Principal;
+import java.security.SecureRandom;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+public class CcopHttpClient
+{
+  public DefaultHttpClient registerSSL(String hostname, String protocol, int port, String scheme)
+    throws NoSuchAlgorithmException, KeyManagementException
+  {
+    DefaultHttpClient httpclient = new DefaultHttpClient();
+
+    SSLContext ctx = SSLContext.getInstance(protocol);
+
+   X509TrustManager tm = new X509TrustManager()
+    {
+      public void checkClientTrusted(X509Certificate[] chain,String authType)
+			 throws CertificateException {
+      }
+
+      public void checkServerTrusted(X509Certificate[] chain,String authType)
+ 			 throws CertificateException {
+        if ((chain == null) || (chain.length == 0))
+          throw new IllegalArgumentException("null or zero-length certificate chain");
+        if ((authType == null) || (authType.length() == 0))
+          throw new IllegalArgumentException("null or zero-length authentication type");
+
+        boolean br = false;
+        Principal principal = null;
+       for (X509Certificate x509Certificate : chain) {   
+          principal = x509Certificate.getSubjectX500Principal();
+          if (principal != null) {
+            br = true;
+            return;
+          }
+        }
+        if (!(br))
+          throw new CertificateException("服务端证书验证失败!");
+      }
+
+      public X509Certificate[] getAcceptedIssuers()
+      {
+        return new X509Certificate[0];
+      }
+
+    };
+    ctx.init(null, new TrustManager[] { tm }, new SecureRandom());
+
+    SSLSocketFactory socketFactory = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+    Scheme sch = new Scheme(scheme, port, socketFactory);
+
+    httpclient.getConnectionManager().getSchemeRegistry().register(sch);
+    return httpclient;
+  }
+}

+ 78 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/sms/DateUtil.java

@@ -0,0 +1,78 @@
+/*
+ *  Copyright (c) 2014 The CCP project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license
+ *  that can be found in the LICENSE file in the root of the web site.
+ *
+ *   http://www.yuntongxun.com
+ *
+ *  An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+package com.jeeplus.sys.sms;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class DateUtil
+{
+  public static final int DEFAULT = 0;
+  public static final int YM = 1;
+  public static final int YMR_SLASH = 11;
+  public static final int NO_SLASH = 2;
+  public static final int YM_NO_SLASH = 3;
+  public static final int DATE_TIME = 4;
+  public static final int DATE_TIME_NO_SLASH = 5;
+  public static final int DATE_HM = 6;
+  public static final int TIME = 7;
+  public static final int HM = 8;
+  public static final int LONG_TIME = 9;
+  public static final int SHORT_TIME = 10;
+  public static final int DATE_TIME_LINE = 12;
+
+  public static String dateToStr(Date date, String pattern)
+  {
+    if ((date == null) || (date.equals("")))
+      return null;
+    SimpleDateFormat formatter = new SimpleDateFormat(pattern);
+    return formatter.format(date);
+  }
+
+  public static String dateToStr(Date date) {
+    return dateToStr(date, "yyyy/MM/dd");
+  }
+
+  public static String dateToStr(Date date, int type) {
+    switch (type)
+    {
+    case 0:
+      return dateToStr(date);
+    case 1:
+      return dateToStr(date, "yyyy/MM");
+    case 2:
+      return dateToStr(date, "yyyyMMdd");
+    case 11:
+      return dateToStr(date, "yyyy-MM-dd");
+    case 3:
+      return dateToStr(date, "yyyyMM");
+    case 4:
+      return dateToStr(date, "yyyy/MM/dd HH:mm:ss");
+    case 5:
+      return dateToStr(date, "yyyyMMddHHmmss");
+    case 6:
+      return dateToStr(date, "yyyy/MM/dd HH:mm");
+    case 7:
+      return dateToStr(date, "HH:mm:ss");
+    case 8:
+      return dateToStr(date, "HH:mm");
+    case 9:
+      return dateToStr(date, "HHmmss");
+    case 10:
+      return dateToStr(date, "HHmm");
+    case 12:
+      return dateToStr(date, "yyyy-MM-dd HH:mm:ss");
+    }
+    throw new IllegalArgumentException("Type undefined : " + type);
+  }
+}

+ 62 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/sms/EncryptUtil.java

@@ -0,0 +1,62 @@
+/*
+ *  Copyright (c) 2014 The CCP project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license
+ *  that can be found in the LICENSE file in the root of the web site.
+ *
+ *   http://www.yuntongxun.com
+ *
+ *  An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+package com.jeeplus.sys.sms;
+
+
+
+import sun.misc.BASE64Decoder;
+import sun.misc.BASE64Encoder;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+
+public class EncryptUtil
+{
+  private static final String UTF8 = "utf-8";
+
+  public String md5Digest(String src) throws NoSuchAlgorithmException, UnsupportedEncodingException
+  {
+    MessageDigest md = MessageDigest.getInstance("MD5");
+    byte[] b = md.digest(src.getBytes("utf-8"));
+    return byte2HexStr(b);
+  }
+
+  public String base64Encoder(String src) throws UnsupportedEncodingException
+  {
+    BASE64Encoder encoder = new BASE64Encoder();
+    return encoder.encode(src.getBytes("utf-8"));
+  }
+
+  public String base64Decoder(String dest)
+    throws NoSuchAlgorithmException, IOException
+  {
+    BASE64Decoder decoder = new BASE64Decoder();
+    return new String(decoder.decodeBuffer(dest), "utf-8");
+  }
+
+  private String byte2HexStr(byte[] b)
+  {
+    StringBuilder sb = new StringBuilder();
+    for (int i = 0; i < b.length; ++i) {
+      String s = Integer.toHexString(b[i] & 0xFF);
+      if (s.length() == 1)
+        sb.append("0");
+
+      sb.append(s.toUpperCase());
+    }
+    return sb.toString();
+  }
+}

+ 61 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/sms/LoggerUtil.java

@@ -0,0 +1,61 @@
+package com.jeeplus.sys.sms;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+import java.util.Date;
+
+
+public class LoggerUtil {
+	private static boolean isLog = true;
+	private static Logger logger;
+	static {
+		if (logger == null) {
+			logger = Logger.getLogger(CCPRestSDK.class);
+			
+		}
+	}
+	 
+	public static void setLogger(boolean isLog) {
+		isLog = isLog;
+	}
+	public static void setLog(Logger logger) {
+		logger = logger;
+	}
+	
+	public static void setLogLevel(int level) {
+		if (logger == null) {
+			logger = Logger.getLogger(CCPRestSDK.class);
+		}
+		PropertyConfigurator.configure(PropertiesUtil.getPropertie(level));
+		 
+
+
+	}
+
+	public static void debug(Object msg) {
+		if (isLog)
+			logger.debug(new Date()+" "+msg);
+	}
+
+	public static void info(Object msg) {
+		if (isLog)
+			logger.info(new Date()+" "+msg);
+	}
+
+	public static void warn(Object msg) {
+		if (isLog)
+			logger.warn(msg);
+	}
+
+	public static void error(Object msg) {
+		if (isLog)
+			logger.error(msg);
+	}
+
+	public static void fatal(Object msg) {
+		if (isLog)
+			logger.fatal(msg);
+	}
+	  
+}

+ 45 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/sms/PropertiesUtil.java

@@ -0,0 +1,45 @@
+/*
+ *  Copyright (c) 2013 The CCP project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license
+ *  that can be found in the LICENSE file in the root of the web site.
+ *
+ *   http://www.cloopen.com
+ *
+ *  An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+package com.jeeplus.sys.sms;
+import java.util.Properties;
+
+public class PropertiesUtil {
+	
+	
+	public static Properties getPropertie(int level) {
+			String loggerLever="all";
+			if(level==1){
+				loggerLever="info";
+			}else if(level==2){
+				loggerLever="warn";
+			}else if(level==3){
+				loggerLever="error";
+			}else if(level==4){
+				loggerLever="fatal";
+			}
+			Properties props = new Properties();
+			
+			props.setProperty("log4j.rootLogger", loggerLever+",A,R");
+			props.setProperty("log4j.appender.A", "org.apache.log4j.ConsoleAppender");
+			props.setProperty("log4j.appender.A.layout", "org.apache.log4j.PatternLayout");
+			props.setProperty("log4j.appender.R", "org.apache.log4j.RollingFileAppender");
+			props.setProperty("log4j.appender.R.File", "log.txt");
+			props.setProperty("log4j.appender.R.MaxFileSize", "100KB");
+			props.setProperty("log4j.appender.R.MaxBackupIndex", "1");
+			props.setProperty("log4j.appender.R.layout", "org.apache.log4j.PatternLayout");
+			props.setProperty("log4j.appender.R.layout.ConversionPattern", "%p %t %c - %m%n");
+			
+			return props;
+	}
+	
+}

+ 196 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/sms/SMSUtils.java

@@ -0,0 +1,196 @@
+package com.jeeplus.sys.sms;
+
+import com.jeeplus.sys.utils.Global;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.util.HashMap;
+
+/*
+功能:		企信通PHP HTTP接口 发送短信
+修改日期:	2014-03-19
+说明:		http://api.cnsms.cn/?ac=send&uid=用户账号&pwd=MD5位32密码&mobile=号码&content=内容
+状态:
+	100 发送成功
+	101 验证失败
+	102 短信不足
+	103 操作失败
+	104 非法字符
+	105 内容过多
+	106 号码过多
+	107 频率过快
+	108 号码内容空
+	109 账号冻结
+	110 禁止频繁单条发送
+	111 系统暂定发送
+	112 号码不正确
+	120 系统升级
+*/
+public class SMSUtils {
+    //发送短信,uid,pwd,参数值请向企信通申请, tel:发送的手机号, content:发送的内容
+    public static String send(String mobile,String content,String sendTime,String checkcontent) throws IOException {
+        BufferedReader in = null;
+        String result = "";
+        try {
+            // 创建StringBuffer对象用来操作字符串
+            StringBuffer sb = new StringBuffer("http://www.lcqxt.com/sms.aspx?action=send");
+
+            // 向StringBuffer追加用户名
+            sb.append("&userid=" + Global.getSmsUserid());//在此申请企信通uid,并进行配置用户名
+
+            // 向StringBuffer追加密码(密码采用MD5 32位 小写)
+            sb.append("&account=" + Global.getSmsAccount());
+
+            // 向StringBuffer追加密码(密码采用MD5 32位 小写)
+            //sb.append("&pwd="+Digests.string2MD5(pwd));//在此申请企信通uid,并进行配置密码
+            sb.append("&password=" + Global.getSmsPassword());
+            // 向StringBuffer追加手机号码
+            sb.append("&mobile=" + mobile);
+            // 向StringBuffer追加消息内容转URL标准码
+            sb.append("&content=" + URLEncoder.encode(content, "utf8"));
+            sb.append("&sendTime=" + sendTime);
+            sb.append("&checkcontent=" + checkcontent);
+
+            // 创建url对象
+            URL url = new URL(sb.toString());
+
+            // 打开url连接
+            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+
+            // 设置url请求方式 ‘get’ 或者 ‘post’
+            connection.setRequestMethod("POST");
+
+            // 发送
+            in = new BufferedReader(new InputStreamReader(url.openStream()));
+
+            // 返回发送结果
+            String line;
+            while ((line = in.readLine()) != null) {
+                result += line;
+            }
+        }catch (Exception e) {
+            System.out.println("发送 POST 请求出现异常!"+e);
+            e.printStackTrace();
+        }
+        //使用finally块来关闭输出流、输入流
+        finally{
+            try{
+                if(in!=null){
+                    in.close();
+                }
+            }
+            catch(IOException ex){
+                ex.printStackTrace();
+            }
+            return result;
+        }
+    }
+//    //容联云通讯(160040--超过同模板同号码上限)
+//    public static String sends(String mobile,String randomCode) throws IOException {
+//        BufferedReader reader = null;
+//        StringBuffer result = new StringBuffer("");
+//        try {
+//            StringBuffer sb = new StringBuffer("https://app.cloopen.com:8883/2013-12-26/Accounts/"+Global.getRongUserid()+"/SMS/TemplateSMS?");
+//            StringBuffer sbr = new StringBuffer();
+//            String aid = Global.getRongUserid();
+//            String atoken = Global.getRongToken();
+//            SimpleDateFormat sdf =   new SimpleDateFormat( "yyyyMMddHHmmss" );
+//            String time =sdf.format(new Date());
+//            sbr.append(aid).append(atoken).append(time);
+//            //模板指定参数
+//            String [] s = new String[]{randomCode,"60"};
+//            //sig
+//            sb.append("sig="+ MD5.toMD5(sbr.toString()));
+//
+//            // 创建url对象
+//            URL url = new URL(sb.toString());
+//
+//            // 打开url连接
+//            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+//
+//            // 设置url请求方式 ‘get’ 或者 ‘post’
+//            connection.setRequestMethod("POST");
+//            connection.setRequestProperty("Accept","application/json");
+//            connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
+//            String an = Global.getRongUserid()+":"+time;
+//            BASE64Encoder encoder = new BASE64Encoder();
+//            an = encoder.encode(an.getBytes("UTF-8"));
+//            connection.setRequestProperty("Authorization", an);
+//            connection.setRequestProperty("Content-Length", "256");
+//            connection.setDoOutput(true);
+//            connection.connect();
+//            //post请求
+//            DataOutputStream out = new DataOutputStream(connection.getOutputStream());
+//            JSONObject obj = new JSONObject();
+//            obj.element("to", mobile);
+//            obj.element("appId", Global.getAppId());
+//            obj.element("templateId", Global.getTemplateId());
+//            obj.element("datas", s);
+//
+//            out.writeBytes(obj.toString());
+//            out.flush();
+//            out.close();
+//            // 发送
+//            reader = new BufferedReader(new InputStreamReader(
+//                    connection.getInputStream()));
+//            String lines;
+//            while ((lines = reader.readLine()) != null) {
+//                lines = new String(lines.getBytes(), "utf-8");
+//                result.append(lines);
+//            }
+//            System.out.println(result);
+//            // 断开连接
+//            connection.disconnect();
+//        }catch (Exception e) {
+//            System.out.println("发送 POST 请求出现异常!"+e);
+//            e.printStackTrace();
+//        }
+//        //使用finally块来关闭输出流、输入流
+//        finally{
+//            try{
+//                if(reader!=null){
+//                    reader.close();
+//                }
+//            }
+//            catch(IOException ex){
+//                ex.printStackTrace();
+//            }
+//            return result.toString();
+//        }
+//    }
+
+
+    //容联云通讯(160040--超过同模板同号码上限)
+    public static HashMap<String,Object> sends(String mobile,String randomCode) throws IOException {
+        HashMap<String, Object> result = null;
+        CCPRestSDK restAPI = new CCPRestSDK();
+        try {
+            String aid = Global.getRongUserid();
+            String atoken = Global.getRongToken();
+            String appId = Global.getAppId();
+            String templateId = Global.getTemplateId();
+            restAPI.init("app.cloopen.com", "8883");
+            restAPI.setAccount(aid, atoken);
+            restAPI.setAppId(appId);
+            result = restAPI.sendTemplateSMS(mobile,templateId,new String[]{randomCode,"60"});
+        }catch (Exception e) {
+            System.out.println("发送 POST 请求出现异常!"+e);
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+//    public static void main(String[] args) throws Exception {
+//        String inputline =sends("15201428039","系统预警");
+//        System.out.println(inputline);
+//        long sys = System.currentTimeMillis();
+//        System.out.println(sys);
+//    }
+
+
+
+}

+ 9 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/utils/UserUtils.java

@@ -18,7 +18,10 @@ import com.jeeplus.sys.service.dto.MenuDTO;
 import com.jeeplus.sys.service.dto.RoleDTO;
 import com.jeeplus.sys.service.dto.UserDTO;
 import com.jeeplus.sys.service.mapstruct.MenuWrapper;
+import com.jeeplus.sys.sms.SMSUtils;
 
+import java.io.IOException;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -200,5 +203,11 @@ public class UserUtils {
         return false;
     }
 
+    //容联云通讯
+    public static HashMap<String,Object> sendRandomCodes(String mobile, String randomCode) throws IOException {
+        return SMSUtils.sends(mobile, randomCode);
+
+    }
+
 
 }

+ 1 - 0
jeeplus-platform/jeeplus-common/src/main/java/com/jeeplus/core/errors/ErrorConstants.java

@@ -11,4 +11,5 @@ public final class ErrorConstants {
     public static final String LOGIN_ERROR_FORBID_LOGGED_IN_ELSEWHERE = "您的账号已在其它地方登录,您被禁止登录!";
     public static final String LOGIN_ERROR__KICK_OUT_LOGGED_IN_ELSEWHERE = "您的账号在另一台设备上登录,如非本人操作,请立即修改密码!";
     public static final String LOGIN_ERROR_ERROR_VALIDATE_CODE = "您输入的验证码不正确,请重新输入!";
+    public static final String LOGIN_CODE = "请输入验证码进行登录!";
 }

+ 7 - 0
jeeplus-web/src/main/resources/application-development.yml

@@ -237,3 +237,10 @@ aliyun_directory: attachment-file/assess
 #签章阿里云文件bucketName
 qzBucketName: xg-qz
 
+
+#容联云相关参数
+rong_userid: 8a216da86715511501673e331c24171e
+rong_token: 3d7dc58c6a334ad6887317efbf847e41
+app_id: 8a216da86715511501673e331c741725
+template_id: 435329
+code_type: 1