Commit 4227c8d1 authored by 周健威's avatar 周健威

Merge remote-tracking branch 'origin/base-modify' into base-modify

parents 5f1eab7b 4729eea5
package com.github.wxiaoqi.security.auth.controller;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.auth.service.AuthService;
import com.github.wxiaoqi.security.auth.util.user.JwtAuthenticationRequest;
import com.github.wxiaoqi.security.common.constant.RequestTypeConstants;
......@@ -8,10 +9,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
......@@ -62,4 +60,9 @@ public class AuthController {
authService.validate(token);
return new ObjectRestResponse<>();
}
@RequestMapping(value = "/sendsms", method = RequestMethod.POST)
public JSONObject sendsms(@RequestParam(value="username",defaultValue="")String username, @RequestParam(value="type",defaultValue="0")Integer type) throws Exception {
log.info(username+"----require sendsms...");
return authService.sendsms(username,type);
}
}
package com.github.wxiaoqi.security.auth.feign;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.api.vo.user.AppUserInfo;
import com.github.wxiaoqi.security.api.vo.user.UserInfo;
import com.github.wxiaoqi.security.auth.configuration.FeignConfiguration;
......@@ -8,6 +9,7 @@ import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
/**
......@@ -23,4 +25,7 @@ public interface IUserService {
@RequestMapping(value = "/api/app/user/validate", method = RequestMethod.POST)
AppUserInfo AppValidate(@RequestBody JwtAuthenticationRequest authenticationRequest);
@RequestMapping(value = "/api/app/user/sendsms", method = RequestMethod.POST)
public JSONObject sendsms(@RequestParam(value="username",defaultValue="")String username, @RequestParam(value="type",defaultValue="0")Integer type);
}
package com.github.wxiaoqi.security.auth.service;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.auth.util.user.JwtAuthenticationRequest;
public interface AuthService {
String login(JwtAuthenticationRequest authenticationRequest) throws Exception;
String refresh(String oldToken) throws Exception;
void validate(String token) throws Exception;
JSONObject sendsms(String username, Integer type) throws Exception;
}
package com.github.wxiaoqi.security.auth.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.api.vo.user.AppUserInfo;
import com.github.wxiaoqi.security.auth.common.util.jwt.JWTInfo;
import com.github.wxiaoqi.security.auth.feign.IUserService;
......@@ -44,4 +45,9 @@ public class AppAuthServiceImpl implements AuthService {
public void validate(String token) throws Exception {
jwtTokenUtil.getInfoFromToken(token);
}
@Override
public JSONObject sendsms(String username, Integer type) throws Exception {
return userService.sendsms(username,type);
}
}
package com.github.wxiaoqi.security.auth.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.api.vo.user.UserInfo;
import com.github.wxiaoqi.security.auth.common.util.jwt.JWTInfo;
import com.github.wxiaoqi.security.auth.feign.IUserService;
......@@ -43,4 +44,8 @@ public class AuthServiceImpl implements AuthService {
public String refresh(String oldToken) throws Exception {
return jwtTokenUtil.generateToken(jwtTokenUtil.getInfoFromToken(oldToken));
}
@Override
public JSONObject sendsms(String username, Integer type) throws Exception {
return userService.sendsms(username,type);
}
}
......@@ -59,7 +59,12 @@
<artifactId>spring-web</artifactId>
<version>5.0.4.RELEASE</version>
</dependency>
<!-- fastjson.jar -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.37</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
......
package com.github.wxiaoqi.security.common.util;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
/**
* @author
* @version
*/
public class SystemProperty {
private static final String XML_FILE_EXTENSION = ".xml";
//读取key
public static Map<String,String> getValue() throws Exception
{
Resource resource = new ClassPathResource("/androidver.properties");
Properties prop = PropertiesLoaderUtils.loadProperties(resource);
Map<String,String> map = new HashMap<String, String>();
map.put("versioncode", prop.getProperty("versioncode"));
map.put("versionname", prop.getProperty("versionname"));
map.put("downurl", prop.getProperty("downurl"));
return map;
}
//写key
public static void setValue(Map<String,String> map) throws Exception
{
Resource resource = new ClassPathResource("/androidver.properties");
System.out.println(resource.getFile().getPath());
Properties prop = PropertiesLoaderUtils.loadProperties(resource);
for(Map.Entry<String, String> entry:map.entrySet()){
prop.setProperty(entry.getKey(), entry.getValue());
}
OutputStream fos = new FileOutputStream(resource.getFile().getPath());
// 以适合使用 load 方法加载到 Properties 表中的格式,
// 将此 Properties 表中的属性列表(键和元素对)写入输出流
prop.store(fos, null);
fos.close();
}
//读取key
public static Map<String,String> getValue_sign() throws Exception
{
Resource resource = new ClassPathResource("/androidver_sign.properties");
Properties prop = PropertiesLoaderUtils.loadProperties(resource);
Map<String,String> map = new HashMap<String, String>();
map.put("versioncode", prop.getProperty("versioncode"));
map.put("versionname", prop.getProperty("versionname"));
map.put("downurl", prop.getProperty("downurl"));
return map;
}
//写key
public static void setValue_sign(Map<String,String> map) throws Exception
{
Resource resource = new ClassPathResource("/androidver_sign.properties");
System.out.println(resource.getFile().getPath());
Properties prop = PropertiesLoaderUtils.loadProperties(resource);
for(Map.Entry<String, String> entry:map.entrySet()){
prop.setProperty(entry.getKey(), entry.getValue());
}
OutputStream fos = new FileOutputStream(resource.getFile().getPath());
// 以适合使用 load 方法加载到 Properties 表中的格式,
// 将此 Properties 表中的属性列表(键和元素对)写入输出流
prop.store(fos, null);
fos.close();
}
//读取key
public static String getSystemConfig(String key) throws Exception
{
Resource resource = new ClassPathResource("/properties/systemconfig.properties");
Properties prop = loadProperties(resource);
return prop.getProperty(key);
}
//读取key
public static String getResultCod(String key) throws Exception
{
Resource resource = new ClassPathResource("/properties/resultcod.properties");
Properties prop = loadProperties(resource);
return prop.getProperty(key);
}
//读取key
public static String getScrmservice(String key) throws Exception
{
Resource resource = new ClassPathResource("/scrmservice.properties");
Properties prop = PropertiesLoaderUtils.loadProperties(resource);
return prop.getProperty(key);
}
public static String getConfig(String key){
String config = "";
try {
config = getSystemConfig(key);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return config;
}
public static String getResultConfig(String key){
String config = "";
try {
config = getResultCod(key);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return config;
}
public static String getScrmConfig(String key){
String config = "";
try {
config = getScrmservice(key);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return config;
}
public static Properties loadProperties(Resource resource) throws IOException {
Properties props = new Properties();
fillProperties(props, resource);
return props;
}
public static void fillProperties(Properties props, Resource resource) throws IOException {
InputStream is = resource.getInputStream();
InputStreamReader reader = new InputStreamReader(is, "UTF-8");
try {
String filename = resource.getFilename();
if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) {
props.loadFromXML(is);
}
else {
props.load(reader);
}
}
finally {
is.close();
}
}
}
package com.github.wxiaoqi.security.common.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
/**
* 验证防止new创建类对象改用单例调用
* @author GongXiaoBin
*
*/
public class VerificationUtils {
private static VerificationUtils pvu = null;
public static VerificationUtils getPvu() {
if(pvu==null){
pvu=new VerificationUtils();
}
return pvu;
}
/**
* 参数是否为null或空
* @param String parameter
* @return boolean
*/
public boolean parameterVt(String parameter){
boolean bool= null!=parameter||StringUtils.isNotEmpty(parameter)?true:false;
return bool;
}
/**
* 验证邮箱
* @param email
* @return
*/
public boolean checkEmail(String parameter){
boolean flag = false;
try{
String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(parameter);
flag = matcher.matches();
}catch(Exception e){
flag = false;
}
return flag;
}
/**
* 验证手机号码
* @param mobiles
* @return
*/
public boolean checkMobileNumber(String parameter){
boolean flag = false;
try{
//Pattern regex = Pattern.compile("^(((13[0-9])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8})|(0\\d{2}-\\d{8})|(0\\d{3}-\\d{7})$");
Pattern regex = Pattern.compile("1\\d{10}");
Matcher matcher = regex.matcher(parameter);
flag = matcher.matches();
}catch(Exception e){
flag = false;
}
return flag;
}
}
package com.github.wxiaoqi.security.common.util.process;
import com.github.wxiaoqi.security.common.util.SystemProperty;
public class ResultCode {
// 操作成功
public static int SUCCESS_CODE = Integer.valueOf(SystemProperty.getResultConfig("SUCCESS_CODE"));
// 操作失败
public static int FAILED_CODE = Integer.valueOf(SystemProperty.getResultConfig("FAILED_CODE"));
// 操作失败
public static int NULL_CODE = Integer.valueOf(SystemProperty.getResultConfig("NULL_CODE"));
// 操作出现异常
public static int EXCEPTION_CODE = Integer.valueOf(SystemProperty.getResultConfig("EXCEPTION_CODE"));
// 数据已存在
public static int EXIST_CODE = Integer.valueOf(SystemProperty.getResultConfig("EXIST_CODE"));
// 数据不存在
public static int NOTEXIST_CODE = Integer.valueOf(SystemProperty.getResultConfig("NOTEXIST_CODE"));
// rstoken失效
public static int RSTOKEN_EXPIRED_CODE = Integer.valueOf(SystemProperty.getResultConfig("RSTOKEN_EXPIRED_CODE"));
// rstoken不合法
public static int RSTOKEN_NULL_CODE = Integer.valueOf(SystemProperty.getResultConfig("RSTOKEN_NULL_CODE"));
// 请求微信接口错误
public static int WXAPI_CODE = Integer.valueOf(SystemProperty.getResultConfig("WXAPI_CODE"));
// 微信用户不存在
public static int WXNOTEXIST_CODE = Integer.valueOf(SystemProperty.getResultConfig("WXNOTEXIST_CODE"));
// ajax请求,用户未登录
public static int AJAX_WECHAT_NOTEXIST_CODE = Integer
.valueOf(SystemProperty.getResultConfig("AJAX_WECHAT_NOTEXIST_CODE"));
// 手机号已绑定人脸
public static int FACE_BIND_CODE = Integer.valueOf(SystemProperty.getResultConfig("FACE_BIND_CODE"));
// 手机号未绑定人脸
public static int FACE_NOTBIND_CODE = Integer.valueOf(SystemProperty.getResultConfig("FACE_NOTBIND_CODE"));
// 人脸识别失败
public static int FACE_NOTEXIST_CODE = Integer.valueOf(SystemProperty.getResultConfig("FACE_NOTEXIST_CODE"));
// 人脸比对失败
public static int FACE_COMPARE_FAILED_CODE = Integer
.valueOf(SystemProperty.getResultConfig("FACE_COMPARE_FAILED_CODE"));
// 人脸+眼睛识别失败
public static int EYE_NOTEXIST_CODE = Integer.valueOf(SystemProperty.getResultConfig("EYE_NOTEXIST_CODE"));
// redis中的token过期或者为空
public static int REDIS_TOKEN_NULL_CODE = Integer.valueOf(SystemProperty.getResultConfig("REDIS_TOKEN_NULL_CODE"));
// 手机号码已被使用
public static int PHONE_EXIST_CODE = Integer.valueOf(SystemProperty.getResultConfig("PHONE_EXIST_CODE"));
// 获取app用户失败
public static int GET_APPUSER_FAILED_CODE = Integer
.valueOf(SystemProperty.getResultConfig("GET_APPUSER_FAILED_CODE"));
// 用户不存在
public static int USER_NOTEXIST_CODE = Integer.valueOf(SystemProperty.getResultConfig("USER_NOTEXIST_CODE"));
// 用户已存在
public static int USER_EXIST_CODE = Integer.valueOf(SystemProperty.getResultConfig("USER_EXIST_CODE"));
// 手机号已绑定人脸
public static int WX_BIND_CODE = Integer.valueOf(SystemProperty.getResultConfig("WX_BIND_CODE"));
// 人脸已绑定手机号
public static int FACE_BIND_PHONE_CODE = Integer.valueOf(SystemProperty.getResultConfig("FACE_BIND_PHONE_CODE"));
// 新增组织失败
public static int ORG_INSERT_FAILED_CODE = Integer
.valueOf(SystemProperty.getResultConfig("ORG_INSERT_FAILED_CODE"));
// 更新组织信息失败
public static int ORG_UPDATE_FAILED_CODE = Integer
.valueOf(SystemProperty.getResultConfig("ORG_UPDATE_FAILED_CODE"));
// 新增角色信息失败
public static int ROLE_INSERT_FAILED_CODE = Integer
.valueOf(SystemProperty.getResultConfig("ROLE_INSERT_FAILED_CODE"));
// 更新组织信息失败
public static int ROLE_UPDATE_FAILED_CODE = Integer
.valueOf(SystemProperty.getResultConfig("ROLE_UPDATE_FAILED_CODE"));
// 组织下已存在超级管理员角色
public static int ROLE_SUPER_ISEXIST_CODE = Integer
.valueOf(SystemProperty.getResultConfig("ROLE_SUPER_ISEXIST_CODE"));
// 角色不存在
public static int ROLE_NOTEXIST_CODE = Integer.valueOf(SystemProperty.getResultConfig("ROLE_NOTEXIST_CODE"));
// 没有操作菜单的权限
public static int NOT_MENU_AUTH_CODE = Integer.valueOf(SystemProperty.getResultConfig("NOT_MENU_AUTH_CODE"));
// 新增权限失败
public static int INSERT_AUTH_FAILED_CODE = Integer
.valueOf(SystemProperty.getResultConfig("INSERT_AUTH_FAILED_CODE"));
// 更新权限失败
public static int UPDATE_AUTH_FAILED_CODE = Integer
.valueOf(SystemProperty.getResultConfig("UPDATE_AUTH_FAILED_CODE"));
// 角色权限不存在
public static int ROLE_NOTEXIST_AUTH_CODE = Integer
.valueOf(SystemProperty.getResultConfig("ROLE_NOTEXIST_AUTH_CODE"));
// 无一级角色
public static int NOT_HAVE_LEVEL1 = Integer.valueOf(SystemProperty.getResultConfig("NOT_HAVE_LEVEL1"));
// 账户已存在
public static int ACCOUNT_ISEXIST_CODE = Integer.valueOf(SystemProperty.getResultConfig("ACCOUNT_ISEXIST_CODE"));
// 账户不存在
public static int ACCOUNT_NOT_EXIST_CODE = Integer
.valueOf(SystemProperty.getResultConfig("ACCOUNT_NOT_EXIST_CODE"));
// 账户不存在
public static int ORG_DONTHAVE_PUBLIC_CODE = Integer
.valueOf(SystemProperty.getResultConfig("ORG_DONTHAVE_PUBLIC_CODE"));
// 组织超级管理员已存在
public static int ACCOUNT_FIRST_ISEXIST_CODE = Integer
.valueOf(SystemProperty.getResultConfig("ACCOUNT_FIRST_ISEXIST_CODE"));
// 昵称格式有误,请填写正确昵称
public static int NICKNAME_NULL_CODE = Integer.valueOf(SystemProperty.getResultConfig("NICKNAME_NULL_CODE"));
// 账户已禁用
public static int ACCOUNTINFO_ISDEL = Integer.valueOf(SystemProperty.getResultConfig("ACCOUNTINFO_ISDEL"));
// 监控设备不存在
public static int DEVICE_NOTEXIST_CODE = Integer.valueOf(SystemProperty.getResultConfig("DEVICE_NOTEXIST_CODE"));
// 设备access_token获取失败
public static int DEVICE_TOKEN_NOTEXIST_CODE = Integer
.valueOf(SystemProperty.getResultConfig("DEVICE_TOKEN_NOTEXIST_CODE"));
// 操作频繁提示
public static int API_MAX_CODE = Integer.valueOf(SystemProperty.getResultConfig("API_MAX_CODE"));
// 公众号不存在
public static int PUBLIC_NOTEXIST_CODE = Integer.valueOf(SystemProperty.getResultConfig("PUBLIC_NOTEXIST_CODE"));
// 公众号不存在
public static int REPEAT_SUB_CODE = Integer.valueOf(SystemProperty.getResultConfig("REPEAT_SUB_CODE"));
// 身份证信息已存在
public static int IDNUM_ISEXIST_CODE = Integer.valueOf(SystemProperty.getResultConfig("IDNUM_ISEXIST_CODE"));
// 身份证信息已存在
public static int IDCARD_INVALID_CODE = Integer.valueOf(SystemProperty.getResultConfig("IDCARD_INVALID_CODE"));
// 企业个人简历不存在
public static int CORP_VITA_NOTEXIST = Integer.valueOf(SystemProperty.getResultConfig("CORP_VITA_NOTEXIST"));
// 企业个人简历不完善
public static int CORP_VITA_INCOMPLETET = Integer.valueOf(SystemProperty.getResultConfig("CORP_VITA_INCOMPLETET"));
// 简历有效期内已投
public static int VITA_DELIVERED = Integer.valueOf(SystemProperty.getResultConfig("VITA_DELIVERED"));
// 岗位已下架
public static int POST_END_CODE = Integer.valueOf(SystemProperty.getResultConfig("POST_END_CODE"));
// 客服下存在粉丝
public static int SERVICE_HAS_FANS = Integer.valueOf(SystemProperty.getResultConfig("SERVICE_HAS_FANS"));
// 未找到客服信息
public static int NOT_FIND_SERVICE_CODE = Integer.valueOf(SystemProperty.getResultConfig("NOT_FIND_SERVICE_CODE"));
// 非客服身份
public static int NOT_SERVICE = Integer.valueOf(SystemProperty.getResultConfig("NOT_SERVICE"));
// 圈子模块resultInfo类型返回正确码
public static int SCRM_RESULTINFO_SUCCESS_CODE = Integer
.valueOf(SystemProperty.getResultConfig("SCRM_RESULTINFO_SUCCESS_CODE"));
// 市接口无数据返回
public static int NO_SELECT_BY_RS = Integer.valueOf(SystemProperty.getResultConfig("NO_SELECT_BY_RS"));
// 未绑定社保卡
public static int NOT_BIND_SOCIAL_CARD = Integer.valueOf(SystemProperty.getResultConfig("NOT_BIND_SOCIAL_CARD"));
}
package com.github.wxiaoqi.security.common.util.process;
import com.github.wxiaoqi.security.common.util.SystemProperty;
public class SystemConfig {
// token到期时间
public static Integer TOKENOVERTIME = Integer.valueOf(SystemProperty.getConfig("TOKEN_OVER_TIME"));
// redis缓存时间
public static Integer REDISTOKENTIME = Integer.valueOf(SystemProperty.getConfig("REDIS_TOKEN_TIME"));
// redis缓存itoken时间
public static Integer REDIS_ITOKEN_TIME = Integer.valueOf(SystemProperty.getConfig("REDIS_ITOKEN_TIME"));
// session有效时间
public static Integer SESSION_TIME = Integer.valueOf(SystemProperty.getConfig("SESSION_TIME"));
// 根据key名获取value
public static String getCongif(String key) {
return SystemProperty.getConfig(key);
}
}
package com.github.wxiaoqi.security.common.util.result;
import java.io.Serializable;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.common.util.SystemProperty;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
/**
* 返回操作结果
* @author Czz
*
*/
public final class JsonResultUtil implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private static final Integer WEB_CALL_RESULT_SUCCESS = ResultCode.SUCCESS_CODE;
private static final Integer WEB_CALL_RESULT_FAILED = ResultCode.FAILED_CODE;
private static final String RESULT_KEY_TYPE = "status";
private static final String RESULT_KEY_MSG = "message";
private static final String RESULT_SUCCESS_MSG = "操作成功";
private static final String RESULT_FAIL_MSG = "操作失败";
private static final String DATA_KEY = "data";
public static final JSONObject SUCCESS_RESULT_JSON = new JSONObject();
private static final JSONObject FAIL_RESULT_JSON = new JSONObject();
static {
/**
* 默认成功初始化
*/
SUCCESS_RESULT_JSON.put(RESULT_KEY_TYPE, WEB_CALL_RESULT_SUCCESS);
SUCCESS_RESULT_JSON.put(RESULT_KEY_MSG, RESULT_SUCCESS_MSG);
/**
* 默认失败初始化
*/
FAIL_RESULT_JSON.put(RESULT_KEY_TYPE, WEB_CALL_RESULT_FAILED);
FAIL_RESULT_JSON.put(RESULT_KEY_MSG, RESULT_FAIL_MSG);
}
/**
* 创建一个正确的调用结果
* @return
*/
public static JSONObject createSuccessResult() {
return SUCCESS_RESULT_JSON;
}
/**
*
* @Description: 创建一个没有错误信息的失败返回
* @return
* @throws
*/
public static JSONObject createDefaultFail() {
return FAIL_RESULT_JSON;
}
/**
*
* @Description: 创建一个带一个键值对对象的正确调用结果
* @param value
* @return
* @throws
*/
public static JSONObject createSuccessResultWithObj(final Object value) {
JSONObject successJson = new JSONObject();
successJson.put(RESULT_KEY_TYPE, WEB_CALL_RESULT_SUCCESS);
successJson.put(RESULT_KEY_MSG, RESULT_SUCCESS_MSG);
successJson.put(DATA_KEY, value);
return successJson;
}
/**
* 创建一个异常的调用结果
* @param message
* @return
*/
public static JSONObject createFailedResult(int code, String message) {
JSONObject failedResult = new JSONObject();
failedResult.put(RESULT_KEY_TYPE, code);
failedResult.put(RESULT_KEY_MSG, message);
return failedResult;
}
/**
* 创建一个异常的调用结果并携带结果参数
* @param message
* @return
*/
public static JSONObject createFailedResult(int code, String message,final Object value) {
JSONObject failedResult = new JSONObject();
failedResult.put(RESULT_KEY_TYPE, code);
failedResult.put(RESULT_KEY_MSG, message);
failedResult.put(DATA_KEY, value);
return failedResult;
}
/**
* 创建一个异常的调用结果,根据code获取对应的提示
* @param code
* @return
*/
public static JSONObject createFailedResultMsg(int code) {
JSONObject failedResult = new JSONObject();
failedResult.put(RESULT_KEY_TYPE, code);
failedResult.put(RESULT_KEY_MSG, SystemProperty.getResultConfig(code + ""));
return failedResult;
}
}
#返回结果代码
#操作成功
SUCCESS_CODE=1000
#操作失败
FAILED_CODE=1001
#数据已存在
EXIST_CODE=1002
#数据不存在
NOTEXIST_CODE=1003
#参数为空
NULL_CODE=1003
1003=参数为空
#操作出现异常
EXCEPTION_CODE=1004
1004=操作出现异常
#操作频繁,稍后再试
API_MAX_CODE=1005
1005=操作频繁,稍后再试
#rstoken已失效
RSTOKEN_EXPIRED_CODE=1006
1006=rstoken已失效
#rstoken为空
RSTOKEN_NULL_CODE=1007
1007=rstoken为空
#请求微信接口失败
WXAPI_CODE=2001
#微信用不不存在
WXNOTEXIST_CODE=2003
#公众号不存在
PUBLIC_NOTEXIST_CODE=2004
2004=公众号不存在
#ajax请求,用户未登录
AJAX_WECHAT_NOTEXIST_CODE=2005
2005=ajax请求,用户未登录
#手机号已绑定人脸
FACE_BIND_CODE=3000
3000=手机号已绑定人脸
#手机号未绑定人脸
FACE_NOTBIND_CODE=3001
3001=手机号未绑定人脸
#人脸识别失败
FACE_NOTEXIST_CODE=3002
3002=人脸识别失败
#人脸比对失败
FACE_COMPARE_FAILED_CODE=3003
3003=人脸比对失败
#人脸已绑定手机号码
FACE_BIND_PHONE_CODE=3004
3004=人脸已绑定手机号
#人脸已绑定手机号码
EYE_NOTEXIST_CODE=3005
3005=识别失败
#登陆token过期
REDIS_TOKEN_NULL_CODE=4001
4001=登陆token过期
#手机号已绑定微信
WX_BIND_CODE=4002
4002=手机号已绑定微信
#获取用户失败
GET_APPUSER_FAILED_CODE=4003
4003=获取用户失败
#手机号码已被使用
PHONE_EXIST_CODE=5001
5001=手机号码已被使用
#用户不存在
USER_NOTEXIST_CODE=5002
5002=用户不存在
#用户已存在
USER_EXIST_CODE=5003
5003=用户不存在
ORG_INSERT_FAILED_CODE=6001
6001=新增组织失败
ORG_UPDATE_FAILED_CODE=6002
6001=更新组织信息失败
ROLE_INSERT_FAILED_CODE=7001
7001=新增角色信息失败
ROLE_UPDATE_FAILED_CODE=7002
7002=更新角色信息失败
ROLE_SUPER_ISEXIST_CODE=7003
7003=该组织已存在一级管理员角色
ROLE_NOTEXIST_CODE=7004
7004=角色不存在
NOT_HAVE_LEVEL1=7005
7005=该组织无一级角色,请先创建
NOT_MENU_AUTH_CODE=8001
8001=没有操作该菜单的权限
INSERT_AUTH_FAILED_CODE=8003
8003=新增权限失败
UPDATE_AUTH_FAILED_CODE=8002
8002=更新权限失败
ROLE_NOTEXIST_AUTH_CODE=8004
8004=角色权限不存在
ACCOUNT_ISEXIST_CODE=9001
9001=账户已存在
ACCOUNT_FIRST_ISEXIST_CODE=9002
9002=该组织已存在超级管理员账户
ACCOUNT_NOT_EXIST_CODE=9003
9003=账户不存在
NOT_FIND_SERVICE_CODE=9004
9004=未找到客服信息
ORG_DONTHAVE_PUBLIC_CODE=9005
9005=该组织暂未配置公众号信息,请先配置!
NICKNAME_NULL_CODE=9006
9006=昵称格式有误,请填写正确昵称
ACCOUNTINFO_ISDEL=9007
9007=账户已禁用
DEVICE_NOTEXIST_CODE=1005
1005=监控设备不存在
DEVICE_TOKEN_NOTEXIST_CODE=1006
1005=设备access_token获取失败
REPEAT_SUB_CODE=1008
#身份证信息已采集
IDNUM_ISEXIST_CODE=10001
#身份证已过去
IDCARD_INVALID_CODE=10002
#企业个人简历不存在
CORP_VITA_NOTEXIST=20001
20001=个人简历不存在,请先创建简历
#企业个人简历不完善
CORP_VITA_INCOMPLETET=20002
20002=个人简历不完善,请先完善简历
#简历在有效时间内已投递
VITA_DELIVERED=20003
#岗位已下架
POST_END_CODE=20004
20004=该岗位已下架
#客服存在粉丝
SERVICE_HAS_FANS=40001
40001=请先转移该客服的粉丝!
#客服
NOT_SERVICE=40002
40002=当前用户不是客服身份!
#圈子模块resultInfo类型返回正确码
SCRM_RESULTINFO_SUCCESS_CODE=10344
#市接口无数据返回
NO_SELECT_BY_RS=1010
#还未绑定社保卡
NOT_BIND_SOCIAL_CARD=3010
\ No newline at end of file
#项目url
XXMP_URL=http://zhrstest.qzlife.net
#token到期时间
TOKEN_OVER_TIME=604800
#itoken到期时间(6天)
REDIS_ITOKEN_TIME=51840
#redis有效期
REDIS_TOKEN_TIME=604800
#session有效期
SESSION_TIME=3600
\ No newline at end of file
......@@ -35,6 +35,10 @@
<artifactId>ace-common</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
......@@ -71,7 +75,12 @@
<!--<groupId>org.springframework.amqp</groupId>-->
<!--<artifactId>spring-rabbit</artifactId>-->
<!--</dependency>-->
<!-- fastjson.jar -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.37</version>
</dependency>
<!--用于测试的,本例可省略-->
<dependency>
<groupId>org.springframework.boot</groupId>
......
package com.github.wxiaoqi.security.admin.biz;
import com.ace.cache.annotation.CacheClear;
import com.github.wxiaoqi.security.admin.entity.AppUserDetail;
import com.github.wxiaoqi.security.admin.mapper.AppUserDetailMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* ${DESCRIPTION}
*
* @author wanghaobin
* @create 2017-06-08 16:23
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class AppUserDetailBiz extends BaseBiz<AppUserDetailMapper, AppUserDetail> {
@Override
@CacheClear(pre="user{1.username}")
public void updateSelectiveById(AppUserDetail entity) {
super.updateSelectiveById(entity);
}
}
package com.github.wxiaoqi.security.admin.biz;
import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.wxiaoqi.security.admin.entity.AppUserLogin;
import com.github.wxiaoqi.security.admin.entity.User;
import com.github.wxiaoqi.security.admin.mapper.AppUserLoginMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.constant.UserConstant;
import com.github.wxiaoqi.security.common.msg.TableResultResponse;
import com.github.wxiaoqi.security.common.util.Query;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static com.github.wxiaoqi.security.auth.common.constatns.CommonConstants.DATA_ALL_TRUE;
/**
* ${DESCRIPTION}
*
* @author wanghaobin
* @create 2017-06-08 16:23
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class AppUserLoginBiz extends BaseBiz<AppUserLoginMapper, AppUserLogin> {
@Override
public void insertSelective(AppUserLogin entity) {
String password = new BCryptPasswordEncoder(UserConstant.PW_ENCORDER_SALT).encode(entity.getPassword());
entity.setPassword(password);
super.insertSelective(entity);
}
@Override
@CacheClear(pre="user{1.username}")
public void updateSelectiveById(AppUserLogin entity) {
super.updateSelectiveById(entity);
}
/**
* 根据用户名获取用户信息
* @param username
* @return
*/
@Cache(key="user{1}")
public AppUserLogin getUserByUsername(String username){
AppUserLogin user = new AppUserLogin();
user.setUsername(username);
return mapper.selectOne(user);
}
/* public TableResultResponse<AppUserLogin> selectPage(Query query, AppUserLogin currentUser) {
if(DATA_ALL_TRUE.equals(currentUser.getDataAll())) {
return super.selectByQuery(query);
}else {
Example example = new Example(User.class);
if(query.entrySet().size()>0) {
Example.Criteria criteria = example.createCriteria();
for (Map.Entry<String, Object> entry : query.entrySet()) {
criteria.andLike(entry.getKey(), "%" + entry.getValue().toString() + "%");
}
}
if(StringUtils.isNotBlank(currentUser.getDataCompany())){
example.createCriteria().andIn("companyId", Arrays.asList(currentUser.getDataCompany().split(",")));
}
if(StringUtils.isNotBlank(currentUser.getDataZone())){
example.createCriteria().andIn("zoneId", Arrays.asList(currentUser.getDataZone().split(",")));
}
Page<Object> result = PageHelper.startPage(query.getPage(), query.getLimit());
List<User> list = mapper.selectByExample(example);
return new TableResultResponse<User>(result.getTotal(), list);
}
}*/
/**
* 根据手机号码判断是否存在用户
*
* @param username
* @return
* @throws Exception
*/
public AppUserLogin checkeUserLogin(String username) {
Example example = new Example(AppUserLogin.class);
example.createCriteria().andEqualTo("username", username).andEqualTo("isdel", 0);
List<AppUserLogin> userLoginList = mapper.selectByExample(example);
if (userLoginList != null && userLoginList.size() != 0) {
return userLoginList.get(0);
}
return null;
}
/**
* 根据手机号码判断是否已绑定微信
*
* @param userLogin
* @return
*/
public boolean checkeWechatUser(AppUserLogin userLogin) {
boolean flag = true;
if (null != userLogin) {
Integer userid = userLogin.getId();
userLogin= mapper.selectByPrimaryKey(userid);
if (userLogin==null) {
flag = false;
}
}
return flag;
}
}
package com.github.wxiaoqi.security.admin.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* ${DESCRIPTION}
*
* @author wanghaobin
* @create 2017-06-21 8:39
*/
@Configuration
@Primary
public class RedisConfiguration {
@Bean
public RedisTemplate<String, Object> userRedisTemplate(RedisConnectionFactory factory) {
RedisTemplate redisTemplate = new RedisTemplate();
redisTemplate.setConnectionFactory(factory);
RedisSerializer<String> stringSerializer = new StringRedisSerializer();
redisTemplate.setKeySerializer(stringSerializer);
redisTemplate.setValueSerializer(stringSerializer);
redisTemplate.setHashKeySerializer(stringSerializer);
redisTemplate.setHashValueSerializer(stringSerializer);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
package com.github.wxiaoqi.security.admin.entity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* 用户详情信息表
*/
@Table(name = "app_user_detail")
@Data
public class AppUserDetail {
@Id
@GeneratedValue(generator = "JDBC")
private int id;
private Integer userid;
@Column(name = "is_member")
private Integer isMember;
private String nickname;
private String realname;
private String headimgurl;
private String email;
private Integer sex;
private String birthday;
@Column(name = "person_sign")
private String personSign;
private String remark;
private Long createtime;
private Long updatetime;
private Integer isdel;
}
package com.github.wxiaoqi.security.admin.entity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* 用户登录信息表
*/
@Table(name = "app_user_login")
@Data
public class AppUserLogin {
@Id
@GeneratedValue(generator = "JDBC")
private int id;
@Column(name = "im_userid")
private Integer imUserid;
private String username;
private String password;
@Column(name = "wx_openid")
private String wxOpenid;
private String unionid;
private String openid;
private Long createtime;
private Long updatetime;
private Integer isdel;
private Integer status;
}
package com.github.wxiaoqi.security.admin.mapper;
import com.github.wxiaoqi.security.admin.entity.AppUserDetail;
import tk.mybatis.mapper.common.Mapper;
public interface AppUserDetailMapper extends Mapper<AppUserDetail> {
}
\ No newline at end of file
package com.github.wxiaoqi.security.admin.mapper;
import com.github.wxiaoqi.security.admin.entity.AppUserLogin;
import tk.mybatis.mapper.common.Mapper;
public interface AppUserLoginMapper extends Mapper<AppUserLogin> {
}
\ No newline at end of file
package com.github.wxiaoqi.security.admin.rpc;
import com.ace.cache.annotation.Cache;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.admin.rpc.service.AppPermissionService;
import com.github.wxiaoqi.security.admin.rpc.service.PermissionService;
import com.github.wxiaoqi.security.api.vo.authority.PermissionInfo;
......@@ -40,5 +41,17 @@ public class AppUserRest {
return appPermissionService.validate(body.get("username"),body.get("password"));
}
/**
* 发送验证码
* @param username
* @param type 0-注册验证,1-找回密码验证,2&3-修改手机号
* @return
*/
@RequestMapping(value = "/user/sendsms", method = RequestMethod.POST)
public @ResponseBody
JSONObject sendsms(@RequestParam(value="username",defaultValue="")String username, @RequestParam(value="type",defaultValue="0")Integer type){
return appPermissionService.sendSMS(username,type);
}
}
package com.github.wxiaoqi.security.admin.rpc;
import com.ace.cache.annotation.Cache;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.admin.rpc.service.PermissionService;
import com.github.wxiaoqi.security.api.vo.authority.PermissionInfo;
import com.github.wxiaoqi.security.api.vo.user.UserInfo;
......@@ -41,4 +42,7 @@ public class UserRest {
}
}
package com.github.wxiaoqi.security.admin.rpc.service;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.admin.biz.AppUserBiz;
import com.github.wxiaoqi.security.admin.biz.AppUserDetailBiz;
import com.github.wxiaoqi.security.admin.biz.AppUserLoginBiz;
import com.github.wxiaoqi.security.admin.biz.ElementBiz;
import com.github.wxiaoqi.security.admin.entity.AppUser;
import com.github.wxiaoqi.security.admin.entity.Element;
import com.github.wxiaoqi.security.admin.entity.Menu;
import com.github.wxiaoqi.security.admin.entity.*;
import com.github.wxiaoqi.security.api.vo.authority.PermissionInfo;
import com.github.wxiaoqi.security.api.vo.user.AppUserInfo;
import com.github.wxiaoqi.security.common.util.VerificationUtils;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.github.wxiaoqi.security.common.util.process.SystemConfig;
import com.github.wxiaoqi.security.common.util.result.JsonResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* @author keliii
*/
@Service
@Slf4j
public class AppPermissionService {
@Autowired
......@@ -28,6 +40,12 @@ public class AppPermissionService {
ElementBiz elementBiz;
private BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(12);
@Autowired
private RedisTemplate userRedisTemplate;
@Autowired
private AppUserDetailBiz appUserDetailBiz;
@Autowired
private AppUserLoginBiz appUserLoginBiz;
public AppUserInfo validate(String username, String password) {
......@@ -62,4 +80,159 @@ public class AppPermissionService {
result.add(info);
}
}
/**
* 发送短信
*
* @param phone
* @param type
* @return phone手机号 type:类型(0用户注册,1微信绑定,2人脸注册,3忘记密码,4直接发送验证码) 改写发送验证码方法(暂时通过测试)
*/
public JSONObject sendSMS(String phone, Integer type) {
if (StringUtils.isBlank(phone) || type == null) {
return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "参数为空");
}
// 验证手机号码是否正确
if (!VerificationUtils.getPvu().checkMobileNumber(phone)) {
return JsonResultUtil.createFailedResult(ResultCode.FAILED_CODE, "手机号码有误");
}
// 组织返回结果集
JSONObject result = new JSONObject();
if (type == 0) {
AppUserLogin rsUserLogin = appUserLoginBiz.checkeUserLogin(phone);
if (rsUserLogin != null)
return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "用户已存在");
} else if (type == 1) {
AppUserLogin rsUserLogin = appUserLoginBiz.checkeUserLogin(phone);
// 判断手机号码是否已绑定
boolean isBind = appUserLoginBiz.checkeWechatUser(rsUserLogin);
if (!isBind) {
return JsonResultUtil.createFailedResultMsg(ResultCode.WX_BIND_CODE);
} else {
result.put("registered", rsUserLogin != null);
}
}/* else if (type == 3) {
if (checkeUserLogin(phone) == null)
return JsonResultUtil.createFailedResult(ResultCode.FAILED_CODE, "手机号未注册,请确认手机号无误");
}*/ else if (type == 4) {
AppUserLogin rsUserLogin = appUserLoginBiz.checkeUserLogin(phone);
if (rsUserLogin != null)
return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "手机号已注册");
}
// String sms = PassportUtil.SendSMS(phone, SystemConfig.SENDSMS_TITLE);
String mobilecode="123456";
log.info("调用短信发送接口返回值为:{}", mobilecode);
// 判断返回值是否为空,并且是否可以转换成JSONObject
if (StringUtils.isBlank(mobilecode))
return JsonResultUtil.createDefaultFail();
try {
/* JSONObject smsJSON = JSONObject.parseObject(sms);
if (smsJSON.getIntValue("error") != 0)
return JsonResultUtil.createDefaultFail();
JSONObject data = smsJSON.getJSONObject("data");
if (data == null)
return JsonResultUtil.createDefaultFail();
String mobilecode = data.getString("mobilecode");
if (mobilecode != null) {
result.put("mobilecode", mobilecode);
redisDao.set(phone + mobilecode, String.class, mobilecode, 300);
}*/
result.put("mobilecode", mobilecode);
// redisDao.set(phone + mobilecode, String.class, mobilecode, 300);
userRedisTemplate.opsForValue().set(phone + mobilecode,mobilecode,300, TimeUnit.SECONDS);
} catch (Exception e) {
return JsonResultUtil.createFailedResult(ResultCode.EXCEPTION_CODE, "出现异常");
}
return JsonResultUtil.createSuccessResultWithObj(result);
}
/**
* 注册用户
*
* @param username
* @param password
* @param headimgurl
* @param mobilecode
*/
@Transactional
public JSONObject register(HttpServletRequest request, String username, String password, String headimgurl, String nickname, String mobilecode) {
// 判断参数和验证码
if (StringUtils.isBlank(username) || StringUtils.isBlank(password) || StringUtils.isBlank(mobilecode)) {
return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "参数为空");
}
String mobilecodeRedis=userRedisTemplate.opsForValue().get(username + mobilecode).toString();
// 获取到缓存的验证码后要先清空缓存对应键的值
userRedisTemplate.delete(username + mobilecode);
log.error("注册接口,获取redis中的验证码:" + mobilecodeRedis);
if (mobilecodeRedis == null) {
return JsonResultUtil.createFailedResult(ResultCode.NOTEXIST_CODE, "验证码错误");
}
// 是否已存在
AppUserLogin user = appUserLoginBiz.checkeUserLogin(username);
if (null != user) {
return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "用户已存在");
}
// 新增用户登录信息
try {
Long now = System.currentTimeMillis() / 1000;
AppUserLogin appUserLogin = new AppUserLogin();
//String userid = result.getJSONObject("data").getString("userid");
appUserLogin.setUsername(username);
appUserLogin.setPassword(password);
appUserLogin.setIsdel(0);
appUserLogin.setStatus(0);
appUserLogin.setCreatetime(now);
appUserLogin.setUpdatetime(now);
appUserLoginBiz.insertSelective(appUserLogin);
Integer userid=appUserLogin.getId();
log.error("注册:新增登陆用户信息: " + userid);
// 新增用户详情
AppUserDetail rsUserDetail = new AppUserDetail();
rsUserDetail.setUserid(userid);
rsUserDetail.setNickname(nickname);
rsUserDetail.setHeadimgurl(headimgurl); // 默认路径,待写
rsUserDetail.setCreatetime(now);
rsUserDetail.setUpdatetime(now);
rsUserDetail.setIsdel(0);
appUserDetailBiz.insertSelective(rsUserDetail);
log.error("注册:新增用户详情: " + userid);
// 登录结果要做做统一处理
JSONObject data = autoLogin(userid, username, headimgurl, nickname);
/* // 到im注册,获取返回结果
*/
if (data != null) {
return JsonResultUtil.createSuccessResultWithObj(data);
} else {
return JsonResultUtil.createDefaultFail();
}
} catch (Exception e) {
e.printStackTrace();
return JsonResultUtil.createFailedResult(ResultCode.EXCEPTION_CODE, "出现异常");
}
}
/**
* 自动登录
*/
public JSONObject autoLogin(Integer userid, String username, String headimgurl, String nickname) {
JSONObject data = new JSONObject();
AppUserLogin userLoign = appUserLoginBiz.selectById(userid);
if (userLoign!=null) {
// 缓存操作
String token="";
String imtoken_="";
userRedisTemplate.opsForValue().set("token_" + userid,token, SystemConfig.REDISTOKENTIME, TimeUnit.SECONDS);
userRedisTemplate.opsForValue().set("imtoken_" + userid,imtoken_,SystemConfig.REDISTOKENTIME, TimeUnit.SECONDS);
// 返回结果
data.put("token", token);
data.put("imtoken", imtoken_);
data.put("nickname", nickname);
data.put("headerurl",headimgurl);
}
return data;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment