├── dingding-app-server-web ├── src │ ├── main │ │ ├── webapp │ │ │ ├── WEB-INF │ │ │ │ ├── lib │ │ │ │ │ └── taobao.api-1.0.0.jar │ │ │ │ └── web.xml │ │ │ └── static │ │ │ │ └── download │ │ │ │ └── index.html │ │ ├── resources │ │ │ ├── config.properties │ │ │ ├── generatorConfig.properties │ │ │ ├── spring-config-executor.xml │ │ │ ├── spring-config.xml │ │ │ ├── spring-config-redis.xml │ │ │ ├── spring-config-datasource.xml │ │ │ ├── log4j2.xml │ │ │ ├── generatorConfig.xml │ │ │ └── spring-config-mvc.xml │ │ └── java │ │ │ └── com │ │ │ └── mocoder │ │ │ └── dingding │ │ │ └── web │ │ │ ├── annotation │ │ │ ├── RequiredParam.java │ │ │ └── ValidateBody.java │ │ │ ├── util │ │ │ ├── BodyAlgorithmEnum.java │ │ │ ├── CacheKeyGenerator.java │ │ │ ├── ExceptionResolver.java │ │ │ └── RequestArgumentResolver.java │ │ │ ├── exception │ │ │ └── ParameterValidateException.java │ │ │ ├── interceptor │ │ │ ├── ValidatorInterceptor.java │ │ │ ├── LoginStatusInterceptor.java │ │ │ ├── EncryptParameterValidateInterceptor.java │ │ │ └── BaseParamValidateInterceptor.java │ │ │ └── controller │ │ │ ├── ParameterController.java │ │ │ ├── IndexController.java │ │ │ └── LoginAccountController.java │ └── test │ │ └── java │ │ └── com │ │ └── mocoder │ │ └── dingding │ │ └── test │ │ ├── service │ │ └── RpcServiceTest.java │ │ └── client │ │ ├── HttpClientUtil.java │ │ └── httpClientTest.java └── pom.xml ├── dingding-app-server-rpc ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── mocoder │ │ │ └── dingding │ │ │ └── rpc │ │ │ ├── othersys │ │ │ └── XxxServiceWrap.java │ │ │ ├── SmsServiceWrap.java │ │ │ └── impl │ │ │ └── SmsServiceWrapImpl.java │ │ └── resources │ │ └── rpc │ │ ├── spring-config-jsf-client.xml │ │ └── spring-config-saf-client.xml └── pom.xml ├── dingding-app-server-model ├── src │ └── main │ │ └── java │ │ └── com │ │ └── mocoder │ │ └── dingding │ │ ├── constants │ │ ├── AppVersionConstant.java │ │ ├── EncryptionConstant.java │ │ ├── PlatformConstant.java │ │ ├── SessionKeyConstant.java │ │ ├── RequestAttributeKeyConstant.java │ │ └── RedisKeyConstant.java │ │ ├── vo │ │ ├── CommonResponse.java │ │ ├── LoginAccountRequest.java │ │ └── CommonRequest.java │ │ └── enums │ │ └── ErrorTypeEnum.java └── pom.xml ├── README.md ├── dingding-app-server-utils ├── src │ └── main │ │ └── java │ │ └── com │ │ └── mocoder │ │ └── dingding │ │ └── utils │ │ ├── bean │ │ ├── TypeRef.java │ │ └── RedisRequestSession.java │ │ ├── spring │ │ └── SpringContextHolder.java │ │ ├── web │ │ ├── JsonUtil.java │ │ ├── WebUtil.java │ │ └── RedisUtil.java │ │ └── encryp │ │ └── EncryptUtils.java └── pom.xml ├── profiles-dev.properties ├── profiles-test.properties ├── profiles-production.properties ├── dingding-app-server-dao ├── src │ └── main │ │ ├── resources │ │ ├── mybatis-config.xml │ │ └── mapper │ │ │ └── LoginAccountMapper.xml │ │ └── java │ │ └── com │ │ └── mocoder │ │ └── dingding │ │ ├── dao │ │ └── LoginAccountMapper.java │ │ └── model │ │ ├── LoginAccount.java │ │ └── LoginAccountCriteria.java └── pom.xml ├── dingding-app-server-service ├── src │ └── main │ │ └── java │ │ └── com │ │ └── mocoder │ │ └── dingding │ │ └── service │ │ ├── LoginAccountService.java │ │ └── impl │ │ └── LoginAccountServiceImpl.java └── pom.xml └── LICENSE /dingding-app-server-web/src/main/webapp/WEB-INF/lib/taobao.api-1.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangshuai0711/dingding-app-server/HEAD/dingding-app-server-web/src/main/webapp/WEB-INF/lib/taobao.api-1.0.0.jar -------------------------------------------------------------------------------- /dingding-app-server-rpc/src/main/java/com/mocoder/dingding/rpc/othersys/XxxServiceWrap.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.rpc.othersys; 2 | 3 | /** 4 | * 外系统服务(接口)包装类型 5 | * @author wenjun 6 | * 7 | */ 8 | public class XxxServiceWrap { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /dingding-app-server-model/src/main/java/com/mocoder/dingding/constants/AppVersionConstant.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.constants; 2 | 3 | /** 4 | * Created by yangshuai3 on 2016/1/28. 5 | */ 6 | public class AppVersionConstant { 7 | public static final String VERSION_1_0_0 = "1.0.0"; 8 | } 9 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/resources/config.properties: -------------------------------------------------------------------------------- 1 | common.dateFormat=yyyy-MM-dd HH:mm:ss 2 | app.session.timeout.days=7 3 | #taobao sms api config 4 | taobao.api.sms.url=http://gw.api.taobao.com/router/rest 5 | taobao.api.sms.appkey=23402595 6 | taobao.api.sms.secret=bd79d5b490f680eb8a9c14c10be651e7 7 | taobao.api.verify.code=3rdjia1 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dingding-app-server 2 | this is a project or webapp for mobile ,contains some basic function such as register and login. 3 | it is just a demo and have nothing to do with a real project. 4 | it is public because a private repository is not for free. 5 | so,please,please and please do not look into it or clone it to your computer. 6 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/java/com/mocoder/dingding/web/annotation/RequiredParam.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.web.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Created by yangshuai3 on 2016/2/1. 7 | */ 8 | 9 | @Target(ElementType.FIELD) 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Documented 12 | public @interface RequiredParam { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /dingding-app-server-model/src/main/java/com/mocoder/dingding/constants/EncryptionConstant.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.constants; 2 | 3 | /** 4 | * Created by yangshuai3 on 2016/1/28. 5 | */ 6 | public class EncryptionConstant { 7 | public static final String HEADER_PARAM_SIGN_PRIVATE_KEY = "66666"; 8 | public static final String DES_ENCRYPT_PRIVATE_KEY = "40010011"; 9 | } 10 | -------------------------------------------------------------------------------- /dingding-app-server-model/src/main/java/com/mocoder/dingding/constants/PlatformConstant.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.constants; 2 | 3 | /** 4 | * Created by yangshuai3 on 2016/1/28. 5 | */ 6 | public class PlatformConstant { 7 | public static final String ANDROID = "android"; 8 | public static final String IOS = "ios"; 9 | public static final String HTML5 = "html5"; 10 | } 11 | -------------------------------------------------------------------------------- /dingding-app-server-utils/src/main/java/com/mocoder/dingding/utils/bean/TypeRef.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.utils.bean; 2 | 3 | import org.codehaus.jackson.type.TypeReference; 4 | 5 | /** 6 | * Created by yangshuai on 16/1/31. 7 | */ 8 | public class TypeRef extends TypeReference { 9 | 10 | @Override 11 | public int compareTo(TypeReference o) { 12 | return this.getType().equals(o.getType())?0:1; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /dingding-app-server-model/src/main/java/com/mocoder/dingding/constants/SessionKeyConstant.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.constants; 2 | 3 | /** 4 | * Created by yangshuai on 16/2/1. 5 | */ 6 | public class SessionKeyConstant { 7 | public static final String USER_LOGIN_KEY = "USER_LOGIN_KEY"; 8 | public static final String VERIFY_CODE_KEY = "VERIFY_CODE_KEY"; 9 | public static final String LOGIN_TYPE_KEY = "USER_LOGIN_TYPE_KEY"; 10 | } 11 | -------------------------------------------------------------------------------- /profiles-dev.properties: -------------------------------------------------------------------------------- 1 | #log config 2 | mvn.log.level=info 3 | mvn.log.path=~/export/logs 4 | mvn.app.domainName=dingding.com 5 | 6 | #jdbc config 7 | mvn.jdbc.driver=com.mysql.jdbc.Driver 8 | mvn.jdbc.url=jdbc:mysql://127.0.0.1:3306/dingding 9 | mvn.jdbc.username=root 10 | mvn.jdbc.password=1234 11 | 12 | # Redis settings 13 | redis.host=127.0.0.1 14 | redis.port=6379 15 | redis.database=0 16 | redis.maxIdle=1 17 | redis.maxWait=50000 18 | redis.testOnBorrow=true -------------------------------------------------------------------------------- /profiles-test.properties: -------------------------------------------------------------------------------- 1 | #log config 2 | mvn.log.level=warn 3 | mvn.log.path=~/export/logs 4 | mvn.app.domainName=dingding.com 5 | 6 | #jdbc config 7 | mvn.jdbc.driver=com.mysql.jdbc.Driver 8 | mvn.jdbc.url=jdbc:mysql://127.0.0.1:3306/dingding 9 | mvn.jdbc.username=root 10 | mvn.jdbc.password=1234 11 | 12 | # Redis settings 13 | redis.host=127.0.0.1 14 | redis.port=6379 15 | redis.database=0 16 | redis.maxIdle=300 17 | redis.maxWait=3000 18 | redis.testOnBorrow=true -------------------------------------------------------------------------------- /profiles-production.properties: -------------------------------------------------------------------------------- 1 | #log config 2 | mvn.log.level=warn 3 | mvn.log.path=export/logs 4 | mvn.app.domainName=dingding.mocoder.com 5 | 6 | #jdbc config 7 | mvn.jdbc.driver=com.mysql.jdbc.Driver 8 | mvn.jdbc.url=jdbc:mysql://127.0.0.1:3306/dingding 9 | mvn.jdbc.username=root 10 | mvn.jdbc.password=1234 11 | 12 | # Redis settings 13 | redis.host=127.0.0.1 14 | redis.port=6379 15 | redis.database=0 16 | redis.maxIdle=30 17 | redis.maxWait=3000 18 | redis.testOnBorrow=true -------------------------------------------------------------------------------- /dingding-app-server-model/src/main/java/com/mocoder/dingding/constants/RequestAttributeKeyConstant.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.constants; 2 | 3 | /** 4 | * Created by yangshuai3 on 2016/2/3. 5 | */ 6 | public class RequestAttributeKeyConstant { 7 | public static final String REQUEST_ATTRIBUTE_KEY_COMMON_REQUEST = "REQUEST_ATTRIBUTE_KEY_COMMON_REQUEST"; 8 | public static final String REQUEST_ATTRIBUTE_KEY_REQUEST_SESSION = "REQUEST_ATTRIBUTE_KEY_REQUEST_SESSION"; 9 | } 10 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/java/com/mocoder/dingding/web/util/BodyAlgorithmEnum.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.web.util; 2 | 3 | /** 4 | * Created by yangshuai3 on 2016/2/4. 5 | */ 6 | public enum BodyAlgorithmEnum { 7 | 8 | BASE64("base64"), 9 | DES("des") 10 | ; 11 | private String name; 12 | 13 | BodyAlgorithmEnum(String name) { 14 | this.name = name; 15 | } 16 | 17 | public String getName() { 18 | return name; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/webapp/static/download/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 京东ME下载 6 | 7 | 8 | 9 | 10 | 点击右上角“···”,选择“在Safari中打开”进行下载 11 | 15 | 16 | -------------------------------------------------------------------------------- /dingding-app-server-model/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | dingding-app-server 7 | com.mocoder.dingding 8 | 1.0-SNAPSHOT 9 | 10 | 11 | 4.0.0 12 | 13 | dingding-app-server-model 14 | dingding-app-server-model 15 | 16 | 17 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/resources/generatorConfig.properties: -------------------------------------------------------------------------------- 1 | #classPath=C:\\Users\\Administrator\\.m2\\repository\\mysql\\mysql-connector-java\\5.1.21\\mysql-connector-java-5.1.21.jar 2 | classPath=/Users/yangshuai/.m2/repository/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar 3 | driverClass=com.mysql.jdbc.Driver 4 | connectionURL=jdbc:mysql://115.28.240.152:3306/dingding?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull 5 | targetProject=../dingding-app-server-dao 6 | schema=dingding 7 | userId=root 8 | password=870711Mysql 9 | modelPackage=com.mocoder.dingding.model 10 | sqlMapperPackage=mapper 11 | daoMapperPackage=com.mocoder.dingding.dao -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/resources/spring-config-executor.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /dingding-app-server-rpc/src/main/resources/rpc/spring-config-jsf-client.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 14 | -------------------------------------------------------------------------------- /dingding-app-server-rpc/src/main/java/com/mocoder/dingding/rpc/SmsServiceWrap.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.rpc; 2 | 3 | /** 4 | * 短信发送接口包装类 5 | */ 6 | public interface SmsServiceWrap { 7 | 8 | /** 9 | * 发送登录验证码短信 10 | * @param validCode 11 | * @param mobileNum 12 | * @return 13 | */ 14 | public boolean sentLoginValidCodeSms(String mobileNum,String validCode); 15 | 16 | /** 17 | * 发送登录验证码短信 18 | * @param validCode 19 | * @param mobileNum 20 | * @return 21 | */ 22 | public boolean sentRegValidCodeSms(String mobileNum,String validCode); 23 | /** 24 | * 发送重要操作验证码短信 25 | * @param validCode 26 | * @param mobileNum 27 | * @return 28 | */ 29 | public boolean sentRegValidCodeSms(String mobileNum,String validCode,String operate); 30 | } 31 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/java/com/mocoder/dingding/web/annotation/ValidateBody.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.web.annotation; 2 | 3 | import com.mocoder.dingding.web.util.BodyAlgorithmEnum; 4 | 5 | import java.lang.annotation.*; 6 | 7 | /** 8 | * Created by yangshuai3 on 2016/2/1. 9 | */ 10 | 11 | @Target(ElementType.PARAMETER) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface ValidateBody { 15 | /** 16 | * @return 参数字段名,从request.getParameter获取 17 | */ 18 | String value() default "body"; 19 | 20 | /** 21 | * @return 对称加密算法 22 | * @see com.mocoder.dingding.web.util.BodyAlgorithmEnum 23 | */ 24 | BodyAlgorithmEnum[] algorithm() default {}; 25 | 26 | /** 27 | * 必需字段名 28 | * @return 29 | */ 30 | String[] requiredAttrs() default {}; 31 | } 32 | -------------------------------------------------------------------------------- /dingding-app-server-model/src/main/java/com/mocoder/dingding/constants/RedisKeyConstant.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.constants; 2 | 3 | /** 4 | * Created by yangshuai on 16/1/31. 5 | */ 6 | public class RedisKeyConstant { 7 | public static final String PROJECT_PREFIX="DINGDING_"; 8 | public static final String REQUEST_SESSION_KEY_PREFIX=PROJECT_PREFIX+"REQUEST_SESSION_KEY_PREFIX_"; 9 | public static final String USER_REQUEST_SESSION_INFO_KEY_PREFIX=PROJECT_PREFIX+"USER_REQUEST_SESSION_INFO_KEY_PREFIX_"; 10 | public static final String TEMP_SESSION_ID_PREFIX = PROJECT_PREFIX+ "TEMP_SESSION_ID_PREFIX"; 11 | public static final String USER_LOGIN_RETRY_TIMES_KEY = PROJECT_PREFIX+ "USER_LOGIN_RETRY_TIMES_KEY"; 12 | public static final String USER_GET_VERIFY_CODE_TIMES_KEY = PROJECT_PREFIX+ "USER_LOGIN_RETRY_TIMES_KEY"; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /dingding-app-server-utils/src/main/java/com/mocoder/dingding/utils/spring/SpringContextHolder.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.utils.spring; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationContextAware; 6 | 7 | /** 8 | * Created by yangshuai on 16/1/31. 9 | */ 10 | public class SpringContextHolder implements ApplicationContextAware{ 11 | private static ApplicationContext context; 12 | @Override 13 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 14 | context = applicationContext; 15 | } 16 | 17 | public static T getBean(Class claz){ 18 | return context.getBean(claz); 19 | } 20 | 21 | public static T getBean(String name){ 22 | return (T)context.getBean(name); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/test/java/com/mocoder/dingding/test/service/RpcServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.test.service; 2 | 3 | import com.mocoder.dingding.rpc.SmsServiceWrap; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.test.context.ContextConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | import javax.annotation.Resource; 10 | 11 | /** 12 | * Created with IntelliJ IDEA. 13 | * User: likun7 14 | * Date: 14-11-19 15 | * Time: 上午11:52 16 | * To change this template use File | Settings | File Templates. 17 | */ 18 | @RunWith(SpringJUnit4ClassRunner.class) 19 | @ContextConfiguration({"classpath:spring-config.xml"}) 20 | public class RpcServiceTest { 21 | @Resource 22 | private SmsServiceWrap smsServiceWrap; 23 | 24 | @Test 25 | public void sentSms(){ 26 | smsServiceWrap.sentLoginValidCodeSms("15652301160","1234"); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /dingding-app-server-dao/src/main/resources/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/java/com/mocoder/dingding/web/util/CacheKeyGenerator.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.web.util; 2 | 3 | import com.mocoder.dingding.utils.web.JsonUtil; 4 | import org.springframework.cache.interceptor.DefaultKeyGenerator; 5 | import org.springframework.cache.interceptor.KeyGenerator; 6 | 7 | import java.io.IOException; 8 | import java.lang.reflect.Method; 9 | 10 | /** 11 | * Created by yangshuai on 16/1/30. 12 | */ 13 | public class CacheKeyGenerator implements KeyGenerator { 14 | @Override 15 | public Object generate(Object target, Method method, Object... params) { 16 | try { 17 | StringBuilder sb = new StringBuilder(target.getClass().getName()).append('.') 18 | .append(method.getName()).append('(').append(JsonUtil.toString(params)) 19 | .append(')'); 20 | return sb.toString(); 21 | } catch (IOException e) { 22 | throw new RuntimeException("spring cache key 生成失败"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /dingding-app-server-model/src/main/java/com/mocoder/dingding/vo/CommonResponse.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.vo; 2 | 3 | import com.mocoder.dingding.enums.ErrorTypeEnum; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * Created by yangshuai3 on 2016/1/26. 9 | */ 10 | public class CommonResponse implements Serializable { 11 | private String code; 12 | private String msg; 13 | private T data; 14 | 15 | 16 | public String getCode() { 17 | return code; 18 | } 19 | 20 | public void setCode(String code) { 21 | this.code = code; 22 | } 23 | 24 | public String getMsg() { 25 | return msg; 26 | } 27 | 28 | public void setMsg(String msg) { 29 | this.msg = msg; 30 | } 31 | 32 | public void resolveErrorInfo(ErrorTypeEnum errorType) { 33 | this.code=String.valueOf(errorType.getCode()); 34 | this.msg =errorType.getUiMsg(); 35 | } 36 | 37 | public T getData() { 38 | return data; 39 | } 40 | 41 | public void setData(T data) { 42 | this.data = data; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /dingding-app-server-dao/src/main/java/com/mocoder/dingding/dao/LoginAccountMapper.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.dao; 2 | 3 | import com.mocoder.dingding.model.LoginAccount; 4 | import com.mocoder.dingding.model.LoginAccountCriteria; 5 | import java.util.List; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface LoginAccountMapper { 9 | int countByExample(LoginAccountCriteria example); 10 | 11 | int deleteByExample(LoginAccountCriteria example); 12 | 13 | int deleteByPrimaryKey(Integer id); 14 | 15 | int insert(LoginAccount record); 16 | 17 | int insertSelective(LoginAccount record); 18 | 19 | List selectByExample(LoginAccountCriteria example); 20 | 21 | LoginAccount selectByPrimaryKey(Integer id); 22 | 23 | int updateByExampleSelective(@Param("record") LoginAccount record, @Param("example") LoginAccountCriteria example); 24 | 25 | int updateByExample(@Param("record") LoginAccount record, @Param("example") LoginAccountCriteria example); 26 | 27 | int updateByPrimaryKeySelective(LoginAccount record); 28 | 29 | int updateByPrimaryKey(LoginAccount record); 30 | } -------------------------------------------------------------------------------- /dingding-app-server-rpc/src/main/resources/rpc/spring-config-saf-client.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 19 | -------------------------------------------------------------------------------- /dingding-app-server-dao/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | com.mocoder.dingding 5 | dingding-app-server 6 | 1.0-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | dingding-app-server-dao 11 | dingding-app-server-dao 12 | 13 | 14 | com.mocoder.dingding 15 | dingding-app-server-model 16 | 1.0-SNAPSHOT 17 | 18 | 19 | org.springframework 20 | spring-context 21 | 22 | 23 | 24 | org.mybatis 25 | mybatis 26 | 27 | 28 | org.mybatis 29 | mybatis-spring 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/java/com/mocoder/dingding/web/exception/ParameterValidateException.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.web.exception; 2 | 3 | import com.mocoder.dingding.enums.ErrorTypeEnum; 4 | import com.mocoder.dingding.vo.CommonResponse; 5 | 6 | /** 7 | * Created by yangshuai3 on 2016/2/4. 8 | */ 9 | public class ParameterValidateException extends Exception{ 10 | private CommonResponse response = new CommonResponse(); 11 | 12 | public ParameterValidateException(Throwable cause) { 13 | super(cause); 14 | response.resolveErrorInfo(ErrorTypeEnum.INPUT_PARAMETER_VALIDATE_ERROR); 15 | } 16 | 17 | public ParameterValidateException(String message, Throwable cause) { 18 | super(message, cause); 19 | response.resolveErrorInfo(ErrorTypeEnum.INPUT_PARAMETER_VALIDATE_ERROR); 20 | } 21 | 22 | public ParameterValidateException(String message) { 23 | super(message); 24 | response.resolveErrorInfo(ErrorTypeEnum.INPUT_PARAMETER_VALIDATE_ERROR); 25 | } 26 | 27 | public ParameterValidateException() { 28 | super(); 29 | response.resolveErrorInfo(ErrorTypeEnum.INPUT_PARAMETER_VALIDATE_ERROR); 30 | } 31 | 32 | public CommonResponse getResponse() { 33 | return response; 34 | } 35 | 36 | public void setErrorType(ErrorTypeEnum errorType){ 37 | response.resolveErrorInfo(errorType); 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/java/com/mocoder/dingding/web/interceptor/ValidatorInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.web.interceptor; 2 | 3 | import org.apache.logging.log4j.LogManager; 4 | import org.apache.logging.log4j.Logger; 5 | import org.springframework.web.servlet.HandlerInterceptor; 6 | import org.springframework.web.servlet.ModelAndView; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | /** 12 | * 校验拦截器抽象类,用于参数校验 13 | * Created by yangshuai3 on 2016/1/26. 14 | */ 15 | public abstract class ValidatorInterceptor implements HandlerInterceptor { 16 | 17 | protected static final Logger logger = LogManager.getLogger(ValidatorInterceptor.class); 18 | 19 | @Override 20 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 21 | return validate(request,response); 22 | } 23 | 24 | /** 25 | * 实现校验逻辑 26 | * @param request 27 | * @param response 28 | * @return 29 | */ 30 | protected abstract boolean validate(HttpServletRequest request, HttpServletResponse response); 31 | 32 | @Override 33 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { 34 | 35 | } 36 | 37 | @Override 38 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /dingding-app-server-model/src/main/java/com/mocoder/dingding/vo/LoginAccountRequest.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.vo; 2 | 3 | import java.io.Serializable; 4 | 5 | public class LoginAccountRequest implements Serializable { 6 | 7 | private String mobile; 8 | 9 | private String nickName; 10 | 11 | private String password; 12 | 13 | private String verifyCode; 14 | 15 | private String oldPassword; 16 | 17 | private static final long serialVersionUID = 1L; 18 | 19 | public String getMobile() { 20 | return mobile; 21 | } 22 | 23 | public void setMobile(String mobile) { 24 | this.mobile = mobile == null ? null : mobile.trim(); 25 | } 26 | 27 | public String getNickName() { 28 | return nickName; 29 | } 30 | 31 | public void setNickName(String nickName) { 32 | this.nickName = nickName == null ? null : nickName.trim(); 33 | } 34 | 35 | public String getPassword() { 36 | return password; 37 | } 38 | 39 | public void setPassword(String password) { 40 | this.password = password == null ? null : password.trim(); 41 | } 42 | 43 | public String getVerifyCode() { 44 | return verifyCode; 45 | } 46 | 47 | public void setVerifyCode(String verifyCode) { 48 | this.verifyCode = verifyCode; 49 | } 50 | 51 | public String getOldPassword() { 52 | return oldPassword; 53 | } 54 | 55 | public void setOldPassword(String oldPassword) { 56 | this.oldPassword = oldPassword; 57 | } 58 | } -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/resources/spring-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 16 | 17 | classpath:config.properties 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /dingding-app-server-model/src/main/java/com/mocoder/dingding/enums/ErrorTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.enums; 2 | 3 | /** 4 | * Created by yangshuai3 on 2016/1/28. 5 | */ 6 | public enum ErrorTypeEnum { 7 | 8 | SYSTEM_EXCEPTION(10,"后台程序异常","系统繁忙,请重试"), 9 | SYSTEM_ENV_EXCEPTION(11,"系统环境异常","系统繁忙,请重试"), 10 | 11 | INPUT_PARAMETER_VALIDATE_ERROR(20,"参数校验错误","系统繁忙,请重试"), 12 | INPUT_PARAMETER_SESSION_ERROR(-20,"参数sessionId为空","系统繁忙,请重试"), 13 | INPUT_PARAMETER_PARSE_ERROR(21,"入参解析错误","系统繁忙,请重试"), 14 | 15 | VALIDATE_CODE_ERROR(30,"验证码不正确","验证码输入有误,请重试"), 16 | VALIDATE_CODE_RETRY_ERROR(-30,"验证码不正确","验证码输入错误次数超过限制,请重新获取验证码"), 17 | NOT_LOGIN(-31,"未登录","您的登录信息已过期,请重新登录"), 18 | LOGIN_DUPLICATE_ERROR(31,"重复登录,session未过期,无需登录" ,"您已经在线,无需再次登录" ), 19 | REG_DUPLICATE_ERROR(32,"重复注册,手机号码已注册" ,"您的手机号码已注册" ), 20 | PASS_LOGIN_ERROR(33,"密码错误","账号或密码错误"), 21 | ACCOUNT_NOT_EXISTS(35,"手机号不存在","该手机号还没有注册"), 22 | NOT_LOG_OUT_ERROR(36,"需要退出登录状态","请先退出登录"), 23 | 24 | SMS_SEND_ERROR(40,"短信发送失败","短信发送失败,请稍后再试"), 25 | 26 | USER_OPERATE_NOT_PERMIT(50,"用户没有权限进行此操作","您没有权限进行此操作") 27 | ; 28 | 29 | private Integer code; 30 | private String msg; 31 | private String uiMsg; 32 | 33 | ErrorTypeEnum(Integer code, String msg, String uiMsg) { 34 | this.code = code; 35 | this.msg = msg; 36 | this.uiMsg = uiMsg; 37 | } 38 | 39 | public Integer getCode() { 40 | return code; 41 | } 42 | 43 | public String getMsg() { 44 | return msg; 45 | } 46 | 47 | public String getUiMsg() { 48 | return uiMsg; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/java/com/mocoder/dingding/web/interceptor/LoginStatusInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.web.interceptor; 2 | 3 | import com.mocoder.dingding.constants.RequestAttributeKeyConstant; 4 | import com.mocoder.dingding.constants.SessionKeyConstant; 5 | import com.mocoder.dingding.enums.ErrorTypeEnum; 6 | import com.mocoder.dingding.utils.bean.RedisRequestSession; 7 | import com.mocoder.dingding.utils.web.WebUtil; 8 | import com.mocoder.dingding.vo.CommonResponse; 9 | 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import java.io.IOException; 13 | 14 | /** 15 | * 登录状态拦截器 16 | * Created by yangshuai3 on 2016/1/28. 17 | */ 18 | public class LoginStatusInterceptor extends EncryptParameterValidateInterceptor { 19 | 20 | @Override 21 | protected boolean validate(HttpServletRequest request, HttpServletResponse response) { 22 | if (!super.validate(request, response)) { 23 | return false; 24 | } 25 | RedisRequestSession session = (RedisRequestSession) request.getAttribute(RequestAttributeKeyConstant.REQUEST_ATTRIBUTE_KEY_REQUEST_SESSION); 26 | CommonResponse resp = new CommonResponse(); 27 | if (session.getAttribute(SessionKeyConstant.USER_LOGIN_KEY) == null) { 28 | resp.resolveErrorInfo(ErrorTypeEnum.NOT_LOGIN); 29 | try { 30 | WebUtil.writeResponse(response, resp); 31 | } catch (IOException e) { 32 | logger.error("登录拦截器:写出登录结果异常",e); 33 | } 34 | return false; 35 | } 36 | return true; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/java/com/mocoder/dingding/web/controller/ParameterController.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.web.controller; 2 | 3 | import com.mocoder.dingding.constants.RedisKeyConstant; 4 | import com.mocoder.dingding.utils.bean.RedisRequestSession; 5 | import com.mocoder.dingding.utils.encryp.EncryptUtils; 6 | import com.mocoder.dingding.utils.web.RedisUtil; 7 | import com.mocoder.dingding.vo.CommonRequest; 8 | import com.mocoder.dingding.vo.CommonResponse; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.ResponseBody; 12 | 13 | import java.util.UUID; 14 | 15 | /** 16 | * 登录账户相关功能的控制器,包括登录、注册、获取验证码等,其中获取验证码也对应不同的入口,这样是为了区分开是哪个功能调用的获取验证码,从来增加一些条件判断 17 | */ 18 | @Controller 19 | @RequestMapping("/param/") 20 | public class ParameterController { 21 | 22 | @RequestMapping("getSessionId") 23 | @ResponseBody 24 | public CommonResponse getSessionId(CommonRequest request,RedisRequestSession session){ 25 | CommonResponse response = new CommonResponse(); 26 | String uuid = UUID.randomUUID().toString(); 27 | String digested = EncryptUtils.md5(request.getDeviceid()); 28 | String sessionId=new StringBuffer(digested.substring(3,7)).append('-').append(digested.substring(9, 13)).append('-').append(uuid).toString(); 29 | //临时保存sessioId,用于验证用户请求使用的sessionId为系统分配的 30 | RedisUtil.setString(RedisKeyConstant.TEMP_SESSION_ID_PREFIX+sessionId,"ok",60*30L); 31 | response.setCode("0"); 32 | response.setData(sessionId); 33 | return response; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /dingding-app-server-model/src/main/java/com/mocoder/dingding/vo/CommonRequest.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.vo; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by yangshuai3 on 2016/1/26. 7 | */ 8 | public class CommonRequest implements Serializable{ 9 | private String appversion; 10 | private String platform; 11 | private String deviceid; 12 | private String sessionid; 13 | private String sign; 14 | private String timestamp; 15 | private String body; 16 | 17 | public String getAppversion() { 18 | return appversion; 19 | } 20 | 21 | public void setAppversion(String appversion) { 22 | this.appversion = appversion; 23 | } 24 | 25 | public String getPlatform() { 26 | return platform; 27 | } 28 | 29 | public void setPlatform(String platform) { 30 | this.platform = platform; 31 | } 32 | 33 | public String getDeviceid() { 34 | return deviceid; 35 | } 36 | 37 | public void setDeviceid(String deviceid) { 38 | this.deviceid = deviceid; 39 | } 40 | 41 | public String getSessionid() { 42 | return sessionid; 43 | } 44 | 45 | public void setSessionid(String sessionid) { 46 | this.sessionid = sessionid; 47 | } 48 | 49 | public String getSign() { 50 | return sign; 51 | } 52 | 53 | public void setSign(String sign) { 54 | this.sign = sign; 55 | } 56 | 57 | public String getTimestamp() { 58 | return timestamp; 59 | } 60 | 61 | public void setTimestamp(String timestamp) { 62 | this.timestamp = timestamp; 63 | } 64 | 65 | public String getBody() { 66 | return body; 67 | } 68 | 69 | public void setBody(String body) { 70 | this.body = body; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /dingding-app-server-utils/src/main/java/com/mocoder/dingding/utils/web/JsonUtil.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.utils.web; 2 | 3 | import com.mocoder.dingding.utils.bean.TypeRef; 4 | import org.codehaus.jackson.map.ObjectMapper; 5 | import org.codehaus.jackson.map.annotate.JsonSerialize; 6 | import org.codehaus.jackson.type.TypeReference; 7 | 8 | import java.io.IOException; 9 | 10 | /** 11 | * Created by yangshuai3 on 2016/1/26. 12 | */ 13 | public class JsonUtil { 14 | 15 | /** 16 | * 将对象按照json字符串格式输出 17 | * 18 | * @param obj javabean对象实例 19 | * @return json字符串 20 | * @throws IOException 21 | */ 22 | public static String toString(Object obj) throws IOException { 23 | if(obj==null){ 24 | return null; 25 | } 26 | ObjectMapper mapper = new ObjectMapper(); 27 | mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); 28 | return mapper.writeValueAsString(obj); 29 | } 30 | 31 | /** 32 | * 解析json字符串格式到javabean对象 33 | * 34 | * @param json json字符串 35 | * @param type 类型包装类,new新实力请带上泛型 36 | * @param 目标对象类型 37 | * @return 目标对象实例 38 | * @throws IOException 39 | */ 40 | public static T toObject(String json, TypeRef type) throws IOException { 41 | ObjectMapper mapper = new ObjectMapper(); 42 | return mapper.readValue(json, type); 43 | } 44 | 45 | /** 46 | * 解析json字符串格式到javabean对象 47 | * 48 | * @param json json字符串 49 | * @param claz 目标类型,不支持泛型 50 | * @param 目标对象类型 51 | * @return 目标对象实例 52 | * @throws IOException 53 | */ 54 | public static T toObject(String json, Class claz) throws IOException { 55 | ObjectMapper mapper = new ObjectMapper(); 56 | return mapper.readValue(json, claz); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/java/com/mocoder/dingding/web/util/ExceptionResolver.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.web.util; 2 | 3 | import com.mocoder.dingding.enums.ErrorTypeEnum; 4 | import com.mocoder.dingding.utils.web.WebUtil; 5 | import com.mocoder.dingding.vo.CommonResponse; 6 | import com.mocoder.dingding.web.exception.ParameterValidateException; 7 | import org.apache.logging.log4j.LogManager; 8 | import org.apache.logging.log4j.Logger; 9 | import org.springframework.web.servlet.ModelAndView; 10 | import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | import java.io.IOException; 15 | 16 | /** 17 | * Created by yangshuai3 on 2016/2/4. 18 | */ 19 | public class ExceptionResolver extends DefaultHandlerExceptionResolver{ 20 | private static final Logger log = LogManager.getLogger(ExceptionResolver.class); 21 | @Override 22 | protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { 23 | try { 24 | log.error("异常处理器:request:"+request.getRequestURI(),ex); 25 | if(ex instanceof ParameterValidateException){ 26 | WebUtil.writeResponse(response,((ParameterValidateException) ex).getResponse()); 27 | }else{ 28 | CommonResponse commonResp = new CommonResponse(); 29 | commonResp.resolveErrorInfo(ErrorTypeEnum.SYSTEM_EXCEPTION); 30 | WebUtil.writeResponse(response,commonResp); 31 | } 32 | return new ModelAndView(); 33 | } catch (IOException e) { 34 | log.error("异常处理器:写出返回值异常",e); 35 | } 36 | return super.doResolveException(request, response, handler, ex); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/java/com/mocoder/dingding/web/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.web.controller; 2 | 3 | import com.mocoder.dingding.dao.LoginAccountMapper; 4 | import com.mocoder.dingding.model.LoginAccountCriteria; 5 | import com.mocoder.dingding.utils.bean.RedisRequestSession; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.ui.ModelMap; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.bind.annotation.ResponseBody; 11 | 12 | import javax.annotation.Resource; 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | import java.util.Arrays; 16 | 17 | /** 18 | * XXX控制器 19 | * author: wenjun 20 | * Time: 2015.03.11 09:47 21 | */ 22 | @Controller 23 | @RequestMapping("/test") 24 | public class IndexController{ 25 | 26 | @SuppressWarnings("SpringJavaAutowiringInspection") 27 | @Resource 28 | private LoginAccountMapper loginAccountMapper; 29 | 30 | private String vmRootPath = "biz-index/"; 31 | 32 | /** 33 | * 主页 34 | * 35 | * @param request 36 | * @param response 37 | * @return 38 | */ 39 | @RequestMapping(value = "index", method = RequestMethod.GET) 40 | public String index(HttpServletRequest request, HttpServletResponse response, ModelMap model, String orderNo) { 41 | String result = vmRootPath.concat("index"); 42 | return result; 43 | } 44 | 45 | @RequestMapping("del") 46 | @ResponseBody 47 | public String del(String mobile){ 48 | try { 49 | RedisRequestSession.cleanUserAllDeviceSession(mobile); 50 | LoginAccountCriteria example = new LoginAccountCriteria(); 51 | example.createCriteria().andMobileEqualTo(mobile); 52 | if(loginAccountMapper.deleteByExample(example)>0){ 53 | return "ok"; 54 | } 55 | } catch (Exception e) { 56 | e.printStackTrace(); 57 | return e.toString()+Arrays.toString(e.getStackTrace()); 58 | } 59 | return "fail"; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/resources/spring-config-redis.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /dingding-app-server-utils/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | dingding-app-server 7 | com.mocoder.dingding 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | dingding-app-server-utils 13 | dingding-app-server-utils 14 | 15 | 16 | 17 | 18 | com.mocoder.dingding 19 | dingding-app-server-model 20 | 21 | 22 | commons-beanutils 23 | commons-beanutils 24 | 25 | 26 | commons-digester 27 | commons-digester 28 | 29 | 30 | commons-codec 31 | commons-codec 32 | 33 | 34 | commons-lang 35 | commons-lang 36 | 37 | 38 | org.codehaus.jackson 39 | jackson-mapper-asl 40 | 1.9.13 41 | 42 | 43 | 44 | javax.servlet 45 | servlet-api 46 | provided 47 | 48 | 49 | 50 | org.springframework 51 | spring-web 52 | 53 | 54 | 55 | 56 | org.springframework.data 57 | spring-data-redis 58 | 1.4.0.RELEASE 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /dingding-app-server-dao/src/main/java/com/mocoder/dingding/model/LoginAccount.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.model; 2 | 3 | import java.io.Serializable; 4 | 5 | public class LoginAccount implements Serializable { 6 | private Integer id; 7 | 8 | private String mobile; 9 | 10 | private String nickName; 11 | 12 | private String password; 13 | 14 | private static final long serialVersionUID = 1L; 15 | 16 | public Integer getId() { 17 | return id; 18 | } 19 | 20 | public void setId(Integer id) { 21 | this.id = id; 22 | } 23 | 24 | public String getMobile() { 25 | return mobile; 26 | } 27 | 28 | public void setMobile(String mobile) { 29 | this.mobile = mobile == null ? null : mobile.trim(); 30 | } 31 | 32 | public String getNickName() { 33 | return nickName; 34 | } 35 | 36 | public void setNickName(String nickName) { 37 | this.nickName = nickName == null ? null : nickName.trim(); 38 | } 39 | 40 | public String getPassword() { 41 | return password; 42 | } 43 | 44 | public void setPassword(String password) { 45 | this.password = password == null ? null : password.trim(); 46 | } 47 | 48 | @Override 49 | public boolean equals(Object that) { 50 | if (this == that) { 51 | return true; 52 | } 53 | if (that == null) { 54 | return false; 55 | } 56 | if (getClass() != that.getClass()) { 57 | return false; 58 | } 59 | LoginAccount other = (LoginAccount) that; 60 | return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) 61 | && (this.getMobile() == null ? other.getMobile() == null : this.getMobile().equals(other.getMobile())) 62 | && (this.getNickName() == null ? other.getNickName() == null : this.getNickName().equals(other.getNickName())) 63 | && (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword())); 64 | } 65 | 66 | @Override 67 | public int hashCode() { 68 | final int prime = 31; 69 | int result = 1; 70 | result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); 71 | result = prime * result + ((getMobile() == null) ? 0 : getMobile().hashCode()); 72 | result = prime * result + ((getNickName() == null) ? 0 : getNickName().hashCode()); 73 | result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode()); 74 | return result; 75 | } 76 | } -------------------------------------------------------------------------------- /dingding-app-server-service/src/main/java/com/mocoder/dingding/service/LoginAccountService.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.service; 2 | 3 | import com.mocoder.dingding.vo.CommonRequest; 4 | import com.mocoder.dingding.vo.CommonResponse; 5 | import com.mocoder.dingding.model.LoginAccount; 6 | import com.mocoder.dingding.utils.bean.RedisRequestSession; 7 | import com.mocoder.dingding.vo.LoginAccountRequest; 8 | 9 | /** 10 | * 登录账户服务 11 | * Created by yangshuai3 on 2016/1/25. 12 | */ 13 | 14 | public interface LoginAccountService { 15 | 16 | /** 17 | * 密码登录 18 | * @param mobile 19 | * @param password 20 | * @param session 21 | * @param request 22 | * @return 23 | */ 24 | public CommonResponse loginByPass(String mobile, String password, RedisRequestSession session, CommonRequest request); 25 | 26 | /** 27 | * 验证码登录 28 | * @param mobile 29 | * @param verifyCode 30 | * @param session 31 | * @param request 32 | * @return 33 | */ 34 | public CommonResponse loginByVerifyCode(String mobile, String verifyCode, RedisRequestSession session, CommonRequest request); 35 | 36 | /** 37 | * 注册 38 | * @param account 39 | * @param session 40 | * @param request 41 | * @return 42 | */ 43 | public CommonResponse registerAccount(LoginAccountRequest account, RedisRequestSession session, CommonRequest request); 44 | 45 | /** 46 | * 获取注册验证码 47 | * @param mobile 48 | * @param session 49 | * @return 50 | */ 51 | public CommonResponse getRegVerifyCode(String mobile, RedisRequestSession session); 52 | 53 | /** 54 | * 获取登录验证码 55 | * @param mobile 56 | * @param session 57 | * @return 58 | */ 59 | public CommonResponse getLoginVerifyCode(String mobile, RedisRequestSession session); 60 | 61 | /** 62 | * 注销当前设备的当前账户 63 | * @param body 64 | * @param session 65 | * @return 66 | */ 67 | CommonResponse logoutAccount(LoginAccountRequest body, RedisRequestSession session); 68 | /** 69 | * 更新账户信息 70 | * @param account 71 | * @param session 72 | * @param request 73 | * @return 74 | */ 75 | public CommonResponse updateAccount(LoginAccountRequest account, RedisRequestSession session, CommonRequest request); 76 | /** 77 | * 获取重要操作验证码 78 | * @param mobile 79 | * @param session 80 | * @return 81 | */ 82 | public CommonResponse getImportantOperationVerifyCode(String mobile, RedisRequestSession session); 83 | } 84 | -------------------------------------------------------------------------------- /dingding-app-server-utils/src/main/java/com/mocoder/dingding/utils/bean/RedisRequestSession.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.utils.bean; 2 | 3 | import com.mocoder.dingding.constants.RedisKeyConstant; 4 | import com.mocoder.dingding.utils.web.RedisUtil; 5 | import com.mocoder.dingding.vo.CommonRequest; 6 | 7 | import java.util.Map; 8 | import java.util.concurrent.ConcurrentHashMap; 9 | 10 | /** 11 | * Created by yangshuai on 16/1/31. 12 | */ 13 | public class RedisRequestSession { 14 | private String sessionId; 15 | private Map attributes = new ConcurrentHashMap(); 16 | private long expireDelay; 17 | 18 | /** 19 | * 创建一个session 20 | * @param sessionId 21 | * @param minutes n秒后过期 22 | */ 23 | public RedisRequestSession(String sessionId,long minutes) { 24 | this.sessionId = sessionId; 25 | expireDelay = minutes; 26 | } 27 | 28 | public String getSessionId() { 29 | return sessionId; 30 | } 31 | 32 | public void setSessionId(String sessionId) { 33 | this.sessionId = sessionId; 34 | } 35 | 36 | public Map getAttributes() { 37 | return RedisUtil.hGetAllString(RedisKeyConstant.REQUEST_SESSION_KEY_PREFIX,expireDelay*60); 38 | } 39 | 40 | public String getAttribute(String key){ 41 | return RedisUtil.hGetString(RedisKeyConstant.REQUEST_SESSION_KEY_PREFIX + sessionId,key,expireDelay*60); 42 | } 43 | 44 | public void setAttribute(String key,String obj){ 45 | RedisUtil.hSetString(RedisKeyConstant.REQUEST_SESSION_KEY_PREFIX+sessionId,key,obj,expireDelay*60); 46 | } 47 | 48 | public void removeAttribute(String key){ 49 | RedisUtil.hDel(RedisKeyConstant.REQUEST_SESSION_KEY_PREFIX+sessionId,key); 50 | } 51 | 52 | public void saveUserSessionId(CommonRequest request,String userId){ 53 | StringBuilder stringBuilder = new StringBuilder(request.getDeviceid()).append('_').append(request.getAppversion()); 54 | RedisUtil.hSetString(RedisKeyConstant.USER_REQUEST_SESSION_INFO_KEY_PREFIX+userId,stringBuilder.toString(),sessionId,null); 55 | } 56 | 57 | public void destroy(){ 58 | RedisUtil.del(RedisKeyConstant.REQUEST_SESSION_KEY_PREFIX+sessionId); 59 | } 60 | 61 | public static void cleanUserAllDeviceSession(String userId){ 62 | Map sessionIdMap = RedisUtil.hGetAllString(RedisKeyConstant.USER_REQUEST_SESSION_INFO_KEY_PREFIX + userId, null); 63 | for(String value:sessionIdMap.values()){ 64 | RedisUtil.del(RedisKeyConstant.REQUEST_SESSION_KEY_PREFIX+value); 65 | } 66 | } 67 | 68 | 69 | 70 | 71 | } 72 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/java/com/mocoder/dingding/web/interceptor/EncryptParameterValidateInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.web.interceptor; 2 | 3 | import com.mocoder.dingding.constants.EncryptionConstant; 4 | import com.mocoder.dingding.constants.RequestAttributeKeyConstant; 5 | import com.mocoder.dingding.enums.ErrorTypeEnum; 6 | import com.mocoder.dingding.utils.encryp.EncryptUtils; 7 | import com.mocoder.dingding.utils.web.WebUtil; 8 | import com.mocoder.dingding.vo.CommonRequest; 9 | import com.mocoder.dingding.vo.CommonResponse; 10 | import org.apache.commons.lang.StringUtils; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | import java.io.IOException; 15 | 16 | /** 17 | * 加密参数请求拦截器(重要或者限制性操作如获取短信验证码等,不需要登录) 18 | * Created by yangshuai3 on 2016/1/28. 19 | */ 20 | public class EncryptParameterValidateInterceptor extends BaseParamValidateInterceptor { 21 | 22 | @Override 23 | protected boolean validate(HttpServletRequest request, HttpServletResponse response) { 24 | if (!super.validate(request, response)) { 25 | return false; 26 | } 27 | CommonRequest req = (CommonRequest) request.getAttribute(RequestAttributeKeyConstant.REQUEST_ATTRIBUTE_KEY_COMMON_REQUEST); 28 | CommonResponse resp = new CommonResponse(); 29 | if (StringUtils.isBlank(req.getSign())) { 30 | resp.resolveErrorInfo(ErrorTypeEnum.INPUT_PARAMETER_VALIDATE_ERROR); 31 | logErrorInfo(request,"参数sign不能为空"); 32 | try { 33 | WebUtil.writeResponse(response, resp); 34 | } catch (IOException e1) { 35 | logger.error("请求拦截器:写出返回值失败", e1); 36 | } 37 | return false; 38 | } 39 | if (StringUtils.isBlank(req.getBody())) { 40 | req.setBody(""); 41 | } 42 | if (StringUtils.isBlank(req.getSessionid())) { 43 | req.setSessionid(""); 44 | } 45 | String tmpStr = /*req.getBody()+ */ req.getTimestamp() + req.getSessionid() + EncryptionConstant.HEADER_PARAM_SIGN_PRIVATE_KEY; 46 | String targetToken = null; 47 | targetToken = EncryptUtils.md5(tmpStr); 48 | if (!req.getSign().equals(targetToken)) { 49 | resp.resolveErrorInfo(ErrorTypeEnum.INPUT_PARAMETER_VALIDATE_ERROR); 50 | logErrorInfo(request,"参数sign验证失败,right:"+targetToken+" input:"+req.getSign()); 51 | try { 52 | WebUtil.writeResponse(response, resp); 53 | } catch (IOException e1) { 54 | logger.error("请求拦截器:写出返回值失败", e1); 55 | } 56 | return false; 57 | } 58 | return true; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/resources/spring-config-datasource.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /dingding-app-server-rpc/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | com.mocoder.dingding 5 | dingding-app-server 6 | 1.0-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | dingding-app-server-rpc 11 | dingding-app-server-rpc 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | org.apache.logging.log4j 32 | log4j-api 33 | 34 | 35 | org.apache.logging.log4j 36 | log4j-core 37 | 38 | 39 | org.apache.logging.log4j 40 | log4j-slf4j-impl 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | org.springframework 50 | spring-beans 51 | 52 | 53 | org.springframework 54 | spring-context 55 | 56 | 57 | commons-beanutils 58 | commons-beanutils 59 | 60 | 61 | commons-digester 62 | commons-digester 63 | 64 | 65 | commons-lang 66 | commons-lang 67 | 68 | 69 | 70 | com.alibaba 71 | taobao-api 72 | 1.0.0 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ${mvn.log.level} 5 | ${mvn.log.path}/${mvn.app.domainName} 6 | [%-5p %d{yyyy-MM-dd HH:mm:ss.SSS}] [%t] [%l] %m%n 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 | ${var.output.pattern} 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | ${var.output.pattern} 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /dingding-app-server-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | com.mocoder.dingding 5 | dingding-app-server 6 | 1.0-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | dingding-app-server-service 11 | dingding-app-server-service 12 | 13 | 14 | 15 | com.mocoder.dingding 16 | dingding-app-server-rpc 17 | 18 | 19 | com.mocoder.dingding 20 | dingding-app-server-dao 21 | 22 | 23 | com.mocoder.dingding 24 | dingding-app-server-utils 25 | 26 | 27 | org.springframework 28 | spring-core 29 | 30 | 31 | org.springframework 32 | spring-beans 33 | 34 | 35 | org.springframework 36 | spring-aop 37 | 38 | 39 | org.springframework 40 | spring-tx 41 | 42 | 43 | org.springframework 44 | spring-jdbc 45 | 46 | 47 | org.springframework 48 | spring-web 49 | 50 | 51 | 52 | 53 | org.slf4j 54 | slf4j-api 55 | 56 | 57 | org.slf4j 58 | jcl-over-slf4j 59 | 60 | 61 | log4j 62 | log4j 63 | 64 | 65 | org.slf4j 66 | slf4j-log4j12 67 | 68 | 69 | org.apache.logging.log4j 70 | log4j-api 71 | 72 | 73 | org.apache.logging.log4j 74 | log4j-core 75 | 76 | 77 | org.apache.logging.log4j 78 | log4j-slf4j-impl 79 | 80 | 81 | com.lmax 82 | disruptor 83 | 84 | 85 | 86 | 87 | joda-time 88 | joda-time 89 | 90 | 91 | 92 | org.springframework.data 93 | spring-data-redis 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | dingding-app-server 7 | 8 | 9 | 10 | org.springframework.web.context.ContextLoaderListener 11 | 12 | 13 | contextConfigLocation 14 | classpath:spring-config.xml 15 | 16 | 17 | org.springframework.web.util.IntrospectorCleanupListener 18 | 19 | 20 | 21 | 22 | dingding-app-server 23 | org.springframework.web.servlet.DispatcherServlet 24 | 25 | contextConfigLocation 26 | classpath:spring-config-mvc.xml 27 | 28 | 1 29 | 30 | 31 | dingding-app-server 32 | / 33 | 34 | 35 | dingding-app-server 36 | *.html 37 | 38 | 39 | 40 | 41 | CharacterEncodingFilter 42 | org.springframework.web.filter.CharacterEncodingFilter 43 | 44 | encoding 45 | UTF-8 46 | 47 | 48 | forceEncoding 49 | true 50 | 51 | 52 | 53 | CharacterEncodingFilter 54 | dingding-app-server 55 | 56 | 57 | RequestContextFilter 58 | org.springframework.web.filter.RequestContextFilter 59 | 60 | 61 | RequestContextFilter 62 | dingding-app-server 63 | 64 | 65 | HiddenHttpMethodFilter 66 | org.springframework.web.filter.HiddenHttpMethodFilter 67 | 68 | 69 | HiddenHttpMethodFilter 70 | dingding-app-server 71 | 72 | 73 | 74 | 75 | 30 76 | 77 | 78 | 79 | 80 | 403 81 | /error/403.html 82 | 83 | 84 | 404 85 | /error/404.html 86 | 87 | 88 | 405 89 | /error/405.html 90 | 91 | 92 | 500 93 | /error/500.html 94 | 95 | 96 | 505 97 | /error/505.html 98 | 99 | -------------------------------------------------------------------------------- /dingding-app-server-utils/src/main/java/com/mocoder/dingding/utils/web/WebUtil.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.utils.web; 2 | 3 | import com.mocoder.dingding.vo.CommonResponse; 4 | import org.apache.commons.beanutils.BeanUtils; 5 | import org.apache.commons.lang.StringUtils; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import java.io.IOException; 10 | import java.io.PrintWriter; 11 | import java.util.Enumeration; 12 | import java.util.Map; 13 | 14 | /** 15 | * Created by yangshuai3 on 2016/1/26. 16 | */ 17 | public class WebUtil { 18 | 19 | /** 20 | * 转换请求中的参数为简单对象(只有对象中的简单类型会被赋值),参数值为数组的只取第一个 21 | * 22 | * @param request 请求对象 23 | * @param claz 目标对象类型类 24 | * @param 目标对象类型 25 | * @return 目标对象 26 | * @throws IllegalAccessException 27 | * @throws InstantiationException 28 | */ 29 | public static T paramsToSimpleBean(HttpServletRequest request, Class claz) throws IllegalAccessException, InstantiationException { 30 | Map paramMap = request.getParameterMap(); 31 | T object = claz.newInstance(); 32 | for (Map.Entry ent : paramMap.entrySet()) { 33 | if (StringUtils.isNotBlank(ent.getKey()) && ent.getValue() != null && ent.getValue().length > 0 && StringUtils.isNotBlank(ent.getValue()[0])) { 34 | try { 35 | BeanUtils.setProperty(object, ent.getKey(), ent.getValue()[0]); 36 | } catch (Exception e) { 37 | } 38 | } 39 | } 40 | return object; 41 | } 42 | 43 | /** 44 | * 转换请求中的header中的参数为简单对象(只有对象中的简单类型会被赋值),参数值为数组的只取第一个 45 | * 46 | * @param request 请求对象 47 | * @param claz 目标对象类型类 48 | * @param 目标对象类型 49 | * @return 目标对象 50 | * @throws IllegalAccessException 51 | * @throws InstantiationException 52 | */ 53 | public static T HeaderToSimpleBean(HttpServletRequest request, Class claz) throws IllegalAccessException, InstantiationException { 54 | Enumeration it = request.getHeaderNames(); 55 | T object = claz.newInstance(); 56 | while (it.hasMoreElements()) { 57 | String hKey = (String) it.nextElement(); 58 | String hValue = request.getHeader(hKey); 59 | if (StringUtils.isNotBlank(hKey) && StringUtils.isNotBlank(hValue)) { 60 | try { 61 | BeanUtils.setProperty(object, hKey, hValue); 62 | } catch (Exception e) { 63 | } 64 | } 65 | } 66 | return object; 67 | } 68 | 69 | 70 | /** 71 | * 手否简单类型(字符串、基本类型以及其包装类型) 72 | * 73 | * @param obj 要判断的对象实例 74 | * @return 是否简单类型 75 | */ 76 | public static boolean isSimpleType(Object obj) { 77 | Class claz = obj.getClass(); 78 | if (claz.isPrimitive()) {//基本类型 79 | return true; 80 | } 81 | try { 82 | if (((Class) claz.getField("TYPE").get(null)).isPrimitive()) {//包装基本类型 83 | return true; 84 | } 85 | } catch (Exception e) { 86 | } 87 | if (claz == String.class) { 88 | return true; 89 | } 90 | return false; 91 | } 92 | 93 | /** 94 | * 写出返回结果到response 95 | * @param response 96 | * @param result 97 | * @throws IOException 98 | */ 99 | public static void writeResponse(HttpServletResponse response, CommonResponse result) throws IOException { 100 | response.setContentType("text/json;utf-8"); 101 | PrintWriter out = response.getWriter(); 102 | out.write(JsonUtil.toString(result)); 103 | out.flush(); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/resources/generatorConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 39 | 40 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 65 | 66 | 67 | 68 | 69 | 70 | 73 | 74 | -------------------------------------------------------------------------------- /dingding-app-server-rpc/src/main/java/com/mocoder/dingding/rpc/impl/SmsServiceWrapImpl.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.rpc.impl; 2 | 3 | import com.mocoder.dingding.rpc.SmsServiceWrap; 4 | import com.taobao.api.ApiException; 5 | import com.taobao.api.AutoRetryTaobaoClient; 6 | import com.taobao.api.TaobaoClient; 7 | import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest; 8 | import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse; 9 | import org.apache.commons.lang.builder.ReflectionToStringBuilder; 10 | import org.apache.commons.lang.builder.ToStringStyle; 11 | import org.apache.logging.log4j.LogManager; 12 | import org.apache.logging.log4j.Logger; 13 | import org.springframework.beans.factory.annotation.Value; 14 | import org.springframework.stereotype.Service; 15 | 16 | /** 17 | * 短信发送服务实现 18 | */ 19 | @Service 20 | public class SmsServiceWrapImpl implements SmsServiceWrap { 21 | 22 | private static final Logger log = LogManager.getLogger(SmsServiceWrapImpl.class); 23 | 24 | public static final String SMS_SIGH_NAME = "注册验证"; 25 | public static final String SMS_PRODUCT_NAME = "叮叮"; 26 | public static final String SMS_TAMPLATE_REG_VALIDATE_CODE = "SMS_4790018"; 27 | public static final String SMS_TAMPLATE_LOGIN_VALIDATE_CODE = "SMS_4790018"; 28 | public static final String SMS_TAMPLATE_CHANGE_PASS = "SMS_4790016"; 29 | 30 | @Value("${taobao.api.sms.url}") 31 | private String sms_url; 32 | @Value("${taobao.api.sms.appkey}") 33 | private String sms_appkey; 34 | @Value("${taobao.api.sms.secret}") 35 | private String sms_secret; 36 | 37 | private TaobaoClient smsClient = null; 38 | 39 | public TaobaoClient getSmsClient() { 40 | if(smsClient==null) { 41 | smsClient = new AutoRetryTaobaoClient(sms_url, sms_appkey, sms_secret); 42 | } 43 | return smsClient; 44 | } 45 | 46 | public boolean sentLoginValidCodeSms(String mobileNum, String validCode) { 47 | return sentValidCodeSms(mobileNum,validCode,SMS_SIGH_NAME,SMS_TAMPLATE_LOGIN_VALIDATE_CODE,"登录验证"); 48 | } 49 | 50 | @Override 51 | public boolean sentRegValidCodeSms(String mobileNum, String validCode) { 52 | return sentValidCodeSms(mobileNum,validCode,SMS_SIGH_NAME,SMS_TAMPLATE_REG_VALIDATE_CODE,"注册验证"); 53 | } 54 | 55 | @Override 56 | public boolean sentRegValidCodeSms(String mobileNum, String validCode, String operate) { 57 | return sentValidCodeSms(mobileNum,validCode,SMS_SIGH_NAME,SMS_TAMPLATE_REG_VALIDATE_CODE,"重要操作"); 58 | } 59 | 60 | /** 61 | * 发送验证码 62 | * @param mobileNum 手机号 63 | * @param validCode 验证码内容 64 | * @param signName 短信签名 65 | * @param templateNum 模板号 66 | * @param opeateName 操作名称(日志用) 67 | * @return 发送是否成功 68 | */ 69 | private boolean sentValidCodeSms(String mobileNum, String validCode,String signName,String templateNum,String opeateName){ 70 | AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest(); 71 | req.setSmsType("normal"); 72 | req.setSmsFreeSignName(signName); 73 | req.setSmsParamString("{\"code\":\"" + validCode + "\",\"product\":\" "+SMS_PRODUCT_NAME+" \"}"); 74 | req.setRecNum(mobileNum); 75 | req.setSmsTemplateCode(templateNum); 76 | AlibabaAliqinFcSmsNumSendResponse rsp ; 77 | try { 78 | rsp = getSmsClient().execute(req); 79 | if (rsp==null){ 80 | log.error("验证码-"+opeateName+"-失败:返回结果为null,mobile:{} validCode{}",mobileNum,validCode); 81 | return false; 82 | }else{ 83 | if(!rsp.isSuccess()){ 84 | log.error("验证码-"+opeateName+"-失败:返回结果失败:,mobile:{} code:{} response:{}",mobileNum,validCode, ReflectionToStringBuilder.toString(rsp, ToStringStyle.SIMPLE_STYLE)); 85 | return false; 86 | } 87 | } 88 | } catch (ApiException e) { 89 | log.error("验证码-"+opeateName+"-失败:短信发送异常,mobile:"+mobileNum+" code:"+validCode, e); 90 | } 91 | 92 | log.info("验证码-"+opeateName+":发送成功,mobile:{} validCode:{}",mobileNum,validCode); 93 | return true; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /dingding-app-server-utils/src/main/java/com/mocoder/dingding/utils/encryp/EncryptUtils.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.utils.encryp; 2 | 3 | import org.apache.commons.codec.DecoderException; 4 | import org.apache.commons.codec.binary.Hex; 5 | import org.apache.commons.codec.binary.StringUtils; 6 | import org.apache.commons.codec.digest.DigestUtils; 7 | import sun.misc.BASE64Decoder; 8 | import sun.misc.BASE64Encoder; 9 | 10 | import javax.crypto.Cipher; 11 | import javax.crypto.SecretKeyFactory; 12 | import javax.crypto.spec.DESKeySpec; 13 | import javax.crypto.spec.IvParameterSpec; 14 | import java.io.IOException; 15 | import java.security.Key; 16 | import java.security.spec.AlgorithmParameterSpec; 17 | 18 | /** 19 | * Created by yangshuai3 on 2016/2/18. 20 | * mail:yangshuai3@jd.com 21 | */ 22 | public class EncryptUtils { 23 | 24 | private static final BASE64Encoder base64Encoder = new BASE64Encoder(); 25 | private static final BASE64Decoder base64Decoder = new BASE64Decoder(); 26 | 27 | 28 | public static String md5(String sourceStr) { 29 | return DigestUtils.md5Hex(sourceStr); 30 | } 31 | 32 | public static String sha1(String src) { 33 | return DigestUtils.sha1Hex(src); 34 | } 35 | 36 | public static String base64Encode(String src) { 37 | return base64Encoder.encode(StringUtils.getBytesUtf8(src)); 38 | } 39 | 40 | public static String base64Decode(String src) throws IOException { 41 | return StringUtils.newStringUtf8(base64Decoder.decodeBuffer(src)); 42 | } 43 | 44 | /** 45 | * DES算法,加密 46 | * 47 | * @param data 待加密字符串 48 | * @param key 加密私钥,长度不能够小于8位 49 | * @return 加密后字符串 50 | * @throws Exception 51 | */ 52 | public static String desEncode(String key, String data) { 53 | if (data == null) 54 | return null; 55 | try { 56 | DESKeySpec dks = new DESKeySpec(StringUtils.getBytesUtf8(key)); 57 | SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); 58 | //key的长度不能够小于8位字节 59 | Key secretKey = keyFactory.generateSecret(dks); 60 | Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); 61 | IvParameterSpec iv = new IvParameterSpec(StringUtils.getBytesUtf8("12345678")); 62 | AlgorithmParameterSpec paramSpec = iv; 63 | cipher.init(Cipher.ENCRYPT_MODE, secretKey, paramSpec); 64 | byte[] bytes = cipher.doFinal(StringUtils.getBytesUtf8(data)); 65 | return Hex.encodeHexString(bytes); 66 | } catch (Exception e) { 67 | throw new RuntimeException("des加密失败", e); 68 | } 69 | } 70 | 71 | /** 72 | * DES算法,解密 73 | * 74 | * @param data 待解密字符串 75 | * @param key 解密私钥,长度不能够小于8位 76 | * @return 解密后的字符串 77 | * @throws Exception 异常 78 | */ 79 | public static String desDecode(String key, String data) { 80 | if (data == null) 81 | return null; 82 | try { 83 | DESKeySpec dks = new DESKeySpec(StringUtils.getBytesUtf8(key)); 84 | SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); 85 | //key的长度不能够小于8位字节 86 | Key secretKey = keyFactory.generateSecret(dks); 87 | Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); 88 | IvParameterSpec iv = new IvParameterSpec(StringUtils.getBytesUtf8("12345678")); 89 | AlgorithmParameterSpec paramSpec = iv; 90 | cipher.init(Cipher.DECRYPT_MODE, secretKey, paramSpec); 91 | byte[] bytes = Hex.decodeHex(data.toCharArray()); 92 | return StringUtils.newStringUtf8(cipher.doFinal(bytes)); 93 | } catch (Exception e) { 94 | throw new RuntimeException("des解密失败", e); 95 | } 96 | } 97 | 98 | public static void main(String[] args) throws DecoderException { 99 | String str = base64Encode("[{\"mobile\":\"1565230哈哈60\",\"age\":3]}"); 100 | System.out.println(str); 101 | try { 102 | System.out.println(base64Decode(str)); 103 | } catch (IOException e) { 104 | } 105 | String str2 = desEncode("123123123","[{\"mobile\":\"1565230哈哈60\",\"age\":3]}"); 106 | System.out.println(str2); 107 | System.out.println(desDecode("123123123",str2)); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/java/com/mocoder/dingding/web/controller/LoginAccountController.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.web.controller; 2 | 3 | import com.mocoder.dingding.model.LoginAccount; 4 | import com.mocoder.dingding.service.LoginAccountService; 5 | import com.mocoder.dingding.utils.bean.RedisRequestSession; 6 | import com.mocoder.dingding.vo.CommonRequest; 7 | import com.mocoder.dingding.vo.CommonResponse; 8 | import com.mocoder.dingding.vo.LoginAccountRequest; 9 | import com.mocoder.dingding.web.annotation.ValidateBody; 10 | import org.apache.commons.lang.builder.ReflectionToStringBuilder; 11 | import org.apache.commons.lang.builder.ToStringStyle; 12 | import org.apache.logging.log4j.LogManager; 13 | import org.apache.logging.log4j.Logger; 14 | import org.springframework.stereotype.Controller; 15 | import org.springframework.web.bind.annotation.RequestMapping; 16 | import org.springframework.web.bind.annotation.RequestMethod; 17 | import org.springframework.web.bind.annotation.ResponseBody; 18 | 19 | import javax.annotation.Resource; 20 | import java.lang.reflect.InvocationTargetException; 21 | 22 | /** 23 | * 登录账户相关功能的控制器,包括登录、注册、获取验证码等,其中获取验证码也对应不同的入口,这样是为了区分开是哪个功能调用的获取验证码,从来增加一些条件判断 24 | */ 25 | @Controller 26 | @RequestMapping("/account/") 27 | public class LoginAccountController { 28 | 29 | public static final Logger log = LogManager.getLogger(LoginAccountController.class); 30 | 31 | @Resource 32 | private LoginAccountService loginAccountService; 33 | 34 | 35 | @RequestMapping("loginByPass") 36 | @ResponseBody 37 | public CommonResponse loginByPassword(@ValidateBody(requiredAttrs = {"mobile", "password"}) LoginAccountRequest body, RedisRequestSession session,CommonRequest request) { 38 | //TODO 调试完成候去掉,保护用户关键信息隐私 39 | log.info("密码登陆开始:入参:body:{},request:{}", ReflectionToStringBuilder.toString(body, ToStringStyle.SIMPLE_STYLE),ReflectionToStringBuilder.toString(request, ToStringStyle.SIMPLE_STYLE)); 40 | CommonResponse response = loginAccountService.loginByPass(body.getMobile(), body.getPassword(), session,request); 41 | log.info("密码登陆完成:{}", ReflectionToStringBuilder.toString(response, ToStringStyle.SIMPLE_STYLE)); 42 | return response; 43 | } 44 | 45 | @RequestMapping(value = "loginByCode",method = {RequestMethod.POST}) 46 | @ResponseBody 47 | public CommonResponse loginByCode(@ValidateBody(requiredAttrs = {"mobile", "verifyCode"}) LoginAccountRequest body, RedisRequestSession session,CommonRequest request) { 48 | log.info("验证码登陆开始:入参:body:{},request:{}", ReflectionToStringBuilder.toString(body, ToStringStyle.SIMPLE_STYLE),ReflectionToStringBuilder.toString(request, ToStringStyle.SIMPLE_STYLE)); 49 | CommonResponse response = loginAccountService.loginByVerifyCode(body.getMobile(), body.getVerifyCode(), session,request); 50 | log.info("验证码登陆完成:{}", ReflectionToStringBuilder.toString(response, ToStringStyle.SIMPLE_STYLE)); 51 | return response; 52 | } 53 | 54 | @RequestMapping("getRegVerifyCode") 55 | @ResponseBody 56 | public CommonResponse getRegVerifyCode(@ValidateBody(requiredAttrs = "mobile") LoginAccountRequest body, RedisRequestSession session) { 57 | log.info("获取注册验证码开始:入参:body:{}", ReflectionToStringBuilder.toString(body, ToStringStyle.SIMPLE_STYLE)); 58 | CommonResponse response = loginAccountService.getRegVerifyCode(body.getMobile(), session); 59 | log.info("获取注册验证码完成:{}", ReflectionToStringBuilder.toString(response, ToStringStyle.SIMPLE_STYLE)); 60 | return response; 61 | } 62 | 63 | @RequestMapping("getLoginVerifyCode") 64 | @ResponseBody 65 | public CommonResponse getLoginVerifyCode(@ValidateBody(requiredAttrs = "mobile") LoginAccountRequest body, RedisRequestSession session) { 66 | log.info("获取登陆验证码开始:入参:body:{}", ReflectionToStringBuilder.toString(body, ToStringStyle.SIMPLE_STYLE)); 67 | CommonResponse response = loginAccountService.getLoginVerifyCode(body.getMobile(), session); 68 | log.info("获取登陆验证码完成:{}", ReflectionToStringBuilder.toString(response, ToStringStyle.SIMPLE_STYLE)); 69 | return response; 70 | } 71 | 72 | @RequestMapping("reg") 73 | @ResponseBody 74 | public CommonResponse reg(@ValidateBody(requiredAttrs = {"mobile","verifyCode"}) LoginAccountRequest body, RedisRequestSession session,CommonRequest request) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { 75 | log.info("注册开始:入参:body:{},request:{}", ReflectionToStringBuilder.toString(body, ToStringStyle.SIMPLE_STYLE),ReflectionToStringBuilder.toString(request, ToStringStyle.SIMPLE_STYLE)); 76 | CommonResponse response = loginAccountService.registerAccount(body, session,request); 77 | log.info("注册完成:{}", ReflectionToStringBuilder.toString(response, ToStringStyle.SIMPLE_STYLE)); 78 | return response; 79 | } 80 | 81 | @RequestMapping("logout") 82 | @ResponseBody 83 | public CommonResponse logout(@ValidateBody(requiredAttrs = {"mobile"}) LoginAccountRequest body, RedisRequestSession session) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { 84 | CommonResponse response = loginAccountService.logoutAccount(body, session); 85 | return response; 86 | } 87 | 88 | @RequestMapping("update") 89 | @ResponseBody 90 | public CommonResponse updateInfo(@ValidateBody(requiredAttrs = {"mobile"}) LoginAccountRequest body, RedisRequestSession session,CommonRequest request) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { 91 | log.info("更新用户信息开始:入参:body:{},request:{}", ReflectionToStringBuilder.toString(body, ToStringStyle.SIMPLE_STYLE),ReflectionToStringBuilder.toString(request, ToStringStyle.SIMPLE_STYLE)); 92 | CommonResponse response = loginAccountService.updateAccount(body, session,request); 93 | log.info("更新用户信息完成:{}", ReflectionToStringBuilder.toString(response, ToStringStyle.SIMPLE_STYLE)); 94 | return response; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/java/com/mocoder/dingding/web/interceptor/BaseParamValidateInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.web.interceptor; 2 | 3 | import com.mocoder.dingding.constants.*; 4 | import com.mocoder.dingding.enums.ErrorTypeEnum; 5 | import com.mocoder.dingding.utils.bean.RedisRequestSession; 6 | import com.mocoder.dingding.utils.encryp.EncryptUtils; 7 | import com.mocoder.dingding.utils.web.RedisUtil; 8 | import com.mocoder.dingding.utils.web.WebUtil; 9 | import com.mocoder.dingding.vo.CommonRequest; 10 | import com.mocoder.dingding.vo.CommonResponse; 11 | import org.springframework.beans.factory.annotation.Value; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | import java.io.IOException; 16 | import java.util.Arrays; 17 | import java.util.Enumeration; 18 | import java.util.Map; 19 | import java.util.Set; 20 | 21 | /** 22 | * 基本参数拦截器 23 | * Created by yangshuai3 on 2016/1/28. 24 | */ 25 | public class BaseParamValidateInterceptor extends ValidatorInterceptor { 26 | 27 | @Value("${app.session.timeout.days}") 28 | private long appSessionExpireDays; 29 | 30 | @Override 31 | protected boolean validate(HttpServletRequest request, HttpServletResponse response) { 32 | CommonRequest req = null; 33 | Enumeration headerNames = request.getHeaderNames(); 34 | StringBuilder stringBuilder = new StringBuilder("reqeust headers -->>"); 35 | while(headerNames.hasMoreElements()){ 36 | String name = (String) headerNames.nextElement(); 37 | String value = request.getHeader(name); 38 | stringBuilder.append(name).append(": ").append(value).append(","); 39 | } 40 | stringBuilder.append('\n'); 41 | stringBuilder.append("request body -->>"); 42 | Set set = request.getParameterMap().entrySet(); 43 | for (Map.Entry ent :set ){ 44 | stringBuilder.append(ent.getKey()).append(": ").append(Arrays.toString((String[]) ent.getValue())).append(","); 45 | } 46 | logger.info(stringBuilder.toString()); 47 | try { 48 | req = WebUtil.HeaderToSimpleBean(request, CommonRequest.class); 49 | } catch (Exception e){ 50 | logger.error("参数拦截器:获取请求头内容失败",e); 51 | } 52 | CommonResponse resp = null; 53 | if(req==null){ 54 | resp = new CommonResponse(); 55 | resp.resolveErrorInfo(ErrorTypeEnum.INPUT_PARAMETER_PARSE_ERROR); 56 | logErrorInfo(request, "获取请求头内容失败"); 57 | }else if(req.getAppversion()==null|| !AppVersionConstant.VERSION_1_0_0.equals(req.getAppversion())){ 58 | resp = new CommonResponse(); 59 | resp.resolveErrorInfo(ErrorTypeEnum.INPUT_PARAMETER_VALIDATE_ERROR); 60 | logErrorInfo(request, "参数appVersion取值不正确"); 61 | }else if(req.getPlatform()==null|| (!PlatformConstant.ANDROID.equals(req.getPlatform())&&!PlatformConstant.IOS.equals(req.getPlatform())&&!PlatformConstant.HTML5.equals(req.getPlatform()))){ 62 | resp = new CommonResponse(); 63 | resp.resolveErrorInfo(ErrorTypeEnum.INPUT_PARAMETER_VALIDATE_ERROR); 64 | logErrorInfo(request, "参数platform取值不正确"); 65 | }else if(!validateTimeStamp(req.getTimestamp())){ 66 | resp = new CommonResponse(); 67 | resp.resolveErrorInfo(ErrorTypeEnum.INPUT_PARAMETER_VALIDATE_ERROR); 68 | logErrorInfo(request, "参数timeStamp取值不正确"); 69 | }else if(!validateDeviceId(req.getDeviceid())){ 70 | resp = new CommonResponse(); 71 | resp.resolveErrorInfo(ErrorTypeEnum.INPUT_PARAMETER_VALIDATE_ERROR); 72 | logErrorInfo(request, "参数deviceId取值不正确"); 73 | } else if(!validateSessionId(request,req)){ 74 | resp = new CommonResponse(); 75 | resp.resolveErrorInfo(ErrorTypeEnum.INPUT_PARAMETER_SESSION_ERROR); 76 | logErrorInfo(request, "参数sessionId取值不正确"); 77 | } 78 | if(resp!=null){ 79 | try { 80 | WebUtil.writeResponse(response, resp); 81 | } catch (IOException e) { 82 | logger.error("参数拦截器:写出返回值失败", e); 83 | } 84 | return false; 85 | } 86 | req.setBody(request.getParameter("body")); 87 | request.setAttribute(RequestAttributeKeyConstant.REQUEST_ATTRIBUTE_KEY_COMMON_REQUEST,req); 88 | return true; 89 | } 90 | 91 | private boolean validateSessionId(HttpServletRequest request, CommonRequest req) { 92 | String uri = request.getRequestURI().replace(request.getContextPath(),""); 93 | uri=uri.replaceAll("//","/"); 94 | if("/param/getSessionId".equals(uri)) { 95 | return true; 96 | } 97 | String sessionId = req.getSessionid(); 98 | if(sessionId==null){ 99 | return false; 100 | } 101 | String digested = EncryptUtils.md5(req.getDeviceid()); 102 | String prefix = new StringBuffer(digested.substring(3,7)).append('-').append(digested.substring(9, 13)).toString(); 103 | if(!sessionId.startsWith(prefix)){ 104 | return false; 105 | } 106 | RedisRequestSession session = new RedisRequestSession(sessionId, appSessionExpireDays *24*60); 107 | if(RedisUtil.getString(RedisKeyConstant.TEMP_SESSION_ID_PREFIX+sessionId,null)!=null){ 108 | request.setAttribute(RequestAttributeKeyConstant.REQUEST_ATTRIBUTE_KEY_REQUEST_SESSION,session); 109 | return true; 110 | } 111 | if(session.getAttribute(SessionKeyConstant.USER_LOGIN_KEY)!=null){ 112 | request.setAttribute(RequestAttributeKeyConstant.REQUEST_ATTRIBUTE_KEY_REQUEST_SESSION,session); 113 | return true; 114 | } 115 | return false; 116 | } 117 | 118 | private boolean validateDeviceId(String deviceid) { 119 | if(!PlatformConstant.HTML5.equals(deviceid)&&deviceid==null){ 120 | return false; 121 | } 122 | 123 | return true; 124 | } 125 | 126 | private boolean validateTimeStamp(String timeStamp){ 127 | if(timeStamp==null){ 128 | return false; 129 | } 130 | Long longValue = null; 131 | try { 132 | longValue = Long.valueOf(timeStamp); 133 | } catch (NumberFormatException e) { 134 | 135 | } 136 | if(longValue==null){ 137 | return false; 138 | } 139 | // long now = new Date().getTime(); 140 | // if(Math.abs(now-longValue)>1000*60*60*24*180){ 141 | // return false; 142 | // } 143 | return true; 144 | } 145 | 146 | protected void logErrorInfo(HttpServletRequest request,String msg){ 147 | logger.error("参数拦截器:{},uri:{}",msg,request.getRequestURI()); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/java/com/mocoder/dingding/web/util/RequestArgumentResolver.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.web.util; 2 | 3 | import com.mocoder.dingding.constants.EncryptionConstant; 4 | import com.mocoder.dingding.constants.RequestAttributeKeyConstant; 5 | import com.mocoder.dingding.enums.ErrorTypeEnum; 6 | import com.mocoder.dingding.utils.bean.RedisRequestSession; 7 | import com.mocoder.dingding.utils.encryp.EncryptUtils; 8 | import com.mocoder.dingding.utils.web.JsonUtil; 9 | import com.mocoder.dingding.vo.CommonRequest; 10 | import com.mocoder.dingding.web.annotation.RequiredParam; 11 | import com.mocoder.dingding.web.annotation.ValidateBody; 12 | import com.mocoder.dingding.web.exception.ParameterValidateException; 13 | import org.apache.commons.beanutils.PropertyUtils; 14 | import org.apache.commons.lang.StringUtils; 15 | import org.springframework.core.MethodParameter; 16 | import org.springframework.web.bind.support.WebDataBinderFactory; 17 | import org.springframework.web.context.request.NativeWebRequest; 18 | import org.springframework.web.context.request.RequestAttributes; 19 | import org.springframework.web.method.support.HandlerMethodArgumentResolver; 20 | import org.springframework.web.method.support.ModelAndViewContainer; 21 | 22 | import java.io.IOException; 23 | import java.lang.reflect.Field; 24 | import java.util.Map; 25 | 26 | /** 27 | * Created by yangshuai3 on 2016/2/1. 28 | */ 29 | public class RequestArgumentResolver implements HandlerMethodArgumentResolver { 30 | 31 | @Override 32 | public boolean supportsParameter(MethodParameter methodParameter) { 33 | ValidateBody annotation = methodParameter.getParameterAnnotation(ValidateBody.class); 34 | if (annotation != null) { 35 | return true; 36 | } else if (RedisRequestSession.class == methodParameter.getParameterType()) { 37 | return true; 38 | } else if (CommonRequest.class == methodParameter.getParameterType()) { 39 | return true; 40 | } 41 | return false; 42 | } 43 | 44 | @Override 45 | public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { 46 | ValidateBody annotation = methodParameter.getParameterAnnotation(ValidateBody.class); 47 | if (annotation != null) { 48 | BodyAlgorithmEnum[] algorithms = annotation.algorithm(); 49 | String paramName = annotation.value(); 50 | String[] requiredFields = annotation.requiredAttrs(); 51 | if (StringUtils.isNotBlank(paramName) && StringUtils.isNotBlank(webRequest.getParameter(paramName))) { 52 | String encBody = webRequest.getParameter(paramName); 53 | String bodyString = getDecodedBody(encBody, algorithms); 54 | Object obj; 55 | try { 56 | obj = JsonUtil.toObject(bodyString, methodParameter.getParameterType()); 57 | } catch (IOException e) { 58 | ParameterValidateException exception = new ParameterValidateException("请求体解析异常",e); 59 | exception.setErrorType(ErrorTypeEnum.INPUT_PARAMETER_PARSE_ERROR); 60 | throw exception; 61 | } 62 | validParam(obj,requiredFields); 63 | return obj; 64 | }else{ 65 | ParameterValidateException exception = new ParameterValidateException("请求体"+paramName+"不能为空"); 66 | throw exception; 67 | } 68 | } else if (RedisRequestSession.class == methodParameter.getParameterType()) { 69 | return webRequest.getAttribute(RequestAttributeKeyConstant.REQUEST_ATTRIBUTE_KEY_REQUEST_SESSION, RequestAttributes.SCOPE_REQUEST); 70 | } else if (CommonRequest.class == methodParameter.getParameterType()) { 71 | return webRequest.getAttribute(RequestAttributeKeyConstant.REQUEST_ATTRIBUTE_KEY_COMMON_REQUEST, RequestAttributes.SCOPE_REQUEST); 72 | } 73 | return null; 74 | } 75 | 76 | /** 77 | * 解密body 78 | * @param encBody 加密的body字符串 79 | * @param algorithms 加密算法列表 80 | * @return 返回解密后的body字符串 81 | * @throws ParameterValidateException 82 | */ 83 | private String getDecodedBody(String encBody, BodyAlgorithmEnum[] algorithms) throws ParameterValidateException { 84 | if(algorithms.length>0){ 85 | for (BodyAlgorithmEnum alg:algorithms){ 86 | if (BodyAlgorithmEnum.BASE64==alg) { 87 | try { 88 | encBody = EncryptUtils.base64Decode(encBody); 89 | } catch (Exception e1) { 90 | ParameterValidateException exception = new ParameterValidateException("请求体解密失败",e1); 91 | exception.setErrorType(ErrorTypeEnum.INPUT_PARAMETER_PARSE_ERROR); 92 | throw exception; 93 | } 94 | }else if (BodyAlgorithmEnum.DES==alg) { 95 | try { 96 | encBody = EncryptUtils.desDecode(EncryptionConstant.DES_ENCRYPT_PRIVATE_KEY,encBody); 97 | } catch (Exception e1) { 98 | ParameterValidateException exception = new ParameterValidateException("请求体解密失败",e1); 99 | exception.setErrorType(ErrorTypeEnum.INPUT_PARAMETER_PARSE_ERROR); 100 | throw exception; 101 | } 102 | } 103 | } 104 | } 105 | return encBody; 106 | } 107 | 108 | /** 109 | * 校验必须参数 110 | * @param obj 需要校验的bean 111 | * @param requiredField 必须的属性名 112 | * @throws Exception 113 | */ 114 | private void validParam(Object obj, String[] requiredField) throws Exception{ 115 | Map map = PropertyUtils.describe(obj); 116 | if(requiredField!=null&&requiredField.length>0){ 117 | for (String key:requiredField){ 118 | Object object = map.get(key); 119 | if (object == null || (object instanceof String && StringUtils.isBlank((String) object))) { 120 | ParameterValidateException exception = new ParameterValidateException(key + "不能为空"); 121 | throw exception; 122 | } 123 | } 124 | }else { 125 | for (Map.Entry ent : map.entrySet()) { 126 | Field field = obj.getClass().getField(ent.getKey()); 127 | if (field != null && field.getAnnotation(RequiredParam.class) != null) { 128 | if (ent.getValue() == null || (ent.getValue() instanceof String && StringUtils.isBlank((String) ent.getValue()))) { 129 | ParameterValidateException exception = new ParameterValidateException(ent.getKey() + "不能为空"); 130 | throw exception; 131 | } 132 | } 133 | } 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /dingding-app-server-web/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | com.mocoder.dingding 5 | dingding-app-server 6 | 1.0-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | dingding-app-server-web 11 | war 12 | dingding-app-server-web 13 | 14 | 15 | 16 | 17 | com.mocoder.dingding 18 | dingding-app-server-service 19 | 1.0-SNAPSHOT 20 | 21 | 22 | 23 | 24 | org.springframework 25 | spring-webmvc 26 | ${spring.version} 27 | 28 | 29 | org.springframework 30 | spring-core 31 | 32 | 33 | org.springframework 34 | spring-beans 35 | 36 | 37 | org.springframework 38 | spring-aop 39 | 40 | 41 | org.springframework 42 | spring-tx 43 | 44 | 45 | org.springframework 46 | spring-jdbc 47 | 48 | 49 | org.springframework 50 | spring-web 51 | 52 | 53 | 54 | org.codehaus.jackson 55 | jackson-mapper-asl 56 | 57 | 58 | 59 | 60 | javax.servlet 61 | servlet-api 62 | provided 63 | 64 | 65 | javax.servlet 66 | jsp-api 67 | provided 68 | 69 | 70 | 71 | 72 | org.slf4j 73 | slf4j-api 74 | 75 | 76 | org.slf4j 77 | jcl-over-slf4j 78 | 79 | 80 | log4j 81 | log4j 82 | 83 | 84 | org.slf4j 85 | slf4j-log4j12 86 | 87 | 88 | org.apache.logging.log4j 89 | log4j-api 90 | 91 | 92 | org.apache.logging.log4j 93 | log4j-core 94 | 95 | 96 | org.apache.logging.log4j 97 | log4j-slf4j-impl 98 | 99 | 100 | 101 | 102 | org.aspectj 103 | aspectjrt 104 | 105 | 106 | org.aspectj 107 | aspectjweaver 108 | 109 | 110 | javassist 111 | javassist 112 | 113 | 114 | commons-beanutils 115 | commons-beanutils 116 | 117 | 118 | commons-digester 119 | commons-digester 120 | 121 | 122 | commons-lang 123 | commons-lang 124 | 125 | 126 | org.springframework 127 | spring-context-support 128 | 129 | 130 | org.springframework 131 | spring-test 132 | 133 | 134 | junit 135 | junit 136 | test 137 | 138 | 139 | 140 | org.apache.velocity 141 | velocity 142 | 143 | 144 | org.apache.velocity 145 | velocity-tools 146 | 147 | 148 | 149 | mysql 150 | mysql-connector-java 151 | 152 | 153 | org.mybatis 154 | mybatis 155 | 156 | 157 | org.mybatis 158 | mybatis-spring 159 | 160 | 161 | com.alibaba 162 | druid 163 | ${druid.version} 164 | 165 | 166 | 167 | 168 | org.springframework.data 169 | spring-data-redis 170 | 171 | 172 | redis.clients 173 | jedis 174 | 175 | 176 | org.apache.httpcomponents 177 | httpclient 178 | 4.3.5 179 | test 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/main/resources/spring-config-mvc.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 19 | 20 | classpath:config.properties 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 54 | 55 | 56 | 57 | application/json 58 | application/javascript 59 | text/json 60 | text/javascript 61 | text/plain 62 | text/html 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | UTF-8 98 | UTF-8 99 | text/html;charset=UTF-8 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /dingding-app-server-dao/src/main/resources/mapper/LoginAccountMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | and ${criterion.condition} 19 | 20 | 21 | and ${criterion.condition} #{criterion.value} 22 | 23 | 24 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} 25 | 26 | 27 | and ${criterion.condition} 28 | 29 | #{listItem} 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | and ${criterion.condition} 48 | 49 | 50 | and ${criterion.condition} #{criterion.value} 51 | 52 | 53 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} 54 | 55 | 56 | and ${criterion.condition} 57 | 58 | #{listItem} 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | id, mobile, nick_name, password 70 | 71 | 85 | 91 | 92 | delete from login_account 93 | where id = #{id,jdbcType=INTEGER} 94 | 95 | 96 | delete from login_account 97 | 98 | 99 | 100 | 101 | 102 | insert into login_account (id, mobile, nick_name, 103 | password) 104 | values (#{id,jdbcType=INTEGER}, #{mobile,jdbcType=VARCHAR}, #{nickName,jdbcType=VARCHAR}, 105 | #{password,jdbcType=VARCHAR}) 106 | 107 | 108 | insert into login_account 109 | 110 | 111 | id, 112 | 113 | 114 | mobile, 115 | 116 | 117 | nick_name, 118 | 119 | 120 | password, 121 | 122 | 123 | 124 | 125 | #{id,jdbcType=INTEGER}, 126 | 127 | 128 | #{mobile,jdbcType=VARCHAR}, 129 | 130 | 131 | #{nickName,jdbcType=VARCHAR}, 132 | 133 | 134 | #{password,jdbcType=VARCHAR}, 135 | 136 | 137 | 138 | 144 | 145 | update login_account 146 | 147 | 148 | id = #{record.id,jdbcType=INTEGER}, 149 | 150 | 151 | mobile = #{record.mobile,jdbcType=VARCHAR}, 152 | 153 | 154 | nick_name = #{record.nickName,jdbcType=VARCHAR}, 155 | 156 | 157 | password = #{record.password,jdbcType=VARCHAR}, 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | update login_account 166 | set id = #{record.id,jdbcType=INTEGER}, 167 | mobile = #{record.mobile,jdbcType=VARCHAR}, 168 | nick_name = #{record.nickName,jdbcType=VARCHAR}, 169 | password = #{record.password,jdbcType=VARCHAR} 170 | 171 | 172 | 173 | 174 | 175 | update login_account 176 | 177 | 178 | mobile = #{mobile,jdbcType=VARCHAR}, 179 | 180 | 181 | nick_name = #{nickName,jdbcType=VARCHAR}, 182 | 183 | 184 | password = #{password,jdbcType=VARCHAR}, 185 | 186 | 187 | where id = #{id,jdbcType=INTEGER} 188 | 189 | 190 | update login_account 191 | set mobile = #{mobile,jdbcType=VARCHAR}, 192 | nick_name = #{nickName,jdbcType=VARCHAR}, 193 | password = #{password,jdbcType=VARCHAR} 194 | where id = #{id,jdbcType=INTEGER} 195 | 196 | -------------------------------------------------------------------------------- /dingding-app-server-web/src/test/java/com/mocoder/dingding/test/client/HttpClientUtil.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.test.client; 2 | 3 | import com.mocoder.dingding.utils.encryp.EncryptUtils; 4 | 5 | import javax.net.ssl.*; 6 | import java.io.*; 7 | import java.net.*; 8 | import java.security.cert.CertificateException; 9 | import java.security.cert.X509Certificate; 10 | import java.util.Iterator; 11 | import java.util.Map; 12 | 13 | 14 | public class HttpClientUtil { 15 | 16 | private final static String charset = "utf-8"; 17 | private static Integer connectTimeout = null; 18 | private static Integer socketTimeout = null; 19 | private static String proxyHost = null; 20 | private static Integer proxyPort = null; 21 | 22 | 23 | 24 | public static String doGet(String url, Map extraHeader) throws Exception { 25 | URLConnection connection = openConnection(url); 26 | HttpURLConnection httpURLConnection = (HttpURLConnection) connection; 27 | httpURLConnection.setRequestProperty("Accept-Charset", charset); 28 | httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 29 | if (extraHeader != null && !extraHeader.isEmpty()) { 30 | for (Map.Entry ent : extraHeader.entrySet()) { 31 | httpURLConnection.setRequestProperty(ent.getKey(), ent.getValue()); 32 | } 33 | } 34 | InputStream inputStream = null; 35 | InputStreamReader inputStreamReader = null; 36 | BufferedReader reader = null; 37 | StringBuffer resultBuffer = new StringBuffer(); 38 | String tempLine = null; 39 | if (httpURLConnection.getResponseCode() >= 300) { 40 | throw new Exception("HTTP Request is not success, Response code is " + httpURLConnection.getResponseCode()); 41 | } 42 | try { 43 | inputStream = httpURLConnection.getInputStream(); 44 | inputStreamReader = new InputStreamReader(inputStream); 45 | reader = new BufferedReader(inputStreamReader); 46 | while ((tempLine = reader.readLine()) != null) { 47 | resultBuffer.append(tempLine); 48 | } 49 | } finally { 50 | 51 | if (reader != null) { 52 | reader.close(); 53 | } 54 | if (inputStreamReader != null) { 55 | inputStreamReader.close(); 56 | } 57 | if (inputStream != null) { 58 | inputStream.close(); 59 | } 60 | } 61 | return resultBuffer.toString(); 62 | } 63 | 64 | public static String doPost(String url, Map extraHeader, Map parameterMap) throws Exception { 65 | /* Translate parameter map to parameter date string */ 66 | StringBuffer parameterBuffer = new StringBuffer(); 67 | if (parameterMap != null) { 68 | Iterator iterator = parameterMap.keySet().iterator(); 69 | String key = null; 70 | String value = null; 71 | while (iterator.hasNext()) { 72 | key = (String) iterator.next(); 73 | if (parameterMap.get(key) != null) { 74 | value = (String) parameterMap.get(key); 75 | } else { 76 | value = ""; 77 | } 78 | parameterBuffer.append(key).append("=").append(value); 79 | if (iterator.hasNext()) { 80 | parameterBuffer.append("&"); 81 | } 82 | } 83 | } 84 | URLConnection connection = openConnection(url); 85 | HttpURLConnection httpURLConnection = (HttpURLConnection) connection; 86 | httpURLConnection.setDoOutput(true); 87 | httpURLConnection.setRequestMethod("POST"); 88 | httpURLConnection.setRequestProperty("Accept-Charset", charset); 89 | httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 90 | httpURLConnection.setRequestProperty("Content-Length", String.valueOf(parameterBuffer.length())); 91 | if (extraHeader != null && !extraHeader.isEmpty()) { 92 | for (Map.Entry ent : extraHeader.entrySet()) { 93 | httpURLConnection.setRequestProperty(ent.getKey(), ent.getValue()); 94 | } 95 | } 96 | OutputStream outputStream = null; 97 | OutputStreamWriter outputStreamWriter = null; 98 | InputStream inputStream = null; 99 | InputStreamReader inputStreamReader = null; 100 | BufferedReader reader = null; 101 | StringBuffer resultBuffer = new StringBuffer(); 102 | String tempLine = null; 103 | try { 104 | outputStream = httpURLConnection.getOutputStream(); 105 | outputStreamWriter = new OutputStreamWriter(outputStream); 106 | 107 | outputStreamWriter.write(parameterBuffer.toString()); 108 | outputStreamWriter.flush(); 109 | 110 | if (httpURLConnection.getResponseCode() >= 300) { 111 | throw new Exception("HTTP Request is not success, Response code is " + httpURLConnection.getResponseCode()); 112 | } 113 | inputStream = httpURLConnection.getInputStream(); 114 | inputStreamReader = new InputStreamReader(inputStream); 115 | reader = new BufferedReader(inputStreamReader); 116 | while ((tempLine = reader.readLine()) != null) { 117 | resultBuffer.append(tempLine); 118 | } 119 | } finally { 120 | if (outputStreamWriter != null) { 121 | outputStreamWriter.close(); 122 | } 123 | if (outputStream != null) { 124 | outputStream.close(); 125 | } 126 | if (reader != null) { 127 | reader.close(); 128 | } 129 | if (inputStreamReader != null) { 130 | inputStreamReader.close(); 131 | } 132 | if (inputStream != null) { 133 | inputStream.close(); 134 | } 135 | } 136 | return resultBuffer.toString(); 137 | } 138 | 139 | private static URLConnection openConnection(String url) throws IOException { 140 | URL localURL = new URL(url); 141 | URLConnection connection; 142 | if (proxyHost != null && proxyPort != null) { 143 | Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)); 144 | connection = localURL.openConnection(proxy); 145 | } else { 146 | connection = localURL.openConnection(); 147 | } 148 | if(url.startsWith("https")){ 149 | ((HttpsURLConnection)connection).setSSLSocketFactory(sslSocketFactory); 150 | ((HttpsURLConnection)connection).setHostnameVerifier(myHostnameVerifier); 151 | } 152 | return connection; 153 | } 154 | 155 | /** 156 | * Render request according setting 157 | * 158 | * @param connection 159 | */ 160 | private static void renderRequest(URLConnection connection) { 161 | 162 | if (connectTimeout != null) { 163 | connection.setConnectTimeout(connectTimeout); 164 | } 165 | 166 | if (socketTimeout != null) { 167 | connection.setReadTimeout(socketTimeout); 168 | } 169 | 170 | } 171 | 172 | 173 | private static final HostnameVerifier myHostnameVerifier = new HostnameVerifier() { 174 | public boolean verify(String urlHostName, SSLSession session) { 175 | System.out.println("Warning: URL Host: " + urlHostName + " vs. " 176 | + session.getPeerHost()); 177 | return true; 178 | } 179 | }; 180 | 181 | private static SSLSocketFactory sslSocketFactory; 182 | 183 | static { 184 | try { 185 | TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { 186 | 187 | @Override 188 | public X509Certificate[] getAcceptedIssuers() { 189 | return null; 190 | } 191 | 192 | @Override 193 | public void checkServerTrusted(X509Certificate[] chain, String authType) 194 | throws CertificateException { 195 | } 196 | 197 | @Override 198 | public void checkClientTrusted(X509Certificate[] chain, String authType) 199 | throws CertificateException { 200 | } 201 | }}; 202 | SSLContext sslContext = SSLContext.getInstance("TLS"); 203 | sslContext.init(null, trustAllCerts, null); 204 | sslSocketFactory = sslContext.getSocketFactory(); 205 | } catch (Exception e) { 206 | new RuntimeException(e); 207 | } 208 | 209 | 210 | 211 | } 212 | 213 | 214 | public static void main(String[] args) { 215 | String tmpStr = "14589071547192919-5308-35d3d1ec-a2a7-48b7-b7ce-abafaf3be4ec66666"; 216 | String targetToken = EncryptUtils.md5(tmpStr); 217 | System.out.println(targetToken); 218 | } 219 | 220 | } -------------------------------------------------------------------------------- /dingding-app-server-utils/src/main/java/com/mocoder/dingding/utils/web/RedisUtil.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.utils.web; 2 | 3 | import com.mocoder.dingding.utils.bean.TypeRef; 4 | import com.mocoder.dingding.utils.spring.SpringContextHolder; 5 | import org.springframework.dao.DataAccessException; 6 | import org.springframework.data.redis.connection.RedisConnection; 7 | import org.springframework.data.redis.core.RedisCallback; 8 | import org.springframework.data.redis.core.RedisTemplate; 9 | 10 | import java.io.IOException; 11 | import java.io.UnsupportedEncodingException; 12 | import java.util.LinkedHashMap; 13 | import java.util.Map; 14 | 15 | /** 16 | * Created by yangshuai on 16/1/31. 17 | */ 18 | public class RedisUtil { 19 | private static RedisTemplate redisTemplate; 20 | 21 | static { 22 | redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); 23 | } 24 | 25 | 26 | public static String getString(final String key, final Long seconds) { 27 | String result = (String) redisTemplate.execute(new RedisCallback() { 28 | @Override 29 | public String doInRedis(RedisConnection connection) throws DataAccessException { 30 | try { 31 | byte[] byteKey = key.getBytes("utf-8"); 32 | byte[] value = connection.get(byteKey); 33 | if (value == null) { 34 | return null; 35 | } 36 | if (seconds != null) { 37 | connection.expire(byteKey, seconds); 38 | } 39 | return new String(value, "utf-8"); 40 | } catch (UnsupportedEncodingException e) { 41 | throw new RuntimeException("不支持的编码类型utf-8", e); 42 | } 43 | } 44 | }, true, false); 45 | return result; 46 | } 47 | 48 | public static void setString(final String key, final String value, final Long seconds) { 49 | redisTemplate.execute(new RedisCallback() { 50 | @Override 51 | public Object doInRedis(RedisConnection connection) throws DataAccessException { 52 | try { 53 | byte[] byteKey = key.getBytes("utf-8"); 54 | connection.set(byteKey, value.getBytes("utf-8")); 55 | if (seconds != null) { 56 | connection.expire(byteKey, seconds); 57 | } 58 | } catch (UnsupportedEncodingException e) { 59 | throw new RuntimeException("不支持的编码类型utf-8", e); 60 | } 61 | return null; 62 | } 63 | }, true, true); 64 | } 65 | 66 | public static void del(final String key) { 67 | redisTemplate.execute(new RedisCallback() { 68 | @Override 69 | public Object doInRedis(RedisConnection connection) throws DataAccessException { 70 | try { 71 | byte[] byteKey = key.getBytes("utf-8"); 72 | connection.del(byteKey); 73 | } catch (UnsupportedEncodingException e) { 74 | throw new RuntimeException("不支持的编码类型utf-8", e); 75 | } 76 | return null; 77 | } 78 | }, true, true); 79 | } 80 | 81 | public static T getObj(final String key, final TypeRef type, final Long seconds) { 82 | String result = getString(key,seconds); 83 | if (result == null) { 84 | return null; 85 | } 86 | try { 87 | return JsonUtil.toObject(result, type); 88 | } catch (IOException e) { 89 | throw new RuntimeException("json对象解析失败", e); 90 | } 91 | } 92 | 93 | public static void setObj(final String key, T obj, Long seconds) { 94 | String value = null; 95 | try { 96 | value = JsonUtil.toString(obj); 97 | } catch (IOException e) { 98 | throw new RuntimeException("json序列化对象失败", e); 99 | } 100 | if (value != null) { 101 | setString(key, value, seconds); 102 | } 103 | } 104 | 105 | public static String hGetString(final String key, final String field, final Long seconds) { 106 | String result = (String) redisTemplate.execute(new RedisCallback() { 107 | @Override 108 | public String doInRedis(RedisConnection connection) throws DataAccessException { 109 | try { 110 | byte[] byteKey = key.getBytes("utf-8"); 111 | byte[] value = connection.hGet(byteKey, field.getBytes("utf-8")); 112 | if (value == null) { 113 | return null; 114 | } 115 | if (seconds != null) { 116 | connection.expire(byteKey, seconds); 117 | } 118 | return new String(value, "utf-8"); 119 | } catch (UnsupportedEncodingException e) { 120 | throw new RuntimeException("不支持的编码类型utf-8", e); 121 | } 122 | } 123 | }, true, false); 124 | return result; 125 | } 126 | 127 | public static void hSetString(final String key, final String field, final String value, final Long seconds) { 128 | redisTemplate.execute(new RedisCallback() { 129 | @Override 130 | public Object doInRedis(RedisConnection connection) throws DataAccessException { 131 | try { 132 | byte[] byteKey = key.getBytes("utf-8"); 133 | connection.hSet(byteKey, field.getBytes("utf-8"), value.getBytes("utf-8")); 134 | if (seconds != null) { 135 | connection.expire(byteKey, seconds); 136 | } 137 | } catch (UnsupportedEncodingException e) { 138 | throw new RuntimeException("不支持的编码类型utf-8", e); 139 | } 140 | return null; 141 | } 142 | }, true, true); 143 | } 144 | 145 | public static void hDel(final String key, final String field) { 146 | Long result = (Long)redisTemplate.execute(new RedisCallback() { 147 | @Override 148 | public Long doInRedis(RedisConnection connection) throws DataAccessException { 149 | try { 150 | long value = connection.hDel(key.getBytes("utf-8"), field.getBytes("utf-8")); 151 | return Long.valueOf(value); 152 | } catch (UnsupportedEncodingException e) { 153 | throw new RuntimeException("不支持的编码类型utf-8", e); 154 | } 155 | } 156 | }, true, false); 157 | } 158 | 159 | public static T hGetObj(final String key, final String field, final TypeRef type, final Long seconds) { 160 | String result = hGetString(key, field,seconds); 161 | if (result == null) { 162 | return null; 163 | } 164 | try { 165 | return JsonUtil.toObject(result, type); 166 | } catch (IOException e) { 167 | throw new RuntimeException("json对象解析失败", e); 168 | } 169 | } 170 | 171 | public static void hSetObj(final String key, final String field, T obj, final Long seconds) { 172 | String value = null; 173 | try { 174 | value = JsonUtil.toString(obj); 175 | } catch (IOException e) { 176 | throw new RuntimeException("json序列化对象失败", e); 177 | } 178 | if (value != null) { 179 | hSetString(key, field, value, seconds); 180 | } 181 | } 182 | 183 | public static Map hGetAllObj(final String key, final TypeRef type, final Long seconds) { 184 | 185 | Map result = (Map) redisTemplate.execute(new RedisCallback>() { 186 | @Override 187 | public Map doInRedis(RedisConnection connection) throws DataAccessException { 188 | try { 189 | byte[] byteKey = key.getBytes("utf-8"); 190 | Map resultMap = new LinkedHashMap(); 191 | Map map = connection.hGetAll(byteKey); 192 | if (map == null) { 193 | return resultMap; 194 | } 195 | if (seconds != null) { 196 | connection.expire(byteKey, seconds); 197 | } 198 | for (Map.Entry ent : map.entrySet()) { 199 | String key = new String(ent.getKey(), "utf-8"); 200 | T value = JsonUtil.toObject(new String(ent.getValue(), "utf-8"), type); 201 | resultMap.put(key, value); 202 | } 203 | return resultMap; 204 | } catch (Exception e) { 205 | throw new RuntimeException(e); 206 | } 207 | } 208 | }, true, false); 209 | return result; 210 | } 211 | 212 | public static Map hGetAllString(final String key,final Long seconds) { 213 | 214 | Map result = (Map) redisTemplate.execute(new RedisCallback>() { 215 | @Override 216 | public Map doInRedis(RedisConnection connection) throws DataAccessException { 217 | try { 218 | byte[] byteKey = key.getBytes("utf-8"); 219 | Map resultMap = new LinkedHashMap(); 220 | Map map = connection.hGetAll(byteKey); 221 | if (map == null) { 222 | return resultMap; 223 | } 224 | if (seconds != null) { 225 | connection.expire(byteKey, seconds); 226 | } 227 | for (Map.Entry ent : map.entrySet()) { 228 | String key = new String(ent.getKey(), "utf-8"); 229 | String value = new String(ent.getValue(), "utf-8"); 230 | resultMap.put(key, value); 231 | } 232 | return resultMap; 233 | } catch (Exception e) { 234 | throw new RuntimeException(e); 235 | } 236 | } 237 | }, true, false); 238 | return result; 239 | } 240 | 241 | } 242 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, and 10 | distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright 13 | owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all other entities 16 | that control, are controlled by, or are under common control with that entity. 17 | For the purposes of this definition, "control" means (i) the power, direct or 18 | indirect, to cause the direction or management of such entity, whether by 19 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the 20 | outstanding shares, or (iii) beneficial ownership of such entity. 21 | 22 | "You" (or "Your") shall mean an individual or Legal Entity exercising 23 | permissions granted by this License. 24 | 25 | "Source" form shall mean the preferred form for making modifications, including 26 | but not limited to software source code, documentation source, and configuration 27 | files. 28 | 29 | "Object" form shall mean any form resulting from mechanical transformation or 30 | translation of a Source form, including but not limited to compiled object code, 31 | generated documentation, and conversions to other media types. 32 | 33 | "Work" shall mean the work of authorship, whether in Source or Object form, made 34 | available under the License, as indicated by a copyright notice that is included 35 | in or attached to the work (an example is provided in the Appendix below). 36 | 37 | "Derivative Works" shall mean any work, whether in Source or Object form, that 38 | is based on (or derived from) the Work and for which the editorial revisions, 39 | annotations, elaborations, or other modifications represent, as a whole, an 40 | original work of authorship. For the purposes of this License, Derivative Works 41 | shall not include works that remain separable from, or merely link (or bind by 42 | name) to the interfaces of, the Work and Derivative Works thereof. 43 | 44 | "Contribution" shall mean any work of authorship, including the original version 45 | of the Work and any modifications or additions to that Work or Derivative Works 46 | thereof, that is intentionally submitted to Licensor for inclusion in the Work 47 | by the copyright owner or by an individual or Legal Entity authorized to submit 48 | on behalf of the copyright owner. For the purposes of this definition, 49 | "submitted" means any form of electronic, verbal, or written communication sent 50 | to the Licensor or its representatives, including but not limited to 51 | communication on electronic mailing lists, source code control systems, and 52 | issue tracking systems that are managed by, or on behalf of, the Licensor for 53 | the purpose of discussing and improving the Work, but excluding communication 54 | that is conspicuously marked or otherwise designated in writing by the copyright 55 | owner as "Not a Contribution." 56 | 57 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf 58 | of whom a Contribution has been received by Licensor and subsequently 59 | incorporated within the Work. 60 | 61 | 2. Grant of Copyright License. 62 | 63 | Subject to the terms and conditions of this License, each Contributor hereby 64 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 65 | irrevocable copyright license to reproduce, prepare Derivative Works of, 66 | publicly display, publicly perform, sublicense, and distribute the Work and such 67 | Derivative Works in Source or Object form. 68 | 69 | 3. Grant of Patent License. 70 | 71 | Subject to the terms and conditions of this License, each Contributor hereby 72 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 73 | irrevocable (except as stated in this section) patent license to make, have 74 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where 75 | such license applies only to those patent claims licensable by such Contributor 76 | that are necessarily infringed by their Contribution(s) alone or by combination 77 | of their Contribution(s) with the Work to which such Contribution(s) was 78 | submitted. If You institute patent litigation against any entity (including a 79 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a 80 | Contribution incorporated within the Work constitutes direct or contributory 81 | patent infringement, then any patent licenses granted to You under this License 82 | for that Work shall terminate as of the date such litigation is filed. 83 | 84 | 4. Redistribution. 85 | 86 | You may reproduce and distribute copies of the Work or Derivative Works thereof 87 | in any medium, with or without modifications, and in Source or Object form, 88 | provided that You meet the following conditions: 89 | 90 | You must give any other recipients of the Work or Derivative Works a copy of 91 | this License; and 92 | You must cause any modified files to carry prominent notices stating that You 93 | changed the files; and 94 | You must retain, in the Source form of any Derivative Works that You distribute, 95 | all copyright, patent, trademark, and attribution notices from the Source form 96 | of the Work, excluding those notices that do not pertain to any part of the 97 | Derivative Works; and 98 | If the Work includes a "NOTICE" text file as part of its distribution, then any 99 | Derivative Works that You distribute must include a readable copy of the 100 | attribution notices contained within such NOTICE file, excluding those notices 101 | that do not pertain to any part of the Derivative Works, in at least one of the 102 | following places: within a NOTICE text file distributed as part of the 103 | Derivative Works; within the Source form or documentation, if provided along 104 | with the Derivative Works; or, within a display generated by the Derivative 105 | Works, if and wherever such third-party notices normally appear. The contents of 106 | the NOTICE file are for informational purposes only and do not modify the 107 | License. You may add Your own attribution notices within Derivative Works that 108 | You distribute, alongside or as an addendum to the NOTICE text from the Work, 109 | provided that such additional attribution notices cannot be construed as 110 | modifying the License. 111 | You may add Your own copyright statement to Your modifications and may provide 112 | additional or different license terms and conditions for use, reproduction, or 113 | distribution of Your modifications, or for any such Derivative Works as a whole, 114 | provided Your use, reproduction, and distribution of the Work otherwise complies 115 | with the conditions stated in this License. 116 | 117 | 5. Submission of Contributions. 118 | 119 | Unless You explicitly state otherwise, any Contribution intentionally submitted 120 | for inclusion in the Work by You to the Licensor shall be under the terms and 121 | conditions of this License, without any additional terms or conditions. 122 | Notwithstanding the above, nothing herein shall supersede or modify the terms of 123 | any separate license agreement you may have executed with Licensor regarding 124 | such Contributions. 125 | 126 | 6. Trademarks. 127 | 128 | This License does not grant permission to use the trade names, trademarks, 129 | service marks, or product names of the Licensor, except as required for 130 | reasonable and customary use in describing the origin of the Work and 131 | reproducing the content of the NOTICE file. 132 | 133 | 7. Disclaimer of Warranty. 134 | 135 | Unless required by applicable law or agreed to in writing, Licensor provides the 136 | Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, 137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 138 | including, without limitation, any warranties or conditions of TITLE, 139 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are 140 | solely responsible for determining the appropriateness of using or 141 | redistributing the Work and assume any risks associated with Your exercise of 142 | permissions under this License. 143 | 144 | 8. Limitation of Liability. 145 | 146 | In no event and under no legal theory, whether in tort (including negligence), 147 | contract, or otherwise, unless required by applicable law (such as deliberate 148 | and grossly negligent acts) or agreed to in writing, shall any Contributor be 149 | liable to You for damages, including any direct, indirect, special, incidental, 150 | or consequential damages of any character arising as a result of this License or 151 | out of the use or inability to use the Work (including but not limited to 152 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or 153 | any and all other commercial damages or losses), even if such Contributor has 154 | been advised of the possibility of such damages. 155 | 156 | 9. Accepting Warranty or Additional Liability. 157 | 158 | While redistributing the Work or Derivative Works thereof, You may choose to 159 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or 160 | other liability obligations and/or rights consistent with this License. However, 161 | in accepting such obligations, You may act only on Your own behalf and on Your 162 | sole responsibility, not on behalf of any other Contributor, and only if You 163 | agree to indemnify, defend, and hold each Contributor harmless for any liability 164 | incurred by, or claims asserted against, such Contributor by reason of your 165 | accepting any such warranty or additional liability. 166 | 167 | END OF TERMS AND CONDITIONS 168 | 169 | APPENDIX: How to apply the Apache License to your work 170 | 171 | To apply the Apache License to your work, attach the following boilerplate 172 | notice, with the fields enclosed by brackets "{}" replaced with your own 173 | identifying information. (Don't include the brackets!) The text should be 174 | enclosed in the appropriate comment syntax for the file format. We also 175 | recommend that a file or class name and description of purpose be included on 176 | the same "printed page" as the copyright notice for easier identification within 177 | third-party archives. 178 | 179 | Copyright 2016 yangshuai0711 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | http://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. -------------------------------------------------------------------------------- /dingding-app-server-service/src/main/java/com/mocoder/dingding/service/impl/LoginAccountServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.service.impl; 2 | 3 | import com.mocoder.dingding.constants.SessionKeyConstant; 4 | import com.mocoder.dingding.dao.LoginAccountMapper; 5 | import com.mocoder.dingding.enums.ErrorTypeEnum; 6 | import com.mocoder.dingding.model.LoginAccount; 7 | import com.mocoder.dingding.model.LoginAccountCriteria; 8 | import com.mocoder.dingding.rpc.SmsServiceWrap; 9 | import com.mocoder.dingding.service.LoginAccountService; 10 | import com.mocoder.dingding.utils.bean.RedisRequestSession; 11 | import com.mocoder.dingding.utils.encryp.EncryptUtils; 12 | import com.mocoder.dingding.utils.web.JsonUtil; 13 | import com.mocoder.dingding.vo.CommonRequest; 14 | import com.mocoder.dingding.vo.CommonResponse; 15 | import com.mocoder.dingding.vo.LoginAccountRequest; 16 | import org.apache.commons.beanutils.PropertyUtils; 17 | import org.apache.commons.lang.StringUtils; 18 | import org.apache.logging.log4j.LogManager; 19 | import org.apache.logging.log4j.Logger; 20 | import org.springframework.stereotype.Service; 21 | 22 | import javax.annotation.Resource; 23 | import java.io.IOException; 24 | import java.util.List; 25 | import java.util.Random; 26 | 27 | /** 28 | * Created by yangshuai3 on 2016/1/26. 29 | */ 30 | @Service 31 | public class LoginAccountServiceImpl implements LoginAccountService { 32 | 33 | private static final Logger log = LogManager.getLogger(LoginAccountServiceImpl.class); 34 | 35 | @Resource 36 | private SmsServiceWrap smsServiceWrap; 37 | 38 | @SuppressWarnings("SpringJavaAutowiringInspection") 39 | @Resource 40 | private LoginAccountMapper loginAccountMapper; 41 | 42 | @Override 43 | public CommonResponse loginByPass(String mobile, String password, RedisRequestSession session, CommonRequest request) { 44 | 45 | CommonResponse response = new CommonResponse(); 46 | if (session.getAttribute(SessionKeyConstant.USER_LOGIN_KEY) != null) { 47 | response.resolveErrorInfo(ErrorTypeEnum.LOGIN_DUPLICATE_ERROR); 48 | return response; 49 | } 50 | LoginAccount record = queryLoginAccounts(mobile); 51 | if (record != null) { 52 | if (EncryptUtils.md5(password).equals(record.getPassword())) { 53 | if(record.getPassword()!=null){ 54 | record.setPassword("Y"); 55 | }else{ 56 | record.setPassword("N"); 57 | } 58 | try { 59 | session.setAttribute(SessionKeyConstant.USER_LOGIN_KEY, JsonUtil.toString(record)); 60 | session.setAttribute(SessionKeyConstant.LOGIN_TYPE_KEY, "pass"); 61 | } catch (IOException e) { 62 | log.error("用户验证码登陆-失败:设置session异常", e); 63 | response.resolveErrorInfo(ErrorTypeEnum.SYSTEM_EXCEPTION); 64 | return response; 65 | } 66 | session.removeAttribute(SessionKeyConstant.VERIFY_CODE_KEY); 67 | session.saveUserSessionId(request, record.getMobile()); 68 | response.setData(record); 69 | response.setCode("0"); 70 | response.setMsg("登录成功"); 71 | return response; 72 | } else { 73 | response.resolveErrorInfo(ErrorTypeEnum.PASS_LOGIN_ERROR); 74 | return response; 75 | } 76 | } else { 77 | response.resolveErrorInfo(ErrorTypeEnum.ACCOUNT_NOT_EXISTS); 78 | return response; 79 | } 80 | } 81 | 82 | private LoginAccount queryLoginAccounts(String mobile) { 83 | LoginAccountCriteria example = new LoginAccountCriteria(); 84 | example.createCriteria().andMobileEqualTo(mobile); 85 | List list = loginAccountMapper.selectByExample(example); 86 | if (!list.isEmpty()) { 87 | return list.get(0); 88 | } 89 | return null; 90 | } 91 | 92 | @Override 93 | public CommonResponse loginByVerifyCode(String mobile, String verifyCode, RedisRequestSession session, CommonRequest request) { 94 | CommonResponse response = new CommonResponse(); 95 | if (session.getAttribute(SessionKeyConstant.USER_LOGIN_KEY) != null) { 96 | response.resolveErrorInfo(ErrorTypeEnum.LOGIN_DUPLICATE_ERROR); 97 | return response; 98 | } 99 | String code = session.getAttribute(SessionKeyConstant.VERIFY_CODE_KEY); 100 | if (verifyCode != null && verifyCode.equals(code)) { 101 | LoginAccount record = queryLoginAccounts(mobile); 102 | if (record != null) { 103 | if(record.getPassword()!=null){ 104 | record.setPassword("Y"); 105 | }else{ 106 | record.setPassword("N"); 107 | } 108 | response.setData(record); 109 | response.setCode("0"); 110 | response.setMsg("登录成功"); 111 | try { 112 | session.setAttribute(SessionKeyConstant.USER_LOGIN_KEY, JsonUtil.toString(record)); 113 | session.setAttribute(SessionKeyConstant.LOGIN_TYPE_KEY, "code"); 114 | } catch (IOException e) { 115 | log.error("用户验证码登陆-失败:设置session异常", e); 116 | response.resolveErrorInfo(ErrorTypeEnum.SYSTEM_EXCEPTION); 117 | return response; 118 | } 119 | session.removeAttribute(SessionKeyConstant.VERIFY_CODE_KEY); 120 | session.saveUserSessionId(request, record.getMobile()); 121 | return response; 122 | } else { 123 | response.resolveErrorInfo(ErrorTypeEnum.ACCOUNT_NOT_EXISTS); 124 | return response; 125 | } 126 | } else { 127 | response.resolveErrorInfo(ErrorTypeEnum.VALIDATE_CODE_ERROR); 128 | return response; 129 | } 130 | } 131 | 132 | @Override 133 | public CommonResponse registerAccount(LoginAccountRequest body, RedisRequestSession session, CommonRequest request) { 134 | CommonResponse response = new CommonResponse(); 135 | String code = session.getAttribute(SessionKeyConstant.VERIFY_CODE_KEY); 136 | if (!body.getVerifyCode().equals(code)) { 137 | response.resolveErrorInfo(ErrorTypeEnum.VALIDATE_CODE_ERROR); 138 | return response; 139 | } 140 | LoginAccount account = new LoginAccount(); 141 | try { 142 | PropertyUtils.copyProperties(account, body); 143 | } catch (Exception e) { 144 | response.resolveErrorInfo(ErrorTypeEnum.SYSTEM_EXCEPTION); 145 | } 146 | if (session.getAttribute(SessionKeyConstant.USER_LOGIN_KEY) != null) { 147 | response.resolveErrorInfo(ErrorTypeEnum.NOT_LOG_OUT_ERROR); 148 | return response; 149 | } 150 | LoginAccount record = queryLoginAccounts(account.getMobile()); 151 | if (record != null) { 152 | response.resolveErrorInfo(ErrorTypeEnum.REG_DUPLICATE_ERROR); 153 | return response; 154 | } 155 | if(StringUtils.isNotBlank(body.getPassword())) { 156 | account.setPassword(EncryptUtils.md5(body.getPassword())); 157 | } 158 | loginAccountMapper.insertSelective(account); 159 | if(account.getPassword()!=null){ 160 | account.setPassword("Y"); 161 | }else{ 162 | account.setPassword("N"); 163 | } 164 | try { 165 | session.setAttribute(SessionKeyConstant.USER_LOGIN_KEY, JsonUtil.toString(account)); 166 | session.setAttribute(SessionKeyConstant.LOGIN_TYPE_KEY, "pass"); 167 | } catch (IOException e) { 168 | session.removeAttribute(SessionKeyConstant.USER_LOGIN_KEY); 169 | log.error("用户注册-成功:设置session异常",e); 170 | } 171 | session.removeAttribute(SessionKeyConstant.VERIFY_CODE_KEY); 172 | session.saveUserSessionId(request, account.getMobile()); 173 | response.setData(account); 174 | response.setCode("0"); 175 | response.setMsg("注册成功"); 176 | return response; 177 | } 178 | 179 | @Override 180 | public CommonResponse getRegVerifyCode(String mobile, RedisRequestSession session) { 181 | CommonResponse response = new CommonResponse(); 182 | if (session.getAttribute(SessionKeyConstant.USER_LOGIN_KEY) != null) { 183 | response.resolveErrorInfo(ErrorTypeEnum.NOT_LOG_OUT_ERROR); 184 | return response; 185 | } 186 | LoginAccount record = queryLoginAccounts(mobile); 187 | if (record != null) { 188 | response.resolveErrorInfo(ErrorTypeEnum.REG_DUPLICATE_ERROR); 189 | return response; 190 | } 191 | Random random = new Random(); 192 | String code = String.valueOf(1000 + random.nextInt(8999)); 193 | session.setAttribute(SessionKeyConstant.VERIFY_CODE_KEY, code); 194 | if (smsServiceWrap.sentRegValidCodeSms(mobile, code)) { 195 | response.setCode("0"); 196 | return response; 197 | } else { 198 | response.resolveErrorInfo(ErrorTypeEnum.SMS_SEND_ERROR); 199 | return response; 200 | } 201 | } 202 | 203 | @Override 204 | public CommonResponse getLoginVerifyCode(String mobile, RedisRequestSession session) { 205 | CommonResponse response = new CommonResponse(); 206 | if (session.getAttribute(SessionKeyConstant.USER_LOGIN_KEY) != null) { 207 | response.resolveErrorInfo(ErrorTypeEnum.LOGIN_DUPLICATE_ERROR); 208 | return response; 209 | } 210 | LoginAccount record = queryLoginAccounts(mobile); 211 | if (record != null) { 212 | Random random = new Random(); 213 | String code = String.valueOf(1000 + random.nextInt(8999)); 214 | session.setAttribute(SessionKeyConstant.VERIFY_CODE_KEY, code); 215 | if (smsServiceWrap.sentRegValidCodeSms(mobile, code)) { 216 | response.setCode("0"); 217 | return response; 218 | } else { 219 | response.resolveErrorInfo(ErrorTypeEnum.SMS_SEND_ERROR); 220 | return response; 221 | } 222 | } else { 223 | response.resolveErrorInfo(ErrorTypeEnum.ACCOUNT_NOT_EXISTS); 224 | return response; 225 | } 226 | } 227 | 228 | @Override 229 | public CommonResponse logoutAccount(LoginAccountRequest body, RedisRequestSession session) { 230 | CommonResponse response = new CommonResponse(); 231 | try { 232 | session.destroy(); 233 | } catch (Exception e) { 234 | response.resolveErrorInfo(ErrorTypeEnum.SYSTEM_EXCEPTION); 235 | log.error("账户注销-异常:销毁session失败,redis操作异常", e); 236 | return response; 237 | } 238 | response.setCode("0"); 239 | response.setMsg("注销成功"); 240 | return response; 241 | } 242 | 243 | @Override 244 | public CommonResponse updateAccount(LoginAccountRequest body, RedisRequestSession session, CommonRequest request) { 245 | CommonResponse response = new CommonResponse(); 246 | // String code = session.getAttribute(SessionKeyConstant.VERIFY_CODE_KEY, String.class); 247 | // if (!body.getVerifyCode().equals(code)) { 248 | // response.resolveErrorInfo(ErrorTypeEnum.VALIDATE_CODE_ERROR); 249 | // return response; 250 | // } 251 | //用户权限验证 252 | LoginAccount login = null; 253 | try { 254 | login = JsonUtil.toObject(session.getAttribute(SessionKeyConstant.USER_LOGIN_KEY), LoginAccount.class); 255 | } catch (IOException e) { 256 | log.error("更新登陆账户-异常:反序列化redis值失败",e); 257 | response.resolveErrorInfo(ErrorTypeEnum.SYSTEM_EXCEPTION); 258 | return response; 259 | } 260 | if (login == null||!login.getMobile().equals(body.getMobile())) { 261 | response.resolveErrorInfo(ErrorTypeEnum.USER_OPERATE_NOT_PERMIT); 262 | return response; 263 | } 264 | LoginAccountCriteria example = new LoginAccountCriteria(); 265 | example.createCriteria().andMobileEqualTo(body.getMobile()); 266 | LoginAccount record = loginAccountMapper.selectByExample(example).get(0); 267 | LoginAccount account = new LoginAccount(); 268 | try { 269 | PropertyUtils.copyProperties(account, body); 270 | } catch (Exception e) { 271 | log.error("更新登陆账户-异常:属性拷贝异常",e); 272 | response.resolveErrorInfo(ErrorTypeEnum.SYSTEM_EXCEPTION); 273 | return response; 274 | } 275 | if(StringUtils.isNotBlank(body.getPassword())) { 276 | account.setPassword(EncryptUtils.md5(body.getPassword())); 277 | if(StringUtils.isNotBlank(record.getPassword())&&(StringUtils.isBlank(body.getOldPassword())||!record.getPassword().equals(EncryptUtils.md5(body.getOldPassword())))&&!"code".equals(session.getAttribute(SessionKeyConstant.LOGIN_TYPE_KEY))){ 278 | response.setCode("50"); 279 | response.setMsg("当前密码输入不正确"); 280 | return response; 281 | } 282 | } 283 | account.setMobile(null); 284 | account.setId(null); 285 | loginAccountMapper.updateByExampleSelective(account, example); 286 | record = loginAccountMapper.selectByExample(example).get(0); 287 | if(record.getPassword()!=null) { 288 | record.setPassword("Y"); 289 | }else{ 290 | record.setPassword("N"); 291 | } 292 | account.setMobile(body.getMobile()); 293 | try { 294 | session.setAttribute(SessionKeyConstant.USER_LOGIN_KEY,JsonUtil.toString( record)); 295 | session.setAttribute(SessionKeyConstant.LOGIN_TYPE_KEY, "pass"); 296 | } catch (IOException e) { 297 | log.error("更新登陆账户-异常:反序列化redis值失败",e); 298 | session.removeAttribute(SessionKeyConstant.USER_LOGIN_KEY); 299 | } 300 | response.setData(record); 301 | response.setCode("0"); 302 | response.setMsg("修改成功"); 303 | return response; 304 | } 305 | 306 | @Override 307 | public CommonResponse getImportantOperationVerifyCode(String mobile, RedisRequestSession session) { 308 | CommonResponse response = new CommonResponse(); 309 | Random random = new Random(); 310 | String code = String.valueOf(1000 + random.nextInt(8999)); 311 | session.setAttribute(SessionKeyConstant.VERIFY_CODE_KEY, code); 312 | if (smsServiceWrap.sentRegValidCodeSms(mobile, code)) { 313 | response.setCode("0"); 314 | return response; 315 | } else { 316 | response.resolveErrorInfo(ErrorTypeEnum.SMS_SEND_ERROR); 317 | return response; 318 | } 319 | } 320 | } 321 | -------------------------------------------------------------------------------- /dingding-app-server-dao/src/main/java/com/mocoder/dingding/model/LoginAccountCriteria.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.model; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class LoginAccountCriteria { 7 | protected String orderByClause; 8 | 9 | protected boolean distinct; 10 | 11 | protected List oredCriteria; 12 | 13 | public LoginAccountCriteria() { 14 | oredCriteria = new ArrayList(); 15 | } 16 | 17 | public void setOrderByClause(String orderByClause) { 18 | this.orderByClause = orderByClause; 19 | } 20 | 21 | public String getOrderByClause() { 22 | return orderByClause; 23 | } 24 | 25 | public void setDistinct(boolean distinct) { 26 | this.distinct = distinct; 27 | } 28 | 29 | public boolean isDistinct() { 30 | return distinct; 31 | } 32 | 33 | public List getOredCriteria() { 34 | return oredCriteria; 35 | } 36 | 37 | public void or(Criteria criteria) { 38 | oredCriteria.add(criteria); 39 | } 40 | 41 | public Criteria or() { 42 | Criteria criteria = createCriteriaInternal(); 43 | oredCriteria.add(criteria); 44 | return criteria; 45 | } 46 | 47 | public Criteria createCriteria() { 48 | Criteria criteria = createCriteriaInternal(); 49 | if (oredCriteria.size() == 0) { 50 | oredCriteria.add(criteria); 51 | } 52 | return criteria; 53 | } 54 | 55 | protected Criteria createCriteriaInternal() { 56 | Criteria criteria = new Criteria(); 57 | return criteria; 58 | } 59 | 60 | public void clear() { 61 | oredCriteria.clear(); 62 | orderByClause = null; 63 | distinct = false; 64 | } 65 | 66 | protected abstract static class GeneratedCriteria { 67 | protected List criteria; 68 | 69 | protected GeneratedCriteria() { 70 | super(); 71 | criteria = new ArrayList(); 72 | } 73 | 74 | public boolean isValid() { 75 | return criteria.size() > 0; 76 | } 77 | 78 | public List getAllCriteria() { 79 | return criteria; 80 | } 81 | 82 | public List getCriteria() { 83 | return criteria; 84 | } 85 | 86 | protected void addCriterion(String condition) { 87 | if (condition == null) { 88 | throw new RuntimeException("Value for condition cannot be null"); 89 | } 90 | criteria.add(new Criterion(condition)); 91 | } 92 | 93 | protected void addCriterion(String condition, Object value, String property) { 94 | if (value == null) { 95 | throw new RuntimeException("Value for " + property + " cannot be null"); 96 | } 97 | criteria.add(new Criterion(condition, value)); 98 | } 99 | 100 | protected void addCriterion(String condition, Object value1, Object value2, String property) { 101 | if (value1 == null || value2 == null) { 102 | throw new RuntimeException("Between values for " + property + " cannot be null"); 103 | } 104 | criteria.add(new Criterion(condition, value1, value2)); 105 | } 106 | 107 | public Criteria andIdIsNull() { 108 | addCriterion("id is null"); 109 | return (Criteria) this; 110 | } 111 | 112 | public Criteria andIdIsNotNull() { 113 | addCriterion("id is not null"); 114 | return (Criteria) this; 115 | } 116 | 117 | public Criteria andIdEqualTo(Integer value) { 118 | addCriterion("id =", value, "id"); 119 | return (Criteria) this; 120 | } 121 | 122 | public Criteria andIdNotEqualTo(Integer value) { 123 | addCriterion("id <>", value, "id"); 124 | return (Criteria) this; 125 | } 126 | 127 | public Criteria andIdGreaterThan(Integer value) { 128 | addCriterion("id >", value, "id"); 129 | return (Criteria) this; 130 | } 131 | 132 | public Criteria andIdGreaterThanOrEqualTo(Integer value) { 133 | addCriterion("id >=", value, "id"); 134 | return (Criteria) this; 135 | } 136 | 137 | public Criteria andIdLessThan(Integer value) { 138 | addCriterion("id <", value, "id"); 139 | return (Criteria) this; 140 | } 141 | 142 | public Criteria andIdLessThanOrEqualTo(Integer value) { 143 | addCriterion("id <=", value, "id"); 144 | return (Criteria) this; 145 | } 146 | 147 | public Criteria andIdIn(List values) { 148 | addCriterion("id in", values, "id"); 149 | return (Criteria) this; 150 | } 151 | 152 | public Criteria andIdNotIn(List values) { 153 | addCriterion("id not in", values, "id"); 154 | return (Criteria) this; 155 | } 156 | 157 | public Criteria andIdBetween(Integer value1, Integer value2) { 158 | addCriterion("id between", value1, value2, "id"); 159 | return (Criteria) this; 160 | } 161 | 162 | public Criteria andIdNotBetween(Integer value1, Integer value2) { 163 | addCriterion("id not between", value1, value2, "id"); 164 | return (Criteria) this; 165 | } 166 | 167 | public Criteria andMobileIsNull() { 168 | addCriterion("mobile is null"); 169 | return (Criteria) this; 170 | } 171 | 172 | public Criteria andMobileIsNotNull() { 173 | addCriterion("mobile is not null"); 174 | return (Criteria) this; 175 | } 176 | 177 | public Criteria andMobileEqualTo(String value) { 178 | addCriterion("mobile =", value, "mobile"); 179 | return (Criteria) this; 180 | } 181 | 182 | public Criteria andMobileNotEqualTo(String value) { 183 | addCriterion("mobile <>", value, "mobile"); 184 | return (Criteria) this; 185 | } 186 | 187 | public Criteria andMobileGreaterThan(String value) { 188 | addCriterion("mobile >", value, "mobile"); 189 | return (Criteria) this; 190 | } 191 | 192 | public Criteria andMobileGreaterThanOrEqualTo(String value) { 193 | addCriterion("mobile >=", value, "mobile"); 194 | return (Criteria) this; 195 | } 196 | 197 | public Criteria andMobileLessThan(String value) { 198 | addCriterion("mobile <", value, "mobile"); 199 | return (Criteria) this; 200 | } 201 | 202 | public Criteria andMobileLessThanOrEqualTo(String value) { 203 | addCriterion("mobile <=", value, "mobile"); 204 | return (Criteria) this; 205 | } 206 | 207 | public Criteria andMobileLike(String value) { 208 | addCriterion("mobile like", value, "mobile"); 209 | return (Criteria) this; 210 | } 211 | 212 | public Criteria andMobileNotLike(String value) { 213 | addCriterion("mobile not like", value, "mobile"); 214 | return (Criteria) this; 215 | } 216 | 217 | public Criteria andMobileIn(List values) { 218 | addCriterion("mobile in", values, "mobile"); 219 | return (Criteria) this; 220 | } 221 | 222 | public Criteria andMobileNotIn(List values) { 223 | addCriterion("mobile not in", values, "mobile"); 224 | return (Criteria) this; 225 | } 226 | 227 | public Criteria andMobileBetween(String value1, String value2) { 228 | addCriterion("mobile between", value1, value2, "mobile"); 229 | return (Criteria) this; 230 | } 231 | 232 | public Criteria andMobileNotBetween(String value1, String value2) { 233 | addCriterion("mobile not between", value1, value2, "mobile"); 234 | return (Criteria) this; 235 | } 236 | 237 | public Criteria andNickNameIsNull() { 238 | addCriterion("nick_name is null"); 239 | return (Criteria) this; 240 | } 241 | 242 | public Criteria andNickNameIsNotNull() { 243 | addCriterion("nick_name is not null"); 244 | return (Criteria) this; 245 | } 246 | 247 | public Criteria andNickNameEqualTo(String value) { 248 | addCriterion("nick_name =", value, "nickName"); 249 | return (Criteria) this; 250 | } 251 | 252 | public Criteria andNickNameNotEqualTo(String value) { 253 | addCriterion("nick_name <>", value, "nickName"); 254 | return (Criteria) this; 255 | } 256 | 257 | public Criteria andNickNameGreaterThan(String value) { 258 | addCriterion("nick_name >", value, "nickName"); 259 | return (Criteria) this; 260 | } 261 | 262 | public Criteria andNickNameGreaterThanOrEqualTo(String value) { 263 | addCriterion("nick_name >=", value, "nickName"); 264 | return (Criteria) this; 265 | } 266 | 267 | public Criteria andNickNameLessThan(String value) { 268 | addCriterion("nick_name <", value, "nickName"); 269 | return (Criteria) this; 270 | } 271 | 272 | public Criteria andNickNameLessThanOrEqualTo(String value) { 273 | addCriterion("nick_name <=", value, "nickName"); 274 | return (Criteria) this; 275 | } 276 | 277 | public Criteria andNickNameLike(String value) { 278 | addCriterion("nick_name like", value, "nickName"); 279 | return (Criteria) this; 280 | } 281 | 282 | public Criteria andNickNameNotLike(String value) { 283 | addCriterion("nick_name not like", value, "nickName"); 284 | return (Criteria) this; 285 | } 286 | 287 | public Criteria andNickNameIn(List values) { 288 | addCriterion("nick_name in", values, "nickName"); 289 | return (Criteria) this; 290 | } 291 | 292 | public Criteria andNickNameNotIn(List values) { 293 | addCriterion("nick_name not in", values, "nickName"); 294 | return (Criteria) this; 295 | } 296 | 297 | public Criteria andNickNameBetween(String value1, String value2) { 298 | addCriterion("nick_name between", value1, value2, "nickName"); 299 | return (Criteria) this; 300 | } 301 | 302 | public Criteria andNickNameNotBetween(String value1, String value2) { 303 | addCriterion("nick_name not between", value1, value2, "nickName"); 304 | return (Criteria) this; 305 | } 306 | 307 | public Criteria andPasswordIsNull() { 308 | addCriterion("password is null"); 309 | return (Criteria) this; 310 | } 311 | 312 | public Criteria andPasswordIsNotNull() { 313 | addCriterion("password is not null"); 314 | return (Criteria) this; 315 | } 316 | 317 | public Criteria andPasswordEqualTo(String value) { 318 | addCriterion("password =", value, "password"); 319 | return (Criteria) this; 320 | } 321 | 322 | public Criteria andPasswordNotEqualTo(String value) { 323 | addCriterion("password <>", value, "password"); 324 | return (Criteria) this; 325 | } 326 | 327 | public Criteria andPasswordGreaterThan(String value) { 328 | addCriterion("password >", value, "password"); 329 | return (Criteria) this; 330 | } 331 | 332 | public Criteria andPasswordGreaterThanOrEqualTo(String value) { 333 | addCriterion("password >=", value, "password"); 334 | return (Criteria) this; 335 | } 336 | 337 | public Criteria andPasswordLessThan(String value) { 338 | addCriterion("password <", value, "password"); 339 | return (Criteria) this; 340 | } 341 | 342 | public Criteria andPasswordLessThanOrEqualTo(String value) { 343 | addCriterion("password <=", value, "password"); 344 | return (Criteria) this; 345 | } 346 | 347 | public Criteria andPasswordLike(String value) { 348 | addCriterion("password like", value, "password"); 349 | return (Criteria) this; 350 | } 351 | 352 | public Criteria andPasswordNotLike(String value) { 353 | addCriterion("password not like", value, "password"); 354 | return (Criteria) this; 355 | } 356 | 357 | public Criteria andPasswordIn(List values) { 358 | addCriterion("password in", values, "password"); 359 | return (Criteria) this; 360 | } 361 | 362 | public Criteria andPasswordNotIn(List values) { 363 | addCriterion("password not in", values, "password"); 364 | return (Criteria) this; 365 | } 366 | 367 | public Criteria andPasswordBetween(String value1, String value2) { 368 | addCriterion("password between", value1, value2, "password"); 369 | return (Criteria) this; 370 | } 371 | 372 | public Criteria andPasswordNotBetween(String value1, String value2) { 373 | addCriterion("password not between", value1, value2, "password"); 374 | return (Criteria) this; 375 | } 376 | 377 | public Criteria andMobileLikeInsensitive(String value) { 378 | addCriterion("upper(mobile) like", value.toUpperCase(), "mobile"); 379 | return (Criteria) this; 380 | } 381 | 382 | public Criteria andNickNameLikeInsensitive(String value) { 383 | addCriterion("upper(nick_name) like", value.toUpperCase(), "nickName"); 384 | return (Criteria) this; 385 | } 386 | 387 | public Criteria andPasswordLikeInsensitive(String value) { 388 | addCriterion("upper(password) like", value.toUpperCase(), "password"); 389 | return (Criteria) this; 390 | } 391 | } 392 | 393 | public static class Criteria extends GeneratedCriteria { 394 | 395 | protected Criteria() { 396 | super(); 397 | } 398 | } 399 | 400 | public static class Criterion { 401 | private String condition; 402 | 403 | private Object value; 404 | 405 | private Object secondValue; 406 | 407 | private boolean noValue; 408 | 409 | private boolean singleValue; 410 | 411 | private boolean betweenValue; 412 | 413 | private boolean listValue; 414 | 415 | private String typeHandler; 416 | 417 | public String getCondition() { 418 | return condition; 419 | } 420 | 421 | public Object getValue() { 422 | return value; 423 | } 424 | 425 | public Object getSecondValue() { 426 | return secondValue; 427 | } 428 | 429 | public boolean isNoValue() { 430 | return noValue; 431 | } 432 | 433 | public boolean isSingleValue() { 434 | return singleValue; 435 | } 436 | 437 | public boolean isBetweenValue() { 438 | return betweenValue; 439 | } 440 | 441 | public boolean isListValue() { 442 | return listValue; 443 | } 444 | 445 | public String getTypeHandler() { 446 | return typeHandler; 447 | } 448 | 449 | protected Criterion(String condition) { 450 | super(); 451 | this.condition = condition; 452 | this.typeHandler = null; 453 | this.noValue = true; 454 | } 455 | 456 | protected Criterion(String condition, Object value, String typeHandler) { 457 | super(); 458 | this.condition = condition; 459 | this.value = value; 460 | this.typeHandler = typeHandler; 461 | if (value instanceof List) { 462 | this.listValue = true; 463 | } else { 464 | this.singleValue = true; 465 | } 466 | } 467 | 468 | protected Criterion(String condition, Object value) { 469 | this(condition, value, null); 470 | } 471 | 472 | protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { 473 | super(); 474 | this.condition = condition; 475 | this.value = value; 476 | this.secondValue = secondValue; 477 | this.typeHandler = typeHandler; 478 | this.betweenValue = true; 479 | } 480 | 481 | protected Criterion(String condition, Object value, Object secondValue) { 482 | this(condition, value, secondValue, null); 483 | } 484 | } 485 | } -------------------------------------------------------------------------------- /dingding-app-server-web/src/test/java/com/mocoder/dingding/test/client/httpClientTest.java: -------------------------------------------------------------------------------- 1 | package com.mocoder.dingding.test.client; 2 | 3 | import com.mocoder.dingding.constants.AppVersionConstant; 4 | import com.mocoder.dingding.constants.EncryptionConstant; 5 | import com.mocoder.dingding.constants.PlatformConstant; 6 | import com.mocoder.dingding.utils.encryp.EncryptUtils; 7 | import com.mocoder.dingding.utils.web.JsonUtil; 8 | import com.mocoder.dingding.vo.CommonResponse; 9 | import com.mocoder.dingding.vo.LoginAccountRequest; 10 | import org.junit.Assert; 11 | import org.junit.Test; 12 | 13 | import java.util.Date; 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | import java.util.Scanner; 17 | 18 | /** 19 | * Created with IntelliJ IDEA. 20 | * User: likun7 21 | * Date: 14-11-19 22 | * Time: 上午11:52 23 | * To change this template use File | Settings | File Templates. 24 | */ 25 | public class httpClientTest { 26 | 27 | // private static final String HOST = "https://mocoder.com/dingding"; 28 | 29 | // private static final String HOST = "http://mocoder.com:8080/dingding-app-server"; 30 | 31 | private static final String HOST = "http://localhost:8080/dingding"; 32 | @Test 33 | public void testGetLoginCode() { 34 | String sessionId = getSessionId(); 35 | Assert.assertNotNull(sessionId); 36 | boolean result = getLoginCode(sessionId); 37 | Assert.assertTrue(result); 38 | } 39 | 40 | @Test 41 | public void testGetRegCode() { 42 | String sessionId = getSessionId(); 43 | Assert.assertNotNull(sessionId); 44 | boolean result = getRegCode(sessionId); 45 | Assert.assertTrue(result); 46 | } 47 | 48 | @Test 49 | public void testLogout() { 50 | String sessionId = getSessionId(); 51 | Assert.assertNotNull(sessionId); 52 | boolean result = logout(sessionId); 53 | Assert.assertTrue(result); 54 | } 55 | 56 | public static String getSessionId() { 57 | String url = HOST + "/param/getSessionId"; 58 | Map header = new HashMap(); 59 | header.put("appversion", AppVersionConstant.VERSION_1_0_0); 60 | header.put("platform", PlatformConstant.ANDROID); 61 | header.put("timestamp", String.valueOf(new Date().getTime())); 62 | header.put("deviceid", "123456"); 63 | header.put("sessionid", ""); 64 | Map param = new HashMap(); 65 | try { 66 | String body = ""; 67 | 68 | // TODO body = EncryptUtils.base64Encode(body); 69 | param.put("body",body); 70 | String tmpStr = /*param.get("body") +*/ header.get("timestamp") + header.get("sessionid") + EncryptionConstant.HEADER_PARAM_SIGN_PRIVATE_KEY; 71 | String targetToken = EncryptUtils.md5(tmpStr); 72 | header.put("sign", targetToken); 73 | String response = HttpClientUtil.doPost(url, header, param); 74 | System.out.println("--------getSessionId()--------"); 75 | System.out.println(response); 76 | CommonResponse commonResponse = JsonUtil.toObject(response, CommonResponse.class); 77 | if (commonResponse.getCode().equals("0")) { 78 | return (String) commonResponse.getData(); 79 | } 80 | } catch (Exception e) { 81 | e.printStackTrace(); 82 | } 83 | return null; 84 | } 85 | 86 | public static boolean getLoginCode(String sessionId) { 87 | String url = HOST + "/account/getLoginVerifyCode"; 88 | Map header = new HashMap(); 89 | header.put("appversion", AppVersionConstant.VERSION_1_0_0); 90 | header.put("platform", PlatformConstant.ANDROID); 91 | header.put("timestamp", String.valueOf(new Date().getTime())); 92 | header.put("deviceid", "123456"); 93 | header.put("sessionid", sessionId); 94 | Map param = new HashMap(); 95 | try { 96 | String body = "{\"mobile\":\"15652301160\"}"; 97 | 98 | // TODO body = EncryptUtils.base64Encode(body); 99 | param.put("body", body); 100 | String tmpStr = /*param.get("body") + */ header.get("timestamp") + header.get("sessionid") + EncryptionConstant.HEADER_PARAM_SIGN_PRIVATE_KEY; 101 | String targetToken = EncryptUtils.md5(tmpStr); 102 | header.put("sign", targetToken); 103 | String response = HttpClientUtil.doPost(url, header, param); 104 | System.out.println("--------getLoginCode()--------"); 105 | System.out.println(response); 106 | CommonResponse commonResponse = JsonUtil.toObject(response, CommonResponse.class); 107 | if (commonResponse.getCode().equals("0")) { 108 | return true; 109 | } 110 | } catch (Exception e) { 111 | e.printStackTrace(); 112 | } 113 | return false; 114 | } 115 | 116 | public static boolean getRegCode(String sessionId) { 117 | String url = HOST + "/account/getRegVerifyCode"; 118 | Map header = new HashMap(); 119 | header.put("appversion", AppVersionConstant.VERSION_1_0_0); 120 | header.put("platform", PlatformConstant.IOS); 121 | header.put("timestamp", String.valueOf(new Date().getTime())); 122 | header.put("deviceid", "123456"); 123 | header.put("sessionid", sessionId); 124 | Map param = new HashMap(); 125 | try { 126 | String body = "{\"mobile\":\"15652301160\"}"; 127 | 128 | // TODO body = EncryptUtils.base64Encode(body); 129 | param.put("body", body); 130 | String tmpStr = /*param.get("body") +*/ header.get("timestamp") + header.get("sessionid") + EncryptionConstant.HEADER_PARAM_SIGN_PRIVATE_KEY; 131 | String targetToken = EncryptUtils.md5(tmpStr); 132 | header.put("sign", targetToken); 133 | String response = HttpClientUtil.doPost(url, header, param); 134 | System.out.println("--------getRegCode()--------"); 135 | System.out.println(response); 136 | CommonResponse commonResponse = JsonUtil.toObject(response, CommonResponse.class); 137 | if (commonResponse.getCode().equals("0")) { 138 | return true; 139 | } 140 | } catch (Exception e) { 141 | e.printStackTrace(); 142 | } 143 | return false; 144 | } 145 | 146 | public static boolean reg(String sessionId, String verifyCode) { 147 | String url = HOST + "/account/reg"; 148 | Map header = new HashMap(); 149 | header.put("appversion", AppVersionConstant.VERSION_1_0_0); 150 | header.put("platform", PlatformConstant.ANDROID); 151 | header.put("timestamp", String.valueOf(new Date().getTime())); 152 | header.put("deviceid", "123456"); 153 | header.put("sessionid", sessionId); 154 | Map param = new HashMap(); 155 | LoginAccountRequest request = new LoginAccountRequest(); 156 | request.setNickName("杨帅"); 157 | request.setMobile("15652301160"); 158 | request.setPassword("123456"); 159 | request.setVerifyCode(verifyCode); 160 | try { 161 | String body = JsonUtil.toString(request); 162 | 163 | // TODO body = EncryptUtils.base64Encode(body); 164 | param.put("body", body); 165 | String tmpStr = /*param.get("body") + */ header.get("timestamp") + header.get("sessionid") + EncryptionConstant.HEADER_PARAM_SIGN_PRIVATE_KEY; 166 | 167 | String targetToken = EncryptUtils.md5(tmpStr); 168 | header.put("sign", targetToken); 169 | String response = HttpClientUtil.doPost(url, header, param); 170 | System.out.println("--------reg()--------"); 171 | System.out.println(response); 172 | CommonResponse commonResponse = JsonUtil.toObject(response, CommonResponse.class); 173 | if (commonResponse.getCode().equals("0")) { 174 | return true; 175 | } 176 | } catch (Exception e) { 177 | e.printStackTrace(); 178 | } 179 | return false; 180 | } 181 | 182 | public static boolean loginByCode(String sessionId, String verifyCode) { 183 | String url = HOST + "/account/loginByCode"; 184 | Map header = new HashMap(); 185 | header.put("appversion", AppVersionConstant.VERSION_1_0_0); 186 | header.put("platform", PlatformConstant.ANDROID); 187 | header.put("timestamp", String.valueOf(new Date().getTime())); 188 | header.put("deviceid", "123456"); 189 | header.put("sessionid", sessionId); 190 | Map param = new HashMap(); 191 | LoginAccountRequest request = new LoginAccountRequest(); 192 | request.setMobile("15652301160"); 193 | request.setVerifyCode(verifyCode); 194 | try { 195 | String body = JsonUtil.toString(request); 196 | 197 | // TODO body = EncryptUtils.base64Encode(body); 198 | param.put("body", body); 199 | String tmpStr = /*param.get("body") + */ header.get("timestamp") + header.get("sessionid") + EncryptionConstant.HEADER_PARAM_SIGN_PRIVATE_KEY; 200 | 201 | String targetToken = EncryptUtils.md5(tmpStr); 202 | header.put("sign", targetToken); 203 | String response = HttpClientUtil.doPost(url, header, param); 204 | System.out.println("--------reg()--------"); 205 | System.out.println(response); 206 | CommonResponse commonResponse = JsonUtil.toObject(response, CommonResponse.class); 207 | if (commonResponse.getCode().equals("0")) { 208 | return true; 209 | } 210 | } catch (Exception e) { 211 | e.printStackTrace(); 212 | } 213 | return false; 214 | } 215 | 216 | public static boolean loginByPass(String sessionId, String pass) { 217 | String url = HOST + "/account/loginByPass"; 218 | Map header = new HashMap(); 219 | header.put("appversion", AppVersionConstant.VERSION_1_0_0); 220 | header.put("platform", PlatformConstant.ANDROID); 221 | header.put("timestamp", String.valueOf(new Date().getTime())); 222 | header.put("deviceid", "123456"); 223 | header.put("sessionid", sessionId); 224 | Map param = new HashMap(); 225 | LoginAccountRequest request = new LoginAccountRequest(); 226 | request.setMobile("15652301160"); 227 | request.setPassword(pass); 228 | try { 229 | String body = JsonUtil.toString(request); 230 | 231 | // TODO body = EncryptUtils.base64Encode(body); 232 | param.put("body", body); 233 | String tmpStr = /*param.get("body") + */ header.get("timestamp") + header.get("sessionid") + EncryptionConstant.HEADER_PARAM_SIGN_PRIVATE_KEY; 234 | 235 | String targetToken = EncryptUtils.md5(tmpStr); 236 | header.put("sign", targetToken); 237 | String response = HttpClientUtil.doPost(url, header, param); 238 | System.out.println("--------loginByPass()--------"); 239 | System.out.println(response); 240 | CommonResponse commonResponse = JsonUtil.toObject(response, CommonResponse.class); 241 | if (commonResponse.getCode().equals("0")) { 242 | return true; 243 | } 244 | } catch (Exception e) { 245 | e.printStackTrace(); 246 | } 247 | return false; 248 | } 249 | 250 | public static boolean logout(String sessionId) { 251 | String url = HOST + "/account/logout"; 252 | Map header = new HashMap(); 253 | header.put("appversion", AppVersionConstant.VERSION_1_0_0); 254 | header.put("platform", PlatformConstant.ANDROID); 255 | header.put("timestamp", String.valueOf(new Date().getTime())); 256 | header.put("deviceid", "123456"); 257 | header.put("sessionid", sessionId); 258 | Map param = new HashMap(); 259 | try { 260 | String body = "{\"mobile\":\"15652301160\"}"; 261 | 262 | // TODO body = EncryptUtils.base64Encode(body); 263 | param.put("body", body); 264 | String tmpStr = /*param.get("body") + */ header.get("timestamp") + header.get("sessionid") + EncryptionConstant.HEADER_PARAM_SIGN_PRIVATE_KEY; 265 | String targetToken = EncryptUtils.md5(tmpStr); 266 | header.put("sign", targetToken); 267 | String response = HttpClientUtil.doPost(url, header, param); 268 | System.out.println("--------logout()--------"); 269 | System.out.println(response); 270 | CommonResponse commonResponse = JsonUtil.toObject(response, CommonResponse.class); 271 | if (commonResponse.getCode().equals("0")) { 272 | return true; 273 | } 274 | } catch (Exception e) { 275 | e.printStackTrace(); 276 | } 277 | return false; 278 | } 279 | 280 | public static void main(String[] args) { 281 | String sessionId = getSessionId(); 282 | String code = ""; 283 | String pass = ""; 284 | Scanner scanner = new Scanner(System.in); 285 | while (true) { 286 | System.out.println("\n\noptions:1.register; 2.login; 3.get session id; 4.logout; 5.exit"); 287 | String input1 = scanner.nextLine(); 288 | if ("1".equals(input1)) { 289 | do { 290 | System.out.println("options:1.input verify code; 2.get and input verify code; 3.reg; 4.to menu"); 291 | String input2 = scanner.nextLine(); 292 | if ("2".equals(input2)) { 293 | if (!getRegCode(sessionId)) { 294 | continue; 295 | } 296 | code = scanner.nextLine(); 297 | } else if ("1".equals(input2)) { 298 | System.out.println("last code:" + code); 299 | code = scanner.nextLine(); 300 | } else if ("4".equals(input2)) { 301 | break; 302 | } 303 | System.out.println("use code:" + code); 304 | if (!reg(sessionId, code)) { 305 | continue; 306 | } 307 | } while (true); 308 | } else if ("2".equals(input1)) {//login 309 | do { 310 | System.out.println("options:1.input code; 2.get and input code; 3.input pass; 4.login with last code; 5.login with last pass; 6.to menu"); 311 | String input2 = scanner.nextLine(); 312 | if ("2".equals(input2)) { 313 | if (!getLoginCode(sessionId)) { 314 | continue; 315 | } 316 | code = scanner.nextLine(); 317 | System.out.println("use code:" + code); 318 | loginByCode(sessionId, code); 319 | } else if ("1".equals(input2)) { 320 | System.out.println("last code:" + code); 321 | code = scanner.nextLine(); 322 | System.out.println("use code:" + code); 323 | loginByCode(sessionId, code); 324 | } else if ("3".equals(input2)) { 325 | System.out.println("last pass:" + pass); 326 | pass = scanner.nextLine(); 327 | System.out.println("use pass:" + pass); 328 | loginByPass(sessionId, pass); 329 | } else if ("4".equals(input2)) { 330 | System.out.println("last code:" + code); 331 | System.out.println("use code:" + code); 332 | loginByCode(sessionId, code); 333 | } else if ("5".equals(input2)) { 334 | System.out.println("last pass:" + pass); 335 | System.out.println("use pass:" + pass); 336 | loginByPass(sessionId, pass); 337 | } else if ("6".equals(input2)) { 338 | break; 339 | } else { 340 | System.out.println("无效的选项"); 341 | } 342 | } while (true); 343 | } else if ("3".equals(input1)) {//get session id 344 | sessionId = getSessionId(); 345 | } else if ("4".equals(input1)) {//logout 346 | logout(sessionId); 347 | } else if ("5".equals(input1)) {//exit 348 | break; 349 | } else { 350 | System.out.println("无效的选项"); 351 | } 352 | } 353 | } 354 | } --------------------------------------------------------------------------------