From d0ac51a0596b5a76fba7b4e5bc4f441dba56c3d8 Mon Sep 17 00:00:00 2001 From: zenghao Date: Sun, 11 Sep 2016 21:37:13 +0800 Subject: [PATCH] =?UTF-8?q?1.0.0=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/entity/ApiCommonResultVo.java | 85 ++++++++++++ .../core/entity/ApiPageListResultVo.java | 83 ++++++++++++ .../pay/common/core/entity/PageListVO.java | 107 ++++++++++++++++ .../pay/common/core/entity/rpObject.java | 25 ++++ .../pay/common/core/utils/EncryptUtil.java | 121 ++++++++++++++++++ 5 files changed, 421 insertions(+) create mode 100644 roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/entity/ApiCommonResultVo.java create mode 100644 roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/entity/ApiPageListResultVo.java create mode 100644 roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/entity/PageListVO.java create mode 100644 roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/entity/rpObject.java create mode 100644 roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/utils/EncryptUtil.java diff --git a/roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/entity/ApiCommonResultVo.java b/roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/entity/ApiCommonResultVo.java new file mode 100644 index 0000000..39d0ce5 --- /dev/null +++ b/roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/entity/ApiCommonResultVo.java @@ -0,0 +1,85 @@ +/* + * Copyright 2015-2102 RonCoo(http://www.roncoo.com) Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.roncoo.pay.common.core.entity; + +import com.alibaba.fastjson.JSONObject; + +/** + * api请求正常返回结果,该实体作为API请求时,按照规范返回的实体. code 为返回码 msg 为返回描述 data 为返回的具体结果 Created + * 龙果学院:www.roncoo.com + * @author zenghao + */ +public class ApiCommonResultVo { + + public ApiCommonResultVo(int code, String msg, Object data) { + this.code = code; + this.msg = msg; + if (data != null) { + this.data = data; + } + } + + public ApiCommonResultVo(Object data) { + this.code = 0; + this.msg = ""; + if (data != null) { + this.data = data; + } + } + + /** + * 返回码 + */ + private int code; + + /** + * 返回描述 + */ + private String msg = ""; + + /** + * 返回数据 + */ + private Object data = new Object(); + + public void setCode(int code) { + this.code = code; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public void setData(Object data) { + this.data = data; + } + + public int getCode() { + return code; + } + + public String getMsg() { + return msg; + } + + public Object getData() { + return data; + } + + public static void main(String[] args) { + System.out.println(JSONObject.toJSONString(new ApiCommonResultVo(-1, "", null))); + } +} diff --git a/roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/entity/ApiPageListResultVo.java b/roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/entity/ApiPageListResultVo.java new file mode 100644 index 0000000..385ce8b --- /dev/null +++ b/roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/entity/ApiPageListResultVo.java @@ -0,0 +1,83 @@ +/* + * Copyright 2015-2102 RonCoo(http://www.roncoo.com) Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.roncoo.pay.common.core.entity; + +import com.alibaba.fastjson.JSONObject; + +import java.util.ArrayList; + +/** + * API请求,返回分页数据时,统一实体类,将返回的数据统一封装到该实体中,返回给客户端 + * 龙果学院:www.roncoo.com + * @author zenghao + */ +public class ApiPageListResultVo { + + /** + * 返回码 + */ + private int code; + + /** + * 返回描述 + */ + private String msg = ""; + + /** + * 返回分页数据,默认为0页0条 + */ + private PageListVO data = new PageListVO(0,0,0,new ArrayList()); + + public void setCode(int code) { + this.code = code; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public void setData(PageListVO data) { + this.data = data; + } + + public int getCode() { + return code; + } + + public String getMsg() { + return msg; + } + + public PageListVO getData() { + return data; + } + + + + public static void main(String [] args ){ + + ApiPageListResultVo apiPageListResultVo = new ApiPageListResultVo(); + apiPageListResultVo.setCode(-1); + apiPageListResultVo.setMsg("测试数据"); + + PageListVO pageListVO = new PageListVO(0,2,33,new ArrayList()); + + apiPageListResultVo.setData(pageListVO); + + System.out.println(JSONObject.toJSONString(apiPageListResultVo)); + } + +} diff --git a/roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/entity/PageListVO.java b/roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/entity/PageListVO.java new file mode 100644 index 0000000..c071eaa --- /dev/null +++ b/roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/entity/PageListVO.java @@ -0,0 +1,107 @@ +/* + * Copyright 2015-2102 RonCoo(http://www.roncoo.com) Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.roncoo.pay.common.core.entity; + +import java.util.ArrayList; +import java.util.List; + +/** + * 返回的分页实体 + * 龙果学院:www.roncoo.com + * @author zenghao + */ +public class PageListVO { + + /** 总数量 **/ + private long total ; + + /** 页码 **/ + private int page; + + /** 每页条数 **/ + private int pageSize; + + /** 分页数据 **/ + private List pageData = new ArrayList(); + + /** + * 汇总数据 + */ + private Object summary; + + public PageListVO(long total , int page , int pageSize , List pageData){ + this.total = total; + this.page = page; + this.pageSize = pageSize; + + if (pageData != null){ + this.pageData = pageData; + } + + } + + public PageListVO(long total , int page , int pageSize , List pageData, Object summary){ + this.total = total; + this.page = page; + this.pageSize = pageSize; + this.summary = summary; + + if (pageData != null){ + this.pageData = pageData; + } + + } + + public Object getSummary() { + return summary; + } + + public void setSummary(Object summary) { + this.summary = summary; + } + + public void setTotal(int total) { + this.total = total; + } + + public void setPage(int page) { + this.page = page; + } + + public void setPageSize(int pageSize) { + this.pageSize = pageSize; + } + + public void setPageData(List pageData) { + this.pageData = pageData; + } + + public long getTotal() { + return total; + } + + public int getPage() { + return page; + } + + public int getPageSize() { + return pageSize; + } + + public List getPageData() { + return pageData; + } +} diff --git a/roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/entity/rpObject.java b/roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/entity/rpObject.java new file mode 100644 index 0000000..86217e3 --- /dev/null +++ b/roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/entity/rpObject.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015-2102 RonCoo(http://www.roncoo.com) Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.roncoo.pay.common.core.entity; + +import java.io.Serializable; + +/** + * 龙果学院:www.roncoo.com + * @author zenghao + */ +public class rpObject extends Object implements Serializable { +} diff --git a/roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/utils/EncryptUtil.java b/roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/utils/EncryptUtil.java new file mode 100644 index 0000000..5712e97 --- /dev/null +++ b/roncoo-pay-common-core/src/main/java/com/roncoo/pay/common/core/utils/EncryptUtil.java @@ -0,0 +1,121 @@ +/* + * Copyright 2015-2102 RonCoo(http://www.roncoo.com) Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.roncoo.pay.common.core.utils; + +import java.io.IOException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import sun.misc.BASE64Decoder; +import sun.misc.BASE64Encoder; + +/** + * 加密工具类 + * @company:广州领课网络科技有限公司(龙果学院 www.roncoo.com). + * @author zenghao + */ +public class EncryptUtil { + + private static final Log LOG = LogFactory.getLog(EncryptUtil.class); + + // 密码盐 + public static final String PWDSALT = "PAY"; + + /** + * 私有构造方法,将该工具类设为单例模式. + */ + private EncryptUtil() { + } + + /** + * 用MD5算法进行加密 + * + * @param str + * 需要加密的字符串 + * @return MD5加密后的结果 + */ + public static String encodeMD5String(String str) { + return encode(str, "MD5"); + } + + /** + * 用SHA算法进行加密 + * + * @param str + * 需要加密的字符串 + * @return SHA加密后的结果 + */ + public static String encodeSHAString(String str) { + return encode(str, "SHA"); + } + + /** + * 用base64算法进行加密 + * + * @param str + * 需要加密的字符串 + * @return base64加密后的结果 + */ + public static String encodeBase64String(String str) { + BASE64Encoder encoder = new BASE64Encoder(); + return encoder.encode(str.getBytes()); + } + + /** + * 用base64算法进行解密 + * + * @param str + * 需要解密的字符串 + * @return base64解密后的结果 + * @throws IOException + */ + public static String decodeBase64String(String str) throws IOException { + BASE64Decoder encoder = new BASE64Decoder(); + return new String(encoder.decodeBuffer(str)); + } + + private static String encode(String str, String method) { + MessageDigest mdInst = null; + // 把密文转换成十六进制的字符串形式 + // 单线程用StringBuilder,速度快 多线程用stringbuffer,安全 + StringBuilder dstr = new StringBuilder(); + try { + // 获得MD5摘要算法的 MessageDigest对象 + mdInst = MessageDigest.getInstance(method); + // 使用指定的字节更新摘要 + mdInst.update(str.getBytes()); + // 获得密文 + byte[] md = mdInst.digest(); + for (int i = 0; i < md.length; i++) { + int tmp = md[i]; + if (tmp < 0) { + tmp += 256; + } + if (tmp < 16) { + dstr.append("0"); + } + dstr.append(Integer.toHexString(tmp)); + } + } catch (NoSuchAlgorithmException e) { + LOG.error(e); + } + return dstr.toString(); + } + +}