├── JetBrains_Open_Source ├── LICENSE ├── README.md ├── common-cache ├── pom.xml ├── pom.xml.versionsBackup └── src │ └── main │ └── java │ └── com │ └── yz │ └── common │ └── cache │ └── ICache.java ├── common-core ├── pom.xml ├── pom.xml.versionsBackup └── src │ └── main │ └── java │ └── com │ └── yz │ └── common │ └── core │ ├── configuration │ └── ValidatorConfiguration.java │ ├── dao │ └── BaseDao.java │ ├── enums │ ├── CacheTypeEnum.java │ ├── ErrorInfo.java │ ├── JsonTypeEnum.java │ └── PayEnum.java │ ├── exception │ └── HandlerException.java │ ├── file │ └── dowload │ │ ├── FileDownload.java │ │ ├── FileDownloadManager.java │ │ └── FileDownloadProgress.java │ ├── json │ ├── FastJson.java │ ├── IJsonInterface.java │ ├── JSON.java │ ├── Jackson.java │ └── JacksonUtil.java │ ├── message │ └── ResponseMessage.java │ ├── model │ └── Page.java │ ├── service │ ├── BaseService.java │ └── BaseServiceManager.java │ └── utils │ ├── AioOperation.java │ ├── BeanUtil.java │ ├── ClassLocationUtils.java │ ├── ClassUtil.java │ ├── CommandUtil.java │ ├── DataCompressUtil.java │ ├── DateUtils.java │ ├── EncryptUtil.java │ ├── FileUploadUtil.java │ ├── FileUtils.java │ ├── GraphicsMagick.java │ ├── HttpUtil.java │ ├── IDCardUtil.java │ ├── IHttpClient.java │ ├── IPUtil.java │ ├── ImageUtil.java │ ├── ImgCompress.java │ ├── ListUtils.java │ ├── MD5Util.java │ ├── PlatformUtil.java │ ├── PropertyUtil.java │ ├── QRCodeUtil.java │ ├── RandomUtil.java │ ├── SHA256Util.java │ ├── SerializeUtil.java │ ├── SnowflakeID.java │ ├── SnowflakeIdWorker.java │ ├── SolrAPI.java │ ├── StringUtils.java │ ├── UUIDUtil.java │ ├── VerifyCodeUtil.java │ ├── WordUtil.java │ ├── XMLUtil.java │ └── ZipUtil.java ├── common-distributed-lock ├── pom.xml ├── pom.xml.versionsBackup └── src │ └── main │ └── java │ └── com │ └── yz │ └── common │ └── distributed │ └── lock │ ├── DistributedLock.java │ ├── MethodLockConfigBeanNameUtils.java │ ├── annotation │ ├── EnableMethodLock.java │ └── MethodLock.java │ ├── configuration │ └── MethodLockConfiguration.java │ └── interceptor │ └── MethodLockInterceptor.java ├── common-elasticsearch ├── pom.xml ├── pom.xml.versionsBackup └── src │ └── main │ └── java │ └── com │ └── yz │ └── elasticsearch │ ├── ESOpt.java │ └── ESSearch.java ├── common-pay ├── pom.xml ├── pom.xml.versionsBackup └── src │ └── main │ └── java │ └── com │ └── yz │ └── common │ ├── pay │ ├── bean │ │ ├── AliPayParams.java │ │ ├── AliRefundParams.java │ │ ├── AliRequestParams.java │ │ ├── RequestParams.java │ │ ├── WXCreateOrderParams.java │ │ ├── WXPayParams.java │ │ ├── WXRefundParams.java │ │ └── WXRequestParams.java │ ├── service │ │ ├── AliPay.java │ │ ├── IPay.java │ │ ├── PayFactory.java │ │ └── WXPay.java │ └── util │ │ ├── AlipayUtil.java │ │ └── WXPayUtil.java │ └── payment │ ├── AliPayServiceImpl.java │ ├── PayService.java │ ├── ThirdPayFactory.java │ ├── WXPayServiceImpl.java │ ├── config │ ├── AliPayConfig.java │ ├── PayConfig.java │ └── WXPayConfig.java │ ├── constants │ └── WXPayConstant.java │ ├── enums │ ├── PayChannelEnum.java │ ├── PayTypeEnum.java │ └── WXTradeState.java │ ├── order │ └── query │ │ ├── OrderQueryResponse.java │ │ └── WxOrderQueryResponse.java │ ├── trade │ └── pay │ │ ├── AliAppTradePayImpl.java │ │ ├── AliH5TradePayImpl.java │ │ ├── TradePay.java │ │ ├── WXJsApiTradePayImpl.java │ │ ├── WXTradeAppPayImpl.java │ │ ├── bo │ │ ├── AliTradePayResponse.java │ │ ├── TradePayResponse.java │ │ ├── UserOrder.java │ │ └── WXTradePayResponse.java │ │ ├── builder │ │ ├── AliTradePayBuilder.java │ │ ├── AliTradePayParamsBuilder.java │ │ ├── WXTradePayBuilder.java │ │ └── WXTradePayParamsBuilder.java │ │ └── params │ │ ├── AliTradeAppPayParams.java │ │ ├── AliTradeH5PayParams.java │ │ ├── AliTradePayParams.java │ │ ├── TradePayParams.java │ │ ├── WXTradeAppPayParams.java │ │ ├── WXTradeJsApiPayParams.java │ │ └── WXTradePayParams.java │ └── utils │ ├── WXPayUtil.java │ └── WXPayXmlUtil.java ├── common-security ├── pom.xml ├── pom.xml.versionsBackup └── src │ └── main │ └── java │ └── com │ └── yz │ └── common │ └── security │ ├── DES.java │ ├── ISecurity.java │ ├── RSA.java │ ├── RSA256.java │ ├── SHA.java │ └── aes │ ├── AES_CBC.java │ └── AES_ECB.java ├── common-web ├── pom.xml ├── pom.xml.versionsBackup └── src │ └── main │ └── java │ └── com │ └── yz │ └── common │ └── web │ ├── IHttpServletRequestWrapper.java │ ├── annotations │ ├── HttpParam.java │ └── ParamsValidate.java │ ├── controller │ └── ControllerAdviceHandler.java │ ├── filter │ ├── BaseFilter.java │ └── DataSafeFilter.java │ ├── http │ └── params │ │ └── validate │ │ ├── HttpParamsValidateAdvisor.java │ │ └── HttpRequestParamsValidateManager.java │ ├── springmvc │ └── interceptor │ │ └── BaseInterceptor.java │ └── utils │ └── WebUtil.java ├── common ├── pom.xml └── pom.xml.versionsBackup ├── pom.xml └── pom.xml.versionsBackup /JetBrains_Open_Source: -------------------------------------------------------------------------------- 1 | yangzhao_java@163.com 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # common-project 2 | 3 | Java后端常用工具类、缓存接口、消息队列接口、第三方支付接口封装;Restful接口参数验证,错误信息友好提示。 4 | 5 | [TOC] 6 | 7 | ## 1.分布式锁、分布式方法锁(common-distributed-lock): 8 | 9 | ### DistributedLock类(依赖RedisTemplate接口实现) 10 | ``` 11 | 12 | /** 13 | * 14 | * @param key 锁标识 15 | * @param attempt 重试次数 16 | * @return 17 | */ 18 | public boolean lock(String key,int attempt); 19 | 20 | /** 21 | * 22 | * @param key 锁标识 23 | * @param time 过期时间 24 | * @param timeUnit 过期时间单位 25 | * @param attemptNum 重试次数 26 | * @return 27 | */ 28 | public boolean lock(String key, long time, TimeUnit timeUnit,int attemptNum) 29 | ``` 30 | 31 | ### @EnableMethodLock @MethodLock 使用 32 | #### @EnableMethodLock 33 | 34 | **在Spring Boot 项目启动类添加该注解开启分布式方法锁** 35 | 36 | **普通Spring项目配置component-scan自动扫描com.yz.common.distributed.lock.configuration包即可** 37 | 38 | #### @MethodLock 39 | 40 | ``` 41 | @Target({ElementType.METHOD}) 42 | @Retention(RetentionPolicy.RUNTIME) 43 | @Documented 44 | public @interface MethodLock { 45 | /** 46 | * 锁标识 47 | * @return 48 | */ 49 | String key() default ""; 50 | 51 | /** 52 | * 时间 53 | * @return 54 | */ 55 | long time() default 10; 56 | 57 | /** 58 | * 单位 59 | * @return 60 | */ 61 | TimeUnit timeUnit() default TimeUnit.SECONDS; 62 | 63 | /** 64 | * 是否自动解锁 65 | * @return 66 | */ 67 | boolean autoUnLock() default true; 68 | 69 | /** 70 | * 重试次数 71 | * @return 72 | */ 73 | int attemptNum() default 0; 74 | 75 | } 76 | ``` 77 | 78 | 在需要使用分布式方法锁的method上使用该注解即可 79 | 80 | 81 | 82 | ## 2.ES(common-elasticsearch) 83 | 84 | ① ElasticSearch 增删改操作 85 | 86 | ② ElasticSearch 高级查询(链式调用) 87 | 88 | ## 3.常用工具类(common-core) 89 | 90 | 网络类(HttpUtil) 91 | 92 | 时间类(DateUtils) 93 | 94 | JSON类(JsonUtil) 95 | 96 | 安全类(MD5加密、AES加密、Base64编码、3DES加密、RSA加密、SHA256) 97 | 98 | 图片处理(GraphicsMagick) 99 | 100 | ... 101 | 102 | ## 4.Redis(common-redis) 103 | 104 | ①redis常用API接口(RedisUtil) 105 | 106 | ②基于redis实现分布式锁(RedisLockUtil) 107 | 108 | ## 5.支付模块(common-pay) 109 | 110 | ①使用简单工厂模式实现预支付订单生成(位于com.yz.common.payment.trade.pay包下) 111 | 112 | ![image.png](https://upload-images.jianshu.io/upload_images/3057341-77da3dce07ca5e42.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 113 | 114 | ②使用建造者模式对预支付订单参数进行动态构建(位于com.yz.common.payment.trade.pay.builder包下) 115 | 116 | ![image.png](https://upload-images.jianshu.io/upload_images/3057341-b31a5e2f5428a365.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 117 | 118 | ③通过ThirdPayFactory工厂类获取PayService 119 | 120 | ![image.png](https://upload-images.jianshu.io/upload_images/3057341-240fecbbe6264c28.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 121 | 122 | ④发起预支付订单、退款、订单查询调用 123 | 124 | ## 6.common-web 125 | 126 | ①请求参数转换(非Form表单或get+参数方式): 127 | 128 | 自定义web拦截器(DataSafeFilter),加密json数据解析为Map保存到HttpServletRequest 129 | 中;自定义HttpServletRequest包装类(IHttpServletRequestWrapper),将解析的Map数 130 | 据保存到Parameter中 131 | 132 | 133 | ②基于hibernate-validator restful接口参数验证 134 | -------------------------------------------------------------------------------- /common-cache/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | common-project 5 | com.yz 6 | 1.0.3 7 | 8 | 4.0.0 9 | 10 | common-cache 11 | jar 12 | 13 | common-cache 14 | http://maven.apache.org 15 | 16 | 17 | 18 | redis.clients 19 | jedis 20 | 21 | 22 | org.springframework.data 23 | spring-data-redis 24 | 25 | 26 | 27 | 28 | ${artifactId} 29 | 30 | 31 | -------------------------------------------------------------------------------- /common-cache/pom.xml.versionsBackup: -------------------------------------------------------------------------------- 1 | 3 | 4 | common-project 5 | com.yz 6 | 0.0.1-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | common-cache 11 | jar 12 | 13 | common-cache 14 | http://maven.apache.org 15 | 16 | 17 | 18 | 19 | com.yz 20 | common-core 21 | 0.0.1-SNAPSHOT 22 | 23 | 24 | 25 | org.springframework.data 26 | spring-data-redis 27 | 2.0.5.RELEASE 28 | 29 | 30 | 31 | 32 | 33 | ${artifactId} 34 | 35 | 36 | -------------------------------------------------------------------------------- /common-core/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | common-project 5 | com.yz 6 | 1.0.3 7 | 8 | 4.0.0 9 | 10 | common-core 11 | jar 12 | 13 | common-core 14 | http://maven.apache.org 15 | 16 | 17 | 18 | org.apache.httpcomponents 19 | httpclient 20 | 21 | 22 | 23 | org.apache.httpcomponents 24 | httpmime 25 | 26 | 27 | 28 | 29 | org.apache.solr 30 | solr-solrj 31 | 32 | 33 | 34 | 35 | org.apache.poi 36 | poi 37 | 38 | 39 | 40 | 41 | org.apache.poi 42 | poi-ooxml 43 | 44 | 45 | 46 | 47 | org.apache.poi 48 | poi-scratchpad 49 | 50 | 51 | 52 | 53 | org.apache.poi 54 | poi-ooxml-schemas 55 | 56 | 57 | 58 | com.fasterxml.jackson.core 59 | jackson-core 60 | 61 | 62 | com.fasterxml.jackson.core 63 | jackson-databind 64 | 65 | 66 | com.fasterxml.jackson.core 67 | jackson-annotations 68 | 69 | 70 | 71 | 72 | com.google.zxing 73 | core 74 | 75 | 76 | 77 | org.hibernate.validator 78 | hibernate-validator 79 | 80 | 81 | 82 | javax.validation 83 | validation-api 84 | 85 | 86 | 87 | org.javassist 88 | javassist 89 | 90 | 91 | org.dom4j 92 | dom4j 93 | 94 | 95 | 96 | 97 | ${artifactId} 98 | 99 | 100 | -------------------------------------------------------------------------------- /common-core/pom.xml.versionsBackup: -------------------------------------------------------------------------------- 1 | 3 | 4 | common-project 5 | com.yz 6 | 1.0.1 7 | 8 | 4.0.0 9 | 10 | common-core 11 | jar 12 | 13 | common-core 14 | http://maven.apache.org 15 | 16 | 17 | 18 | org.apache.httpcomponents 19 | httpclient 20 | 21 | 22 | 23 | org.apache.httpcomponents 24 | httpmime 25 | 26 | 27 | 28 | 29 | org.apache.solr 30 | solr-solrj 31 | 32 | 33 | 34 | 35 | org.apache.poi 36 | poi 37 | 38 | 39 | 40 | 41 | org.apache.poi 42 | poi-ooxml 43 | 44 | 45 | 46 | 47 | org.apache.poi 48 | poi-scratchpad 49 | 50 | 51 | 52 | 53 | org.apache.poi 54 | poi-ooxml-schemas 55 | 56 | 57 | 58 | com.fasterxml.jackson.core 59 | jackson-core 60 | 61 | 62 | com.fasterxml.jackson.core 63 | jackson-databind 64 | 65 | 66 | 67 | 68 | com.google.zxing 69 | core 70 | 71 | 72 | 73 | org.hibernate.validator 74 | hibernate-validator 75 | 76 | 77 | org.javassist 78 | javassist 79 | 80 | 81 | dom4j 82 | dom4j 83 | 84 | 85 | 86 | 87 | ${artifactId} 88 | 89 | 90 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/configuration/ValidatorConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.configuration; 2 | 3 | import org.hibernate.validator.HibernateValidator; 4 | 5 | import javax.validation.Validation; 6 | import javax.validation.Validator; 7 | import javax.validation.ValidatorFactory; 8 | 9 | /** 10 | * @author yangzhao 11 | * @Description 12 | * @Date create by 21:25 18/2/25 13 | */ 14 | public class ValidatorConfiguration { 15 | 16 | public static Validator validator(){ 17 | ValidatorFactory validatorFactory = Validation.byProvider( HibernateValidator.class ) 18 | .configure() 19 | .addProperty( "hibernate.validator.fail_fast", "true" ) 20 | .buildValidatorFactory(); 21 | Validator validator = validatorFactory.getValidator(); 22 | 23 | return validator; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/dao/BaseDao.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.dao; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author yangzhao 10 | * @Description 11 | * @Date create by 11:32 18/1/2 12 | */ 13 | public interface BaseDao { 14 | 15 | public final Logger logger = LoggerFactory.getLogger(BaseDao.class); 16 | 17 | boolean deleteByPrimaryKey(Long id); 18 | 19 | boolean insert(E e); 20 | 21 | boolean insertSelective(E e); 22 | 23 | E selectByPrimaryKey(Long id); 24 | 25 | boolean updateByPrimaryKeySelective(E e); 26 | 27 | boolean updateByPrimaryKey(E e); 28 | 29 | boolean insertList(List eList); 30 | 31 | public boolean deleteByIdList(Long[] ids); 32 | 33 | List select(E e); 34 | 35 | List selectByIdList(List idList); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/enums/CacheTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.enums; 2 | 3 | /** 4 | * Created by yangzhao on 18/1/17. 5 | */ 6 | public enum CacheTypeEnum { 7 | 8 | JVM(1),REDIS(2); 9 | 10 | private int type; 11 | 12 | private CacheTypeEnum(int type){ 13 | this.type = type; 14 | } 15 | 16 | public int getType(){ 17 | return this.type; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/enums/ErrorInfo.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.enums; 2 | 3 | /** 4 | * @author: yangzhao 5 | * @Date: 2020-01-05 13:57 6 | * @Description: 7 | */ 8 | public interface ErrorInfo { 9 | 10 | public int getErrorCode(); 11 | 12 | public String getErrorMsg(); 13 | } 14 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/enums/JsonTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.enums; 2 | 3 | /** 4 | * Created by yangzhao on 18/1/17. 5 | */ 6 | public enum JsonTypeEnum { 7 | 8 | FASTJSON(1),JACKSON(2); 9 | 10 | private int type; 11 | 12 | private JsonTypeEnum(int type){ 13 | this.type = type; 14 | } 15 | 16 | public int getType() { 17 | return type; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/enums/PayEnum.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.enums; 2 | 3 | /** 4 | * Created by yangzhao on 18/1/17. 5 | */ 6 | public enum PayEnum { 7 | 8 | WEIXIN(1),ALI(2); 9 | 10 | private int type; 11 | 12 | private PayEnum(int type){ 13 | this.type = type; 14 | } 15 | 16 | public int getType() { 17 | return type; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/exception/HandlerException.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.exception; 2 | 3 | import com.yz.common.core.enums.ErrorInfo; 4 | 5 | /** 6 | * Created by yangzhao on 17/3/29. 7 | */ 8 | public class HandlerException extends RuntimeException { 9 | 10 | private int code; 11 | 12 | public HandlerException(int code, String message) { 13 | super(String.valueOf(message)); 14 | this.code = code; 15 | } 16 | 17 | public HandlerException(ErrorInfo errorInfo) { 18 | super(String.valueOf(errorInfo.getErrorMsg())); 19 | this.code = errorInfo.getErrorCode(); 20 | } 21 | 22 | public HandlerException(String message) { 23 | super(String.valueOf(message)); 24 | } 25 | 26 | public String getErrorInfo() { 27 | return super.getMessage(); 28 | } 29 | 30 | public int getCode() { 31 | return code; 32 | } 33 | 34 | public void setCode(int code) { 35 | this.code = code; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/file/dowload/FileDownload.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.file.dowload; 2 | 3 | import org.apache.http.HttpEntity; 4 | import org.apache.http.HttpResponse; 5 | import org.apache.http.client.HttpClient; 6 | import org.apache.http.client.methods.HttpGet; 7 | import org.apache.http.impl.client.HttpClients; 8 | 9 | import java.io.*; 10 | import java.util.Date; 11 | import java.util.Timer; 12 | import java.util.TimerTask; 13 | import java.util.concurrent.CountDownLatch; 14 | 15 | /** 16 | * @author: yangzhao 17 | * @Date: 2019/7/28 22:34 18 | * @Description: 19 | */ 20 | public class FileDownload implements Runnable { 21 | 22 | public static final CountDownLatch countDownLatch =new CountDownLatch(1); 23 | 24 | private long fileSize; 25 | 26 | private String fileUrl; 27 | 28 | private String fileSavePath; 29 | /** 30 | * 已下载文件大小 31 | */ 32 | private long downloadFileSize=0; 33 | 34 | private FileDownloadProgress fileDownloadProgress; 35 | 36 | public FileDownload(long fileSize, String fileUrl, String fileSavePath){ 37 | this.fileSize=fileSize; 38 | this.fileUrl=fileUrl; 39 | this.fileSavePath=fileSavePath; 40 | } 41 | 42 | public FileDownload(long fileSize, String fileUrl, String fileSavePath, FileDownloadProgress fileDownloadProgress){ 43 | this.fileSize=fileSize; 44 | this.fileUrl=fileUrl; 45 | this.fileSavePath=fileSavePath; 46 | this.fileDownloadProgress=fileDownloadProgress; 47 | } 48 | 49 | @Override 50 | public void run() { 51 | HttpClient httpClient = HttpClients.createDefault(); 52 | OutputStream out = null; 53 | InputStream in = null; 54 | Timer timer = new Timer(); 55 | try { 56 | HttpGet httpGet = new HttpGet(this.fileUrl); 57 | HttpResponse httpResponse = httpClient.execute(httpGet); 58 | HttpEntity entity = httpResponse.getEntity(); 59 | in = entity.getContent(); 60 | long length = entity.getContentLength(); 61 | if (length <= 0) { 62 | System.out.println("下载文件不存在!"); 63 | return; 64 | } 65 | 66 | File file = new File(this.fileSavePath); 67 | if(!file.exists()){ 68 | file.createNewFile(); 69 | } 70 | out = new FileOutputStream(file); 71 | byte[] buffer = new byte[4096]; 72 | int readLength = 0; 73 | timer.scheduleAtFixedRate(new TimerTask() { 74 | public void run() { 75 | if (fileDownloadProgress!=null){ 76 | //回调进度信息 77 | fileDownloadProgress.progressCallBack(fileSize,downloadFileSize); 78 | } 79 | } 80 | }, new Date(),2000); 81 | while ((readLength=in.read(buffer)) > 0) { 82 | byte[] bytes = new byte[readLength]; 83 | System.arraycopy(buffer, 0, bytes, 0, readLength); 84 | downloadFileSize+=bytes.length; 85 | out.write(bytes); 86 | } 87 | out.flush(); 88 | if (fileDownloadProgress!=null){ 89 | //回调进度信息 90 | fileDownloadProgress.finish(fileSavePath); 91 | } 92 | } catch (Exception e) { 93 | e.printStackTrace(); 94 | }finally{ 95 | try { 96 | if(in != null){ 97 | in.close(); 98 | } 99 | } catch (IOException e) { 100 | e.printStackTrace(); 101 | } 102 | 103 | try { 104 | if(out != null){ 105 | out.close(); 106 | } 107 | } catch (IOException e) { 108 | e.printStackTrace(); 109 | } 110 | if (countDownLatch!=null){ 111 | countDownLatch.countDown(); 112 | } 113 | timer.cancel(); 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/file/dowload/FileDownloadManager.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.file.dowload; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.io.IOException; 7 | import java.net.HttpURLConnection; 8 | import java.net.URL; 9 | 10 | /** 11 | * @author: yangzhao 12 | * @Date: 2019/7/28 22:27 13 | * @Description: 14 | */ 15 | public class FileDownloadManager { 16 | 17 | private static final Logger logger = LoggerFactory.getLogger(FileDownloadManager.class); 18 | 19 | /** 20 | * 获取远程文件大小 21 | */ 22 | public static long getRemoteFileSize(String remoteFileUrl) throws IOException { 23 | long fileSize = 0; 24 | HttpURLConnection httpConnection = (HttpURLConnection) new URL(remoteFileUrl).openConnection(); 25 | httpConnection.setRequestMethod("HEAD"); 26 | int responseCode = httpConnection.getResponseCode(); 27 | if (responseCode >= 400) { 28 | logger.debug("Web服务器响应错误!"); 29 | return 0; 30 | } 31 | String sHeader; 32 | for (int i = 1; ; i++) { 33 | sHeader = httpConnection.getHeaderFieldKey(i); 34 | if (sHeader != null && sHeader.equals("Content-Length")) { 35 | logger.info("文件大小ContentLength:"+ httpConnection.getContentLength()); 36 | fileSize = Long.parseLong(httpConnection.getHeaderField(sHeader)); 37 | break; 38 | } 39 | 40 | } 41 | return fileSize; 42 | } 43 | 44 | /** 45 | * 同步下载文件 46 | * @param url 47 | * @param savePath 48 | * @throws Exception 49 | */ 50 | public static void syncDownload(String url,String savePath) throws Exception { 51 | long remoteFileSize = getRemoteFileSize(url); 52 | FileDownload fileDownload = new FileDownload(remoteFileSize, url, savePath); 53 | Thread thread=new Thread(fileDownload); 54 | thread.start(); 55 | FileDownload.countDownLatch.await(); 56 | } 57 | 58 | /** 59 | * 同步下载文件(回调) 60 | * @param url 61 | * @param savePath 62 | * @param fileDownloadProgress 63 | * @throws Exception 64 | */ 65 | public static void syncDownload(String url,String savePath,FileDownloadProgress fileDownloadProgress) throws Exception { 66 | long remoteFileSize = getRemoteFileSize(url); 67 | FileDownload fileDownload = new FileDownload(remoteFileSize, url, savePath,fileDownloadProgress); 68 | Thread thread=new Thread(fileDownload); 69 | thread.start(); 70 | FileDownload.countDownLatch.await(); 71 | } 72 | 73 | /** 74 | * 异步下载文件 75 | * @param url 76 | * @param savePath 77 | * @throws Exception 78 | */ 79 | public static void asyncDownload(String url,String savePath) throws Exception { 80 | long remoteFileSize = getRemoteFileSize(url); 81 | FileDownload fileDownload = new FileDownload(remoteFileSize, url, savePath); 82 | Thread thread=new Thread(fileDownload); 83 | thread.start(); 84 | } 85 | 86 | /** 87 | * 异步下载文件(回调) 88 | * @param url 89 | * @param savePath 90 | * @param fileDownloadProgress 91 | * @throws Exception 92 | */ 93 | public static void asyncDownload(String url,String savePath,FileDownloadProgress fileDownloadProgress) throws Exception { 94 | long remoteFileSize = getRemoteFileSize(url); 95 | FileDownload fileDownload = new FileDownload(remoteFileSize, url, savePath,fileDownloadProgress); 96 | Thread thread=new Thread(fileDownload); 97 | thread.start(); 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/file/dowload/FileDownloadProgress.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.file.dowload; 2 | 3 | /** 4 | * @author: yangzhao 5 | * @Date: 2019/7/28 22:42 6 | * @Description: 7 | */ 8 | public interface FileDownloadProgress { 9 | /** 10 | * 进度回调 11 | * @param fileSize 12 | * @param currentFileSize 13 | */ 14 | public void progressCallBack(long fileSize,long currentFileSize); 15 | 16 | /** 17 | * 完成下载 18 | * @param filePath 19 | */ 20 | public void finish(String filePath); 21 | } 22 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/json/FastJson.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.json; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 阿里巴巴fastjson 9 | * 10 | * @auther yangzhao 11 | * create by 17/10/9 12 | */ 13 | public class FastJson implements IJsonInterface { 14 | @Override 15 | public T parseObject(String json, Class t) { 16 | T t1 = JSON.parseObject(json, t); 17 | return t1; 18 | } 19 | 20 | @Override 21 | public List parseList(String json, Class t) { 22 | List tList = JSON.parseArray(json, t); 23 | return tList; 24 | } 25 | 26 | @Override 27 | public String toJsonString(Object obj) { 28 | return JSON.toJSONString(obj); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/json/IJsonInterface.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.json; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * json接口 7 | * 8 | * @auther yangzhao 9 | * create by 17/10/9 10 | */ 11 | public interface IJsonInterface { 12 | 13 | public T parseObject(String json,Class t); 14 | 15 | public List parseList(String json, Class t); 16 | 17 | public String toJsonString(Object obj); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/json/JSON.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.json; 2 | 3 | 4 | /** 5 | * json装饰类 6 | * 7 | * @auther yangzhao 8 | * create by 17/10/9 9 | */ 10 | public final class JSON { 11 | 12 | private static IJsonInterface jsonInterface; 13 | 14 | public static void init(int type){ 15 | switch (type){ 16 | case 1: 17 | jsonInterface = new FastJson(); 18 | break; 19 | case 2: 20 | jsonInterface = new Jackson(); 21 | break; 22 | default: 23 | jsonInterface=new FastJson(); 24 | } 25 | } 26 | 27 | public static IJsonInterface getInterface(){ 28 | if (jsonInterface==null){ 29 | throw new RuntimeException("jsonInterface接口==null,请预先实例化该工具类"); 30 | } 31 | return jsonInterface; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/json/Jackson.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.json; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | import com.fasterxml.jackson.core.JsonGenerator; 5 | import com.fasterxml.jackson.core.JsonParser; 6 | import com.fasterxml.jackson.core.JsonProcessingException; 7 | import com.fasterxml.jackson.databind.*; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.io.IOException; 12 | import java.util.ArrayList; 13 | import java.util.Collection; 14 | import java.util.List; 15 | 16 | /** 17 | * jackson 18 | * 19 | * @auther yangzhao 20 | * create by 17/10/9 21 | */ 22 | public class Jackson implements IJsonInterface { 23 | 24 | private static final Logger logger= LoggerFactory.getLogger(Jackson.class); 25 | 26 | @Override 27 | public T parseObject(String json, Class t) { 28 | try { 29 | return objectMapper.readValue(json, t); 30 | } catch (Exception e) { 31 | logger.error("JSON字符串转对象失败 ----", e); 32 | } 33 | return null; 34 | } 35 | 36 | @Override 37 | public List parseList(String json, Class t) { 38 | try { 39 | Collection collection = this.parse(json, ArrayList.class, t); 40 | return (List) collection; 41 | } catch (IOException e) { 42 | e.printStackTrace(); 43 | } 44 | return null; 45 | } 46 | 47 | @Override 48 | public String toJsonString(Object obj) { 49 | try { 50 | return objectMapper.writeValueAsString(obj); 51 | } catch (Exception e) { 52 | logger.error(e.getMessage(), e); 53 | } 54 | return null; 55 | } 56 | 57 | private ObjectMapper objectMapper = new ObjectMapper(); 58 | 59 | public Jackson() { 60 | //不允许出现特殊字符和转义符 61 | objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true) ; 62 | //支持单引号 63 | objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); 64 | // 设置输出时包含属性的风格 65 | objectMapper.configure(MapperFeature.USE_ANNOTATIONS, false); 66 | 67 | objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true); 68 | //jackson 实体转json为NULL或者为空不参加序列化 69 | objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); 70 | 71 | //jackson实体转json为null时修改null值为"" 72 | objectMapper.getSerializerProvider().setNullValueSerializer(new JsonSerializer() { 73 | @Override 74 | public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { 75 | jsonGenerator.writeString(""); 76 | } 77 | }); 78 | } 79 | 80 | /** 81 | * 获取泛型的Collection Type 82 | * @param collectionClass 83 | * @param elementClasses 84 | * @return 85 | */ 86 | @SuppressWarnings("deprecation") 87 | public JavaType getCollectionType(Class collectionClass, Class... elementClasses) { 88 | return objectMapper.getTypeFactory().constructParametricType(collectionClass, elementClasses); 89 | } 90 | 91 | /** 92 | * 泛型反序列化 ,如List,Map 93 | * @param json 94 | * @param collectionClass 95 | * @param clazz 96 | * @return 97 | * @throws Exception 98 | */ 99 | @SuppressWarnings("rawtypes") 100 | public Collection parse(String json, Class collectionClass, Class clazz) throws IOException { 101 | JavaType javaType = getCollectionType(collectionClass, clazz); 102 | return objectMapper.readValue(json, javaType); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/json/JacksonUtil.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.json; 2 | 3 | import java.io.IOException; 4 | import java.util.Collection; 5 | import com.fasterxml.jackson.core.JsonGenerator; 6 | import com.fasterxml.jackson.core.JsonProcessingException; 7 | import com.fasterxml.jackson.databind.*; 8 | import com.fasterxml.jackson.core.JsonParser.Feature; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | /** 13 | * json工具类 14 | * @author yangzhao 2015年10月28日 15 | */ 16 | public class JacksonUtil { 17 | 18 | private static final Logger logger= LoggerFactory.getLogger(JacksonUtil.class); 19 | 20 | private static ObjectMapper objectMapper = new ObjectMapper(); 21 | 22 | static { 23 | //不允许出现特殊字符和转义符 24 | objectMapper.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true) ; 25 | //支持单引号 26 | objectMapper.configure(Feature.ALLOW_SINGLE_QUOTES, true); 27 | // 设置输出时包含属性的风格 28 | objectMapper.configure(MapperFeature.USE_ANNOTATIONS, false); 29 | 30 | objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true); 31 | //jackson 实体转json为NULL或者为空不参加序列化 32 | // objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); 33 | 34 | //jackson实体转json为null时修改null值为"" 35 | objectMapper.getSerializerProvider().setNullValueSerializer(new JsonSerializer() { 36 | @Override 37 | public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { 38 | jsonGenerator.writeString(""); 39 | } 40 | }); 41 | } 42 | 43 | /** 44 | * JSON字符串转对象 45 | * @param json 46 | * @param valueType 47 | * @return 48 | */ 49 | public static T parse(String json, Class valueType) { 50 | 51 | try { 52 | return objectMapper.readValue(json, valueType); 53 | } catch (Exception e) { 54 | logger.error("JSON字符串转对象失败 ----", e); 55 | } 56 | return null; 57 | } 58 | 59 | /** 60 | * 对象转json字符串 61 | * @param obj 62 | * @return 63 | */ 64 | public static String parse(Object obj) { 65 | try { 66 | return objectMapper.writeValueAsString(obj); 67 | } catch (Exception e) { 68 | logger.error(e.getMessage(), e); 69 | } 70 | return null; 71 | } 72 | 73 | /** 74 | * 获取泛型的Collection Type 75 | * @param collectionClass 76 | * @param elementClasses 77 | * @return 78 | */ 79 | @SuppressWarnings("deprecation") 80 | public static JavaType getCollectionType(Class collectionClass, Class... elementClasses) { 81 | return objectMapper.getTypeFactory().constructParametricType(collectionClass, elementClasses); 82 | } 83 | 84 | /** 85 | * 泛型反序列化 ,如List,Map 86 | * @param json 87 | * @param collectionClass 88 | * @param clazz 89 | * @return 90 | * @throws Exception 91 | */ 92 | @SuppressWarnings("rawtypes") 93 | public static Collection parse(String json, Class collectionClass, Class clazz) { 94 | JavaType javaType = getCollectionType(collectionClass, clazz); 95 | try { 96 | return objectMapper.readValue(json, javaType); 97 | } catch (IOException e) { 98 | e.printStackTrace(); 99 | } 100 | return null; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/message/ResponseMessage.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.message; 2 | 3 | /** 4 | * http请求返回消息 5 | * Created by yangzhao on 17/7/7. 6 | */ 7 | public class ResponseMessage { 8 | 9 | public ResponseMessage() {} 10 | 11 | public ResponseMessage(int code, int errorCode, Object data, String errorMessage) { 12 | this.code = code; 13 | this.errorCode = errorCode; 14 | this.data = data; 15 | this.errorMessage = errorMessage; 16 | } 17 | 18 | public ResponseMessage(int code) { 19 | this.code = code; 20 | } 21 | 22 | /** 23 | * 构造函数 24 | * @param data 正确返回数据 25 | */ 26 | public ResponseMessage(Object data) { 27 | this.data = data; 28 | } 29 | 30 | /** 31 | * 构造函数 32 | * @param errorCode 错误状态码 33 | * @param errorMessage 错误信息 34 | */ 35 | public ResponseMessage(int errorCode, String errorMessage) { 36 | this.errorCode=errorCode; 37 | this.errorMessage = errorMessage; 38 | } 39 | 40 | private int code = 200; 41 | 42 | private int errorCode; 43 | 44 | private Object data; 45 | 46 | private String errorMessage; 47 | 48 | public void setCode(int code) { 49 | this.code = code; 50 | } 51 | 52 | public int getCode() { 53 | return code; 54 | } 55 | 56 | public int getErrorCode() { 57 | return errorCode; 58 | } 59 | 60 | public void setErrorCode(int errorCode) { 61 | this.errorCode = errorCode; 62 | } 63 | 64 | public Object getData() { 65 | return data; 66 | } 67 | 68 | public void setData(Object data) { 69 | this.data = data; 70 | } 71 | 72 | public String getErrorMessage() { 73 | return errorMessage; 74 | } 75 | 76 | public void setErrorMessage(String errorMessage) { 77 | this.errorMessage = errorMessage; 78 | } 79 | 80 | /** 81 | * 成功 无返回数据 82 | * @return 83 | */ 84 | public static ResponseMessage success(){ 85 | return new ResponseMessage(); 86 | } 87 | 88 | /** 89 | * 成功 90 | * @param data 返回数据 91 | * @return 92 | */ 93 | public static ResponseMessage success(Object data){ 94 | return new ResponseMessage(data); 95 | } 96 | 97 | /** 98 | * 失败 99 | * @param errorCode 错误码 100 | * @param errorMessage 错误信息 101 | * @return 102 | */ 103 | public static ResponseMessage error(int code,int errorCode,String errorMessage){ 104 | ResponseMessage responseMessage = new ResponseMessage(); 105 | responseMessage.setCode(code); 106 | responseMessage.setErrorCode(errorCode); 107 | responseMessage.setErrorMessage(errorMessage); 108 | return responseMessage; 109 | } 110 | /** 111 | * 失败 112 | * @param errorCode 错误码 113 | * @param errorInfo 错误信息 114 | * @return 115 | */ 116 | public static ResponseMessage error(int errorCode,String errorInfo){ 117 | return new ResponseMessage(errorCode,errorInfo); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/model/Page.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.model; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 分页模型 7 | * @author yangzhao 8 | * @Date create by 22:59 18/9/19 9 | */ 10 | public class Page { 11 | /** 12 | * 当前页 13 | */ 14 | private int currentPage; 15 | /** 16 | * 每页显示数量 17 | */ 18 | private int pageSize; 19 | /** 20 | * 总页数 21 | */ 22 | private long totalPage; 23 | /** 24 | * 分页数据 25 | */ 26 | private List dataList; 27 | 28 | public Page(){} 29 | 30 | public Page(int currentPage, int pageSize) { 31 | this.currentPage = currentPage; 32 | this.pageSize = pageSize; 33 | } 34 | 35 | public int getCurrentPage() { 36 | return currentPage; 37 | } 38 | 39 | public void setCurrentPage(int currentPage) { 40 | this.currentPage = currentPage; 41 | } 42 | 43 | public int getPageSize() { 44 | return pageSize; 45 | } 46 | 47 | public void setPageSize(int pageSize) { 48 | this.pageSize = pageSize; 49 | } 50 | 51 | public long getTotalPage() { 52 | return totalPage; 53 | } 54 | 55 | public void setTotalPage(long totalPage) { 56 | this.totalPage = totalPage; 57 | } 58 | 59 | public List getDataList() { 60 | return dataList; 61 | } 62 | 63 | public void setDataList(List dataList) { 64 | this.dataList = dataList; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/service/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.service; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author yangzhao 10 | * @Description 11 | * @Date create by 11:15 18/1/2 12 | */ 13 | public interface BaseService { 14 | 15 | public final Logger logger = LoggerFactory.getLogger(BaseService.class); 16 | 17 | /** 18 | * 添加 19 | * 20 | * @param e 21 | * @return 22 | */ 23 | public boolean insert(E e); 24 | 25 | /** 26 | * 删除 27 | * 28 | * @param id 29 | * @return 30 | */ 31 | public boolean deleteById(Long id); 32 | 33 | /** 34 | * 批量删除 35 | * 36 | * @param ids 37 | * @return 38 | */ 39 | public boolean deleteByIdList(Long[] ids); 40 | 41 | /** 42 | * 修改 43 | * 44 | * @param e 45 | * @return 46 | */ 47 | public boolean update(E e); 48 | 49 | /** 50 | * 查询一条记录 51 | * 52 | * @param e 53 | * @return 54 | */ 55 | public E selectOne(E e); 56 | 57 | /** 58 | * 根据ID查询一条记录 59 | * 60 | * @param id 61 | * @return 62 | */ 63 | public E selectById(Long id); 64 | 65 | /** 66 | * 分页查询 67 | * 68 | * @param e 69 | * @return 70 | */ 71 | public List selectPageList(E e, int pageIndex, int pageSize); 72 | 73 | /** 74 | * 根据条件查询所有 75 | * @return 76 | */ 77 | public List selectList(E e); 78 | 79 | /** 80 | * 批量添加 81 | * @param list 82 | * @return 83 | */ 84 | public boolean insertList(List list); 85 | 86 | /** 87 | * 通过ID获取 88 | * @param idList 89 | * @return 90 | */ 91 | public List selectListByIdList(List idList); 92 | } 93 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/service/BaseServiceManager.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.service; 2 | 3 | import com.yz.common.core.dao.BaseDao; 4 | import org.apache.commons.collections4.CollectionUtils; 5 | import java.util.List; 6 | 7 | /** 8 | * @author yangzhao 9 | * @Description 10 | * @Date create by 11:29 18/1/2 11 | */ 12 | public abstract class BaseServiceManager implements BaseService{ 13 | 14 | public DAO dao; 15 | 16 | public DAO getDao() { 17 | return dao; 18 | } 19 | 20 | public abstract void setDao(DAO dao); 21 | 22 | /** 23 | * 添加 24 | * 25 | * @param e 26 | * @return 27 | */ 28 | @Override 29 | public boolean insert(E e) { 30 | if(e==null){ 31 | throw new NullPointerException(); 32 | } 33 | return dao.insertSelective(e); 34 | } 35 | 36 | /** 37 | * 批量添加 38 | * @param list 39 | * @return 40 | */ 41 | @Override 42 | public boolean insertList(List list) { 43 | boolean b = dao.insertList(list); 44 | return b; 45 | } 46 | 47 | /** 48 | * 删除 49 | * 50 | * @param id 51 | * @return 52 | */ 53 | @Override 54 | public boolean deleteById(Long id) { 55 | return dao.deleteByPrimaryKey(id); 56 | } 57 | 58 | @Override 59 | public boolean deleteByIdList(Long[] ids) { 60 | boolean b = dao.deleteByIdList(ids); 61 | return b; 62 | } 63 | 64 | /** 65 | * 修改 66 | * 67 | * @param e 68 | * @return 69 | */ 70 | @Override 71 | public boolean update(E e) { 72 | if(e==null){ 73 | throw new NullPointerException(); 74 | } 75 | return dao.updateByPrimaryKeySelective(e); 76 | } 77 | 78 | /** 79 | * 查询一条记录 80 | * 81 | * @param e 82 | * @return 83 | */ 84 | @Override 85 | public E selectOne(E e) { 86 | List select = dao.select(e); 87 | if (CollectionUtils.isEmpty(select)){ 88 | return null; 89 | } 90 | return select.get(0); 91 | } 92 | 93 | /** 94 | * 分页查询 95 | * 96 | * @param e 97 | * @return 98 | */ 99 | @Override 100 | public abstract List selectPageList(E e, int pageIndex, int pageSize); 101 | 102 | @Override 103 | public List selectList(E e) { 104 | return dao.select(e); 105 | } 106 | 107 | @Override 108 | public E selectById(Long id) { 109 | E o = (E) dao.selectByPrimaryKey(id); 110 | return o; 111 | } 112 | 113 | @Override 114 | public List selectListByIdList(List idList) { 115 | return dao.selectByIdList(idList); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/AioOperation.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | import java.nio.ByteBuffer; 4 | import java.nio.channels.AsynchronousFileChannel; 5 | import java.nio.channels.CompletionHandler; 6 | import java.nio.file.Path; 7 | import java.nio.file.Paths; 8 | 9 | public class AioOperation { 10 | public static byte[] readFile() throws Exception { 11 | Path path = Paths.get("e:\\1.txt"); 12 | AsynchronousFileChannel asynchronousFileChannel = AsynchronousFileChannel.open(path); 13 | final ByteBuffer buffer = ByteBuffer.allocate(1024 * 10); 14 | asynchronousFileChannel.read(buffer, 0, "", new CompletionHandler() { 15 | 16 | @Override 17 | public void completed(Integer result, Object attachment) { 18 | System.out.println("读取成功!"); 19 | } 20 | 21 | @Override 22 | public void failed(Throwable exc, Object attachment) { 23 | // TODO Auto-generated method stub 24 | 25 | } 26 | }); 27 | Thread.sleep(1000); 28 | return buffer.array(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/BeanUtil.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | import java.beans.BeanInfo; 4 | import java.beans.Introspector; 5 | import java.beans.PropertyDescriptor; 6 | import java.lang.reflect.Method; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | /** 11 | * @Auther: yangzhao 12 | * @Date: 2019/4/2 18:35 13 | * @Description: 14 | */ 15 | public class BeanUtil { 16 | 17 | public static Map beanToMap(Object object){ 18 | if(object == null){ 19 | return null; 20 | } 21 | Map map = new HashMap(); 22 | try { 23 | BeanInfo beanInfo = Introspector.getBeanInfo(object.getClass()); 24 | PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); 25 | for (PropertyDescriptor property : propertyDescriptors) { 26 | String key = property.getName(); 27 | // 过滤class属性 28 | if (!key.equals("class")) { 29 | // 得到property对应的getter方法 30 | Method getter = property.getReadMethod(); 31 | Object value = getter.invoke(object); 32 | map.put(key, value); 33 | } 34 | 35 | } 36 | } catch (Exception e) { 37 | e.printStackTrace(); 38 | } 39 | 40 | return map; 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/ClassLocationUtils.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | import java.io.File; 4 | import java.net.MalformedURLException; 5 | import java.net.URL; 6 | import java.security.CodeSource; 7 | import java.security.ProtectionDomain; 8 | 9 | /** 10 | * @author: yangzhao 11 | * @Date: 2019/9/17 11:18 12 | * @Description: 13 | */ 14 | public class ClassLocationUtils { 15 | 16 | public static String where(final Class clazz) { 17 | if (clazz == null) { 18 | throw new IllegalArgumentException("null input: cls"); 19 | } 20 | URL result = null; 21 | final String clazzAsResource = clazz.getName().replace('.', '/').concat(".class"); 22 | final ProtectionDomain protectionDomain = clazz.getProtectionDomain(); 23 | if (protectionDomain != null) { 24 | final CodeSource codeSource = protectionDomain.getCodeSource(); 25 | if (codeSource != null) { 26 | result = codeSource.getLocation(); 27 | } 28 | if (result != null) { 29 | if ("file".equals(result.getProtocol())) { 30 | try { 31 | if (result.toExternalForm().endsWith(".jar") || result.toExternalForm().endsWith(".zip")) { 32 | result = new URL("jar:".concat(result.toExternalForm()).concat("!/").concat(clazzAsResource)); 33 | } else if (new File(result.getFile()).isDirectory()) { 34 | result = new URL(result, clazzAsResource); 35 | } 36 | } catch (MalformedURLException ignore) { 37 | 38 | } 39 | } 40 | } 41 | } 42 | if (result == null) { 43 | final ClassLoader clsLoader = clazz.getClassLoader(); 44 | result = clsLoader != null ? clsLoader.getResource(clazzAsResource) : ClassLoader.getSystemResource(clazzAsResource); 45 | } 46 | return result.toString(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/CommandUtil.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStream; 5 | import java.io.InputStreamReader; 6 | 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | /** 11 | * @author: yangzhao 12 | * @Date: 2020-01-09 12:55 13 | * @Description: 14 | */ 15 | public class CommandUtil { 16 | 17 | private static final Logger logger = LoggerFactory.getLogger(CommandUtil.class); 18 | 19 | public static String exec(String[] cmd) throws Exception { 20 | Process exec = Runtime.getRuntime().exec(cmd); 21 | exec.waitFor(); 22 | InputStream inputStream = exec.getInputStream(); 23 | BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); 24 | String readLine; 25 | StringBuilder resultBuilder = new StringBuilder(); 26 | while ((readLine = br.readLine()) != null) { 27 | resultBuilder.append(readLine); 28 | } 29 | logger.info("command result is " + resultBuilder.toString()); 30 | return resultBuilder.toString(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/DataCompressUtil.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.IOException; 5 | import java.util.zip.Deflater; 6 | import java.util.zip.Inflater; 7 | 8 | public class DataCompressUtil { 9 | /** 10 | * 压缩 11 | * 12 | * @param data 13 | * 待压缩数据 14 | * @return byte[] 压缩后的数据 15 | */ 16 | public static byte[] compress(byte[] data) { 17 | byte[] output = new byte[0]; 18 | 19 | Deflater compresser = new Deflater(); 20 | 21 | compresser.reset(); 22 | compresser.setInput(data); 23 | compresser.finish(); 24 | ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length); 25 | try { 26 | byte[] buf = new byte[1024]; 27 | while (!compresser.finished()) { 28 | int i = compresser.deflate(buf); 29 | bos.write(buf, 0, i); 30 | } 31 | output = bos.toByteArray(); 32 | } catch (Exception e) { 33 | output = data; 34 | e.printStackTrace(); 35 | } finally { 36 | try { 37 | bos.close(); 38 | } catch (IOException e) { 39 | e.printStackTrace(); 40 | } 41 | } 42 | compresser.end(); 43 | return output; 44 | } 45 | 46 | /** 47 | * 解压缩 48 | * 49 | * @param data 50 | * 待压缩的数据 51 | * @return byte[] 解压缩后的数据 52 | */ 53 | public static byte[] dedcompress(byte[] data) { 54 | byte[] output = new byte[0]; 55 | Inflater decompresser = new Inflater(); 56 | decompresser.reset(); 57 | decompresser.setInput(data); 58 | ByteArrayOutputStream o = new ByteArrayOutputStream(data.length); 59 | try { 60 | byte[] buf = new byte[1024]; 61 | while (!decompresser.finished()) { 62 | int i = decompresser.inflate(buf); 63 | o.write(buf, 0, i); 64 | } 65 | output = o.toByteArray(); 66 | } catch (Exception e) { 67 | output = data; 68 | e.printStackTrace(); 69 | } finally { 70 | try { 71 | o.close(); 72 | } catch (IOException e) { 73 | e.printStackTrace(); 74 | } 75 | } 76 | decompresser.end(); 77 | return output; 78 | } 79 | /** 80 | * 解压缩 81 | * 82 | * @param data 83 | * 待压缩的数据 84 | * @return byte[] 解压缩后的数据 85 | */ 86 | public static byte[] dedcompressTest(byte[] data) { 87 | byte[] output = new byte[0]; 88 | Inflater decompresser = new Inflater(); 89 | decompresser.reset(); 90 | decompresser.setInput(data); 91 | ByteArrayOutputStream o = new ByteArrayOutputStream(data.length); 92 | try { 93 | byte[] buf = new byte[1024]; 94 | while (!decompresser.finished()) { 95 | int i = decompresser.inflate(buf); 96 | o.write(buf, 0, i); 97 | } 98 | output = o.toByteArray(); 99 | } catch (Exception e) { 100 | output = data; 101 | e.printStackTrace(); 102 | } finally { 103 | try { 104 | o.close(); 105 | } catch (IOException e) { 106 | e.printStackTrace(); 107 | } 108 | } 109 | decompresser.end(); 110 | return output; 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/EncryptUtil.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | /** 6 | * 数据包的发送与接收都需要进行异或 7 | * @author yangzhao 2015年10月17日 8 | */ 9 | public class EncryptUtil { 10 | /** 11 | * 加密钥匙 12 | */ 13 | public static final int MAX_BUFFER = 1024; 14 | public static final byte BUFFER[] = new byte[MAX_BUFFER]; 15 | 16 | /** 17 | * 加密 18 | * @param source 要加密的数据 19 | * @param key 加密密钥 20 | * @return 21 | */ 22 | public static byte[] encrypt(byte[] source, String key) { 23 | if (source == null) { 24 | return null; 25 | } 26 | int keyLength = key.length(); 27 | int length = source.length; 28 | ByteBuffer ba = ByteBuffer.allocate(length); 29 | for (int i = 0; i < length; i++) { 30 | ba.put((byte) (source[i] ^ (byte) key.charAt(i % keyLength))); 31 | } 32 | return ba.array(); 33 | } 34 | 35 | /** 36 | * 解密 37 | * @param source 要解密的数据 38 | * @param offset 从第几位开始进行解密 39 | * @param length 解密多少位 40 | * @param key 解密密钥 41 | * @return 42 | */ 43 | public static byte[] decrypt(byte[] source, int offset, int length, String key) { 44 | int keyLength = key.length(); 45 | ByteBuffer ba = ByteBuffer.allocate(length); 46 | length = length + offset; 47 | for (int i = offset; i < length; i++) { 48 | ba.put((byte) (source[i] ^ (byte) key.charAt((i - offset) % keyLength))); 49 | } 50 | return ba.array(); 51 | } 52 | 53 | /** 54 | * 解密 55 | * @param source 要解密的数据 56 | * @param key 解密密钥 57 | * @return 58 | */ 59 | public static byte[] decrypt(byte[] source, String key) { 60 | if (source == null) { 61 | return null; 62 | } 63 | int offset = 0; 64 | int length = source.length; 65 | return decrypt(source, offset, length, key); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/FileUploadUtil.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | import java.io.File; 4 | import java.io.FileOutputStream; 5 | import java.io.OutputStream; 6 | import java.util.Arrays; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | 11 | public class FileUploadUtil { 12 | private static final Logger logger= LoggerFactory.getLogger(FileUploadUtil.class); 13 | 14 | private static final String[] FILE_EXTS = { "JPG", "PNG", "GIF" }; 15 | 16 | private static final byte[][] FILE_MAGS = new byte[][] { new byte[] { (byte) 0xFF, (byte) 0xD8, (byte) 0xFF, (byte) 0xE0 }, // JPG 17 | new byte[] { (byte) 0x89, (byte) 0x50, (byte) 0x4E, (byte) 0x47 }, // PNG 18 | new byte[] { (byte) 0x47, (byte) 0x49, (byte) 0x46, (byte) 0x38 } // GIF 19 | }; 20 | 21 | /** 22 | * 字节流保存上传图片 23 | * @param data 24 | * @param path 25 | * @return 26 | */ 27 | public static boolean byteUpload(byte[] data, String path,String fileName) { 28 | boolean flag = false; 29 | File file = new File(path); 30 | if (!file.exists()){ 31 | file.mkdirs(); 32 | } 33 | file = new File(path+fileName); 34 | try { 35 | OutputStream os = new FileOutputStream(file); 36 | os.write(data); 37 | os.close(); 38 | flag = true; 39 | } catch (Exception e) { 40 | logger.error("上传图片失败 ----", e); 41 | } 42 | return flag; 43 | } 44 | 45 | /** 46 | * 通过文件流判断文件类型 47 | * @param contents file contents 48 | * @return file format, null if unsupported. 49 | */ 50 | public static String getFileType(byte[] contents) { 51 | for (int i = 0; i < FILE_MAGS.length; i++) { 52 | byte[] mag = FILE_MAGS[i]; 53 | if (contents.length >= mag.length) { 54 | if (Arrays.equals(Arrays.copyOf(contents, mag.length), mag)) { 55 | return FILE_EXTS[i]; 56 | } 57 | } 58 | } 59 | return null; 60 | } 61 | /** 62 | * 验证上传文件类型 63 | * @param fileType 64 | * @return 65 | */ 66 | public static boolean validateFileType(String fileType){ 67 | for (String type:FILE_EXTS) { 68 | if (type.equalsIgnoreCase(fileType)){ 69 | return true; 70 | } 71 | } 72 | return false; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/GraphicsMagick.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | /** 7 | * 图片处理 8 | * 服务器需要安装GraphicsMagick 9 | * @author yangzhao 2016年2月29日 10 | * 11 | */ 12 | public class GraphicsMagick { 13 | private static final Logger logger= LoggerFactory.getLogger(GraphicsMagick.class); 14 | 15 | /** 16 | * 缩放图片 17 | * @param width 18 | * @param height 19 | * @param srcPath 20 | * @param newPath 21 | * @param type 1=按像素缩放 2=按百分比 22 | * @return 23 | */ 24 | public static boolean thumbnail(int width, int height, String srcPath, String newPath, int type) { 25 | String raw = ""; 26 | if (type == 1) { 27 | raw = width + "x" + height ; 28 | } else { 29 | raw = width + "%x" + height + "%"; 30 | } 31 | try { 32 | Runtime.getRuntime().exec("gm convert -resize " + raw + " -gravity Center -quality 99 " + srcPath + " " + newPath); 33 | } catch (Exception e) { 34 | logger.error("缩放图片失败!----", e); 35 | return false; 36 | } 37 | return true; 38 | } 39 | 40 | /** 41 | * 裁剪图片 42 | * @param width 剪裁后的宽度 43 | * @param height 剪裁后的高度 44 | * @param x 坐标X 45 | * @param y 坐标Y 46 | * @param srcPath 47 | * @param newPath 48 | * @return 49 | */ 50 | public static boolean cutImage(int width, int height, int x, int y, String srcPath, String newPath) { 51 | try { 52 | Runtime.getRuntime().exec("gm convert -crop " + width + "x" + height + "+" + x + "+" + y + srcPath + " " + newPath); 53 | return true; 54 | } catch (Exception e) { 55 | logger.error("裁剪图片失败!----", e); 56 | } 57 | return false; 58 | } 59 | 60 | /** 61 | * 旋转图片 62 | * @param degree 旋转角度 63 | * @param srcPath 64 | * @param newPath 65 | * @return 66 | */ 67 | public static boolean rotateImage(int degree, String srcPath, String newPath) { 68 | try { 69 | Runtime.getRuntime().exec("gm convert -rotate " + degree + " " + srcPath + " " + newPath); 70 | return true; 71 | } catch (Exception e) { 72 | logger.error("旋转图片失败!----", e); 73 | } 74 | return false; 75 | } 76 | 77 | /** 78 | * 把图片变为黑白颜色 79 | * @param srcPath 80 | * @param newPath 81 | * @return 82 | */ 83 | public static boolean imageBlackAndWhite(String srcPath, String newPath) { 84 | try { 85 | Runtime.getRuntime().exec("gm convert -monochrome " + srcPath + " " + newPath); 86 | return true; 87 | } catch (Exception e) { 88 | logger.error("图片变为黑白颜色失败!----", e); 89 | } 90 | return false; 91 | } 92 | } -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/IPUtil.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | import com.yz.common.core.json.JSON; 4 | 5 | import java.net.InetAddress; 6 | import java.net.NetworkInterface; 7 | import java.util.*; 8 | 9 | /** 10 | * IP工具类 11 | * Created by yangzhao on 16/11/16. 12 | */ 13 | public class IPUtil { 14 | 15 | private static final String SINA_API="message://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip="; 16 | 17 | private static final String TAOBAO_API="message://ip.taobao.com/service/getIpInfo.php?ip="; 18 | 19 | /** 20 | * 免费IP查询接口 21 | * @param ip 22 | * @return 23 | */ 24 | public static Map query(String ip){ 25 | String request = HttpUtil.getRequest(SINA_API+ip); 26 | HashMap responseData = JSON.getInterface().parseObject(request, HashMap.class); 27 | Set set = responseData.keySet(); 28 | Iterator iterator = set.iterator(); 29 | while (iterator.hasNext()){ 30 | String key = iterator.next().toString(); 31 | responseData.put(key,new String(responseData.get(key).toString())); 32 | } 33 | return responseData; 34 | } 35 | 36 | /** 37 | * 获取本机IP地址 38 | * @return 39 | * @throws Exception 40 | */ 41 | public static InetAddress getLocalHostLANAddress() { 42 | try { 43 | InetAddress candidateAddress = null; 44 | // 遍历所有的网络接口 45 | for (Enumeration ifaces = NetworkInterface.getNetworkInterfaces(); ifaces.hasMoreElements(); ) { 46 | NetworkInterface iface = (NetworkInterface) ifaces.nextElement(); 47 | // 在所有的接口下再遍历IP 48 | for (Enumeration inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements(); ) { 49 | InetAddress inetAddr = (InetAddress) inetAddrs.nextElement(); 50 | if (!inetAddr.isLoopbackAddress()) {// 排除loopback类型地址 51 | if (inetAddr.isSiteLocalAddress()) { 52 | // 如果是site-local地址,就是它了 53 | return inetAddr; 54 | } else if (candidateAddress == null) { 55 | // site-local类型的地址未被发现,先记录候选地址 56 | candidateAddress = inetAddr; 57 | } 58 | } 59 | } 60 | } 61 | if (candidateAddress != null) { 62 | return candidateAddress; 63 | } 64 | // 如果没有发现 non-loopback地址.只能用最次选的方案 65 | InetAddress jdkSuppliedAddress = InetAddress.getLocalHost(); 66 | return jdkSuppliedAddress; 67 | } catch (Exception e) { 68 | e.printStackTrace(); 69 | } 70 | return null; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/ImageUtil.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | 4 | import java.io.File; 5 | 6 | /** 7 | * @author: yangzhao 8 | * @Date: 2019/7/31 09:46 9 | * @Description: 10 | */ 11 | public class ImageUtil { 12 | 13 | /** 14 | * 图片转换成base64字符串 15 | * @param imgFile 16 | * @return 17 | */ 18 | public static String imageToBase64(File imgFile) {// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理 19 | String contentToBase64 = FileUtils.fileContentToBase64(imgFile); 20 | String name = imgFile.getName(); 21 | String suffix = name.substring(name.lastIndexOf(".") + 1); 22 | String data = "data:image/" + suffix + ";base64," + contentToBase64; 23 | return data; 24 | } 25 | 26 | /** 27 | * 图片转换成base64字符串 28 | * @param imgFilePath 图片本地路径 29 | * @return 30 | */ 31 | public static String imageToBase64(String imgFilePath) {// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理 32 | File file = new File(imgFilePath); 33 | return imageToBase64(file); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/ImgCompress.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | import java.awt.Image; 4 | import java.awt.image.BufferedImage; 5 | import java.io.File; 6 | import java.io.FileOutputStream; 7 | import java.io.IOException; 8 | import javax.imageio.ImageIO; 9 | import com.sun.image.codec.jpeg.JPEGCodec; 10 | import com.sun.image.codec.jpeg.JPEGImageEncoder; 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | 14 | /** 15 | * 图片压缩 16 | * 17 | * @author yangzhao at 2015年11月30日 18 | * 19 | */ 20 | public class ImgCompress { 21 | 22 | private static final Logger logger= LoggerFactory.getLogger(ImgCompress.class); 23 | 24 | private Image img; 25 | private int width; 26 | private int height; 27 | private String imgUrl; 28 | 29 | /** 30 | * 构造函数 31 | */ 32 | public ImgCompress(File file, String imgUrl) throws IOException { 33 | // File file = new File(path);// 读入文件 34 | img = ImageIO.read(file); // 构造Image对象 35 | width = img.getWidth(null); // 得到源图宽 36 | height = img.getHeight(null); // 得到源图长 37 | this.imgUrl = imgUrl; 38 | } 39 | 40 | /** 41 | * 按照宽度还是高度进行压缩 42 | * 43 | * @param w 44 | * int 最大宽度 45 | * @param h 46 | * int 最大高度 47 | */ 48 | public void resizeFix(int w, int h) throws IOException { 49 | if (width / height > w / h) { 50 | resizeByWidth(w); 51 | } else { 52 | resizeByHeight(h); 53 | } 54 | } 55 | 56 | /** 57 | * 以宽度为基准,等比例放缩图片 58 | * 59 | * @param w 60 | * int 新宽度 61 | */ 62 | public void resizeByWidth(int w) throws IOException { 63 | int h = (int) (height * w / width); 64 | resize(w, h); 65 | } 66 | 67 | /** 68 | * 以高度为基准,等比例缩放图片 69 | * 70 | * @param h 71 | * int 新高度 72 | */ 73 | public void resizeByHeight(int h) throws IOException { 74 | int w = (int) (width * h / height); 75 | resize(w, h); 76 | } 77 | 78 | /** 79 | * 强制压缩/放大图片到固定的大小 80 | * 81 | * @param w 82 | * int 新宽度 83 | * @param h 84 | * int 新高度 85 | */ 86 | public boolean resize(int w, int h) { 87 | boolean flag = false; 88 | // SCALE_SMOOTH 的缩略算法 生成缩略图片的平滑度的 优先级比速度高 生成的图片质量比较好 但速度慢 89 | BufferedImage image = new BufferedImage(w, h, 90 | BufferedImage.TYPE_INT_RGB); 91 | image.getGraphics().drawImage(img, 0, 0, w, h, null); // 绘制缩小后的图 92 | File saveFile = new File(imgUrl); 93 | FileOutputStream out = null; 94 | try { 95 | out = new FileOutputStream(saveFile); 96 | // 可以正常实现bmp、png、gif转jpg 97 | JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); 98 | encoder.encode(image); // JPEG编码 99 | out.close(); 100 | flag = true; 101 | } catch (Exception e) { 102 | logger.error("压缩图片失败! ----", e); 103 | } 104 | return flag; 105 | } 106 | 107 | public static void main(String[] args) throws Exception { 108 | 109 | File file = new File("D:\\banner4.png"); 110 | ImgCompress imgCom = new ImgCompress(file, "d:\\123.png"); 111 | imgCom.resizeFix(1280, 720); 112 | 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/ListUtils.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Random; 6 | 7 | /** 8 | * @auther yangzhao 9 | * create by 17/10/10 10 | */ 11 | public class ListUtils { 12 | 13 | /** 14 | * 从list中随机获取指定个数元素 15 | * @param list 16 | * @param count 17 | * @param 18 | * @return 19 | */ 20 | public static List getRandomFromArray(List list, int count) { 21 | 22 | List result = new ArrayList(); 23 | Random random = new Random(); 24 | 25 | // 要随机取的元素个数 26 | if (count > list.size() || count < 0) 27 | return list; 28 | 29 | int n = 0; 30 | while (true) { 31 | 32 | if (n == count) // 取到足量随机数后退出循环 33 | break; 34 | int size = list.size(); 35 | int temp = random.nextInt(size); 36 | result.add(list.get(temp)); 37 | list.remove(temp); 38 | n++; 39 | } 40 | return result; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/MD5Util.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.security.MessageDigest; 5 | import java.security.NoSuchAlgorithmException; 6 | 7 | /** 8 | * Created by yangzhao on 17/8/8. 9 | */ 10 | public class MD5Util { 11 | 12 | private static final char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };// 用来将字节转换成16进制表示的字符 13 | private static final String hexStrDigits[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; 14 | 15 | public static String md5(String data) { 16 | String s = null; 17 | try { 18 | MessageDigest md = MessageDigest.getInstance("MD5"); 19 | md.update(data.getBytes()); 20 | byte tmp[] = md.digest();// MD5 的计算结果是一个 128 位的长整数, 21 | // 用字节表示就是 16 个字节 22 | char str[] = new char[16 * 2];// 每个字节用 16 进制表示的话,使用两个字符, 所以表示成 16 23 | // 进制需要 32 个字符 24 | int k = 0;// 表示转换结果中对应的字符位置 25 | for (int i = 0; i < 16; i++) {// 从第一个字节开始,对 MD5 的每一个字节// 转换成 16 26 | // 进制字符的转换 27 | byte byte0 = tmp[i];// 取第 i 个字节 28 | str[k++] = hexDigits[byte0 >>> 4 & 0xf];// 取字节中高 4 位的数字转换,// >>> 29 | // 为逻辑右移,将符号位一起右移 30 | str[k++] = hexDigits[byte0 & 0xf];// 取字节中低 4 位的数字转换 31 | 32 | } 33 | s = new String(str);// 换后的结果转换为字符串 34 | 35 | } catch (NoSuchAlgorithmException e) { 36 | } 37 | return s; 38 | } 39 | 40 | public static String MD5Encode(String origin, String charsetname) { 41 | String resultString = null; 42 | try { 43 | resultString = new String(origin); 44 | MessageDigest md = MessageDigest.getInstance("MD5"); 45 | if (charsetname == null || "".equals(charsetname)) 46 | resultString = byteArrayToHexString(md.digest(resultString.getBytes())); 47 | else 48 | resultString = byteArrayToHexString(md.digest(resultString.getBytes(charsetname))); 49 | } catch (Exception exception) { 50 | } 51 | return resultString; 52 | } 53 | 54 | private static String byteArrayToHexString(byte b[]) { 55 | StringBuffer resultSb = new StringBuffer(); 56 | for (int i = 0; i < b.length; i++) 57 | resultSb.append(byteToHexString(b[i])); 58 | 59 | return resultSb.toString(); 60 | } 61 | 62 | private static String byteToHexString(byte b) { 63 | int n = b; 64 | if (n < 0) 65 | n += 256; 66 | int d1 = n / 16; 67 | int d2 = n % 16; 68 | return hexStrDigits[d1] + hexStrDigits[d2]; 69 | } 70 | 71 | /** 72 | * 签名字符串 73 | */ 74 | public static String sign(byte[] buffer) { 75 | char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; 76 | String result=null; 77 | try { 78 | MessageDigest mdTemp = MessageDigest.getInstance("MD5"); 79 | mdTemp.update(buffer); 80 | byte[] md = mdTemp.digest(); 81 | int j = md.length; 82 | char str[] = new char[j * 2]; 83 | int k = 0; 84 | for (int i = 0; i < j; i++) { 85 | byte byte0 = md[i]; 86 | str[k++] = hexDigits[byte0 >>> 4 & 0xf]; 87 | str[k++] = hexDigits[byte0 & 0xf]; 88 | } 89 | result= new String(str); 90 | } catch (Exception e) { 91 | return null; 92 | } 93 | return result; 94 | } 95 | 96 | /** 97 | * @param content 98 | * @param charset 99 | * @return 100 | */ 101 | private static byte[] getContentBytes(String content, String charset) { 102 | if (charset == null || "".equals(charset)) { 103 | return content.getBytes(); 104 | } 105 | try { 106 | return content.getBytes(charset); 107 | } catch (UnsupportedEncodingException e) { 108 | throw new RuntimeException("MD5签名过程中出现错误,指定的编码集不对,您目前指定的编码集是:" + charset); 109 | } 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/PropertyUtil.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.io.FileNotFoundException; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.util.Properties; 10 | 11 | /** 12 | * @author yangzhao 13 | * @Description 读取properties配置文件工具类 14 | * @Date create by 13:25 18/3/4 15 | */ 16 | public class PropertyUtil { 17 | 18 | private static final Logger logger = LoggerFactory.getLogger(PropertyUtil.class); 19 | 20 | private Properties properties; 21 | 22 | private String resourceUri; 23 | 24 | public PropertyUtil(String resourceUri) { 25 | this.resourceUri = resourceUri; 26 | loadProperties(resourceUri); 27 | } 28 | 29 | 30 | private void loadProperties(String resourceUri) { 31 | logger.info("开始加载properties文件内容......."); 32 | properties = new Properties(); 33 | InputStream in = null; 34 | try { 35 | //第一种,通过类加载器进行获取properties文件流 36 | in = PropertyUtil.class.getClassLoader().getResourceAsStream(resourceUri); 37 | //第二种,通过类进行获取properties文件流 38 | //in = PropertyUtil.class.getResourceAsStream("/jdbc.properties"); 39 | properties.load(in); 40 | } catch (FileNotFoundException e) { 41 | logger.error("properties文件未找到"); 42 | } catch (IOException e) { 43 | logger.error("出现IOException"); 44 | } finally { 45 | try { 46 | if (null != in) { 47 | in.close(); 48 | } 49 | } catch (IOException e) { 50 | logger.error("properties文件流关闭出现异常"); 51 | } 52 | } 53 | logger.info("加载properties文件内容完成..........."); 54 | } 55 | 56 | public String getProperty(String key){ 57 | return properties.getProperty(key); 58 | } 59 | 60 | public String getProperty(String key, String defaultValue) { 61 | return properties.getProperty(key, defaultValue); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/QRCodeUtil.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | import com.google.zxing.BarcodeFormat; 4 | import com.google.zxing.EncodeHintType; 5 | import com.google.zxing.MultiFormatWriter; 6 | import com.google.zxing.common.BitMatrix; 7 | import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; 8 | 9 | import javax.imageio.ImageIO; 10 | import java.awt.image.BufferedImage; 11 | import java.io.File; 12 | import java.io.IOException; 13 | import java.util.HashMap; 14 | 15 | /** 16 | * 生成二维码工具类 17 | * @author yangzhao 18 | * @Description 19 | * @Date create by 22:50 18/9/1 20 | */ 21 | public class QRCodeUtil { 22 | 23 | private static final int BLACK = 0xFF000000; 24 | 25 | private static final int WHITE = 0xFFFFFFFF; 26 | 27 | private static final String FORMAT = "png"; 28 | 29 | private int width = 300; 30 | 31 | private int height = 300; 32 | 33 | public void setWidth(int width) { 34 | this.width = width; 35 | } 36 | 37 | public void setHeight(int height) { 38 | this.height = height; 39 | } 40 | 41 | public static QRCodeUtil build(){ 42 | return new QRCodeUtil(); 43 | } 44 | 45 | public static QRCodeUtil build(int width,int height){ 46 | QRCodeUtil qrCodeUtil = new QRCodeUtil(); 47 | qrCodeUtil.setHeight(height); 48 | qrCodeUtil.setWidth(width); 49 | return qrCodeUtil; 50 | } 51 | 52 | public BufferedImage toBufferedImage(BitMatrix matrix) { 53 | int width = matrix.getWidth(); 54 | int height = matrix.getHeight(); 55 | BufferedImage image = new BufferedImage(width, height, 56 | BufferedImage.TYPE_INT_RGB); 57 | for (int x = 0; x < width; x++) { 58 | for (int y = 0; y < height; y++) { 59 | image.setRGB(x, y, matrix.get(x, y) ? BLACK : WHITE); 60 | } 61 | } 62 | return image; 63 | } 64 | 65 | 66 | public void writeToFile(BitMatrix matrix, String format, File file) 67 | throws IOException { 68 | BufferedImage image = toBufferedImage(matrix); 69 | if (!ImageIO.write(image, format, file)) { 70 | throw new IOException("Could not write an image of format " 71 | + format + " to " + file); 72 | } 73 | } 74 | 75 | public void createQRCode(String contents, String filePath) throws Exception { 76 | int width = 300; 77 | int height = 300; 78 | HashMap map = new HashMap(); 79 | map.put(EncodeHintType.CHARACTER_SET, "utf-8"); 80 | map.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); 81 | map.put(EncodeHintType.MARGIN, 0); 82 | BitMatrix bm = new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE, width, height); 83 | writeToFile(bm, FORMAT, new File(filePath)); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/RandomUtil.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | import java.util.Random; 4 | 5 | /** 6 | * @author: yangzhao 7 | * @Date: 2020-05-02 11:47 8 | * @Description: 9 | */ 10 | public class RandomUtil { 11 | /** 12 | * 生成随机字符串 13 | * 14 | * @param len 15 | * @return 16 | */ 17 | public static String getRandomString(int len) { 18 | 19 | String[] baseString = 20 | {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", 21 | "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", 22 | "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; 23 | Random random = new Random(); 24 | int length = baseString.length; 25 | String randomString = ""; 26 | for (int i = 0; i < length; i++) { 27 | randomString += baseString[random.nextInt(length)]; 28 | } 29 | random = new Random(System.currentTimeMillis()); 30 | String resultStr = ""; 31 | for (int i = 0; i < len; i++) { 32 | resultStr += randomString.charAt(random.nextInt(randomString.length() - 1)); 33 | } 34 | return resultStr; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/SHA256Util.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.security.MessageDigest; 5 | import java.security.NoSuchAlgorithmException; 6 | 7 | /** 8 | * @Auther: yangzhao 9 | * @Date: 2019/3/22 22:54 10 | * @Description: 11 | */ 12 | public class SHA256Util { 13 | 14 | /** 15 | * 利用java原生的摘要实现SHA256加密 16 | * 17 | * @param str 加密后的报文 18 | * @return 19 | */ 20 | public static String SHA256(String str) { 21 | MessageDigest messageDigest; 22 | String encodeStr = ""; 23 | try { 24 | messageDigest = MessageDigest.getInstance("SHA-256"); 25 | messageDigest.update(str.getBytes("UTF-8")); 26 | encodeStr = byte2Hex(messageDigest.digest()); 27 | } catch (NoSuchAlgorithmException e) { 28 | e.printStackTrace(); 29 | } catch (UnsupportedEncodingException e) { 30 | e.printStackTrace(); 31 | } 32 | return encodeStr; 33 | } 34 | 35 | /** 36 | * 将byte转为16进制 37 | * 38 | * @param bytes 39 | * @return 40 | */ 41 | private static String byte2Hex(byte[] bytes) { 42 | StringBuffer stringBuffer = new StringBuffer(); 43 | String temp = null; 44 | for (int i = 0; i < bytes.length; i++) { 45 | temp = Integer.toHexString(bytes[i] & 0xFF); 46 | if (temp.length() == 1) { 47 | //1得到一位的进行补0操作 48 | stringBuffer.append("0"); 49 | } 50 | stringBuffer.append(temp); 51 | } 52 | return stringBuffer.toString(); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/SerializeUtil.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | import java.io.*; 4 | 5 | /** 6 | * 对象序列化、反序列化工具类 7 | * 8 | * @Auther: yangzhao 9 | * @Date: 2018/11/26 10:28 10 | * @Description: 11 | */ 12 | public class SerializeUtil { 13 | /** 14 | * 序列化 15 | * 16 | * @param object 17 | * @return 18 | */ 19 | public static byte[] serialize(Object object) throws IOException { 20 | ObjectOutputStream oos = null; 21 | ByteArrayOutputStream baos = null; 22 | // 序列化 23 | baos = new ByteArrayOutputStream(); 24 | oos = new ObjectOutputStream(baos); 25 | oos.writeObject(object); 26 | byte[] bytes = baos.toByteArray(); 27 | return bytes; 28 | } 29 | 30 | /** 31 | * 反序列化 32 | * 33 | * @param bytes 34 | * @return 35 | */ 36 | public static Object unserialize(byte[] bytes) throws Exception { 37 | ByteArrayInputStream bais = null; 38 | // 反序列化 39 | bais = new ByteArrayInputStream(bytes); 40 | ObjectInputStream ois = new ObjectInputStream(bais); 41 | return ois.readObject(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/SnowflakeID.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | 4 | /** 5 | * 推特 雪花ID生成器 6 | * @auther yangzhao 7 | * create by 17/9/19 8 | */ 9 | @Deprecated 10 | public class SnowflakeID { 11 | 12 | /** 13 | * 起始的时间戳 14 | */ 15 | private final static long START_STMP = 1480166465631L; 16 | 17 | /** 18 | * 每一部分占用的位数 19 | */ 20 | private final static long SEQUENCE_BIT = 12; //序列号占用的位数 21 | private final static long MACHINE_BIT = 5; //机器标识占用的位数 22 | private final static long DATACENTER_BIT = 5;//数据中心占用的位数 23 | 24 | /** 25 | * 每一部分的最大值 26 | */ 27 | private final static long MAX_DATACENTER_NUM = -1L ^ (-1L << DATACENTER_BIT); 28 | private final static long MAX_MACHINE_NUM = -1L ^ (-1L << MACHINE_BIT); 29 | private final static long MAX_SEQUENCE = -1L ^ (-1L << SEQUENCE_BIT); 30 | 31 | /** 32 | * 每一部分向左的位移 33 | */ 34 | private final static long MACHINE_LEFT = SEQUENCE_BIT; 35 | private final static long DATACENTER_LEFT = SEQUENCE_BIT + MACHINE_BIT; 36 | private final static long TIMESTMP_LEFT = DATACENTER_LEFT + DATACENTER_BIT; 37 | //数据中心 38 | private long datacenterId; 39 | //机器标识 40 | private long machineId; 41 | //序列号 42 | private long sequence = 0L; 43 | //上一次时间戳 44 | private long lastStmp = -1L; 45 | 46 | private static SnowflakeID snowflakeID; 47 | 48 | public synchronized static void instance(long datacenterId, long machineId){ 49 | if (snowflakeID==null){ 50 | snowflakeID = new SnowflakeID(datacenterId, machineId); 51 | } 52 | 53 | } 54 | 55 | public SnowflakeID(long datacenterId, long machineId) { 56 | if (datacenterId > MAX_DATACENTER_NUM || datacenterId < 0) { 57 | throw new IllegalArgumentException("datacenterId can't be greater than MAX_DATACENTER_NUM or less than 0"); 58 | } 59 | if (machineId > MAX_MACHINE_NUM || machineId < 0) { 60 | throw new IllegalArgumentException("machineId can't be greater than MAX_MACHINE_NUM or less than 0"); 61 | } 62 | this.datacenterId = datacenterId; 63 | this.machineId = machineId; 64 | } 65 | 66 | /** 67 | * 产生下一个ID 68 | * 69 | * @return 70 | */ 71 | public synchronized long nextId() { 72 | long currStmp = getNewstmp(); 73 | if (currStmp < lastStmp) { 74 | throw new RuntimeException("Clock moved backwards. Refusing to generate id"); 75 | } 76 | 77 | if (currStmp == lastStmp) { 78 | //相同毫秒内,序列号自增 79 | sequence = (sequence + 1) & MAX_SEQUENCE; 80 | //同一毫秒的序列数已经达到最大 81 | if (sequence == 0L) { 82 | currStmp = getNextMill(); 83 | } 84 | } else { 85 | //不同毫秒内,序列号置为0 86 | sequence = 0L; 87 | } 88 | 89 | lastStmp = currStmp; 90 | 91 | return (currStmp - START_STMP) << TIMESTMP_LEFT //时间戳部分 92 | | datacenterId << DATACENTER_LEFT //数据中心部分 93 | | machineId << MACHINE_LEFT //机器标识部分 94 | | sequence; //序列号部分 95 | } 96 | 97 | private long getNextMill() { 98 | long mill = getNewstmp(); 99 | while (mill <= lastStmp) { 100 | mill = getNewstmp(); 101 | } 102 | return mill; 103 | } 104 | 105 | private long getNewstmp() { 106 | return System.currentTimeMillis(); 107 | } 108 | 109 | public static SnowflakeID getInstance(){ 110 | return snowflakeID; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /common-core/src/main/java/com/yz/common/core/utils/StringUtils.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.core.utils; 2 | 3 | import java.util.Random; 4 | import java.util.regex.Matcher; 5 | import java.util.regex.Pattern; 6 | 7 | public class StringUtils extends org.apache.commons.lang3.StringUtils { 8 | public static int isAcronym(String word) 9 | { 10 | for(int i = 0; i < word.length(); i++) 11 | { 12 | char c = word.charAt(i); 13 | if (!Character.isLowerCase(c)) 14 | { 15 | return i; 16 | } 17 | } 18 | return -1; 19 | } 20 | /** 21 | * 在字符串大写字母前添加指定字符 22 | * @param 23 | * @param character 24 | * @param addChar 25 | * @return 26 | */ 27 | public static String addCharByIndexFront(String character,String addChar){ 28 | StringBuilder builder=new StringBuilder(); 29 | for(int i=0;i 2 | 3 | 5 | 6 | common-project 7 | com.yz 8 | 1.0.3 9 | 10 | 4.0.0 11 | 12 | common-distributed-lock 13 | 14 | common-distributed-lock 15 | 16 | 17 | 18 | redis.clients 19 | jedis 20 | 21 | 22 | org.springframework.data 23 | spring-data-redis 24 | 25 | 26 | 27 | 28 | ${artifactId} 29 | 30 | 31 | -------------------------------------------------------------------------------- /common-distributed-lock/pom.xml.versionsBackup: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | common-project 7 | com.yz 8 | 1.0.1 9 | 10 | 4.0.0 11 | 12 | common-distributed-lock 13 | 14 | common-distributed-lock 15 | 16 | 17 | 18 | com.yz 19 | common-core 20 | 1.0.1 21 | 22 | 23 | redis.clients 24 | jedis 25 | 26 | 27 | org.springframework.data 28 | spring-data-redis 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | maven-clean-plugin 38 | 3.1.0 39 | 40 | 41 | 42 | maven-resources-plugin 43 | 3.0.2 44 | 45 | 46 | maven-compiler-plugin 47 | 3.8.0 48 | 49 | 50 | maven-surefire-plugin 51 | 2.22.1 52 | 53 | 54 | maven-jar-plugin 55 | 3.0.2 56 | 57 | 58 | maven-install-plugin 59 | 2.5.2 60 | 61 | 62 | maven-deploy-plugin 63 | 2.8.2 64 | 65 | 66 | 67 | maven-site-plugin 68 | 3.7.1 69 | 70 | 71 | maven-project-info-reports-plugin 72 | 3.0.0 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /common-distributed-lock/src/main/java/com/yz/common/distributed/lock/DistributedLock.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.distributed.lock; 2 | 3 | import org.springframework.dao.DataAccessException; 4 | import org.springframework.data.redis.connection.RedisConnection; 5 | import org.springframework.data.redis.core.RedisCallback; 6 | import org.springframework.data.redis.core.RedisTemplate; 7 | import org.springframework.data.redis.serializer.RedisSerializer; 8 | 9 | import javax.annotation.Resource; 10 | import java.util.List; 11 | import java.util.concurrent.TimeUnit; 12 | 13 | /** 14 | * @author: yangzhao 15 | * @Date: 2019/4/29 18:22 16 | * @Description: 17 | */ 18 | public class DistributedLock { 19 | 20 | @Resource(name = "redisTemplate") 21 | private RedisTemplate redisTemplate; 22 | 23 | public DistributedLock() { 24 | } 25 | 26 | public DistributedLock(RedisTemplate redisTemplate) { 27 | this.redisTemplate=redisTemplate; 28 | } 29 | 30 | /** 31 | * 32 | * @param key 锁标识 33 | * @param attempt 重试次数 34 | * @return 35 | */ 36 | public boolean lock(String key,int attempt){ 37 | Boolean absent = redisTemplate.opsForValue().setIfAbsent(key, System.currentTimeMillis()); 38 | if (absent){ 39 | return true; 40 | } 41 | if (attempt>0){ 42 | attempt--; 43 | try { 44 | Thread.sleep(1000); 45 | } catch (InterruptedException e) { 46 | e.printStackTrace(); 47 | } 48 | return lock(key,attempt); 49 | } 50 | return false; 51 | } 52 | 53 | /** 54 | * 55 | * @param key 锁标识 56 | * @param time 过期时间 57 | * @param timeUnit 过期时间单位 58 | * @param attemptNum 重试次数 59 | * @return 60 | */ 61 | public boolean lock(String key, long time, TimeUnit timeUnit,int attemptNum){ 62 | boolean lock = this.lock(key, time, timeUnit); 63 | attemptNum--; 64 | if (!lock){ 65 | if (attemptNum<0){ 66 | return false; 67 | } 68 | try { 69 | Thread.sleep(1000); 70 | } catch (InterruptedException e) { 71 | e.printStackTrace(); 72 | } 73 | return lock(key, time, timeUnit, attemptNum); 74 | } 75 | return true; 76 | } 77 | 78 | public boolean lock(String key, long time, TimeUnit timeUnit){ 79 | List results = redisTemplate.executePipelined(new RedisCallback() { 80 | 81 | RedisSerializer keySerializer = redisTemplate.getKeySerializer(); 82 | 83 | RedisSerializer valueSerializer = redisTemplate.getValueSerializer(); 84 | 85 | @Override 86 | public Boolean doInRedis(RedisConnection redisConnection) throws DataAccessException { 87 | redisConnection.openPipeline(); 88 | byte[] keySerialize = keySerializer.serialize(key); 89 | byte[] valueSerialize = valueSerializer.serialize(System.currentTimeMillis()); 90 | redisConnection.setNX(keySerialize, valueSerialize); 91 | long l = timeUnit.toSeconds(time); 92 | redisConnection.expire(keySerialize, l); 93 | return null; 94 | } 95 | }); 96 | for (Boolean result :results) { 97 | if (!result){ 98 | return false; 99 | } 100 | } 101 | return true; 102 | } 103 | 104 | public void unlock(String key){ 105 | redisTemplate.delete(key); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /common-distributed-lock/src/main/java/com/yz/common/distributed/lock/MethodLockConfigBeanNameUtils.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.distributed.lock; 2 | 3 | /** 4 | * @author: yangzhao 5 | * @Date: 2019/9/14 21:58 6 | * @Description: 7 | */ 8 | public class MethodLockConfigBeanNameUtils { 9 | 10 | public static final String METHOD_DISTRIBUTED_LOCK_BEAN_NAME="methodDistributedLock"; 11 | 12 | public static final String METHOD_DISTRIBUTED_LOCK_POINTCUT_ADVISOR_BEAN_NAME="methodDistributedLockPointCutAdvisor"; 13 | } 14 | -------------------------------------------------------------------------------- /common-distributed-lock/src/main/java/com/yz/common/distributed/lock/annotation/EnableMethodLock.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.distributed.lock.annotation; 2 | 3 | import com.yz.common.distributed.lock.configuration.MethodLockConfiguration; 4 | import org.springframework.context.annotation.Import; 5 | 6 | import java.lang.annotation.*; 7 | 8 | /** 9 | * @author: yangzhao 10 | * @Date: 2019/9/14 17:42 11 | * @Description: 12 | */ 13 | @Target({ElementType.METHOD,ElementType.TYPE}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Documented 16 | @Import({MethodLockConfiguration.class}) 17 | public @interface EnableMethodLock { 18 | } 19 | -------------------------------------------------------------------------------- /common-distributed-lock/src/main/java/com/yz/common/distributed/lock/annotation/MethodLock.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.distributed.lock.annotation; 2 | 3 | import java.lang.annotation.*; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | /** 7 | * @author: yangzhao 8 | * @Date: 2019/7/25 14:34 9 | * @Description: 10 | */ 11 | @Target({ElementType.METHOD}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface MethodLock { 15 | /** 16 | * 锁标识 17 | * @return 18 | */ 19 | String key() default ""; 20 | 21 | /** 22 | * 时间 23 | * @return 24 | */ 25 | long time() default 10; 26 | 27 | /** 28 | * 单位 29 | * @return 30 | */ 31 | TimeUnit timeUnit() default TimeUnit.SECONDS; 32 | 33 | /** 34 | * 是否自动解锁 35 | * @return 36 | */ 37 | boolean autoUnLock() default true; 38 | 39 | /** 40 | * 重试次数 41 | * @return 42 | */ 43 | int attemptNum() default 0; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /common-distributed-lock/src/main/java/com/yz/common/distributed/lock/configuration/MethodLockConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.distributed.lock.configuration; 2 | 3 | import com.yz.common.distributed.lock.annotation.MethodLock; 4 | import com.yz.common.distributed.lock.DistributedLock; 5 | import com.yz.common.distributed.lock.MethodLockConfigBeanNameUtils; 6 | import com.yz.common.distributed.lock.interceptor.MethodLockInterceptor; 7 | import org.springframework.aop.Pointcut; 8 | import org.springframework.aop.support.DefaultPointcutAdvisor; 9 | import org.springframework.aop.support.annotation.AnnotationMatchingPointcut; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | 13 | /** 14 | * @author: yangzhao 15 | * @Date: 2019/9/14 17:18 16 | * @Description: 17 | */ 18 | @Configuration 19 | public class MethodLockConfiguration { 20 | 21 | @Bean(name = MethodLockConfigBeanNameUtils.METHOD_DISTRIBUTED_LOCK_POINTCUT_ADVISOR_BEAN_NAME) 22 | public DefaultPointcutAdvisor defaultBeanFactoryPointcutAdvisor(){ 23 | DefaultPointcutAdvisor defaultPointcutAdvisor = new DefaultPointcutAdvisor(); 24 | defaultPointcutAdvisor.setAdvice(methodLockInterceptor()); 25 | defaultPointcutAdvisor.setPointcut(pointcut()); 26 | return defaultPointcutAdvisor; 27 | } 28 | 29 | @Bean 30 | public MethodLockInterceptor methodLockInterceptor(){ 31 | return new MethodLockInterceptor(); 32 | } 33 | 34 | @Bean 35 | public Pointcut pointcut(){ 36 | return new AnnotationMatchingPointcut(null,MethodLock.class); 37 | } 38 | 39 | @Bean(name = MethodLockConfigBeanNameUtils.METHOD_DISTRIBUTED_LOCK_BEAN_NAME) 40 | public DistributedLock distributedLock(){ 41 | return new DistributedLock(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /common-distributed-lock/src/main/java/com/yz/common/distributed/lock/interceptor/MethodLockInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.distributed.lock.interceptor; 2 | 3 | import com.yz.common.distributed.lock.annotation.MethodLock; 4 | import com.yz.common.distributed.lock.DistributedLock; 5 | import com.yz.common.distributed.lock.MethodLockConfigBeanNameUtils; 6 | import org.aopalliance.intercept.MethodInterceptor; 7 | import org.aopalliance.intercept.MethodInvocation; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.beans.factory.annotation.Qualifier; 12 | import org.springframework.core.LocalVariableTableParameterNameDiscoverer; 13 | import org.springframework.expression.EvaluationContext; 14 | import org.springframework.expression.Expression; 15 | import org.springframework.expression.ExpressionParser; 16 | import org.springframework.expression.spel.standard.SpelExpressionParser; 17 | import org.springframework.expression.spel.support.StandardEvaluationContext; 18 | 19 | import java.lang.reflect.Method; 20 | import java.util.concurrent.TimeUnit; 21 | 22 | /** 23 | * @author: yangzhao 24 | * @Date: 2019/9/14 17:25 25 | * @Description: 26 | */ 27 | public class MethodLockInterceptor implements MethodInterceptor { 28 | 29 | private static final Logger logger = LoggerFactory.getLogger(MethodLockInterceptor.class); 30 | 31 | @Autowired 32 | @Qualifier(MethodLockConfigBeanNameUtils.METHOD_DISTRIBUTED_LOCK_BEAN_NAME) 33 | private DistributedLock distributedLock; 34 | 35 | @Override 36 | public Object invoke(MethodInvocation methodInvocation) throws Throwable { 37 | MethodLock annotation=null; 38 | String lockKey=""; 39 | boolean lock=false; 40 | try { 41 | Method currentMethod = methodInvocation.getMethod(); 42 | Object[] arguments = methodInvocation.getArguments(); 43 | Object target = methodInvocation.getThis(); 44 | annotation = currentMethod.getAnnotation(MethodLock.class); 45 | String[] paramterNames = getParamterNames(currentMethod); 46 | ExpressionParser parser = new SpelExpressionParser(); 47 | Expression expression = parser.parseExpression(annotation.key()); 48 | EvaluationContext context = new StandardEvaluationContext(); 49 | for(int i=0;i"+methodName+" 未获取到锁"); 62 | throw new RuntimeException("获取方法锁失败"); 63 | } 64 | return methodInvocation.proceed(); 65 | }finally { 66 | if (annotation!=null&&annotation.autoUnLock()&&lock){ 67 | distributedLock.unlock(lockKey); 68 | } 69 | } 70 | } 71 | 72 | public String[] getParamterNames(Method method){ 73 | LocalVariableTableParameterNameDiscoverer u = new LocalVariableTableParameterNameDiscoverer(); 74 | return u.getParameterNames(method); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /common-elasticsearch/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | common-project 7 | com.yz 8 | 1.0.3 9 | 10 | 4.0.0 11 | 12 | common-elasticsearch 13 | 14 | common-elasticsearch 15 | 16 | 17 | 18 | 19 | org.elasticsearch 20 | elasticsearch 21 | 22 | 23 | 24 | org.elasticsearch.client 25 | transport 26 | 27 | 28 | com.yz 29 | common-core 30 | 1.0.3 31 | 32 | 33 | 34 | 35 | ${artifactId} 36 | 37 | 38 | -------------------------------------------------------------------------------- /common-elasticsearch/pom.xml.versionsBackup: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | common-project 7 | com.yz 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | common-elasticsearch 13 | 14 | common-elasticsearch 15 | 16 | 17 | 6.2.4 18 | 19 | 20 | 21 | 22 | 23 | org.elasticsearch 24 | elasticsearch 25 | ${org.elasticsearch.version} 26 | 27 | 28 | 29 | org.elasticsearch.client 30 | transport 31 | ${org.elasticsearch.version} 32 | 33 | 34 | com.yz 35 | common-core 36 | 0.0.1-SNAPSHOT 37 | 38 | 39 | 40 | 41 | ${artifactId} 42 | 43 | 44 | -------------------------------------------------------------------------------- /common-pay/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | common-project 5 | com.yz 6 | 1.0.3 7 | 8 | 4.0.0 9 | 10 | common-pay 11 | jar 12 | 13 | ${artifactId} 14 | http://maven.apache.org 15 | 16 | 17 | UTF-8 18 | 19 | 20 | 21 | 22 | 23 | com.yz 24 | common-core 25 | 1.0.3 26 | 27 | 28 | 29 | com.alipay.sdk 30 | alipay-sdk-java 31 | 32 | 33 | 34 | 35 | 36 | ${artifactId} 37 | 38 | 39 | -------------------------------------------------------------------------------- /common-pay/pom.xml.versionsBackup: -------------------------------------------------------------------------------- 1 | 3 | 4 | common-project 5 | com.yz 6 | 0.0.1-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | common-pay 11 | jar 12 | 13 | ${artifactId} 14 | http://maven.apache.org 15 | 16 | 17 | UTF-8 18 | 19 | 20 | 21 | 22 | 23 | com.yz 24 | common-core 25 | 0.0.1-SNAPSHOT 26 | 27 | 28 | 29 | 30 | 31 | ${artifactId} 32 | 33 | 34 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/pay/bean/AliPayParams.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.pay.bean; 2 | 3 | 4 | import com.yz.common.pay.util.AlipayUtil; 5 | 6 | /** 7 | * Created by yangzhao on 17/8/8. 8 | */ 9 | public class AliPayParams extends AliRequestParams { 10 | 11 | private String method = "alipay.trade.app.pay"; 12 | 13 | private String version = "1.0"; 14 | 15 | private String notifyUrl = AlipayUtil.pay_notify_url; 16 | 17 | //该笔订单允许的最晚付款时间,逾期将关闭交易。取值范围:1m~15d。m-分钟,h-小时,d-天,1c-当天(1c-当天的情况下,无论交易何时创建,都在0点关闭)。 该参数数值不接受小数点, 如 1.5h,可转换为 90m 18 | private String timeoutExpress = "1d"; 19 | //销售产品码,商家和支付宝签约的产品码,为固定值QUICK_MSECURITY_PAY 20 | private String productCode = "QUICK_MSECURITY_PAY"; 21 | 22 | private double totalAmount = 0; 23 | //商品的标题/交易标题/订单标题/订单关键字等。示例值:大乐透 24 | private String subject; 25 | //对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。示例值:Iphone6 16G 26 | private String body; 27 | //商户唯一订单号 28 | private String outTradeNo; 29 | 30 | 31 | public double getTotalAmount() { 32 | return totalAmount; 33 | } 34 | 35 | public void setTotalAmount(double totalAmount) { 36 | this.totalAmount = totalAmount; 37 | } 38 | 39 | public String getSubject() { 40 | return subject; 41 | } 42 | 43 | public void setSubject(String subject) { 44 | this.subject = subject; 45 | } 46 | 47 | public String getBody() { 48 | return body; 49 | } 50 | 51 | public void setBody(String body) { 52 | this.body = body; 53 | } 54 | 55 | public String getOutTradeNo() { 56 | return outTradeNo; 57 | } 58 | 59 | public void setOutTradeNo(String outTradeNo) { 60 | this.outTradeNo = outTradeNo; 61 | } 62 | 63 | public String getMethod() { 64 | return method; 65 | } 66 | 67 | public String getVersion() { 68 | return version; 69 | } 70 | 71 | public String getNotifyUrl() { 72 | return notifyUrl; 73 | } 74 | 75 | public String getTimeoutExpress() { 76 | return timeoutExpress; 77 | } 78 | 79 | public String getProductCode() { 80 | return productCode; 81 | } 82 | 83 | 84 | } 85 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/pay/bean/AliRefundParams.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.pay.bean; 2 | 3 | /** 4 | * Created by yangzhao on 17/8/8. 5 | */ 6 | public class AliRefundParams extends AliRequestParams { 7 | 8 | private String method = "alipay.trade.refund"; 9 | 10 | private String version = "1.0"; 11 | //订单支付时传入的商户订单号 12 | private String outTradeNo; 13 | //需要退款的金额,该金额不能大于订单金额,单位为元,支持两位小数 14 | private double refundAmount; 15 | 16 | 17 | public String getMethod() { 18 | return method; 19 | } 20 | 21 | public String getVersion() { 22 | return version; 23 | } 24 | 25 | public String getOutTradeNo() { 26 | return outTradeNo; 27 | } 28 | 29 | public void setOutTradeNo(String outTradeNo) { 30 | this.outTradeNo = outTradeNo; 31 | } 32 | 33 | public double getRefundAmount() { 34 | return refundAmount; 35 | } 36 | 37 | public void setRefundAmount(double refundAmount) { 38 | this.refundAmount = refundAmount; 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/pay/bean/AliRequestParams.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.pay.bean; 2 | 3 | 4 | import com.yz.common.pay.util.AlipayUtil; 5 | 6 | /** 7 | * Created by yangzhao on 17/8/8. 8 | */ 9 | public class AliRequestParams extends RequestParams { 10 | 11 | private String app_id = AlipayUtil.app_id; 12 | 13 | private String applicationAppId = AlipayUtil.application_app_id; 14 | 15 | private String charset = "utf-8"; 16 | 17 | private String signType = "RSA2"; 18 | 19 | public String getApp_id() { 20 | return app_id; 21 | } 22 | 23 | public void setApp_id(String app_id) { 24 | this.app_id = app_id; 25 | } 26 | 27 | public String getApplicationAppId() { 28 | return applicationAppId; 29 | } 30 | 31 | public void setApplicationAppId(String applicationAppId) { 32 | this.applicationAppId = applicationAppId; 33 | } 34 | 35 | public String getCharset() { 36 | return charset; 37 | } 38 | 39 | public void setCharset(String charset) { 40 | this.charset = charset; 41 | } 42 | 43 | public String getSignType() { 44 | return signType; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/pay/bean/RequestParams.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.pay.bean; 2 | 3 | import com.yz.common.core.utils.MD5Util; 4 | 5 | import java.util.Random; 6 | 7 | /** 8 | * Created by yangzhao on 17/8/8. 9 | */ 10 | public abstract class RequestParams { 11 | 12 | public String genNonceStr() { 13 | Random random = new Random(); 14 | return MD5Util.md5(String.valueOf(random.nextInt(10000))); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/pay/bean/WXCreateOrderParams.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.pay.bean; 2 | 3 | import com.yz.common.pay.util.WXPayUtil; 4 | 5 | import javax.validation.constraints.NotNull; 6 | import java.util.Map; 7 | 8 | /** 9 | * Created by yangzhao on 17/8/8. 10 | */ 11 | public class WXCreateOrderParams extends WXRequestParams { 12 | 13 | //商品描述 14 | @NotNull 15 | private String body = ""; 16 | //附加参数 17 | private Map attach; 18 | //商户订单号 19 | @NotNull 20 | private String outTradeNo; 21 | //总金额 22 | @NotNull 23 | private double totalFee; 24 | //终端IP 25 | @NotNull 26 | private String spbillCreateIp; 27 | /** 28 | * 交易结束时间 29 | * 订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见 时间规则 30 | */ 31 | private String timeExpire; 32 | 33 | @NotNull 34 | private String notifyUrl; 35 | 36 | private String tradeType = "APP"; 37 | 38 | public String getBody() { 39 | return body; 40 | } 41 | 42 | public void setBody(String body) { 43 | this.body = body; 44 | } 45 | 46 | public Map getAttach() { 47 | return attach; 48 | } 49 | 50 | public void setAttach(Map attach) { 51 | this.attach = attach; 52 | } 53 | 54 | public String getOutTradeNo() { 55 | return outTradeNo; 56 | } 57 | 58 | public void setOutTradeNo(String outTradeNo) { 59 | this.outTradeNo = outTradeNo; 60 | } 61 | 62 | public double getTotalFee() { 63 | return totalFee; 64 | } 65 | 66 | public void setTotalFee(double totalFee) { 67 | this.totalFee = totalFee; 68 | } 69 | 70 | public String getSpbillCreateIp() { 71 | return spbillCreateIp; 72 | } 73 | 74 | public void setSpbillCreateIp(String spbillCreateIp) { 75 | this.spbillCreateIp = spbillCreateIp; 76 | } 77 | 78 | public String getTimeExpire() { 79 | return timeExpire; 80 | } 81 | 82 | public void setTimeExpire(String timeExpire) { 83 | this.timeExpire = timeExpire; 84 | } 85 | 86 | public String getNotifyUrl() { 87 | return notifyUrl; 88 | } 89 | 90 | public void setNotifyUrl(String notifyUrl) { 91 | this.notifyUrl = notifyUrl; 92 | } 93 | 94 | public String getTradeType() { 95 | return tradeType; 96 | } 97 | 98 | public void setTradeType(String tradeType) { 99 | this.tradeType = tradeType; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/pay/bean/WXPayParams.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.pay.bean; 2 | 3 | 4 | import com.yz.common.core.utils.UUIDUtil; 5 | 6 | /** 7 | * Created by yangzhao on 17/8/8. 8 | */ 9 | public class WXPayParams extends WXRequestParams { 10 | //预支付订单id 11 | private String prepayId; 12 | //扩展字段 填写固定值Sign=WXPay 13 | private String pkg = "Sign=WXPay"; 14 | 15 | private String noncestr = UUIDUtil.getUUID(); 16 | 17 | public String getPrepayId() { 18 | return prepayId; 19 | } 20 | 21 | public void setPrepayId(String prepayId) { 22 | this.prepayId = prepayId; 23 | } 24 | 25 | public String getPkg() { 26 | return pkg; 27 | } 28 | 29 | public String getNoncestr() { 30 | return noncestr; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/pay/bean/WXRefundParams.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.pay.bean; 2 | 3 | /** 4 | * Created by yangzhao on 17/8/8. 5 | */ 6 | public class WXRefundParams extends WXRequestParams { 7 | 8 | //商户订单号 9 | private String outTradeNo; 10 | //商户退款单号 11 | private String outRefundNo; 12 | //订单金额 13 | private double totalFee; 14 | //退款金额 15 | private double refundFee; 16 | 17 | public String getOutTradeNo() { 18 | return outTradeNo; 19 | } 20 | 21 | public void setOutTradeNo(String outTradeNo) { 22 | this.outTradeNo = outTradeNo; 23 | } 24 | 25 | public String getOutRefundNo() { 26 | return outRefundNo; 27 | } 28 | 29 | public void setOutRefundNo(String outRefundNo) { 30 | this.outRefundNo = outRefundNo; 31 | } 32 | 33 | public double getTotalFee() { 34 | return totalFee; 35 | } 36 | 37 | public void setTotalFee(double totalFee) { 38 | this.totalFee = totalFee; 39 | } 40 | 41 | public double getRefundFee() { 42 | return refundFee; 43 | } 44 | 45 | public void setRefundFee(double refundFee) { 46 | this.refundFee = refundFee; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/pay/bean/WXRequestParams.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.pay.bean; 2 | 3 | import com.yz.common.pay.util.WXPayUtil; 4 | 5 | /** 6 | * Created by yangzhao on 17/8/8. 7 | */ 8 | public class WXRequestParams extends RequestParams { 9 | 10 | private String appId = WXPayUtil.APPID; 11 | 12 | private String mchId = WXPayUtil.MCHID; 13 | 14 | public String getAppId() { 15 | return appId; 16 | } 17 | 18 | public void setAppId(String appId) { 19 | this.appId = appId; 20 | } 21 | 22 | public String getMchId() { 23 | return mchId; 24 | } 25 | 26 | public void setMchId(String mchId) { 27 | this.mchId = mchId; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/pay/service/IPay.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.pay.service; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | public interface IPay { 7 | 8 | public final Logger logger = LoggerFactory.getLogger(IPay.class); 9 | 10 | /** 11 | * 创建订单 12 | * @param t 13 | */ 14 | public Object createOrder(T t); 15 | /** 16 | * 退款 17 | * @param 18 | */ 19 | public Object refund(T t) throws Exception; 20 | /** 21 | * 生成客户端请求支付的参数 22 | * @param t 23 | * @return 24 | */ 25 | public Object createPayParams(T t); 26 | 27 | /** 28 | * 查询订单状态 29 | * @param orderId 30 | * @return 31 | */ 32 | public Object queryOrderStatus(String orderId); 33 | } 34 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/pay/service/PayFactory.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.pay.service; 2 | 3 | public class PayFactory { 4 | 5 | public IPay init(int payWay) { 6 | IPay payInterface = null; 7 | switch (payWay) { 8 | case 1: 9 | payInterface = new WXPay(); 10 | break; 11 | case 2: 12 | payInterface = new AliPay(); 13 | break; 14 | } 15 | return payInterface; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/pay/util/WXPayUtil.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.pay.util; 2 | 3 | import com.yz.common.core.utils.MD5Util; 4 | import org.apache.http.NameValuePair; 5 | import java.io.UnsupportedEncodingException; 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | public final class WXPayUtil { 12 | 13 | public static String KEY=""; 14 | 15 | public static String APPID=""; 16 | 17 | public static String MCHID=""; 18 | /** 19 | * 微信回调接口 20 | */ 21 | public static final String pay_notify_url = ""; 22 | 23 | public static String getSign(Map map){ 24 | ArrayList list = new ArrayList(); 25 | for(Map.Entry entry:map.entrySet()){ 26 | if(entry.getValue()!=""&& !entry.getKey().equalsIgnoreCase("sign")){ 27 | list.add(entry.getKey() + "=" + entry.getValue() + "&"); 28 | } 29 | } 30 | int size = list.size(); 31 | String [] arrayToSort = list.toArray(new String[size]); 32 | Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER); 33 | StringBuilder sb = new StringBuilder(); 34 | for(int i = 0; i < size; i ++) { 35 | sb.append(arrayToSort[i]); 36 | } 37 | String result = sb.toString(); 38 | result += "key=" +KEY; 39 | result = MD5Util.MD5Encode(result, "UTF-8").toUpperCase(); 40 | return result; 41 | } 42 | 43 | public static String getSign(List params) { 44 | ArrayList list = new ArrayList(); 45 | StringBuilder sb = new StringBuilder(); 46 | for(NameValuePair pair:params){ 47 | if (pair.getValue()!=""&& !pair.getValue().equalsIgnoreCase("sign")) 48 | list.add(pair.getName() + "=" + pair.getValue() + "&"); 49 | } 50 | int size = list.size(); 51 | String [] arrayToSort = list.toArray(new String[size]); 52 | Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER); 53 | for(int i = 0; i < size; i ++) { 54 | sb.append(arrayToSort[i]); 55 | } 56 | String result = sb.toString(); 57 | result += "key=" +KEY; 58 | byte[] data=null; 59 | try { 60 | data = result.getBytes("utf-8"); 61 | } catch (UnsupportedEncodingException e) { 62 | e.printStackTrace(); 63 | } 64 | String appSign = MD5Util.sign(data).toUpperCase(); 65 | return appSign; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/AliPayServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment; 2 | 3 | import com.alipay.api.AlipayApiException; 4 | import com.alipay.api.AlipayClient; 5 | import com.alipay.api.DefaultAlipayClient; 6 | import com.alipay.api.request.AlipayTradeQueryRequest; 7 | import com.alipay.api.request.AlipayTradeRefundRequest; 8 | import com.alipay.api.response.AlipayTradeQueryResponse; 9 | import com.alipay.api.response.AlipayTradeRefundResponse; 10 | import com.yz.common.payment.config.AliPayConfig; 11 | import com.yz.common.payment.config.PayConfig; 12 | import com.yz.common.payment.order.query.OrderQueryResponse; 13 | import com.yz.common.payment.trade.pay.TradePay; 14 | import com.yz.common.payment.trade.pay.bo.AliTradePayResponse; 15 | import com.yz.common.payment.trade.pay.bo.TradePayResponse; 16 | import com.yz.common.payment.trade.pay.bo.UserOrder; 17 | import com.yz.common.payment.trade.pay.builder.AliTradePayBuilder; 18 | import com.yz.common.payment.trade.pay.builder.AliTradePayParamsBuilder; 19 | import com.yz.common.payment.trade.pay.params.TradePayParams; 20 | 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | 24 | /** 25 | * @author: yangzhao 26 | * @Date: 2019/7/10 19:18 27 | * @Description: 28 | */ 29 | public class AliPayServiceImpl implements PayService { 30 | 31 | 32 | @Override 33 | public PayConfig getPayConfig(Integer orderFrom) { 34 | return null; 35 | } 36 | 37 | @Override 38 | public TradePayResponse tradePayOrder(UserOrder userOrder, String notifyUrl, String returnUrl) throws Exception { 39 | AliPayConfig aliPayConfig= (AliPayConfig) getPayConfig(userOrder.getOrderFrom()); 40 | TradePay tradePay = AliTradePayBuilder.builder().aliPayConfig(aliPayConfig).payType(userOrder.getPayType()).build(); 41 | TradePayParams tradePayParams = AliTradePayParamsBuilder.builder().userOrder(userOrder).notifyUrl(notifyUrl).returnUrl(returnUrl).build(); 42 | AliTradePayResponse tradePayResponse = (AliTradePayResponse) tradePay.createTradePay(tradePayParams); 43 | return tradePayResponse; 44 | } 45 | 46 | @Override 47 | public boolean refund(String orderNum) { 48 | //TODO 根据实际业务参数填写 49 | Integer orderFrom=0; 50 | AliPayConfig aliPayConfig= (AliPayConfig) getPayConfig(orderFrom); 51 | AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",aliPayConfig.getAppId(),aliPayConfig.getAppPrivateKey(),"json",aliPayConfig.getCharset(),aliPayConfig.getAliPayPublicKey(),"RSA2"); 52 | AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); 53 | Map bizContent = new HashMap<>(); 54 | bizContent.put("out_trade_no",orderNum); 55 | String refundAmount=""; 56 | bizContent.put("refund_amount",refundAmount); 57 | AlipayTradeRefundResponse response = null; 58 | try { 59 | response = alipayClient.execute(request); 60 | if(!response.isSuccess()){ 61 | return false; 62 | } 63 | } catch (AlipayApiException e) { 64 | logger.error("调用支付宝退款失败 ====> "+e.getErrMsg()); 65 | } 66 | return true; 67 | } 68 | 69 | @Override 70 | public OrderQueryResponse orderQuery(String orderNum) throws AlipayApiException { 71 | //TODO 根据实际业务参数填写 72 | Integer orderFrom=0; 73 | AliPayConfig aliPayConfig= (AliPayConfig) getPayConfig(orderFrom); 74 | AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",aliPayConfig.getAppId(),aliPayConfig.getAppPrivateKey(),"json",aliPayConfig.getCharset(),aliPayConfig.getAliPayPublicKey(),"RSA2"); 75 | AlipayTradeQueryRequest request = new AlipayTradeQueryRequest(); 76 | request.setBizContent("{\"out_trade_no\":\""+orderNum+"\"}"); 77 | AlipayTradeQueryResponse response = alipayClient.execute(request); 78 | if(!response.isSuccess()){ 79 | return null; 80 | } 81 | return null; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/PayService.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment; 2 | 3 | import com.alipay.api.AlipayApiException; 4 | import com.yz.common.core.exception.HandlerException; 5 | import com.yz.common.payment.config.PayConfig; 6 | import com.yz.common.payment.order.query.OrderQueryResponse; 7 | import com.yz.common.payment.trade.pay.bo.TradePayResponse; 8 | import com.yz.common.payment.trade.pay.bo.UserOrder; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | /** 13 | * 14 | * @author: yangzhao 15 | * @Date: 2019/7/10 11:01 16 | * @Description: 17 | */ 18 | public interface PayService { 19 | 20 | public static final Logger logger = LoggerFactory.getLogger(PayService.class); 21 | 22 | /** 23 | * 通过订单来源获取支付配置信息 24 | * @param orderFrom 25 | * @return 26 | */ 27 | public PayConfig getPayConfig(Integer orderFrom); 28 | 29 | /** 30 | * 统一支付下单 31 | * @param userOrder 32 | * @param notifyUrl 回调url 33 | * @param returnUrl 返回页面url 34 | * @return 35 | * @throws Exception 36 | */ 37 | public TradePayResponse tradePayOrder(UserOrder userOrder, String notifyUrl, String returnUrl) throws Exception; 38 | 39 | /** 40 | * 通过订单号退款 41 | * @param orderNum 42 | */ 43 | public boolean refund(String orderNum) throws HandlerException; 44 | 45 | /** 46 | * 订单查询 47 | * @param orderNum 48 | * @return 49 | */ 50 | public OrderQueryResponse orderQuery(String orderNum) throws AlipayApiException, HandlerException; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/ThirdPayFactory.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment; 2 | 3 | 4 | import com.yz.common.payment.enums.PayChannelEnum; 5 | 6 | /** 7 | * @author: yangzhao 8 | * @Date: 2019/7/15 15:47 9 | * @Description: 10 | */ 11 | public class ThirdPayFactory { 12 | 13 | private static WXPayServiceImpl wxPayService; 14 | 15 | private static AliPayServiceImpl aliPayService; 16 | 17 | public void setWxPayServiceImpl(WXPayServiceImpl wxPayServiceImpl) { 18 | ThirdPayFactory.wxPayService = wxPayServiceImpl; 19 | } 20 | public void setAliPayService(AliPayServiceImpl aliPayServiceImpl) { 21 | ThirdPayFactory.aliPayService = aliPayService; 22 | } 23 | 24 | public static PayService getPayService(int payChannel){ 25 | if (payChannel== PayChannelEnum.WX_PAY.getCode()){ 26 | return wxPayService; 27 | }else if (payChannel==PayChannelEnum.ALI_PAY.getCode()){ 28 | return aliPayService; 29 | } 30 | return null; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/config/AliPayConfig.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.config; 2 | 3 | /** 4 | * @author: yangzhao 5 | * @Date: 2019/7/10 14:24 6 | * @Description: 7 | */ 8 | public class AliPayConfig extends PayConfig { 9 | 10 | /** 11 | * 支付宝分配给开发者的应用ID 12 | */ 13 | private String appId; 14 | /** 15 | * 请求使用的编码格式 16 | */ 17 | private String charset="utf-8"; 18 | /** 19 | * 商户生成签名字符串所使用的签名算法类型,目前支持RSA2和RSA,推荐使用RSA2 20 | */ 21 | private String signType="RSA2"; 22 | 23 | private String appPrivateKey; 24 | 25 | private String aliPayPublicKey; 26 | 27 | public String getAppId() { 28 | return appId; 29 | } 30 | 31 | public void setAppId(String appId) { 32 | this.appId = appId; 33 | } 34 | 35 | public String getCharset() { 36 | return charset; 37 | } 38 | 39 | public void setCharset(String charset) { 40 | this.charset = charset; 41 | } 42 | 43 | public String getSignType() { 44 | return signType; 45 | } 46 | 47 | public void setSignType(String signType) { 48 | this.signType = signType; 49 | } 50 | 51 | public String getAppPrivateKey() { 52 | return appPrivateKey; 53 | } 54 | 55 | public void setAppPrivateKey(String appPrivateKey) { 56 | this.appPrivateKey = appPrivateKey; 57 | } 58 | 59 | public String getAliPayPublicKey() { 60 | return aliPayPublicKey; 61 | } 62 | 63 | public void setAliPayPublicKey(String aliPayPublicKey) { 64 | this.aliPayPublicKey = aliPayPublicKey; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/config/PayConfig.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.config; 2 | 3 | /** 4 | * @author: yangzhao 5 | * @Date: 2019/7/25 10:41 6 | * @Description: 7 | */ 8 | public abstract class PayConfig { 9 | } 10 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/config/WXPayConfig.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.config; 2 | 3 | /** 4 | * 微信支付配置类 5 | */ 6 | public class WXPayConfig extends PayConfig{ 7 | /** 8 | * 公众账号ID 9 | */ 10 | private String appId; 11 | /** 12 | * 商户号 13 | */ 14 | private String mchId; 15 | 16 | private String mchKey; 17 | 18 | public enum SignType { 19 | MD5, HMACSHA256 20 | } 21 | 22 | public String getAppId() { 23 | return appId; 24 | } 25 | 26 | public void setAppId(String appId) { 27 | this.appId = appId; 28 | } 29 | 30 | public String getMchId() { 31 | return mchId; 32 | } 33 | 34 | public void setMchId(String mchId) { 35 | this.mchId = mchId; 36 | } 37 | 38 | public String getMchKey() { 39 | return mchKey; 40 | } 41 | 42 | public void setMchKey(String mchKey) { 43 | this.mchKey = mchKey; 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/constants/WXPayConstant.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.constants; 2 | 3 | import org.apache.http.client.HttpClient; 4 | 5 | /** 6 | * @author: yangzhao 7 | * @Date: 2019/7/10 16:10 8 | * @Description: 9 | */ 10 | public class WXPayConstant { 11 | 12 | public static final String DOMAIN_API = "api.mch.weixin.qq.com"; 13 | public static final String DOMAIN_API2 = "api2.mch.weixin.qq.com"; 14 | public static final String DOMAIN_APIHK = "apihk.mch.weixin.qq.com"; 15 | public static final String DOMAIN_APIUS = "apius.mch.weixin.qq.com"; 16 | 17 | 18 | public static final String FAIL = "FAIL"; 19 | public static final String SUCCESS = "SUCCESS"; 20 | public static final String HMACSHA256 = "HMAC-SHA256"; 21 | public static final String MD5 = "MD5"; 22 | 23 | public static final String FIELD_SIGN = "sign"; 24 | public static final String FIELD_SIGN_TYPE = "sign_type"; 25 | 26 | public static final String WXPAYSDK_VERSION = "WXPaySDK/3.0.9"; 27 | public static final String USER_AGENT = WXPAYSDK_VERSION + 28 | " (" + System.getProperty("os.arch") + " " + System.getProperty("os.name") + " " + System.getProperty("os.version") + 29 | ") Java/" + System.getProperty("java.version") + " HttpClient/" + HttpClient.class.getPackage().getImplementationVersion(); 30 | 31 | public static final String MICROPAY_URL_SUFFIX = "/pay/micropay"; 32 | /** 33 | * 统一下单 34 | */ 35 | public static final String UNIFIEDORDER_URL_SUFFIX = "/pay/unifiedorder"; 36 | 37 | public static final String ORDERQUERY_URL_SUFFIX = "/pay/orderquery"; 38 | public static final String REVERSE_URL_SUFFIX = "/secapi/pay/reverse"; 39 | public static final String CLOSEORDER_URL_SUFFIX = "/pay/closeorder"; 40 | public static final String REFUND_URL_SUFFIX = "/secapi/pay/refund"; 41 | public static final String REFUNDQUERY_URL_SUFFIX = "/pay/refundquery"; 42 | public static final String DOWNLOADBILL_URL_SUFFIX = "/pay/downloadbill"; 43 | public static final String REPORT_URL_SUFFIX = "/payitil/report"; 44 | public static final String SHORTURL_URL_SUFFIX = "/tools/shorturl"; 45 | public static final String AUTHCODETOOPENID_URL_SUFFIX = "/tools/authcodetoopenid"; 46 | 47 | // sandbox 48 | public static final String SANDBOX_MICROPAY_URL_SUFFIX = "/sandboxnew/pay/micropay"; 49 | public static final String SANDBOX_UNIFIEDORDER_URL_SUFFIX = "/sandboxnew/pay/unifiedorder"; 50 | public static final String SANDBOX_ORDERQUERY_URL_SUFFIX = "/sandboxnew/pay/orderquery"; 51 | public static final String SANDBOX_REVERSE_URL_SUFFIX = "/sandboxnew/secapi/pay/reverse"; 52 | public static final String SANDBOX_CLOSEORDER_URL_SUFFIX = "/sandboxnew/pay/closeorder"; 53 | public static final String SANDBOX_REFUND_URL_SUFFIX = "/sandboxnew/secapi/pay/refund"; 54 | public static final String SANDBOX_REFUNDQUERY_URL_SUFFIX = "/sandboxnew/pay/refundquery"; 55 | public static final String SANDBOX_DOWNLOADBILL_URL_SUFFIX = "/sandboxnew/pay/downloadbill"; 56 | public static final String SANDBOX_REPORT_URL_SUFFIX = "/sandboxnew/payitil/report"; 57 | public static final String SANDBOX_SHORTURL_URL_SUFFIX = "/sandboxnew/tools/shorturl"; 58 | public static final String SANDBOX_AUTHCODETOOPENID_URL_SUFFIX = "/sandboxnew/tools/authcodetoopenid"; 59 | } 60 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/enums/PayChannelEnum.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.enums; 2 | 3 | /** 4 | * @author: yangzhao 5 | * @Date: 2019/7/15 15:49 6 | * @Description: 7 | */ 8 | public enum PayChannelEnum { 9 | 10 | WX_PAY(1), 11 | ALI_PAY(2); 12 | 13 | private int code; 14 | 15 | PayChannelEnum(int code) { 16 | this.code = code; 17 | } 18 | 19 | public int getCode() { 20 | return code; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/enums/PayTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.enums; 2 | 3 | /** 4 | * @author: yangzhao 5 | * @Date: 2019/7/10 19:24 6 | * @Description: 7 | */ 8 | public enum PayTypeEnum { 9 | JS(1), 10 | APP(2), 11 | PC(3) 12 | ; 13 | private int code; 14 | 15 | PayTypeEnum(int code) { 16 | this.code = code; 17 | } 18 | 19 | public int getCode() { 20 | return code; 21 | } 22 | 23 | public void setCode(int code) { 24 | this.code = code; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/enums/WXTradeState.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.enums; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * @author: yangzhao 8 | * @Date: 2019/7/11 20:05 9 | * @Description: 10 | */ 11 | public enum WXTradeState { 12 | //支付成功 13 | SUCCESS, 14 | //转入退款 15 | REFUND, 16 | //未支付 17 | NOTPAY, 18 | //已关闭 19 | CLOSED, 20 | //已撤销(付款码支付) 21 | REVOKED, 22 | //用户支付中(付款码支付) 23 | USERPAYING, 24 | //支付失败(其他原因,如银行返回失败) 25 | PAYERROR; 26 | 27 | private static final Map lookup = new HashMap(); 28 | 29 | static { 30 | for (WXTradeState d : WXTradeState.values()) { 31 | lookup.put(d.name(), d); 32 | } 33 | } 34 | 35 | public static WXTradeState get(String abbr){ 36 | return lookup.get(abbr); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/order/query/OrderQueryResponse.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.order.query; 2 | 3 | /** 4 | * @author: yangzhao 5 | * @Date: 2019/7/23 15:40 6 | * @Description: 7 | */ 8 | public abstract class OrderQueryResponse { 9 | } 10 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/order/query/WxOrderQueryResponse.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.order.query; 2 | 3 | /** 4 | * @author: yangzhao 5 | * @Date: 2019/7/11 20:00 6 | * @Description: 7 | */ 8 | public class WxOrderQueryResponse extends OrderQueryResponse { 9 | /** 10 | * 交易类型 11 | * JSAPI,NATIVE,APP,MICROPAY 12 | */ 13 | private String tradeType; 14 | /** 15 | * 交易状态 16 | * SUCCESS—支付成功 17 | * REFUND—转入退款 18 | * NOTPAY—未支付 19 | * CLOSED—已关闭 20 | * REVOKED—已撤销(付款码支付) 21 | * USERPAYING--用户支付中(付款码支付) 22 | * PAYERROR--支付失败(其他原因,如银行返回失败) 23 | */ 24 | private String tradeState; 25 | /** 26 | * 订单总金额 27 | */ 28 | private String totalFee; 29 | /** 30 | * 现金支付金额 31 | */ 32 | private String cashFee; 33 | /** 34 | * 微信支付订单号 35 | */ 36 | private String transactionId; 37 | /** 38 | * 商户订单号 39 | */ 40 | private String outTradeNo; 41 | /** 42 | * 支付完成时间 43 | * 订单支付时间,格式为yyyyMMddHHmmss 44 | */ 45 | private String timeEnd; 46 | /** 47 | * 交易状态描述 48 | */ 49 | private String tradeStateDesc; 50 | 51 | public String getTradeType() { 52 | return tradeType; 53 | } 54 | 55 | public void setTradeType(String tradeType) { 56 | this.tradeType = tradeType; 57 | } 58 | 59 | public String getTradeState() { 60 | return tradeState; 61 | } 62 | 63 | public void setTradeState(String tradeState) { 64 | this.tradeState = tradeState; 65 | } 66 | 67 | public String getTotalFee() { 68 | return totalFee; 69 | } 70 | 71 | public void setTotalFee(String totalFee) { 72 | this.totalFee = totalFee; 73 | } 74 | 75 | public String getCashFee() { 76 | return cashFee; 77 | } 78 | 79 | public void setCashFee(String cashFee) { 80 | this.cashFee = cashFee; 81 | } 82 | 83 | public String getTransactionId() { 84 | return transactionId; 85 | } 86 | 87 | public void setTransactionId(String transactionId) { 88 | this.transactionId = transactionId; 89 | } 90 | 91 | public String getOutTradeNo() { 92 | return outTradeNo; 93 | } 94 | 95 | public void setOutTradeNo(String outTradeNo) { 96 | this.outTradeNo = outTradeNo; 97 | } 98 | 99 | public String getTimeEnd() { 100 | return timeEnd; 101 | } 102 | 103 | public void setTimeEnd(String timeEnd) { 104 | this.timeEnd = timeEnd; 105 | } 106 | 107 | public String getTradeStateDesc() { 108 | return tradeStateDesc; 109 | } 110 | 111 | public void setTradeStateDesc(String tradeStateDesc) { 112 | this.tradeStateDesc = tradeStateDesc; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/trade/pay/AliAppTradePayImpl.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.trade.pay; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alipay.api.AlipayClient; 5 | import com.alipay.api.DefaultAlipayClient; 6 | import com.alipay.api.request.AlipayTradeAppPayRequest; 7 | import com.alipay.api.response.AlipayTradeAppPayResponse; 8 | import com.yz.common.payment.config.AliPayConfig; 9 | import com.yz.common.payment.trade.pay.bo.AliTradePayResponse; 10 | import com.yz.common.payment.trade.pay.params.AliTradeAppPayParams; 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | /** 16 | * @author: yangzhao 17 | * @Date: 2019/7/10 17:43 18 | * @Description: 19 | */ 20 | public class AliAppTradePayImpl implements TradePay { 21 | 22 | private AliPayConfig aliPayConfig; 23 | 24 | public AliAppTradePayImpl(AliPayConfig aliPayConfig) { 25 | this.aliPayConfig = aliPayConfig; 26 | } 27 | 28 | @Override 29 | public AliTradePayResponse createTradePay(AliTradeAppPayParams aliTradeAppPayParams) throws Exception { 30 | AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",aliPayConfig.getAppId(),aliPayConfig.getAppPrivateKey(),"json",aliPayConfig.getCharset(),aliPayConfig.getAliPayPublicKey(),aliPayConfig.getSignType()); 31 | AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest(); 32 | request.setNotifyUrl(aliTradeAppPayParams.getNotifyUrl()); 33 | Map bizContent = new HashMap<>(); 34 | bizContent.put("total_amount", aliTradeAppPayParams.getTotalAmount()); 35 | bizContent.put("subject", aliTradeAppPayParams.getSubject()); 36 | bizContent.put("out_trade_no", aliTradeAppPayParams.getOutTradeNo()); 37 | request.setBizContent(JSON.toJSONString(bizContent)); 38 | AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request); 39 | if(!response.isSuccess()){ 40 | return null; 41 | } 42 | logger.info("支付宝APP统一下单成功"); 43 | return AliTradePayResponse.generator(response); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/trade/pay/AliH5TradePayImpl.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.trade.pay; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import com.alibaba.fastjson.JSON; 8 | import com.alipay.api.AlipayClient; 9 | import com.alipay.api.DefaultAlipayClient; 10 | import com.alipay.api.request.AlipayTradeWapPayRequest; 11 | import com.alipay.api.response.AlipayTradeWapPayResponse; 12 | import com.yz.common.payment.config.AliPayConfig; 13 | import com.yz.common.payment.trade.pay.bo.AliTradePayResponse; 14 | import com.yz.common.payment.trade.pay.params.AliTradeH5PayParams; 15 | 16 | /** 17 | * @author: yangzhao 18 | * @Date: 2019/7/10 17:43 19 | * @Description: 20 | */ 21 | public class AliH5TradePayImpl implements TradePay { 22 | 23 | private AliPayConfig aliPayConfig; 24 | 25 | public AliH5TradePayImpl(AliPayConfig aliPayConfig) { 26 | this.aliPayConfig = aliPayConfig; 27 | } 28 | 29 | @Override 30 | public AliTradePayResponse createTradePay(AliTradeH5PayParams aliTradeH5PayParams) throws Exception { 31 | AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", 32 | aliPayConfig.getAppId(), aliPayConfig.getAppPrivateKey(), "json", aliPayConfig.getCharset(), 33 | aliPayConfig.getAliPayPublicKey(), aliPayConfig.getSignType()); 34 | AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); 35 | request.setNotifyUrl(aliTradeH5PayParams.getNotifyUrl()); 36 | request.setReturnUrl(aliTradeH5PayParams.getQuitUrl()); 37 | Map bizContent = new HashMap<>(); 38 | BigDecimal bigDecimal = new BigDecimal(aliTradeH5PayParams.getTotalAmount()); 39 | // BigDecimal bigDecimal = new BigDecimal("0.01"); 40 | bigDecimal = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP); 41 | bizContent.put("total_amount", bigDecimal.toString()); 42 | bizContent.put("subject", aliTradeH5PayParams.getSubject()); 43 | bizContent.put("out_trade_no", aliTradeH5PayParams.getOutTradeNo()); 44 | bizContent.put("quit_url", aliTradeH5PayParams.getQuitUrl()); 45 | bizContent.put("product_code", "QUICK_WAP_WAY"); 46 | request.setBizContent(JSON.toJSONString(bizContent)); 47 | AlipayTradeWapPayResponse alipayTradeWapPayResponse = alipayClient.pageExecute(request); 48 | if (!alipayTradeWapPayResponse.isSuccess()) { 49 | return null; 50 | } 51 | logger.info("支付宝H5统一下单成功"); 52 | return AliTradePayResponse.generator(alipayTradeWapPayResponse); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/trade/pay/TradePay.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.trade.pay; 2 | 3 | 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | /** 8 | * 统一下单 9 | * @author: yangzhao 10 | * @Date: 2019/7/10 11:38 11 | * @Description: 12 | */ 13 | public interface TradePay { 14 | 15 | public static final Logger logger = LoggerFactory.getLogger(TradePay.class); 16 | 17 | public TradePayResponse createTradePay(TradePayParams tradPayParams) throws Exception; 18 | } 19 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/trade/pay/WXTradeAppPayImpl.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.trade.pay; 2 | 3 | import com.yz.common.core.utils.HttpUtil; 4 | import com.yz.common.payment.config.WXPayConfig; 5 | import com.yz.common.payment.constants.WXPayConstant; 6 | import com.yz.common.payment.trade.pay.bo.WXTradePayResponse; 7 | import com.yz.common.payment.trade.pay.params.WXTradeJsApiPayParams; 8 | import com.yz.common.payment.utils.WXPayUtil; 9 | 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | import java.util.UUID; 13 | 14 | /** 15 | * @author: yangzhao 16 | * @Date: 2019/7/10 14:44 17 | * @Description: 18 | */ 19 | public class WXTradeAppPayImpl implements TradePay { 20 | 21 | private WXPayConfig wxPayConfig; 22 | 23 | public WXTradeAppPayImpl(WXPayConfig wxPayConfig) { 24 | this.wxPayConfig = wxPayConfig; 25 | } 26 | 27 | @Override 28 | public WXTradePayResponse createTradePay(WXTradeJsApiPayParams wxTradeJsApiPayParams) { 29 | Map requestParams = new HashMap<>(); 30 | requestParams.put("appid",wxPayConfig.getAppId()); 31 | requestParams.put("mch_id",wxPayConfig.getMchId()); 32 | requestParams.put("nonce_str", UUID.randomUUID().toString().replace("-","")); 33 | requestParams.put("body", wxTradeJsApiPayParams.getBody()); 34 | requestParams.put("out_trade_no", wxTradeJsApiPayParams.getOutTradeNo()); 35 | requestParams.put("total_fee", wxTradeJsApiPayParams.getTotalFee().toString()); 36 | requestParams.put("spbill_create_ip", wxTradeJsApiPayParams.getSpbillCreateIp()); 37 | requestParams.put("notify_url", wxTradeJsApiPayParams.getNotifyUrl()); 38 | requestParams.put("trade_type", wxTradeJsApiPayParams.getTradeType()); 39 | Map resultMap = null; 40 | try { 41 | String sign = WXPayUtil.generateSignature(requestParams, wxPayConfig.getMchKey()); 42 | requestParams.put("sign",sign); 43 | String xml = WXPayUtil.mapToXml(requestParams); 44 | String resultXml = HttpUtil.sendPost(WXPayConstant.DOMAIN_API + WXPayConstant.UNIFIEDORDER_URL_SUFFIX, xml); 45 | resultMap = WXPayUtil.xmlToMap(resultXml); 46 | } catch (Exception e) { 47 | e.printStackTrace(); 48 | } 49 | 50 | if (resultMap.get("return_code").equals("SUCCESS")&&resultMap.get("result_code").equals("SUCCESS")){ 51 | WXTradePayResponse wxTradePayResponse = new WXTradePayResponse(); 52 | wxTradePayResponse.setTradeType(resultMap.get("trade_type")); 53 | wxTradePayResponse.setPrepayId(resultMap.get("prepay_id")); 54 | return wxTradePayResponse; 55 | } 56 | return null; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/trade/pay/bo/AliTradePayResponse.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.trade.pay.bo; 2 | 3 | import com.alipay.api.response.AlipayTradeAppPayResponse; 4 | import com.alipay.api.response.AlipayTradeWapPayResponse; 5 | 6 | /** 7 | * @author: yangzhao 8 | * @Date: 2019/7/23 15:10 9 | * @Description: 10 | */ 11 | public class AliTradePayResponse extends TradePayResponse { 12 | 13 | /** 14 | * 商户原始订单号 15 | */ 16 | private String merchantOrderNo; 17 | /** 18 | * 商户网站唯一订单号 19 | */ 20 | private String outTradeNo; 21 | /** 22 | * 收款支付宝账号对应支付宝唯一用户号 23 | */ 24 | private String sellerId; 25 | /** 26 | * 订单总金额 27 | */ 28 | private String totalAmount; 29 | /** 30 | * 支付宝系统交易流水号 31 | */ 32 | private String tradeNo; 33 | 34 | public String getMerchantOrderNo() { 35 | return merchantOrderNo; 36 | } 37 | 38 | public void setMerchantOrderNo(String merchantOrderNo) { 39 | this.merchantOrderNo = merchantOrderNo; 40 | } 41 | 42 | public String getOutTradeNo() { 43 | return outTradeNo; 44 | } 45 | 46 | public void setOutTradeNo(String outTradeNo) { 47 | this.outTradeNo = outTradeNo; 48 | } 49 | 50 | public String getSellerId() { 51 | return sellerId; 52 | } 53 | 54 | public void setSellerId(String sellerId) { 55 | this.sellerId = sellerId; 56 | } 57 | 58 | public String getTotalAmount() { 59 | return totalAmount; 60 | } 61 | 62 | public void setTotalAmount(String totalAmount) { 63 | this.totalAmount = totalAmount; 64 | } 65 | 66 | public String getTradeNo() { 67 | return tradeNo; 68 | } 69 | 70 | public void setTradeNo(String tradeNo) { 71 | this.tradeNo = tradeNo; 72 | } 73 | 74 | public static AliTradePayResponse generator(AlipayTradeAppPayResponse alipayTradeAppPayResponse) { 75 | AliTradePayResponse aliTradePayResponse = new AliTradePayResponse(); 76 | aliTradePayResponse.setOutTradeNo(alipayTradeAppPayResponse.getOutTradeNo()); 77 | aliTradePayResponse.setTotalAmount(alipayTradeAppPayResponse.getTotalAmount()); 78 | aliTradePayResponse.setTradeNo(alipayTradeAppPayResponse.getOutTradeNo()); 79 | aliTradePayResponse.setMerchantOrderNo(alipayTradeAppPayResponse.getMerchantOrderNo()); 80 | aliTradePayResponse.setSellerId(alipayTradeAppPayResponse.getSellerId()); 81 | return null; 82 | } 83 | 84 | public static AliTradePayResponse generator(AlipayTradeWapPayResponse alipayTradeAppPayResponse) { 85 | AliTradePayResponse aliTradePayResponse = new AliTradePayResponse(); 86 | aliTradePayResponse.setOutTradeNo(alipayTradeAppPayResponse.getOutTradeNo()); 87 | aliTradePayResponse.setTotalAmount(alipayTradeAppPayResponse.getTotalAmount()); 88 | aliTradePayResponse.setTradeNo(alipayTradeAppPayResponse.getOutTradeNo()); 89 | aliTradePayResponse.setSellerId(alipayTradeAppPayResponse.getSellerId()); 90 | aliTradePayResponse.setBody(alipayTradeAppPayResponse.getBody()); 91 | return aliTradePayResponse; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/trade/pay/bo/TradePayResponse.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.trade.pay.bo; 2 | 3 | /** 4 | * @author: yangzhao 5 | * @Date: 2019/7/23 15:03 6 | * @Description: 7 | */ 8 | public abstract class TradePayResponse { 9 | 10 | private String body; 11 | 12 | public String getBody() { 13 | return body; 14 | } 15 | 16 | public void setBody(String body) { 17 | this.body = body; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/trade/pay/bo/WXTradePayResponse.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.trade.pay.bo; 2 | 3 | /** 4 | * @author: yangzhao 5 | * @Date: 2019/7/10 14:46 6 | * @Description: 7 | */ 8 | public class WXTradePayResponse extends TradePayResponse { 9 | /** 10 | * 公众号 ID 11 | */ 12 | private String appId; 13 | /** 14 | * 随机字符串 15 | */ 16 | private String nonceStr; 17 | /** 18 | * 签名类型 19 | */ 20 | private String signType; 21 | /** 22 | * 签名 23 | */ 24 | private String sign; 25 | 26 | /** 27 | * 交易类型 28 | * JSAPI -JSAPI支付 29 | * NATIVE -Native支付 30 | * APP -APP支付 31 | */ 32 | private String tradeType; 33 | /** 34 | * 预支付交易会话标识 35 | */ 36 | private String prepayId; 37 | /** 38 | * 二维码链接 39 | */ 40 | private String codeUrl; 41 | 42 | private String timeStamp; 43 | 44 | public String getTradeType() { 45 | return tradeType; 46 | } 47 | 48 | public void setTradeType(String tradeType) { 49 | this.tradeType = tradeType; 50 | } 51 | 52 | public String getPrepayId() { 53 | return prepayId; 54 | } 55 | 56 | public void setPrepayId(String prepayId) { 57 | this.prepayId = prepayId; 58 | } 59 | 60 | public String getCodeUrl() { 61 | return codeUrl; 62 | } 63 | 64 | public void setCodeUrl(String codeUrl) { 65 | this.codeUrl = codeUrl; 66 | } 67 | 68 | public String getAppId() { 69 | return appId; 70 | } 71 | 72 | public void setAppId(String appId) { 73 | this.appId = appId; 74 | } 75 | 76 | public String getNonceStr() { 77 | return nonceStr; 78 | } 79 | 80 | public void setNonceStr(String nonceStr) { 81 | this.nonceStr = nonceStr; 82 | } 83 | 84 | public String getSignType() { 85 | return signType; 86 | } 87 | 88 | public void setSignType(String signType) { 89 | this.signType = signType; 90 | } 91 | 92 | public String getSign() { 93 | return sign; 94 | } 95 | 96 | public void setSign(String sign) { 97 | this.sign = sign; 98 | } 99 | 100 | public String getTimeStamp() { 101 | return timeStamp; 102 | } 103 | 104 | public void setTimeStamp(String timeStamp) { 105 | this.timeStamp = timeStamp; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/trade/pay/builder/AliTradePayBuilder.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.trade.pay.builder; 2 | 3 | 4 | import com.yz.common.payment.config.AliPayConfig; 5 | import com.yz.common.payment.enums.PayTypeEnum; 6 | import com.yz.common.payment.trade.pay.AliAppTradePayImpl; 7 | import com.yz.common.payment.trade.pay.TradePay; 8 | 9 | /** 10 | * @author: yangzhao 11 | * @Date: 2019/7/10 19:52 12 | * @Description: 13 | */ 14 | public class AliTradePayBuilder { 15 | 16 | private AliPayConfig aliPayConfig; 17 | 18 | private Integer payType; 19 | 20 | public static AliTradePayBuilder builder(){ 21 | return new AliTradePayBuilder(); 22 | } 23 | 24 | public AliTradePayBuilder aliPayConfig(AliPayConfig aliPayConfig){ 25 | this.aliPayConfig=aliPayConfig; 26 | return this; 27 | } 28 | 29 | public AliTradePayBuilder payType(Integer payType){ 30 | this.payType=payType; 31 | return this; 32 | } 33 | 34 | public TradePay build(){ 35 | TradePay tradePay=null; 36 | if (payType== PayTypeEnum.JS.getCode()){ 37 | 38 | }else if (payType==PayTypeEnum.APP.getCode()){ 39 | tradePay = new AliAppTradePayImpl(aliPayConfig); 40 | }else if (payType==PayTypeEnum.PC.getCode()){ 41 | 42 | } 43 | return tradePay; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/trade/pay/builder/AliTradePayParamsBuilder.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.trade.pay.builder; 2 | 3 | import com.yz.common.payment.enums.PayTypeEnum; 4 | import com.yz.common.payment.trade.pay.bo.UserOrder; 5 | import com.yz.common.payment.trade.pay.params.AliTradeAppPayParams; 6 | import com.yz.common.payment.trade.pay.params.AliTradeH5PayParams; 7 | import com.yz.common.payment.trade.pay.params.TradePayParams; 8 | 9 | /** 10 | * @author: yangzhao 11 | * @Date: 2019/7/11 17:06 12 | * @Description: 13 | */ 14 | public class AliTradePayParamsBuilder { 15 | 16 | private UserOrder userOrder; 17 | 18 | private String notifyUrl; 19 | 20 | private String returnUrl; 21 | 22 | public static AliTradePayParamsBuilder builder() { 23 | return new AliTradePayParamsBuilder(); 24 | } 25 | 26 | public AliTradePayParamsBuilder userOrder(UserOrder userOrder) { 27 | this.userOrder = userOrder; 28 | return this; 29 | } 30 | 31 | public AliTradePayParamsBuilder notifyUrl(String notifyUrl) { 32 | this.notifyUrl = notifyUrl; 33 | return this; 34 | } 35 | 36 | public AliTradePayParamsBuilder returnUrl(String returnUrl) { 37 | this.returnUrl = returnUrl; 38 | return this; 39 | } 40 | 41 | public TradePayParams build() { 42 | TradePayParams tradePayParams = null; 43 | Integer payType = userOrder.getPayType(); 44 | if (payType == PayTypeEnum.JS.getCode()) { 45 | AliTradeH5PayParams aliTradeH5PayParams = new AliTradeH5PayParams(); 46 | aliTradeH5PayParams.setBody(userOrder.getSubject()); 47 | aliTradeH5PayParams.setOutTradeNo(userOrder.getOrderNum()); 48 | aliTradeH5PayParams.setSubject(userOrder.getSubject()); 49 | aliTradeH5PayParams.setTotalAmount(userOrder.getActualPrice().toString()); 50 | aliTradeH5PayParams.setMethod("alipay.trade.wap.pay"); 51 | aliTradeH5PayParams.setNotifyUrl(notifyUrl); 52 | aliTradeH5PayParams.setQuitUrl(returnUrl); 53 | tradePayParams = aliTradeH5PayParams; 54 | } else if (payType == PayTypeEnum.APP.getCode()) { 55 | AliTradeAppPayParams aliTradeAppPayParams = new AliTradeAppPayParams(); 56 | aliTradeAppPayParams.setBody(userOrder.getSubject()); 57 | aliTradeAppPayParams.setOutTradeNo(userOrder.getOrderNum()); 58 | aliTradeAppPayParams.setSubject(userOrder.getSubject()); 59 | aliTradeAppPayParams.setTotalAmount(userOrder.getActualPrice().toString()); 60 | aliTradeAppPayParams.setMethod("alipay.trade.app.pay"); 61 | aliTradeAppPayParams.setNotifyUrl(notifyUrl); 62 | tradePayParams = aliTradeAppPayParams; 63 | } else if (payType == PayTypeEnum.PC.getCode()) { 64 | 65 | } 66 | return tradePayParams; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/trade/pay/builder/WXTradePayBuilder.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.trade.pay.builder; 2 | 3 | 4 | import com.yz.common.payment.config.WXPayConfig; 5 | import com.yz.common.payment.enums.PayTypeEnum; 6 | import com.yz.common.payment.trade.pay.TradePay; 7 | import com.yz.common.payment.trade.pay.WXJsApiTradePayImpl; 8 | 9 | /** 10 | * @author: yangzhao 11 | * @Date: 2019/7/10 19:52 12 | * @Description: 13 | */ 14 | public class WXTradePayBuilder { 15 | 16 | private Integer payType; 17 | 18 | private WXPayConfig wxPayConfig; 19 | 20 | public static WXTradePayBuilder newInstance(){ 21 | return new WXTradePayBuilder(); 22 | } 23 | 24 | public WXTradePayBuilder payType(int payType){ 25 | this.payType=payType; 26 | return this; 27 | } 28 | 29 | public WXTradePayBuilder wxPayConfig(WXPayConfig wxPayConfig){ 30 | this.wxPayConfig=wxPayConfig; 31 | return this; 32 | } 33 | 34 | public TradePay build(){ 35 | TradePay tradePay=null; 36 | if (payType== PayTypeEnum.JS.getCode()){ 37 | tradePay=new WXJsApiTradePayImpl(wxPayConfig); 38 | }else if (payType==PayTypeEnum.APP.getCode()){ 39 | 40 | }else if (payType==PayTypeEnum.PC.getCode()){ 41 | 42 | } 43 | return tradePay; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/trade/pay/builder/WXTradePayParamsBuilder.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.trade.pay.builder; 2 | 3 | import com.yz.common.payment.enums.PayTypeEnum; 4 | import com.yz.common.payment.trade.pay.bo.UserOrder; 5 | import com.yz.common.payment.trade.pay.params.TradePayParams; 6 | import com.yz.common.payment.trade.pay.params.WXTradeAppPayParams; 7 | import com.yz.common.payment.trade.pay.params.WXTradeJsApiPayParams; 8 | import org.apache.commons.lang3.StringUtils; 9 | 10 | /** 11 | * @author: yangzhao 12 | * @Date: 2019/7/10 19:57 13 | * @Description: 14 | */ 15 | public class WXTradePayParamsBuilder { 16 | 17 | private UserOrder userOrder; 18 | 19 | private String openId; 20 | 21 | private String notifyUrl; 22 | 23 | public static WXTradePayParamsBuilder newInstance(){ 24 | return new WXTradePayParamsBuilder(); 25 | } 26 | 27 | public WXTradePayParamsBuilder userOrder(UserOrder userOrder){ 28 | this.userOrder=userOrder; 29 | return this; 30 | } 31 | 32 | public WXTradePayParamsBuilder notifyUrl(String notifyUrl){ 33 | this.notifyUrl=notifyUrl; 34 | return this; 35 | } 36 | 37 | public WXTradePayParamsBuilder openId(String openId){ 38 | this.openId=openId; 39 | return this; 40 | } 41 | 42 | public TradePayParams build() throws Exception { 43 | TradePayParams tradePayParams=null; 44 | Integer payType=userOrder.getPayType(); 45 | if (payType== PayTypeEnum.JS.getCode()){ 46 | 47 | if (StringUtils.isEmpty(openId)){ 48 | throw new Exception("OPENID IS NOT NULL OR EMPTY"); 49 | } 50 | 51 | WXTradeJsApiPayParams wxTradeJsApiPayParams =new WXTradeJsApiPayParams(); 52 | wxTradeJsApiPayParams.setOpenId(openId); 53 | wxTradeJsApiPayParams.setBody(userOrder.getSubject()); 54 | wxTradeJsApiPayParams.setNotifyUrl(notifyUrl); 55 | wxTradeJsApiPayParams.setOutTradeNo(userOrder.getOrderNum()); 56 | wxTradeJsApiPayParams.setTotalFee((long)(userOrder.getActualPrice().doubleValue()*100)); 57 | wxTradeJsApiPayParams.setTradeType("JSAPI"); 58 | wxTradeJsApiPayParams.setSpbillCreateIp("127.0.0.1"); 59 | tradePayParams= wxTradeJsApiPayParams; 60 | }else if (payType==PayTypeEnum.APP.getCode()){ 61 | WXTradeAppPayParams wxTradeAppPayParams =new WXTradeAppPayParams(); 62 | wxTradeAppPayParams.setBody(userOrder.getSubject()); 63 | wxTradeAppPayParams.setNotifyUrl(notifyUrl); 64 | wxTradeAppPayParams.setOutTradeNo(userOrder.getOrderNum()); 65 | wxTradeAppPayParams.setTotalFee((long)userOrder.getActualPrice().doubleValue()*100); 66 | wxTradeAppPayParams.setTradeType("APP"); 67 | tradePayParams= wxTradeAppPayParams; 68 | }else if (payType==PayTypeEnum.PC.getCode()){ 69 | 70 | } 71 | return tradePayParams; 72 | } 73 | 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/trade/pay/params/AliTradeAppPayParams.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.trade.pay.params; 2 | 3 | /** 4 | * 蚂蚁金服APP统一下单参数 5 | * @author: yangzhao 6 | * @Date: 2019/7/10 14:15 7 | * @Description: 8 | */ 9 | public class AliTradeAppPayParams extends AliTradePayParams { 10 | /** 11 | * 支付宝服务器主动通知商户服务器 12 | */ 13 | private String notifyUrl; 14 | 15 | public String getNotifyUrl() { 16 | return notifyUrl; 17 | } 18 | 19 | public void setNotifyUrl(String notifyUrl) { 20 | this.notifyUrl = notifyUrl; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/trade/pay/params/AliTradeH5PayParams.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.trade.pay.params; 2 | 3 | /** 4 | * @author: yangzhao 5 | * @Date: 2019/7/10 11:58 6 | * @Description: 7 | */ 8 | public class AliTradeH5PayParams extends AliTradePayParams { 9 | 10 | /** 11 | * 用户付款中途退出返回商户网站的地址 12 | */ 13 | private String quitUrl; 14 | /** 15 | * 销售产品码,商家和支付宝签约的产品码 16 | */ 17 | private String product_code; 18 | 19 | private String notifyUrl; 20 | 21 | public String getQuitUrl() { 22 | return quitUrl; 23 | } 24 | 25 | public void setQuitUrl(String quitUrl) { 26 | this.quitUrl = quitUrl; 27 | } 28 | 29 | public String getProduct_code() { 30 | return product_code; 31 | } 32 | 33 | public void setProduct_code(String product_code) { 34 | this.product_code = product_code; 35 | } 36 | 37 | public String getNotifyUrl() { 38 | return notifyUrl; 39 | } 40 | 41 | public void setNotifyUrl(String notifyUrl) { 42 | this.notifyUrl = notifyUrl; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/trade/pay/params/AliTradePayParams.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.trade.pay.params; 2 | 3 | /** 4 | * @author: yangzhao 5 | * @Date: 2019/7/10 11:58 6 | * @Description: 7 | */ 8 | public class AliTradePayParams extends TradePayParams { 9 | /** 10 | *接口名称 11 | */ 12 | private String method; 13 | 14 | /** 15 | * 订单总金额,单位为元,精确到小数点后两位,取值范围[0.01,100000000] 16 | */ 17 | private String totalAmount; 18 | /** 19 | * 对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。 20 | */ 21 | private String body; 22 | /** 23 | * 商品的标题/交易标题/订单标题/订单关键字等 24 | */ 25 | private String subject; 26 | /** 27 | * 商户唯一订单号 最大长度64 28 | */ 29 | private String outTradeNo; 30 | 31 | public String getTotalAmount() { 32 | return totalAmount; 33 | } 34 | 35 | public void setTotalAmount(String totalAmount) { 36 | this.totalAmount = totalAmount; 37 | } 38 | 39 | public String getBody() { 40 | return body; 41 | } 42 | 43 | public void setBody(String body) { 44 | this.body = body; 45 | } 46 | 47 | public String getSubject() { 48 | return subject; 49 | } 50 | 51 | public void setSubject(String subject) { 52 | this.subject = subject; 53 | } 54 | 55 | public String getOutTradeNo() { 56 | return outTradeNo; 57 | } 58 | 59 | public void setOutTradeNo(String outTradeNo) { 60 | this.outTradeNo = outTradeNo; 61 | } 62 | 63 | public String getMethod() { 64 | return method; 65 | } 66 | 67 | public void setMethod(String method) { 68 | this.method = method; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/trade/pay/params/TradePayParams.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.trade.pay.params; 2 | 3 | 4 | /** 5 | * 统一下单参数 6 | * @author: yangzhao 7 | * @Date: 2019/7/10 11:39 8 | * @Description: 9 | */ 10 | public abstract class TradePayParams { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/trade/pay/params/WXTradeAppPayParams.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.trade.pay.params; 2 | 3 | /** 4 | * @author: yangzhao 5 | * @Date: 2019/7/11 20:11 6 | * @Description: 7 | */ 8 | public class WXTradeAppPayParams extends WXTradePayParams { 9 | } 10 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/trade/pay/params/WXTradeJsApiPayParams.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.trade.pay.params; 2 | 3 | /** 4 | * @author: yangzhao 5 | * @Date: 2019/7/10 19:00 6 | * @Description: 7 | */ 8 | public class WXTradeJsApiPayParams extends WXTradePayParams { 9 | 10 | private String openId; 11 | 12 | public String getOpenId() { 13 | return openId; 14 | } 15 | 16 | public void setOpenId(String openId) { 17 | this.openId = openId; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/trade/pay/params/WXTradePayParams.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.trade.pay.params; 2 | 3 | /** 4 | * @author: yangzhao 5 | * @Date: 2019/7/10 11:41 6 | * @Description: 7 | */ 8 | public class WXTradePayParams extends TradePayParams { 9 | /** 10 | * 商品描述 11 | */ 12 | private String body; 13 | /** 14 | * 商户订单号 15 | */ 16 | private String outTradeNo; 17 | /** 18 | * 订单总金额,单位为分 19 | */ 20 | private Long totalFee; 21 | /** 22 | * 终端IP 支持IPV4和IPV6两种格式的IP地址。用户的客户端IP 23 | */ 24 | private String spbillCreateIp; 25 | /** 26 | * 异步接收微信支付结果通知的回调地址 27 | */ 28 | private String notifyUrl; 29 | /** 30 | * 交易类型 31 | * 32 | * JSAPI -JSAPI支付 33 | * NATIVE -Native支付 34 | * APP -APP支付 35 | */ 36 | private String tradeType; 37 | 38 | public String getBody() { 39 | return body; 40 | } 41 | 42 | public void setBody(String body) { 43 | this.body = body; 44 | } 45 | 46 | public String getOutTradeNo() { 47 | return outTradeNo; 48 | } 49 | 50 | public void setOutTradeNo(String outTradeNo) { 51 | this.outTradeNo = outTradeNo; 52 | } 53 | 54 | public Long getTotalFee() { 55 | return totalFee; 56 | } 57 | 58 | public void setTotalFee(Long totalFee) { 59 | this.totalFee = totalFee; 60 | } 61 | 62 | public String getSpbillCreateIp() { 63 | return spbillCreateIp; 64 | } 65 | 66 | public void setSpbillCreateIp(String spbillCreateIp) { 67 | this.spbillCreateIp = spbillCreateIp; 68 | } 69 | 70 | public String getNotifyUrl() { 71 | return notifyUrl; 72 | } 73 | 74 | public void setNotifyUrl(String notifyUrl) { 75 | this.notifyUrl = notifyUrl; 76 | } 77 | 78 | public String getTradeType() { 79 | return tradeType; 80 | } 81 | 82 | public void setTradeType(String tradeType) { 83 | this.tradeType = tradeType; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /common-pay/src/main/java/com/yz/common/payment/utils/WXPayXmlUtil.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.payment.utils; 2 | 3 | import org.w3c.dom.Document; 4 | 5 | import javax.xml.XMLConstants; 6 | import javax.xml.parsers.DocumentBuilder; 7 | import javax.xml.parsers.DocumentBuilderFactory; 8 | import javax.xml.parsers.ParserConfigurationException; 9 | 10 | /** 11 | * 2018/7/3 12 | */ 13 | public final class WXPayXmlUtil { 14 | public static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException { 15 | DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); 16 | documentBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); 17 | documentBuilderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false); 18 | documentBuilderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); 19 | documentBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); 20 | documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); 21 | documentBuilderFactory.setXIncludeAware(false); 22 | documentBuilderFactory.setExpandEntityReferences(false); 23 | 24 | return documentBuilderFactory.newDocumentBuilder(); 25 | } 26 | 27 | public static Document newDocument() throws ParserConfigurationException { 28 | return newDocumentBuilder().newDocument(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /common-security/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | common-project 5 | com.yz 6 | 1.0.3 7 | 8 | 4.0.0 9 | 10 | common-security 11 | jar 12 | 13 | common-security 14 | http://maven.apache.org 15 | 16 | 17 | 18 | com.yz 19 | common-core 20 | 1.0.3 21 | 22 | 23 | 24 | 25 | ${artifactId} 26 | 27 | 28 | -------------------------------------------------------------------------------- /common-security/pom.xml.versionsBackup: -------------------------------------------------------------------------------- 1 | 3 | 4 | common-project 5 | com.yz 6 | 0.0.1-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | common-security 11 | jar 12 | 13 | common-security 14 | http://maven.apache.org 15 | 16 | 17 | UTF-8 18 | 19 | 20 | 21 | 22 | junit 23 | junit 24 | 3.8.1 25 | test 26 | 27 | 28 | com.yz 29 | common-core 30 | 0.0.1-SNAPSHOT 31 | 32 | 33 | 34 | 35 | ${artifactId} 36 | 37 | 38 | -------------------------------------------------------------------------------- /common-security/src/main/java/com/yz/common/security/DES.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.security; 2 | 3 | import org.apache.logging.log4j.LogManager; 4 | import org.apache.logging.log4j.Logger; 5 | import javax.crypto.Cipher; 6 | import javax.crypto.SecretKeyFactory; 7 | import javax.crypto.spec.DESedeKeySpec; 8 | import javax.crypto.spec.IvParameterSpec; 9 | import java.security.Key; 10 | import java.util.Base64; 11 | 12 | public class DES implements ISecurity{ 13 | 14 | private static final Logger logger=LogManager.getLogger(DES.class); 15 | 16 | // 密钥 17 | private final static String secretKey = ""; 18 | // 向量 19 | private final static String iv = "01234567"; 20 | // 加解密统一使用的编码方式 21 | private final static String encoding = "utf-8"; 22 | 23 | @Override 24 | public String Encrypt(String data) throws Exception { 25 | Key deskey = null; 26 | DESedeKeySpec spec; 27 | spec = new DESedeKeySpec(secretKey.getBytes()); 28 | SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede"); 29 | deskey = keyfactory.generateSecret(spec); 30 | 31 | Cipher cipher = Cipher.getInstance("desede/CBC/PKCS5Padding"); 32 | IvParameterSpec ips = new IvParameterSpec(iv.getBytes()); 33 | cipher.init(Cipher.ENCRYPT_MODE, deskey, ips); 34 | byte[] encryptData = cipher.doFinal(data.getBytes(encoding)); 35 | return java.util.Base64.getEncoder().encodeToString(encryptData); 36 | } 37 | 38 | @Override 39 | public String Decrypt(String data) throws Exception { 40 | Key deskey = null; 41 | DESedeKeySpec spec; 42 | spec = new DESedeKeySpec(secretKey.getBytes()); 43 | SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede"); 44 | deskey = keyfactory.generateSecret(spec); 45 | Cipher cipher = Cipher.getInstance("desede/CBC/PKCS5Padding"); 46 | IvParameterSpec ips = new IvParameterSpec(iv.getBytes()); 47 | cipher.init(Cipher.DECRYPT_MODE, deskey, ips); 48 | byte[] decode = Base64.getDecoder().decode(data); 49 | byte[] decryptData = cipher.doFinal(decode); 50 | return new String(decryptData, encoding); 51 | } 52 | 53 | @Override 54 | public String Sign(String content, String privateKey) throws Exception { 55 | return null; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /common-security/src/main/java/com/yz/common/security/ISecurity.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.security; 2 | 3 | import java.util.*; 4 | 5 | /** 6 | * Created by yangzhao on 17/7/20. 7 | */ 8 | public interface ISecurity { 9 | 10 | /** 11 | * 加密字符串 12 | * @param data 13 | * @return 14 | */ 15 | public String Encrypt(String data) throws Exception; 16 | 17 | /** 18 | * 解密字符串 19 | * @param data 20 | * @return 21 | */ 22 | public String Decrypt(String data) throws Exception; 23 | 24 | /** 25 | * 签名 26 | * @param content 27 | * @param privateKey 28 | * @return 29 | * @throws Exception 30 | */ 31 | public String Sign(String content, String privateKey) throws Exception; 32 | 33 | /** 34 | * 除去数组中的空值和签名参数 35 | * @param sArray 签名参数组 36 | * @return 去掉空值与签名参数后的新签名参数组 37 | */ 38 | public default Map paraFilter(Map sArray) { 39 | 40 | Map result = new HashMap(); 41 | 42 | if (sArray == null || sArray.size() <= 0) { 43 | return result; 44 | } 45 | 46 | for (String key : sArray.keySet()) { 47 | String value = sArray.get(key); 48 | if (value == null || value.equals("") || key.equalsIgnoreCase("sign")) { 49 | continue; 50 | } 51 | result.put(key, value); 52 | } 53 | 54 | return result; 55 | } 56 | 57 | /** 58 | * 把数组所有元素排序,并按照“参数=参数值”的模式用“&”字符拼接成字符串 59 | * @param params 需要排序并参与字符拼接的参数组 60 | * @return 拼接后字符串 61 | */ 62 | public default String createLinkString(Map params) { 63 | 64 | List keys = new ArrayList(params.keySet()); 65 | Collections.sort(keys); 66 | 67 | String prestr = ""; 68 | 69 | for (int i = 0; i < keys.size(); i++) { 70 | String key = keys.get(i); 71 | String value = params.get(key); 72 | 73 | if (i == keys.size() - 1) {//拼接时,不包括最后一个&字符 74 | prestr = prestr + key + "=" + value; 75 | } else { 76 | prestr = prestr + key + "=" + value + "&"; 77 | } 78 | } 79 | return prestr; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /common-security/src/main/java/com/yz/common/security/RSA.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.security; 2 | 3 | import java.security.KeyFactory; 4 | import java.security.PrivateKey; 5 | import java.security.Signature; 6 | import java.security.spec.PKCS8EncodedKeySpec; 7 | import java.util.Base64; 8 | 9 | public class RSA { 10 | 11 | private final String SIGN_ALGORITHMS = "SHA1WithRSA"; 12 | 13 | public String Sign(String content, String privateKey) throws Exception { 14 | PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKey)); 15 | KeyFactory keyf = KeyFactory.getInstance("RSA"); 16 | PrivateKey priKey = keyf.generatePrivate(priPKCS8); 17 | Signature signature = Signature.getInstance(SIGN_ALGORITHMS); 18 | signature.initSign(priKey); 19 | signature.update(content.getBytes("UTF-8")); 20 | byte[] signed = signature.sign(); 21 | return Base64.getEncoder().encodeToString(signed); 22 | } 23 | } -------------------------------------------------------------------------------- /common-security/src/main/java/com/yz/common/security/RSA256.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.security; 2 | 3 | 4 | import java.security.KeyFactory; 5 | import java.security.PrivateKey; 6 | import java.security.Signature; 7 | import java.security.spec.PKCS8EncodedKeySpec; 8 | import java.util.Base64; 9 | 10 | /** 11 | * Created by yangzhao on 17/7/20. 12 | */ 13 | public final class RSA256 { 14 | 15 | private final String SIGN_256_ALGORITHMS = "SHA256WithRSA"; 16 | 17 | public String Sign(String content, String privateKey) throws Exception { 18 | PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKey.getBytes())); 19 | KeyFactory keyf = KeyFactory.getInstance("RSA"); 20 | PrivateKey priKey = keyf.generatePrivate(priPKCS8); 21 | Signature signature = Signature.getInstance(SIGN_256_ALGORITHMS); 22 | signature.initSign(priKey); 23 | signature.update(content.getBytes("UTF-8")); 24 | byte[] signed = signature.sign(); 25 | return Base64.getEncoder().encodeToString(signed); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /common-security/src/main/java/com/yz/common/security/SHA.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.security; 2 | 3 | import java.security.MessageDigest; 4 | 5 | /** 6 | * Created by yangzhao on 17/7/20. 7 | */ 8 | public class SHA { 9 | 10 | public String Sign(String content, String privateKey) throws Exception { 11 | byte[] bt = content.getBytes(); 12 | String encName = "SHA-256"; 13 | MessageDigest md = MessageDigest.getInstance(encName); 14 | md.update(bt); 15 | String strDes = bytes2Hex(md.digest()); 16 | return strDes; 17 | } 18 | 19 | private String bytes2Hex(byte[] bts) { 20 | String des = ""; 21 | String tmp = null; 22 | for (int i = 0; i < bts.length; i++) { 23 | tmp = (Integer.toHexString(bts[i] & 0xFF)); 24 | if (tmp.length() == 1) { 25 | des += "0"; 26 | } 27 | des += tmp; 28 | } 29 | return des; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /common-security/src/main/java/com/yz/common/security/aes/AES_CBC.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.security.aes; 2 | 3 | import com.yz.common.security.ISecurity; 4 | import sun.misc.BASE64Decoder; 5 | import sun.misc.BASE64Encoder; 6 | 7 | import javax.crypto.Cipher; 8 | import javax.crypto.spec.IvParameterSpec; 9 | import javax.crypto.spec.SecretKeySpec; 10 | import java.util.Map; 11 | 12 | /** 13 | * @author yangzhao 14 | * @Description 15 | * @Date create by 15:49 18/2/3 16 | */ 17 | public class AES_CBC implements ISecurity { 18 | /** 19 | * 加密用的Key 可以用26个字母和数字组成 20 | * 此处使用AES-128-CBC加密模式,key需要为16位。 21 | */ 22 | private String sKey = "B31F2A75FBF94099"; 23 | private String ivParameter = "1234567890123456"; 24 | 25 | public AES_CBC(String sKey,String ivParameter){ 26 | this.sKey=sKey; 27 | this.ivParameter=ivParameter; 28 | } 29 | 30 | // 加密 31 | @Override 32 | public String Encrypt(String sSrc) throws Exception { 33 | Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); 34 | byte[] raw = sKey.getBytes(); 35 | SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); 36 | IvParameterSpec iv = new IvParameterSpec(ivParameter.getBytes());//使用CBC模式,需要一个向量iv,可增加加密算法的强度 37 | cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); 38 | byte[] encrypted = cipher.doFinal(sSrc.getBytes("utf-8")); 39 | return new BASE64Encoder().encode(encrypted);//此处使用BASE64做转码。 40 | } 41 | 42 | // 解密 43 | @Override 44 | public String Decrypt(String sSrc) throws Exception { 45 | try { 46 | byte[] raw = sKey.getBytes("ASCII"); 47 | SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); 48 | Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); 49 | IvParameterSpec iv = new IvParameterSpec(ivParameter.getBytes()); 50 | cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv); 51 | byte[] encrypted1 = new BASE64Decoder().decodeBuffer(sSrc);//先用base64解密 52 | byte[] original = cipher.doFinal(encrypted1); 53 | String originalString = new String(original, "utf-8"); 54 | return originalString; 55 | } catch (Exception ex) { 56 | return null; 57 | } 58 | } 59 | 60 | @Override 61 | public String Sign(String content, String privateKey) throws Exception { 62 | return null; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /common-security/src/main/java/com/yz/common/security/aes/AES_ECB.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.security.aes; 2 | 3 | import com.yz.common.security.ISecurity; 4 | import sun.misc.BASE64Encoder; 5 | 6 | import javax.crypto.Cipher; 7 | import javax.crypto.spec.SecretKeySpec; 8 | import java.security.Security; 9 | import java.util.Base64; 10 | 11 | public class AES_ECB implements ISecurity { 12 | 13 | private String sKey = "B31F2A75FBF94099"; 14 | 15 | private String ALGORITHM = "AES/ECB/PKCS7Padding"; 16 | 17 | private byte[] raw = null; 18 | 19 | 20 | public AES_ECB(String sKey, String algorithm) { 21 | this.sKey = sKey; 22 | this.ALGORITHM = algorithm; 23 | Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); 24 | try { 25 | raw = sKey.getBytes(); 26 | } catch (Exception e) { 27 | e.printStackTrace(); 28 | } 29 | } 30 | 31 | /** 32 | * 加密 33 | * 34 | * @param data 35 | * @return 36 | * @throws Exception 37 | */ 38 | @Override 39 | public String Encrypt(String data) throws Exception { 40 | byte[] encrypted = null; 41 | SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); 42 | Cipher cipher = Cipher.getInstance(ALGORITHM, "BC");//"算法/模式/补码方式" 43 | cipher.init(Cipher.ENCRYPT_MODE, skeySpec); 44 | encrypted = cipher.doFinal(data.getBytes("utf-8")); 45 | return new BASE64Encoder().encode(encrypted);//此处使用BASE64做转码功能,同时能起到2次加密的作用。 46 | } 47 | 48 | /** 49 | * 解密 50 | * 51 | * @param data 52 | * @return 53 | * @throws Exception 54 | */ 55 | @Override 56 | public String Decrypt(String data) throws Exception { 57 | SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); 58 | Cipher cipher = Cipher.getInstance(ALGORITHM, "BC"); 59 | cipher.init(Cipher.DECRYPT_MODE, skeySpec); 60 | byte[] decode = Base64.getDecoder().decode(data.getBytes());//先用base64解密 61 | byte[] original = cipher.doFinal(decode); 62 | String originalString = new String(original, "utf-8"); 63 | return originalString; 64 | } 65 | 66 | @Override 67 | public String Sign(String content, String privateKey) throws Exception { 68 | return null; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /common-web/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | common-project 5 | com.yz 6 | 1.0.3 7 | 8 | 4.0.0 9 | 10 | common-web 11 | jar 12 | 13 | common-web 14 | http://maven.apache.org 15 | 16 | 17 | 18 | org.springframework 19 | spring-web 20 | 21 | 22 | org.springframework 23 | spring-webmvc 24 | 25 | 26 | com.yz 27 | common-core 28 | 1.0.3 29 | 30 | 31 | com.yz 32 | common-security 33 | 1.0.3 34 | 35 | 36 | 37 | javax.servlet 38 | javax.servlet-api 39 | 40 | 41 | org.reflections 42 | reflections 43 | 44 | 45 | 46 | 47 | 48 | ${artifactId} 49 | 50 | 51 | -------------------------------------------------------------------------------- /common-web/pom.xml.versionsBackup: -------------------------------------------------------------------------------- 1 | 3 | 4 | common-project 5 | com.yz 6 | 0.0.1-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | common-web 11 | jar 12 | 13 | common-web 14 | http://maven.apache.org 15 | 16 | 17 | UTF-8 18 | 19 | 20 | 21 | 22 | 23 | org.springframework 24 | spring-webmvc 25 | ${org.springframework.version} 26 | 27 | 28 | com.yz 29 | common-core 30 | 0.0.1-SNAPSHOT 31 | 32 | 33 | com.yz 34 | common-security 35 | 0.0.1-SNAPSHOT 36 | 37 | 38 | 39 | 40 | 41 | ${artifactId} 42 | 43 | 44 | -------------------------------------------------------------------------------- /common-web/src/main/java/com/yz/common/web/IHttpServletRequestWrapper.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.web; 2 | 3 | import com.alibaba.fastjson.JSONArray; 4 | import javax.servlet.http.HttpServletRequest; 5 | import javax.servlet.http.HttpServletRequestWrapper; 6 | import java.util.*; 7 | 8 | /** 9 | * @author yangzhao 10 | * @Description 11 | * @Date create by 00:02 18/2/15 12 | */ 13 | public class IHttpServletRequestWrapper extends HttpServletRequestWrapper { 14 | 15 | private Map params = new HashMap(); 16 | 17 | public IHttpServletRequestWrapper(HttpServletRequest request) { 18 | super(request); 19 | //将参数表,赋予给当前的Map以便于持有request中的参数 20 | this.params.putAll(request.getParameterMap()); 21 | } 22 | //重载一个构造方法 23 | public IHttpServletRequestWrapper(HttpServletRequest request , Map extendParams) { 24 | this(request); 25 | addAllParameters(extendParams);//这里将扩展参数写入参数表 26 | } 27 | 28 | @Override 29 | public String getParameter(String name) {//重写getParameter,代表参数从当前类中的map获取 30 | String[]values = params.get(name); 31 | if(values == null || values.length == 0) { 32 | return null; 33 | } 34 | return values[0]; 35 | } 36 | 37 | @Override 38 | public String[] getParameterValues(String name) {//同上 39 | return params.get(name); 40 | } 41 | 42 | public void addAllParameters(MapotherParams) {//增加多个参数 43 | if (otherParams==null){ 44 | return; 45 | } 46 | for(Map.Entryentry : otherParams.entrySet()) { 47 | addParameter(entry.getKey() , entry.getValue()); 48 | } 49 | } 50 | 51 | public void addParameter(String name , Object value) {//增加参数 52 | if(value == null) { 53 | return; 54 | } 55 | if(value instanceof String[]) { 56 | params.put(name , (String[])value); 57 | }else if(value instanceof String) { 58 | params.put(name , new String[] {(String)value}); 59 | }else if (value instanceof JSONArray){ 60 | JSONArray jsonArray = (JSONArray) value; 61 | Object[] objects = jsonArray.toArray(); 62 | String[] values = new String[jsonArray.size()]; 63 | for (int i=0;i getParameterMap() { 74 | return params; 75 | } 76 | 77 | @Override 78 | public Enumeration getParameterNames() { 79 | if(this.getRequest() == null) { 80 | throw new IllegalStateException("requestFacade.nullRequest"); 81 | } else { 82 | return Collections.enumeration(params.keySet()); 83 | } 84 | } 85 | 86 | public void emptyParameters(){ 87 | params.clear(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /common-web/src/main/java/com/yz/common/web/annotations/HttpParam.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.web.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Created by yangzhao on 18/2/13. 10 | */ 11 | @Target(ElementType.FIELD) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | public @interface HttpParam { 14 | } 15 | -------------------------------------------------------------------------------- /common-web/src/main/java/com/yz/common/web/annotations/ParamsValidate.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.web.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Created by yangzhao on 18/2/14. 10 | */ 11 | @Target(ElementType.PARAMETER) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | public @interface ParamsValidate { 14 | } 15 | -------------------------------------------------------------------------------- /common-web/src/main/java/com/yz/common/web/controller/ControllerAdviceHandler.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.web.controller; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.yz.common.core.exception.HandlerException; 5 | import com.yz.common.core.message.ResponseMessage; 6 | import org.apache.commons.fileupload.FileUploadException; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.core.MethodParameter; 10 | import org.springframework.http.HttpStatus; 11 | import org.springframework.http.MediaType; 12 | import org.springframework.http.server.ServerHttpRequest; 13 | import org.springframework.http.server.ServerHttpResponse; 14 | import org.springframework.stereotype.Component; 15 | import org.springframework.validation.BindException; 16 | import org.springframework.validation.FieldError; 17 | import org.springframework.web.bind.MissingServletRequestParameterException; 18 | import org.springframework.web.bind.annotation.ControllerAdvice; 19 | import org.springframework.web.bind.annotation.ExceptionHandler; 20 | import org.springframework.web.bind.annotation.ResponseBody; 21 | import org.springframework.web.bind.annotation.ResponseStatus; 22 | import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; 23 | 24 | import javax.validation.ConstraintViolation; 25 | import javax.validation.ConstraintViolationException; 26 | import java.util.List; 27 | import java.util.Set; 28 | 29 | /** 30 | * @author yangzhao 31 | * @Description 32 | * @Date create by 20:57 18/2/25 33 | */ 34 | @ControllerAdvice 35 | @Component 36 | public class ControllerAdviceHandler implements ResponseBodyAdvice { 37 | 38 | private final Logger logger = LoggerFactory.getLogger(ControllerAdviceHandler.class); 39 | 40 | @ExceptionHandler 41 | @ResponseBody 42 | @ResponseStatus(HttpStatus.OK) 43 | public Object handle(Exception exception) { 44 | logger.error("错误信息 ==== "+exception.getMessage()); 45 | if (exception instanceof BindException) { 46 | BindException bindException = (BindException) exception; 47 | List fieldErrors = bindException.getFieldErrors(); 48 | for (FieldError fieldError : fieldErrors) { 49 | return ResponseMessage.error(10010,fieldError.getField() + fieldError.getDefaultMessage()); 50 | } 51 | } 52 | 53 | if (exception instanceof ConstraintViolationException) { 54 | ConstraintViolationException exs = (ConstraintViolationException) exception; 55 | 56 | Set> violations = exs.getConstraintViolations(); 57 | for (ConstraintViolation violation : violations) { 58 | return ResponseMessage.error(10010,violation.getPropertyPath() + violation.getMessage()); 59 | } 60 | } 61 | if (exception instanceof HandlerException) { 62 | HandlerException handlerException = (HandlerException) exception; 63 | return new ResponseMessage(handlerException.getCode(), handlerException.getErrorInfo()); 64 | } 65 | if (exception instanceof MissingServletRequestParameterException) { 66 | MissingServletRequestParameterException missingServletRequestParameterException = (MissingServletRequestParameterException) exception; 67 | return ResponseMessage.error(10010, "请求参数" + missingServletRequestParameterException.getParameterName() + "不能为空"); 68 | } 69 | if (exception instanceof FileUploadException) { 70 | FileUploadException fileUploadException = (FileUploadException) exception; 71 | return ResponseMessage.error(10010, fileUploadException.getMessage()); 72 | } 73 | 74 | return ResponseMessage.error(0, "服务异常"); 75 | } 76 | 77 | @Override 78 | public boolean supports(MethodParameter returnType, Class converterType) { 79 | return true; 80 | } 81 | 82 | @Override 83 | public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) { 84 | ResponseMessage message = ResponseMessage.success(body); 85 | String responseData = JSON.toJSONString(message); 86 | logger.info("返回客户端数据:"+responseData); 87 | return message; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /common-web/src/main/java/com/yz/common/web/filter/BaseFilter.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.web.filter; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import javax.servlet.Filter; 7 | import javax.servlet.http.HttpServletResponse; 8 | import java.io.IOException; 9 | import java.io.PrintWriter; 10 | 11 | /** 12 | * @author yangzhao 13 | * @Description 14 | * @Date create by 16:39 18/2/17 15 | */ 16 | public abstract class BaseFilter implements Filter { 17 | public final Logger logger = LoggerFactory.getLogger(BaseFilter.class); 18 | 19 | public void serverReturn(HttpServletResponse response, String errorInfo){ 20 | PrintWriter writer = null; 21 | try { 22 | writer = response.getWriter(); 23 | writer.write(errorInfo); 24 | writer.flush(); 25 | } catch (IOException e) { 26 | e.printStackTrace(); 27 | }finally { 28 | writer.close(); 29 | } 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /common-web/src/main/java/com/yz/common/web/filter/DataSafeFilter.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.web.filter; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.yz.common.core.message.ResponseMessage; 5 | import com.yz.common.core.utils.HttpUtil; 6 | import com.yz.common.core.utils.StringUtils; 7 | import com.yz.common.security.ISecurity; 8 | import com.yz.common.web.IHttpServletRequestWrapper; 9 | import com.yz.common.web.utils.WebUtil; 10 | 11 | import javax.servlet.*; 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | import java.io.IOException; 15 | import java.util.HashMap; 16 | import java.util.Iterator; 17 | import java.util.Map; 18 | import java.util.Set; 19 | 20 | /** 21 | * @author yangzhao 22 | * @Description 请求参数转换;数据保存Parameter中 23 | * @Date create by 14:45 18/2/17 24 | */ 25 | public class DataSafeFilter extends BaseFilter { 26 | 27 | private ISecurity iSecurity; 28 | 29 | public void setiSecurity(ISecurity iSecurity) { 30 | this.iSecurity = iSecurity; 31 | } 32 | 33 | @Override 34 | public void init(FilterConfig filterConfig) throws ServletException { 35 | 36 | } 37 | 38 | @Override 39 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { 40 | HttpServletRequest httpServletRequest = (HttpServletRequest)request; 41 | String url = httpServletRequest.getRequestURL().toString(); 42 | IHttpServletRequestWrapper iHttpServletRequestWrapper = new IHttpServletRequestWrapper((HttpServletRequest) request,null); 43 | //解析请求数据 44 | try { 45 | byte[] data = WebUtil.getRequestByteArray(httpServletRequest); 46 | if (data == null || data.length <= 0) { 47 | logger.info("请求数据为空,url=" + url); 48 | chain.doFilter(iHttpServletRequestWrapper,response); 49 | return; 50 | } 51 | String strData = new String(data, "UTF-8"); 52 | logger.info("解密前数据:" + strData); 53 | if (!StringUtils.isEmpty(strData)){ 54 | strData = iSecurity.Decrypt(strData); 55 | logger.info("请求数据data:" + strData); 56 | if (StringUtils.isEmpty(strData)){ 57 | chain.doFilter(iHttpServletRequestWrapper,response); 58 | return; 59 | } 60 | Map map = JSON.parseObject(strData, HashMap.class); 61 | //将请求数据保存 62 | iHttpServletRequestWrapper.setAttribute("data",map); 63 | Set set = map.keySet(); 64 | Iterator iterator = set.iterator(); 65 | while (iterator.hasNext()){ 66 | Object next = iterator.next(); 67 | //将json数据以参数形式保存 68 | iHttpServletRequestWrapper.addParameter(next.toString(),map.get(next.toString())); 69 | } 70 | } 71 | } catch (Exception e) { 72 | logger.error("请求失败!", e); 73 | serverReturn((HttpServletResponse) response,JSON.toJSONString(new ResponseMessage(0, e.getMessage()))); 74 | return; 75 | } 76 | chain.doFilter(iHttpServletRequestWrapper,response); 77 | } 78 | 79 | @Override 80 | public void destroy() { 81 | 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /common-web/src/main/java/com/yz/common/web/http/params/validate/HttpParamsValidateAdvisor.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.web.http.params.validate; 2 | 3 | import java.lang.reflect.Field; 4 | import java.lang.reflect.InvocationTargetException; 5 | import java.lang.reflect.Method; 6 | import java.lang.reflect.Parameter; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import java.util.Set; 10 | import java.util.stream.Collectors; 11 | 12 | import javax.validation.ConstraintViolation; 13 | 14 | import org.aopalliance.intercept.MethodInterceptor; 15 | import org.aopalliance.intercept.MethodInvocation; 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | import org.springframework.stereotype.Component; 19 | 20 | import com.alibaba.fastjson.JSON; 21 | import com.yz.common.core.configuration.ValidatorConfiguration; 22 | import com.yz.common.core.exception.HandlerException; 23 | import com.yz.common.core.message.ResponseMessage; 24 | import com.yz.common.core.utils.ClassUtil; 25 | import com.yz.common.web.annotations.HttpParam; 26 | import com.yz.common.web.annotations.ParamsValidate; 27 | 28 | /** 29 | * 增强类 实现MethodInterceptor接口,通过反射动态解析方法是否标注@DataSource {@link ParamsValidate}注解。 30 | * 31 | * @author yangzhao create by 17/10/20 32 | */ 33 | @Component("httpParamsValidateAdvisor") 34 | public class HttpParamsValidateAdvisor implements MethodInterceptor { 35 | 36 | private final Logger logger = LoggerFactory.getLogger(HttpParamsValidateAdvisor.class); 37 | 38 | @Override 39 | public Object invoke(MethodInvocation methodInvocation) throws Throwable { 40 | Method method = methodInvocation.getMethod(); 41 | Object[] arguments = methodInvocation.getArguments(); 42 | Parameter[] parameters = method.getParameters(); 43 | for (int i = 0; i < parameters.length; i++) { 44 | ParamsValidate annotation = parameters[i].getAnnotation(ParamsValidate.class); 45 | if (annotation != null) { 46 | Set> violationSet = 47 | ValidatorConfiguration.validator().validate(arguments[i]); 48 | for (ConstraintViolation model : violationSet) { 49 | logger.warn(model.getPropertyPath() + model.getMessage()); 50 | return JSON.toJSONString(new ResponseMessage(-1, model.getPropertyPath() + model.getMessage())); 51 | } 52 | } 53 | } 54 | 55 | Object proceed = null; 56 | try { 57 | proceed = methodInvocation.proceed(); 58 | } catch (Exception e) { 59 | throw e; 60 | } 61 | return proceed; 62 | } 63 | 64 | private void validate(Object argument) throws HandlerException { 65 | Class aClass = argument.getClass(); 66 | Field[] declaredFields = aClass.getDeclaredFields(); 67 | List nullParams = new ArrayList<>(); 68 | for (Field field : declaredFields) { 69 | HttpParam annotation = field.getAnnotation(HttpParam.class); 70 | if (annotation == null) { 71 | continue; 72 | } 73 | 74 | String methodName = ClassUtil.createFieldMethodName("get", field.getName()); 75 | Method declaredMethod = null; 76 | try { 77 | declaredMethod = aClass.getDeclaredMethod(methodName); 78 | Object invoke = declaredMethod.invoke(argument); 79 | if (invoke == null) { 80 | nullParams.add(field.getName()); 81 | } 82 | } catch (NoSuchMethodException e) { 83 | e.printStackTrace(); 84 | } catch (InvocationTargetException e) { 85 | e.printStackTrace(); 86 | } catch (IllegalAccessException e) { 87 | e.printStackTrace(); 88 | } 89 | 90 | } 91 | 92 | if (nullParams.size() > 0) { 93 | String collect = nullParams.stream().collect(Collectors.joining("、")); 94 | throw new HandlerException("请求参数" + collect + "不能为空"); 95 | } 96 | 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /common-web/src/main/java/com/yz/common/web/springmvc/interceptor/BaseInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.yz.common.web.springmvc.interceptor; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.web.servlet.HandlerInterceptor; 7 | import org.springframework.web.servlet.ModelAndView; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.io.IOException; 12 | import java.io.PrintWriter; 13 | import java.util.Enumeration; 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | 17 | /** 18 | * @author yangzhao 19 | * @Description 20 | * @Date create by 17:24 18/2/4 21 | */ 22 | public class BaseInterceptor implements HandlerInterceptor { 23 | 24 | public final Logger logger = LoggerFactory.getLogger(BaseInterceptor.class); 25 | 26 | @Override 27 | public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception { 28 | logger.info(httpServletRequest.getRequestURL().toString()); 29 | //设置header头数据返回类型 30 | httpServletResponse.setContentType("content-type: application/json; charset=utf-8;"); 31 | logger.info("请求参数:"+ JSON.toJSONString(httpServletRequest.getParameterMap())); 32 | return true; 33 | } 34 | 35 | @Override 36 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { 37 | } 38 | 39 | @Override 40 | public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception { 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /common/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | common-project 5 | com.yz 6 | 1.0.3 7 | 8 | 4.0.0 9 | 10 | common 11 | jar 12 | 13 | common 14 | http://maven.apache.org 15 | 16 | 17 | UTF-8 18 | 19 | 20 | 21 | 22 | com.yz 23 | common-core 24 | 1.0.3 25 | 26 | 27 | com.yz 28 | common-cache 29 | 1.0.3 30 | 31 | 32 | com.yz 33 | common-security 34 | 1.0.3 35 | 36 | 37 | com.yz 38 | common-web 39 | 1.0.3 40 | 41 | 42 | com.yz 43 | common-elasticsearch 44 | 1.0.3 45 | 46 | 47 | com.yz 48 | common-pay 49 | 1.0.3 50 | 51 | 52 | com.yz 53 | common-distributed-lock 54 | 1.0.3 55 | 56 | 57 | 58 | 59 | ${project.artifactId} 60 | 61 | 62 | org.apache.maven.plugins 63 | maven-shade-plugin 64 | 1.4 65 | 66 | 67 | package 68 | 69 | shade 70 | 71 | 72 | true 73 | true 74 | 75 | 76 | com.yz:common-core 77 | com.yz:common-pay 78 | com.yz:common-cache 79 | com.yz:common-security 80 | com.yz:common-web 81 | com.yz:common-elasticsearch 82 | com.yz:common-distributed-lock 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /common/pom.xml.versionsBackup: -------------------------------------------------------------------------------- 1 | 3 | 4 | common-project 5 | com.yz 6 | 0.0.1-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | common 11 | jar 12 | 13 | common 14 | http://maven.apache.org 15 | 16 | 17 | UTF-8 18 | 19 | 20 | 21 | 22 | com.yz 23 | common-core 24 | 0.0.1-SNAPSHOT 25 | 26 | 27 | com.yz 28 | common-cache 29 | 0.0.1-SNAPSHOT 30 | 31 | 32 | com.yz 33 | common-security 34 | 0.0.1-SNAPSHOT 35 | 36 | 37 | com.yz 38 | common-web 39 | 0.0.1-SNAPSHOT 40 | 41 | 42 | com.yz 43 | common-elasticsearch 44 | 0.0.1-SNAPSHOT 45 | 46 | 47 | 48 | 49 | ${project.artifactId} 50 | 51 | 52 | org.apache.maven.plugins 53 | maven-shade-plugin 54 | 1.4 55 | 56 | 57 | package 58 | 59 | shade 60 | 61 | 62 | true 63 | true 64 | 65 | 66 | com.yz:common-core 67 | com.yz:common-pay 68 | com.yz:common-cache 69 | com.yz:common-security 70 | com.yz:common-web 71 | com.yz:common-elasticsearch 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | --------------------------------------------------------------------------------