From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 25 二月 2025 16:41:22 +0800 Subject: [PATCH] 淘宝转链接口更新 --- fanli/src/main/java/com/yeshi/fanli/util/StringUtil.java | 645 +++++++++++++++++++++++++++++----------------------------- 1 files changed, 321 insertions(+), 324 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/StringUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/StringUtil.java index ba9af49..53f198c 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/StringUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/StringUtil.java @@ -1,324 +1,321 @@ -package com.yeshi.fanli.util; - -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Method; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.commons.codec.binary.Base64; - -import net.sf.json.JSONObject; -import sun.misc.BASE64Encoder; - -public class StringUtil { - public static String getWholePathWithHost(HttpServletRequest request, String path) { - String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() - + request.getContextPath() + "/"; - return basePath + path; - } - - public static String getBasePath(HttpServletRequest request) { - String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() - + request.getContextPath();// 锟斤拷锟斤拷锟斤拷式 - return basePath; - } - - public static String getWholePath(HttpServletRequest request, String url) { - if (url != null) { - if (url.startsWith("http://") || url.startsWith("https://")) - return url; - else - return getWholePathWithHost(request, url); - } - return ""; - } - - // 鏄惁涓虹數璇濆彿鐮� - public static boolean isMobile(String mobile) { - - String regex = "^((13[0-9])|(14[0-9])|(17[0-9])|(15[^4,\\D])|(18[0-9])|(19[0-9])|(16[0-9]))\\d{8}$"; - Pattern p = Pattern.compile(regex); - Matcher m = p.matcher(mobile); - - if (mobile == null || mobile.equals("") || mobile.length() != 11) { - - return false; - - } else { - return m.find(); - } - } - - /** - * 锟斤拷锟斤拷锟斤拷锟斤拷 - * - * @return - */ - public static String getRandomCode() { - String sts = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - String code = ""; - for (int i = 0; i < 10; i++) { - int p = (int) (Math.random() * 26); - code += sts.charAt(p); - } - return code; - } - - public static String getRandomCode(int count) { - String sts = "0123456789abcdefghijklmnopqrsduvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - String code = ""; - for (int i = 0; i < count; i++) { - int p = (int) (Math.random() * 62); - code += sts.charAt(p); - } - return code; - } - - /** - * 锟斤拷证锟斤拷锟斤拷锟�? - * - * @return - */ - public static String getVerifyCode() { - String sts = "0123456789"; - String code = ""; - for (int i = 0; i < 6; i++) { - int p = (int) (Math.random() * 10); - code += sts.charAt(p); - } - return code; - } - - public static String getVerifyCode(int count) { - String sts = "0123456789"; - String code = ""; - for (int i = 0; i < count; i++) { - int p = (int) (Math.random() * 10); - code += sts.charAt(p); - } - return code; - } - - // 锟斤拷取锟斤拷锟脚凤拷锟酵的革拷式 - public static String getMessageStyle(String code) { - - return "校锟斤拷锟斤拷:" + code + ",锟斤拷锟斤拷锟剿猴拷注锟结。锟斤拷锟斤拷锟斤拷锟斤拷锟轿猴拷锟斤拷锟结供锟斤拷锟秸碉拷锟侥讹拷锟斤拷校锟斤拷锟诫】"; - } - - // 锟角凤拷锟角空碉拷锟街凤拷 - public static boolean isNullOrEmpty(String text) { - if (text == null || text.length() == 0 || text.equalsIgnoreCase("null")) { - return true; - } - return false; - } - - // 32位MD5锟斤拷锟斤拷 - public static String Md5(String st) { - try { - MessageDigest md = MessageDigest.getInstance("MD5"); - try { - md.update(st.getBytes("UTF-8")); - } catch (UnsupportedEncodingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - byte b[] = md.digest(); - - int i; - - StringBuffer buf = new StringBuffer(""); - for (int offset = 0; offset < b.length; offset++) { - i = b[offset]; - if (i < 0) - i += 256; - if (i < 16) - buf.append("0"); - buf.append(Integer.toHexString(i)); - } - return buf.toString(); - // LogUtil.i("result: " + buf.toString());// 32位锟侥硷拷锟斤拷 - // LogUtil.i("result: " + buf.toString().substring(8, - // 24));// 16位锟侥硷拷锟斤拷 - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } - return null; - } - - public static String getString(String st) { - return isNullOrEmpty(st) ? "" : st; - } - - public static String getString(int i) { - return getString(i + ""); - } - - public static String getString(long i) { - return getString(i + ""); - } - - /* - * 锟斤拷取锟叫硷拷锟斤拷呛诺牡缁帮拷锟斤拷锟�? - */ - public static String getSubMobile(String mobile) { - if (!StringUtil.isNullOrEmpty(mobile) && mobile.length() > 10) { - return mobile.subSequence(0, 3).toString() + "****" + mobile.subSequence(7, mobile.length()).toString(); - } else - return mobile; - } - - public static String getBase64FromByte(byte[] b) { - - String s = null; - if (b != null) { - s = new BASE64Encoder().encode(b); - } - return s; - } - - public static int getPage(String page) { - if (StringUtil.isNullOrEmpty(page)) { - return 0; - } else { - try { - return Integer.parseInt(page); - } catch (Exception e) { - return 0; - } - } - } - - public static String getNumberFromString(String st) { - String number = ""; - Pattern p = Pattern.compile("[0-9\\.]+"); - Matcher m = p.matcher(st); - - while (m.find()) { - number += (m.group() + ","); - } - return number; - } - - public static String getNotNullString(String st) { - if (isNullOrEmpty(st)) - return ""; - else - return st; - } - - public static String getUTF8String(String resource, String chactor) { - if (!isNullOrEmpty(resource)) { - try { - return new String(resource.getBytes(chactor), "UTF-8"); - } catch (UnsupportedEncodingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - return ""; - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - public static String getBase64String(String str) throws Exception { - byte[] input = str.getBytes("UTF-8"); - Class clazz = Class.forName("com.sun.org.apache.xerces.internal.impl.dv.util.Base64"); - Method mainMethod = clazz.getMethod("encode", byte[].class); - mainMethod.setAccessible(true); - Object retObj = mainMethod.invoke(null, new Object[] { input }); - return (String) retObj; - } - - // 瑙e瘑 - public static String getFromBase64(String s) { - byte[] b = null; - String result = null; - if (s != null) { - final Base64 base64 = new Base64(); - try { - b = base64.decode(s.getBytes("UTF-8")); - result = new String(b, "utf-8"); - } catch (Exception e) { - e.printStackTrace(); - } - } - return result; - } - - public static String SHA1(String decript) { - try { - MessageDigest digest = java.security.MessageDigest.getInstance("SHA-1"); - digest.update(decript.getBytes()); - byte messageDigest[] = digest.digest(); - // Create Hex String - StringBuffer hexString = new StringBuffer(); - // 瀛楄妭鏁扮粍杞崲锟�?鍗佸叚杩涘埗 锟�? - for (int i = 0; i < messageDigest.length; i++) { - String shaHex = Integer.toHexString(messageDigest[i] & 0xFF); - if (shaHex.length() < 2) { - hexString.append(0); - } - hexString.append(shaHex); - } - return hexString.toString(); - - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } - return ""; - } - - public static long[] parseLong(String[] arr) { - long[] lArr = new long[arr.length]; - int ii = 0; - for (String str : arr) { - lArr[ii] = Long.parseLong(str); - ii++; - } - return lArr; - } - - public static boolean isJson(String content) { - try { - JSONObject.fromObject(content); - return true; - } catch (Exception e) { - return false; - } - } - - public static String concat(List list, String sperator) { - if (list == null) - return null; - String str = ""; - for (Object obj : list) { - str += obj + sperator; - } - if (str.endsWith(sperator)) - str = str.substring(0, str.length() - sperator.length()); - return str; - } - - /** - * 娣樺彛浠ゆ彁鍙� - * - * @param str - * @return - */ - public static String picUpTaoToken(String str) { - String pattern = "(鈧硔1}[A-Za-z0-9]+鈧硔1})|(楼{1}[A-Za-z0-9]+楼{1})|(锟1}[A-Za-z0-9]+锟1})"; - Pattern r = Pattern.compile(pattern); - Matcher m = r.matcher(str); - while (m.find()) { - String group = m.group(0); - if (!StringUtil.isNullOrEmpty(group)) - return group; - } - return null; - } -} +package com.yeshi.fanli.util; + +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Method; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.codec.binary.Base64; + +import net.sf.json.JSONObject; +import sun.misc.BASE64Encoder; + +public class StringUtil { + public static String getWholePathWithHost(HttpServletRequest request, String path) { + String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + + request.getContextPath() + "/"; + return basePath + path; + } + + public static String getBasePath(HttpServletRequest request) { + String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + + request.getContextPath();// 锟斤拷锟斤拷锟斤拷式 + return basePath; + } + + public static String getWholePath(HttpServletRequest request, String url) { + if (url != null) { + if (url.startsWith("http://") || url.startsWith("https://")) + return url; + else + return getWholePathWithHost(request, url); + } + return ""; + } + + // 鏄惁涓虹數璇濆彿鐮� + public static boolean isMobile(String mobile) { + + String regex = "^((13[0-9])|(14[0-9])|(17[0-9])|(15[^4,\\D])|(18[0-9])|(19[0-9])|(16[0-9]))\\d{8}$"; + Pattern p = Pattern.compile(regex); + Matcher m = p.matcher(mobile); + + if (mobile == null || mobile.equals("") || mobile.length() != 11) { + + return false; + + } else { + return m.find(); + } + } + + /** + * 锟斤拷锟斤拷锟斤拷锟斤拷 + * + * @return + */ + public static String getRandomCode() { + String sts = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + String code = ""; + for (int i = 0; i < 10; i++) { + int p = (int) (Math.random() * 26); + code += sts.charAt(p); + } + return code; + } + + public static String getRandomCode(int count) { + String sts = "0123456789abcdefghijklmnopqrsduvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + String code = ""; + for (int i = 0; i < count; i++) { + int p = (int) (Math.random() * 62); + code += sts.charAt(p); + } + return code; + } + + /** + * 锟斤拷证锟斤拷锟斤拷锟�? + * + * @return + */ + public static String getVerifyCode() { + String sts = "0123456789"; + String code = ""; + for (int i = 0; i < 6; i++) { + int p = (int) (Math.random() * 10); + code += sts.charAt(p); + } + return code; + } + + public static String getVerifyCode(int count) { + String sts = "0123456789"; + String code = ""; + for (int i = 0; i < count; i++) { + int p = (int) (Math.random() * 10); + code += sts.charAt(p); + } + return code; + } + + // 锟斤拷取锟斤拷锟脚凤拷锟酵的革拷式 + public static String getMessageStyle(String code) { + + return "校锟斤拷锟斤拷:" + code + ",锟斤拷锟斤拷锟剿猴拷注锟结。锟斤拷锟斤拷锟斤拷锟斤拷锟轿猴拷锟斤拷锟结供锟斤拷锟秸碉拷锟侥讹拷锟斤拷校锟斤拷锟诫】"; + } + + // 锟角凤拷锟角空碉拷锟街凤拷 + public static boolean isNullOrEmpty(String text) { + if (text == null || text.trim().length() == 0 || text.equalsIgnoreCase("null")) { + return true; + } + return false; + } + + // 32位MD5锟斤拷锟斤拷 + public static String Md5(String st) { + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + try { + md.update(st.getBytes("UTF-8")); + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + byte b[] = md.digest(); + + int i; + + StringBuffer buf = new StringBuffer(""); + for (int offset = 0; offset < b.length; offset++) { + i = b[offset]; + if (i < 0) + i += 256; + if (i < 16) + buf.append("0"); + buf.append(Integer.toHexString(i)); + } + return buf.toString(); + // LogUtil.i("result: " + buf.toString());// 32位锟侥硷拷锟斤拷 + // LogUtil.i("result: " + buf.toString().substring(8, + // 24));// 16位锟侥硷拷锟斤拷 + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + return null; + } + + public static String getString(String st) { + return isNullOrEmpty(st) ? "" : st; + } + + public static String getString(int i) { + return getString(i + ""); + } + + public static String getString(long i) { + return getString(i + ""); + } + + /* + * 锟斤拷取锟叫硷拷锟斤拷呛诺牡缁帮拷锟斤拷锟�? + */ + public static String getSubMobile(String mobile) { + if (!StringUtil.isNullOrEmpty(mobile) && mobile.length() > 10) { + return mobile.subSequence(0, 3).toString() + "****" + mobile.subSequence(7, mobile.length()).toString(); + } else + return mobile; + } + + public static String getBase64FromByte(byte[] b) { + + String s = null; + if (b != null) { + s = new BASE64Encoder().encode(b); + } + return s; + } + + public static int getPage(String page) { + if (StringUtil.isNullOrEmpty(page)) { + return 0; + } else { + try { + return Integer.parseInt(page); + } catch (Exception e) { + return 0; + } + } + } + + public static String getNumberFromString(String st) { + String number = ""; + Pattern p = Pattern.compile("[0-9\\.]+"); + Matcher m = p.matcher(st); + + while (m.find()) { + number += (m.group() + ","); + } + return number; + } + + public static String getNotNullString(String st) { + if (isNullOrEmpty(st)) + return ""; + else + return st; + } + + public static String getUTF8String(String resource, String chactor) { + if (!isNullOrEmpty(resource)) { + try { + return new String(resource.getBytes(chactor), "UTF-8"); + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return ""; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public static String getBase64String(String str) throws Exception { + byte[] input = str.getBytes("UTF-8"); + Class clazz = Class.forName("com.sun.org.apache.xerces.internal.impl.dv.util.Base64"); + Method mainMethod = clazz.getMethod("encode", byte[].class); + mainMethod.setAccessible(true); + Object retObj = mainMethod.invoke(null, new Object[] { input }); + return (String) retObj; + } + + // 瑙e瘑 + public static String getFromBase64(String s) { + byte[] b = null; + String result = null; + if (s != null) { + final Base64 base64 = new Base64(); + try { + b = base64.decode(s.getBytes("UTF-8")); + result = new String(b, "utf-8"); + } catch (Exception e) { + e.printStackTrace(); + } + } + return result; + } + + public static String SHA1(String decript) { + try { + MessageDigest digest = java.security.MessageDigest.getInstance("SHA-1"); + digest.update(decript.getBytes()); + byte messageDigest[] = digest.digest(); + // Create Hex String + StringBuffer hexString = new StringBuffer(); + // 瀛楄妭鏁扮粍杞崲锟�?鍗佸叚杩涘埗 锟�? + for (int i = 0; i < messageDigest.length; i++) { + String shaHex = Integer.toHexString(messageDigest[i] & 0xFF); + if (shaHex.length() < 2) { + hexString.append(0); + } + hexString.append(shaHex); + } + return hexString.toString(); + + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + return ""; + } + + public static long[] parseLong(String[] arr) { + long[] lArr = new long[arr.length]; + int ii = 0; + for (String str : arr) { + lArr[ii] = Long.parseLong(str); + ii++; + } + return lArr; + } + + public static boolean isJson(String content) { + try { + JSONObject.fromObject(content); + return true; + } catch (Exception e) { + return false; + } + } + + public static String concat(List list, String sperator) { + if (list == null) + return null; + String str = ""; + for (Object obj : list) { + str += obj + sperator; + } + if (str.endsWith(sperator)) + str = str.substring(0, str.length() - sperator.length()); + return str; + } + + public static String concat(Object[] array, String sperator) { + if (array == null) + return null; + + String str = ""; + for (int i = 0; i < array.length; i++) { + str += array[i] + sperator; + } + + if (str.endsWith(sperator)) + str = str.substring(0, str.length() - sperator.length()); + return str; + } + +} -- Gitblit v1.8.0